Professional Documents
Culture Documents
Quicksort
Quicksort
1
2
3
4
5
6
Running Time
7
Performance of quicksort
8
9
10
Heap Sort
11
Heap
12
Heap
13
Heap
14
Heap
• There are two kinds of binary heaps: max-heaps and
min-heaps. In both kinds, the values in the nodes
satisfy a heap property, the specifics of which depend
on the kind of heap.
• In a max-heap, the max-heap property is that for every
node i other than the root,
16
Heap
• Viewing a heap as a tree, we define the height of a
node in a heap to be the number of edges on the
longest simple downward path from the node to a leaf,
and we define the height of the heap to be the height
of its root.
17
Heap
18
Maintaining the heap property
19
20
Fig: 6.2
21
Running Time
22
Building a heap
23
Example: Build Heap
24
25
26
The heapsort algorithm
27
28
29
30
Running Time
31
Priority queues
32
33
34
35
Thank You
36