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
class Node { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.left = null | |
this.right = null | |
} | |
} | |
class Tree { |
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
class Node { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.left = null | |
this.right = null | |
} | |
} | |
class Tree { |
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
class MaxHeap { | |
// creates an array of given length | |
constructor(length) { | |
this.data = new Array(length) | |
this.size = 0 | |
} | |
// helpers | |
rehash = () => { |
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
class MinHeap { | |
// creates an array of given length | |
constructor(length) { | |
this.data = new Array(length) | |
this.size = 0 | |
} | |
// helpers | |
rehash = () => { |
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
class Node { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.left = null | |
this.right = null | |
} | |
} | |
class Tree { |
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
class Item { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.next = null | |
} | |
} | |
class Queue { | |
// initial size is 0 and initially just has two reference items that store nothing and point to nothing |
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
class Item { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.next = null | |
} | |
} | |
class Stack { | |
// initial size is 0 and initially just has a head node that stores nothing and points to nothing |
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
class Node { | |
// stores given value and points to nothing | |
constructor (value) { | |
this.value = value | |
this.next = null | |
} | |
} | |
class LinkedList { | |
// initial size is 0 and initially just has a head node that stores nothing and points to nothing |
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
const hashFunction = (key, tableSize) => { | |
// index we are going to return | |
let index = 0 | |
// get list of characters in key string as an array | |
let numChars = String(key) | |
// assign numChars size to index to start | |
index = numChars.length | |
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
// assumption - each input would have exactly one solution, and the same element may not be used twice in the input array | |
// brute force solution | |
function twoSumNaive(array, sum) { | |
let indices = [] | |
for (let i = 0; i < array.length; i++) { | |
for (let j = i + 1; j < array.length; j++) { | |
if (array[i] + array[j] === sum) { | |
indices.push(i) |
NewerOlder