Skip to content

Instantly share code, notes, and snippets.

View dyllandry's full-sized avatar
🍞

Dylan Landry dyllandry

🍞
  • Tactus Therapy
  • Toronto, ON, Canada
View GitHub Profile
@dyllandry
dyllandry / quick-sort.js
Created June 21, 2019 15:29
Description and implementation of a quick sort algorithm.
/**
* 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
@dyllandry
dyllandry / merge-sort.js
Created June 20, 2019 18:35
Description and implementation of a merge sort algorithm.
/**
* 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:
@dyllandry
dyllandry / insertion-sort.js
Created June 20, 2019 16:16
Description and implementation of a insertion sort algorithm.
/**
* 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
@dyllandry
dyllandry / selection-sort.js
Created June 20, 2019 15:13
Description and implementation of a selection sort algorithm.
/**
* 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.
@dyllandry
dyllandry / bubble-sort.js
Last active June 20, 2019 15:02
Description and implementation of a bubble sort algorithm.
/**
* 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.
@dyllandry
dyllandry / frequencyCounters.js
Created June 10, 2019 15:54
Frequency Counters
/**
* 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) {