edited by
4,123 views
0 0 votes

Which one  of the following is the recurrence equation for the worst case time complexity of finding Kth smallest element in an array of size ‘n’ using partition function? Assume ‘c’ is constant.

A. T(n) = 2T(n/2) + c . n

B. T(n) = 2T(n – 1) + c

C. (n) = T(n – 1) + c . n

D. T(n) = T(n/2) + c . n

Explanation Please and please tell me the different ways we can solve this problem

2 Answers

3 3 votes

This question is for recurrence equation, so we have to apply divide and conquer approach. Finding Kth smallest element using divide and conquer algorithm is known as Selection procedure. Selection procedure is similar to quick sort partition algorithm. After every pass we will get one element at it's correct position. This position is nothing but smallest value at this position . Suppose after first pass we will get pivot element at 7th position so 7th smallest element is Pivot element.

Difference between quick sort and selection procedure is, in quick sort we will partitioning array in two parts but here we only partitioning array into one part. 

We will partitioning array into only one part because after every pass we exact know that either we will go at right partition or left partition.

Example :

15,25,10,85,75,95,87,5,6

Here we have 9 elements array and we want to find 3rd smallest number.

Now we apply partitioning algorithm and take pivot as first element

First pass output ---->6 10 5 [15] 75 95 87 23 85 ------>15 is at 4th position so 15 is 4th smallest but we want 3rd smallest so we will go to left partition and we have only three elements 6 10 5

Second pass output---->5 [6] 10 ----->6 is at 2nd position so 6 is 2nd smallest but we want 3rd smallest so we will go to right and we have only one element 10

So our 3rd smallest element is ----------->10

Now we all now that in worst case partition will be occur in (n-1) part so

T(n) = T(n – 1) + c . n

Position:
Show:

Related questions

0 0 votes
0 0 answers
1.9k
1.9k views
yes asked Dec 11, 2015
1,936 views
time complexit..?Q1. to find kth smallest element from a binary heap...a) O(k log k) b) O(k log n) c) O(1) d)O(nk) e) a,b bothQ2. Print the biggest K e...
11 11 votes
5 answers 5 answers
6.0k
6.0k views
Vikrant Singh asked Dec 28, 2014
5,968 views
What is the complexity of finding $50^{th}$ smallest element in an already constructed binary min-heap?$\Theta(1)$$\Theta (\log n)$$\Theta (n)$$\Theta (n \log n)$
3 3 votes
2 2 answers
3.4k
3.4k views
rahuldb asked May 10, 2017
3,354 views
Please show the workingConsider a Quick-sort algorithm that always selects $(n / 5)^{\text {th }}$ smallest as the pivot element using $\mathrm{O}(\mathrm{n})$ time algor...
6 6 votes
2 answers 2 answers
9.0k
9.0k views
worst_engineer asked Oct 7, 2015
8,970 views
In quick sort , for sorting n elements , the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What will be the time complexity?it is $\Theta (...