recategorized by
15,344 views
45 votes
45 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 $\left[1 \ 2 \ 3 \ 4\right]$ and $\left[5 \ 4 \ 3 \ 2 \ 1\right]$, 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$ 
recategorized by

5 Answers

Best answer
56 votes
56 votes
Actually, in both the cases, it will take $O(n^{2})$ time for partition algorithm and $T(n-1)$ time for subproblem. As $n$ is the number of inputs and in the $2^{\text{nd}}$ case inputs are $5($greater than $1^{\text{st}}$ one that is $4),t_{1}<t_{2}.$

Correct Answer: C.
edited by
15 votes
15 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
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 votes
–1 votes
The question seems to be wrong.There should be 5 inputs for the 1st case.otherwise t1<t2
Answer:

Related questions

11.8k
views
3 answers
34 votes
makhdoom ghaya asked Feb 11, 2015
11,762 views
Which one of the following is the recurrence equation for the worst case time complexity of the quick sort algorithm for sorting $n\;( \geq 2)$ numbers? In the recurrenc...
19.6k
views
6 answers
46 votes
go_editor asked Sep 26, 2014
19,571 views
Let $P$ be quicksort program to sort numbers in ascending order using the first element as the pivot. Let $t_1$ and $t_2$ be the number of comparisons made by P for the i...
13.9k
views
4 answers
43 votes
Kathleen asked Sep 14, 2014
13,886 views
Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using Randomized quicksort?$O...
1.5k
views
2 answers
1 votes
makhdoom ghaya asked Nov 15, 2016
1,472 views
The relative costs of assigning jobs $J_{1}, J_{2}$ and $J_{3}$ to machines $M_{1}, M_{2}$ and $M_{3}$ are given below:$$\begin{array}{|c|cccc|}\hline\textbf{JOBS} && \te...