day8 2/4/98 ``I'd do it, but it probably doesn't work.''
1. Treaps, continued
1.1 timing analses for search
- p{i = ancestor(j)} = [1/( j-i+1)] with i £ j = number of right turns in descending the tree = In a random ordering
among {i,i+1,...,j} , the probability that i is first.
- p{i = ancestor(j)} = [1/( j-i+1)] with j £ i = number of left turns in descending the tree = In a random ordering
among {j,j+1,...,i} , the probability that i is first.
Then the expected number of ancestors of j is åi = 1n[1/( |j-i|+1)] £ 2åi = 1n1/i = 2*ln(n)
1.2 number of rotations in a delete.
The expected number of rotations in a delete is less than 2. The number of rotations
is less than the sum of the rightmost branch (right spine) of the left child
and the leftmost branch (left spine) of the right child.
analyse the right spine.
pi £ j{j = ancestor(i)Ùi Î rightspine} = random order of {i,...,j} with j first and i second = [1/( (j-i+1)(j-i))]
let size of right spine = Gj . Then E(Gj) = åi = 2j-1[1/( i(i-1))] = [(j-1)/( j)]
1.3 dynamic treaps
When a particular element is accessed adjust it's priority so the elements float
towards the top of the treap.
old p(k) uniform in [0,1] .
new p(k) = min(p(k),random Î [0,1])
2. Binomial and Fibonacci heaps
2.1 An algorithm using these structures
- G = (V,E) an undirected graph
- |V| = n
- |E| = m
- l:E® R+
- extend l as l(v,w) = ¥ if (v,w) Ï E , 0 if v = w , and l(e) where e = (v,w) otherwise
- P = path = e1,...,ek .
- l(P) = åi = 1kl(ei)
- d(u,v) = length of minimum weight path
2.1.1 Dijkstra's algorithm
- W = V-{s} , D(s) = 0
- "u Î W do D(u) = l(s,u)
- while W ¹ 0
- u = Extractmin(W,D)
- "(u,v) Î E with v Î W , D(v) = min(D(v),D(u)+l(u,v))
- endwhile
2.1.2 timing analyses
with a good data structure you can get:
|
2.2 binomial heap operations
- makeheap(i) O(1)
- findmin(h) O(1)
- insert(h,i) O(1)
- deletemin(h) O(log(n))
- meld(h,h') O(1) or O(log(n))
- decrement(h,i, D) (only efficient with fibonacci heaps) O(1)
- delete(h,i) (only efficient with fibonacci heaps) O(log(n))
2.3 definition of binomial trees
- B0 = 1 element tree
- B1 = 2 element tree with one a root of the other
- B2 = 4 element tree composed of 2 B1 trees joined at the root.
- In general |Bi| = 2i and the degree of the root node is i
Since the number of elements in each Bi doubles with i, you can have a heap of
arbitrariy (integer) size represented as a set of Bi trees of different sizes.
- a set of trees is in heap order if each tree is ordered and points to the min.
- rank(x)=# of children of x
2.4 operation implementations
2.4.1 meld(h,h')
Essentially, you just do binary addition between the sets of trees in h and
h'. The amortized cost of adding an element to the heap is 2.
File translated from TEX by TTH, version 1.30.
|