# sol2 - Massachusetts Institute of Technology Handout 6...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Massachusetts Institute of Technology Handout 6 6.854J/18.415J: Advanced Algorithms Wednesday, September 30, 2009 David Karger Problem Set 2 Solutions Wednesday, September 30, 2009 Collaboration policy: collaboration is strongly encouraged . However, remember that 1. You must write up your own solutions, independently. 2. You must record the name of every collaborator. 3. You must actually participate in solving all the problems. This is difficult in very large groups, so you should keep your collaboration groups limited to 3 or 4 people in a given week. 4. No bibles. This includes solutions posted to problems in previous years. Problem 1. (a) Heres the tree after splaying the leaf: x[n] \ x[1] / . . . / x[n - 3] / x[n - 2] / x[n - 1] Repeatedly splaying the leaf n/ 2 times will cost n/ 2 units of work each time. If we use zig-zig double rotations instead, the final structure is (when n is even): x[n] / x[2] / \ x[1] x[4] / \ x[3] x[6] / \ 2 Handout 6: Problem Set 2 Solutions x[5] . . . \ x[n - 2] / \ x[n - 3] x[n - 1] This splay has improved the tree by reducing the heights of n- o (1) nodes by a factor of about 2. Subsequent splays will take much less time than the first one because of this height reduction. (b) Observe first that the claim in the question is not true for n = 3; it is not possible to turn a zig-zig into a zig-zag by splaying (try it). Claim: For n 4, it is possible to turn any n node binary search tree into any other by a sequence of splay operations. Proof: We will prove this claim by induction on n . Base case: n = 4. We can turn the tree into a left path by splaying on the items in order. (It is easy to show this for all n by induction. The key observation is that the last step of each successive splay must be a zig or zig-zag, which pushes the root onto the left path.) This is true for all n It remains to check that we can turn a left path into anything: file=splay-4node.eps, width=6in Inductive step: We need to show that if it is possible to restructure any n- 1 node binary search tree into any other by a sequence of splay operations then the same is true for any n node binary search tree. We will accomplish this goal via the following four lemmas: Any node in a binary search tree with 4 nodes can be moved to a leaf position by an appropriate sequence of splay operations. A leaf node will remain a leaf node under a sequence of splay operations if it is not splayed. The structure of the tree containing the descendants of a node that is splayed has no effect on the structure of the tree that results. No two binary search trees on n nodes differ only in the position of one leaf node. By Lemma Problem 1 we can pick a node that is to become a leaf in the final tree and make it a leaf. Now Lemmas Problem 1 and Problem 1 say that this leaf will stay a leaf if we splay the other nodes, and will not affect the results of splaying on the other nodes. Thus by the inductive hypothesis we know that we can restructure the other...
View Full Document

## This note was uploaded on 11/24/2009 for the course CS 6.854/18.4 taught by Professor Davidkarger during the Fall '09 term at MIT.

### Page1 / 8

sol2 - Massachusetts Institute of Technology Handout 6...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online