This repo contains various sorting algorithms written in go.
Running main.go
will compare the execution times for each of the different sorting algorithms in the sort
folder, instead of outputting the sorted values.
I implemented multithreading to improve the overall runtime, instead of running each sort sequentially.
Use the -h
or -help
flags to see all options.
To compile into a binary, use the following while in the directory with main.go
:
go build
There are a few different modes and options To run them, open the root folder of this repo locally, in a terminal. Then, follow the instructions below depending on which mode you want to execute.
Notes:
- Bad sorts (Bogo, Stooge) will default to certain values due to their slowness.
- Bitonic will round up to the nearest power of 2, due to its algorithmic nature. To do this, it pads the input array with 0s.
- Count mode cannot be used with input mode.
- Verbose option can be used with any of the modes
Default mode executes on the default (random) values. In your terminal, run:
go run main.go
This will run the program on the default file: test.txt
, which has 100 values.
You can input a number of values to test the sorting algorithms against. In your terminal, run:
go run main.go -count ####
where #### is replaced by the number you want to enter. For instance:
go run main.go -count 69420
will execute each of the sorting algorithms on 69420 randomly generated digits varying in size.
You can also input a file of your own custom values to test the sorting algorithms against. In your terminal, run:
go run main.go -input filename.txt
where filename.txt
is the path to the file you want to use. For instance:
go run main.go -input input.txt
will use the file input.txt
(which is provided in this repo).
Verbose is an option to see extra printing or debug information. Apply 0 for quiet, or 1 for verbose:
go run main.go -verbose 1
Verbose can be added to other modes (i.e. count+verbose mode).
- sort
bitonic.go
-- implementation for bitonic sortbogo.go
-- implementation for bogo sortbubble.go
-- implementation for bubble sortbucket.go
-- implementation for bucket sortcocktail.go
-- implementation for cocktail sortcomb.go
-- implementation for comb sortcounting.go
-- implementation for counting sortcycle.go
-- implementation for cycle sortgnome.go
-- implementation for gnome sortheapsort.go
-- implementation for heap sortinsertion.go
-- implementation for insertion sortmerge.go
-- implementation for merge sortoddeven.go
-- implementation for odd-even sortpancake.go
-- implementation for pancake sortpigeonhole.go
-- implementation for pigeonhole sortquicksort.go
-- implementation for quicksortradix.go
-- implementation for radix sortselection.go
-- implementation for selection sortshell.go
-- implementation for shell sortstooge.go
-- implementation for stooge sorttim.go
-- implementation for tim sort
- utils
utils.go
-- general utils and other useful things
go.mod
-- module fileinput.txt
-- sample text file with numbers 1 thru 16384 (shuffled)main.go
-- houses mainREADME.md
-- the thing you're readingtest.txt
-- smaller test file with numbers 1 thru 100 (shuffled)