Max Heap: Introduction
A brief introduction to max heap and how elements are inserted or removed from them.
We'll cover the following
Building a max heap
As mentioned in the previous lesson, max heaps follow the max heap property, which means that the key at the parent node is always greater than the keys at the child nodes. Heaps can be implemented by using lists. Initially, elements are placed in nodes in the same order as they appear in the list. Then a function is called over the whole heap in a bottom-up manner that “Max Heapifies” or “percolates up” on this heap so that the heap property is restored. The “Max Heapify” function is bottom-up because it starts comparing and swapping parent-child key values from the last parent (at the th index).
For a visual demonstration of heap creation, check out the following illustration:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy