This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1A binary search tree is generated by inserting the following integers
47, 19, 5, 68, 23, 58, 39, 4, 6, 27, 50, 14
The number of nodes in the left sub-tree and right sub-tree of the root are _______ respectively.
Option C
A Binary Search Tree (BST) is a binary tree where:
The first element 47 becomes the root of the Binary Search Tree, and the remaining elements are inserted according to BST rules.
However, it is not always necessary to draw the complete tree, we can simply count the elements such that all values less than the root belong to the left subtree, and all values greater than the root belong to the right subtree.
Left Subtree (< 47):
Right Subtree (> 47):
Q: 2Consider the following array elements A=[4, 1, 3, 2, 16, 9, 10, 14, 8, 7]. The number of interchanges that are necessary to convert the array elements into a max-heap is?
Option B
A Max-Heap is a complete binary tree in which every parent node is greater than or equal to its children.
So, if a parent has children, then:
Heaps are usually stored in an array.
For index i:
So, the given array A = [4, 1, 3, 2, 16, 9, 10, 14, 8, 7] is treated like this tree structure:

“Convert to Max-Heap” means rearranging the given array elements so that they satisfy the properties of a max-heap. In a max-heap, the largest element is always placed at the root (top), and every parent node has a value greater than or equal to its child nodes.
The Build-Max-Heap Algorithm uses a Bottom-Up approach to convert an array into a max-heap. Instead of starting from the root, it begins from the last non-leaf node and moves upward to the root, applying heapify at each step. This approach ensures that smaller subtrees are fixed first before handling their parent nodes.
Leaf Nodes are not processed because they already satisfy the heap property. Only internal nodes may violate the max-heap condition, so they are adjusted.
In an array representation of a max-heap (0-based indexing), the last non-leaf node is found using the formula: ⌊n/2⌋-1, where n is the total number of elements in the heap.
Step-by-Step Process:
Given Array A=[4, 1, 3, 2, 16, 9, 10, 14, 8, 7]
There are 10 elements, so the last non-leaf node is at index: ⌊10/2⌋-1 = 4. So we heapify from index 4 down to 0. Heapify from bottom to top.
Heapify at Index 4 : Value 16
Heapify at Index 3 : Value 2

Heapify at Index 2 : Value 3

Heapify at Index 1 : Value 1

Heapify at Index 0 : Value 4

The total number of interchanges necessary to convert the array into a Max-Heap is 7.
Q: 3Inorder and postorder traversal of a binary tree are given.
In: E, I, C, F, B, G, D, J, H, K
Post: I, E, F, C, G, J, K, H, D, B
What is the preorder traversal of the binary tree?
Option A
In a Binary Tree:
Given:
In postorder traversal, the last element is always the root. Therefore, Root = B.
Now split Inorder traversal around B.
Now split postorder accordingly.
Left Subtree Postorder:
Right Subtree Postorder:
Construct Left Subtree:
From left subtree postorder, last element is C. So, C becomes left child of B.
In inorder:
E, I | C | F
From Postorder:
Thus, left subtree preorder becomes: C, E, I, F.
Construct Right Subtree:
Right subtree postorder are G, J, K, H, D. Last element is D So D becomes right child of B.
In inorder:
G | D | J, H, K
From postorder:
Thus, right subtree preorder becomes D, G, H, J, K.
Final Preorder Traversal sequence are B, C, E, I, F, D, G, H, J, K.
Q: 4A complete binary tree T have n leaf nodes. What is the number of nodes with degree of 2 in tree T?
Option C
The relation between leaf nodes and nodes having degree 2 is generally derived using the property of a full (strict) binary tree. In such a tree, every internal node has exactly two children.
If L is number of leaf nodes and I is number of nodes with degree 2 then the standard relation is L=I+1.
Given that the number of leaf nodes is n, and using the relation L=I+1, we get n=I+1. Therefore, I=n-1. Hence, the number of nodes with degree 2 is n-1.

