80 likes | 171 Views
1. 7. 2. 5. 2. 1. 3. 1. 3. 3. 1. 4. 4. 1. L(T) = 19. W(T) = 19. Potential Function (part 1/2). 1+depth T (x) = # ancestors of x (including x) in T = access cost of x in T.
E N D
1 7 2 5 2 1 3 1 3 3 1 4 4 1 L(T) = 19 W(T) = 19 Potential Function (part 1/2) • 1+depthT(x) = # ancestors of x (including x) in T = access cost of x in T. • wT(x) = weight of x in T = # descendents of x (including x) in T = # nodes in the subtree rooted at x. • Candidate 1:Internal path length of T: L(T) = SxT (1+depthT(x)). • Candidate 2:Weight of T: W(T) = SxT wT(x). • FACT: (1) T L(T) = W(T). Why? • (2) As potentials, L(T) and W(T) are regular (i.e., always 0, L() = W() = 0). • (3) Q(n log n) L(T) = W(T) Q(n2), where n=|T|. • L(T) & W(T) can become too large. They won’t work!Dampen W(T) by a sublinear function, e.g., log.
F(n) = F(n-1) + log n = Q(n log n) F(n) = 2 F(n/2) + log n = Q(n) Potential Function (part 2/2) • Rank of x in T: rT(x) = log wT(x). • Potential:F(T) = SxTrT(x). • FACT:F(T) is also regular, and Q(n) F(T) Q(n log n).
log b log (a+b)/2 (log a + log b)/2 log a a (a+b)/2 b This makes the potential function work! The LOG LEMMA LEMMA 0: For any numbers a, b, c 1 a + b c log a + log b 2 log c – 2. Proof 1: c2 (a+b)2 = 4ab + (a-b)2 4ab. So, c2 4ab. Now take log. Proof 2: Logarithm is a concave function:
root x LEMMA 1: root y ZIG y x A C T B C ĉ 1 + 3[rT’ (x) – rT (x)] A B T’ ZIG LEMMA Proof:
z LEMMA 2: x ZIG-ZIG y y z x D A C ĉ 3[rT’ (x) – rT (x)] B A B C D T T’ ZIG-ZIG LEMMA Proof:
z LEMMA 3: ZIG-ZAG T’ y x D T ĉ 3[rT’ (x) – rT (x)] A B C x y z A B C D ZIG-ZAG LEMMA Proof:
z x root x LEMMA 1: root y y ZIG y y x z x D A A T C T B B C A ĉ 1 + 3[rT’ (x) – rT (x)] A B T’ C D B C T’ z LEMMA 2: ZIG-ZIG y x D T C ĉ 3[rT’ (x) – rT (x)] A B LEMMA 3: ZIG-ZAG x T’ y z ĉ 3[rT’ (x) – rT (x)] A B C D Lemmas on each Splay Step
Proof: Splay(x) operation is a sequence of splay steps: ci Tbefore = T0 Ti-1 Ti Tk = Tafter ĉi Fbefore = F0 Fi-1 Fi Fk= Fafter Amortized cost of Splay THEOREM 1: Amortized number of rotations by a Splay operation on an n-node BST is at most 3 log n + 1. only last splay step can be a ZIG