1 / 55

Heapsort

Heapsort. An Auto-generated Presentation. First, heapsort must build a heap. A ‘heap’ is a tree wherein each node is of a value equal to or less than its parent.

justincole
Download Presentation

Heapsort

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. Heapsort An Auto-generated Presentation

  2. First, heapsort must build a heap • A ‘heap’ is a tree wherein each node is of a value equal to or less than its parent. • Additionally, a ‘binary tree’ is used, which adds the constraint that no parent may have more than two nodes; this allows heapsort to run within its own array, without additional space complexity. • Each limb is passed through in reverse order, if the largest child is larger than the parent, they are swapped

  3. First, heapsort must build a heap 4 7 43 98 38 98 75 66 7 94 80 12 12 33 66 31 8 25 43 43

  4. First, heapsort must build a heap 4 7 43 98 38 98 75 66 7 94 80 12 12 33 66 31 8 25 43 43

  5. First, heapsort must build a heap 4 7 43 98 38 98 75 66 43 94 80 12 12 33 66 31 8 25 7 43

  6. First, heapsort must build a heap 4 7 43 98 38 98 75 66 43 94 80 12 12 33 66 31 8 25 7 43

  7. First, heapsort must build a heap 4 7 43 98 38 98 75 66 43 94 80 12 12 33 66 31 8 25 7 43

  8. First, heapsort must build a heap 4 7 43 98 38 98 75 66 43 94 80 12 12 33 66 31 8 25 7 43

  9. First, heapsort must build a heap 4 7 43 98 94 98 75 66 43 43 80 12 12 33 66 31 8 25 7 38

  10. First, heapsort must build a heap 4 7 43 98 94 98 75 66 43 43 80 12 12 33 66 31 8 25 7 38

  11. First, heapsort must build a heap 4 7 98 98 94 43 75 66 43 43 80 12 12 33 66 31 8 25 7 38

  12. First, heapsort must build a heap 4 98 98 66 94 43 75 31 43 43 80 12 12 33 66 7 8 25 7 38

  13. First, heapsort must build a heap 98 94 98 66 80 43 75 31 43 43 4 12 12 33 66 7 8 25 7 38

  14. The finished heap 98 94 98 66 80 43 75 31 43 43 4 12 12 33 66 7 8 25 7 38

  15. Now, heapsort can sort the array • At this point heapsort functions much like a ‘reverse’ selection sort, only ‘selecting’ is hardly necessary; it knows exactly where the largest values are: at the top of the heap! • The first in the array is swapped with the last unsorted number, and the heap rebuilds itself.

  16. Now, heapsort can sort the array 38 94 98 66 80 43 75 31 43 43 4 12 12 33 66 7 8 25 7

  17. Now, heapsort can sort the array 98 94 75 66 80 43 66 31 43 43 4 12 12 33 38 7 8 25 7

  18. Now, heapsort can sort the array 7 94 75 66 80 43 66 31 43 43 4 12 12 33 38 7 8 25

  19. Now, heapsort can sort the array 94 80 75 66 43 43 66 31 43 7 4 12 12 33 38 7 8 25

  20. Now, heapsort can sort the array 25 80 75 66 43 43 66 31 43 7 4 12 12 33 38 7 8

  21. Now, heapsort can sort the array 80 66 75 43 43 43 66 31 25 7 4 12 12 33 38 7 8

  22. Now, heapsort can sort the array 8 66 75 43 43 43 66 31 25 7 4 12 12 33 38 7

  23. Now, heapsort can sort the array 75 66 66 43 43 43 38 31 25 7 4 12 12 33 8 7

  24. Now, heapsort can sort the array 7 66 66 43 43 43 38 31 25 7 4 12 12 33 8

  25. Now, heapsort can sort the array 66 43 66 31 43 43 38 7 25 7 4 12 12 33 8

  26. Now, heapsort can sort the array 8 43 66 31 43 43 38 7 25 7 4 12 12 33

  27. Now, heapsort can sort the array 66 43 43 31 43 12 38 7 25 7 4 8 12 33

  28. Now, heapsort can sort the array 33 43 43 31 43 12 38 7 25 7 4 8 12

  29. Now, heapsort can sort the array 43 43 43 31 33 12 38 7 25 7 4 8 12

  30. Now, heapsort can sort the array 12 43 43 31 33 12 38 7 25 7 4 8

  31. Now, heapsort can sort the array 43 33 43 31 12 12 38 7 25 7 4 8

  32. Now, heapsort can sort the array 8 33 43 31 12 12 38 7 25 7 4

  33. Now, heapsort can sort the array 43 33 38 31 12 12 8 7 25 7 4

  34. Now, heapsort can sort the array 4 33 38 31 12 12 8 7 25 7

  35. Now, heapsort can sort the array 38 33 12 31 12 4 8 7 25 7

  36. Now, heapsort can sort the array 7 33 12 31 12 4 8 7 25

  37. Now, heapsort can sort the array 33 31 12 25 12 4 8 7 7

  38. Now, heapsort can sort the array 7 31 12 25 12 4 8 7

  39. Now, heapsort can sort the array 31 25 12 7 12 4 8 7

  40. Now, heapsort can sort the array 7 25 12 7 12 4 8

  41. Now, heapsort can sort the array 25 12 12 7 7 4 8

  42. Now, heapsort can sort the array 8 12 12 7 7 4

  43. Now, heapsort can sort the array 12 8 12 7 7 4

  44. Now, heapsort can sort the array 4 8 12 7 7

  45. Now, heapsort can sort the array 12 8 4 7 7

  46. Now, heapsort can sort the array 7 8 4 7

  47. Now, heapsort can sort the array 8 7 4 7

  48. Now, heapsort can sort the array 7 7 4

  49. Now, heapsort can sort the array 7 7 4

  50. Now, heapsort can sort the array 4 7

More Related