This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Quick Sort: Gets its name from being... Quick...? | |
| * | |
| * Process: | |
| * Pick an element of the array, a value to pivot around. | |
| * Place all less than values before the pivot, and all the | |
| * greater than values after the pivot. These values do not | |
| * need to be sorted, just properly placed before or | |
| * after the pivot value. The pivot value is now sorted. | |
| * Repeat the process recursively on the values less than |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Merge Sort: Gets its name from the process of repeatedly | |
| * splitting the original array and merging it back together. | |
| * | |
| * Process: | |
| * Repeatedly split the original array until all subarrays | |
| * are of just one element. Remerge the subarrays and | |
| * continuously sort the elements. | |
| * | |
| * Performance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Insertion Sort: The name comes from the process of | |
| * maintaining a sorted subarray by which unsorted values | |
| * are inserted within through a process of repeated | |
| * swapping. | |
| * | |
| * Process: | |
| * Maintain a sorted subarray in place that begins with | |
| * only the array's first element. Beginning at the second | |
| * element, repeatedly swap the current element with those |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Selection Sort: The name comes from the process of | |
| * repeatedly selecting the minimum element and swapping it | |
| * with the first unsorted element. Selection sort works | |
| * as well by selecting and sorting maximum values. | |
| * | |
| * Process: Iterate through the array to find the minimum | |
| * value. Swap the minumum value with the first | |
| * element. Repeat this process beginning with the element | |
| * proceeding the previously sorted value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Named 'bubble sort' because the largest value will | |
| * bubble to the array's end after the first pass. | |
| * | |
| * Instructions: | |
| * Beginning at the start of the array and | |
| * progressing to the end, repeatedly swap adjacent | |
| * elements in place if they are in the wrong order. | |
| * To sort the entire array, perform subsequent passes | |
| * going only as far as the previously sorted element. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * These two functions do the same thing. | |
| * They check if a second array contains squared values of the first array. | |
| * The first is slow. Every value is compared to each other. | |
| * The second is faster, it runs through each array only once. | |
| * The approach of the second function I refer to as a "frequency counter". | |
| */ | |
| function nestedLoop (array1, array2) { | |
| if (array1.length !== array2.length) { |
NewerOlder