Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure BFS/tree.js #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions Brute Force/Breadth-First Search/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ const G = [ // G[i][j] indicates whether the path from the i-th node to the j-th
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];

// define tracer variables {
const tracer = new GraphTracer();
const logger = new LogTracer();
tracer.log(logger);
Layout.setRoot(new VerticalLayout([tracer, logger]));
tracer.set(G);
tracer.layoutTree(0);
Tracer.delay();
// }
/**
* Traverse a tree in breadth-first order.
*
* @param G The tree to be traversed, represented by an adjacency matrix.
* @param s The starting node.
*/
function BFS(G, s) {

// define tracer variables {
const tracer = new GraphTracer();
const logger = new LogTracer();
tracer.log(logger);
Layout.setRoot(new VerticalLayout([tracer, logger]));
tracer.set(G);
tracer.layoutTree(0);
Tracer.delay();
// }

function BFS(s) { // s = start node
const Q = [];
Q.push(s); // add start node to queue
// visualize {
Expand All @@ -47,4 +54,4 @@ function BFS(s) { // s = start node
}
}

BFS(0);
BFS(G, 0);