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
// Node class | |
class Node { | |
constructor(data) { | |
this.data = data; | |
this.left = null; | |
this.right = null; | |
} | |
} | |
// Binary Search tree class |
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
// Binary Search tree class | |
class BinarySearchTree { | |
constructor() { | |
// root of a binary search tree | |
this.root = 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(data) { | |
this.data = data; | |
this.leftChild = null; | |
this.rightChild = 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
if root === null | |
return null | |
if value === root -> data | |
return data | |
if value < root -> data | |
return search(leftTree) | |
if value > root -> data | |
return search(rightTree) |
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
V = {A, B, C, D, E} | |
E = {(AB), (AC), (AD), (BD), (BE), (CD), (DE)} | |
G = {V, E} |
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 HashTable { | |
constructor(size) { | |
this.table = new Array(size); | |
} | |
hashFunction(value) { | |
let hash = 0; | |
for (let i = 0; i < value.length; i++) { | |
hash = (hash + value.charCodeAt(i) * i) % this.table.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
const hashTable = new HashTable(4); | |
hashTable.set('Victor', 24) | |
// [ <1 empty item>, [ [ 'Victor', 24 ] ], <2 empty items> ] |
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 HashTable { | |
constructor(size) { | |
this.table = new Array(size); | |
} | |
hashFunction(value) { | |
let hash = 0; | |
for (let i = 0; i < value.length; i++) { | |
hash = (hash + value.charCodeAt(i) * i) % this.table.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
const hashTable = new HashTable(4); | |
hashTable.hashFunction('Hey') | |
// 3 |
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 HashTable { | |
constructor(size) { | |
this.data = new Array(size); | |
} | |
hashFunction(value) { | |
let hash = 0; | |
for (let i = 0; i < value.length; i++) { | |
hash = (hash + value.charCodeAt(i) * i) % this.data.length; | |
console.log(hash); |