Priority Queue Introduction

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

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

  • @sunnilabeouf
    @sunnilabeouf 4 года назад +90

    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!

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

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

  • @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.

  • @sword013
    @sword013 4 года назад +34

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

  • @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.

  • @forresthopkinsa
    @forresthopkinsa 3 года назад +51

    pro tip: playback speed 2x

  • @J235304204
    @J235304204 5 лет назад +27

    I really liked all the example heaps.

  • @taylorgerrish7264
    @taylorgerrish7264 6 лет назад +52

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

  • @quocbao6046
    @quocbao6046 5 лет назад +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!!

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

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

  • @BookofYAH777
    @BookofYAH777 2 года назад +14

    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

    • @emmanuelnsiah8036
      @emmanuelnsiah8036 14 дней назад

      this is a tree. look at it carefully every parent has child in it.

  • @namangupta2587
    @namangupta2587 5 лет назад +1

    the best video so far....nice explanation

  • @benleung6331
    @benleung6331 6 лет назад +12

    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  6 лет назад +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 лет назад +4

      @@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

  • @miriyalajeevankumar5449
    @miriyalajeevankumar5449 4 года назад +3

    Golden content

  • @AbdullaNabeel
    @AbdullaNabeel 3 года назад +8

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

    • @rhl_
      @rhl_ 2 месяца назад

      Heap need to be always binary tree. They can be ternary also.

    • @mahinhossen4251
      @mahinhossen4251 24 дня назад

      he missed some facts also. Heap needs to be complete binary tree. He called some of them heap while they weren't complete bt

  • @clashclan4739
    @clashclan4739 2 года назад +1

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

  • @spicyshizz2850
    @spicyshizz2850 Год назад +1

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

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

    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 года назад +1

      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.

  • @anujonthemove
    @anujonthemove 2 года назад +1

    In short: I subscribed to you channel!

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

    Clear and Conceptual

  • @sarthakshah1058
    @sarthakshah1058 6 лет назад +6

    These videos are very well made and helpful

  • @brunoserras
    @brunoserras 7 лет назад +2

    Fantastic video! Keep up the good work.

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

    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.

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

    Great explanation! Thanks!

  • @olivierkoster
    @olivierkoster 5 лет назад +24

    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.

  • @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 4 года назад

      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 2 года назад

    Very good video! thanks

  • @AdrianMei
    @AdrianMei 6 лет назад +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)

  • @francois-xaviermenage4531
    @francois-xaviermenage4531 7 месяцев назад

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

  • @dorktales254
    @dorktales254 2 месяца назад

    Is the video slowed down?

  • @codeschool3964
    @codeschool3964 2 года назад +1

    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 года назад

      ruclips.net/video/wptevk0bshY/видео.html at here

  • @shaygahhendricks
    @shaygahhendricks 4 года назад +4

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

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

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

  • @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

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

    do you have a code on that circles

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

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

  • @Cool.couple.channel
    @Cool.couple.channel 4 года назад

    can u tell me what is heap invariant??

  • @subee128
    @subee128 9 месяцев назад

    Thank you very much

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

    great stuff, who needs a CS degree?

  • @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.

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

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

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

    Thank you!

  • @YogeshDarji99
    @YogeshDarji99 6 лет назад

    Thanks for explaining concepts nicely!

  • @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 4 года назад

      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.

  • @tangtanghouse4399
    @tangtanghouse4399 7 лет назад +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  7 лет назад

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

    • @tangtanghouse4399
      @tangtanghouse4399 7 лет назад +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  7 лет назад +4

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

    • @pooja9587
      @pooja9587 6 лет назад +1

      Polling means deleating not adding

  • @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 6 лет назад +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)

  • @huseyinmesecan9161
    @huseyinmesecan9161 6 лет назад

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

    • @cloud15487
      @cloud15487 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

  • @SK-cs1by
    @SK-cs1by 3 года назад

    Still you didn’t clear main concept on priority Queue

  • @GURUYATHI
    @GURUYATHI 5 лет назад

    Thank you very much for making this video.!

  • @Mai-qr6hj
    @Mai-qr6hj 6 лет назад +3

    I love your voice

  • @shangluntsai6787
    @shangluntsai6787 6 лет назад

    Nice explanation, thank you

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

    deserve our prof's salary

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

    Thanks!!!

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

    nice 😊👍 thanks

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

    Grt explNtion

  • @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.

  • @lang-disa
    @lang-disa 6 лет назад

    u r best!11!

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

    Instead of asking me questions, you could have explained the time complexities better!

  • @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.

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

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

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

    4:50

  • @Manlikerik8
    @Manlikerik8 7 месяцев назад

    You sound like MoistCritikal before he got into chain smoking

  • @sase1017
    @sase1017 4 года назад

    Play at lest 1.25 speed, but great content

  • @lowochi
    @lowochi 5 лет назад +2

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

  • @rohanramani6243
    @rohanramani6243 5 лет назад

    Like if you are here for a Dijkstra assignment

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

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

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

    Watch at 1.25x

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

    Om shanti k

  • @SantoshKumar-bu2qr
    @SantoshKumar-bu2qr 5 лет назад +2

    1.5x

  • @Lynkor
    @Lynkor 5 лет назад

    bad
    i still like you as a person though