Skip to content

Commit be2f769

Browse files
committed
Let algorithm directories contain variations
1 parent 7cbece1 commit be2f769

29 files changed

Lines changed: 22 additions & 216 deletions

File tree

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Branch and Bound/Depth-Limited Search (Counting Descendant)/code.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

Branch and Bound/Depth-Limited Search/code.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ const G = [ // G[i][j] indicates whether the path from the i-th node to the j-th
1818
];
1919
tracer.set(G).layoutTree(0).delay();
2020

21-
// This is a sample DLS where
21+
// This is a sample DLS applications where
2222
// we try to find number of descendant of root within some depth
23-
function DLS(limit, node, parent) { // node = current node, parent = previous node
23+
function DLSCount(limit, node, parent) { // node = current node, parent = previous node
2424
tracer.visit(node, parent).delay();
25+
let child = 0;
2526
if (limit > 0) { // cut off the search
2627
for (let i = 0; i < G[node].length; i++) {
2728
if (G[node][i]) { // if current node has the i-th node as a child
28-
DLS(limit - 1, i, node); // recursively call DLS
29+
child += 1 + DLSCount(limit - 1, i, node); // recursively call DLS
2930
}
3031
}
32+
return child;
3133
}
34+
return child;
3235
}
33-
DLS(2, 0);
36+
logger.print(`Number of descendant is ${DLSCount(2, 0)}`);

Brute Force/All Paths (DFS)/code.js

Lines changed: 0 additions & 30 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)