Sorting Algorithms

Bubble Sort

Bubble Sort is a simple algorithm that sorts by switching the smaller of 2 numbers. It starts at the end of the array and goes to the start. It compares each index to the index before it. As it moves down it sees which is smaller, then it swaps it to the left. This behavior can been seen in the sketch as a small number moving very quickly to the left and the higher numbers slowly shifting to the right.
github.com/lucas6238/Sorting/BubbleSort

Shaker Sort

Shaker Sort sorts the same way as bubble sort except in both directions. It switches directions in which it searches through the array for the next value. If the algorithm is moving up the array it is looking for the largest number, if it is moving down it is looking for the smallest number. This results in the top and bottom of the array being sorted first.
github.com/lucas6238/Sorting/ShakerSort


Selection Sort

Selection Sort is based on finding the next value by searching the unsorted portion of the array. First the entire array is searched, and the number that is found to contain the lowest number is swapped with the number at index 0. The portion of the array that is searched shrinks and the process is repeated.
github.com/lucas6238/Sorting/SelectionSort

Insertion Sort

Insertion Sort works by inserting an element into a growing sorted list. The first two elements are compared and sorted and then each number following is compared to all numbers on the left and swapped. It will stop swapping and move to the next number when it sees that the number to the left is less than its value.
github.com/lucas6238/Sorting/InsertionSort

Shell Sort

Shell Sort is a improved version of insertion sort. Comparisons occur first at large intervals and work down to a interval of just 1. This allows for numbers never having to move very far on the last interval of sorting.
github.com/lucas6238/SortingShell


Quick Sort

Quick Sort is a more commonly used sorting algorithm. It works by splitting up the array into partitions. A pivot point is chosen at random and all values on the wrong side are moved to the correct side. This means that if a pivot point is chosen and a number is found that is less than the pivot point value but it is above it in the array, it is swapped with a number that is greater than the pivot point value but below the pivot point in the array. The process of partitioning continues recursively until the array is sorted.
github.com/lucas6238/Sorting/QuickSort


Merge Sort

Merge Sort is a recursive sorting algorithm that combines sorted portions of the array together. The array is broken down into very small parts where 2 numbers are compared and sorted. Then this section of sorted array is combined with another of equal size in order to have a a sorted array of 4 numbers. This process of creating sorted lists continues until the entire array has only two lists which are then combined and the array is completely sorted.
github.com/lucas6238/Sorting/MergeSort


Heap Sort

Heap Sort has two distinct parts first the random numbers in the array are used to create a binomial tree this process is called heapify, and then that tree is transformed into a sorted array. The binomial tree is organized where each parent has exactly 2 children which are smaller in value, this process means that the largest value will always be at the root of the tree. To sort the array we take the root, which is the largest and swap it with the value at the end of the array, the small value that is now positioned at the beginning is sorted correctly into the heap and the process is repeated.
github.com/lucas6238/Sorting/Heapify