Data Structures: Heaps

Ғылым және технология

Learn about heaps. This video is a part of HackerRank's Cracking The Coding Interview Tutorial with Gayle Laakmann McDowell. www.hackerrank.com/domains/tut...

Пікірлер: 456

  • @cron93
    @cron935 жыл бұрын

    If you're trying to write this code in Python, beware: You cannot simply assign items[0] = items[self.size - 1]. You must pop() the item at the end of the list to remove it: items[0] = items.pop() ... also be sure to use floor division in the parent calc if using Python 3: (index - 1) // 2

  • @harshitm6403
    @harshitm64034 жыл бұрын

    Storing the heap in the form of an array just blew my mind...so effective

  • @theinverteddonkey2961

    @theinverteddonkey2961

    2 жыл бұрын

    it's really a tree in the form of a list of nodes

  • @typingcat

    @typingcat

    2 жыл бұрын

    Damn, if that blows your mind, your mind most be blown multiple times a day.

  • @davidlee588

    @davidlee588

    2 жыл бұрын

    @@typingcat haha, i'm also been wondering why people easily got blown away by simply KZread videos, it must be like an ejaculation moment for them. 😂

  • @vectoralphaAI

    @vectoralphaAI

    2 жыл бұрын

    @@typingcat mine is. There is so much to learn every day. My mind is blown on a daily basis. Its great because im never bored.

  • @hamzahkhan878

    @hamzahkhan878

    Жыл бұрын

    what in the hell we were you thinking of if that blew your mind? lol

  • @WorklLife
    @WorklLife6 жыл бұрын

    This is one of Gayle Laakmann's best videos. She walks us through the code, array, and tree versions while speaking calmly in a pleasant voice. Thank you!

  • @Saztog1425
    @Saztog14253 жыл бұрын

    3:22 "Aaand there we go, we've created Minecraft!"

  • @AlanD20

    @AlanD20

    3 жыл бұрын

    EXACTLYYYY 😂😂😂

  • @octamodius
    @octamodius5 жыл бұрын

    Clean implementation. Clean explanation. Wonderful video! Thank you very much for taking the time to make this. I really needed it!

  • @harshwardhankoushik8515
    @harshwardhankoushik85155 жыл бұрын

    The explanation with the code is amazzing !! loved it....seems that would work for me! Please continue with the good work

  • @BeginningProgrammer
    @BeginningProgrammer4 жыл бұрын

    This is a really nice explanation of min heaps.... Very nice, very clear, very simple , concise and short enough to pick up in a jiffy. Thanks Gayle.

  • @murnoth
    @murnoth Жыл бұрын

    I am translating these lessons for use in Unreal Engine Visual Blueprints, and Gayle delivers these lessons very cohesively. Thank You!

  • @kiaksarshirvanimoghaddam4354
    @kiaksarshirvanimoghaddam43543 жыл бұрын

    I always had problems understanding heaps, but you made it so clear. Thank you so much ...

  • @LeaFox
    @LeaFox7 жыл бұрын

    I read about heaps online and first implemented it using a right and left Node. I felt array, though - spidey senses. I wish I would have seen it on my own. But, this video was a close second. Thank you so much for a clear description.

  • @sherazdotnet
    @sherazdotnet2 жыл бұрын

    Just an FYI: At 3:01 timeframe, you are showing formulas and for pareint you have [Index -2) / 2]. This needs to be change dto index -1 * 2. On next screen where you are coding it, you have it right.

  • @Pazushh

    @Pazushh

    2 жыл бұрын

    I think it shouldv'e been (Index-1)/2. while "/" rounds to bottom

  • @calviethang7139

    @calviethang7139

    2 жыл бұрын

    You are right!

  • @SupunNimantha

    @SupunNimantha

    2 жыл бұрын

    Actually that equation is not for the immediate parent of any given node but it gives you the min node (top most node ). Instead of saying parent she should have told its the min. There she made a mistake. At the same time actually there is no need to have that equation because simply the 0th element is always the min.

  • @dennisfolz352

    @dennisfolz352

    Жыл бұрын

    @@SupunNimantha no you are wrong. The formula (index-1)/2 returns the parent for any given node. And it is important, because you need the parent of any given node if you want to heapify up. ^^

  • @santjagocorkez

    @santjagocorkez

    7 ай бұрын

    @@SupunNimantha You could do the maths yourself: take the 9 at #3. Its parent is 4 at #1. Now let's compute: (3 - 2) / 2 = 0 (floor div). Oopsie, 9 at #3 has the root as its parent, while we know from the picture it's not.

  • @technowey
    @technowey3 жыл бұрын

    Thanks you for this excellent video. It''s the best, most concise and straightforward, explanation of a heap that I've seen.

  • @JOJOSHgaming7514
    @JOJOSHgaming75143 жыл бұрын

    Thanks a lot, Madam. I've been burning out myself scrolling numerous websites not getting how a heap actually works and how it's implemented, and now finally implemented successfully in C#.

  • @johnkimura5585
    @johnkimura55856 жыл бұрын

    Her keyboard clicks are the most satisfying sound

  • @RobsRobotChannel

    @RobsRobotChannel

    5 жыл бұрын

    ASMR, wikipedia it.

  • @ivanleon6164

    @ivanleon6164

    3 жыл бұрын

    hate it.

  • @himanshusingh5118

    @himanshusingh5118

    3 жыл бұрын

    😂😂😂 irritating

  • @sanjayvasnani988

    @sanjayvasnani988

    2 жыл бұрын

    Nah. It seems as if her keyboard hates being used by her.

  • @NilakshMalpotra

    @NilakshMalpotra

    2 жыл бұрын

    Agreed! Lovely sound

  • @guadalupevictoriamartinez4537
    @guadalupevictoriamartinez45373 жыл бұрын

    I forgot this channel existed. It saved me once again

  • @akhiljain1695
    @akhiljain16954 жыл бұрын

    I was searching for something just like this. Awesome explanation of implementation of heap.

  • @AlexXPandian
    @AlexXPandian3 жыл бұрын

    Best video explanation with code walkthrough showing how to answer the ubiquitous lazy interviewer question "Implement a Heap data structure".

  • @CamdenBloke
    @CamdenBloke5 жыл бұрын

    Pro tip: if your array is indexed at 1 (like with Fortran) the pointers are parent: (index-1)/2, left child:2*index, right child:2*index +1

  • @xMercuryx56

    @xMercuryx56

    2 жыл бұрын

    that's not pro, that's just math ... lmfao

  • @MrJakson112
    @MrJakson1122 жыл бұрын

    Having that visual next to the code is such a godsent, thank you for saving my bachelors degree

  • @m2rafik
    @m2rafik5 жыл бұрын

    Most of coders strugles to use complex abstract data structures like heaps or graphs because they dont learn it from a concrete use case.

  • @sarvasvarora

    @sarvasvarora

    3 жыл бұрын

    +1 for this. Doing an intro to CS course at uni rn and def if it wasn't for the coding assignments involving practical usr cases, I would've never appreciated such data structures... It's certainly very important to actually implement them in some use case in order to grasp them well.

  • @stas4985

    @stas4985

    3 жыл бұрын

    why the hell graphs or heaps complex???

  • @axea4554

    @axea4554

    3 жыл бұрын

    @@stas4985 because they are more complex than a simple non-resizable array or a linked list

  • @programmercouple
    @programmercouple3 жыл бұрын

    This is the best explanation of Heap. Thanks 🙌🏻

  • @PsyKosh
    @PsyKosh7 жыл бұрын

    Possible error around 2:52 The diagram shows the parent as (index-2)/2, when it should be (index-1)/2

  • @g.o.4678

    @g.o.4678

    7 жыл бұрын

    I believe that calculation takes the ceiling (or whole integer value rounded up, depending on the programming language) of the operation. So, for instance, to get the parent of the node at index 7, we'd have: ceiling((7-2)/2) = ceiling(5/2) = ceiling(2.5) = 3, which is the appropriate index we're looking for.

  • @arvinsim

    @arvinsim

    7 жыл бұрын

    Gbenga Ojo

  • @DimaKurguzov

    @DimaKurguzov

    7 жыл бұрын

    Your are right. (index-2)/2 for parent index is a mistake. Look the code at 3:22 - here is the correct version (index-1)/2.

  • @quangthang10d4

    @quangthang10d4

    7 жыл бұрын

    Yes I was gonna say the same thing!

  • @josevillegas2721

    @josevillegas2721

    7 жыл бұрын

    In python 2, / is integer division and it truncates the result so 5/2 = truncate(2.5) = 2

  • @NathanSowatskey
    @NathanSowatskey6 ай бұрын

    The calculation shown in the cartoon diagram to get the parent of the node is shown as (index-2)/2. In the code the calculation is (index-1)/2.

  • @alicianieto2822
    @alicianieto28224 жыл бұрын

    The video is awesome and what I needed to know. Thank you!

  • @eddiet279
    @eddiet2797 жыл бұрын

    Very clear. Even more clear than the book actually.

  • @enkhboldochirbat3578
    @enkhboldochirbat35784 жыл бұрын

    This is best explanation of BST on basic concepts.

  • @Thunder117
    @Thunder1173 жыл бұрын

    This is the most helpful code video i have ever seen

  • @AshfaqAhmed05
    @AshfaqAhmed052 жыл бұрын

    such an amazing explanation with clean code. Loved it!!!

  • @beingyourself9824
    @beingyourself98246 жыл бұрын

    Today I actually understand how coders actually codes and how to actually maintain the semantics of variables name fabulous explanation I sub you within 1 minutes of this video

  • @principlesoflife172
    @principlesoflife1727 жыл бұрын

    This is awesome explanation and you are awesome.

  • @ManuelRochaCR
    @ManuelRochaCR7 жыл бұрын

    I completely ignored about heaps. Nice explanation. Thanks!

  • @heldermelendez61
    @heldermelendez612 жыл бұрын

    Well done, Gayle. Thank you.

  • @tritrinh568
    @tritrinh5687 жыл бұрын

    Didn't know HackerRank has itself a KZread channel. Subscribed! :)

  • @VideosOfEarth
    @VideosOfEarth5 жыл бұрын

    I didn't know until now the God of programming is on youtube! Thank you ma'am! 🙏

  • @salman8562

    @salman8562

    4 жыл бұрын

    goddess

  • @paoloparker8991
    @paoloparker89917 жыл бұрын

    Thank you very much miss! Awesome lesson!

  • @johndubchak
    @johndubchak5 жыл бұрын

    Thank you, Gayle. I enjoyed your explanation and found the visual and code helpful.

  • @xXmayank.kumarXx
    @xXmayank.kumarXxАй бұрын

    Heaps can be thought of as a binary tree. Peek takes O(1) while other operations take O(log n). For min heap: 1) Insert new node at last, then heapify (ie swap with parent until parent > child) 2) Delete the root node, replace last element at root then heapify (ie swap down)

  • @SavageScientist
    @SavageScientist2 жыл бұрын

    Bringing back memories of my Data Structures course Shini book it was actually good

  • @gauravmaithani4707
    @gauravmaithani47073 жыл бұрын

    best vid ever... thanks McDowell.

  • @lolipopscandy62
    @lolipopscandy627 жыл бұрын

    How does this not have more views?? What a simple, and amazing explanation. Subscribed!!!

  • @palanisamymadakkannu4350

    @palanisamymadakkannu4350

    6 жыл бұрын

    only entertainment videos ll get more views.. useful videos wont get..😊

  • @intrepidsouls

    @intrepidsouls

    5 жыл бұрын

    Agree with you. I watched quite a lot of her videos and it seems like she doesn't quite understand what she is talking about either.

  • @blasttrash

    @blasttrash

    5 жыл бұрын

    @@intrepidsouls I agree too. Her book is good though.

  • @thatoneuser8600

    @thatoneuser8600

    3 жыл бұрын

    Because it doesn't answer why heaps are used or when one should use them. It doesn't give a perfect concrete use-case where a heap would always be beneficial if used.

  • @SicariusVIII
    @SicariusVIII5 жыл бұрын

    Really have to appreciate the readability of the code a variables.

  • @rock53355
    @rock533553 жыл бұрын

    I've basically watched every one of her videos before starting the chapter in my book on the topic

  • @kimberlycaritas
    @kimberlycaritas5 жыл бұрын

    SO helpful - thank you so much!

  • @Brlitzkreig
    @Brlitzkreig Жыл бұрын

    Excellent explanation

  • @chaptersdiversified2940
    @chaptersdiversified29402 жыл бұрын

    This is the best explanation I've seen :) ty!

  • @anwarshaikh6023
    @anwarshaikh60237 жыл бұрын

    Very nice explanation. Though including big O complexity of the operations would be great.

  • @BryanTidwell2

    @BryanTidwell2

    7 жыл бұрын

    Anwar Shaikh insertion and removal should be logarithmic. of course poll is constant and search is linear but you wouldn't want to use the structure for search

  • @damnstupidoldidiot8776

    @damnstupidoldidiot8776

    5 жыл бұрын

    It should be O(nlog(n)).

  • @uusoft

    @uusoft

    4 жыл бұрын

    time complexity O(nlog(n)) space complexity O(1)

  • @drophy

    @drophy

    3 жыл бұрын

    Insertion and removal have a time complexity of O(log(n)), where 'n' is the number of nodes in the heap. This is because for example, during insertion, in the worst case scenario, you'll need to move the inserted element from the bottom all the way up. Therefore, the max number of swaps is the height of the tree, which is log2(n) approximately (note that this is just true if the tree is balanced, but they always are for heaps). For example, her tree had 10 nodes at some point, a height of 3 (or 4, depending on how you define 'height') and log2(10) = 3.32. The max number of swaps you might need when inserting is 3. The same idea applies for removal, since the element you place at the top might need to go all the way down. The space complexity of the structure is O(n), of course, since you need an array of size 'n'. The space complexity of the 2 operations, however, is indeed O(1), since they don't need additional space.

  • @mvcds92
    @mvcds927 жыл бұрын

    The video feels incomplete because it never explains what a heap is used for, though the data structure very well.

  • @jimmithfarrel8986

    @jimmithfarrel8986

    7 жыл бұрын

    A heap is used as a queue where the min (or max if max heap) is always accessed in O(1) time. If the min (which is always at index 0 is popped off, then the next smallest takes its place. Remember its stored linearly yet indexed logarithmically. Therefore its a "priority" queue.

  • @mvcds92

    @mvcds92

    7 жыл бұрын

    Yeah, I've googled it afterward, though it's kind of you helping me here, thanks!

  • @musicprod8366

    @musicprod8366

    6 жыл бұрын

    Thank you : )

  • @xNajda

    @xNajda

    6 жыл бұрын

    What's the difference then between a heap data set and just a normal ordered data set using a binary search for the placing of each new element?

  • @sumitbhattacharya1720

    @sumitbhattacharya1720

    6 жыл бұрын

    go read a book then.

  • @AlexandruRepede
    @AlexandruRepede7 жыл бұрын

    this is useful for priority queues

  • @tamoorhamid519

    @tamoorhamid519

    4 жыл бұрын

    That's one application.

  • @jadanabil8044

    @jadanabil8044

    3 жыл бұрын

    @@tamoorhamid519 what are the other applications?

  • @tamoorhamid519

    @tamoorhamid519

    3 жыл бұрын

    @@jadanabil8044 They can be used to efficiently find the largest or smallest value in an array.

  • @julieh4488
    @julieh44886 жыл бұрын

    Great explanation of heaps

  • @dvvdsvsd
    @dvvdsvsd7 жыл бұрын

    I have final exam tomorrow, after this explanation, if this will be my pick, I know I'm safe. Amazing videos!

  • @utkarsh_108

    @utkarsh_108

    4 жыл бұрын

    Best of luck

  • @ShermanSitter

    @ShermanSitter

    4 жыл бұрын

    I don't have an exam, but i found it useful as well! I don't know why, but heaps were so confusing...until now! :)

  • @ShermanSitter

    @ShermanSitter

    3 жыл бұрын

    @Chris Chu Learns ah shucks. thank you!

  • @kenansari

    @kenansari

    3 жыл бұрын

    how it was?

  • @Itskfx

    @Itskfx

    Жыл бұрын

    Same, I'm terrible at heaps. These vids help a lot!

  • @santoshsco
    @santoshsco2 жыл бұрын

    Super clear explanation .

  • @timdick5149
    @timdick51493 жыл бұрын

    excellent work!

  • @nyahhbinghi
    @nyahhbinghi Жыл бұрын

    Not sure if she explains this clearly but keeping the array operations to O(1) is probably accomplished via using swaps, where the indices to be used by the swap are found in O(1) by using parent/left/right references?

  • @quoctrung2610
    @quoctrung26107 жыл бұрын

    This is so simple and easy to understand. A+++++++++++++++++++

  • @LY-up3qr
    @LY-up3qr3 жыл бұрын

    Very good explanation!

  • @exatiqurrahman3116
    @exatiqurrahman31166 жыл бұрын

    Except a small mistake this video is a great resource in understanding heap data structure. Thank you. :)

  • @ontimegrad7069
    @ontimegrad70692 жыл бұрын

    Thanks for the video! But I am a bit confused about the smallerChirld at around 10 min. Should the left child always be the smaller one?

  • @manojkanduri1823
    @manojkanduri18235 жыл бұрын

    Curious how rightChild, leftChild hasParent english syllabuls used here are actually implemented when we are dealing with arrays :) May be doable but will turn brain teaser. I guess one would prefer to use classes at that point. In any case this video is worthwhile and very relevant. Thank you Gayle.

  • @tiffany831101
    @tiffany8311014 жыл бұрын

    Amazing explanation!!!

  • @michaeldang8189
    @michaeldang81895 жыл бұрын

    hasParent method should be simplified to: hasParent(int index) {return index > 0}

  • @randomrandom316

    @randomrandom316

    4 жыл бұрын

    Its quite clever

  • @brianspinos

    @brianspinos

    3 жыл бұрын

    Nice!!!

  • @DanielAzevedo94
    @DanielAzevedo944 жыл бұрын

    Awesome explanation. Healped me a lot. Thank you.

  • @lilypad5182
    @lilypad51822 жыл бұрын

    For heapingDown, what if instead of the left child being swapped, the right child was being swapped, and the new node would get bubbled down to a place that exceeds the size? then the heap will no longer be compact and there would be empty spots, no? So we'd need additional implementations to take care of this case

  • @colorfulcodes
    @colorfulcodes6 жыл бұрын

    Thanks for this.

  • @DominicVictoria
    @DominicVictoria5 жыл бұрын

    What overhead will you get from an array of class?

  • @DanielSincAlexandru
    @DanielSincAlexandru4 жыл бұрын

    I didn't figure it out how main should look like. Could you give me some tips? Thank you! Keep up the good work!

  • @rushabhajain3977
    @rushabhajain3977 Жыл бұрын

    Excellent explanation :)

  • @aadil4236
    @aadil42362 жыл бұрын

    Great and concise

  • @satyam_dey
    @satyam_dey2 жыл бұрын

    When I clicked on this video I had no idea I'd be learning from the legend herself. Damn.

  • @Amolang991
    @Amolang9912 жыл бұрын

    After you poll(), shouldn't you remove the element at `items[size - 1]`?

  • @finn5571
    @finn55717 жыл бұрын

    For deleting a node, is there any issue with just not moving the last node up and bubbling up the smaller child of the empty node until there are no children, and then moving the remaining indices left by 1? Is it less efficient, does it cause any problems, or is it just that we want to heapify down since we already have that method for other purposes anyway?

  • @dmitrybahtiarov3555
    @dmitrybahtiarov35552 жыл бұрын

    There is error at 2:56, parent is (index - 1 ) / 2 Or otherwise for left node we get (parent -1) instead of parent. Everything else is just brilliant, thank you for the Great Explanation! 💓

  • @Itskfx

    @Itskfx

    Жыл бұрын

    Noticed that too, but I think they corrected that in their code implementation. lmk if I'm wrong cause I'm here for exam revision and I'm kinda weak at heaps.

  • @aanchalsharma8362
    @aanchalsharma83623 жыл бұрын

    Why do I relate to that node that is all empty inside! xD

  • @ariefsetiawan3516
    @ariefsetiawan35162 жыл бұрын

    Easy to understand!

  • @ronitdhingra4395
    @ronitdhingra43954 жыл бұрын

    That was great , could you also post an explanation of Iterative Heap Sort algorithm this simple way!!

  • @rajivkumarkale
    @rajivkumarkale3 жыл бұрын

    Concise and crisp

  • @farithd2042
    @farithd20423 жыл бұрын

    Note: formula for getting parent index, in the diagram is different from the actual formula used in the code. In Diagram - Wrong, In code - Correct

  • @ophir1982
    @ophir19827 жыл бұрын

    Possible error at 1:54 the algorithm is said to be swapping with the smallest of the 2 child elements (when bubbling down) So 20 is swapped with 4, then the pointer is swapped with 9 (left child) while the right child is 7 - smaller.

  • @nopenope8409

    @nopenope8409

    5 жыл бұрын

    1 year later but that is not correct because what you see there is already swapped so there was 4 before the swap and 20 took the place of 4 and then took the place of 9. there isn't an error

  • @devinebug
    @devinebug11 күн бұрын

    What is the time and space complexity ? And what are the effective use cases for min/max heap?

  • @comosehaceyt
    @comosehaceyt3 жыл бұрын

    Thank you :D

  • @v.audioslave
    @v.audioslave7 жыл бұрын

    is it book in russian on the table behind Gayle? :)

  • @esa2236
    @esa22366 жыл бұрын

    So in this array, the entire time the last subscript will be empty? I ask because when you add a new value to the heap you first put it in the last space in the array then you increment right after.

  • @sachinmagdum
    @sachinmagdum3 жыл бұрын

    Method hasParent will return true for root node as well. Because for rootIndex =0, getParent will return 0, because (0-1)/2 = 0. Hence, use of hasParent at line #55 has no effect. To fix this, hasParent can simply return true for all nodes if their index > 0.

  • @jimgetsjob9551
    @jimgetsjob95512 жыл бұрын

    so simple to impliment, just paste these blocks of code and *BAM* it probably does stuff but good luck explaining it on an interview

  • @wong7642
    @wong76424 жыл бұрын

    may i ask, is it true that the array index will always start from 1 for the root in the heap? but your video said it will start from 0? Thank you !

  • @RachelWho
    @RachelWho2 жыл бұрын

    Minor mistake, at 8:23 instead of comparing the indexes of the left and right children, you should be comparing their values to get the smaller child!

  • @adityamedhe

    @adityamedhe

    2 жыл бұрын

    that's not minor

  • @maheshnampoothirikv5080
    @maheshnampoothirikv50806 жыл бұрын

    We need to have one more line in the "poll()" method, correct me if I am wrong. I used the starting example (after inserting 3 as new value to heap) to test the same. int item = items[0]; items[0] = items[size - 1]; items[size - 1] = 0;//We need to make the last element zero explicitly as the last element will stay otherwise. size--;

  • @dishantsheth9592

    @dishantsheth9592

    5 жыл бұрын

    The "size" variable maintains the boundary of the heap in the array and so there isn't a necessity to take care of elements with index >= size in the array. Also, "items[size-1] = 0" doesn't achieve the same result as assigning a dynamic node in a tree to null. Here, it simply gets assigned a value of 0. To help with understanding, consider the pop operation in the static implementation of a stack. The popped values remain in memory after pop but not in the stack because of the "TOP" pointer there. Similarly here, size keeps track of the boundary of the heap to help with add and poll operations.

  • @persianhenry2897
    @persianhenry28975 жыл бұрын

    How can I insert String objects to the Heap if it is an Array? Or should I use and ArrayList

  • @benjaminbirchman3732
    @benjaminbirchman3732 Жыл бұрын

    Great video thank you

  • @jonasgrnbek7113
    @jonasgrnbek71134 жыл бұрын

    That butterfly keyboard sound 😕

  • @yogendrapawar1738
    @yogendrapawar17389 ай бұрын

    Her way of writing the code... thats impressive

  • @moelayo
    @moelayo7 жыл бұрын

    In the heapifyUp() function why do you have to reassign index = getParentIndex(index) when the swap function does that for you

  • @chinmayrao3831
    @chinmayrao38314 жыл бұрын

    0:06 i forgot it just after 2mins watching this video, and so watched again🤐

  • @whiskas-1
    @whiskas-1 Жыл бұрын

    There is an animation on 1:49 which not reflects the actual logic of the heap sink down ( accordingnaly to the idea of swaping with smallest child node when bubbling down )

  • @Nickel80
    @Nickel804 жыл бұрын

    The video should also talk about the run time complexity of the functions implemented

  • @wotizit

    @wotizit

    3 жыл бұрын

    should O(nlogn) worst case

  • @supportteam2007
    @supportteam20077 жыл бұрын

    Correct me if I am wrong but I think that adding 1000 (or any number greater than 7) and then adding 5 (or 6 or 7 as well) to the heap example at 3:00 would result in an error if the heapfyUp() code provided further in the video is used. Namely, the top node would be the second number added (5 or 6 or 7) which would be greater than the left hand side child.

  • @bigbangind

    @bigbangind

    7 жыл бұрын

    I don't think so

  • @supportteam2007

    @supportteam2007

    7 жыл бұрын

    Me neither. haha I guess I wasn't paying too much attention.

  • @arthuran4361
    @arthuran43613 жыл бұрын

    very good pseudo-codes.

  • @cron93
    @cron935 жыл бұрын

    Also, what happens if you pass 0 as an index into parent()? You'll get back -1 from getParentIndex since (0-1)//2 == -1, and then you'll get an "index out of bounds error" in some languages or worse, you'll get the last item in the list in python!

  • @kafychannel
    @kafychannel Жыл бұрын

    yes I got everything thank s a lot !

  • @motaaaa
    @motaaaa5 жыл бұрын

    Nice explanation

  • @acymiranda
    @acymiranda4 жыл бұрын

    I don't know, but is getParent(index) correct? If I get the final heap of the example, like: [10, 15, 20, 17, 25] and I add an element in the end, for example, 32 and it would be below 17, so 17 is 32 parent. 32 index is 5. 17 index is 3. If we use getParent(5), I would have: (5 - 1) / 2 => 4 / 2 = 2 But index 2 is not 17, but 20... Am I missing something here?

  • @dmitrybahtiarov3555

    @dmitrybahtiarov3555

    2 жыл бұрын

    There is error at 2:56, parent is (index - 1 ) / 2 and not (index - 2) / 2

Келесі