Binary Heap MCQ Quiz - Objective Question with Answer for Binary Heap - Download Free PDF
Last updated on Jul 22, 2025
Latest Binary Heap MCQ Objective Questions
Binary Heap Question 1:
Which of the following traversal techniques lists the nodes of a binary search tree in ascending order?
Answer (Detailed Solution Below)
Binary Heap Question 1 Detailed Solution
The correct answer is Inorder
Key Points
- Inorder Traversal: ✅ Inorder traversal of a Binary Search Tree (BST) visits the nodes in the following sequence: Left subtree → Root → Right subtree. This traversal technique lists the nodes of a BST in ascending order if the BST property is maintained.
- Postorder Traversal: ❌ Postorder traversal visits the nodes in the order: Left subtree → Right subtree → Root. This does not guarantee ascending order in a BST.
- Preorder Traversal: ❌ Preorder traversal visits the nodes in the order: Root → Left subtree → Right subtree. This also does not guarantee ascending order in a BST.
- None of the above: ❌ This is incorrect as Inorder traversal is a valid option for listing nodes in ascending order in a BST.
Additional Information
- A Binary Search Tree (BST) is a binary tree where the left subtree of a node contains only nodes with values less than the node's key, and the right subtree contains only nodes with values greater than the node's key.
- Inorder traversal is particularly useful for BSTs as it produces a sorted sequence of node values.
- Other traversal techniques (preorder, postorder) are used for different purposes, such as tree reconstruction or evaluating expressions represented by trees.
Binary Heap Question 2:
Which of the following search algorithms does not need the elements of the array to be in sorted order?
Answer (Detailed Solution Below)
Binary Heap Question 2 Detailed Solution
The correct answer is Option 1) Linear search.
Key Points
- Linear search (also called sequential search) does not require the array to be sorted.
- It works by checking each element one by one from the start until the desired element is found or the end of the array is reached.
- It is simple but less efficient than other searching algorithms for large datasets.
Additional Information
- Binary search requires a sorted array and works by repeatedly dividing the search interval in half.
- Interpolation search also requires a sorted (uniformly distributed) array and estimates the position of the target value.
- Jump search works on sorted arrays and involves jumping ahead by fixed steps to find a block where the element might exist.
- Only linear search can be reliably used on unsorted data.
Binary Heap Question 3:
In a max heap the smallest key is at :
Answer (Detailed Solution Below)
Binary Heap Question 3 Detailed Solution
The correct answer is: option 2: Leaf
Concept:
A max heap is a complete binary tree in which the value of each node is greater than or equal to its children. This ensures that the maximum key is at the root.
Key Properties of Max Heap:
- The largest element is always at the root.
- Values decrease as you move from the root to the leaves.
- Thus, the smallest element must be in one of the leaf nodes, as these are the furthest from the root and have no children.
Explanation of options:
- Option 1 – Root: ❌ Contains the largest key in a max heap.
- Option 2 – Leaf: ✅ Correct. The smallest key will be among the leaf nodes.
- Option 3 – Node: ❌ Too vague — all positions in the tree are nodes.
- Option 4 – Either root or node: ❌ Incorrect — only leaf node can guarantee smallest key in a max heap.
Hence, the correct answer is: option 2: Leaf
Binary Heap Question 4:
If we draw a binary search tree of the sequence 30 9 15 45 24 8 5 75 50 80. Then the no. of nodes in left sub tree, right sub tree and height of the tree are as follows: (note: empty tree is considered of height 0)
Answer (Detailed Solution Below)
Binary Heap Question 4 Detailed Solution
The correct answer is : option 1
Key Points
Step-by-Step BST Construction:
- Insert 30 → root
- Insert 9 → left of 30
- Insert 15 → right of 9
- Insert 45 → right of 30
- Insert 24 → right of 15
- Insert 8 → left of 9
- Insert 5 → left of 8
- Insert 75 → right of 45
- Insert 50 → left of 75
- Insert 80 → right of 75
Resulting BST Structure:
30 / \ 9 45 / \ \ 8 15 75 / \ / \ 5 24 50 80
Left Subtree of 30:
Nodes: 9, 8, 5, 15, 24 → Total = 5 nodes
Right Subtree of 30:
Nodes: 45, 75, 50, 80 → Total = 4 nodes
Height of the Tree:
Longest path from root to leaf:
- Path 1: 30 → 9 → 8 → 5 → 4 nodes
- Path 2: 30 → 45 → 75 → 80 → 4 nodes
✅ Final Answer:
- Left Subtree Nodes: 5
- Right Subtree Nodes: 4
- Height: 3
✔ Correct Option: Option 1) 5 4 3
Binary Heap Question 5:
Let T(n) be the number of different binary search trees on n distinct elements-then
Answer (Detailed Solution Below)
Binary Heap Question 5 Detailed Solution
Let T(n) be the number of different binary search trees on n distinct elements. Then:
T(n) = ∑k=1n T(k-1) T(x) where x is:
- 1) n - k + 1
- 2) n - k
- 3) n - k - 1
- 4) n - k - 2
The correct answer is option 1: n - k + 1
Key Points
- The formula for the number of different binary search trees (BSTs) on n distinct elements can be understood as follows:
- For each element k (from 1 to n) chosen as the root, there are T(k-1) ways to arrange the elements to the left of k (i.e., the left subtree) and T(x) ways to arrange the elements to the right of k (i.e., the right subtree).
- In this context, x represents the number of elements remaining after choosing k and the elements to its left, which is n - k + 1.
- Thus, the formula is: T(n) = ∑k=1n T(k-1) T(n - k + 1).
Additional Information
- The number of different BSTs on n distinct elements is also known as the nth Catalan number, which has a closed-form expression: C(n) = (1 / (n + 1)) (2n choose n).
- This counting problem is fundamental in combinatorial mathematics and has applications in various fields, including computer science and algorithm design.
- Understanding the properties and formulas of BSTs helps in optimizing search and sort operations in data structures.
Top Binary Heap MCQ Objective Questions
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
Answer (Detailed Solution Below)
Binary Heap Question 6 Detailed Solution
Download Solution PDFThe correct answer is "option 4".
CONCEPT:
A Binary Search Tree (BST) is also known as an ordered tree or sorted binary tree.
It is a binary tree with the following properties:
1. The left sub-tree of a node contains only nodes with key-value lesser than the node’s key value.
2. The right subtree of a node contains only nodes with a key-value greater than the node’s key value.
There are three types of traversal:
1. In-order traversal: In this traversal, the first left node will traverse, the root node then the right node will get traversed.
2. Pre-order traversal: In this traversal, the first root node will traverse, the left node then the right node will get traversed.
3. Post-order traversal: In this traversal, the First left node will traverse, the right node then the root node will get traversed.
The in-order traversal of the Binary search tree always returns key values in ascending order.
EXPLANATION:
The pre-order traversal of given BST is:
30, 20, 10, 15, 25, 23, 39, 35, 42.
So, the In-order traversal of the BST is:
10, 15, 20, 23, 25, 30, 35, 39, 42.
The Binary Search Tree is:
So the post-order traversal of the tree is:
15, 10, 23, 25, 20, 35, 42, 39, 30
Hence, the correct answer is "option 4".
Which of the following is/are correct in-order traversal sequence(s) of binary search tree(s)?
I. 3, 5, 7, 8, 15, 19, 25
II. 5, 8, 9, 12, 10, 15, 25
III. 2, 7, 10, 8, 14, 16, 20
IV. 4, 6, 7, 9 18, 20, 25
Answer (Detailed Solution Below)
Binary Heap Question 7 Detailed Solution
Download Solution PDFStatement I: 3, 5, 7, 8, 15, 19, 25
It doesn't violate Binary search tree property and hence it is the correct order of traversal.
Statement II: 5, 8, 9, 12, 10, 15, 25
15 is left of 12 which violates binary search tree property.
Statement III: 2, 7, 10, 8, 14, 16, 20
14 is left of 10 which violates binary search tree property.
Statement IV: 4, 6, 7, 9 18, 20, 25
It doesn't violate Binary search tree property and hence it is the correct order of traversal.
Consider an 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:
Answer (Detailed Solution Below)
Binary Heap Question 8 Detailed Solution
Download Solution PDFThe correct answer is "option 3".
CONCEPT:
The binary heap is a complete binary tree with heap properties.
Binary heap is either max. heap (root value > all key values) or min. heap. (root value < all key values).
EXPLANATION:
Binary heap elements can be represented using an array with index value i (i < = n),
Parent node of element will be at index: floor (i / 2)
Left Child node will be at index: 2 * i
Right child node will be at index: 2 * i + 1
Hence, the index of the parent is floor (i / 2).
What will be post order traversal of a binary Tree T, if preorder and inorder traversals of T are given by ABCDEF and BADCFE respectively?
Answer (Detailed Solution Below)
Binary Heap Question 9 Detailed Solution
Download Solution PDFThe correct answer is option 4.
Concept:
The given data,
preorder = ABCDEF
In order = BADCFE
Tree traversal | |||
Method Sequence | Inorder | Preorder | Postorder |
Left Sub-tree | Root | Left Sub-tree | |
Root | Left Sub-tree | Right Sub-tree | |
Right Sub-tree | Right Sub-tree | Root |
The binary tree for the traversal is,
Post order for the above tree is,
BDFECA
Hence the correct answer is BDFECA.
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Answer (Detailed Solution Below)
Binary Heap Question 10 Detailed Solution
Download Solution PDFConcept:
Max heap: Root node value should be greater than child nodes.
Whenever we insert new element in heap, we will insert at the last level of heap.
After inserting element if max heap doesn’t follow the property then we will apply heapify algorithm until we get max heap.
Explanation:
Initial Heap
After inserting 1:
After inserting 7:
It doesn’t follow max heap property because 7 is greater than 5 so we will apply heapify algorithm on node 7.
After applied heapify algorithm:
Level order: 10, 8, 7, 3, 2, 1, 5
Hence option 1 is the correct answer.
What is the worst case time complexity of inserting n2 elements into an AVL-tree with n elements initially?
Answer (Detailed Solution Below)
Binary Heap Question 11 Detailed Solution
Download Solution PDFConcept:
AVL tree is a height balanced binary search tree.
Insertion in AVL takes Θ (log n) time and height of an AVL tree with n nodes is log n.
Calculation:
The given AVL tree already has n nodes. Now each successive insertion would involve two operations: Θ(log n) to find the appropriate place to insert and another Θ(log n) to do any rotation if required. So in worst case, each successive insertion requires 2 log n operation i.e. Θ (log n).
Therefore, n2 insertions would require Θ (n2 log n).
The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree?
Answer (Detailed Solution Below)
Binary Heap Question 12 Detailed Solution
Download Solution PDFThe correct answer is option 1
Concept:
A binary search tree (BST) is a node-based binary tree data structure and it follows the following points
- Left sub-tree nodes key value will exist only if lesser than the parent node key value.
- Right sub-tree nodes key value will exist only if greater than the parent node key value.
- Left sub-tree and Right sub-tree must be a Binary search tree.
Explanation:
Step 1: First 10 comes and now that is the Root node.
Step 2: Now 1 came and 1 < 10 then insert Node 1 to the Left of Node 10.
Step 3: Now 3 came and 3 < 10 go to the Left of
Node 10 and check 3 > 1 then insert Node 3 to the Right of Node 1.
Step 4: Now 5 came and 5 < 10 go to the Left of
Node 10 and check 5 > 1 go to the Right of Node 1 then check 5 > 3 then insert Node 5 to the Right of Node 3.
Step 5: Now 15 came and 15 > 10 then insert Node 15 to the Right of Node 10.
Step 6: Now 12 came and 12 > 10 go to the Right of Node 10 and check 15 > 12 then insert Node 12 to the Left of Node 15.
Step 7: Now 16 came and 16 > 10 go to the Right of
10 and check 16 > 15 then insert 16 to the Right of Node 15.
After step 7, we can count the height of the tree as 3.
Important Points
Follow the longest path in the tree and count the edges that are height.
Tips To Learn:
Left sub-tree(key)<Node(key)<Right sub-tree(key)
Node(key): Parent node of Left sub-tree and Right sub-tree
Which of the following is a height of a given binary tree?
Hint:
The height of a binary tree is equal to the largest number of edges from the root to the most distant leaf node.
Answer (Detailed Solution Below)
Binary Heap Question 13 Detailed Solution
Download Solution PDFThe correct answer is option 2.
Concept:
Binary tree:
A binary tree is a tree in which no node can have more than two children. Every binary tree has parents, children, siblings, leaves, and internal nodes.
Height of a binary tree:
The height of a binary tree is equal to the largest number of edges from the root to the most distant leaf node.
Explanation:
Hence the correct answer is 2.
The program written for binary search, calculates the midpoint of the span as mid : = (Low + High)/2. The program works well if the number of elements in the list is small (about 32,000) but it behaves abnormally when the number of elements is large. This can be avoided by performing the calculation as:
Answer (Detailed Solution Below)
Binary Heap Question 14 Detailed Solution
Download Solution PDFThe correct answer is option 1.
Key Points
- In a general scenario, binary search mid-value computed with, mid=(low+high)/2.
- However, with a vast list of elements, "high" would be a very large value. As a result, it's possible that it's beyond the Integer limit. It's known as an integer overflow.
- To stop this Integer overflow, the ‘mid' value can also be determined using, mid = (High - Low)/2 + Low
- Integer overflow is never an issue with this form.
Explanation
mid : = (High - Low)/2 + Low
mid : = High/2 - Low/2 + low
mid : = (High + Low)/2
Alternate Method
-
Option D is removed because it is the same as the incorrect option.
-
Taking into account The low index is 10, while the high index is 15.
-
Option B returns a mid-index of 3 that is not even in the sub-array index.
-
Choice C returns a mid-index of 2 that isn't even in the sub-array index.
-
Option A is the best solution.
Hence the correct answer is mid : = (High - Low)/2 + Low .
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
Answer (Detailed Solution Below)
Binary Heap Question 15 Detailed Solution
Download Solution PDFConcepts:
Minimum height of the tree is when all the levels of the binary search tree (BST) are completely filled.
Maximum height of the BST is the worst case when nodes are in skewed manner.
Formula:
Minimum height of the BST with n nodes is ⌈log2 (n + 1)⌉ - 1
The maximum height of the BST with n nodes is n - 1.
BST with a maximum height:
Insertion:
Traverser the BST to the maximum height
Worst-case time complexity of Insertion = θ (n - 1) ≡ θ (n)
Deletion:
Traverser the BST to the maximum height
Worst-case time complexity of = θ (n - 1) ≡ θ (n)