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
{ | |
0: 2, | |
1: 0, | |
2: 1, | |
3: 3, | |
4: Infinity | |
} |
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
var graph = [ | |
[0, 1, 1, 1, 0], | |
[0, 0, 1, 0, 0], | |
[1, 1, 0, 0, 0], | |
[0, 0, 0, 1, 0], | |
[0, 1, 0, 0, 0] | |
]; | |
console.log(bfs(graph, 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
function bfs(graph, root) { | |
var nodesLen = {}; | |
for (var i = 0; i < graph.length; i++) { | |
nodesLen[i] = Infinity; | |
} | |
nodesLen[root] = 0; | |
var queue = [root]; | |
var current; | |
while (queue.length != 0) { | |
current = queue.shift(); |
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
/** Node in Trie **/ | |
function Node() { | |
this.keys = new Map(); | |
this.end = false; | |
this.setEnd = function () { | |
this.end = true; | |
}; | |
this.isEnd = function () { | |
return this.end; | |
} |
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
1 | |
7 | |
6 | |
false |
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 bst = new BST(); | |
bst.add(4); | |
bst.add(2); | |
bst.add(6); | |
bst.add(1); | |
bst.add(3); | |
bst.add(5); | |
bst.add(7); | |
bst.remove(4); | |
console.log(bst.findMin()); |
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 Node { | |
constructor(data, left = null, right = null) { | |
this.data = data; | |
this.left = left; | |
this.right = right; | |
} | |
} | |
class BST { | |
constructor() { |
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
function hash(string, max) { | |
var hash = 0; | |
for (var i = 0; i < string.length; i++) { | |
hash += string.charCodeAt(i); | |
} | |
return hash % max; | |
} | |
function HashTable() { | |
let storage = []; |
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
function MySet() { | |
var collection = []; | |
this.has = function (element) { | |
return (collection.indexOf(element) !== -1); | |
} | |
this.values = function () { | |
return collection; | |
} | |
this.size = function () { | |
return collection.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
/** Node in the linked list **/ | |
function Node(element) { | |
// Data in the node | |
this.element = element; | |
// Pointer to the next node | |
this.next = null; | |
} | |
function LinkedList() { | |
var length = 0; | |
var head = null; |
NewerOlder