Transcript for:
Building a Minimum Heap

hey guys this is a video to build a minimum Heap also known as men Heap um we have an array here that we want to make a heap so building a heap from an array of in input elements can be done starting with the empty uh starting with a empty Heap so that means there's nothing there it's completely empty and then we're going to keep inserting each element from the array um this technique or method is called the Williams method after the guy who invented the binary heaps so let's go ahead and get started here so first what we're going to do is we're going to add the element three to our Heap and we're going to go from top to bottom left to right so next up we go left to add our next element which is one and because this is a Min heat it must follow the property that all of the children are greater than or equal to is parent so we have to swap these two elements so three goes here one goes here it will continue so next up we have the element six so we're going to add six here and six follows that property six is greater than or equal to its parent so next up we continue we go top down left right so we go to the left here we add the number five and five is greater than or equal to is parent so we go to the next element and we have two um two is less than its parent so we have to swap so we swap the two with the three so two goes here now and three goes here and now this two we have to also check with this parent make sure that it's um greater than or equal to its parent and two is greater than or equal equal to one so we continue we go to our four and we add our four here and now we have another issue four is uh less than six so we must swap the four and the six here and four here and then check that the four is greater than or equal to its parent which is one and it is so this is our Heap and how it would look in the array now that we've done all these swapping of the elements would be one two four five three and six so now this is how our our Heap looks as an array so thank you guys uh please leave likes and comments and I'll see you all in the next video