Ryan Rad
Ryan Rad
  • 11
  • 7 489
Algorithm Optimization: Beyond O(n log n) built-in sort with the power of Context-Aware Sorting
Discover the untold story of Counting Sort and its surprising performance! This video unveils when and why Counting Sort can outperform popular built-in sorting algorithms like Timsort and Introsort. Learn how to identify scenarios where Counting Sort shines and when it falls short. Perfect for software engineers aiming to optimize their code and computer science enthusiasts eager to deepen their understanding of sorting algorithms.
0:00 Introduction to Built-in Sorting Algorithms
2:18 Benchmarking Sorting Algorithms
4:17 Counting Sort: How It Works
6:37 When to Use Counting Sort: Real-world Examples
8:35 Pitfalls: When Not to Use Counting Sort
Link to the Benchmarking Code: colab.research.google.com/drive/1QEHSZwZUqvB00JwtxbzY20vvKOKULZKA?usp=sharing
มุมมอง: 183

วีดีโอ

Algorithm Optimization: Constant Factor Improvement for Built-in min()/max() in Python
มุมมอง 2.1K3 หลายเดือนก่อน
Uncover the surprising truth about Python's built-in min() and max() functions! This video dives deep into constant factor optimization, comparing built-in functions with direct comparison approaches. Learn how small optimizations can lead to significant performance gains in large-scale applications. Perfect for Python developers looking to level up their optimization skills and algorithm enthu...
The Closest Pair of Points Problem: Brute Force to Divide and Conquer
มุมมอง 3993 หลายเดือนก่อน
Dive into one of computer science's classic problems: finding the closest pair of points in a 2D plane. This video breaks down the problem, explores its real-world applications, guides you through an efficient divide-and-conquer solution, demonstrates a brute force approach for comparison, and covers time and space complexity. Perfect for coding interview preparation and algorithm enthusiasts! ...
Prompt Engineering Mini-Course
มุมมอง 3834 หลายเดือนก่อน
Unlock the full potential of Large Language Models with expert prompt engineering techniques! This comprehensive guide will take you from basic prompts to advanced strategies, empowering you to harness the true power of AI language models. Whether you're a developer, data scientist, or AI enthusiast, you'll gain practical skills to dramatically improve your LLM interactions. Dive into the world...
Introduction to Large Language Models (LLMs): Core concepts and Techniques
มุมมอง 1.4K4 หลายเดือนก่อน
Uncover the transformative power of LLMs and their impact on industries across the globe. This video will guide you through the fundamental concepts, development process, and practical applications of these groundbreaking AI models. Whether you're a curious beginner or an experienced data enthusiast, you'll gain invaluable insights into the technology shaping the future of language-based intera...
Introduction to Clustering & K-Means
มุมมอง 1935 หลายเดือนก่อน
Explore the world of Clustering and K-Means in this brief 20 min video lesson! This video will guide you through the fundamentals of clustering and it's applications, with a special focus on the popular K-Means algorithm. Whether you're a beginner or an experienced data scientist, you'll gain valuable insights into this essential unsupervised learning technique. Join us on this journey to maste...
Introduction to Linear Programming
มุมมอง 46210 หลายเดือนก่อน
Explore the world of Linear Programming in this brief 20 min video lesson! In this video, we'll unravel the intuition behind linear programming, shed light on its core principles and popular methods (Simplex, Interior Point, and Elipsoid), and demonstrate its real-world applications across different domains. Whether you're a novice or a seasoned algorithm enthusiast, this video will empower you...
Gas Station Problem: Brute Force, Dynamic Programming, & Greedy Solutions - LeetCode 134
มุมมอง 397ปีที่แล้ว
Welcome to this coding/problem-solving adventure! In this video, we're tackling the popular LeetCode Gas Station problem from multiple angles: Brute Force, Dynamic Programming, and Greedy algorithms. We'll start by exploring the most straightforward approach, Brute Force, to truly grasp the problem. Then, we'll dive into more efficient strategies using Dynamic Programming and wrap up with the G...
Introduction to Greedy Programming
มุมมอง 589ปีที่แล้ว
Explore the world of Greedy Programming in this video lesson! In this video, we'll unravel the mysteries of this problem-solving technique, shed light on its core principles, and demonstrate its real-world applications across different domains. Whether you're a novice or a seasoned algorithm enthusiast, this video will empower you with the insights and expertise required to approach intricate o...
Introduction to Dynamic Programming
มุมมอง 1.3Kปีที่แล้ว
Dive into the world of Dynamic Programming with this comprehensive video lesson! In this video, we'll provide you with the intuition behind this powerful problem-solving technique, break down its key principles, and showcase its practical applications in various domains. Whether you're a beginner or looking to enhance your algorithmic skills, this video will equip you with the knowledge you nee...
Navigating Careers: Small vs Large Companies
มุมมอง 129ปีที่แล้ว
Are you at a career crossroads? Explore the intriguing dynamics of working in Large Corporations versus Small Companies. Discover the pros and cons, and find the path that aligns with your goals. 🔍 What We'll Discuss: 📈 Defining Large or Small Companies: Understand the differences in scale and impact between these two types of businesses. 🏆 Employment Benefits and Perks: Explore the comprehensi...

