Day3 Session 1
Day3 Session 1
(A) 2
(B) 3
(C) 4
(D) 5
Ans: B
Ans: C
• How many rotations are required during the
construction of an AVL tree if the following
elements are to be added in the order given?
35, 50, 40, 25, 30, 60, 78, 20, 28
RL + LR + RR
2 LL rotations and 3 RR rotations are required.
What will be the post order traversal of the AVL
tree formed by the nodes given below:
10, 15, 40, 20, 50, 30, 18, 5, 7
(A) 10 15 12 20 30 22 45 18 40
(B) 10 15 12 20 22 30 45 40 18
(C) 10 15 12 20 30 22 45 40 18
(D) none of these
Ans: C
In the AVL tree shown here, How many
nodes will become unbalanced if a node
is inserted as a child of node g?
A. 2
B. 3
C. 4
D. Depends whether the node inserted is
left child of g or right child.
Ans: B
On addition of a node below g in the previous
question, which of the following will make the
tree balanced again with minimum movement?
A.Making c as root
B.Connecting left subtree below c as right subtree
of b.
C.g as left subtree of f.
D.None of These
Ans: D
How many LL rotations will be applied to
construct an AVL tree with given nodes?
30, 40, 20, 50, 35, 33, 15
A. 0
B. 1
C. 2
D. 3
Ans: B
Which of the following is TRUE?
A.Every Binary Search Tree is an AVL.
B.Complexity of searching an element in AVL
tree is O(n).
C.LL rotation is consists of two Left rotations on
different nodes.
D.None of These
Ans: D
HEAP
Consider a binary min-heap implemented
using an array. Which one of the following
array represents a binary min-heap?
A. (ii),(iv)
B. (ii),(iii)
C. (i),(ii),(iii)
D. (ii),(iii),(iv)
Ans: B
Consider the following array of elements.
〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〈.
The minimum number of interchanges needed
to convert it into a max-heap is:
A.2
B. 3
C. 4
D. 5
Ans: B
Consider any array representation of an n
element binary heap where the elements are
stored from index 1 to index n of the array.
For the element stored at index i of the array
(i <= n), the index of the parent is:
A. i-1
B. (i+1)/2
C. ceiling(i/2)
D. floor(i/2)
Ans: D
In a heap with n elements with the smallest
element at the root, the 7th smallest element
can be found in time:
A. O(logn)
B. O(n)
C. O(nlogn)
D. O(n^2)
Ans: B
• A 3-ary max heap is like a binary max heap, but instead of 2
children, nodes have 3 children. A 3-ary heap can be
represented by an array as follows: The root is stored in the
first location, a[0], nodes in the next level, from left to right, is
stored from a[1] to a[3]. The nodes from the second level of
the tree from left to right are stored from a[4] location onward.
An item x can be inserted into a 3-ary heap containing n items
by placing x in the location a[n] and pushing it up the tree to
satisfy the heap property. Which one of the following is a valid
sequence of elements in an array representing 3-ary max heap?
A. 1, 3, 5, 6, 8, 9 B. 9, 6, 3, 1, 8, 5
C. 9, 3, 6, 8, 5, 1 D. 9, 5, 6, 8, 3, 1
Ans: D
Suppose the elements 7, 2, 10 and 4 are inserted, in
that order, into the valid 3- ary max heap found in the
above question, Which one of the following is the
sequence of items in the array representing the
resultant heap?
A. 10, 7, 9, 8, 3, 1, 5, 2, 6, 4
B. 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
C. 10, 9, 4, 5, 7, 6, 8, 2, 1, 3
D. 10, 8, 6, 9, 7, 2, 3, 4, 1, 5
Ans: A
B-Tree
Which one of the following is a key factor for
preferring B-trees to binary search trees for indexing
database relations?
A. 2.0 bit
B. 2.1 bit
C. 1.9 bit
D. 1.8 bit
• Ans: C
A Text consists of the letters A, B, C and D.
The probability of occurrence is
P(A) = 0.4, P(B) = 0.1, P(C) = 0.2 and P(D) = 0.3.
The Huffman code is: