1 / 6

Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19.

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

leei
Download Presentation

Build a heap with 27, 35, 23, 22, 4, 45, 21, 5, 42 and 19.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

More Related