Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
// Node class
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Binary Search tree class
// Binary Search tree class
class BinarySearchTree {
constructor() {
// root of a binary search tree
this.root = null;
}
}
class Node {
constructor(data) {
this.data = data;
this.leftChild = null;
this.rightChild = null;
}
}
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)
V = {A, B, C, D, E}
E = {(AB), (AC), (AD), (BD), (BE), (CD), (DE)}
G = {V, E}
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;
}
const hashTable = new HashTable(4);
hashTable.set('Victor', 24)
// [ <1 empty item>, [ [ 'Victor', 24 ] ], <2 empty items> ]
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;
}
const hashTable = new HashTable(4);
hashTable.hashFunction('Hey')
// 3
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);