This file contains 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
// InsertionSort to be used within bucket sort | |
function insertionSort(array) { | |
var length = array.length; | |
for(var i = 1; i < length; i++) { | |
var temp = array[i]; | |
for(var j = i - 1; j >= 0 && array[j] > temp; j--) { | |
array[j+1] = array[j]; | |
} | |
array[j+1] = temp; |
This file contains 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
var HashTable = function() { | |
this._storage = []; | |
this._count = 0; | |
this._limit = 8; | |
} | |
HashTable.prototype.insert = function(key, value) { | |
//create an index for our storage location by passing it through our hashing function | |
var index = this.hashFunc(key, this._limit); |
This file contains 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
class HashTable { | |
constructor() { | |
this.table = new Array(137); | |
this.values = []; | |
} | |
// Defining the hashing function which allows a sting to be used as a key | |
hash(string) { | |
const H = 37; | |
let total = 0; |
This file contains 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
// Implement a min heap: | |
// -> insert, extract_min | |
// property: | |
// - elements are in ascending order | |
// - complete binary tree (node is smaller than it’s children) | |
// - root is the most minimum | |
// - insert takes O(logn) time | |
// - insert to the bottom right |
This file contains 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
// Trie.js - super simple JS implementation | |
// https://en.wikipedia.org/wiki/Trie | |
// ----------------------------------------- | |
// we start with the TrieNode | |
function TrieNode(key) { | |
// the "key" value will be the character in sequence | |
this.key = key; | |