In quick-sort, for sorting elements, the smallest element is selected as pivot using an time algorithm. What is the worst case time complexity of the quick sort?
View worked solution
Answer: B
In the given quick-sort variant, the pivot is always chosen as the smallest element using an time selection algorithm. This guarantees a consistent split ratio of at least at every step of the recursion.
The recurrence relation for the worst-case time complexity is:
Where:
- and represent the time to recursively sort the two partitioned subarrays.
- is the time taken to find the smallest element and partition the array around it.
We can solve this recurrence using the recursion tree method:
- At the root (level 0), the cost is .
- At level 1, the subproblems have sizes and . The total cost is .
- At any level , the sum of the sizes of all subproblems is at most , meaning the total work done at each level is bounded by .
- The recursion stops when the subproblem size reduces to . The longest path in the tree corresponds to repeatedly taking the larger fraction , which gives a maximum depth of:
Multiplying the work per level by the maximum depth of the tree:
Since the depth is at least , we also have . Thus, the worst-case time complexity is .
Free practice · Your answers on this page are not saved.
