The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+19 votes

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?

- $t_{1} = t_{2}$
- $t_{1} > t_{2}$
- $t_{1} < t_{2}$
- $t_{1}=t_{2}+5 \log 5$

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

@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?

Has anybody got the correct answer and explaination yet?? And no, I think question is framed correctly.

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})$.

+16 votes

Best answer

+8 votes

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.

+4 votes

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).

–1 vote

- All categories
- General Aptitude 1.2k
- Engineering Mathematics 4.7k
- Digital Logic 1.9k
- Programming & DS 3.5k
- Algorithms 3k
- Theory of Computation 3.7k
- Compiler Design 1.5k
- Databases 2.8k
- CO & Architecture 2.5k
- Computer Networks 2.9k
- Non GATE 837
- Others 1.2k
- Admissions 284
- Exam Queries 398
- Tier 1 Placement Questions 17
- Job Queries 51
- Projects 7

33,711 questions

40,253 answers

114,363 comments

38,875 users