examKEY - COP 3530 Summer 2002 Midterm Exam June 17, 2002...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1. (20 points) Shown below is a BST which has become unbalanced after a series of insertions and deletions. Rebalance the BST using the DSW algorithm. Clearly show the following in your answer: The initial backbone. The values of n and m as defined by the algorithm. The initial set of rotations (those which occur outside of the loop in the DSW algorithm). Show the rotations performed in each iteration of the algorithm leading to the perfectly balanced BST. Backbone is: Value of n = 9, m = 1 2 1 n 2 - + ) ( log = 2 3 -1 = 7 Number of initial rotations is given by n – m = 2 Thus, first rotate 18 about 15 and 32 about 22 1 COP 3530 – Summer 2002 Midterm Exam June 17, 2002 Name: 100 points total 3 2 1 3 1 4 6 5 4 KEY 1 1 2 3 3 4 4 5 6 1 1 2 3 4 4 5 6 1 1 2 3 3 4 5 0 6 9
Background image of page 1

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

View Full DocumentRight Arrow Icon
Backbone after initial 2 rotations First iteration causes m = 7/2 = 3 rotations 32 about 18, 45 about 35, and 50 about 47. Next iteration sets m = 3/2 = 1 rotation, 45 about 32 to produce the final perfectly balance tree. 2. (15 points) 2 1 2 1 3 3 4 5 6 1 2 1 3
Background image of page 2
Shown below is a splay tree. Assuming that a get(34) operation is performed on this tree. (a) Identify the splay node and its level in the tree, and (b) perform the splay operation and redraw the tree in the configuration that will result after the splay operation is completed. The search for 34 is unsuccessful, thus 31 becomes the splay node. The splay node is at level 6, thus it will require 2 two-level splay steps, and 1 one-level splay step to move the splay node to level 1 (the root level).
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/13/2011.

Page1 / 9

examKEY - COP 3530 Summer 2002 Midterm Exam June 17, 2002...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online