Quiz1 Set1
Quiz1 Set1
Name:
2. Consider the following pseudo-code. Assume A is an array of storing n elements from A[0] to
A[n-1].
3. (4 points) Given a binary tree, you would like to output the sum of the depths of all the leaf
nodes. Assume that each node of the tree stores left child, right child, and parent values only.
Complete the following pseudocode, it is called with FindDepthSum(r,0), where r is the root.
FindDepthSum(p,d) returns an integer. The parameter p is the reference to a Node and the
parameter d is an integer.
if ( p is NULL )
return _____________ ;
else
return _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ;
}
Paper Set-1
Quiz 1. COL106 Page 2 of 2
6. (3 points) A tree has 10006 leaves. Half of the internal nodes have 3 children, and the other
half have 4 children each. How many nodes are there? Answer:
7. (2 points) What is the minimum number of nodes in an AVL tree of height 10?
Answer:
8. (4 points) Starting from an empty AVL tree, the following elements are inserted (in this order)
in the AVL tree: 6,9,10,3,2,1,8,7. You should use the rotation/balancing procedures described
in the class. Show the final AVL tree after the insert operations. After constructing the AVL
tree, delete the node containing element 1. Show the final tree.
9. (2 points) Suppose you have a doubly linked list and are allowed to use a constant amount of
other variables. You are maintaining a sequence of numbers using this doubly linked list, where
insert or delete can happen at either end. For each of the following operations, state whether
it can be done in constant time or not. (Yes/No)
Paper Set-1