Correct : Sorting Algorithm
The question asks us to compare the number of comparisons made by QuickSort when the first element is always chosen as the pivot.
Analyze the Options:
Input 1: [1, 2, 3, 4, 5]
The first element, 1, is the smallest element, so every other element is compared with the pivot. This creates the worst-case pattern, where the list is divided as 0 and 4, then 0 and 3, and so on.
Comparisons = 4 + 3 + 2 + 1 = 10.
Input 2: [4, 1, 5, 3, 2]
The first pivot is 4. The elements 1, 3, and 2 go to the left, while 5 goes to the right. The resulting subarrays are smaller and require fewer comparisons than the first input.
Comparisons = 4 + 3 + 1 = 8.
Comparison:
t1 = 10 and t2 = 8.
Therefore, t1 > t2.
Correct Answer: c) t1 > t2
Similar Questions
Total Unique Visitors