1 / 24

Bottom-Up Splay Trees–Analysis

Bottom-Up Splay Trees–Analysis. Actual complexity of search, insert, delete, and split is O(n) . Actual complexity of join is O(1) . Amortized complexity of search, insert, delete, join, and split is O(log n). Potential Function. size(x) = #nodes in subtree whose root is x .

Download Presentation

Bottom-Up Splay Trees–Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bottom-Up Splay Trees–Analysis • Actual complexity of search, insert, delete, and split is O(n). • Actual complexity of join is O(1). • Amortized complexity of search, insert, delete, join, and split is O(log n).

  2. Potential Function • size(x) = #nodes in subtree whose root is x. • rank(x) = floor(log2 size(x)). • P(i) = Sx is a tree node rank(x). • P(i) is potential after i’th operation. • size(x) and rank(x) are computed after i’thoperation. • P(0) = 0. • When join and split operations are done, number of splay trees > 1 at times. • P(i) is obtained by summing over all nodes in all trees.

  3. 20 10 40 6 30 8 Example 6 2 • size(x) is in red. 3 1 2 1 2 1 1 0 1 0 • rank(x) is in blue. • Potential = 5.

  4. 6 2 20 3 1 2 1 10 40 2 1 1 0 6 30 1 0 8 Root Rank • rank(root) <= floor(log2 n) • n is total number of operations

  5. m S B Join • Actual complexity = 1 • Rank of root is <= floor(log2 n). • Other ranks unchanged. • Potential increases by <= floor(log2 n). • amortized complexity = actual complexity + DP <= 1 + floor(log2 n)

  6. Other Operations • actual complexity = # of splay steps • amortized complexity = actual complexity + DP = # of splay steps + DP

  7. Splay Step Potential Change • If q = null or q is the root, do nothing. • DP = 0.

  8. q p a p q c b c a b 1-Level Move • Do a one-level move. • r(x) = rank of x before splay step. • r’(x) = rank of x after splay step.

  9. q p a p q c b c a b 1-Level Move • DP = r’(p) + r’(q) – r(p) – r(q) <= r’(q) – r(q).

  10. q gp a p p d b gp q c c d a b 2-Level Move (case 1) • DP = r’(gp) + r’(p) + r’(q) – r(gp) – r(p) – r(q)

  11. q gp a p p d b gp q c c d a b 2-Level Move (case 1) • r’(gp) <= r’(q) • r (q) <= r(p) • r’(q) = r(gp) • r’(p) <= r’(q)

  12. 2-Level Move (case 1) • DP = r’(gp) + r’(p) + r’(q) – r(gp) – r(p) – r(q) • r’(q) = r(gp) • r’(gp) <= r’(q) • r’(p) <= r’(q) • r (q) <= r(p) • DP <= r’(q) + r’(q) – r(q) – r(q) = 2(r’(q) – r(q))

  13. 2-Level Move (case 1) A more careful analysis reveals that DP <= 3(r’(q) – r(q)) –1

  14. 2-Level Move (case 2) • Similar to Case 1.

  15. Only 1-Level Moves • Suppose that the splay node q is initially at level L > 1. • Let r(q,j) be the rank of q when it is at level j following/preceding a splay step. • When only 1-level moves are made, DP <= S2<=j<=L(r(q,j-1)-r(q,j)) = r(q,1)-r(q,L)

  16. Search With Only 1-Level Moves • amortized complexity = # of splay steps + DP <= L-1+r(q,1)-r(q,L) <= n-1+floor(log2n) = O(n)

  17. Correct Splay • Make as many 2-level moves as possible. A 1-level move is made at the end if necessary. • When L is odd, floor(L/2)2-level moves are made; there is no 1-level move. • Single 2-level move DP <= 3(r’(q) – r(q)) –1 • For complete splay DP <= 3(r(q,1)-r(q,L))-floor(L/2) = 3(r(q,1)-r(q,L))- # of splay steps

  18. Correct Splay • When L is even, L/2-12-level moves are made; there is also one 1-level move. • Single 2-level move DP <= 3(r’(q) – r(q)) –1 • Single 1-level move DP <= r’(q) – r(q) <= 3(r’(q) – r(q)) • For complete splay DP <= 3(r(q,1)-r(q,L))- # of splay steps+1 DP <= S2<=j<=L(r(j-1)-r(j)) = r(1)-r(L)

  19. Correct Splay • So, regardless of the value of L DP <= 3(r(q,1)-r(q,L))- # of splay steps+1 <= 3floor(log2n)-# of splay steps+1

  20. Search With Correct Splay • amortized complexity = # of splay steps + DP <= # of splay steps +3floor(log2n)-# of splay steps+1 = 3floor(log2n)+1 = O(log n)

  21. Insert 7 4 • On every leaf to root path ranks are non-decreasing. • At most floor(log2 n)+1 different ranks on such a path. • Insert may increase the rank of only the last node in each sequence of equal rank nodes (view sequence from bottom to top). • When you insert, potential increases by up to floor(log2 n)+1. 4 4 1 1 0

  22. Insert With Correct Splay • total potential change caused by an insert <=floor(log2n)+1 +3floor(log2n)-# of splay steps+1 • amortized complexity = # of splay steps + DP <= 4floor(log2n)+2 = O(log n)

  23. Delete With Correct Splay • total potential change caused by a delete <=3floor(log2n)-# of splay steps+1 • amortized complexity = # of splay steps + DP <= 3floor(log2n)+1 = O(log n)

  24. Split With Correct Splay • total potential change caused by a split <=3floor(log2n)-# of splay steps+2 • amortized complexity = # of splay steps + DP <= 3floor(log2n)+2 = O(log n)

More Related