Posts

Showing posts from January, 2022

Max Heap Create and Sorting

Image
Hi, this is Shubham Mishra. I write blogs on algorithms and new technologies. In today's blog, we will going to cover the max heap topic. Now before actually looking the code lets understand the max heap tree. A complete binary tree is a tree in which every levels are completely filled except the lowest one, which is filled from the left. And A max heap is a complete binary tree and the root node always have the max value of the tree, hence the name is max heap. Now with this max heap tree is have one more important property, the value of a node is always greater than or equal to the all chindren nodes. Confused, let me explain with a diagram: As can be seen in above tree, this is complete binary tree, since nodes are entered in such as way that all of the in between nodes are have 2 childrens. And any node's value is any time greater than all the children nodes. Take 6, it is greater than all the child nodes (5 -> 4, 2 And 3 -> 1). Similar to this 5 is greater than