VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Heap Data Structure (max and min)- Beau teaches JavaScript

Heap Data Structure (max and min)- Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
A binary heap is a partially ordered binary tree which satisfies the heap property. What is the heap property? Watch the video to find out! Also see how to implement a min heap in JavaScript. Thanks to Sean Smith for the code! - Code: http://codepen.io/beaucarnes/pen/JNvENQ?editors=0010 - Heap visualization: https://www.cs.usfca.edu/-galles/visualization/Heap.html - Beau Carnes on
Date: 2022-03-14

Comments and reviews: 9


While I appreciate the info, why did he choose to show the diagram for a max heap and then walk through the code of a min heap? He even showed us that he has the code for a min heap already there, so why show one thing and explain how to build the opposite? Even more nonsensical, he leaves the diagram of the max heap side by side the whole time he's walking through the code of the min heap. Anyone who wants a visual representation of the min heap while he explains the code has to ignore the diagram displayed side by side with the code.
reply

shouldn't we replace the -- with and && here:
if(heap[left] == undefined -- heap[right] == undefined)-
break;
-
be this instead:
if(heap[left] == undefined && heap[right] == undefined)-
break;
-
because we still want to swap even if the parent has only -one- child.

reply

Thank you Beau. My question is; when you sort the heap, you also remove everything in the actual heap. Is this expected? I mean, if I sort it and then insert another element, the heap will have only 2 elements; the null and the last thing I added.
reply

This is wrong, because if there is an element in the left, then we need to check
if (this.heap[left] == undefined -- this.heap[right] == undefined) -
break;
-

reply

at 10:38, in the remove function you use .splice(heap.length-1); to splice off the last element of our array..
is it faster to use splice instead of a .pop(); there?

reply

if we cut off the last element on line 57, we would be left with just the array with one element in is which is null, then why are we cutting it off?
reply

-this._heap[left] === undefined -- this.heap[right] === undefined-
I think -- sign should be && sign and other logic should be changed respectively

reply

I'm sorry, but this video is not very helpful. There's not one word about WHY heaps are used, so I'm not given any incentive to learn HOW.
reply

Super helpful, thanks Beau for all of your contributions. All of your Data Structure videos are fantastic. Been sharing them with my cohort!
reply
Add a review, comment






Other channel videos