• retagged by
2,077 views
2 2 votes
We want to sort input sequence in ascending order. If inputs are already ascending order , then what is the time complexity to run this of all well known sort (Bobble sort, quick sort,merge sort, insertion sort, selection sort, heap sort,...)

Which complexity of sorting will be change with general case complexity? Which are not ?

If any resource u have for this question plz. provide

2 Answers

Best answer
2 2 votes

For already sorted sequence,

Bubble sort will take $o(n)$

Insertion sort will take $o(n)$, but better than bubble sort.

Merge sort will take $o(n log n)$

Quick sort will take $o(n^{2})$

Heap sort will take $o(n log n)$

• selected by
2 2 votes

Insertion sort--->Best Case : Θ(n); when input is already sorted

Selection sort--->Average Case / Worst Case / Best Case: Θ(n2)

Merge sort--->Average Case / Worst Case / Best case : Θ(nlgn) ; doesn't matter at all whether the input is sorted or not

Quick sort--->Best Case : Θ(nlogn)when pivot divides array in exactly half

Bubble sort--->Best Case : Θ(n) ; on already sorted


Heap sort--->Θ(nlogn) in best case

All complexities depend on the size of the input.

Position:
Show:

Related questions

8 8 votes
6 6 answers
3.9k
3.9k views
Arjun asked Feb 27, 2025
3,895 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...
0 0 votes
1 1 answer
106
106 views
GO Classes asked Aug 25
106 views
Let $P$ be the problem of sorting $n\geq1$ elements using only comparisons.Consider the class of all comparison-based algorithms that correctly solve $P$.What is the asym...
1 1 vote
0 0 answers
2.2k
2.2k views
0 0 votes
1 1 answer
1.6k
1.6k views
GateAspirant999 asked Sep 16, 2018
1,560 views
Consider the following sorting algorithmSorting (A, low, high)Iif (low == high) return;if (low $+1==$ high)Iif $(\mathrm{A}[$ low $]>\mathrm{A}[$ high $])$swap (A[low], A...