63 103
Assignments Done
99%
Successfully Done
In July 2018

Answer to Question #63534 in AJAX | JavaScript | HTML | PHP for Shin

Question #63534
Make a javascript code that implements depth-first search
Expert's answer
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

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions