Algorithms and Data Structures Winter Term 2013/14 Exercises for

advertisement
Algorithms and Data Structures
Winter Term 2013/14
Exercises for Unit 15
1. The Generalized Access Lemma for splay trees can be formulated as follows: For any
assignment of non-negative weights to the nodes, the amortized cost of a single rotation at
any node x is at most 1 + 3r0 (x) − 3r(x), and the amortized cost of a double rotation at any
node x is at most 3r0 (x) − 3r(x).
Prove the Generalized Access Lemma for the zig-zig double-rotation case.
2. The Static Optimality Theorem for splay treesP
can be formulated as follows: Suppose each
node is accessed at least t(x) times, and let T = x t(x). The amortized cost of accessing x
is O(log T − log t(x)).
Prove the Static Optimality Theorem.
Hint: When using the Generalized Access Lemma, the proof of this theorem is very short.
3. The idea of splay trees is to restructure the tree along the path from the root to the accessed
element every time that an element is accessed. Consider using the following algorithm that
uses only single rotations for such a restructuring instead of using the splay operation. That is,
we apply MoveToRoot(v) after every insert, delete, and search operation to bring the accessed
element v to the root of the tree.
Algorithm 1: MoveToRoot(v)
1
2
3
while v is not the root do
rotate (v, parent(v))
end
a) To gain a deeper understanding of splay trees, look for splay tree animations online and
experiment with them.
b) Execute the MoveToRoot(v) method and the splay method for node 1 on example (b).
Which gives the more balanced result?
c) Consider the search sequence 1, 2, . . . , n−1, n in example (c) when using the MoveToRoot
method. What is the amortized cost of these n search operations?
n
5
4
n−1
3
n−2
2
n−3
1
1
(b)
(c)
1
Download