Skip to content

Instantly share code, notes, and snippets.

@GAierken
Last active July 20, 2020 11:27
Show Gist options
  • Save GAierken/cf38cc5809353227e3dabd7a52e8e8e0 to your computer and use it in GitHub Desktop.
Save GAierken/cf38cc5809353227e3dabd7a52e8e8e0 to your computer and use it in GitHub Desktop.
// visiting/updating/checking each vertex in a graph recursive
depthFirstRecursive(start){
const result = []
const visited = {}
const adjacencyList = this.adjacencyList
(function dfs(vertex){
if(!vertex) return null
visited[vertex] = true
result.push(vertex)
adjacencyList[verte].forEach((neighbor) => {
if(!visited[neighbor]){
return dfs(neighbor)
}
})
})(start)
return result
}
dfsIterative(start){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment