Docsity

Binary Search Tree Assignment - Part 3, Assignments of Algorithms and Programming

Toggle sidebar
bg1
Assignment 3 (Binary Search Trees) โ€” KEY
Due: Tuesday, 13 February 2007
50
30
70
10
40
80
60
20
1. Consider the binary search tree shown above.
a. What tree results after you insert the nodes 65, 75, 43, 47, 35, and 25 in
that order. Note: not an AVL tree; a Binary Search Tree.
50
30
70
10
40
80
60
20
65
75
43
47
25
35
pf2

Partial preview of the text

Download Binary Search Tree Assignment - Part 3 and more Assignments Algorithms and Programming in PDF only on Docsity!

Assignment 3 (Binary Search Trees) โ€” KEY

Due: Tuesday, 13 February 2007

30 50 70 10 40 80 20 60

1. Consider the binary search tree shown above. a. What tree results after you insert the nodes 65 , 75 , 43 , 47 , 35 , and 25 in that order. Note: not an AVL tree; a Binary Search Tree. 30 50 70 10 40 80 20 60 65 75 43 47 25 35

b. After inserting the nodes mention in Part a , what tree results when you delete node 40 using the following strategies? i. Show the Part a tree after the deletion if the in-order predecessor is used as the replacement for the deleted node. 30 50 70 10 35 80 20 60 65 75 43 47 25 ii. Show the Part a tree after the deletion if the in-order successor is used as the replacement for the deleted node. 30 50 70 10 43 80 20 60 65 75 25 35 47

2. Suppose that you traverse the binary search tree as it is given above (i.e., before the changes) and write the data item in each node visited to a file. You plan to read this file later and create a new binary search tree using the binary search tree operation insert. In creating the file, in what order (of the ones that we covered) should you traverse the tree so that the new tree will have exactly the same shape and nodes as the original tree? What does the file look like after the original tree is traversed. [Hint: ask yourself where the root must occur in this data file.] You can either use a pre-order traversal or a level-order traversal. Pre-order file: 40 20 10 30 60 50 80 70 Level-order file: 40 20 60 10 30 50 80 70