GithubHelp home page GithubHelp logo

h-ssiqueira / sort_algorithms Goto Github PK

View Code? Open in Web Editor NEW
6.0 0.0 2.0 591 KB

Sorting algorithms in C programming with execution time.

License: MIT License

C 98.61% Makefile 0.94% Batchfile 0.45%
sorting-algorithms c algorithms sort sorting contributions-welcome execution-time bigonotation bigocomplexity hacktoberfest

sort_algorithms's Introduction

Sorting Algorithms

GitHub Repository Size Sorts available

Codacy Badge

Contributions

Ubuntu MAC Windows

Visual Studio Code

C

Summary

Description

A program to show the execution time and the variaty of sorting algorithms in C language. There are 48 sorting algorithms avaliable distributed in 8 different categories.


How to execute

On program settings there are avaliable modifications noted in table below:

Configuration Default
Sorting case Random
Random interval 32
Length of array 10
Save results in a text file NO
Display arrays YES
Display execution time YES

Note: you need to have the GCC compiler installed in your machine to execute the instructions below to run the program.


Linux & MAC

Open a terminal and go to project's directory. Execute make in terminal allow to compile the program. Commands avaliable to execute with make (make ${command}):

Command Description
clean Clear all objects generated
cr Compile and run
rmproper Clear all object files
run Execute main program

Windows

On Command Prompt or PowerShell and go to project's directory and execute execute.bat.


Screens

Menu

Menu

Submenu

Submenu

Settings

Settings

Execution

Execution

Exit

Exit


Algorithms

Category Sort
Esoteric & Fun & Miscellaneous Bad Sort
Bogo Bogo Sort
Bogo Sort
Bubble Bogo Sort
Cocktail Bogo Sort
Exchange Bogo Sort
Less Bogo Sort
Pancake Sort
Silly Sort
Sleep Sort
Slow Sort
Spaghetti Sort
Stooge Sort
Exchange Bubble Sort
Circle Sort
Cocktail Shaker Sort
Comb Sort
Dual Pivot Quick Sort
Gnome Sort
Odd-Even Sort
Optimized Bubble Sort
Optimized Cocktail Shaker Sort
Optimized Gnome Sort
Quick Sort
Quick Sort 3-way
Stable Quick Sort
Hybrids Tim Sort
Insertion AVL Tree Sort
Binary Insertion Sort
Cycle Sort
Insertion Sort
Patience Sort
Shell Sort
Tree Sort
Merge Bottom-up Merge Sort
In-Place Merge Sort
Merge Sort
Networks & Concurrent Bitonic Sort
Pairwise Network Sort
Non-Comparison & Distribution Bucket Sort
Counting Sort
Gravity (Bead) Sort
Pigeonhole Sort
Radix LSD Sort
Selection Double Selection Sort
Max Heap Sort
Min Heap Sort
Selection Sort

Complexity Table

