GeezerVison is showing github.com — minor · absnaik810/AlgorithmVisualizer@ee9e4d9
File treeExpand file treeCollapse file tree Open diff view settings longest_increasing_subsequence
bellman_ford/shortest_path floyd_warshall/shortest_paths topological_sort/kahn_algorithm
string/edit_distance/dynamic_programming
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | for (var i = 2; i < index; i++) { | 2 | 2 | D[i] = D[i - 2] + D[i - 1]; | 3 | | - tracer._select(i - 2, i - 1)._next(); | 4 | | - tracer._notify(i, D[i])._next(); | | 3 | + tracer._select(i - 2, i - 1)._wait(); | | 4 | + tracer._notify(i, D[i])._wait(); | 5 | 5 | tracer._denotify(i); | 6 | 6 | tracer._deselect(i - 2, i - 1); | 7 | 7 | } |
Collapse file Copy file name to clipboardExpand all lines: algorithm/etc/dp/longest_increasing_subsequence/code.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ for (var i = 1; i < 10; i++) { | 9 | 9 | tracer._select(i); | 10 | 10 | logger._print(' LIS[' + i + '] = ' + LIS[i]); | 11 | 11 | for (var j = 0; j < i; j++) { | 12 | | - tracer._notify(j)._next(); | | 12 | + tracer._notify(j)._wait(); | 13 | 13 | tracer._denotify(j); | 14 | 14 | if (A[i] > A[j] && LIS[i] < LIS[j] + 1) { | 15 | 15 | LIS[i] = LIS[j] + 1; | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/etc/dp/max_sum_path/code.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,8 +2,8 @@ var N = DP.length; | 2 | 2 | var M = DP[0].length; | 3 | 3 | function update(i, j, value) { | 4 | 4 | DP[i][j] = value; | 5 | | - dataViewer._select(i, j)._next(); | 6 | | - tracer._notify(i, j, DP[i][j])._next(); | | 5 | + dataViewer._select(i, j)._wait(); | | 6 | + tracer._notify(i, j, DP[i][j])._wait(); | 7 | 7 | tracer._denotify(i, j); | 8 | 8 | dataViewer._deselect(i, j); | 9 | 9 | } | |
Collapse file Copy file name to clipboard +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | var sum = D[0] + D[1] + D[2]; | 2 | 2 | var max = sum; | 3 | 3 | tracer._select(0, 2); | 4 | | -logger._print('sum = ' + sum)._next(); | | 4 | +logger._print('sum = ' + sum)._wait(); | 5 | 5 | for (var i = 3; i < D.length; i++) { | 6 | 6 | sum += D[i] - D[i - 3]; | 7 | 7 | if (max < sum) max = sum; | 8 | 8 | tracer._deselect(i - 3); | 9 | 9 | tracer._select(i); | 10 | | - logger._print('sum = ' + sum)._next(); | | 10 | + logger._print('sum = ' + sum)._wait(); | 11 | 11 | } | 12 | | -tracer._next()._deselect(D.length - 3, D.length - 1); | | 12 | +tracer._deselect(D.length - 3, D.length - 1); | 13 | 13 | logger._print('max = ' + max); |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/bellman_ford/shortest_path/code.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,14 +20,14 @@ function BELLMAN_FORD(src, dest) { | 20 | 20 | for (var currentNode = 0; currentNode < G.length; currentNode++) { | 21 | 21 | for (var currentNodeNeighbor = 0; currentNodeNeighbor <= G.length; currentNodeNeighbor++) { | 22 | 22 | if (G [currentNode] [currentNodeNeighbor]) { //proceed to relax Edges only if a particular weight != 0 (0 represents no edge) | 23 | | - logger._next()._print('Exploring edge from ' + currentNode + ' to ' + currentNodeNeighbor + ', weight = ' + G [currentNode] [currentNodeNeighbor]); | | 23 | + logger._print('Exploring edge from ' + currentNode + ' to ' + currentNodeNeighbor + ', weight = ' + G [currentNode] [currentNodeNeighbor]); | 24 | 24 |
| 25 | 25 | if (weights [currentNodeNeighbor] > (weights [currentNode] + G [currentNode] [currentNodeNeighbor])) { | 26 | 26 | weights [currentNodeNeighbor] = weights [currentNode] + G [currentNode] [currentNodeNeighbor]; | 27 | 27 | logger._print('weights [' + currentNodeNeighbor + '] = weights [' + currentNode + '] + ' + G [currentNode] [currentNodeNeighbor]); | 28 | 28 | } | 29 | | - tracer._visit(currentNodeNeighbor, currentNode, weights [currentNodeNeighbor]); | 30 | | - tracer._next()._leave(currentNodeNeighbor, currentNode); | | 29 | + tracer._visit(currentNodeNeighbor, currentNode, weights [currentNodeNeighbor])._wait(); | | 30 | + tracer._leave(currentNodeNeighbor, currentNode)._wait(); | 31 | 31 | } | 32 | 32 | } | 33 | 33 | } | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/bfs/shortest_path/code.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,15 +8,15 @@ function BFS() { | 8 | 8 | } | 9 | 9 | W[s] = 0; | 10 | 10 | Q.push(s); // add start node to queue | 11 | | - tracer._visit(s, undefined, 0); | | 11 | + tracer._visit(s, undefined, 0)._wait(); | 12 | 12 | while (Q.length > 0) { | 13 | 13 | var node = Q.shift(); // dequeue | 14 | 14 | for (i = 0; i < G[node].length; i++) { | 15 | 15 | if (G[node][i]) { // if the edge from current node to the i-th node exists | 16 | 16 | if (W[i] > W[node] + G[node][i]) { // if current path is shorter than the previously shortest path | 17 | 17 | W[i] = W[node] + G[node][i]; // update the length of the shortest path | 18 | 18 | Q.push(i); // add child node to queue | 19 | | - tracer._next()._visit(i, node, W[i]); | | 19 | + tracer._visit(i, node, W[i])._wait(); | 20 | 20 | } | 21 | 21 | } | 22 | 22 | } | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/bfs/tree/code.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | function BFS(s) { // s = start node | 2 | 2 | var Q = []; | 3 | 3 | Q.push(s); // add start node to queue | 4 | | - tracer._visit(s); | | 4 | + tracer._visit(s)._wait(); | 5 | 5 | while (Q.length > 0) { | 6 | 6 | var node = Q.shift(); // dequeue | 7 | 7 | for (var i = 0; i < G[node].length; i++) { | 8 | 8 | if (G[node][i]) { // if current node has the i-th node as a child | 9 | 9 | Q.push(i); // add child node to queue | 10 | | - tracer._next()._visit(i, node); | | 10 | + tracer._visit(i, node)._wait(); | 11 | 11 | } | 12 | 12 | } | 13 | 13 | } | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/dfs/all_paths/code.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | function DFS(node, parent) { // node = current node, parent = previous node | 2 | | - tracer._next()._visit(node, parent); | | 2 | + tracer._visit(node, parent)._wait(); | 3 | 3 | D[node] = true; // label current node as discovered | 4 | 4 | for (var i = 0; i < G[node].length; i++) { | 5 | 5 | if (G[node][i]) { // if the edge from current node to the i-th node exists | @@ -9,7 +9,7 @@ function DFS(node, parent) { // node = current node, parent = previous node | 9 | 9 | } | 10 | 10 | } | 11 | 11 | D[node] = false; // label current node as undiscovered | 12 | | - tracer._next()._leave(node, parent); | | 12 | + tracer._leave(node, parent)._wait(); | 13 | 13 | } | 14 | 14 | var D; // D[i] indicates whether the i-th node is discovered or not | 15 | 15 | for (var i = 0; i < G.length; i++) { // start from every node | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/dfs/shortest_path/code.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | function DFS(node, parent, weight) { // node = current node, parent = previous node | 2 | 2 | if (minWeight < weight) return; | 3 | 3 | if (node == e) { | 4 | | - tracer._next()._visit(node, parent, weight); | 5 | | - tracer._next()._leave(node, parent, 0); | | 4 | + tracer._visit(node, parent, weight)._wait(); | | 5 | + tracer._leave(node, parent, 0)._wait(); | 6 | 6 | if (minWeight > weight) { | 7 | 7 | minWeight = weight; | 8 | 8 | } | 9 | 9 | return; | 10 | 10 | } | 11 | 11 | D[node] = true; // label current node as discovered | 12 | | - tracer._next()._visit(node, parent, weight); | | 12 | + tracer._visit(node, parent, weight)._wait(); | 13 | 13 | for (var i = 0; i < G[node].length; i++) { | 14 | 14 | if (G[node][i]) { // if the path from current node to the i-th node exists | 15 | 15 | if (!D[i]) { // if the i-th node is not labeled as discovered | @@ -18,7 +18,7 @@ function DFS(node, parent, weight) { // node = current node, parent = previous n | 18 | 18 | } | 19 | 19 | } | 20 | 20 | D[node] = false; // label current node as undiscovered | 21 | | - tracer._next()._leave(node, parent, 0); | | 21 | + tracer._leave(node, parent, 0)._wait(); | 22 | 22 | } | 23 | 23 | var s = Math.random() * G.length | 0; // s = start node | 24 | 24 | var e; // e = end node | |
Collapse file Copy file name to clipboardExpand all lines: algorithm/graph_search/dfs/tree/code.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | function DFS(node, parent) { // node = current node, parent = previous node | 2 | | - tracer._next()._visit(node, parent); | | 2 | + tracer._visit(node, parent)._wait(); | 3 | 3 | for (var i = 0; i < G[node].length; i++) { | 4 | 4 | if (G[node][i]) { // if current node has the i-th node as a child | 5 | 5 | DFS(i, node); // recursively call DFS | |
|