DFS(Depth-First Search) with python
BFS&DFS are probably one of the most frequent and important types of questions in various interviews and coding tests. I’ve also encountered this type every time through several coding tests so far.
In this post, I would like to post about the DFS (Breadth-First Search) algorithm. I try to make it as simple as possible with Python, so I hope it helps a lot of people!🙏
DFS (Depth-First Search) algorithm
def dfs(graph, v, visited):
visited[v] = True
for i in graph[v]:
if not visited[v]:
dfs(graph, i, visited)
This post is part of Python-Team-Notes for coding test posting that I posted. If you have any questions or mistakes regarding the code, please point it out!
Leave a comment