Skip to content

Instantly share code, notes, and snippets.

View ivanzusko's full-sized avatar

Ivan Zusko ivanzusko

  • Telefonica
  • Berlin, Germany
View GitHub Profile
@ivanzusko
ivanzusko / Graph.js
Last active October 27, 2020 23:24
Graph
/* Graph */
class Graph{
constructor(){
this.adjacencyList = {};
}
addVertex(vertex){
if(!this.adjacencyList[vertex]) this.adjacencyList[vertex] = [];
}
addEdge(v1,v2){
@ivanzusko
ivanzusko / hash.js
Created October 27, 2020 22:58
simple and improved hashes
function simpleHash(key, arrayLen) {
let total = 0;
for (let char of key) {
// map "a" to 1, "b" to 2, "c" to 3, etc.
let value = char.charCodeAt(0) - 96
total = (total + value) % arrayLen;
}
return total;
}
@ivanzusko
ivanzusko / PriorityQueue.js
Created October 27, 2020 22:48
PriorityQueue
/* PriorityQueue */
/**
* best & avarage worst
* insertion - O(log n) O(log n)
* removal - O(log n) O(log n)
* searching - O(n) O(n)
*/
function PriorityQueue () {
let nodes = [];
@ivanzusko
ivanzusko / MaxBinaryHeap.js
Created October 27, 2020 22:47
MaxBinaryHeap
/* MaxBinaryHeap */
/**
* best & avarage worst
* insertion - O(log n) O(log n)
* removal - O(log n) O(log n)
* searching - O(n) O(n)
*/
function MaxBinaryHeap () {
let values = [];
@ivanzusko
ivanzusko / BinarySearchTree.js
Created October 27, 2020 09:25
Binary Search Tree
/* BinarySearchTree */
/**
* best & avarage worst
* insertion - O(log n) O(n)
* removal - O(log n) O(n)
* searching - O(log n) O(n)
* access - O(log n) O(n)
*/
function BinarySearchTree () {
@ivanzusko
ivanzusko / Queue.js
Last active October 25, 2020 14:00
Queue data structure
/* Queue */
/**
* insertion - O(1)
* removal - O(1)
* searching - O(n)
* access - O(n)
*/
function Queue() {
let size = 0;
@ivanzusko
ivanzusko / Stack.js
Created October 25, 2020 13:26
Stack
/* Stack */
/**
* insertion - O(1)
* removal - O(1)
* searching - O(n)
* access - O(n)
*/
function Stack () {
let size = 0;
@ivanzusko
ivanzusko / DoubleLinkedList.js
Last active October 25, 2020 12:20
DoubleLinkedList
/* DoubleLinkedList */
/**
* insertion - O(1)
* removal - O(1)
* searching - O(n) (0(n/2) but still O(n))
* access - O(n)
*/
function DoubleLinkedList() {
let head = null;
@ivanzusko
ivanzusko / LinkedList.js
Last active October 25, 2020 14:00
LinkedList
/* LinkedList */
// head -> [info, link] -> [info, link] -> [info, null]
/**
* insertion - O(1)
* removal - O(1) - O(n)
* searching - O(n)
* access - O(n)
*/
function LinkedList() {
@ivanzusko
ivanzusko / example01.js
Created October 14, 2020 19:45 — forked from mpj/example01.js
Code for the async/await episode of Fun Fun Function.
const response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`)
const data = await response.json()
return data.imageUrl
}