1. EE693 DATA STRUCTURES AND ALGORITHMS
QUIZ-GT-1 EXAMINATION
14 OCTOBER, 2014, Time: 1 Hours
EEE Department, IIT Guwahati
NOTE: Attempt and solve all the questions. Question-1 to Question-10 are objective questions (only one choice is
correct). Use of any kind of electronic media other than calculators are strictly prohibited. If anybody finds
voiding this rule will be penalized with -10 marks penalty. Please do not forget to mention your Name and
Roll No in the paper sheet. Please tick the correct choice. All the questions are of 2 marks. For any
wrong answer penalty of -1 marks will be imposed.
Name: Roll No:
1. This is the welcome question! All the best for EE693 Quiz-1 (GT).
In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree
with n internal nodes is
(a) nk (b) (n-1)k+1 (c) n(k-1)+1 (d) n(k-1)
2. The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of
nodes in a binary tree of height h is:
(a) 2h
− 1 (b) 2(h−1)
− 1 (c) 2(h+1)
− 1 (d) 2 × (h + 1)
3. Postorder traversal of a given binary search tree, T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15,
50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an in-order traversal of the tree
T?
(a) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
(b) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(c) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(d) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29
4. Following function is supposed to calculate the maximum depth or height of a Binary tree – the number of nodes
along the longest path from the root node down to the farthest leaf node.
int maxDepth(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the depth of each subtree */
int lDepth = maxDepth(node->left);
int rDepth = maxDepth(node->right);
/* use the larger one */
if (lDepth > rDepth)
return X;
else return Y;
}
}
(a) X = lDepth, Y = rDepth
(b) X = lDepth + 1, Y = rDepth + 1
(c) X = lDepth - 1, Y = rDepth -1
(d) None of the above
2. 5. Following is C like pseudo code of a function that takes a Queue as an argument, and uses a stack S to do processing.
void fun(Queue *Q)
{
Stack S; // Say it creates an empty stack S
// Run while Q is not empty
while (!isEmpty(Q))
{
// deQueue an item from Q and push the dequeued item to S
push(&S, deQueue(Q));
}
// Run while Stack S is not empty
while (!isEmpty(&S))
{
// Pop an item from S and enqueue the poppped item to Q
enQueue(Q, pop(&S));
}
}
What does the above function do in general?
(a) Removes the last from Q
(b) Keeps the Q same as it was before the call
(c) Makes Q empty
(d) Reverses the Q
6. A priority queue can efficiently implemented using which of the following data structures? Assume that the number
of insert and peek (operation to see the current highest priority item) and extraction (remove the highest priority
item) operations are almost same.
(a) Array (b) Linked List (c) Heap Data Structures (d) None of the above
7. A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap
is given below: 10, 8, 5, 3, 2 Two new elements "1" and "7" are inserted in the heap in that order. The level-order
traversal of the heap after the insertion of the elements is:
(a) 10, 8, 7, 5, 3, 2, 1
(b) 10, 8, 7, 2, 3, 1, 5
(c) 10, 8, 7, 1, 2, 3, 5
(d) 10, 8, 7, 3, 2, 1, 5
8. Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in
addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this
modified stack?
(a) A queue cannot be implemented using this stack.
(b) A queue can be implemented where ENQUEUE takes a single instruction and
DEQUEUE takes a sequence of two instructions.
(c) A queue can be implemented where ENQUEUE takes a sequence of three instructions
and DEQUEUE takes a single instruction.
(d) A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.
9. A program takes as input a balanced binary search tree with n leaf nodes and computes the value of a function g(x)
for each node x. If the cost of computing g(x) is min{no. of leaf-nodes in left-subtree of x, no. of leaf-nodes in
right-subtree of x}
then the worst-case time complexity of the program is
(a) Θ(n) (b) Θ(nLog(n)) (c) Θ(n2
) (d) Θ(n2
Log(n))
10. You are given the postorder traversal, P, of a binary search tree on the n elements 1,2,...,n. You have to determine
the unique binary search tree that has P as its postorder traversal. What is the time complexity of the most efficient
algorithm for doing this?
(a) O(Log(n)) (b) O(n) (c) O(nLog(n)) (d) None of the above
All the best for next week quiz.