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

MCQs on Tree with answers

1. The height of a BST is given as h. Consider the height of the tree as the no.
of edges in the longest path from root to the leaf. The maximum no. of nodes
possible in the tree is?

a) 2h-1 -1
b) 2h+1 -1
c) 2h +1
d) 2h-1 +1
ANSWER: B

2. The no of external nodes in a full binary tree with n internal nodes is?

a) n
b) n+1
c) 2n
d) 2n + 1
ANSWER: B

3. The difference between the external path length and the internal path length
of a binary tree with n internal nodes is?

a) 1
b) n
c) n + 1
d) 2n
ANSWER: D

4. Suppose a binary tree is constructed with n nodes, such that each node has
exactly either zero or two children. The maximum height of the tree will be?

a) (n+1)/2
b) (n-1)/2
c) n/2 -1
d) (n+1)/2 -1
ANSWER: B

5. Which of the following statement about binary tree is CORRECT?

a) Every binary tree is either complete or full


b) Every complete binary tree is also a full binary tree
c) Every full binary tree is also a complete binary tree
d) A binary tree cannot be both complete and full
ANSWER: C

6. Suppose we have numbers between 1 and 1000 in a binary search tree and
want to search for the number 363. Which of the following sequence could not
be the sequence of the node examined?

a) 2, 252, 401, 398, 330, 344, 397, 363


b) 924, 220, 911, 244, 898, 258, 362, 363
c) 925, 202, 911, 240, 912, 245, 258, 363
d) 2, 399, 387, 219, 266, 382, 381, 278, 363
ANSWER: C

7. In full binary search tree every internal node has exactly two children. If
there are 100 leaf nodes in the tree, how many internal nodes are there in the
tree?

a) 25
b) 49
c) 99
d) 101
ANSWER: C

8. Which type of traversal of binary search tree outputs the value in sorted
order?

a) Pre-order
b) In-order
c) Post-order
d) None
ANSWER: B

9. Suppose a complete binary tree has height h>0. The minimum no of leaf
nodes possible in term of h is?

a) 2h -1
b) 2h -1 + 1
c) 2h -1
d) 2h +1
ANSWER: C

10. A 2-3 is a tree such that

a) All internal nodes have either 2 or 3 children


b) All path from root to leaves have the same length

The number of internal nodes of a 2-3 tree having 9 leaves could be

a) 4
b) 5
c) 6
d) 7
ANSWER: A, D
11. If a node having two children is to be deleted from binary search tree, it is
replaced by its

a) In-order predecessor
b) In-order successor
c) Pre-order predecessor
d) None
ANSWER: B

12. A binary search tree is formed from the sequence 6, 9, 1, 2, 7, 14, 12, 3, 8,
18. The minimum number of nodes required to be added in to this tree to form
an extended binary tree is?

a) 3
b) 6
c) 8
d) 11
ANSWER: D

13. In a full binary tree, every internal node has exactly two children. A full
binary tree with 2n+1 nodes contains

a) n leaf node
b) n internal nodes
c) n-1 leaf nodes
d) n-1 internal nodes
ANSWER: B

14. the run time for traversing all the nodes of a binary search tree with n
nodes and printing them in an order is

a) O(nlg(n))
b) O(n)
c) O(√n)
d) O(log(n))
ANSWER: B

15. When a binary tree is converted in to an extended binary tree, all the nodes
of a binary tree in the external node becomes

a) Internal nodes
b) External nodes
c) Root nodes
d) None
ANSWER: A
16. If n numbers are to be sorted in ascending order in O(nlogn) time, which of
the following tree can be used

a) Binary tree
b) Binary search tree
c) Max-heap
d) Min-heap
ANSWER: D

17. If n elements are sorted in a binary search tree. What would be the
asymptotic complexity to search a key in the tree?

a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: C

18. If n elements are sorted in a balanced binary search tree. What would be
the asymptotic complexity to search a key in the tree?

a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: B

19. The minimum number of elements in a heap of height h is

