Answer to Question #63534 in AJAX | JavaScript | HTML | PHP for Shin
Make a javascript code that implements depth-first search
1
2016-11-25T08:16:16-0500
var n = 3;
var g = new Array(n);
var used = new Array(n);
function dfs(v) {
used[v] = true;
for (var i = 0; i < n; i++) {
if (g[v][i] == 1 && used[i] == false) {
dfs(i);
}
}
}
for (var i = 0; i < n; i++) {
used[i] = false;
g[i] = new Array(n);
for (var j = 0;j < n; j++) {
g[i][j] = 0;
}
}
g[1][0] = g[0][1] = 1;
document.write(used)
;
dfs(0)
;
document.write(used);
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment