MCPcopy
hub / github.com/TheAlgorithms/JavaScript / dfs

Method dfs

Data-Structures/Graph/Graph.js:60–71  ·  view source on GitHub ↗

* Prints the Depth first traversal of the graph from source. * @param {number} source The source vertex to start DFS.

(source, visited = new Set(), output = (value) => console.log(value))

Source from the content-addressed store, hash-verified

58 * @param {number} source The source vertex to start DFS.
59 */
60 dfs(source, visited = new Set(), output = (value) => console.log(value)) {
61 if (visited.has(source)) {
62 // visited
63 return
64 }
65
66 output(`Visited node ${source}`)
67 visited.add(source)
68 for (const neighbour of this.adjacencyMap[source]) {
69 this.dfs(neighbour, visited, output)
70 }
71 }
72}
73
74const example = () => {

Callers 1

exampleFunction · 0.95

Calls 4

outputFunction · 0.85
logMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected