Open In App

Algorithms | Sorting | Question 18

Like Article
Like
Save Article
Save
Share
Report issue
Report

Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element that splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then

(A)

T(n) <= 2T(n/5) + n

(B)

T(n) <= T(n/5) + T(4n/5) + n

(C)

T(n) <= 2T(4n/5) + n

(D)

T(n) <= 2T(n/2) + n


Answer: (B)

Explanation:

For the case where n/5 elements are in one subset, T(n/5) comparisons are needed for the first subset with n/5 elements, T(4n/5) is for the rest of 4n/5 elements, and n is for finding the pivot. If there are more than n/5 elements in one set then other sets will have less than 4n/5 elements and time complexity will be less than T(n/5) + T(4n/5) + n because the recursion tree will be more balanced.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads