• retagged by
13,493 views
27 27 votes

The complexity of comparison based sorting algorithms is:

  1. $\Theta (n \log n)$
  2. $\Theta (n)$
  3. $\Theta \left(n^2\right)$
  4. $\Theta (n\sqrt n)$

2 Answers

Best answer
38 38 votes

First of all which sorting algorithm is being asked? It is not just the normal ones we see in algorithm text books but can be any sorting algorithm which uses comparisons. So, in crux we cannot rely on any specific algorithms for this question.

Now, coming to the options, we can see that $\Theta$ notation is used. We use $\Theta$ notation for a problem when

  1. we have a lower bound for the solution -- that is any algorithm which solves the problem must have minimum this much complexity (time complexity being implied)
  2. there exist an algorithm which solves the problem with above minimum time complexity (worst case input being implied)

For comparison based sorting we already have known algorithms like heap sort and merge sort, which solves the problem in $O(n \log n)$ $($See $O)$ and now if we show that this is the best possible by any algorithm our answer becomes $\Theta (n \log n).$

And it is indeed proved that for comparison based sorting minimum $\Omega(n \log n)$ comparisons are required and considering time taken being proportional to the number of comparisons, the time complexity is also $\Omega(n \log n).$ Proof of this is given here but in essence it says

  • The output of sorting $n$ elements can be any of the $n!$ permutations.
  • Each comparison reduces the possibility by $2$
  • So, to finish all $n!$ permutations we need minimum $\lg n!$ comparisons which is $\Omega (n \lg n)$

Now, if someone asks what is the minimum number of comparisons to sort $5$ elements answer is definitely $\geq$ $\lg 5! \geq \lg 120 \geq 7. $ We can only use $\geq$ here and not $=$ unless we prove that we can do it in $7$ comparisons. But interestingly, this $\geq$ becomes $=$ till $n = 11$ as given in below Wikipedia link.

Ref: https://en.wikipedia.org/wiki/Comparison_sort

Answer A. $\Theta (n \log n)$

• selected by
3 3 votes

Only A & C are possible in Comparision based sorting.   

Algorithm Time Complexity
  Average Worst
Quicksort O(n log(n)) O(n^2)
Mergesort O(n log(n)) O(n log(n))
Heapsort O(n log(n)) O(n log(n))
Bubble Sort O(n^2) O(n^2)
Insertion Sort O(n^2) O(n^2)
Select Sort O(n^2) O(n^2)

$$\textbf{Time  Complexity}$$

$$\begin{array}{|l|l|}\hline \textbf{Algorithm} & \textbf{Average} & \textbf{Worst} \\\hline \text{Quicksort} & O(n\ log\ n) & O(n^{2})   \\\hline  \text{Mergesort} & O(n\ log\ n) & O(n\ log\ n)   \\\hline \text{Heapsort} & O(n\ log\ n) & O(n\ log\ n)   \\\hline \text{Bubble sort} & O(n^{2}) & O(n^{2})   \\\hline \text{Insertion sort} & O(n^{2}) & O(n^{2})   \\\hline  \text{Selection sort} & O(n^{2}) & O(n^{2})   \\\hline \end{array}$$

• edited by
Answer:
Position:
Show:

Related questions

32 32 votes
2 answers 2 answers
10.7k
10.7k views
Misbah Ghaya asked Nov 19, 2016
10,740 views
The number of rooted binary trees with $n$ nodes is,Equal to the number of ways of multiplying $(n+1)$ matrices.Equal to the number of ways of arranging $n$ out of $2 n$ ...
9 9 votes
6 6 answers
4.0k
4.0k views
Arjun asked Feb 27, 2025
3,960 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
20 20 votes
1 answers 1 answer
9.6k
9.6k views
Misbah Ghaya asked Nov 19, 2016
9,594 views
Match the pairs in the following questions:$$\begin{array}{|ll|ll|}\hline (a) & \text{Strassen's matrix multiplication algorithm} & (p) & \text{Greedy method} \\\hline (...
21 21 votes
2 2 answers
5.8k
5.8k views
Misbah Ghaya asked Nov 23, 2016
5,823 views
State whether the following statements are TRUE or FALSE with reason:The Link-load-and-go loading scheme required less storage space than the link-and-go loading scheme.