Escolar Documentos
Profissional Documentos
Cultura Documentos
Text
Leftist Heap
Sequence of inserts
Re-heapification if leftist heap property is
violated
Motivation
A binary heap provides O(log n) inserts and
O(log n) deletes but suffers from O(n log n)
merges
A leftist heap offers O(log n) inserts and O(log
n) deletes and O(log n) merges
Note, however, leftist heap inserts and deletes
are more expensive than Binary Heap inserts
and deletes
Definition
A Leftist (min)Heap is a binary tree that satisfies the following conditions. If X is a node and L and R are its left and
right children, then:
1. X.value L.value
2. X.value R.value
3. null path length of L null path length of R
19
12
27
15
25
20
43
node
19
12
15
25
27
20
43
npl
27
19
0
What is the npl of the
right child of 8?
25
43
20
node
19
12
15
25
27
20
43
npl
19
27
25
43
20
node
19
12
15
25
27
20
43
npl
Leftist Heap
4
19
27
43
20
12
15
25
node
19
12
15
25
27
20
43
npl
6
8
19
27
43
12
20
15
8
14
25
6
8
19
27
43
12
20
15
14
25
6
8
19
27
43
12
20
15
14
25
6
8
19
27
43
12
20
15
14
25
19
27
43
x
12
20
15
14
25
19
27
43
x
12
20
15
14
25
6
4
19
27
43
x
12
20
15
y
7
14
25
6
4
19
27
43
x
12
20
15
y
7
14
25
7
6
4
19
27
43
x
12
20
15
8
14
25
y
null
7
6
4
19
27
43
x
12
20
15
14
25
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
8
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
8
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
Return node 7
6
8
Refers to node 8
20
7
8
14
12
43
15
25
6
8
Refers to node 8
20
7
8
14
12
43
15
25
6
8
Refers to node 8
20
7
8
14
12
43
15
25
Return node 6
19
27
43
20
7
8
14
12
15
25
19
27
43
20
7
8
14
12
15
25
19
27
43
20
7
8
14
12
15
25
Return node 4
Analysis
Height of a leftist heap O(log n)
Maximum number of values stored in Stack
2 * O(log n) O(log n)
Total cost of merge O(log n)
Skew Heaps
Text
Skew Heap
Sequence of inserts
Swap children at every merge step
Motivation
Simplify leftist heap by
not maintaining null path lengths
swapping children at every merge step
Definition
A Skew (min)Heap is a binary tree that satisfies the follow-ing
conditions. If X is a node and L and R are its left and right
children, then:
1.
2.
X.value L.value
X.value R.value
X.value L.value
X.value R.value
6
8
19
27
43
12
20
15
8
14
25
6
8
19
27
43
12
20
15
14
25
6
8
19
27
43
12
20
15
14
25
6
8
19
27
43
12
20
15
14
25
19
27
43
x
12
20
15
14
25
19
27
43
x
12
20
15
14
25
6
4
19
27
43
x
12
20
15
y
7
14
25
6
4
19
27
43
x
12
20
15
y
7
14
25
7
6
4
19
27
43
x
12
20
15
8
14
25
y
null
7
6
4
19
27
43
x
12
20
15
14
25
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
8
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
8
7
6
4
6
8
Refers to node 8
20
7
8
14
12
43
15
25
Return node 7
6
8
Refers to node 8
20
7
8
14
12
43
15
25
6
7
Refers to node 8
8
20
8
14
12
43
15
25
6
7
Refers to node 8
8
20
8
14
12
43
15
25
Return node 6
19
27
20
8
43
8
14
12
15
25
6
7
8
27
8
14
20
43
12
15
25
6
7
8
27
8
14
20
43
12
15
25
Return node 4
Analysis
Height of a skew heap O(log n)
Maximum number of values stored in Stack
2 * O(log n) O(log n)
Total cost of merge O(log n)