Saturday, December 28, 2024
Google search engine
HomeData Modelling & AIAlgorithms | Sorting | Question 18

Algorithms | Sorting | Question 18

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments