Heaps and Priority Queues - PowerPoint PPT Presentation

1 / 125
About This Presentation
Title:

Heaps and Priority Queues

Description:

Queue of Q's (That's Q from. the James Bond. movies) Queue if Q's. Perhaps we. need to find the ... Advantages of array implementation of complete tree ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 126
Provided by: facul56
Category:
Tags: bond | complete | heaps | in | james | list | movies | of | order | priority | queues

less

Transcript and Presenter's Notes

Title: Heaps and Priority Queues


1
Heaps and Priority Queues
  • CS1332
  • Spring 2007

2
Priority Queues
  • New Structure
  • Produce smallest/largest quickly
  • Sorted list might be a bit too much
  • Goals
  • Quickly add new things
  • Quickly find max/min (Not at same time!)
  • But Why?

3
Queue of Qs
(Thats Q from the James Bond movies)
4
Queue if Qs
Perhaps we need to find the smallest in this
queue of Qs.
5
Alternatives
We might search for the smallest one
Or we might keep them in order
6
Priority Queues
Perhaps we wish to find the smallest document,
and print it first.
A better example is a queue of documents waiting
to be printed.
This is known as the Shortest Job First
scheduling algorithm
7
Priority Queues
The small jobs take less time to print. So its a
better policy to print them first
Take for example a printer queue.
90 mins.
20 mins.
5 secs.
5 mins.
Simply printing in order can cause bottle necks
maybe we need to pump up throughput!
8
Poor Technique 1 Unordered Linked List
We could also adopt some rules to make the list
fast
1
Insertion is at the head of the list, ( O (1) ).
2
Deletion requires us to search for the
smallest, ( O (N) ).
So insertion is fast, and deletion is slow
Deletion is what we do when we remove the
smallest element
9
Poor Technique 2Ordered Linked List
We can tinker with our previous solution to try
and make it faster. Lets sort the elements on
insertion.
Theres a tradeoff between insertion and deletion
speed
1
Insertion is in order ( O (N) )
2
Deletion simply removes the smallest, ( O
(1) )
So deletion is fast, and insertion is slow
10
Better Technique 3BST?
A linked list either required O(N) for either
insertion or deletion. Could we instead use a BST
to get some log(N) behavior for either of the
activities?
As we insert into our BST, we place the smallest
to the left.
What could go wrong?
11
Technique 3 over time
A linked list either required O(N) for either
insertion or deletion. Could we instead use a BST
to get some log(N) behavior for either of the
activities?
Over time, what will happen?
BST becomes right heavy--more like a linked
list. Our log (N) insertion/deletion starts to
decay.
12
Better Technique 4Balanced BST
  • Good
  • Add, Delete in O(log n)
  • Min/Max O(log n) (Go left or right to end)
  • Bad
  • Time spent in rotations, balancing
  • We only care about Max and Min
  • Too much wasted effort

13
Data Structure Heap
Vocabulary Terms binary heap, Queuing Use
used to implement a priority queue. Sorting
Use Heapsort uses a heap. Without
qualification, the term heap refers to binary
heap. So what is a heap? A heap is binary
tree The binary tree is completely
filled there are no gaps, except for the
bottom level. A picture might help. . .
14
Completeness
Complete
Incomplete
A
A
C
C
B
B
D
E
F
G
D
E
F
G
H
I
J
H
I
J
"Complete" is a stronger property than a BST
since it does not permit gaps in any rows -
followsleft to right in its "completeness"
This missing node makes the tree "incomplete".
15
Heap Rules
  • Different Kind of Tree
  • Two Types
  • Min Heap For every node X with parent P, the key
    value in P is smaller than or equal to X
  • Max Heap For every node X with parent P, the key
    value in P is larger than or equal to X
  • Max/Min value always at the tree root node

16
Basic Heap Properties
  • Structure Property
  • organize the data as a complete binary tree
  • enables operation in log N time (tree will always
    be log N tall!)
  • Order Property
  • In a heap, for every node X with parent P, the
    key value in P is smaller than or equal to X
  • Forces the minimum value to be the trees root
  • Tree Operations
  • may disturb the structure or the order or both
    properties
  • must restore those properties

17
Heap Array Implementation
  • Heaps are essentially binary trees
  • The requirements and properties allow us to use a
    very clever implementationimplement a binary
    tree using an Array!!!
  • Consider a typical array

00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
18
Heap Array Implementation
  • Now think of it this way

00
Ignore this one
01
19
Heap Array Implementation
  • Now think of it this way

00
Ignore this one
The lines are not real! I have drawn them in to
help show "tree-like" nature of this arrangement!
01
20
Heap Array Implementation
  • Observe math facts regarding indices

Note The parent of any node i is given by i/2
(integer division)
01
Note The right child of any node i is given by
2i1
Note The left child of any node i is given by 2i
21
Why not use arrays for all trees?
  • Advantages of conventional dynamic tree
    implementation
  • Can always add one more node easily
  • Can move whole chunks of tree by simply
    manipulating pointers. Important for balanced
    tree algorithms
  • Doesn't lose efficiency if tree not complete
  • Typical tree usage does not call for complete
    trees!
  • Advantages of array implementation of complete
    tree
  • Space efficient A node only holds data, no
    pointers
  • Quick access to "next" available spot if size is
    maintained. O(1).
  • Can find a nodes parent without lots of extra
    pointers and manipulation

22
Array Implementation
  • For any element at array position i
  • left child is at ( 2i )
  • right child is at ( 2i1 )
  • parent is at (int) (i / 2)

1
A
3
2
C
B
4
5
6
7
D
E
F
G
Dynamic behavior of arrays achieved by
reallocating larger array blocks
8
9
10
H
I
J
0
1
3
4
5
6
7
8
9
2
10
11
12
13
Can just skip this one
23
Priority Queue Basic Behavior
  • Priority Queues basic behavior
  • insert(item)
  • "item" should be a data that does have an order
    property (like integers, strings (alphabetic
    ordering), etc)
  • min()
  • returns the minimum value without changing the
    priority queue
  • removeMin()
  • delete and return the smallest item in the
    structure
  • isEmpty()
  • makeEmpty()

24
Priority Queue Implementation
  • An excellent choice is a heap.
  • The heap was originally developed as part of a
    sorting algorithm called Heapsort
  • Later, we will show how a heap can be used to
    perform the Heapsort

25
Our Heap API
  • A Heap should implement the following
  • void insert(Comparable c)
  • Comparable removeMin()
  • boolean isEmpty()
  • Internally several other methods may/will be
    needed
  • upheap - bubbles a small value up as far asit
    should be (like after an insertion to a leaf
    position)
  • downHeap - allows a large value to drop asfar as
    it should (like after a removeMin hasforced a
    large value to be swapped to the root)

26
Remember
  • The heap is going to be implemented in an array.
  • The array has a size.
  • The heap also has a size.
  • which may be less than or equal to the array
    size.
  • Example array might have size 100, but weve
    added only 30 elements to our heap.

27
Insertion
  • For the moment assume that the heap exists and
    that the array is big enough to allow the heap to
    expand by at least one element

28
Insertion
size 26
2
26
10
18
21
29
27
57
20
47
37
69
69
29
58
A correct heap to start with...
86
95
85
90
31
94
55
98
71
79
91
29
Insertion
size 27
2
Increment the size, andplace the 25in that slot
26
10
18
21
29
27
57
20
47
37
69
69
29
58
86
25
95
85
90
31
94
55
98
71
79
91
Insert 25 and call upHeap!
30
Insertion
size 27
2
26
10
18
21
29
27
57
20
47
37
69
69
29
58
while(i gt 1 Ai lt Ai/2)
swap(Ai,Ai/2) i i/2
86
25
95
85
90
31
94
55
98
71
79
91
Insert 25
31
Insertion
size 27
2
26
10
18
21
29
27
57
20
47
37
69
25
29
58
while(i gt 1 Ai lt Ai/2)
swap(Ai,Ai/2) i i/2
86
69
95
85
90
31
94
55
98
71
79
91
Insert 25
32
Insertion
size 27
2
26
10
18
21
25
27
57
20
47
37
69
29
29
58
while(i gt 1 Ai lt Ai/2)
swap(Ai,Ai/2) i i/2
86
69
95
85
90
31
94
55
98
71
79
91
Insert 25
33
Insertion
size 27
2
25
10
18
21
26
27
57
20
47
37
69
29
29
58
while(i gt 1 Ai lt Ai/2)
swap(Ai,Ai/2) i i/2
86
69
95
85
90
31
94
55
98
71
79
91
Insert 25
34
Insertion
size 27
2
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
69
95
85
90
31
94
55
98
71
79
91
35
Question?
  • Will insert work starting with an empty heap?

36
removeMin
  • We must take the value from the root node and
    return it to the user.
  • Then we must remove the node.
  • Easy array implementation
  • Take the last element in the heap and put it in
    root
  • Then call downHeap!

37
downHeap
  • downHeap is called on a node. It checks that the
    heap property is being maintained. If not, it
    fixes it.

If a fix was made, then downHeap calls itself
recursively on the value that was swapped down
i
27
Details such as checking to make sure elements 2i
and 2i1 are in the heap are omitted
2i1
2i
42
36
38
removeMin
size 27
2
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
69
95
85
90
31
94
55
98
71
79
91
39
removeMin
returnValue 2
size 27
2
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
69
95
85
90
31
94
55
98
71
79
91
40
removeMin
returnValue 2
size 27
69
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
69
95
85
90
31
94
55
98
71
79
91
41
removeMin
returnValue 2
size 26
69
Decrement the size
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
69
95
85
90
31
94
55
98
71
79
91
42
removeMin
returnValue 2
size 26
69
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
43
removeMin
returnValue 2
size 26
69
25
10
18
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
44
removeMin
returnValue 2
size 26
10
25
69
18
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
45
removeMin
returnValue 2
size 26
10
25
69
18
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
46
removeMin
returnValue 2
size 26
10
25
18
69
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
47
removeMin
returnValue 2
size 26
10
25
18
69
21
26
27
57
20
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
48
removeMin
returnValue 2
size 26
10
25
18
20
21
26
27
57
69
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
49
removeMin
returnValue 2
size 26
10
25
18
20
21
26
27
57
69
47
37
69
29
29
58
86
95
85
90
31
94
55
98
71
79
91
downHeap
50
removeMin
returnValue 2
size 26
10
25
18
20
21
26
27
57
31
47
37
69
29
29
58
86
95
85
90
69
94
55
98
71
79
91
downHeap
51
removeMin
returnValue 2
size 26
10
25
18
20
21
26
27
57
31
47
37
69
29
29
58
86
95
85
90
69
94
55
98
71
79
91
52
removeMin
size 26
10
25
18
20
21
26
27
57
31
47
37
69
29
29
58
86
95
85
90
69
94
55
98
71
79
91
53
Details
  • isEmpty
  • Simply tests size
  • makeEmpty
  • if this is wanted,
  • can just set size to zero.
  • At this point our heap can easily implement a
    priority queue given that we start with an empty
    queue and add and remove elements as necessary.
  • If we were given an array of numbers it might be
    useful to turn the array into a heap "in-place"

54
BuildHeap
  • Given an array of numbers how do we convert it
    into a heap.
  • We could iterate through the array and insert
    each number into heap but this requires us to
    have space big enough for twice the quantity of
    numbers we have.
  • We want to convert in place.
  • Note We will assume that element 0 is not used.
  • Don't confuse this with downHeap. BuildHeap will
    use downHeap and is used to create the Heap

55
BuildHeap
  • Assume that we have the number of elements in a
    variable called size
  • Iterate index from element arraySize/2 down to
    index 1
  • downHeap(index)

56
BuildHeap
size 26
87
68
43
6
77
33
9
11
19
99
6
23
89
2
14
22
1
5
27
35
7
42
12
71
3
67
57
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
23
89
2
14
Start at element arraySize/2
22
1
5
27
35
7
42
12
71
3
67
58
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
23
89
2
14
22
1
5
27
35
7
42
12
71
3
67
downHeap
59
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
23
22
2
14
89
1
5
27
35
7
42
12
71
3
67
downHeap
60
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
23
22
2
14
89
1
5
27
35
7
42
12
71
3
67
downHeap
61
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
3
22
2
14
89
1
5
27
35
7
42
12
71
23
67
downHeap
62
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
3
22
2
14
89
1
5
27
35
7
42
12
71
23
67
downHeap
63
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
99
6
3
22
2
14
89
1
5
27
35
7
42
12
71
23
67
downHeap
64
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
7
6
3
22
2
14
89
1
5
27
35
99
42
12
71
23
67
downHeap
65
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
7
6
3
22
2
14
89
1
5
27
35
99
42
12
71
23
67
downHeap
66
BuildHeap
size 26
87
68
43
6
77
33
9
13
11
19
7
6
3
22
2
14
89
1
5
27
35
99
42
12
71
23
67
downHeap
67
BuildHeap
size 26
87
68
43
6
77
33
9
13
1
19
7
6
3
22
2
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
68
BuildHeap
size 26
87
68
43
6
77
33
9
13
1
19
7
6
3
22
2
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
69
BuildHeap
size 26
87
68
43
6
77
33
2
13
1
19
7
6
3
22
9
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
70
BuildHeap
size 26
87
68
43
6
77
33
2
13
1
19
7
6
3
22
9
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
71
BuildHeap
size 26
87
68
43
6
77
3
2
13
1
19
7
6
33
22
9
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
72
BuildHeap
size 26
87
68
43
6
77
3
2
13
1
19
7
6
33
22
9
14
89
11
5
27
35
99
42
12
71
23
67
downHeap
73
BuildHeap
size 26
87
68
43
6
77
3
2
13
1
19
7
6
23
22
9
14
89
11
5
27
35
99
42
12
71
33
67
downHeap
74
BuildHeap
size 26
87
68
43
6
77
3
2
13
1
19
7
6
23
22
9
14
89
11
5
27
35
99
42
12
71
33
67
downHeap
75
BuildHeap
size 26
87
68
43
6
6
3
2
13
1
19
7
77
23
22
9
14
89
11
5
27
35
99
42
12
71
33
67
downHeap
76
BuildHeap
size 26
87
68
43
6
6
3
2
13
1
19
7
77
23
22
9
14
89
11
5
27
35
99
42
12
71
33
67
downHeap
77
BuildHeap
size 26
87
68
43
6
6
3
2
13
1
19
7
12
23
22
9
14
89
11
5
27
35
99
42
77
71
33
67
downHeap
78
BuildHeap
size 26
87
68
43
6
6
3
2
13
1
19
7
12
23
22
9
14
89
11
5
27
35
99
42
77
71
33
67
downHeap
79
BuildHeap
size 26
87
68
43
1
6
3
2
13
6
19
7
12
23
22
9
14
89
11
5
27
35
99
42
77
71
33
67
downHeap
80
BuildHeap
size 26
87
68
43
1
6
3
2
13
6
19
7
12
23
22
9
14
89
11
5
27
35
99
42
77
71
33
67
downHeap
81
BuildHeap
size 26
87
68
43
1
6
3
2
13
5
19
7
12
23
22
9
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
82
BuildHeap
size 26
87
68
43
1
6
3
2
13
5
19
7
12
23
22
9
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
83
BuildHeap
size 26
87
2
43
1
6
3
68
13
5
19
7
12
23
22
9
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
84
BuildHeap
size 26
87
2
43
1
6
3
68
13
5
19
7
12
23
22
9
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
85
BuildHeap
size 26
87
2
43
1
6
3
9
13
5
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
86
BuildHeap
size 26
87
2
43
1
6
3
9
13
5
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
87
BuildHeap
size 26
87
2
1
43
6
3
9
13
5
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
88
BuildHeap
size 26
87
2
1
43
6
3
9
13
5
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
89
BuildHeap
size 26
87
2
1
5
6
3
9
13
43
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
90
BuildHeap
size 26
87
2
1
5
6
3
9
13
43
19
7
12
23
22
68
14
89
11
6
27
35
99
42
77
71
33
67
downHeap
91
BuildHeap
size 26
87
2
1
5
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
92
BuildHeap
size 26
87
2
1
5
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
93
BuildHeap
size 26
1
2
87
5
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
94
BuildHeap
size 26
1
2
87
5
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
95
BuildHeap
size 26
1
2
5
87
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
96
BuildHeap
size 26
1
2
5
87
6
3
9
13
6
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
97
BuildHeap
size 26
1
2
5
6
6
3
9
13
87
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
98
BuildHeap
size 26
1
2
5
5
6
3
9
13
87
19
7
12
23
22
68
14
89
11
43
27
35
99
42
77
71
33
67
downHeap
99
BuildHeap
size 26
1
2
5
5
6
3
9
13
11
19
7
12
23
22
68
14
89
87
43
27
35
99
42
77
71
33
67
downHeap
100
BuildHeap
size 26
1
2
5
5
6
3
9
13
11
19
7
12
23
22
68
14
89
87
43
27
35
99
42
77
71
33
67
101
What else can we do?
  • Use the heap for sorting.
  • Heapsort!

102
Basic Idea
  • Given an unsorted array we use BuildHeap to
    convert it into a heap
  • While heap is not empty
  • removeMin - remember that replaces the top
    element with the last element of the
    heap/array and then heapifies
  • The heap (logical concept) is one smaller but the
    array (physical concept) hasn't changed
  • Put the item just removed in the element just
    after the logical end of the heap
  • At conclusion the array is sorted

