retagged by
1,428 views
2 votes
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
retagged by

2 Answers

Best answer
2 votes
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 votes
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.

Related questions

1 votes
1 votes
0 answers
1
0 votes
0 votes
1 answer
2
0 votes
0 votes
3 answers
3