Upcoming SlideShare
×

# Heapsort

3,834 views

Published on

heap sort educational powerpoing

3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
3,834
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
199
0
Likes
3
Embeds 0
No embeds

No notes for slide

### Heapsort

1. 1. Heapsort
2. 2. Heapsort <ul><ul><li>Heapsort is a sorting algorithm that makes use of a binary tree. </li></ul></ul><ul><ul><li>Heapsort is always O(n log n) </li></ul></ul><ul><ul><ul><li>there are other  algorithms  such as quicksort that perform better in good scenarios but in worst case perform at O(n 2) </li></ul></ul></ul><ul><ul><ul><li>Heapsort is worst case O(n log n) so it is better for critical applications </li></ul></ul></ul>
3. 3. What is a heap <ul><li>A balanced, left-justified binary tree in which </li></ul><ul><li>no node has a value greater than the value in its </li></ul><ul><li>parent </li></ul>Left-justified Not left-justified 12 8 3 12 8 12 12 8 14
4. 4. What is a heap <ul><li>A balanced, left-justified binary tree in which </li></ul><ul><li>no node has a value greater than the value in its </li></ul><ul><li>parent </li></ul>Left-justified Not left-justified 12 8 3 12 8 12 12 8 14 Heap
5. 5. What is a heap <ul><li>A balanced, left-justified binary tree in which </li></ul><ul><li>no node has a value greater than the value in its </li></ul><ul><li>parent </li></ul>Left-justified Not left-justified 12 8 3 12 8 12 12 8 14 Heap Heap
6. 6. What is a heap <ul><li>A balanced, left-justified binary tree in which </li></ul><ul><li>no node has a value greater than the value in its </li></ul><ul><li>parent </li></ul>Left-justified Not left-justified 12 8 3 12 8 12 12 8 14 Heap Heap Not a Heap
7. 7. Skipping Several pages of Algorithm Description for this class
8. 8. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>
9. 9. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>8 Insert 8 at head of tree
10. 10. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>Insert Ten as child of 8. 8 10
11. 11. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>Insert Ten as child of 8. Then Shift Up 8 10 10 8
12. 12. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>Insert 5 as child of root Tree fits the properties of a heap no addional steps are needs 10 8 5
13. 13. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>Insert 12 a the left most child. 10 8 5 12
14. 14. Insert The following values into a heap <ul><li>8, 10,5, 12 </li></ul>Shift up until heap the tree becomes a heap. 10 8 5 12 10 12 5 8 12 10 5 8