ความคิดเห็น

  • @banihas22
    @banihas22 25 วันที่ผ่านมา

    Fantastic explanation! Any chance you can make this presentation available publicly?

  • @fayezalhussein7115
    @fayezalhussein7115 หลายเดือนก่อน

    complate this series, please ! you are great

    • @RealRyanRad
      @RealRyanRad 25 วันที่ผ่านมา

      I'm glad you enjoyed it! I'm planning on expanding this topic in future videos.

  • @K9Megahertz
    @K9Megahertz 2 หลายเดือนก่อน

    It always boggles my mind why people spend time trying to optimize negligible things while having chosen the almost slowest language on the planet to write their code in. Like if optimized code and performance was that critical why would you pick python in the first place... Aside from that, I can't possibly imagine that the rest of your code base is so optimized that you are now down to trying to whittle nanoseconds off a min function. It's like buying high performance tires for your Ford Pinto so you can cut your 1/4 mile time from 17.75 seconds to 17.72...

  • @hazardousgamer6935
    @hazardousgamer6935 2 หลายเดือนก่อน

    There is another very easy solution to this problem (based on somewhat greedy approach) So it goes like this : First you make two copies of the given input array. ~O(N) Now you sort one of them by x coordinate and the other one by y coordinate. ~O(NlogN) Now in both lists, find out the pairwise distances (consecutive pairs only) and store the minimum found in both the sorted lists. ~O(N) Now simply return the minimum of the two minimums found ~O(N) So the overall complexity comes out to be O(NlogN). Hope this helps!

    • @RealRyanRad
      @RealRyanRad 2 หลายเดือนก่อน

      Thank you for sharing this alternative approach! This is an interesting solution but it's NOT guaranteed to find the answer! - Correctness: While this approach will often find the closest pair, it's not guaranteed to always do so. Consider a case where the closest pair of points are diagonal to each other, they might not be adjacent in either the x-sorted or y-sorted list. - Space Complexity: This solution requires O(N) extra space for the additional sorted arrays, whereas the divide-and-conquer approach can be implemented with O(log N) extra space (for the recursion stack). - Generalization: The divide-and-conquer approach we discussed can be more easily generalized to higher dimensions, while this approach might be more challenging to extend.

    • @hazardousgamer6935
      @hazardousgamer6935 2 หลายเดือนก่อน

      ​​​@@RealRyanRadFrom you reply, i can see that you are doubting the correctness of the greedy algorithm. Like for ex if i take closest pair of points to be diagonally placed as you stated in your reply, let's say : (3,6), (3,3), (4,4) (4,8) Then we sort it according to x we will get : (3,3), (3,6), (4,4), (4,8) Then we sort it according to y we get : (3,3), (4,4), (3,6), (4,8) Now if we find the pairwise minimum in 1st array we will get : sqrt(3) Now if we find the pairwise minimum in 2nd array we will get : sqrt(2) We will return the minimum of two which is sqrt(2) and also the correct answer. Please correct me if i understood your 1st point wrong and provide a test case that you have in mind where this greedy algorithm fails ? Coming to your second point. In order for the divide and conquer approach to work in O(NLogN) time : - you must sort the array according to x (to find the partition line in constant time). Here you can use the input array to store the result. - you must also sort the array according to y coordinate for finding minimum distance between 14 (or 7) adjacent coordinates in the region of length 2(delta) in linear time. So you will require ~O(N) extra space. Note that, if you don't do this preprocessing step, you will need to sort the 14 (or 7) points in every recursive call, which actually makes the time complexity of this algorithm as O(N(LogN)^2) Hence, your algorithm takes ~O(N) space complexity as well Coming to your third point, i would say that the problem can have a maximum of 3 dimensions (x,y,z) in which case, we will sort the list according to all 3 coordinates and compute the minimum among 3, similar to what i did for 2-D. Not sure how this divide and conquer approach would scale to higher dimensions so can't comment on that. Hope this clarifies any issues !

    • @hazardousgamer6935
      @hazardousgamer6935 2 หลายเดือนก่อน

      ​@@RealRyanRadFrom you reply, i can see that you are doubting the correctness of the greedy algorithm. Like for ex if i take closest pair of points to be diagonally placed as you stated in your reply, let's say : (3,6), (3,3), (4,4) (4,8) Then we sort it according to x we will get : (3,3), (3,6), (4,4), (4,8) Then we sort it according to y we get : (3,3), (4,4), (3,6), (4,8) Now if we find the pairwise minimum in 1st array we will get : sqrt(3) Now if we find the pairwise minimum in 2nd array we will get : sqrt(2) We will return the minimum of two which is sqrt(2) and also the correct answer. Please correct me if i understood your 1st point wrong and provide a test case that you have in mind where this greedy algorithm fails ? Coming to your second point. In order for the divide and conquer approach to work in O(NLogN) time : - you must sort the array according to x (to find the partition line in constant time). Here you can use the input array to store the result. - you must also sort the array according to y coordinate for finding minimum distance between 14 (or 7) adjacent coordinates. Here you will require another ~O(N) extra space. Note that, if you don't do this preprocessing step, you will need yo sort the 14 (or 7) points in every recursive call, which actually makes the time complexity of this algorithm as O(N(LogN)^2) Hence, your algorithm takes ~O(N) space complexity as well Coming to your third point, i would say that the problem can have a maximum of 3 dimensions (x,y,z) in which case, we will sort the list according to all 3 coordinates and compute the minimum among 3 similar to what i did for 2-D. Not sure how this divide and conquer approach would scale to higher dimensions so can't comment on that. Hope this clarifies any issues !

    • @hazardousgamer6935
      @hazardousgamer6935 2 หลายเดือนก่อน

      From you reply, i can see that you are doubting the correctness of the greedy algorithm. Like for ex if i take closest pair of points to be diagonally placed as you stated in your reply, let's say : (3,6), (3,3), (4,4) (4,8) Then we sort it according to x we will get : (3,3), (3,6), (4,4), (4,8) Then we sort it according to y we get : (3,3), (4,4), (3,6), (4,8) Now if we find the pairwise minimum in 1st array we will get : sqrt(3) Now if we find the pairwise minimum in 2nd array we will get : sqrt(2) We will return the minimum of two which is sqrt(2) and also the correct answer. Please correct me if i understood your 1st point wrong and provide a test case that you have in mind where this greedy algorithm fails ? Coming to your second point. In order for the divide and conquer approach to work in O(NLogN) time : - you must sort the array according to x (to find the partition line in constant time). Here you can use the input array to store the result. - you must also sort the array according to y coordinate for finding minimum distance between 14 (or 7) adjacent coordinates. Here you will require another ~O(N) extra space. Note that, if you don't do this preprocessing step, you will need yo sort the 14 (or 7) points in every recursive call, which actually makes the time complexity of this algorithm as O(N(LogN)^2) Hence, your algorithm takes ~O(N) space complexity as well Coming to your third point, i would say that the problem can have a maximum of 3 dimensions (x,y,z) in which case, we will sort the list according to all 3 coordinates and compute the minimum among 3 similar to what i did for 2-D. Not sure how this divide and conquer approach would scale to higher dimensions so can't comment on that. Hope this clarifies any issues !

  • @PeterAkwood
    @PeterAkwood 2 หลายเดือนก่อน

    I've been using built-in sorts for years without questioning them. Thanks for such amazing and original content. Subscribed and looking forward to more algorithm deep dives!

    • @RealRyanRad
      @RealRyanRad 2 หลายเดือนก่อน

      Glad to help! Thanks for letting me know!

  • @Planner-William
    @Planner-William 2 หลายเดือนก่อน

    This video completely changed how I think about choosing sorting algorithms. Great content! Thanks for breaking it down in such an easy-to-understand way.

    • @RealRyanRad
      @RealRyanRad 2 หลายเดือนก่อน

      Great to hear! Thanks for letting me know!

  • @PatrickGilmartin-m4m
    @PatrickGilmartin-m4m 2 หลายเดือนก่อน

    Aren't there 8 points not 6? Four in the middle (one bordering the midpoint line from both sides on both the top and bottom of the strip, and two on each respective side. Like this --> : :|: :). We need to look at 7 points when doing so, not 5.

    • @RealRyanRad
      @RealRyanRad 2 หลายเดือนก่อน

      Thank you for your thoughtful question and the neat visualization (: :|: :)! - Remember, δ is the smallest distance we've found so far. Any two points closer than δ would have been caught in our earlier comparisons. - Consider a 2δ x δ rectangle centered on our dividing line. We can think of this as two δ x δ squares side by side. - In a single δ x δ square, we can fit at most 4 points (one in each corner) without any pair being closer than δ. - However, when we combine two such squares (forming 2δ x δ rectangle centered on our dividing line), we can't maintain 4 points in each square without violating our δ distance. Here's why: o If we try to place 4 points around the dividing line (2 on each side), these points would be closer to the other points on the far left and right corners than δ, contradicting our assumption. o We can only have points exactly on the dividing line, not slightly to the left or right. If we placed points at (x-ε) or (x+ε) even where ε is very very small, they would still violate the δ distance with other points in their respective squares. It's a common misconception, but the maximum is indeed 6 points, not 8. Finally, 6 or 8, there will be still constant number of points to check int he worst case scenario in each strip so the complexity of the solution remains about the same.

  • @nitsanbh
    @nitsanbh 3 หลายเดือนก่อน

    You don’t write Python for speed. Don’t make your Python code not readable for negligible questionable performance benefits

  • @HhddGufif
    @HhddGufif 3 หลายเดือนก่อน

    I've heard the sm platforms are very bloated but 500ms of processing sounds extreme.

  • @driesvanheeswijk1633
    @driesvanheeswijk1633 3 หลายเดือนก่อน

    This video was awesome! Seriously very good quality presentation man! Keep making content like this and more people will find you in no time!

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Appreciate your kind words! Glad you liked it.

  • @modimihir
    @modimihir 3 หลายเดือนก่อน

    Subscribed you for this. Please keep such videos that discuss fundamental concepts and applications, looking forward to it!

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Thanks for subscribing! I'm glad you found the video helpful. Definitely, more content is on the way!

  • @nelinotakam2621
    @nelinotakam2621 3 หลายเดือนก่อน

    I like that. I just got into leetcode due to BLE interactions I've been implementing in React Native. The few milliseconds of gain are actually impressive! Even on the mobile side, you have a more robust and consistent UI experience. The goal is always to fine-tune your algorithm for the lowest end devices. Thank you for this video. My next question is what recommendation would you give me if my goal is to consistently do these kinds of tests when I'm trying to compare the performance of different algorithms against each other?

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Thank you for sharing your experience! It's great to hear that you're seeing tangible benefits from optimization in your React Native work. You're absolutely right - even small gains can significantly improve the user experience, especially on lower-end devices. Regarding your question, here are some recommendations: - Use Python's timeit module: This built-in module is designed for small code snippet timing. It's great for comparing different implementations of algorithms. - Create a benchmarking suite: Develop a set of test cases with various input sizes and types. This helps ensure your algorithms perform well across different scenarios. - Utilize profiling tools: Python's cProfile can give you detailed information about function calls and time spent in different parts of your code. - Implement unit tests with performance assertions: Set upper bounds for execution time in your unit tests to catch performance regressions. - Use realistic data: Test with data that closely resembles what you'd encounter in production for more accurate results. - Consider memory usage: Use tools like memory_profiler to track memory consumption alongside execution time. - Automate your tests: Integrate performance tests into your CI/CD pipeline to catch performance issues early. - Visualize results: Use libraries like matplotlib to create graphs of performance across different input sizes or conditions. - Be consistent with your testing environment: Always run your tests on the same machine under similar conditions for comparable results. - Don't forget about worst-case scenarios: Make sure to test edge cases that might lead to poor performance. I hope these suggestions help!

  • @nelinotakam2621
    @nelinotakam2621 3 หลายเดือนก่อน

    Some. glitches in your video. Fix those. This is great content

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Thanks for pointing this out, I've fixed them.

  • @RealRyanRad
    @RealRyanRad 3 หลายเดือนก่อน

    Link to the Experiment Code - Simultaneous Min/Max vs Built-in: colab.research.google.com/drive/17gEgmvQOyQJDTyJoRP-vkoMbUUInFg9o?usp=sharing

  • @Planner-William
    @Planner-William 3 หลายเดือนก่อน

    Great video! The constant factor optimizations shown in this video are exactly the kind of things that separate good Python developers from great ones. Keep up the excellent content!

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Appreciate your kind words!

  • @rockenOne
    @rockenOne 3 หลายเดือนก่อน

    It python champ, there is no point optimising your code for performances. Anything of substance happens in the packages you import.

  • @PeterAkwood
    @PeterAkwood 3 หลายเดือนก่อน

    This content is fantastic! It's very informative and well-explained. Your channel is a hidden gem.

    • @RealRyanRad
      @RealRyanRad 3 หลายเดือนก่อน

      Glad you liked it. Much appreciated!

  • @davidyang4022
    @davidyang4022 4 หลายเดือนก่อน

    Very comprehensive introduction to LLMs! It helped me create a clear roadmap for when to use specific LLM techniques.

    • @RealRyanRad
      @RealRyanRad 4 หลายเดือนก่อน

      Thanks a lot, David! Glad you liked it.

  • @pritiyadav9375
    @pritiyadav9375 4 หลายเดือนก่อน

    Very well put and informative course! Looking forward to a course on RLHF.

    • @RealRyanRad
      @RealRyanRad 4 หลายเดือนก่อน

      Thanks a lot. Glad it was helpful.

  • @RealRyanRad
    @RealRyanRad 4 หลายเดือนก่อน

    Full Code: colab.research.google.com/drive/1w7O7es8s_L3LWw85Y-i0DuxH9YzHEyvY?usp=sharing

  • @Planner-William
    @Planner-William 4 หลายเดือนก่อน

    Great Content! Thanks for packing so much value into a concise video. Looking forward to more content like this!

    • @RealRyanRad
      @RealRyanRad 4 หลายเดือนก่อน

      More to come! Glad you enjoyed it!

  • @Planner-William
    @Planner-William 4 หลายเดือนก่อน

    Wow, this video is exactly what I've been looking for! As someone trying to break into the AI field, I've heard so much about LLMs but struggled to find a comprehensive yet accessible explanation.

    • @RealRyanRad
      @RealRyanRad 4 หลายเดือนก่อน

      Glad it helped!

  • @Planner-William
    @Planner-William 5 หลายเดือนก่อน

    Thanks for the great content! The visuals and examples were super helpful. Gonna try this out on my customer segmentation data.

  • @MissPiggyM976
    @MissPiggyM976 10 หลายเดือนก่อน

    Interesting! Please. more videos on this topic!

  • @Planner-William
    @Planner-William 10 หลายเดือนก่อน

    Where was this video when I was studying LP? This was the most productive 20 minutes I have ever spend learning Linear Programming! THANK YOU!

  • @Chengyan_Tan
    @Chengyan_Tan 11 หลายเดือนก่อน

    This is so much better than reading textbook

  • @likai0822
    @likai0822 11 หลายเดือนก่อน

    Concise, Easy to Understand and Amazing!

    • @RealRyanRad
      @RealRyanRad 11 หลายเดือนก่อน

      Glad it was helpful!

  • @HichamElKaissi-g4s
    @HichamElKaissi-g4s ปีที่แล้ว

    Thanks 🙏🏼

  • @Planner-William
    @Planner-William ปีที่แล้ว

    The best explanation for this problem! Thanks a lot!

  • @rajan-u6b
    @rajan-u6b ปีที่แล้ว

    awesome video bro, thanks

  • @learn4free864
    @learn4free864 ปีที่แล้ว

    good explanation

  • @YedianCheng
    @YedianCheng ปีที่แล้ว

    👍

  • @walker_sean
    @walker_sean ปีที่แล้ว

    Wow, Ryan your editing and set up are really pro level. Rendering time is totally worth it.