MCPcopy Index your code
hub / github.com/loiane/javascript-datastructures-algorithms / enhancedDepthFirstSearch

Function enhancedDepthFirstSearch

src/13-graph/dfs.js:44–66  ·  view source on GitHub ↗
(graph, callback)

Source from the content-addressed store, hash-verified

42}
43
44const enhancedDepthFirstSearch = (graph, callback) => {
45 const vertices = graph.vertices;
46 const adjList = graph.adjList;
47 const color = initializeColor(vertices);
48 const discovery = {}; // Discovery times
49 const finished = {}; // Finish times
50 const predecessors = {};
51 const time = { count: 0 };
52
53 for (let i = 0; i < vertices.length; i++) {
54 finished[vertices[i]] = 0;
55 discovery[vertices[i]] = 0;
56 predecessors[vertices[i]] = null;
57 }
58
59 for (let i = 0; i < vertices.length; i++) {
60 if (color[vertices[i]] === Colors.WHITE) {
61 enhancedDFSVisit(vertices[i], color, discovery, finished, predecessors, time, adjList);
62 }
63 }
64
65 return { discovery, finished, predecessors};
66}
67
68const enhancedDFSVisit = (vertex, color, discovery, finished, predecessors, time, adjList) => {
69 color[vertex] = Colors.GREY;

Callers 3

03-using-dfs.tsFile · 0.90
graph.test.tsFile · 0.90
03-using-dfs.jsFile · 0.70

Calls 2

initializeColorFunction · 0.70
enhancedDFSVisitFunction · 0.70

Tested by

no test coverage detected