Algorithm Worst case Best case Average Space complexity In-place Stable Notes
Bad Sort O(N³) O(N³) O(N³) O(1) ✔️
Bogo Bogo Sort O(infinity) O(N²) O((N+1)!) O(1) ✔️ The worst case can be unbounded due to random manipulation
Bogo Sort O(infinity) O(N) O((N+1)!) O(1) ✔️ The worst case can be unbounded due to random manipulation
Bubble Bogo Sort O(infinity) O(N) O((N+1)!) O(1) ✔️ ✔️ The worst case can be unbounded due to random manipulation
Cocktail Bogo Sort O(infinity) O(N) O((N+1)!) O(1) ✔️ The worst case can be unbounded due to random manipulation
Exchange Bogo Sort O(infinity) O(N) O((N+1)!) O(1) ✔️ The worst case can be unbounded due to random manipulation
Less Bogo Sort O(infinity) O(N²) O((N+1)!) O(1) ✔️ The worst case can be unbounded due to random manipulation
Pancake Sort O(N²) O(N²) O(N²) O(1) ✔️
Silly Sort O(N²) O(N²) O(N²) O(1) ✔️
Sleep Sort O(INT_MAX) O(max(input) + N) O(max(input) + N) O(N) ✔️ Take use of CPU scheduler to sort
Slow Sort O(N*N!) O(N) O((N+1)!) O(1) ✔️
Spaghetti Sort O(N) O(N) O(N) O(N) ✔️
Stooge Sort O(N^(log 3 / log 1.5)) O(N^(log 3 / log 1.5)) O(N^(log 3 / log 1.5)) O(N)
Bubble Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Circle Sort O(N log N log N) O(N log N) O(N log N) O(1) ✔️
Cocktail Shaker Sort O(N²) O(N²) O(N²) O(1) ✔️ ✔️
Comb Sort O(N²) O(N log N) O(N² / 2^p) O(1) ✔️ P is the number of increments
Dual Pivot Quick Sort O(N²) O(N log N) O(N log N) O(log N) ✔️
Gnome Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Odd-Even Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Optimized Bubble Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Optimized Cocktail Shaker Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Optimized Gnome Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Quick Sort O(N²) O(N log N) O(N log N) O(log N) ✔️
Quick Sort 3-way O(N²) O(N) O(N log N) O(log N) or O(N) ✔️
Stable Quick Sort O(N²) O(N log N) O(N log N) O(N) ✔️ ✔️
Tim Sort O(N log N) O(N) O(N log N) O(N) ✔️
AVL Tree Sort O(N log N) O(N) O(N log N) O(N) ✔️ In worst case, O(N²) when using Binary Search Tree and O(N log N) when using Self-Balanced Binary Search Tree
Binary Insertion Sort O(N log N) O(N) O(N log N) O(1) ✔️ ✔️
Cycle Sort O(N²) O(N²) O(N²) O(1) ✔️
Insertion Sort O(N²) O(N) O(N²) O(1) ✔️ ✔️
Patience Sort O(N log N) O(N) O(N log N) O(N) ✔️
Shell Sort O(N<sup>3/2</sup>) or O(N log² N) O(N log N) O(N^1.25) to O(N²) O(1) ✔️
Tree Sort O(N²) O(N log N) O(N log N) O(N) ✔️ In worst case, O(N²) when using Binary Search Tree and O(N log N) when using Self-Balanced Binary Search Tree
Bottom-up Merge Sort O(N log N) O(N log N) O(N log N) O(N) ✔️
In-Place Merge Sort O(N²) O(N²) O(N²) O(log N) ✔️ ✔️
Merge Sort O(N log N) O(N log N) O(N log N) O(N) ✔️
Bitonic Sort O(log² N) O(log² N) O(log² N) O(N log² N) ✔️
Pairwise Network Sort (log N)(log N+1)/2 or O(N log N) O(N log N) O(N log N) N(log N)(log N-1)/4 + N-1 ✔️ Worst case is using parallel time and space complexity non-parallel time
Bucket Sort O(N²) O(N+k) O(N+k) O(N+k) ✔️ k is the number of buckets
Counting Sort O(N+k) O(N+k) O(N+k) O(N+k) ✔️ k is the range of input data
Gravity (Bead) Sort O(S) O(1) or O(sqrt(N)) O(N) O(N²) ✔️ S is the sum of array elements, O(1) cannot be implemented in practice
Pigeonhole Sort O(N+n) O(N+n) O(N+n) O(N+n) ✔️ N is the number of elements and n is the range of input data
Radix LSD Sort O(NW) O(NW) O(NW) O(N) ✔️ W is the maxumum element width (bits)
Double Selection Sort O(N²) O(N²) O(N²) O(1) ✔️ \frac{N^2-N}{2} Comparisons
Max Heap Sort O(N log N) O(N log N) O(N log N) O(1) ✔️
Min Heap Sort O(N log N) O(N log N) O(N log N) O(1) ✔️
Selection Sort O(N²) O(N²) O(N²) O(1) ✔️ \frac{N^2-N}{4} Comparisons

sort_algorithms's People

Contributors

h-ssiqueira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

sort_algorithms's Issues

Self-balancing binary search tree

Hello,

You list min heap sort and max heap sort.

Heap sort is a particular sort in a more general category of sorts which you might call "data structure sorts".

Heap sort can be written in four lines of code:

heap_sort(List l):
    Heap h = new heap()
    for e in l:
        move e from l to h
    while h is not empty:
        e = pop(h)
        add e to l

There are several other data structures that can replace a heap in this algorithm. A notable data structure is the binary search tree. I suggest you look it up (the wikipedia article is a great start). When a binary search tree is traverse in depth-first-search order, the elements are encountered in sorted order. So this is an algorithm:

binary_tree_sort(List l):
    BinarySearchTree t = new BinarySearchTree()
    for e in l:
        move e from l to t
    for e in depth_first_search(t):
        add e to l

This algorithm will be O(n log n) if the binary tree is guaranteed to always be relatively balanced. If the tree has no balancing mechanism, the tree might become degenerate, and the algorithm will run in n^2.

There are several different balancing mechanisms. You can look up "self-balancing binary search tree" and "red-black tree".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.