Heap Sort

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 65

  • @farhadnoori8546
    @farhadnoori8546 9 років тому +120

    amusing and effective explanation - learned it in O(1). Thank you

  • @paanparag01
    @paanparag01 8 років тому +4

    One of the best video series on the topic. I call it an art to be able to explain complex concepts and definitions with ease and and add a pinch of humor as well.
    David this is awesome!!

  • @anishmalhotra9575
    @anishmalhotra9575 8 років тому +2

    This channel really is algorithms with attitude! You keep me awake with all those not-so-subtle jokes. But besides that thank you so much, you've really helped me in not only catching up in my data structures class, but also in getting ahead! Thank you!

  • @ArtremKost
    @ArtremKost 9 років тому +35

    "like a fart in the storm" :) Man you are great!

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  9 років тому +12

      +Artem Aleksandrovich Kost Thought I could slip that one by without anybody noticing...

    • @ArtremKost
      @ArtremKost 9 років тому

      Just like a fart during a storm :) By the way great explanation 

    • @hangchen6131
      @hangchen6131 7 років тому

      I spit my coffee again

    • @perpetualtom6649
      @perpetualtom6649 6 років тому

      fucking amazing

    • @elysel9424
      @elysel9424 4 роки тому +1

      lmaoooo. i wish all of my professors are like him

  • @lakshaylegspin
    @lakshaylegspin 9 років тому +3

    Visually effective while not skipping the analysis part. This is amazing.

  • @ziliestarrive
    @ziliestarrive 5 років тому +5

    "All those moments will be lost in time, like farts in storm."

  • @RunItsTheCat
    @RunItsTheCat 8 років тому +1

    Love how concise these are.

  • @brandonbryant9914
    @brandonbryant9914 9 років тому +4

    Our college would literally hire you if you applied for a job. You're HEAPS and bounds better than the professors here who have their doctorates

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  9 років тому +8

      +Brandon Bryant
      Thank you, though I suspect I wouldn't be hired so easily: it is pretty hard to get a professorship, each of your professors was probably chosen out of 100+ applicants. Crazy, right? Hopefully that will insulate their egos should one of them see this comment (or you could delete it).
      Mildly interesting fact: UA-cam classified your comment as probable spam, probably because of the word "hire". Also, these videos are significantly more organized than my real-life lectures.

  • @aminelagab4830
    @aminelagab4830 9 років тому +1

    thank you verry much Mr , the heaps are not a problem anymore .

  • @kalaja72
    @kalaja72 8 років тому +1

    fantastic video !

  • @codeisawesome369
    @codeisawesome369 5 років тому

    Who the F dislikes these amazing resource videos!

  • @DianaEvergreen
    @DianaEvergreen 9 років тому

    Thanks you, very charismatic explanation!

  • @bilalabdu5733
    @bilalabdu5733 8 років тому +1

    Nice explanation. thanks

  • @ninnschroll2479
    @ninnschroll2479 8 років тому +1

    Great videos, man! :D

  • @brunospasta
    @brunospasta 7 років тому +1

    I like this guy ; )
    Thanks for your videos

  • @theworldeatswithyou
    @theworldeatswithyou 7 років тому +1

    This has been very helpful.

  •  8 років тому +1

    Really helpful! Thank you very much :)

  • @arwag9951
    @arwag9951 9 років тому +1

    Thank u so much!! That was very useful

  • @johnriley1324
    @johnriley1324 8 років тому

    Good Video, Really Helped =)

  • @kalujny
    @kalujny 8 років тому +2

    Amazing! Simple short and fun.
    P.S. where's the attitude? :D

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  8 років тому +1

      Seems like I should insult the snot outta you here, just to answer that question, right?

    • @kalujny
      @kalujny 8 років тому +1

      Naaa I`m good. Keep em coming.

  • @himelsarkar137
    @himelsarkar137 8 років тому +2

    100Thanks

  • @kumariyamala6499
    @kumariyamala6499 6 років тому

    You use delete max which has space of o(logn) because of recursive calls but it is o(1)

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  6 років тому

      Kumari Yamala If maxHeapify is coded iteratively, or with tail recursion that the compiler optimizations unwind (probably pretty standard now, though I am not a compiler guy), it takes Theta(1) space, and O(lg n) time. The recursive version, without tail recursion optimization would take, worst case, Theta(lg n) space.

  • @loremipsumproductivityengi7552
    @loremipsumproductivityengi7552 7 років тому

    Can you explain the difference between siftUp vs siftDown and when they are used?

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  7 років тому

      In a MaxHeap, siftUp is for when an element might be larger than its parent, and might have to move up one (or more) levels. When you insert, you stick the new element as the last leaf, but maybe it is bigger than its parent and grandparent, so it needs to move up.
      siftDown would be for when an element is in danger of being smaller than one of its children. When deleting the maximum element at the root, when you swap the last leaf into its place, that element is likely not the new max element in the heap, so it probably has to move down within the heap, maybe many levels.

    • @loremipsumproductivityengi7552
      @loremipsumproductivityengi7552 7 років тому

      Algorithms with Attitude So this means siftUp is usually called during insertion while siftDown is usually called during deletion after the root and last leaf swapped. Is this a correct interpretation of this?

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  7 років тому

      Yes. siftDown is also called during the linear-time build-heap operation, and if you allow keys to arbitrarily be changed, either can be called there, depending on if the key gets larger or smaller.

  • @xucanwang1458
    @xucanwang1458 9 років тому +1

    awsome!!Thank u

  • @argiromarioli4917
    @argiromarioli4917 5 років тому

    The video is great but I'm a little taken aback by the speaker facing the other way

  • @mueslibrah
    @mueslibrah 9 років тому +1

    Thanks

  • @davidjames1684
    @davidjames1684 3 роки тому

    I tried implementing this but I got myself into a heap of trouble.

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  3 роки тому

      I hope you were able to sort it out.

    • @davidjames1684
      @davidjames1684 3 роки тому

      @@AlgorithmswithAttitude Good one. Actually, many years ago, I did implement heapsort, and instead of just plucking off the largest element, I grabbed the 2 largest (root and larger child), and both myself and someone else (he implemented it too), saw about a 2% to 3% speedup overall. I called it "double pop" heapsort, since it is "popping" 2 elements each "pass".

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  3 роки тому +1

      @@davidjames1684 If you go into my heaps playlist, you one of the videos is on optimization. By changing the way that maxHeapify works, you can nearly cut your expected comparisons in half, which should give you a much bigger speed up (though not 50%).

    • @davidjames1684
      @davidjames1684 3 роки тому

      @@AlgorithmswithAttitude I wonder what happens if you try both.

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  3 роки тому

      @@davidjames1684 I think if you are talking about small changes in efficiency, you need to make sure that big issues are handled first. So here, where I show items swapping during maxHeapify? That isn't the efficient way to do it, even if you do want to compare an item against its children while moving down. It is likely more efficient to copy the item elsewhere, do your comparisons moving things up (without copying the first item during that process), and only have one copy at the end. I would not expect popping two items at once to be better, in that both will usually go back down to the near bottom of the heap, but will do so on different paths, ending up in different parts of the heap.
      Obviously, I don't know how you implemented your double pop, but what savings could it give you? If, without comparing the root to its children, you check which child is bigger and one of the pops goes there, you are basically saving one of the the comparisons that the optimization in the other video already saves. That one comparison per two pops might save you a small amount of time, but it would already be saved with the other optimization.

  • @Bizorke
    @Bizorke 8 років тому

    Isn't quicksort n^2, worst case?

    • @AlgorithmswithAttitude
      @AlgorithmswithAttitude  8 років тому

      +Bizorke It is, but it's expected runtime is faster than heapsort. Do I say otherwise? Please post a time in the video.

    • @Bizorke
      @Bizorke 8 років тому

      Algorithms with Attitude No. Sorry my mistake - I was only considering the worst case and not the average case.
      Thanks for the response.

  • @himelsarkar137
    @himelsarkar137 8 років тому +2

    "100Thanks"

  • @AwesomeComputerTricks
    @AwesomeComputerTricks 8 років тому

    thanks sir

  • @Herotruth
    @Herotruth 8 років тому +6

    your avatar is scary

  • @dilraj8842
    @dilraj8842 4 роки тому

    Im not that far right hahaha