Challenge your understanding of advanced sorting algorithms including Merge Sort, Quick Sort, and Heap Sort. This quiz explores key concepts, performance considerations, and unique properties to help solidify your knowledge of efficient data sorting techniques.
What is the average-case time complexity of Merge Sort when sorting an array of n distinct integers?
Explanation: Merge Sort consistently performs at O(n log n) time complexity in the average case, due to its divide-and-conquer approach that splits and merges arrays recursively. O(n^2) is typical of less efficient algorithms like Bubble Sort. O(log n) and O(n) are not accurate for Merge Sort's overall sorting performance, as the algorithm must process each element multiple times.
How does the choice of pivot affect Quick Sort’s performance, such as when sorting an already sorted list?
Explanation: If Quick Sort consistently picks the smallest or largest element as a pivot on sorted or nearly sorted data, performance drops to O(n^2) due to highly unbalanced partitions. Claiming pivot choice has no effect or that Quick Sort is always O(n log n) ignores practical impact. Instability relates to element order, not time complexity, so that option is also incorrect.
Which property does Heap Sort possess that differentiates it from both Merge Sort and the most common implementations of Quick Sort?
Explanation: Heap Sort is in-place and does not need additional recursion stacks or merge buffers, unlike Merge Sort which needs extra space, and basic Quick Sort implementations which may use stack space for recursion. Heap Sort is not stable by default, so option two is false. Option three is incorrect, as Heap Sort works well on arrays. Option four is incorrect, since Heap Sort is O(n log n) on average.
Why is Merge Sort considered a stable sorting algorithm when sorting objects with duplicate keys?
Explanation: Merge Sort ensures that equal elements appear in the same order as they were in the input, satisfying the definition of stability. Using a randomized pivot is a characteristic of Quick Sort, not Merge Sort. Overwriting values or comparing only adjacent elements does not guarantee stability, making those distractors inaccurate.
During Quick Sort's partition phase, what is the role of the partitioning index with respect to the pivot element?
Explanation: The partitioning index is key to the Quick Sort process, ensuring elements to its left are less than the pivot and those to its right are greater or equal. The partitioning step does not guarantee to place the largest element first or sort the entire array in a single pass. The index is not specifically for finding duplicates, making the other options incorrect.