Download presentation

Presentation is loading. Please wait.

Published byBrent Edmond Modified about 1 year ago

1
What else can we do with heaps? Use the heap for sorting. Heapsort!

2
Basic Idea Given an unsorted array we use BuildHeap to convert it into a heap While(heap is not empty) –removeMin –The heap is one smaller but the array hasn't changed –Put the item just removed in the element just after the end of the heap At conclusion the array is sorted

3
HeapSort after BuildHeap size = 26

4
HeapSort size = 26 removeMin

5
HeapSort size = 25 removeMin = 1 Not in heap now

6
HeapSort size = 25 heap is 1 element smaller, smallest element is at end of array

7
HeapSort size = 25 Now do it again!

8
HeapSort size = 24

9
HeapSort size = 23

10
HeapSort size = 22

11
HeapSort size = 21

12
HeapSort size = 20

13
HeapSort size = 19

14
HeapSort size = 18

15
HeapSort size = 17

16
HeapSort size = 16

17
HeapSort size = 15

18
HeapSort size = 14

19
HeapSort size = 13

20
HeapSort size = 12

21
HeapSort size = 11

22
HeapSort size = 10

23
HeapSort size = 9

24
HeapSort size = 8

25
HeapSort size = 7

26
HeapSort size = 6

27
HeapSort size = 5

28
HeapSort size = 4

29
HeapSort size = 3

30
HeapSort size = 2

31
HeapSort size = 1

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google