0% found this document useful (0 votes)
22 views6 pages

02 2003 S Sol

1. The document provides the solution steps for 4 exam problems involving operations on binary search trees such as deletion, insertion, and rotations. 2. The first problem involves deleting and inserting keys into a binary search tree and performing left and right rotations to maintain the tree's structure. 3. The second problem involves two possible trees that could result from multiple deletions from an initial tree. 4. The third problem walks through inserting keys into an initially empty tree using insertion and rotations. 5. The fourth problem performs deletion, insertion, and rotation operations on two initially empty trees to arrive at a final solution tree for S and B.

Uploaded by

Grace Evangelene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

02 2003 S Sol

1. The document provides the solution steps for 4 exam problems involving operations on binary search trees such as deletion, insertion, and rotations. 2. The first problem involves deleting and inserting keys into a binary search tree and performing left and right rotations to maintain the tree's structure. 3. The second problem involves two possible trees that could result from multiple deletions from an initial tree. 4. The third problem walks through inserting keys into an initially empty tree using insertion and rotations. 5. The fourth problem performs deletion, insertion, and rotation operations on two initially empty trees to arrive at a final solution tree for S and B.

Uploaded by

Grace Evangelene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Exam02 solution.

Spring 2003

1.
(part a)

(after DecreaseKey)
min
|
V
1 15 19 2 13
/ | \ |
14 7 9 (T) 17(T)
| /
11 10
|
32

(part b)

14 7 9 15 19 2 13
| | |
11 10 17
|
32

2 7 9 15 14
| | | | |
13(F) 11 10 17 19(F)
|
32

2 9 14
/ | / | |
13(F) 7(F) 10 15 (F) 19(F)
| |
11(T) 17
|
32(T)

2 14
/ / | |
13(F) 7(F) 9(F) 19(F)
| / |
11(T) 10 15(F)
| |
32(T) 17(T)

2)
35
/ \
20 45 (1)
/ \ / \
14 30 40(-1) 50 (-1)
/ \ / \ / \ \
12 13 26 34 37 43 55
/ / ==
24 41
Part a:
delete 55.

35
/ \
20 45 (2)
/ \ / \
14 30 40(-1) 50(0)
/ \ / \ / \
12 13 26 25 37 43
/ /
24 41
R-1 Rotation

35 (1)
/ \
20 (-1) 43 (0)
/ \ / \
14 30 40(0) 45(-1)
/ \ / \ / \ \
12 13 26 34 37 41 50
/
24

Part b:
Insert 21
35 (1)
/ \
20 (-1) 45 (1)
/ \ / \
14 30 40 50
/ \ / \ / \ \
12 13 26(2)34 37 43 55
/ /
24 41
/
21

LL Rotation
35 (1)
/ \
20 (-1) 45 (1)
/ \ / \
14 30 40 50
/ \ / \ / \ \
12 13 24 34 37 43 55
/ \ /
21 26 41

Insert 28

35
/ \
20 45
/ \ / \
14 30(2) 40 50
/ \ / \ / \ \
12 13 24 34 37 43 55
/\ /
21 26 41
\
28

LR Rotation:

35
/
\
20 45
/ \ / \
14 26(-1) 40 50
/ \ / \ / \ \
12 13 24 30 37 43 55
/ / \ /
21 28 34 41

35 (0)
/ \
20 (-1) 45 (1)
/ \ / \
14(0) 26(0) 40(-1) 50(-1)
/ \ / \ / \ \
12(0) 13(0) 24(1) 30(0) 37(0) 43(1) 55
/ / \ /
21(0) 28(0) 34(0) 41

3. Two possibilities

(a)
6 4,8
/ \ / | \
3 9 2 6 10
/ \ / \ / \ / \ / \
1,2 4,5 7,8 10,11 1 3 5 7 9 11

(b) after the first deletion

6 8
/ \ / \
2 9 4,6 10
/ \ / \ / | \ / \
1 4,5 7,8 10,11 1,3 5 7 9 11

after the second deletion

5 7
/ \ / \
2 9 4 10
/ \ / \ / \ / \
1 4 7,8 10,11 1,3 5,6 9 11

4. (a)

I(10) I(7) LLb I(2)


12 ===> 12 ===> 12 ===> 10 ===> 10
// // // \\ // \\
10 10 7 12 7 12
// //
7 2

LLr 10 I(6) 10 LRb 10


===> / \ ===> / \ ===> / \
7 12 7 12 6 12
// // // \\
2 2 2 7
\\
6

I(9) 10 RRr 10
===> / \ ===> // \
6 12 6 12
// \\ / \
2 7 2 7
\\ \\
9 9

(b)
D(9) 5 D(10) 5
===> // \\ ===> // \\
2 8 2 7
/ \ / \ / \ / \
1 3 6 10 1 3 6 8
\\
7
(c)
Step 1. S=null, B=( 7 )

Step 2. S=null, B=join(B, 8, 9)


\\
10

B= 8 RRr 8
// \\ ===> / \
7 9 7 9
\\ \\
10 10

Step 3. S=join(2,5,S), B=same as that of step 2.

S= 2
/ \
1 3
\\
5

Final

S= 2 B = 8
/ \ / \
1 4 7 9
\\ \\
5 10

The End.

You might also like