Uploaded by b10202013

homework2

advertisement
Data Structure
Homework #2
Due Oct 26, 2023 before class.
Collaboration policy: You may discuss the problem with other students, but you must obtain and
write the final solution by yourself. Please specify all of your collaborators (name and student id)
for each question. If you solve some problems by yourself, please also specify ”no collaborators”.
Homeworks without collaborator specification will not be graded.
(In all problems, assume that all keys are distinct.)
Problem 1 (20%)
Suppose we use a binary search tree to store data. Starting from an empty tree, insert 1, 2, 3, . . . , 8
sequentially, the resulting configuration is C1 . Delete the node with key 5, the resulting configuration is
C2 .
1. Describe the structure of the binary search tree for configurations C1 and C2 .
2. Repeat the above for AVL trees.
3. Repeat the above for 2,3-trees.
4. Repeat the above for 2,4-trees. (Top down insertion / deletion)
5. Repeat the above for red-black trees. (bottom-up insertions)
(No explanation is needed. You only need to describe the structure of the trees, the key(s) on each
node, and the color of the nodes for the red-black trees.)
Problem 2 In a binary search tree, there are two nodes x, y with key(x) < key(y). Suppose that a is
a node in the subtree rooted at x and b is a node in the subtree rooted at y.
1. (5%) Is it always true that key(a) < key(b)? Prove your answer.
2. (10%) Suppose that the subtree rooted at x and the subtree rooted at y are disjoint. Is it always
true that key(a) < key(b)? Prove your answer.
Problem 3 (10%) What is the maximum and minimum number of nodes in a B-tree with height h
(h-levels of nodes)?
1
Problem 4 For each of the following statements, you must either prove the statement or provide a
counter example with brief explanation:
1. (5%) In an AVL tree with n nodes, at most n/2 nodes have exactly one child.
2. (5%) In a binary search tree with n nodes, if at most n/2 nodes have exactly one child, then the
tree must have height O(log n).
3. (5%) In a binary search tree, if two nodes x and y are both leaf nodes, then y is not a successor of
x.
4. (5%) In a 2,3-tree, if y is a successor of x and these two keys belong to different nodes, then one
of them must belong to a leaf node.
5. (5%) In a red-black tree, at most n/2 nodes are red.
6. (5%) In a red-black tree, at least n/3 nodes are black.
7. (5%) Starting from an empty red-black tree, insert 1, 2, . . . , n sequentially using bottom-up insertion. The resulting tree must have at least one red node for all n ≥ 2.
(Do not count external nodes when counting the number of nodes in a red-black tree.)
Problem 5 (20%) In a skip list, we define a data node to be a node that is not the header or sentinel.
A skip list is good if, for any two data nodes with the same height, there must be a node in between
with larger height. Prove or find a counter example: Search operations in good skip lists only need to
check/follow at most 2h pointers, where h is the height of the header.
2
Download