Sort Algorithms排序算法基础详解


原文链接: Sort Algorithms排序算法基础详解

https://github.com/fabioberger/sort

Algorithms

Reviewing algorithms, learning go. Images from wikipedia.

  • Binary Search

Binary search

Sorting

Exchange Sorts:

  • Bubble Sort

Bubble Sort
  • Odd Even Sort

Odd - Even Sort
  • Quicksort

Quick Sort

Selection Sorts

  • Selection Sort

Selection Sort

Insertion Sorts

  • Insertion Sort

Insertion Sort

Merge Sorts

  • Merge Sort

Merge Sort

Primality

  • Naive Primality

  • Sieve of Eratosthenes

Sieve of Eratosthenes

Graphs

Trees

Binary trees

Creation, insertion, searching, and simultaneously searching via go routines. Taken from golang.org

Binary Trees

Outputs

Search

Binary Search:

  • Search Space: [0 1 2 3 4 5 6 7 8 9]
  • a[ 9 ] = 9

Binary Search:

  • Search Space: [0 1 2 3 4 5 6 7 8 9]
  • a[ 2 ] = 2

Binary Search:

  • Search Space: [0 1 2 3 4 5 6 7 8 9]
  • 15 was not found

Binary Search:

  • Search Space: [0 1 2 3 4 5 6 7 8 9]
  • a[ 5 ] = 5

Binary Search:

  • Search Space: [0 1 2 3 4 5 6 7 8 9]
  • 10 was not found

Sort

Quicksort

Unsorted:

  • [9 8 7 6 5 4 3 2 1 0]

Sorted via Quicksort:

  • [0 1 2 3 4 5 6 7 8 9]

Unsorted:

  • [0 9 3 5 4 1 6 7 8 2]

Sorted via Quicksort:

  • [0 1 2 3 4 5 6 7 8 9]
`