Q: 5Consider the following statement:
S1: Ternary search is more efficient than binary search for finding an element in a sorted array.
S2: Worst case deletion and insertion in an AVL tree have same complexity.
Option B
Statement S1: Ternary search divides the array into three parts, while binary search divides it into two parts. Although ternary search reduces the search space into more parts, it requires more comparisons per step than binary search. As a result, binary search is generally more efficient for finding an element in a sorted array. Hence, S1 is incorrect.
Statement S2: In an AVL tree, both insertion and deletion operations may require rebalancing the tree. In the worst case, both operations take O(log n) time because the height of an AVL tree is always logarithmic. Hence, S2 is correct.
Q: 6How many edges does a spanning tree of a graph with N vertices have?
Option B
A spanning tree is a subgraph of a connected graph that includes all the vertices but only enough edges to keep the graph connected without forming any cycles.
Q: 7In a binary search tree, which subtree of a node contains elements that are greater than the node’s value?
Option B
A Binary Search Tree (BST) is a special type of binary tree where the arrangement of elements follows a strict rule:
This property allows fast searching, because at each step, the tree decides whether to go left (for smaller values) or right (for larger values).
Q: 8When a tree given in the diagram is traversed inorder, the order would be

Option C
In inorder traversal, nodes are visited in the order Left Subtree → Root → Right Subtree.
Left subtree of a (rooted at b):
Then visit root:
Right subtree of a (rooted at c):
Final inorder traversal:
h, d, b, i, e, j, a, f, c, k, g
Q: 9Huffman coding algorithm works on the principle of
Option D
The Huffman Coding Algorithm is a lossless data compression technique and a classic example of a Greedy Algorithm. It assigns variable-length binary codes to symbols based on their frequency of occurrence, where more frequent symbols get shorter codes and less frequent symbols get longer codes, reducing the overall size of the encoded data.
Since the algorithm generates codes according to the frequency of input symbols, Huffman coding works on the principle of symbol frequencies.
Q: 10If we implement heap as maximum heap, adding a new node of value 15 to the left most node of right subtree, what value will be at leaf nodes of the right subtree of the heap?

