Binary Heap MCQ Quiz - Objective Question with Answer for Binary Heap - Download Free PDF

Last updated on Jun 26, 2025

Latest Binary Heap MCQ Objective Questions

Binary Heap Question 1:

Which of the following search algorithms does not need the elements of the array to be in sorted order?

  1. Linear search
  2. Interpolation search
  3. Binary search
  4. Jump search

Answer (Detailed Solution Below)

Option 1 : Linear search

Binary Heap Question 1 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 2:

In a max heap the smallest key is at : 

  1. Root 
  2. Leaf 
  3. Node 
  4. Either root or node

Answer (Detailed Solution Below)

Option 2 : Leaf 

Binary Heap Question 2 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 3:

Let T(n) be the number of different binary search trees on n distinct elements-then

\(\mathrm{T}(\mathrm{n})=\sum_{\mathrm{k}=1}^{\mathrm{n}} T(K-1) T(x)\) where x is :

  1. n − k + 1
  2. n − k
  3. n − k − 1
  4. n − k − 2 

Answer (Detailed Solution Below)

Option 1 : n − k + 1

Binary Heap Question 3 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-point-imageKey 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-imageAdditional 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.

Binary Heap Question 4:

Consider a completely skewed (left/right) binary search tree with n elements. What is the worst case time complexity of searching an element in this tree?

  1. O(n)
  2. O(1) 
  3. O(log n) 
  4. O(nlogn)

Answer (Detailed Solution Below)

Option 1 : O(n)

Binary Heap Question 4 Detailed Solution

The correct answer is O(n).

Key Points

  •  A binary search tree (BST) is a binary tree where each node has a value greater than all the values in its left subtree and less than all the values in its right subtree.
  • In a balanced BST, the time complexity for searching is O(log n) due to the tree's height being log(n).
  • However, in a completely skewed (left or right) BST, the tree essentially behaves like a linked list.
  • This means each node only has one child, and the tree's height becomes n (number of nodes).
  • Therefore, the worst-case time complexity of searching an element in a completely skewed BST is O(n) because you may need to traverse all the nodes.

Important Points

  •  In a balanced BST, operations like insertion, deletion, and search have average time complexities of O(log n).
  • In a completely skewed BST, these operations degrade to O(n) in the worst case.

Additional Information

  •  Self-balancing BSTs like AVL trees and Red-Black trees maintain their height close to log(n), ensuring efficient operations.
  • Understanding the structure and properties of different types of BSTs is crucial for optimizing search operations in various applications.

Binary Heap Question 5:

How many distinct binary search trees can be created out of 4 distinct keys?

  1. 8
  2. 24
  3. 14
  4. More than one of the above
  5. None of the above

Answer (Detailed Solution Below)

Option 3 : 14

Binary Heap Question 5 Detailed Solution

The correct answer is 14.

key-point-imageKey Points

  • The number of distinct binary search trees (BSTs) that can be formed with 'n' distinct keys is given by the nth Catalan number.
  • The nth Catalan number is calculated using the formula: C(n) = (2n)! / ((n+1)!n!)
  • For n = 4, the Catalan number is C(4) = (2*4)! / ((4+1)!4!) = 8! / (5!4!) = (8*7*6*5*4*3*2*1) / ((5*4*3*2*1)*(4*3*2*1)) = 40320 / (120*24) = 40320 / 2880 = 14
  • Hence, the number of distinct binary search trees that can be created out of 4 distinct keys is 14.

additional-information-imageAdditional Information

  • The Catalan numbers appear in various counting problems in combinatorial mathematics, often involving recursively-defined objects.
  • Other applications of Catalan numbers include counting the number of expressions containing n pairs of correctly matched parentheses, the number of ways to triangulate a polygon, and more.
  • The first few Catalan numbers for n = 0, 1, 2, 3, 4 are 1, 1, 2, 5, and 14 respectively.
  • The formula for the nth Catalan number can be derived from the binomial coefficients.

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?

  1. 10, 20, 15, 23, 25, 35, 42, 39, 30
  2. 15, 10, 25, 23, 20, 42, 35, 39, 30
  3. 15, 20, 10, 23, 25, 42, 35, 39, 30
  4. 15, 10, 23, 25, 20, 35, 42, 39, 30

Answer (Detailed Solution Below)

Option 4 : 15, 10, 23, 25, 20, 35, 42, 39, 30

Binary Heap Question 6 Detailed Solution

Download Solution PDF

The 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:

F1 Shraddha Raju 11.05.2021 D2

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 

  1. I and IV only
  2. II and III only
  3. II and IV only
  4. II only

