CT DFS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

INDIAN STATISTICAL INSTITUTE

CLASS TEST
M.TECH(CS) IYEAR
DATA STRUCTURES

Date: 14.11.2022 Maximum marks: 40 Duration: 1hour.

1. Give an algorithm to find the 3rd smallest clement in a binary min-hcap in constant
time 3)
2. State what you mean by AVL property ofa node. Show that an
AVL tree withn nodes should
have O(lg n) height.
2+5=7]
3. Consider a binary search tree whOse nodes are labeled by A, B, C, D, E, F,G, H.
and pre-order travaersal of the tree yeilds the following sequence of
The in-order
nodes:
In-order: H, D, I, B, E, J, A, F, C, G, K
Pre-order: A, B, D, H, I, E, J,C, F, G, K
Answer the following questions. You need not provide explanations.
(a) Draw the tree.
(b) Assume that the tree is a valid binary search tree. What is the successor of node A.
(c) Is the tree an AVL tree?
(d) Re-draw the tree after deleting node C.
(e) Is this new tree an AVL tree?

5+1+1 +2 +l= 10)


4. Consider a binary search tree, in which in addition to the standard fields (data, left and right)
cach node has an integer field called size, which storcs the number of clements in the subtree
rooted at this node. In a range query we are given two key values T], T2, Where z; < T2x
and wish to return a count of the number of nodes in the tree whose key value zsatisfies
Z <r< T), Give pseudocode for this operation, and briefly explain how your algorithm
works. Your algorithmshould run in O(h) time, where his the height of the tree.
|10)
5. Consider a binary search tree implementat ion where each node have a key, a parent pointer
and left and right child pointers. Given a node X in the tree, write a routine which does
single right rotation at X. Adjust all pointers (including the parent pointers) appropriately.
|10)
(8 -12) (21)

You might also like