Implementation of 8 different sorting algorithms in Python:
- Selection sort
- Bubble sort
- Quick sort
- Heap sort
- Insertion sort
- Merge sort
- Shell sort
- Pancake sort
Selection sort is a simple sorting algorithm that sorts an array by repeatedly finding the minimum element from the unsorted part of the array and putting it at the beginning. The algorithm maintains two subarrays: the sorted subarray, which is initially empty, and the unsorted subarray, which is initially the entire input array.
Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.
Quick sort is a divide-and-conquer algorithm that works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively.
Heap sort is a comparison-based sorting algorithm that uses a binary heap data structure to sort an array. The algorithm divides the input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element from it and moving that to the sorted region.
Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Merge sort is a divide-and-conquer algorithm that works by dividing the input array into two halves, sorting each half recursively, and then merging the two sorted halves.
Shell sort is a generalization of insertion sort that allows the exchange of items that are far apart. The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared.
Pancake sort is a variation of selection sort that sorts an array by repeatedly flipping the largest element to the beginning of the array, and then flipping the entire array to move the largest element to its correct position.