1.9k views

Let $P$ be a quicksort program to sort numbers in ascending order. Let $t_{1}$ and $t_{2}$ be the time taken by the program for the inputs $[1 \ 2 \ 3 \ 4]$ and $[5 \ 4 \ 3 \ 2 \ 1]$, respectively. Which of the following holds?

1. $t_{1} = t_{2}$
2. $t_{1} > t_{2}$
3. $t_{1} < t_{2}$
4. $t_{1}=t_{2}+5 \log 5$
edited | 1.9k views
–1
But for 1,2,3,4 i think there will be no swaps because they are already in place we only need to compare only
+1
@Bhagirathi, yes it is sorted, and it is the worst case for quicksort, now if you want to do time estimation then you have to consider the implementation also....right?
0
the example you have taken it doesnt require to include the swaps i think
0
Has anybody got the correct answer and explaination yet?? And no, I think question is framed correctly.
+1
how to deal with this kind of question which does not consider any pivot element ??
+4
The number of inputs is different in both cases. ([1,2,3,4] compared to [5,4,3,2,1]). The only interesting thing about the question is to observe the fact that both represent the worst case sorting times of quicksort (without randomised pivot) resulting from the recurrence:  $T(n) = T(n-1) + \Theta(n) = \Theta(n^{2})$.

ACTUALLY IN BOTH THE CASES IT WILL TAKE $O(n^2)$ TIME ($O(n)$ TIME FOR PARTITION ALGORITHM AND $T(n-1)$ TIME FOR SUB PROBLEM. AS $n$ IS THE NUMBER OF INPUTS AND IN THE 2ND CASE INPUTS ARE 5(GREATER THAN 1ST ONE THAT IS 4) I THINK $t_1<t_2$
edited by
+2
@arjun sir , How can you certian about the answer because they didn't mention the position of pivot here .
0
How to solve this when no pivott is given.. answer should be a?
0
answer C) is correct..time taken is asked not the time complexity and by default we should consider last element as pivot.
+1
0
Yes.......
0
@reena , I don't think that there is any rule that by default we should have to pick last element as pivot. If possible please provide any good reference for it.

In this questions ,they have asked the running time and not number of comparisons or swaps.

Time complexity with depend on n.

Since ,both the inputs [1,2,3,4] and [5,4,3,2,1] are already sorted, so both take O(n^2) time.

(a) is correct.

0
bt Here # of elements r 4 and 5 .... So option C ....
0
yes,if it ask about time complexity, then t1=t2 is correct but here they have asked about time taken to compare so c will be the ans.
It will be option A.t1 = t2 ,if the list is already sorted in ascending,descending or even all elements in the list are same (all elements identical) it will be have worst case partion for quicksort and complexity will be O(n^2).
The question seems to be wrong.There should be 5 inputs for the 1st case.otherwise t1<t2
0
t1=t2 .In both cases if last element is taken as pivot then n-1element in the lower part and 1 element in the right half part..this thing repeat again.so worst happen when i/p is already sorted even in ascending order or in descending order.
They said that time taken by input 1 and 2 are t1 and t2 not time complexity. So we consider value here.

1
2