MCPcopy Create free account
hub / github.com/loiane/javascript-datastructures-algorithms / depthFirstSearchVisit

Function depthFirstSearchVisit

src/13-graph/dfs.js:29–42  ·  view source on GitHub ↗
(vertex, color, adjList, callback)

Source from the content-addressed store, hash-verified

27}
28
29const depthFirstSearchVisit = (vertex, color, adjList, callback) => {
30 color[vertex] = Colors.GREY; // Mark as discovered
31 if (callback) {
32 callback(vertex);
33 }
34 const neighbors = adjList.get(vertex);
35 for (let i = 0; i < neighbors.length; i++) {
36 const neighbor = neighbors[i];
37 if (color[neighbor] === Colors.WHITE) { // If unvisited - recursive call
38 depthFirstSearchVisit(neighbor, color, adjList, callback);
39 }
40 }
41 color[vertex] = Colors.BLACK; // Mark as explored
42}
43
44const enhancedDepthFirstSearch = (graph, callback) => {
45 const vertices = graph.vertices;

Callers 1

depthFirstSearchFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected