Professional Documents
Culture Documents
Binomial Tree
A binomial heap is a collection of binomial trees. Binomial tree Bk is an ordered tree defined recursively. The binomial tree B0 has one node. The binomial tree Bk consists of two binomial trees Bk-1 and they are connected such that the root of one tree is the leftmost child of the other. Binomial tree properties: Bk has 2^k nodes Bk has height k There are exactly ( ik ) nodes at depth i for i=0, 1, 2,,k. The root has degree k which is greater than other node in the tree. Each of the roots child is the root of a subtree Bi.
B0
B1
B2
B4
4 21 4 5 7 9 14 32 23 22 11 6
34
31 33
10
12 3
10
13
15 10 12
15
16
c)
NIL 2 0 head[H]
NIL
degree
child
sibling
NIL 1 2
NIL
b)
head[H] 2 1 10 1
NIL
12 0
NIL
10
12 15 0
NIL
NIL
15
Run time: The run time is in the order of O(log n) since the most number of roots in binomial heap is |_(log n)_| +1
b)
head[H] 2 5 1
10
12
10
12
15
15
c)
head[H] 2 5 1
d)
head[H] 2 5 1
10
12
10
12
15
15
a)
11
head[H2]
20
10
12
15
b)
head[H1]
11
20
10
12
15
c)
head[H1]
11
10
12
20
15
d)
head[H1]
10
12
11
15
20
12
child parent
7
sibling
Run time: The running time is O (log n) The total number of combined roots is at most |_logH1_| + |_logH2_| +2. Binomial-Heap-Merge is O (log n) + the while loop is O (log n). Thus, the total time is O(log n).
Pseudocode:
Binomial-Heap-Insert(H,x) 1 H <- Make-Binomial-Heap() 2 p[x] <- NIL 3 child[x] <- NIL 4 sibling[x] <- NIL 5 degree[x] <- 0 6 head[H] <- x 7 H <- Binomial-Heap-Union(H,H)
head[H]
head[H]
10
12
15
head[H]
10
12
15
10
12 3
10
12
15 10 12
15
15 head[H]
10
12
10
12
10
12
15
15
15
7 2
10
12
15
10
12
15
15
head[H] 12 5
10
7 2
10
12
15 10 12
15
15
Decreasing a key
The current key is replaced with a new key. To maintain the min-heap property, it is then compared to the key of the parent. If its parents key is greater then the key and data will be exchanged. This process continues until the new key is greater than the parents key or the new key is in the root. Pseudocode:
Binomial-Heap-Decrease-Key(H,x,k) 1 if k > key[x] 2 then error new key is greater than current key 3 key[x] <-k 4 y <-x 5 z <-p[y] 6 while z not NIL and key[y] < key[z] 7 do exchange key[y] <-> key[z] 8 if y and z have satellite fields, exchange them, too. 9 y <- z 10 z <- p[y]
Decreasing a key
Execution time: This procedure takes O(log n) since the maximum depth of x is |_log n_|. Example:
head[H] 5 2 head[H] 5 2
10
12
10
12
15
head[H]
head[H]
12
12
10
10
Delete a Node
With assumption that there is no node in H has a key of -. The key of deleting node is first decreased to -. This node is then deleted using extracting min procedure. Pseudocode: (from book) Binomial-Heap-Delete(H,x) 1 Binomial-Heap-Decrease-Key(H,x,-) 2 Binomial-Heap-Extract-Min(H) Run time: O(log n) since the run time of both Binomial-Heap-Decrease-Key and Binomial-Heap-Extract-Min procedures are in order of O(log n).
b)
5 2
10
12
12
15
15
c)
head[H] 5
d) -
2 12 head[H] 5
head[H]
12
15
15
f)
5 2
15
12
15
g)
head[H] 2
15
12
Insert
Minimum Extract-Min Union Decrease-Key Delete
O (log n)
O (log n) O (log n) O (log n) O (log n) O (log n)
O (log n)
O (1) O (log n) O (n) O (log n) O (log n)
Applications
The binomial heap is used in an event-driven simulator. It is also used in the applications that need to find the minimum-spanningtree such as electronic circuit design.
References
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Revest, and Clifford Stein, Introduction To Algorithms, McGraw-Hill Higher Education, second edition, 2001