Which Sorting Algorithm Should You Use?

Поделиться
HTML-код
  • Опубликовано: 30 сен 2024

Комментарии • 63

  • @frozen_dusk579
    @frozen_dusk579 3 года назад +36

    You should make a video about Big O notation, because it's a topic that is hard to understand but important!

  • @KaroCodes
    @KaroCodes 3 года назад +12

    Why don't we worry about HeapSort? Is HeapSort ok? Someone check on them please! 😭

    • @maxsuelfernandes3016
      @maxsuelfernandes3016 3 года назад

      HeapSort is the most beautiful sorting algorithm in the world lololo

    • @rodrigoqteixeira
      @rodrigoqteixeira 5 месяцев назад

      Heapsort is an in place n log n worst case algorithm. It really should have been in the test

  • @Caucasian_Shepherd
    @Caucasian_Shepherd 3 года назад +7

    Time complexity is one thing, runtime is another thing. Out of all sorting algorithms, heapsort has the best time and space complexity - O(nlogn) and O(n) (it's an in-place algorithm, meaning we don't even need to create a new array). However, it's runtime is not as great as those of the merge sort and quick sort.
    Quick sort has the fastest average runtime, and even though its worst case behavior is dreadful (the worst case scenario is when the array is in a sorted or reverse sorted order), 1. It's highly unlikely that large arrays will be in sorted orde, 2. It can be optimized in my ways to avoid these worst-case scenarios, e.g. by combining it with other algorithms like insertion sort which is an ideal algorithm for sorted or nearly sorted lists.
    Also, it is proven that any algorithm that uses *comparisons* must have an O(nlogn) time complexity. However, that doesn't refer to algorithms that use other methods. Hence, potentially there might be a linear sorting algorithm, we just haven't found it.

  • @y2kona
    @y2kona 3 года назад +13

    sort by most based to least based

    • @m.a.t.a.s
      @m.a.t.a.s 3 года назад +1

      Debase currency!

    • @y2kona
      @y2kona 3 года назад

      @@m.a.t.a.s yes

  • @AbdullahAhmed-xz8sm
    @AbdullahAhmed-xz8sm 3 года назад +4

    Very helpful video. I briefly learned about the Bubble Sort and Merge Sort I believe last semester in high school which was a long time ago.

  • @harivag30
    @harivag30 3 года назад +3

    Tbh I use the one I don't understand😂

  • @sez5435
    @sez5435 3 года назад +1

    array.sort((a, b) => a - b) ez pz

  • @mohammedj2941
    @mohammedj2941 3 года назад +1

    At the risk of being annoyingly pedantic, I want to mention that the nlogn bound only applies to comparison-based sorting. Linear-time average-case sorting does exist, such as the radix sort.

  • @user-dh8oi2mk4f
    @user-dh8oi2mk4f 3 года назад +1

    Obviously bogosort is the fastest.

  • @gianbattistalorenzato1481
    @gianbattistalorenzato1481 3 года назад +3

    Very interesting topic, in my opinion there's a lot of things to take in account when we talk about sorting algorithms like time, space complexity, if there's a divide & conquer approach which requires recursion, if we can use an algorithm efficient for a specific type of elements to compare, if the sorting algorithm uses comparisons or not...
    In any case it depends on what we are reaching 😂👍

    • @KaroCodes
      @KaroCodes 3 года назад +3

      Yeah as someone who always tries to optimise for memory (embedded and mobile devices) I'd love to see a space complexity focused analysis 😁

  • @maddy3656
    @maddy3656 3 года назад +2

    Thank you for this! It would be great if you could do some videos about Spring Boot, I like how you explain stuff. ☺️🤩

  • @cody_codes_youtube
    @cody_codes_youtube 3 года назад +1

    You know, these sort of things are mostly academic I've found in my career. It's rare that you're put in a situation where you are sorting stuff in memory. I feel like there is too much focus on this stuff in algo exercises. Big-O notation is good to know though

  • @chrisdrakeford8742
    @chrisdrakeford8742 3 года назад +2

    Great video man! Cant believe how much I learnt about sorting algorithms in only 8 mins. Great job! love the videos!

  • @josemartinfriasaguirre8393
    @josemartinfriasaguirre8393 3 года назад +2

    bogo sort is the best sorting algorithm, it can sort in the first try

    • @realtechhacks
      @realtechhacks 3 года назад

      Very true. It could also sort on the 500 quadrillionth try.

  • @jfftck
    @jfftck 3 года назад +2

    I would add that using the built-in sort will give better performance over time since the implementation may change, like Java switching to TimSort from Merge sort. This is the power of abstraction on display and why libraries are preferred over writing from scratch.

  • @dharmaraj-8I624
    @dharmaraj-8I624 3 года назад +2

    Bogosort xD

  • @Pmills9
    @Pmills9 3 года назад +1

    Lol I got the same shirt from h&m

  • @ginimastic3002
    @ginimastic3002 3 года назад +1

    Technically sorting algorithm "by comparison" cannot be faster than nlgn. But algorithm that are not comparison-based can be faster than nlgn

  • @artiartem
    @artiartem Месяц назад

    this video is really casual. Not so interesting.

  • @maxsuelfernandes3016
    @maxsuelfernandes3016 3 года назад +1

    Idk why, but heap sort is my favorite sorting algorithm. Such an amazing video btw

  • @gabormaster1989
    @gabormaster1989 3 года назад +1

    Very nice video, love your explanation. Keep posting this tip of videos, or curses

  • @malicious8909
    @malicious8909 3 года назад

    BogoSort (unbounded). All day every day.

  • @marzanchowdhury5291
    @marzanchowdhury5291 3 года назад +1

    Best place to learn algorithms and data structures?

  • @rohanrao6351
    @rohanrao6351 3 года назад +1

    Great video as usual! Concise and informative.
    Would love to see this one expanded by adding multithreading into the mix, and see what kind of speedups can be achieved (if any) based on input size (maybe a parallel bubble sort with 1M elements would've finished in reasonable time).

    • @KaroCodes
      @KaroCodes 3 года назад +2

      This is such a great idea! Would love to see that too 🙏

    • @stallenricherthisyear2961
      @stallenricherthisyear2961 3 года назад

      @@KaroCodes hello karo help me open up trading coding robot

  • @Shaqqed
    @Shaqqed 3 года назад +1

    pretty interesting video, thanks for the info

  • @TheoEkman
    @TheoEkman 10 месяцев назад

    If I am unsure of what algorithm to use in larger projects, I tend to go for merge sort for 2 reasons. 1. Stable, even though you may not need a stable sorting algorithm, it grants opportunities in the future. 2. No need to worry about worst cases. You will have the same time complexity regardless on how the list is sorted. This means that your application will run smoothly, and it's much easier to test from a performance point of view.

  • @bendakai1
    @bendakai1 Год назад

    Nice video. However it's unfair to compare merge sort and quick sort when the underlying data structure is array. I want to see how things turned out if the underlying data structure is linked list.

  • @nivedmorts
    @nivedmorts 2 года назад

    Can you post the code you used for the sorting algorithms for this video? I made my own tests comparing selection sort and merge sort and the merge sort ran faster in every test. tests included array of 1 int, array of 2 ints, array of 7 ints, and one array of 10,000 random ints. Merge was always faster. So Im guessing I did something wrong...

  • @willemsmart760
    @willemsmart760 3 года назад

    You forgot the absolute best sorting algorithm:
    radix sort, with a time complexity of O(n)
    It only catches up with quick sort and merge sort after like 1 million elements but is really the way to go for HUUUUUGE lists

  • @phillipgoat00
    @phillipgoat00 3 года назад

    what I like about this channel is the educational content. Most programming channels are about selling me courses (algo expert *cough cough8) or people flexing muscles telling about how successful they are, which is useless content to me.

  • @ordinaryshiba
    @ordinaryshiba 3 года назад

    Everyone knows the best sorting algorithm is bogosort. I mean does any other algorithm have a slight but non zero chance of using only ONE operation on ANY array?

  • @realtechhacks
    @realtechhacks 3 года назад

    Next could you explain the RUclips algorithm? It's giving me trouble.

  • @abhishekm3752
    @abhishekm3752 3 года назад +1

    RUclips algorithm

  • @TheAcousticEngineer
    @TheAcousticEngineer 2 года назад

    Great content, very educational. Quick question:
    Were all the sorting algorithms applied on the same array of random numbers for a given input size, or were they random arrays for each sort algo?

  • @elliottstech310
    @elliottstech310 3 года назад

    Spend all that time learning this, and then get into web develop and haven't used it in the last 9 years....

  • @hawksvk1711
    @hawksvk1711 3 года назад

    A bit disappointing that you did not mention warmup cycles when measuring the performance.

  • @mohitganorkar3364
    @mohitganorkar3364 3 года назад

    Talk about github Co pilot

  • @stallenricherthisyear2961
    @stallenricherthisyear2961 3 года назад

    Hello help me on coding

  • @dailydoseofhalal6767
    @dailydoseofhalal6767 3 года назад +2

    first?

  • @wesleymarques2468
    @wesleymarques2468 5 месяцев назад

    good video

  • @agnesakne4409
    @agnesakne4409 2 года назад

    is best case time complexity of quick sort not n?

  • @vamsi_Krishna0_0
    @vamsi_Krishna0_0 10 месяцев назад

    Thanks dude you made it simple and clear.

  • @mythicaldata6297
    @mythicaldata6297 3 года назад

    Bogosort ftw

  • @iliyasamine6483
    @iliyasamine6483 3 года назад

    Now do it in HTML
    Now kill me please, I can afford all the masacre tools JUST DO IT

    • @realtechhacks
      @realtechhacks 3 года назад

      53 large metal rakes @23 dollars a piece -> $1219 + 45 scythes @35 dollars each -> 1535 + 110 torches @ 5 dollars each -> $550 == $3344.
      Now I think it would be best if you also payed for lunch. We are assuming a group of around 100 rioters here so that could cost a couple thousand. Let's say after all expenses...... Just go ahead and pay me $7000. An I'll arrange the massacre.

  • @procode6881
    @procode6881 3 года назад

    Highly knowledgeable

  • @ellmango
    @ellmango 2 года назад

    nice video!