a) 2h+1
b) 2h
c) 2h -1
d) 2h-1
ANSWER: B

20. The maximum number of elements in a heap of height h is

a) 2h+1 -1
b) 2h
c) 2h -1
d) 2h -1
ANSWER: A

21. A threaded binary tree is a binary tree in which every node that does not
have right child has a thread to its

a) Pre-order successor
b) In-order successor
c) In-order predecessor
d) Post-order successor
ANSWER: B

22. In which of the following tree, parent node has a key value greater than or
equal to the key value of both of its children?

a) Binary search tree


b) Threaded binary tree
c) Complete binary tree
d) Max-heap
ANSWER: D

23. A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is

a) log2n
b) n-1
c) n
d) 2n
ANSWER: B

24. A binary search tree is generated by inserting in order the following


integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24

The number of the node in the left sub-tree and right sub-tree of the root,
respectively, is

a) (4, 7)
b) (7, 4)
c) (8, 3)
d) (3, 8)
ANSWER: B

Q. Which of the following is false about a binary search tree?

A. The left child is always lesser than its parent

B. The right child is always greater than its parent

C. The left and right sub-trees should also be binary search trees

D. In order sequence gives decreasing order of elements

Answer» D. In order sequence gives decreasing order of elements


What is the speciality about the inorder traversal of a binary
search tree?
Options
A : It traverses in a non increasing order
B : It traverses in an increasing order
C : It traverses in a random fashion
D : It traverses based on priority of the node
What are the worst case and average case complexities of a
binary search tree?
Options
A : O(n), O(n)
B : O(logn), O(logn)
C : O(logn), O(n)
D : O(n), O(logn)

Which of the following is false about a binary search tree?


Options
A : The left child is always lesser than its parent
B : The right child is always greater than its parent
C : The left and right sub-trees should also be binary search trees
D : In order sequence gives decreasing order of elements
What are the conditions for an optimal binary search tree and
what is its advantage?
Options
A : The tree should not be modified and you should know how often the
keys are accessed, it improves the lookup cost
B : You should know the frequency of access of the keys, improves the
lookup time
C : The tree can be modified and you should know the number of
elements in the tree before hand, it improves the deletion time
D : The tree should be just modified and improves the lookup time

What is a complete binary tree?


Options
A : Each node has exactly zero or two children
B : A binary tree, which is completely filled, with the possible exception of
the bottom level, which is filled from right to left
C : A binary tree, which is completely filled, with the possible exception of
the bottom level, which is filled from left to right
D : A tree In which all nodes have degree 2

What is a full binary tree?


Options
A : Each node has exactly zero or two children
B : Each node has exactly two children
C : All the leaves are at the same level
D : Each node has exactly one or two children

What is the average case time complexity for finding the height of
the binary tree?
Options
A : h = O(loglogn)
B : h = O(nlogn)
C : h = O(n)
D : h = O(log n)

The number of edges from the node to the deepest leaf is called
_________ of the tree.
Options
A : Height
B : Depth
C : Length
D : Width

The number of edges from the root to the node is called


__________ of the tree.
Options
A : Height
B : Depth
C : Length
D : Width

Which of the following is not an advantage of trees?


Options
A : Hierarchical structure
B : Faster search
C : Router algorithms
D : Undo/Redo operations in a notepad

In a full binary tree if number of internal nodes is I, then number


of leaves L are?
Options
A : L = 2*I
B:L=I+1
C:L=I–1
D : L = 2*I – 1

Which of the following is incorrect with respect to binary trees?


Options
A : Let T be a binary tree. For every k ? 0, there are no more than 2k
nodes in level k
B : Let T be a binary tree with ? levels. Then T has no more than 2? – 1
nodes
C : Let T be a binary tree with N nodes. Then the number of levels is at
least ceil(log (N + 1))
D : Let T be a binary tree with N nodes. Then the number of levels
is at least floor(log (N + 1))

In a full binary tree if number of internal nodes is I, then number


of nodes N are?
Options
A : N = 2*I
B:N=I+1
C:N=I–1
D : N = 2*I + 1

