Skip to content

leomirandadev/golang-sort-algorithms

Repository files navigation

Sort Algorithms in Golang

This repository have implementations of sorting methods using Golang. If you want to run the benchmark tests, you can run:

make bench

Simple Sort

The complexity is calculated like this:

For $N = 3$ we have: $$(2+1+0) = 3 = 3*2/2 = 3$$

For $N=4$ we have: $$3+2+1+0 = 6 = 4*3/2 = 6$$

For $N=13$ we have: $$12+11+10+9+8+7+6+5+4+3+2+1+0 = 78 = 13*12/2 = 78$$

So the complexity is

$$ O(N-1 + N-2 + N-3 + N-4 ...) = O(N*(N-1)/2) $$

With simplification we have: $O(Nˆ2)$

We don't need more memory usage to make this process so, for the space complexity we have: $O(1)$

Other Sort Algorithms

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)

About

Examples of sort algorithms written in golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published