Documente Academic
Documente Profesional
Documente Cultură
binary heaps
d-ary heaps
binomial heaps
Fibonacci heaps
A* search.
Heapsort.
Online median.
Huffman encoding.
Prim's MST algorithm.
Discrete event-driven simulation.
Network bandwidth management.
Dijkstra's shortest-paths algorithm.
http://younginc.site11.com/source/5895/fos0092.html
3
P RIORITY Q UEUES
binary heaps
d-ary heaps
binomial heaps
Algorithms
F O U R T H
E D I T I O N
SECTION 2.4
Fibonacci heaps
Binary heap
Binary heap. Heap-ordered complete binary tree.
Heap-ordered tree. For each child, the key in child key in parent.
6
parent
10
child
21
12
18
17
child
11
25
19
10
12
21
18
17
11
25
19
last
next
6
2
10
12
18
11
25
10
21
17
19
10
10
12
18
11
25
21
17
19
11
12
13
14
15
16
heap ordered
6
10
12
21
18
17
11
25
19
10
6
10
12
21
18
17
19
11
25
add key to heap
(violates heap order)
6
7
12
21
10
17
19
11
18
25
swim up
11
6
7
12
21
10
17
11
18
19
25
exchange
with root
sink down
violates
heap order
18
7
10
17
10
12
21
19
11
6
25
remove
from heap
12
21
18
17
19
11
25
12
10
12
21
18
17
11
25
19
13
Each heap op touches nodes only on a path from the root to a leaf;
the height of the tree is at most log2 n.
14
root
10
12
21
17
11
25
15
delete node x or y
6
10
12
11
25
y
21
17
9
last
16
H1
H2
10
12
21
17
11
25
17
14
12
10
11
22
26
11 22
15
12
22
26
14
11
15
22
10
11
18
h+1
n/2
log
h=0
2n
2
h=0
n h / 2h
n / 2h+1 h
log
h=0
2n
2
nh=0
n h / 2h
h / 2h
h=1
= n2n h / 2h
h=1
k
i=1
i
= 2
2i
k
2k
1
2k
= 2n
19
operation
linked list
binary heap
MAKE-HEAP
O(1)
O(1)
ISEMPTY
O(1)
O(1)
INSERT
O(1)
O(log n)
EXTRACT-MIN
O(n)
O(log n)
DECREASE-KEY
O(1)
O(log n)
DELETE
O(1)
O(log n)
MELD
O(1)
O(n)
FIND-MIN
O(n)
O(1)
20
operation
linked list
binary heap
binary heap
MAKE-HEAP
O(1)
O(1)
O(1)
ISEMPTY
O(1)
O(1)
O(1)
INSERT
O(1)
O(log n)
O(log n)
EXTRACT-MIN
O(n)
O(log n)
O(1)
DECREASE-KEY
O(1)
O(log n)
O(log n)
DELETE
O(1)
O(log n)
O(1)
MELD
O(1)
O(n)
O(n)
FIND-MIN
O(n)
O(1)
O(1)
amortized
21
P RIORITY Q UEUES
binary heaps
d-ary heaps
binomial heaps
Algorithms
F O U R T H
E D I T I O N
SECTION 2.4
Fibonacci heaps
23
d-ary heap
d-ary heap. Heap-ordered complete d-ary tree.
Heap-ordered tree. For each child, the key in child key in parent.
30
80
82
32
20
10
34
55
22
34
46
20
40
90
24
30
80
82
32
20
10
34
55
22
34
46
20
40
90
25
30
80
82
32
20
10
34
55
22
34
46
20
40
90
26
30
80
82
32
20
10
34
55
22
34
46
20
40
90
27
operation
linked list
binary heap
d-ary heap
MAKE-HEAP
O(1)
O(1)
O(1)
ISEMPTY
O(1)
O(1)
O(1)
INSERT
O(1)
O(log n)
O(logd n)
EXTRACT-MIN
O(n)
O(log n)
O(d logd n)
DECREASE-KEY
O(1)
O(log n)
O(logd n)
DELETE
O(1)
O(log n)
O(d logd n)
MELD
O(1)
O(n)
O(n)
FIND-MIN
O(n)
O(1)
O(1)
28
P RIORITY Q UEUES
binary heaps
d-ary heaps
binomial heaps
Fibonacci heaps
operation
linked list
binary heap
d-ary heap
MAKE-HEAP
O(1)
O(1)
O(1)
ISEMPTY
O(1)
O(1)
O(1)
INSERT
O(1)
O(log n)
O(logd n)
EXTRACT-MIN
O(n)
O(log n)
O(d logd n)
DECREASE-KEY
O(1)
O(log n)
O(logd n)
DELETE
O(1)
O(log n)
O(d logd n)
MELD
O(1)
O(n)
O(n)
FIND-MIN
O(n)
O(1)
O(1)
30
Binomial heaps
Programming
Techniques
I. Introduction
In order to design correct and efficient algorithms for
solving a specific problem, it is often helpful to describe
our first approach to a solution in a language close to
that in which the problem is formulated. One such
language is that of set theory, augmented by primitive
set manipulation operations. Once the algorithm is outlined in terms of these set operations, one can then look
for data structures most suitable for representing each of
the sets involved. This choice depends only upon the
collection of primitive operations required for each set.
Binomial tree
Def. A binomial tree of order k is defined recursively:
Order 0:
Order k:
single node.
one binomial tree of order k 1 linked to another of order k 1.
B0
Bk
Bk-1
Bk-1
B0
B1
B2
B3
B4
32
Its height is k.
It has !2k "nodes.
It has ki nodes at depth i.
The degree of its root is k.
Deleting its root yields k binomial trees Bk1, , B0.
Bk+1
B2
B1
B0
Bk
B4
33
Binomial heap
Def. A binomial heap is a sequence of binomial trees such that:
45
55
30
23
32
24
22
48
29
10
31
17
44
37
18
50
B4
B1
B0
34
root
31
17
44
37
18
50
48
50
binomial heap
18
37
29
le
48
nt
e
r
pa
ft
10
ht
rig
29
10
31
17
44
The node containing the min element is a root of B0, B1, , or Bk.
It contains the binomial tree Bi iff bi = 1, where bk b2 b1 b0 is binary
representation of n.
45
55
30
23
32
24
22
29
48
31
10
44
37
18
n = 19
# trees = 3
height = 4
binary = 10011
17
50
B4
B1
B0
36
45
55
30
23
32
24
22
48
29
10
31
17
44
50
H1
H2
37
8
30
45
55
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
41
38
12
18
8
30
45
55
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
41
39
12
37
18
25
8
30
45
55
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
41
12
18
40
28
15
33
25
37
12
37
18
25
41
8
30
45
55
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
41
12
18
41
28
15
33
25
37
12
37
18
25
41
8
30
45
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
55
41
28
15
33
25
12
37
18
41
42
28
15
33
25
37
12
37
18
25
41
8
30
45
32
23
22
24
48
29
10
31
17
44
37
15
33
25
18
12
50
28
55
41
45
55
30
23
32
24
22
48
50
29
10
31
17
44
28
15
33
25
12
37
18
41
43
8
30
45
32
23
24
22
48
29
10
31
17
44
37
15
33
25
18
12
50
28
55
41
19 + 7 = 26
0
44
19 + 7 = 26
0
45
45
30
23
32
24
22
48
29
10
31
17
44
37
18
50
55
46
45
30
23
32
24
22
48
29
10
31
17
44
18
37
50
H'
55
47
30
23
32
24
22
48
29
10
31
17
44
37
18
50
55
48
DECREASE-KEY(H, x, -).
DELETE-MIN(H).
Running time. O(log n).
45
30
23
32
24
22
48
29
10
31
17
44
37
18
50
55
49
H' MAKE-HEAP( ).
H' INSERT(H', x).
H MELD(H', H).
Running time. O(log n).
45
30
23
32
24
22
48
29
10
31
17
44
37
18
H'
50
55
50
If n =
If n =
If n =
If n =
44
37
48
29
10
31
17
50
k
i=1
i
= 2
2i
2
k
2k
1
2k
1
51
(H0) = 0.
(Hi) 0 for each binomial heap Hi.
Case 1. [INSERT]
52
(H0) = 0.
(Hi) 0 for each binomial heap Hi.
Case 2. [ DECREASE-KEY ]
O(log n).
53
(H0) = 0.
(Hi) 0 for each binomial heap Hi.
Case 3. [ EXTRACT-MIN or DELETE ]
= O(log n).
54
operation
linked list
binary heap
binomial heap
binomial heap
MAKE-HEAP
O(1)
O(1)
O(1)
O(1)
ISEMPTY
O(1)
O(1)
O(1)
O(1)
INSERT
O(1)
O(log n)
O(log n)
O(1)
EXTRACT-MIN
O(n)
O(log n)
O(log n)
O(log n)
DECREASE-KEY
O(1)
O(log n)
O(log n)
O(log n)
DELETE
O(1)
O(log n)
O(log n)
O(log n)
MELD
O(1)
O(n)
O(log n)
O(1)
FIND-MIN
O(n)
O(1)
O(log n)
O(1)
homework
amortized