hw1KEY - COP 3530 Homework Problems #1 Summer 2002 SOLUTION...

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

View Full Document Right Arrow Icon
COP 3530 – Homework Problems #1 – Summer 2002 SOLUTION KEY 1. Shown below is a BST which is unbalanced. Use the DSW algorithm to create a perfectly balanced version of this tree. Show all intermediate steps in both the creation of the backbone as well as the rotations that will occur to convert the backbone into the perfectly balanced tree. Part 1: Establishing the backbone. To see the creation of the backbone, see page 10. Part 2: Perform required number of initial rotations. There are 12 nodes in this tree so n = 12. m = 2 log 2 (n+1) - 1; m = 2 log 2 (12+1) - 1 = 2 3 -1 = 7 Perform a total of n – m = 12 – 7 = 5 initial rotations on the backbone. 1 45 40 55 25 15 35 85 30 38 70 65 60 15 25 30 35 38 40 45 55 60 65 70 85 15 25 30 35 38 40 45 55 60 65 70 85
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 above) produces the following backbone. The backbone after the initial rotations Part 3: Perform required number of rotations to perfectly balance the tree. Since m=7 and its value is halved after every rotation and rotation stops when m=1, we will perform a total of 4 rotations (when m = 7 do 3: 35 about 25, 55 about 40, and 70 about 65, when m = 3 do 1: 55 about 35). First 3 rotations
Background image of page 2
Image of page 3
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 / 15

hw1KEY - COP 3530 Homework Problems #1 Summer 2002 SOLUTION...

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

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