In a full binary tree if there are L leaves, then total number of


nodes N are?
Options
A : N = 2*L
B:N=L+1
C:N=L–1
D : N = 2*L – 1
How many children does a binary tree have?
Options
A:2
B : any number of children
C : 0 or 1 or 2
D : 0 or 1

What must be the ideal size of array if the height of tree is ‘l’?
Options
A : 2l-1
B : l-1
C:l
D : 2l

What are the children for node ‘w’ of a complete-binary tree in an


array representation?
Options
A : 2w and 2w+1
B : 2+w and 2-w
C : w+1/2 and w/2
D : w-1/2 and w+1/2

What is/are the disadvantages of implementing tree using normal


arrays?
Options
A : difficulty in knowing children nodes of a node
B : difficult in finding the parent of a node
C : have to know the maximum number of nodes possible before creation
of trees
D : difficult to implement

If the tree is not a complete binary tree then what changes can be
made for easy access of children of a node in the array?
Options
A : every node stores data saying which of its children exist in the array
B : no need of any changes continue with 2w and 2w+1, if node is at i
C : keep a seperate table telling children of a node
D : use another array parallel to the array with tree
What is the parent for a node ‘w’ of a complete binary tree in an
array representation when w is not 0?
Options
A : floor(w-1/2)
B : ceil(w-1/2)
C : w-1/2
D : w/2

Consider a situation of writing a binary tree into a file with


memory storage efficiency in mind, is array representation of tree
is good?
Options
A : yes because we are overcoming the need of pointers and so space
efficiency
B : yes because array values are indexable
C : No it is not efficient in case of sparse trees and remaning cases it is
fine
D : No linked list representation of tree is only fine

Can a tree stored in an array using either one of inorder or post


order or pre order traversals be again reformed?
Options
A : Yes just traverse through the array and form the tree
B : No we need one more traversal to form a tree
C : No in case of sparse trees
D : Yes by

Level order traversal of a tree is formed with the help of


Options
A : breadth first search
B : depth first search
C : dijkstra’s algorithm
D : prims algorithm

Advantages of linked list representation of binary trees over


arrays?
Options
A : dynamic size
B : ease of insertion/deletion
C : ease in randomly accessing a node
D : both dynamic size and ease in insertion/deletion

What may be the psuedo code for finding the size of a tree?
Options
A : find_size(root_node–>left_node) + 1 + find_size(root_node–
>right_node)
B : find_size(root_node–>left_node) + find_size(root_node–>right_node)
C : find_size(root_node–>right_node) – 1
D : find_size(root_node–>left_node + 1

Which of the following traversing algorithm is not used to traverse


in a tree?
Options
A : Post order
B : Pre order
C : Post order
D : Randomized

Disadvantages of linked list representation of binary trees over


arrays?
Options
A : Randomly accessing is not possible
B : Extra memory for a pointer is needed with every element in the list
C : Difficulty in deletion
D : Random access is not possible and extra memory with every element

Identify the reason which doesn’t play a key role to use threaded
binary trees?
Options
A : The storage required by stack and queue is more
B : The pointers in most of nodes of a binary tree are NULL
C : It is Difficult to find a successor node
D : They occupy less size

What is the location of a parent node for any arbitary node i?


Options
A : (i/2) position
B : (i+1)/ position
C : floor(i/2) position
D : ceil(i/2) position

Given an array of element 5, 7, 9, 1, 3, 10, 8, 4. Which of the


following is the correct sequences of elements after inserting all
the elements in a min-heap?
Options
A : 1,3,4,5,7,8,9,10
B : 1,4,3,9,8,5,7,10
C : 1,3,4,5,8,7,9,10
D : 1,3,7,4,8,5,9,10

What is the space complexity of searching in a heap?


Options
A : O(logn)
B : O(n)
C : O(1)
D : O(nlogn)

What is the best case complexity in building a heap?


Options
A : O(nlogn)
B : O(n2)
C : O(n*longn *logn)
D : O(n)

You might also like