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
| /* Graph */ | |
| class Graph{ | |
| constructor(){ | |
| this.adjacencyList = {}; | |
| } | |
| addVertex(vertex){ | |
| if(!this.adjacencyList[vertex]) this.adjacencyList[vertex] = []; | |
| } | |
| addEdge(v1,v2){ |
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 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; | |
| } |
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
| /* 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 = []; |
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
| /* 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 = []; |
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
| /* 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 () { |
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
| /* Queue */ | |
| /** | |
| * insertion - O(1) | |
| * removal - O(1) | |
| * searching - O(n) | |
| * access - O(n) | |
| */ | |
| function Queue() { | |
| let 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
| /* Stack */ | |
| /** | |
| * insertion - O(1) | |
| * removal - O(1) | |
| * searching - O(n) | |
| * access - O(n) | |
| */ | |
| function Stack () { | |
| let 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
| /* 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; |
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
| /* LinkedList */ | |
| // head -> [info, link] -> [info, link] -> [info, null] | |
| /** | |
| * insertion - O(1) | |
| * removal - O(1) - O(n) | |
| * searching - O(n) | |
| * access - O(n) | |
| */ | |
| function LinkedList() { |
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 response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`) | |
| const data = await response.json() | |
| return data.imageUrl | |
| } |
NewerOlder