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
function fib(num){ | |
if (num <= 2) return 1; | |
return fib(num - 1) + fib(num - 2); | |
} | |
fib(4); |
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 { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class Queue { | |
constructor() { | |
this.size = 0; |
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 { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class Stack { | |
constructor() { | |
this.first = null; |
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 { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class singlyLinkedList { | |
constructor() { | |
this.length = 0; |
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 { | |
constructor(value) { | |
this.previous = null; | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class DoublyLinkedList { | |
constructor() { |
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
function radixSort(nums) { | |
const maxDigitCount = mostDigits(nums); | |
for (let k = 0; k < maxDigitCount; k++) { | |
const digitsBucket = Array.from({ length: 10 }, () => []); | |
for (let i = 0; i < nums.length; i++) { | |
const currentNum = nums[i]; | |
const digit = getDigit(currentNum, k); |
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
/** | |
* PSEUDOCODE | |
* - initialize the left argument to 0 | |
* - initialize the right argument to array.length | |
* - use the pivot helper fn to get the pivot index pivot(array, right, left) | |
* - recursively call the quickSort fn on both the left and right side of the pivot index | |
* - ONLY if the left is < right index | |
* - hence base case should be if (left < right) { keep calling quickSort recursively } | |
* - when done return array | |
*/ |
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
/** | |
* PSEUDOCODE | |
* - Break up the array into halves until you have an empty array or array with one element | |
* - Once you have the smaller sorted arrays, merge those arrays with other sorted arrays until | |
* - you are back at the full length of the array | |
* - Once the array has been merged back together return the merged and sorted array | |
*/ | |
function mergeSort(array) { | |
if (array.length <= 1) return array; | |
const middlePoint = Math.floor(array.length / 2); |
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
/** | |
* PSEUDOCODE | |
* - start a loop that goes from the end to the start of the array; | |
* - start a second nested loop that goes from the start to the item below the | |
* - current position of the first loop; | |
* - compare each item with next item in the array | |
* - if current item is greater than the next item following it | |
* - then swap current item with next item | |
* - check if any swap happend at every complete iteration of the second loop |
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
/** | |
* PSEUDOCODE | |
* - start a for loop | |
* - store the index of the first item in the array as the current minimum | |
* - start a second nested for loop which starts iterating from the next item | |
* - compare each item with the item at the stored minimum index | |
* - if any item is lower then reassign it to be the stored minimum | |
* - at the end of the of firt iteration for the second loop | |
* - then swap the item at stored minimum index with the item at the | |
* - current iteration of the outer for loop |
NewerOlder