Presentation is loading. Please wait.

Presentation is loading. Please wait.

Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19. With a series of insertions, here’s the result. 27 35 23 42 19 45 21 5224.

Similar presentations


Presentation on theme: "Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19. With a series of insertions, here’s the result. 27 35 23 42 19 45 21 5224."— Presentation transcript:

1 Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19. With a series of insertions, here’s the result. 27 35 23 42 19 45 21 5224

2 Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and 19. 20 3523 2244521 54219 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.

3 Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and 19. 20 3523 42194521 5224 22 and 42 are swapped. 4 and 19 are swapped.

4 Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and 19. 20 4245 35192321 5224 35 and 42 are swapped. 23 and 45 are swapped.

5 Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and 19. 45 4220 35192321 5224 45 and 20 are swapped. We need to continue this comparison until we reach the bottom level.

6 Build a heap with 20, 35, 23, 22, 4, 45, 21, 5, 42 and 19. 45 4223 35192021 5224 20 and 23 are swapped. Now it’s a heap.


Download ppt "Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19. With a series of insertions, here’s the result. 27 35 23 42 19 45 21 5224."

Similar presentations


Ads by Google