This repository have implementations of sorting methods using Golang. If you want to run the benchmark tests, you can run:
make bench
The complexity is calculated like this:
For
For
For
So the complexity is
With simplification we have:
We don't need more memory usage to make this process so, for the space complexity we have:
Algorithms | Best Time complexity | Average Time complexity | Worst Time complexity | Space complexity |
---|---|---|---|---|
Simple Sort | O(Nˆ2) | O(N^2) | O(Nˆ2) | O(1) |
Bubble Sort | O(N) | O(N^2) | O(Nˆ2) | O(1) |
Selection Sort | O(Nˆ2) | O(N^2) | O(Nˆ2) | O(1) |
Insertion Sort | O(N) | O(N^2) | O(Nˆ2) | O(1) |
Merge Sort | O(N*logN) | O(N*logN) | O(N*logN) | O(N) |
Quick Sort | O(N*logN) | O(N*logN) | O(N^2) | O(N) |
Heap Sort | O(N*logN) | O(N*logN) | O(N*logN) | O(1) |