in Algorithms retagged by
1,139 views
0 votes
0 votes
The median of n elements can be found in  O(logn) time.which one of the following is correct about worst case time complexity of quick sort,if always median is selected as pivot element?

a)O(logn)

b)O(n)

c)O(nlogn)

d)O(nloglogn)
in Algorithms retagged by
1.1k views

4 Comments

U will have to apply partitioning algorithm which takes O(n) time after finding median...
0
0

@akash.dinkar12

Input is already sorted

and midium element is pivot

So, will not worst case will be one run of for loop on the input?

So, why not A)?

 

0
0

@srestha how can u say that input is already sorted ?

1
1

1 Answer

0 votes
0 votes
Since the time complexity of finding the median is O ( log n), it indicate the elements are sorted and binary search for finding the median has been applied.

Since the worst case of time complexity for taking pivot element as median the time complexity will ne O ( n log n)

Related questions

0 votes
0 votes
2 answers
2