Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 2.93 KB

sorting.md

File metadata and controls

65 lines (50 loc) · 2.93 KB

Sorting

Sorting a sequence of elements is a well-known problem with many solutions. We could learn a lot just by looking at the steps that different algorithms take to produce a solution.

Selection sort

Selection sort is probably the simplest way of sorting a collection - take the minimum element and put in the first postion, take the next smallest element and put it next to the previous. Do this for all elements and you have a sorted collection! Here is a description of the steps of the algorithm. Here you can find a nice visualization of the steps of the algorithm.

Insertion sort

Insertion sort builds the sorted array by constantly adding elements to it in the correct position. Here is a description of the steps of the algorithm. Here you can find a nice visualization of the steps of the algorithm.

Merge sort

Merge sort is a nice way of sorting a sequence of elements. It is a divide and conquer algorithm that divides the problem in smaller parts, solves them separately and then combines the solutions to produce a result. Here you can find a nice visualization of the steps of the algorithm.

Bubble sort

Bubble sort produces a sorted sequence by comparing and swapping adjacent elements. Here you can find a nice visualization of the steps of the algorithm.

Shell sort

Shell sort improves Bubble sort by comparing elements at longer range (not only adjacent). This way the algorithm is able to fix more out-of-place elements with fewer swaps. Here you can find a nice visualization of the steps of the algorithm.

Quick sort

The name speaks for itself. Quick sort is one of the fastest ways for sorting a sequence of arbitrary elements known to mankind. Here you can find a nice visualization of the steps of the algorithm.

Counting sort

Counting sort is a genious algorithm that exploits the fact that arrays allow us to make n-way decisions (not just binary like if/else) to improve the performance for certain sequences. Here you can find a nice visualization of the steps it executes.