Binary Trees
Question 1 |
Which of the following is true about Binary Trees?
Every binary tree is either complete or full. | |
Every complete binary tree is also a full binary tree. | |
Every full binary tree is also a complete binary tree. | |
No binary tree is both complete and full. | |
None of the above |
Discuss it
A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which every node other than the leaves has two children. A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. A) is incorrect. For example, the following Binary tree is neither complete nor full
12 / 20 / 30
B) is incorrect. The following binary tree is complete but not full
12 / \ 20 30 / 30
C) is incorrect. Following Binary tree is full, but not complete
12 / \ 20 30 / \ 20 40
D) is incorrect. Following Binary tree is both complete and full
12 / \ 20 30 / \ 10 40
Question 2 |
If arity of operators is fixed, then which of the following notations can be used to parse expressions without parentheses? a) Infix Notation (Inorder traversal of a expression tree) b) Postfix Notation (Postorder traversal of a expression tree) c) Prefix Notation (Preorder traversal of a expression tree)
b and c | |
Only b | |
a, b and c | |
None of them |
Discuss it
Preorder and Postorder notations are used to parse expressions without parentheses.
Question 3 |
What are the main applications of tree data structure?
- Manipulate hierarchical data
- Make information easy to search
- Manipulate sorted lists of data
- Router algorithms
- Form of a multi-stage decision-making, like Chess Game.
- As a workflow for compositing digital images for visual effects
1, 2, 3, 4 and 6 | |
1, 2, 3, 4 and 5 | |
1, 3, 4, 5 and 6 | |
1, 2, 3, 4, 5 and 6 |
Discuss it
Tree data structure is used to study or tabulate hierarchical data. Searching of data becomes easy using the tree traversals. Using BST we can easily analyze sorted data. Decision making to reach an objective becomes easy due to decision tree creation. Trees are used in router algorithms. They can be beneficial as a workflow for compositing digital images for visual effects.
Question 4 |
In the following answers, the operator '^' indicates power.
2^(i-1) | |
2^i | |
2^(i+1) | |
2^[(i+1)/2] |
Discuss it
Question 5 |
nk | |
(n – 1) k+ 1 | |
n( k – 1) + 1 | |
n(k – 1) |
Discuss it
o / | \ o o o / | \ / | \ o o o o o o / | \ o o o k = 3 Number of internal nodes n = 4 Number of leaf nodes = (k-1)*n + 1 = (3-1)*4 + 1 = 9
Question 6 |
The maximum number of binary trees that can be formed with three unlabelled nodes is:
1 | |
5 | |
4 | |
3 |
Discuss it
Following are all possible unlabeled binary trees
O / \ O O (i) O / O / O (ii) O / O \ O (iii) O \ O \ O (iv) O \ O / O (v)
Note that nodes are unlabeled. If the nodes are labeled, we get more trees. We can find the number of binary tree by Catalan numbers. Here n = 3 Number of binary tree = (2nCn)/ n+1 = (2*3C3)/ 3+1 = 5. So, option (B) is correct.
Question 7 |
n/2 | |
(n-1)/3 | |
(n-1)/2 | |
(2n+1)/3 |
Discuss it
L = (3-1)I + 1 = 2I + 1Total number of nodes(n) is sum of leaf nodes and internal nodes
n = L + IAfter solving above two, we get L = (2n+1)/3
Question 8 |




A | |
B | |
C | |
D |
Discuss it
H(n) = H(2n/3) + 1The solution of above recurrence is

1) Choose an i uniformly at random from 1..n; 2) If A[i] = x then Stop else Goto 1;Assuming that x is present in A, what is the expected number of comparisons made by the algorithm before it terminates? a) n b) n-l c) 2n d) n/2 Answer(a) If you remember the coin and dice questions, you can just guess the answer for the above. Below is proof for the answer. Let expected number of comparisons be E. Value of E is sum of following expression for all the possible cases.
number_of_comparisons_for_a_case * probability_for_the_caseCase 1
If A[i] is found in the first attempt number of comparisons = 1 probability of the case = 1/nCase 2
If A[i] is found in the second attempt number of comparisons = 2 probability of the case = (n-1)/n*1/nCase 3
If A[i] is found in the third attempt number of comparisons = 2 probability of the case = (n-1)/n*(n-1)/n*1/nThere are actually infinite such cases. So, we have following infinite series for E.
E = 1/n + [(n-1)/n]*[1/n]*2 + [(n-1)/n]*[(n-1)/n]*[1/n]*3 + …. (1)After multiplying equation (1) with (n-1)/n, we get
E (n-1)/n = [(n-1)/n]*[1/n] + [(n-1)/n]*[(n-1)/n]*[1/n]*2 + [(n-1)/n]*[(n-1)/n]*[(n-1)/n]*[1/n]*3 ……….(2)Subtracting (2) from (1), we get
E/n = 1/n + (n-1)/n*1/n + (n-1)/n*(n-1)/n*1/n + …………The expression on right side is a GP with infinite elements. Let us apply the sum formula (a/(1-r))
E/n = [1/n]/[1-(n-1)/n] = 1 E = n
Question 9 |
6 | |
3 | |
4 | |
5 |
Discuss it
L = (n-1)*I + 1Where L is the number of leaf nodes and I is the number of internal nodes. Let us find out the value of n for the given data.
L = 41 , I = 10 41 = 10*(n-1) + 1 (n-1) = 4 n = 5
Question 10 |
2^h -1 | |
2^(h-1) – 1 | |
2^(h+1) -1 | |
2*(h+1) |
Discuss it