103
HeapSortafter BuildHeap
size 26
1
2
5
5
6
3
9
11
19
7
12
23
22
68
14
89
87
43
27
35
99
42
77
71
33
67
104
HeapSort
size 26
1
removeMin
2
5
5
6
3
9
11
19
7
12
23
22
68
14
89
87
43
27
35
99
42
77
71
33
67
105
HeapSort
size 26
89
removeMin
2
5
5
6
3
9
11
19
7
12
23
22
68
14
89
87
43
27
35
99
42
77
71
33
67
106
HeapSort
size 25
2
removeMin 1
3
5
5
6
22
9
11
19
7
12
23
89
68
14
Not in heap now
87
43
27
35
99
42
77
71
33
67
107
HeapSort
size 25
2
3
5
5
6
22
9
11
19
7
12
23
89
68
14
1
87
43
27
35
99
42
77
71
33
67
heap is 1 element smaller, smallest element is at
end of array
108
HeapSort
size 25
2
3
5
5
6
22
9
11
19
7
12
23
89
68
14
1
87
43
27
35
99
42
77
71
33
67
Now do it again!
109
HeapSort
size 24
3
9
5
5
6
22
14
11
19
7
12
23
89
68
67
1
87
43
27
35
99
42
77
71
33
2
110
HeapSort
size 23
5
9
5
11
6
22
14
33
19
7
12
23
89
68
67
1
87
43
27
35
99
42
77
71
3
2
111
HeapSort
size 22
5
9
6
11
7
22
14
33
19
42
12
23
89
68
67
1
87
43
27
35
99
71
77
5
3
2
112
HeapSort
size 21
6
9
7
11
7
22
14
33
19
42
12
23
89
68
67
1
87
43
27
35
99
71
5
5
3
2
113
HeapSort
size 20
7
9
7
11
12
22
14
33
19
42
71
23
89
68
67
1
87
43
27
35
99
6
5
5
3
2
114
HeapSort
size 19
7
9
11
19
12
22
14
33
27
42
71
23
89
68
67
1
87
43
99
35
7
6
5
5
3
2
115
HeapSort
size 18
9
14
11
19
12
22
35
33
27
42
71
23
89
68
67
1
87
43
99
7
7
6
5
5
3
2
116
HeapSort
size 17
11
14
12
19
42
22
35
33
27
99
71
23
89
68
67
1
87
43
9
7
7
6
5
5
3
2
117
HeapSort
size 16
12
14
19
27
42
22
35
33
43
99
71
23
89
68
67
1
87
11
9
7
7
6
5
5
3
2
118
HeapSort
size 15
14
22
19
27
42
23
35
33
43
99
71
87
89
68
67
1
12
11
9
7
7
6
5
5
3
2
119
HeapSort
size 14
19
22
27
33
42
23
35
67
43
99
71
87
89
68
14
1
12
11
9
7
7
6
5
5
3
2
120
HeapSort
size 13
22
23
27
33
42
68
35
67
43
99
71
87
89
19
14
1
12
11
9
7
7
6
5
5
3
2
121
HeapSort
size 12
23
35
27
33
42
68
89
67
43
99
71
87
22
19
14
1
12
11
9
7
7
6
5
5
3
2
122
HeapSort
size 11
27
35
33
43
42
68
89
67
87
99
71
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
123
HeapSort
size 10
33
35
42
43
71
68
89
67
87
99
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
124
HeapSort
size 9
35
68
42
43
71
99
89
67
87
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
125
HeapSort
size 8
42
68
43
67
71
99
89
87
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
126
HeapSort
size 7
43
68
67
87
71
99
89
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
127
HeapSort
size 6
67
68
71
87
89
99
43
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
128
HeapSort
size 5
68
99
71
67
43
87
89
42
35
33
27
23
22
19
14
12
1
11
9
7
7
6
5
5
3
2
129
HeapSort
size 4
71
99
87
89
68
67
43
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
130
HeapSort
size 3
87
99
89
71
68
67
43
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
131
HeapSort
size 2
89
87
99
71
68
67
43
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
132
HeapSort
size 1
99
87
89
71
68
67
43
42
35
33
27
23
22
19
14
1
12
11
9
7
7
6
5
5
3
2
Write a Comment
User Comments (0)
About PowerShow.com