MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / DFS

Method DFS

Data-Structures/Graph/Graph3.js:34–54  ·  view source on GitHub ↗

* Return DFS (Depth First Search) List Using Recursive Method

(start)

Source from the content-addressed store, hash-verified

32 * Return DFS (Depth First Search) List Using Recursive Method
33 */
34 DFS(start) {
35 if (!start) return null
36
37 const result = []
38 const visited = {}
39 const adjacencyObject = this.adjacencyObject
40
41 function dfs(vertex) {
42 if (!vertex) return null
43 visited[vertex] = true
44 result.push(vertex)
45 adjacencyObject[vertex].forEach((neighbor) => {
46 if (!visited[neighbor]) {
47 dfs(neighbor)
48 }
49 })
50 }
51
52 dfs(start)
53 return result
54 }
55
56 /**
57 * Return DFS(Depth First Search) List Using Iteration

Callers 1

Graph3.test.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected