CSCI
151 – Data Structures – Practice Midterm Exam- Spring 2007
Dr. Melody Stapleton Name______________________________________
100
points possible. Points are listed before each problem in
parentheses.
READ
AND FOLLOW ALL TEST DIRECTIONS CAREFULLY.
SHOW ALL WORK. TEST IS OPEN BOOK
AND NOTES. SPREAD OUT WITH AT LEAST ONE SEAT BETWEEN YOU AND YOUR
NEIGHBOR. NO TALKING OR GAZING AT OTHERS
EXAMS. EXPLAIN ALL ASSUMPTIONS. ATTACH WORKSHEETS IF ANY AT THE BACK OF THE
EXAM.
1. (20
points, 5 points for each subpart) For the AVL tree pictured below show the
result of performing the following operations.
Be sure that you always start
with the original tree iN ORDER TO ANSWER THE QUESTION. When asked to delete a node that has
more than one child, use the immediate predecessor in the deletion algorithm.

a)
INSERT 120
b)
DELETE 100
c)
DELETE 80
d)
DELETE 200
2. (20points, 5 for each subpart) For the B-tree of order 3 given below, show the result of performing the given operations. BE SURE IN ANSWERING THIS QUESTION THAT YOU ALWAYS BEGIN WITH THE ORIGINAL TREE, NOT ANY OF YOUR ANSWERS TO THE OTHER SUBPARTS. Draw the resultant tree after performing each operation. Do not attempt to delay splits on inserts (the same as Kruse’s approach to inserts). When deleting from a node that has multiple children, borrow from the immediate successor.

a.
INSERT 48
b.
DELETE 10
c.
DELETE 40
d.
DELETE 25
F 0001011
M 1111010
C 1001111
R 1001101
X 0000111
4.
(20 points) Build a Radix Search Tree by inserting the values given below into
an initially empty tree. Draw the
resulting Radix Search Trie after deleting the following values from the
original Radix Search Trie shown below. Work with the original tree for each delete
operation.
Note: Here are the codes for the elements of this
tree –
B 101101
X 000011
D 000111
E 101110
V 001101
M 101001
a) (10 points) Build the tree
b) Delete X
c) Delete B
5. (20
points) Build a Patricia Tree by inserting the following values into and
initially empty Patricia Tree. Draw the
resulting Patricia tree after deleting the following values from the original
Patricia tree you build. Work with the original tree for each delete
operation.
Note: Here are the codes for the elements of this
tree –
bit 543210
B 101010
X 101001
D 000111
E 111101
V 011100
P 101011
a)Build
the Patricia Tree (10 points)
b)Delete
B (5 points)
c)
Delete E (5 points)
6.
(10 points) Write a class member function in C++ for a Binary_Search_Tree class
that finds the numeric median value (for a tree that stores integers) of all
the values stored in the tree. The
function should accept the root of the tree as a parameter and also the size of
the tree in terms of the number of nodes as a parameter. You can assume that the size value was obtained
by calling an already existing function prior to calling this function you are
writing. The median of a list of values is
defined to be the value that would be in the middle of that list when it is
sorted. Recall that for a Binary Search
Tree, an inorder traversal will give the values in the tree in sorted
increasing order. For an odd number of
values for such a sorted list, the median would be the n/2+1 element to appear
in the sorted list. For an even number
of values for such a sorted list, using n/2+1 also works for the position of
the median value. E.g., if there are 11
values in the tree, the 11/2+1 th value would be the 6th value,
right in the middle of the list. For a
tree with 12 values, either the 6th or 7th position could
be used for the median, so use the 12/2+1 =7th position.
Hint: Perform an inorder traversal on the tree while keeping count of
how many nodes you have visited. When
you get to the median, return that value in the function. E.g., for the tree picture below, this function
should return the numeric value of 30.