Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19. With a series of insertions, here’s the result
Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and First, we build an arbitrary complete binary tree. Then, starting from the bottom level, we fix the tree such that parent_value > child_value. Swap with the larger child.
Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and and 42 are swapped. 4 and 19 are swapped.
Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and and 42 are swapped. 23 and 45 are swapped.
Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and and 20 are swapped. We need to continue this comparison until we reach the bottom level.
Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and and 23 are swapped. Now it’s a heap.