Wiki has a good cheat sheet, but however it does not involve no. of comparisons or swaps. (though no. of swaps is usually decides its complexity). So I created the following. Is the following info is correct ? Please let me know if there is any error, I will correct it.
Insertion Sort:
- Average Case / Worst Case : $\Theta(n^2)$ ; happens when input is already sorted in descending order
- Best Case : $\Theta(n)$ ; when input is already sorted
- No. of comparisons : $\Theta(n^2)$ in worst case & $\Theta(n)$ in best case
- No. of swaps : $\Theta(n^2)$ in worst/average case & $0$ in Best case
Selection Sort:
- Average Case / Worst Case / Best Case: $\Theta(n^2)$
- No. of comparisons : $\Theta(n^2)$
- No. of swaps : $\Theta(n)$ in worst/average case & $0$ in best case At most the algorithm requires N swaps, once you swap an element into place, you never touch it again.
Merge Sort :
- Average Case / Worst Case / Best case : $\Theta(nlgn)$ ; doesn't matter at all whether the input is sorted or not
- No. of comparisons : $\Theta(n+m)$ in worst case & $\Theta(n)$ in best case ; assuming we are merging two array of size n & m where $n<m$
- No. of swaps : No swaps ! [but requires extra memory, not in-place sort]
Quick Sort:
- Worst Case : $\Theta(n^2)$ ; happens input is already sorted
- Best Case : $\Theta(nlogn)$ ; when pivot divides array in exactly half
- No. of comparisons : $\Theta(n^2)$ in worst case & $\Theta(nlogn)$ in best case
- No. of swaps : $\Theta(n^2)$ in worst case & $0$ in best case
Bubble Sort:
- Worst Case : $\Theta(n^2)$
- Best Case : $\Theta(n)$ ; on already sorted
- No. of comparisons : $\Theta(n^2)$ in worst case & best case
- No. of swaps : $\Theta(n^2)$ in worst case & $0$ in best case
Linear Search:
- Worst Case : $\Theta(n)$ ; search key not present or last element
- Best Case : $\Theta(1)$ ; first element
- No. of comparisons : $\Theta(n)$ in worst case & $1$ in best case
Binary Search:
- Worst case/Average case : $\Theta(logn)$
- Best Case : $\Theta(1)$ ; when key is middle element
- No. of comparisons : $\Theta(logn)$ in worst/average case & $1$ in best case