Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 45
Q701:
In merge sort, what determines when the recursive calls stop?
A. The array has only one element
B. The array is fully sorted
C. The array is empty
D. The array size exceeds a threshold
Correct Answer:
A
Chapter: 45
Q702:
How is merge sort implemented in a linked list compared to an array?
A. The algorithm is the same for both
B. Merge sort requires additional space for arrays but not for linked lists
C. Merge sort is faster with arrays
D. Merge sort requires converting the linked list to an array
Correct Answer:
B
Chapter: 45
Q703:
What is the typical use case for quicksort?
A. When memory is a concern
B. When a stable sort is required
C. When a sorting algorithm with guaranteed O(n log n) performance is needed
D. When an in-place sort is required
Correct Answer:
D
Chapter: 45
Q704:
How does quicksort ensure the array is eventually sorted?
A. By repeatedly sorting the entire array
B. By recursively sorting sub-arrays around a pivot
C. By using a temporary array to store sorted elements
D. By performing a linear scan of the array
Correct Answer:
B
Chapter: 45
Q705:
In merge sort, how are elements copied from the temporary array back to the original array?
A. Using a loop that iterates over the temporary array and original array
B. By swapping elements directly
C. By merging in place
D. Using recursive calls to mergeArrays
Correct Answer:
A
Chapter: 45
Q706:
What is the purpose of the partition function in the quicksort algorithm?
A. To swap the pivot element with the smallest element
B. To choose a random pivot element
C. To divide the array into two parts around the pivot element
D. To sort the array recursively
Correct Answer:
C
Chapter: 45
Q707:
In the quicksort algorithm, what happens if the size of the array is less than or equal to 1?
A. The function performs a recursive call
B. The function performs a partition
C. The function returns immediately without changes
D. The function swaps all elements with the pivot
Correct Answer:
D
Chapter: 45
Q708:
Which method is used to place the smallest element of the array at the beginning in quicksort?
A. partition
B. insert
C. sort
D. merge
Correct Answer:
A
Chapter: 45
Q709:
What is the time complexity of the buildHeap algorithm?
A. O(N)
B. O(log N)
C. O(N log N)
D. O(1)
Correct Answer:
A
Chapter: 45
Q710:
How does heap sort achieve sorting of elements?
A. By performing multiple deleteMin operations and recording elements
B. By applying a partition function repeatedly
C. By using quicksort on the heap
D. By iteratively merging sorted arrays
Correct Answer:
A
Chapter: 45
Q711:
Which data structure is used to implement a priority queue efficiently?
A. Stack
B. Queue
C. Heap
D. Linked List
Correct Answer:
C
Chapter: 45
Q712:
What is the time complexity of removing the minimum element from a min-heap?
A. O(1)
B. O(log N)
C. O(N)
D. O(N log N)
Correct Answer:
B
Chapter: 45
Q713:
What is the key property of disjoint sets?
A. If A is related to B and B is related to C, then A is related to C
B. If A is related to B, then B is not related to C
C. If A is related to B, then A and B have no common elements
D. If A is related to B, then A and B are disjoint
Correct Answer:
C
Chapter: 45
Q714:
In the context of disjoint sets, what is the purpose of union operations?
A. To combine two sets into one set
B. To find if two sets are disjoint
C. To partition a set into multiple sets
D. To delete elements from a set
Correct Answer:
A
Chapter: 45
Q715:
What is the use of the `deleteMin` operation in heap data structures?
A. To find the maximum element
B. To remove the minimum element
C. To insert a new element
D. To build a new heap
Correct Answer:
B
Chapter: 45
Q716:
What does the `full()` method check in the PriorityQueue class?
A. Whether the heap is full or not
B. Whether the heap is empty or not
C. The size of the queue
D. The maximum capacity of the heap
Correct Answer:
A
Chapter: 45
Q717:
Which sorting algorithm is known for its efficiency due to its use of heaps?
A. Merge Sort
B. Quick Sort
C. Heap Sort
D. Bubble Sort
Correct Answer:
C
Chapter: 45
Q718:
How is the median of a set of numbers found using heaps?
A. By finding the smallest number in the heap
B. By finding the kth smallest number where k = N/2
C. By sorting the heap and taking the middle element
D. By performing k deleteMin operations, where k = N/2
Correct Answer:
B
Chapter: 45
Q719:
What does the `partition` function in the quicksort algorithm do?
A. It divides the array into two parts based on the pivot element
B. It sorts the array recursively
C. It selects the pivot element randomly
D. It inserts elements into a new array
Correct Answer:
C
Chapter: 45
Q720:
How does the quicksort algorithm improve efficiency?
A. By using a heap to manage elements
B. By dividing the array and sorting each part recursively
C. By using a linked list for sorting
D. By performing insertion sort on each sub-array
Correct Answer:
B