Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
Q491: In a min-heap, what is the maximum number of levels the tree can have if it contains N nodes?
- A: log2(N)
- B: N
- C: sqrt(N)
- D: N log2(N)
View Answer
A
Q492: What does a complete binary tree ensure when implementing a heap?
- A: All nodes have two children
- B: All nodes are in a specific order
- C: The tree is balanced
- D: All levels are fully filled except possibly the last
View Answer
C
Q493: When performing a percolateDown operation, which of the following is true?
- A: The hole moves upward
- B: The hole moves downward
- C: The node moves to the left
- D: The node moves to the right
View Answer
B
Q494: In the heap sort algorithm, how is the smallest element retrieved from the heap?
- A: By removing the root node
- B: By scanning the entire heap
- C: By using a heapify function
- D: By moving the last node to the root
View Answer
A
Q495: What is the primary use of the heap data structure?
- A: Binary search
- B: Priority queues
- C: Sorting
- D: Hashing
View Answer
B
Q496: How are elements arranged in a min-heap relative to each other?
- A: In ascending order from root to leaves
- B: In descending order from root to leaves
- C: Random order
- D: In ascending order from leaves to root
View Answer
A
Q497: How is the complexity of building a heap with the buildHeap method compared to inserting elements one by one?
- A: It is faster
- B: It is slower
- C: It is the same
- D: It is unpredictable
View Answer
A
Q498: What happens if you insert an element that is larger than all existing elements in a min-heap?
- A: It moves to the root node
- B: It stays at the last position
- C: It moves to the bottom of the heap
- D: It gets discarded
View Answer
B
Q499: When deleting an element from a min-heap, what happens to the heap size?
- A: It increases by one
- B: It decreases by one
- C: It stays the same
- D: It doubles
View Answer
B
Q500: What is the time complexity of the insert method for building a heap one element at a time?
- A: O(N)
- B: O(log N)
- C: O(N log N)
- D: O(N^2)
View Answer
C