Red bars indicate the values currently being compared.
To reset the array or generate a new one, simply click "Generate New Array."
If the visualizer is too fast or slow, you can also change the animation speed.
To re-open this welcome screen, click "Intro."
Know Your Algorithms
Selection Sort: A comparison-based algorithm that finds the smallest element of the unsorted portion of the array and places it at the end of the sorted portion. A fairly slow algorithm that runs in Θ(N2) time, where N represents the size of the array. This sort is not stable.
Bubble Sort: A comparison-based algorithm that continuously cycles through the array and swaps unsorted and adjacent pairs until the array is sorted. A fairly slow algorithm that runs in Θ(N2) time in the worst and average case and Θ(N) time in the best case, where N represents the size of the array. This sort is stable.
Heap Sort: A comparison-based algorithm that uses a max-heap to sort a given array. Runs in O(N*log(N)) time, where N represents the size of the array, but can achieve a runtime of Θ(N) if given an array of duplicates. This sort is not stable.
Merge Sort: A comparison-based algorithm that first recursively merge sorts the two halves of the array and then merges those two halves together to form a sorted array. Runs in Θ(N*log(N)) time, where N is the size of the array, but requires Θ(N) memory to maintain an auxiliary array. This sort is stable.
Insertion Sort: A comparison-based algorithm that, for all elements of the array, swaps each element towards the front of the array until all elements before the given element are smaller than that given element. Runs in Ω(N) and O(N2) time, where N is the size of the array. Insertion sort is unique in that its runtime is proportional to the number of "inversions" in the array. Given K inversions, the runtime of insertion sort is Θ(N+K). This sort is stable.
Quick Sort: A comparison-based algorithm that first partitions the given array into two sub-arrays based on a "pivot" and then recursively sorts the two sub-arrays. The partitioning algorithm used for this implementation of Quick Sort is Tony Hoare's partitioning scheme. Despite having a runtime of Ω(N*log(N)) and O(N2), where N is the size of the array, it is empirically the fastest comparison-based sort on average. Due to the way this implementation of Quick Sort partitions an array, this sort is not stable. However, there are stable variations of Quick Sort.
LSD Radix Sort: A radix sort that sorts the array in order of magnitude from the least significant digit. Its runtime is Θ(WN+WR), where N is the array size, R is the size of the alphabet (in this case 10), and W is the number of digits in the longest element of the array. This sort is stable.
MSD Radix Sort: Similar to LSD radix sort, MSD radix sort sorts the array in order of magnitude from the most significant digit. Its runtime is better than that of LSD radix sort in certain cases. MSD radix sort has runtime Θ(N+R) in the best case and Θ(WN+WR) in the worst case, where N is the array size, R is the size of the alphabet (in this case 10), and W is the number of digits in the longest element of the array. This sort is stable.