10 Binomial Heap
10 Binomial Heap
Bk
B0 B0 B1 B2 B3
Bk-1 Bk-1
Binomial Heaps
A binomial heap,
heap H, is a set of binomial trees that satisfies the
following binomial-heap properties.
1. Each binomial tree in H is heap-ordered:
heap-ordered the key of a node is greater
than or equal to the key of its parent
- the root of a heap-ordered tree contains the smallest key in a
given sub-tree
2. There is at most one binomial sub-tree in H whose root has
a given degree
- there are at most log(n) + 1 binomial sub-trees.
Proof: Binary representation of n,< b(logn), b(logn–1), …, b0 > can be given
by: i = logn
n = Σ (bi2i)
I=0
x: key
head[x]: pointer to the root (if NIL, binomial heap is empty)
p[x]: pointer to the parent(if x is the root, then NIL)
child[x]: leftmost child (if node has no children,then NIL)
sibling[x]: sibling of x immediately to its right (rightmost child of
parent, then NIL)
Why Binomial Heaps?
Make-Binomial-Heap()
AIM: to merge two trees until there is no more than 1 sub- tree
of a certain degree.
Binomial-Heap-Union
H1 H2
x next-x
H
Binomial-Heap-Union
prev-x x next-x
H
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’)
Running time:
Make-Binomial-Heap() = O(1)
Binomial-Heap-Union = O(logn)
Binomial-Heap-Decrease-Key
-decreases the key of a node x in a binomial heap H to a new
value k
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. yx
5. z p[y]
6. while z ≠ 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. yz
z p[y]
Applications
http://wwwcsif.cs.ucdavis.edu/~fletcher/classes/110/lecture_
notes.html
http://www2.ics.hawaii.edu/~sugihara/course/ics311s00/pla
n.html