Answer (Detailed Solution Below)

Option 1 : I and IV only

Binary Heap Question 7 Detailed Solution

Download Solution PDF

Statement I:  3, 5, 7, 8, 15, 19, 25

F1 R.S Madhu 10.01.20 D5.1

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

F1 R.S Madhu 10.01.20 D6

15 is left of 12 which violates binary search tree property.

Statement III: 2, 7, 10, 8, 14, 16, 20

F1 R.S Madhu 10.01.20 D7

14 is left of 10 which violates binary search tree property.

Statement IV: 4, 6, 7, 9 18, 20, 25 

F1 R.S Madhu 10.01.20 D10

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:

  1. floor ((i + 1) / 2)
  2. ceiling ((i + 1) / 2
  3. floor (i / 2)
  4. ceiling (i / 2)

Answer (Detailed Solution Below)

Option 3 : floor (i / 2)

Binary Heap Question 8 Detailed Solution

Download Solution PDF

The 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?

  1. BEFDCA
  2. BFDECA
  3. BCFDEA
  4. BDFECA

Answer (Detailed Solution Below)

Option 4 : BDFECA

Binary Heap Question 9 Detailed Solution

Download Solution PDF

The 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,

F1 SSC  Priya 8 5 24 D2

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:

  1. 10, 8, 7, 3, 2, 1, 5
  2. 10, 8, 7, 2, 3, 1, 5
  3. 10, 8, 7, 1, 2, 3, 5
  4. 10, 8, 7, 5, 3, 2, 1

Answer (Detailed Solution Below)

Option 1 : 10, 8, 7, 3, 2, 1, 5

Binary Heap Question 10 Detailed Solution

Download Solution PDF

Concept:

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

F1 Raju Madhu 09.07.20 D2

After inserting 1:

F1 Raju Madhu 09.07.20 D3

After inserting 7:

F1 Raju Madhu 09.07.20 D4

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:

F1 Raju Madhu 09.07.20 D5

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?

  1. Θ(n4)
  2. Θ(n2)
  3. Θ(n2log n)
  4. Θ(n3)

Answer (Detailed Solution Below)

Option 3 : Θ(n2log n)

Binary Heap Question 11 Detailed Solution

Download Solution PDF

Concept:

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?

  1. 3
  2. 4
  3. 5
  4. 6

Answer (Detailed Solution Below)

Option 1 : 3

Binary Heap Question 12 Detailed Solution

Download Solution PDF

The 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

  1. Left sub-tree nodes key value will exist only if lesser than the parent node key value.
  2. Right sub-tree nodes key value will exist only if greater than the parent node key value.
  3. 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.

F1 Raju Shraddha 07.04.2020 D1

Step 2: Now 1 came and 1 < 10 then insert Node 1 to the Left of Node 10.

F1 Raju Shraddha 07.04.2020 D2

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.

F1 Raju Shraddha 07.04.2020 D3

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.

F1 Raju Shraddha 07.04.2020 D4

Step 5: Now 15 came and 15 > 10 then insert Node 15 to the Right of Node 10.

F1 Raju Shraddha 07.04.2020 D5

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.

F1 Raju Shraddha 07.04.2020 D6

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.

F1 Raju Shraddha 07.04.2020 D7

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?

F2 Madhu Engineering 03.06.22 D6

Hint:

The height of a binary tree is equal to the largest number of edges from the root to the most distant leaf node.

  1. 1
  2. 2
  3. 3
  4. 4

Answer (Detailed Solution Below)

Option 2 : 2

Binary Heap Question 13 Detailed Solution

Download Solution PDF

The 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:

F2 Madhu Engineering 03.06.22 D7

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:

  1. mid : = (High - Low)/2 + Low
  2. mid : = (High - Low + 1)/2
  3. mid : = (High - Low)/2
  4. mid : = (High + Low)/2

Answer (Detailed Solution Below)

Option 1 : mid : = (High - Low)/2 + Low

Binary Heap Question 14 Detailed Solution

Download Solution PDF

The 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?

  1. θ (log n) for both insertion and deletion
  2. θ (n) for both insertion and deletion
  3. θ (n) for insertion and θ (log n) for deletion
  4. θ (log n) for insertion and θ (n) for deletion

Answer (Detailed Solution Below)

Option 2 : θ (n) for both insertion and deletion

Binary Heap Question 15 Detailed Solution

Download Solution PDF

Concepts:

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:

zza05

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)

Get Free Access Now
Hot Links: teen patti lotus teen patti real cash withdrawal teen patti game online