328 views
0 votes
0 votes

Please explain me the difference between the following questions and their answers. All seems similar to me with different answers.

https://gateoverflow.in/2048/gate2014-3-14

https://gateoverflow.in/1830/gate2006-52

https://gateoverflow.in/25209/tifr2012-b-14

1 Answer

0 votes
0 votes

MEDIAN means the middle element in the sorted array. Consider the below example.

[2,5,3,4,1] if median is selected as pivot i.e '3'  then after partition algo. is applied if will placed in middle i.e [2,1]{3}[4,5}. so it will divide the array in two halves everytime since always median is selected as pivot. so Time complexity will be O(nlogn).

Whereas middle/central element means the middle element of input. so it is possible that in input middle element is smallest/largest there partiton algo will place it at first/last hence performing best case of quicksort i.e O(n^2).

Related questions

0 votes
0 votes
1 answer
1
tusharb asked Feb 18, 2022
692 views
As we know the time complexity of solving the greedy knapsack algorithm depends mainly on the sorting algorithm used, Can we use counting sort as the sorting algorithm to...
1 votes
1 votes
1 answer
2
afroze asked Nov 4, 2021
572 views
what is significance of loop Invariant?when we use a loop in an algo we check it , if it properly runs then fix it in that, then why do check separately loop invariant ?
1 votes
1 votes
1 answer
3
kumar.dilip asked Jan 19, 2019
685 views
The average no. of comparisons performed by the merge sort algorithm, in merging 2 sorted lists of length 2 is___________.Ans: $\frac{8}{3}$
0 votes
0 votes
1 answer
4
Prince Sindhiya asked Jan 19, 2019
346 views
When relative ordering of equal keys is preserved after sorting then it is called stable. Quick sort and heap sort is not a stable sorting algorithm . Doubt -IS Select...