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 Graph { | |
constructor(isDirected = false, isWeighted = false) { | |
this.vertices = []; | |
this.isDirected = isDirected; | |
this.isWeighted = isWeighted; | |
} | |
addVertex(data) { | |
const newVertex = new Vertex(data); | |
this.vertices.push(newVertex); |
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 Graph { | |
constructor(isDirected = false, isWeighted = false) { | |
this.vertices = []; | |
this.isDirected = isDirected; | |
this.isWeighted = isWeighted; | |
} | |
addVertex(data) { | |
const newVertex = new Vertex(data); | |
this.vertices.push(newVertex); |
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 Graph { | |
constructor(isDirected = false, isWeighted = false) { | |
this.vertices = []; | |
this.isDirected = isDirected; | |
this.isWeighted = isWeighted; | |
} | |
addVertex(data) { | |
const newVertex = new Vertex(data); | |
this.vertices.push(newVertex); |
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 BinaryTree { | |
constructor(value, depth = 1) { | |
this.value = value; | |
this.depth = depth; | |
this.left = null; | |
this.right = null; | |
} | |
insert(value) { | |
if (value < this.value) { |
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
const binarySearch = (arr, target) => { | |
let left = 0; | |
let right = arr.length; | |
while (right > left) { | |
const indexToCheck = Math.floor((left + right) / 2); | |
const checking = arr[indexToCheck]; | |
console.log(indexToCheck); | |
if (checking === target) { |
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
const swap = require('./swap'); | |
const quicksort = (array, leftBound = 0, rightBound = array.length - 1) => { | |
if (leftBound < rightBound) { | |
console.log('. Calling partition', array, `with leftBound ${leftBound} and rightBound ${rightBound}`); | |
const pivotIndex = partition(array, leftBound, rightBound); | |
console.log(`. Returning pivotIndex = ${pivotIndex}`); | |
console.log(`\nCalling quicksort for left partition with leftBound ${leftBound} and (pivotIndex-1) ${pivotIndex - 1}`); | |
quicksort(array, leftBound, pivotIndex - 1); | |
console.log(`\nCalling quicksort for right partition with pivotIndex ${pivotIndex} and rightBound ${rightBound}`); |
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
const mergeSort = (startArray) => { | |
const length = startArray.length; | |
if (length === 1) { | |
return startArray; | |
} | |
const mid = Math.floor(length / 2); | |
const leftArray = startArray.slice(0, mid); | |
const rightArray = startArray.slice(mid, length); |
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
const swap = require("./swap"); | |
const bubbleSort = (input) => { | |
let swapCount = 0; | |
let swapping = true; | |
while (swapping) { | |
swapping = false; | |
for (let i = 0; i < input.length - 1; i++) { | |
if (input[i] > input[i + 1]) { |
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
const Node = require("./Node"); | |
class LinkedList { | |
constructor() { | |
this.head = null; | |
} | |
addToHead(data) { | |
const nextNode = new Node(data); | |
const currentHead = this.head; |
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 Edge { | |
constructor(start, end, weight = null) { | |
this.start = start; | |
this.end = end; | |
this.weight = weight; | |
} | |
} | |
module.exports = Edge; |
NewerOlder