I have learnd more in 8 min with you than 2 h in the university.
@playanakobi44073 жыл бұрын
agree. it's so different when they explained first why you're doing this than focusing on how to do it.
@superannoymous57313 жыл бұрын
True, GOD! it is frustrating when my lecturer would give us homework first before explaining which make the whole thing pointless.
@maxdemian63122 жыл бұрын
this
@jkrigelman2 жыл бұрын
Or is it because you already learned it for two hours and it's easier with a new visual explanation it makes sense now? 🤔 I'm visual so it may be the video.😁
@horaciomlhh Жыл бұрын
Different styles make people learn more!
@BrianOSheaPlus Жыл бұрын
This is a good explanation. It's also worth mentioning that the time complexity of this algorithm is log(n) for inserts and deletes. For example, when you add a new node, it will only have to be swapped at most log(n) times, where n is the total number of nodes in the tree.
@NachitenRemix Жыл бұрын
Yeah, log(n) is basically the depth (amount of rows) of the heap, so that makes sense.
@alpharudiger11937 ай бұрын
@@dominiquefortin5345 isnt he finding it by having a counter in every node?
@dominiquefortin53456 ай бұрын
@@alpharudiger1193 No he keeps 2 in each nodes. One for the right subtree and one for the left subtree. Not very efficient.
@nguyentrieta3 жыл бұрын
At 4:25, I think the insertion is wrong. We always add it to the leftmost en.wikipedia.org/wiki/Binary_heap#Insert
@vorun3 жыл бұрын
Agree! Insertion is wrong.
@znacloudznacloud85682 жыл бұрын
Agree
@georgiatanasow6658 Жыл бұрын
Maybe you missed that part, but he said that we want our binary heap to be perfectly balanced. In that case the insertion showed in the video is correct.
@Yazan_Majdalawi Жыл бұрын
@@georgiatanasow6658 Why though? is there a benefit for doing it that way, compared to the easy way of filling the level from left to right?
@amitdhaterwal8395 Жыл бұрын
@@Yazan_Majdalawi we are trying for perfectly balance, suppose we have imbalance by factor 1 (suppose height(left)-1 === height(right)), now if we are inserting a new node, if we insert it to left again then the factor will still be 1, but if we insert to the right our factor will be zero and heap will be perfectly balanced The complete binary tree shape is also a valid but the balance factor can be 1 (which is allowed).
@carlbutcher226810 ай бұрын
I missed a lecture at university the other week and ended up doing a test without having any idea what a heap was or how it worked; Your video is clear and easy to understand, and I wish I'd looked sooner. Thank you.
@cyril3248 Жыл бұрын
I'm more familiar with the implementation as a complete tree ("filling each level from left to right") as it's easier to implement in a vector which eploits the contiguity in memory. This more AVL styled implementation is still interesting I have to say
@rektdedrip Жыл бұрын
This was my first time seeing an AVL type of implementation for a heap. I was always taught the complete tree structure as well
@angeldude10110 ай бұрын
Somewhat amusingly, this has the same flaw that the video gave for just using an array, but the "flaw" in question is so minor that it's still usually more efficient than using pointers like in a traditional binary tree or linked list.
@dominiquefortin53458 ай бұрын
@@rektdedrip There is no reason to do the AVL type thing.
@krewfit3 жыл бұрын
To make a complete binary tree, you go from top to bottom, left to right ALWAYS. The insertion in this video is not correct... however, the information he presents is very helpful!
@pursadas2 жыл бұрын
and also during deletion, the right-most element is sent to the root, isn't it? to preserve the said property?
@anushreevirtualgaming2262 жыл бұрын
@@pursadas yes, as far as i remember
@jellemiddendorf25722 жыл бұрын
thank you so much, i was learning and checked my results with some homework awnsers and got really confused because the homework only showed the end result not the steps inbetween, know i know it was the left to right thing
@kebman Жыл бұрын
He isn't making a binary tree, though, but a binary heap. Which looks a lot like a binary tree, but is faster - also because it allows for duplicates.
@broccolidiego2053 Жыл бұрын
Binary tree and Binary heap are different. Both have different usage. A binary tree is for storing data while the binary heap is use primarily for a priority queue, either min or max.
@gold49633 жыл бұрын
Easily a 5 star video. You've earned a sub, my friend.
@kritonios Жыл бұрын
Amazing video. The most detailed and "to the point" explanation of binary heaps I have seen. Many thanks. Keep it up!
@johnle77053 жыл бұрын
I love the presenter! Explain so well, so concisely!!!!
@wanwanan63229 ай бұрын
PERFECT video. Not boring and super informative. Covering all exceptions and key concepts. Thank u!
@willabyuberton8186 ай бұрын
Really nice video! I could watch animations of values getting inserted and deleted on binary trees all day.
@cristeycrouler1027 Жыл бұрын
your way of explaining and the sound of your voice and the type of things you talk about is all so great and makes me watch hours and not feel the time. Amazing videos man you deserve much more subscribers, hope you upload more♥️♥️♥️♥️♥️
@jamaka_me_code7962 жыл бұрын
Heck yeah I discovered you on CS50 w/David&Doug earlier this year and can't believe I haven't found this yet.! Thanks Brian for EVERYTHING you do homie ✌️
@abdullahzia46334 жыл бұрын
Bruh this was so much better explained than all of the videos with wayyyy more views on YT
@vaibhavpoliwal28203 жыл бұрын
Explained in very structured way.
@AmanSingh-wk3iv2 жыл бұрын
amazed to see this video in just 8 minutes we need to give at least an hour to learn the same concept at other places . Also it is helpful to understand the concept with the real life example so that we also know the applications. please create more videos on data structure . Thanks!!
@ontreprenor3 жыл бұрын
Hats off for the graphics. It was very much easy to understand
@zekmaroАй бұрын
thanks for explanation. it was so easy to follow. i didnt get heaps and trees but now they look really obvious. thanks man. i was so frustrated now im happy
@kamoroso942 жыл бұрын
Great video! I was looking for a quick refresher to help me implement a priority queue to use in the A* algorithm.
@AP_MLB3 ай бұрын
Amazing how I can learn 20x as much from a 20 minute video than I did in a two hour lecture
@shandou52763 жыл бұрын
This is the best explanation I have seen about heap. Big thumbs up!
@Leihua_Ye3 жыл бұрын
this is the best illustration of a binary heap.
@dodogo777 Жыл бұрын
best explaination ever, wish i watched this before my algorithm exam
@dominiquefortin53458 ай бұрын
Except the information in this video is just so slightly wrong, that people will not know it is bad. So no, not good
@MohammedAli-p7e9d6 ай бұрын
@@dominiquefortin5345 can you tell me what are the wrong points? I am still learning.
@dominiquefortin53456 ай бұрын
@@MohammedAli-p7e9d The problem is the order of insertion in the video which is 0, 1, 2, 3, 5, 4, 6, 7, 11, 9, 13, 8, 12, 10, 14. You have 2 implementations possible in an array or in a tree. Let’s look at array because it is the simplest. the position of the root is 0, the position of the parent node floor(P/2j, the position of the right child is 2P and the left is 2P+1. The insertion is always made at position N, so always O(1) plus the percolation O(log n) and that garanties the height of the right subtree has at most 1 in difference with the height of the left subtree and the rest is like what you have in the video. So here the order of insertion is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, … Now the link binary tree implementation in the next comment.
@dominiquefortin53456 ай бұрын
@@MohammedAli-p7e9d With a binary tree with links, the problem is where to insert a new element. Let’s suppose we put the height of the subtree in each node. Now we will start with a tree that is full on tree level so that all the child nodes of a parent they have the same heights. What rule should we use to find an insertion point? We know percolation is O(log nj so whatever we use it must O(log n) or better. Lets use the rule if the height of the subtree are equal we go left else we go right. In our exemple, we go all the way left and insert then percolate and ajust the height of each father node. The seconde element we add goes to the right first because the 2 subtree have unequal heights the left all the way down insert then percolate and ajust the height of each father node. Imagining that the root is at position 0 the insertion order is 7, 11, 9, 8, 10 and the this rule breaks because it would add a node on level 5 while level 4 is not full. I tried to think of a way to obtain the order … (i will come back, i have to work)
@dominiquefortin53456 ай бұрын
@@MohammedAli-p7e9d Let me correct myself. IT is not wrong just inefficient. He has to keep 2 counts in each node, one for of all the nodes in the left subtree and one for of all the nodes in the right subtree. There is a better way. By using the total element count plus one and from the most significant bit to the least, from the root, go left on a 0 and go right on a 1.
@KingofJ95 Жыл бұрын
This actually helped me understand how Heap Sort works.
@jamilhusssin37924 жыл бұрын
please make some more videos on different Algorithms like sorting Array algorithms, greedy algorithms, graphs implementations, etc.
@vitorhugodasilvalima8592 жыл бұрын
Recognized Brian Yu by voice. Great video, thank you very much, I am your fan
@gdlevels3830 Жыл бұрын
thank you bro, now i understand more and expand my knowledge with this new type of data structure. (really helped in greedy algorithms btw)
@victorgoncalves88833 жыл бұрын
thank you for the help on the CS51 PSET Brian...very much appreciated
@kiopsy75918 ай бұрын
@@dominiquefortin5345 whomp whomp
@wallinslax3 жыл бұрын
I think the insertion operation at 4:27 might be wrong, since the n th node's child node should be 2n and 2n+1.
@DanielVazquez3 жыл бұрын
The insertion is definitely not what many and I have learned, but still the invariant that the n-th node's child node should be 2n and 2n+1 remains unchanged.
@dominiquefortin53456 ай бұрын
In an array, yes, but he is using a binary tree.
@omaryahia Жыл бұрын
this is clear and concise, thank you 🌟
@DamosyTheFreckle3 ай бұрын
Amazing explanation and animation. Keep it up
@stith_pragya Жыл бұрын
Thank You So Much brother for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@kebman Жыл бұрын
I'd love a re-visit of this topic, with a comparison of a binary tree, including big O analysis.
@coffeedude Жыл бұрын
A heap is a kind of binary tree
@dominiquefortin53458 ай бұрын
@@coffeedude Heap is a binary tree.
@coffeedude8 ай бұрын
@@dominiquefortin5345 Yeah, it's a specific kind of binary tree. That's what I meant : )
@coffeedude8 ай бұрын
@@dominiquefortin5345 Yeah, it's a specific kind binary tree. That's what I meant : )
@utkarshsharma1185 Жыл бұрын
Thanks for the clear explanation
@dominiquefortin53458 ай бұрын
Except the information in this video is just so slightly wrong, that people will not know it is bad. So no, it is not Amazing
@utkarshsharma11858 ай бұрын
@@dominiquefortin5345 yeah you are correct, thanks for pointing it out
@dominiquefortin53456 ай бұрын
@@utkarshsharma1185 Let me correct myself. But the author uses a space inefficient way by keeping 2 counter in each node. There are better ways
@_Shubham....-----------------6 Жыл бұрын
The video teaches very much in a short time. Great 👌
@RV-kl2wl2 жыл бұрын
Just 1 mins and 40 sec into this video and already liked and subbed.
@Fido1hn3 ай бұрын
Subscribed! Awesome explanation. ❤
@LaughDimension5 ай бұрын
thank you very much. very intuitively explained
@shubhamnagure76543 жыл бұрын
Brian, Thanks for simplifying.
@charbel40903 жыл бұрын
BRIAN GET SOME FREE TIME AND UPLOAD AGAIN WE NEED YOU HAHAHAHAHAH I LOVE U
@benzeltser98513 жыл бұрын
THIS IS MORE THAN GREAT THIS IS INCREDIBLE
@galiberkowiz5943 жыл бұрын
Thank you for the explanation. I was just studying about it during a computer science -Python course on CodeAcademy and they didn't explain what's the real-life usage for this data structure, which is a shame. If I'd like to go deeper and understand the process that led to the creation and planning of this data structure, where would you recommend me to read or watch?
@dominiquefortin53458 ай бұрын
But for understanding, code it and play with it. It is only 3 functions insert, delete, size.
@supersakib62 Жыл бұрын
Excellent explanation
@brendawilliams8062 Жыл бұрын
I t seems so. I just came in to explore number theory. 💕 the good teachers in different fields.
@rickbacker1Ай бұрын
Thank you very much for this video!
@jatinkumar44103 жыл бұрын
Amazing and clear explanation...
@thedelanyo Жыл бұрын
Priceless lessons
@Bhanuteja015 ай бұрын
need all topics of data structure please 😃
@Dakshgohil-57 ай бұрын
4:42 Where do we add 9th node? Do we add under 5th node or we add under 6th node?
@avocode14872 жыл бұрын
Please make video on radix Heap, as It is difficult to understand. Thanks for this awesome video 👍👍
@rajdave73574 жыл бұрын
My god, you are so amazing please make more videos, we need you
@jimmycheong79702 жыл бұрын
Amazing video. Thank you!
@maxsuelfernandes30163 жыл бұрын
Such an amazing video, thanks
@polarbeargc74914 жыл бұрын
Great animation! Learned a lot.
@utkarshaggarwal16314 жыл бұрын
Amazing explanation. thanks
@alexeydulin85872 жыл бұрын
Really nice explanation, so thank you so much.
@dominiquefortin53458 ай бұрын
Except the information in this video is just so slightly wrong, that people will not know it is bad. So no, not nice
@Aditya-on6ps4 жыл бұрын
keep the good work sir
@jamesmejia2955 Жыл бұрын
Great vid, on an unrelated note, you sound just like the dude from CS50 course
@dipakpardeshi661811 ай бұрын
at 4:30 in video, you have shown wrong complete binary tree, stop teaching wrong concepts.
@jibachhyadav72414 жыл бұрын
Please do cover more portion of ds and algo. Lots of Love. Thank You
@SpanningTree4 жыл бұрын
Feel free to suggest any data structures and algorithms you'd like to see covered!
@aidynabirov77283 жыл бұрын
Great explanation!
@aidynabirov59328 ай бұрын
@@dominiquefortin5345then tell me the right one?
@ArshdeepSingh-rh3zb4 жыл бұрын
Great Explaination thanks
@tarnum1133 жыл бұрын
Thanks Brian!
@tarnum1138 ай бұрын
@@dominiquefortin5345 doesn’t matter. The man is a legend
@AmirAli-hg9bkАй бұрын
great video, thank you
@neuplop Жыл бұрын
But if you want to search for one specific in the bottom of the list you don't know where it is.
@audunoklevik44352 жыл бұрын
Good explanation
@dominiquefortin53458 ай бұрын
Except the information in this video is just so slightly wrong, that people will not know it is bad. So no, it is not good
@Karan-ms5es3 жыл бұрын
Could you make a video on TRIE ?
@leomyskyАй бұрын
Thanks for the video
@stone_pilot3 жыл бұрын
I think it would have been more helpful if you were more specific when discussing time complexity, but I still found this video useful
@marwahmaher85744 жыл бұрын
thank you, it was helpful
@anjaliasolkar88214 жыл бұрын
Amazing💯
@PraiseTheSquid Жыл бұрын
You made this fucking easy, thank god.
@VirtuelleWeltenMitKhan Жыл бұрын
nice video :D at first I thought this is just a binary tree
@dominiquefortin53458 ай бұрын
It is a binary tree, it is a balanced binary tree. It is not a binary search tree.
@VirtuelleWeltenMitKhan8 ай бұрын
@@dominiquefortin5345 at first I thought this is just a binary tree
@leelee34232 жыл бұрын
well explanation !
@dominiquefortin53458 ай бұрын
Except the information in this video is just so slightly wrong, that people will not know it is bad.
@brian_kirk3 жыл бұрын
Excellent video, nice job. Is insertion left-child first or left-most-leaf first? Left-most-leaf would be consistent with array visualization of heaps?
@dominiquefortin53458 ай бұрын
Insertion should be donne at the end of the array, no left-child or right-child.
@nazli9457 Жыл бұрын
very helpful!
@messapatingyАй бұрын
oops "2:99 Insertion" - 3:01 is the time
@enishalilaj93093 жыл бұрын
The explanation is quite good, but there are some small mistakes such as insertation and when you said the child cannot be smaller than the parent in Binary Heaps, that all depends if the Binary Heap is Min or Max, so that rule only exists when we define the Binary Heap!! Great vid!
@s0ulweaver Жыл бұрын
He did say that we will be talking about min-heap for this explanation
@udic01 Жыл бұрын
What is the complexity of searching an element?
@powerdust015lastname4 Жыл бұрын
6:44 why take a low priority element? you could just skip this step and swap the smallest children with null instead
@vr77323 Жыл бұрын
Could you elaborate on that? I don't think I understand what you mean by setting smallest children to null
@powerdust015lastname4 Жыл бұрын
@@vr77323 In the graph at 6:44 the root element is null. So we could just swap it with the smallest of its children and repeat, making the first step (setting 11 to be the new root) obsolete. In the animation it would look like the value null is propagating downwards, kinda like air bubbles in water (but upside down) or the gap between cars in a traffic jam.
@dominiquefortin53458 ай бұрын
@@powerdust015lastname4 What you propose is equivalent. If after that you move the 11 in the hole and you move the 11 toward the root until the parent is smaller.
@toolazy5899 Жыл бұрын
thanks dude!
@derrylmartinez80103 жыл бұрын
thank you so much
@snozking Жыл бұрын
how would you code something like this?
@klausbdl Жыл бұрын
It would be cool to show how that would work in python or some other language
@TheSwissGabber Жыл бұрын
would have been nice to show how this is better then a linked list.
@AnasKhan-pb8tn3 жыл бұрын
Binary heap should be a complete binary tree , that means left to right. The insertion is wrong.
@FranzBiscuit Жыл бұрын
So basically a Huffman tree. Which of course could be implemented as an array (albeit, at the expense of performance).
@dominiquefortin53458 ай бұрын
No, not a Huffman tree, a balanced binary tree. "... at the expense of performance ..." I don't think you know what you are talking about. You are comparing apples to oranges.
@FranzBiscuit8 ай бұрын
@@dominiquefortin5345 Yeah I honestly don't know what I was thinking there. I may have answered that one before I had my coffee! Cheers....
@DanielVazquez3 жыл бұрын
When we move up the number 11 to the root of the heap, we just need to see which root's children is smaller and repeat downwards. If none is smaller, the we are done! Note: We already know that 11 was brought from the bottom of the heap, so it must be either greater or equal to the two root's children.
@dominiquefortin53458 ай бұрын
"... must be either greater or equal to the two root's children ..." False, you only know that it is greater or equal to the left root's child because the 11 was on that sub tree. All the values on the right subtree can be greater than 11.
@wailelbani98152 жыл бұрын
the insertion is wrong
@mossthebryophyter3 жыл бұрын
Why is it that videos on KZbin explain stuff better while I'm paying a ridiculous amount of money just to attend a school?
@aarMess3 жыл бұрын
Good work! Btw. consider investing in a microphone, its worth it...
@kakol209082 ай бұрын
This video is overcomplicating binary heap. Watch Sebastian Lague's Heap Optimization video in his A* Pathfinding series. The way he explains makes more intuitive sense.
@jaimetagle88763 жыл бұрын
this will be thanos favorite data structure..
@JoeyCarb Жыл бұрын
I'm a middle child. Always left out and forgotten.
@mooyee19823 жыл бұрын
讲得不错!!
@Matthew548614 жыл бұрын
Just a heads up, your timestamp for Insertion is not valid!
@minecameraPL4 жыл бұрын
Thank you
@عبداللهاسماعيل-ذ9و4 жыл бұрын
keep more in algorithm
@عبداللهاسماعيل-ذ9و4 жыл бұрын
thanks
@Ggdivhjkjl Жыл бұрын
This method of organisation should be taught in schools.