This program sorts numbers using the following algorithms:
Only the sorted array (comparisons) will be shown for input sizes above 16 elements. Total number of steps are always indicated at the end of the output.
Press Clear after each iteration of Quick and Merge Sort to reset their respective counters.
The aim of this lab was to test the number of comparisons made by different algorithms based on the number of input values that were passed to each algorithm. The input values were 50, 100, 150, 200, 250, 300, 350, 400, 450, 500. By observation, Bubble Sort, Insertion Sort and Quick Sort had a noticeable delay in displaying output however Merge Sort remained the most consistent throughout the testing process. Insertion, Merge Sort and Bubble Sort were the stable sorting techniques whereas Quick Sort was not. Merge Sort was the only algorithm that split the problems into multiple arrays hence it had a better advantage over the other algorithms in terms of working with the console.log output of JavaScript.
The graph above confirms that the average time complexities of each of the algorithms. Bubble Sort and Insertion Sort where both O(n^2) and Merge Sort and Quick Sort were both O(nlogn). The behavior of the graph showed that Quick Sort was the fastest for all the input values provided.
The individual sorting algorithms work in their own unique ways. The list below shows how each sorting technique works including some key differences in their operations