Priority Queue Introduction

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024

ความคิดเห็น • 102

  • @sunnilabeouf
    @sunnilabeouf 4 ปีที่แล้ว +86

    Every time I come back to refresh my memory on an algorithm or data structure, I get excited when I see that you have a video covering it. Thank you for the animations and teaching in such a clear way!

  • @forresthopkinsa
    @forresthopkinsa 3 ปีที่แล้ว +31

    pro tip: playback speed 2x

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

      I also did that

  • @scottzeta3067
    @scottzeta3067 2 ปีที่แล้ว +6

    I love the is this a valid heap section, very useful. Newbies like me often have many “stupid questions” like these, but hardly find answers.

  • @demansou88
    @demansou88 2 ปีที่แล้ว +13

    Been reviewing some concepts for a FAANG interview and your videos are the best for clear and concise review of data structures

  • @sword013
    @sword013 4 ปีที่แล้ว +33

    What a beautiful animation, my eyes were on my laptop cause the colour combination was so good to watch.

  • @BookofYAH777
    @BookofYAH777 2 ปีที่แล้ว +6

    I don't think 7:35 is a heap because it's not a tree. In order for it to be a tree, I think each child can have only 1 parent

  • @slashtab
    @slashtab 2 ปีที่แล้ว +1

    This is what I was looking, How PQ and heap is related and was getting confused b/w these two. Can't thank you enough.

  • @taylorgerrish7264
    @taylorgerrish7264 5 ปีที่แล้ว +52

    this is awesome! thanks for asking questions testing us so we can try to answer it instead of just giving the answer

  • @J235304204
    @J235304204 5 ปีที่แล้ว +27

    I really liked all the example heaps.

  • @quocbao6046
    @quocbao6046 4 ปีที่แล้ว +9

    I learned your Graph Theory Course to this part and I didn't understand PQ so I come here to learn it. I enjoy the way you teach with the animation and other stuffs very much. Thanks
    man!!

  • @AbdullaNabeel
    @AbdullaNabeel 2 ปีที่แล้ว +8

    @7:15, arent heaps always represent a binary tree but with structural ordering?

  • @clashclan4739
    @clashclan4739 2 ปีที่แล้ว +1

    Wow! more in depth videos on balancing tree and tree rotation implementation pls

  • @olivierkoster
    @olivierkoster 4 ปีที่แล้ว +22

    actually, a heap also needs to be a complete binary tree. so the 3rd example is in fact not a heap.

    • @sandeepbhuiya4497
      @sandeepbhuiya4497 4 ปีที่แล้ว +1

      that's Correct

    • @HamidBazargani
      @HamidBazargani 4 ปีที่แล้ว +8

      That's the definition of binary heap. So completeness is not necessary for a heap.

  • @anujonthemove
    @anujonthemove 2 ปีที่แล้ว +1

    In short: I subscribed to you channel!

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

    Thank you! I couldn't find any other video on this topic

  • @miriyalajeevankumar5449
    @miriyalajeevankumar5449 4 ปีที่แล้ว +3

    Golden content

  • @benleung6331
    @benleung6331 5 ปีที่แล้ว +10

    By your definition, a heap is a tree. However, one of the differences between a tree and a graph is that in a tree, every child can only have one parent, and yet in 7:34, the node with 6 in the third level has two parents (one a 3 and ther other is also 6), so it can't be a tree but it is a heap?

    • @WilliamFiset-videos
      @WilliamFiset-videos  5 ปีที่แล้ว +6

      Yeah, that example is questionable. Although I still maintain that the whole structure is a tree because there are no cycles. What I should have done is made the edges directed so that there is no ambiguity regarding which node is the parent/child of which.

    • @subbuktek
      @subbuktek 5 ปีที่แล้ว +1

      Why do you think the other '6' is a parent? ...

    • @benleung6331
      @benleung6331 5 ปีที่แล้ว +2

      @@subbuktek Because the diagram put the other '6' as one level above, the same reason that the '3' on level 2 is a parent. I know what you are alluding to, if you can assume the '6' on level 2 is a child instead of a parent, you can also assume the '3' is a child, not a parent, in that case it still can't be a heap

  • @namangupta2587
    @namangupta2587 4 ปีที่แล้ว +1

    the best video so far....nice explanation

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

    Are the edges bidirectional? I would think they only go in one direction and that displaying the edges vertically or diagonally implies a direction from the higher node to the lower node. So, assuming the edges are directional, breaking with the convention of displaying the directions from top to bottom would mean we should display them as arrows instead of lines.

  • @spicyshizz2850
    @spicyshizz2850 10 หลายเดือนก่อน +1

    7:44 but two things are pointing to the same node?

  • @mosiurrahman4061
    @mosiurrahman4061 2 ปีที่แล้ว

    Clear and Conceptual

  • @sarthakshah1058
    @sarthakshah1058 6 ปีที่แล้ว +6

    These videos are very well made and helpful

  • @AdrianMei
    @AdrianMei 5 ปีที่แล้ว +8

    what is best first search? (same as breadth first search?)

    • @Charlesthebird1
      @Charlesthebird1 4 ปีที่แล้ว +4

      Best first search isn't an algorithm - it's a category of algorithms which require the next-best item or thing in the data structure (where "best" is determined by a weight or a number) at each iteration (A* does this to find the next "best" movement choice for pathfinding in a graph, but the other algorithms he mentions find the next "best" choice in their respective implementations as well)

  • @umairalvi7382
    @umairalvi7382 3 ปีที่แล้ว +2

    Heaps are complete binary tree or almost complete binary tree
    But you didn't mention it

    • @MGtvMusic
      @MGtvMusic 3 ปีที่แล้ว

      He said they don't need to be binary trees right?

    • @sultanahmed9694
      @sultanahmed9694 3 ปีที่แล้ว

      I think that he made fault when validating trees mentioned in this video, I think some of them are not complete binary trees so they are not heap, since heap must be a complete binary tree

  • @shaygahhendricks
    @shaygahhendricks 4 ปีที่แล้ว +4

    ok but the way he asked if 7 was a heap and said "yeah, it's a heap" :')

  • @fatimaadreeta
    @fatimaadreeta 2 ปีที่แล้ว +1

    Binary trees have at most two children, right? Not more than two. But can also have 0 or 1 child. Like showed in the max heap diagram at 6:12

    • @georgiyordanov4407
      @georgiyordanov4407 2 ปีที่แล้ว

      When implementing, every node/element of the binary tree has a value, and two pointers. These two pointers can either point to another node (which is under the current node) or to nothing. So they can technically have 0 children, but they always have two pointers, which are both pointing to nothing.

  • @brunoserras
    @brunoserras 6 ปีที่แล้ว +2

    Fantastic video! Keep up the good work.

  • @natanshimeles1116
    @natanshimeles1116 2 ปีที่แล้ว

    Heap is a complete tree, but you are referring the opposite

  • @francois-xaviermenage4531
    @francois-xaviermenage4531 2 หลายเดือนก่อน

    Is that always lawful to change the root of the heap?

  • @onomatopeia891
    @onomatopeia891 2 ปีที่แล้ว

    Great explanation! Thanks!

  • @cathyliu9900
    @cathyliu9900 2 ปีที่แล้ว

    Is the heap a complete binary tree? At 7'17", the heap is not a complete binary tree.

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

    Thank you very much

  • @isaacdouglas1119
    @isaacdouglas1119 4 ปีที่แล้ว +1

    4:05 If two elements in the priority queue have the lowest value in the queue, doesn't that mean the number polled from the queue isn't necessarily the smallest number in the queue?

    • @AJewFR0
      @AJewFR0 3 ปีที่แล้ว

      No. This example is not how it would be implemented. In a binary tree, the order would be as his examples towards the end of the video demonstrate. You can have two nodes with the same value (priority), where they might be a child of the node that is removed. The node that is left over, would then bubble up and take the place of the just removed node.

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

    Very good video! thanks

  • @codeschool3964
    @codeschool3964 2 ปีที่แล้ว

    Shouldn't a tree be a complete tree for it to become a heap? The second example you gave is not a complete tree right? Correct me if I'm wrong please.

    • @codeschool3964
      @codeschool3964 2 ปีที่แล้ว

      th-cam.com/video/wptevk0bshY/w-d-xo.html at here

  • @snowybutt
    @snowybutt 5 ปีที่แล้ว +10

    9:40 you mean BREADTH first search, not BEST first search, right?

    • @nikhilk7493
      @nikhilk7493 5 ปีที่แล้ว

      best is correct

    • @Charlesthebird1
      @Charlesthebird1 4 ปีที่แล้ว +1

      Best first search isn't an algorithm - it's a category of algorithms which require the next-best item or thing in the data structure (where "best" is determined by a weight or a number) at each iteration (A* does this to find the next "best" movement choice for pathfinding in a graph, but the other algorithms he mentions find the next "best" choice in their respective implementations as well)

  • @orangekitty5192
    @orangekitty5192 2 ปีที่แล้ว

    great stuff, who needs a CS degree?

  • @kirankumar2348
    @kirankumar2348 3 ปีที่แล้ว

    bro heaps are complete binary trees right.....

  • @SK-cs1by
    @SK-cs1by 2 ปีที่แล้ว

    Still you didn’t clear main concept on priority Queue

  • @shaozhetang75
    @shaozhetang75 6 ปีที่แล้ว +7

    May I ask a question? when you took an example of what a priority queue is and the instruction asked us to add 2,4,5,9,
    WHY these numbers were not added with the poll operation?

    • @WilliamFiset-videos
      @WilliamFiset-videos  6 ปีที่แล้ว

      Shaozhe Tang I'm not sure I correctly understand your question. Could you please rephrase it? Thank you.

    • @shaozhetang75
      @shaozhetang75 6 ปีที่แล้ว +1

      Yeah, from 3:35 we can see the instruction and take poll and add operations. Firstly poll() we get 1, secondly add (2) we get 2, thirdly poll() you said it happened to be 2 not 3?....
      I watched the video again and realized it was because the pink circle didn't pop up with the arrow at the same time, but now I understood it. Thank you very much for your reply! your video is very good!

    • @WilliamFiset-videos
      @WilliamFiset-videos  6 ปีที่แล้ว +4

      Oops, sounds like a timing delay! Sorry for the confusion.

    • @pooja9587
      @pooja9587 5 ปีที่แล้ว +1

      Polling means deleating not adding

  • @haykeelili8108
    @haykeelili8108 2 ปีที่แล้ว

    Thank you!

  • @YogeshDarji99
    @YogeshDarji99 5 ปีที่แล้ว

    Thanks for explaining concepts nicely!

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

    do you have a code on that circles

  • @Cool.couple.channel
    @Cool.couple.channel 3 ปีที่แล้ว

    can u tell me what is heap invariant??

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

    deserve our prof's salary

  • @Mai-qr6hj
    @Mai-qr6hj 5 ปีที่แล้ว +3

    I love your voice

  • @wellwell8025
    @wellwell8025 2 ปีที่แล้ว

    Thanks!!!

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

    nice 😊👍 thanks

  • @michaeldang8189
    @michaeldang8189 4 ปีที่แล้ว

    4:21 "As human we can see the numbers visually inside the priority queue, and look and know what one is the smallest to poll".
    Actually not quite, if we have 1 million numbers in the queue, human will have a tough time identifying the number to poll just as an inefficient programmed machine does.

  • @prabhassla4237
    @prabhassla4237 2 ปีที่แล้ว

    Grt explNtion

  • @GURUYATHI
    @GURUYATHI 5 ปีที่แล้ว

    Thank you very much for making this video.!

  • @spicytuna08
    @spicytuna08 6 ปีที่แล้ว +3

    7:16 i thought you said heap tree only applies to binary tree. this one has 3 branches. Great animation.

    • @benleung6331
      @benleung6331 5 ปีที่แล้ว +9

      He actually said heap isn't *necessarily* a binary tree, with heaps that are not implemented as binary tree, they are called binomial heap (as opposed to binary heap)

  • @shangluntsai6787
    @shangluntsai6787 6 ปีที่แล้ว

    Nice explanation, thank you

  • @sashank3
    @sashank3 3 ปีที่แล้ว

    The complexity for building a heap isn't correct. It takes 'O(nlog(n))' to build a heap, because you are doing 'n' additions.Same would go for a priority queue too.

  • @romankorniienko2388
    @romankorniienko2388 5 ปีที่แล้ว

    u r best!11!

  • @zihanbayeed42
    @zihanbayeed42 4 ปีที่แล้ว

    7:39 doesn't a heap have to be a perfect tree too?

    • @kalebnegussie8140
      @kalebnegussie8140 4 ปีที่แล้ว

      Yes exactly. The branching factor for this heap is 3 so we cannot have nodes with just 2 children or ne child.

    • @Dazaromal
      @Dazaromal 4 ปีที่แล้ว

      It does not have to be a perfect tree, the heap simply must be filled from left to right, if you have nodes with children then the next two nodes over at that height have no children and children respectively then that is not a valid heap. Branching factor only affects where you will start your buildHeap method whether that may be max or min, for instance if you had a heap with 3 child nodes the point at which the last possible node with children would be at will be floor of heapSize/3 (ROUGHLY) depending if were talking pseudo code and the starting index is 1 or actual code at 0.

    • @AJewFR0
      @AJewFR0 3 ปีที่แล้ว

      A heap does not have to be a binary tree. It's typically implemented in this way though. I think that's where the confusion comes from. Although the idea of it being a perfect tree makes me think you misunderstand the heap idea. It doesn't have to be perfect (or even complete). It just has to follow the heap invariant.

  • @huseyinmesecan9161
    @huseyinmesecan9161 5 ปีที่แล้ว

    i thought in a binary heap nodes have only one or two children nodes. 7:14min

    • @cloud5887
      @cloud5887 4 ปีที่แล้ว +1

      It’s not a binary heap, it’s just a regular heap. Only binary heaps must satisfy the requirement with up to 2 children

  • @prabhassla4237
    @prabhassla4237 2 ปีที่แล้ว

    *1 2 3 4 4 5 9 8 14 22* _isn't this what first answer should be...

  • @shaleen0mishra
    @shaleen0mishra 2 ปีที่แล้ว

    Watch at 1.25x

  • @littlem5771
    @littlem5771 5 ปีที่แล้ว

    Priority queue != queue with priority im thinking?

    • @anon6975
      @anon6975 5 ปีที่แล้ว +1

      A queue is usually understood like an ordered list. A priority queue is a kind of list where it's structured so you can get things marked with a more important "priority" faster and easier. Heaps are a good way to think about implementation, but they can be implemented a number of ways.

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

    You sound like MoistCritikal before he got into chain smoking

  • @sase1017
    @sase1017 4 ปีที่แล้ว

    Play at lest 1.25 speed, but great content

  • @raceallen1569
    @raceallen1569 2 ปีที่แล้ว

    4:50

  • @lowochi
    @lowochi 5 ปีที่แล้ว +2

    Neat video. I'm not sure I liked your example tho.

  • @rohanramani6243
    @rohanramani6243 4 ปีที่แล้ว

    Like if you are here for a Dijkstra assignment

    • @cocoshady3469
      @cocoshady3469 3 ปีที่แล้ว

      Do you have the code of that with priority queue? 🤔

  • @professordrabhijitsayamber2299
    @professordrabhijitsayamber2299 2 ปีที่แล้ว

    Om shanti k

  • @SantoshKumar-bu2qr
    @SantoshKumar-bu2qr 5 ปีที่แล้ว +2

    1.5x

  • @Lynkor
    @Lynkor 5 ปีที่แล้ว

    bad
    i still like you as a person though