Option A
Q: 11The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree?
Option B
A Binary Search Tree (BST) is a special type of binary tree that is designed to allow fast searching, insertion, and deletion of data. In BST:
The preorder traversal sequence is given and in case of BST, the inorder traversal always sorts the tree nodes into ascending order.
Preorder : 15, 10, 12, 11, 20, 18, 16, 19
Inorder : 10, 11, 12, 15, 16, 18, 19, 20
WHEN PREORDER AND INORDER TRAVERSAL GIVEN:
So, the resultant BST is:
15
/ \
10 20
\ /
12 18
/ / \
11 16 19
Final Postorder traversal sequence is 11, 12, 10, 16, 19, 18, 20, 15
Q: 12In a balanced binary tree, the height of two sub-trees of every node can not differ by more than
Option B
A binary tree is a hierarchical data structure in which each node can have at most two children, called the left child and the right child.
Now, some binary trees can grow in an uneven manner. For example, all nodes may keep inserting to the left side only. This makes the tree skewed, and searching becomes slow. To avoid this, we use a balanced binary tree.
A Balanced Binary Tree is a special type of binary tree in which the height (depth) of the left and right subtrees of every node is kept nearly equal.
Height of left subtree and right subtree differ by 0 or 1 only.
This condition must hold at every node in the tree, not just the root.
So, in a balanced binary tree (AVL Tree), the difference between the heights of the left and right subtree of any node is allowed to be at most 1.
Q: 13A binary search tree is used to locate the number 53. Which of the following probe sequences are not possible
(i) 27,87,37,76,28,53
(ii) 12,13,60,50,70,53
(iii) 20,75,41,58,47,53
(iv) 71,62,24,27,50,53
Option D
A Binary Search Tree (BST) is a tree where:
The given sequences like 27, 87, 37, 76, 28, 53 represent the path followed while searching the key 53 in a BST. That means:
While searching in a BST:
Every step creates a valid range (Minimum, Maximum), Initially: (-∞, +∞). The next node in the sequence must lie within this range.
Rule:
This concept comes from the basic property of a Binary Search Tree (BST), where all elements on the left side of a node are smaller, and all elements on the right side are greater.
While searching for a value (like 53), we move left or right based on comparison, and this movement automatically creates restrictions.
When we move to the right of a node, it means the searched value is greater than that node. So, all future nodes we visit must also be greater than that value. In this way, the Minimum Limit (Lower Bound) gets updated.
Similarly, when we move to the left of a node, it means the searched value is smaller than that node. So, all future nodes must be smaller than that value. This updates the Maximum Limit (Upper Bound).
For example, if we first move right from 27 and then left from 87, the valid range becomes (27, 87). Now, every next node must lie within this range, otherwise, the sequence becomes invalid.
Now check given sequence one by one.
(i) 27 → 87 → 37 → 76 → 28 → 53
| Step | Node | Comparison & Movement | Valid Range |
|---|---|---|---|
| 1 | 27 | 53>27 → Right | (27, ∞) |
| 2 | 87 | 53<87 → Left | (27, 87) |
| 3 | 37 | 53>37 → Right | (37, 87) |
| 4 | 76 | 53<76 → Left | (37, 76) |
| 5 | 28 | 28<37 (Out of Range) | Not in Range |
Problem: 28 is not in (37, 76). Therefore, this sequence is NOT possible.
(ii) 12 → 13 → 60 → 50 → 70 → 53
| Step | Node | Comparison & Movement | Valid Range |
|---|---|---|---|
| 1 | 12 | 53>12 → Right | (12, ∞) |
| 2 | 13 | 53>13 → Right | (13, ∞) |
| 3 | 60 | 53<60 → Left | (13, 60) |
| 4 | 50 | 53>50 → Right | (50, 60) |
| 5 | 70 | 70>60 (Out of Range) | Not in Range |
Problem: 70 is not in (50, 60). Therefore, this sequence is NOT possible.
(iii) 20 → 75 → 41 → 58 → 47 → 53
| Step | Node | Comparison & Movement | Valid Range |
|---|---|---|---|
| 1 | 20 | 53>20 → Right | (20, ∞) |
| 2 | 75 | 53<75 → Left | (20, 75) |
| 3 | 41 | 53>41 → Right | (41, 75) |
| 4 | 58 | 53<58 → Left | (41, 58) |
| 5 | 47 | 53>47 → Right | (47, 58) |
| 6 | 53 | 47<53<58 | Valid |
(iv) 71 → 62 → 24 → 27 → 50 → 53
| Step | Node | Comparison & Movement | Valid Range |
|---|---|---|---|
| 1 | 71 | 53<71 → Left | (-∞, 71) |
| 2 | 62 | 53<62 → Left | (-∞, 62) |
| 3 | 24 | 53>24 → Right | (24, 62) |
| 4 | 27 | 53>27 → Right | (27, 62) |
| 5 | 50 | 53>50 → Right | (50, 62) |
| 6 | 53 | 50<53<62 | Valid |

Q: 14Which one of the following techniques is not used in the binary tree?
Option A
A binary tree is commonly traversed using three standard tree traversal techniques:
These methods are systematic and widely used in all tree-related algorithms.
Q: 15The preorder traversal of a Binary Search Tree (BST) is 100, 50, 20, 30, 60, 55, 150, 130, 140, 180, 170. What would be its postorder traversal?
Option C
As we know, inorder traversal of BST is in sorted order. So,
Inorder Traversal : 20, 30, 50, 55, 60, 100, 130, 140, 150, 170, 180
Preorder Traversal : 100, 50, 20, 30, 60, 55, 150, 130, 140, 180, 170
With Inorder and Preorder, unique BST can be determined.

Using the above constructed BST, the postorder traversal sequence is:
Postorder Traversal : 30, 20, 55, 60, 50, 140, 130, 170, 180, 150, 100
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.