This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Quicksort using Random Sampling”.
1. Quick sort uses which of the following method to implement sorting?
Explanation: In order to implement sorting, Fast Sort divides the input array around the pivot. Partitioning is the name given to this type of sorting.
2. Randomized quick sort is an in place sort.
Explanation: Algorithms that run in place need no or very little auxiliary space. Quick sort is classified as an in-place sorting algorithm because it needs only O bytes of auxiliary space (log n).
3. Randomized quick sort is a stable sort.
Explanation: Like regular fast sort, randomised quick sort is not a stable sorting algorithm. It’s because elements with the same values in the output sorted array aren’t guaranteed to appear in the same relative order.
4. What is the best case time complexity randomized quick sort?
A) O(log n)
B) O(n log n)
D) O(n2 log n)
Explanation: When the array is partitioned evenly around the pivot, the best case time complexity is given. It’s calculated using the formula T(n) = 2T(n/2) + n, which yields the result O. (n log n).
5. Which of the following is incorrect about randomized quicksort?
A) it has the same time complexity as standard quick sort
B) it has the same space complexity as standard quick sort
C) it is an in-place sorting algorithm
D) it cannot have a time complexity of O(n2) in any case.
Explanation: In most cases, randomised simple sort avoids the worst-case complexity of O(n2). However, in a few rare cases, the time complexity will exceed O. (n2). However, the chances of this happening are extremely slim.