The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

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

+13 votes

Best answer

+4 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.

+1 vote

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

0 votes

- All categories
- General Aptitude 1.1k
- Engineering Mathematics 4.1k
- Digital Logic 1.7k
- Programming & DS 3.1k
- Algorithms 2.7k
- Theory of Computation 3.3k
- Compiler Design 1.2k
- Databases 2.5k
- CO & Architecture 2.2k
- Computer Networks 2.5k
- Non GATE 820
- Others 1.2k
- Admissions 244
- Exam Queries 424
- Tier 1 Placement Questions 16
- Job Queries 39
- Projects 4

29,997 questions

37,681 answers

96,746 comments

35,329 users