Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b7c47e

Browse files
committed
Corrected dfs function call, needs dfs_2
1 parent 10815b3 commit 5b7c47e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎dfs_bfs.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Given a graph, there are two methods to
1+
# Given a graph, there are two methods to
22
# perform traversal on it.
33
# 1. Depth First Search (DFS)
44
# 2. Breadth First Search (BFS)
@@ -17,9 +17,9 @@ def dfs_2(graph, start, visited=None):
1717
visited = set()
1818
visited.add(start)
1919
for next in graph[start] - visited:
20-
dfs(graph, next, visited)
20+
dfs_2(graph, next, visited)
2121
return visited
22-
22+
2323
def bfs(graph, start):
2424
visited, queue = set(), [start]
2525
while queue:
@@ -30,7 +30,7 @@ def bfs(graph, start):
3030
return visited
3131

3232
# bfs(graph, 'A') # {'B', 'C', 'A', 'F', 'D', 'E'}
33-
33+
3434
def dfs_paths(graph, start, goal):
3535
stack = [(start, [start])]
3636
while stack:
@@ -47,6 +47,6 @@ def dfs_paths(graph, start, goal):
4747
'D': set(['B']),
4848
'E': set(['B', 'F']),
4949
'F': set(['C', 'E'])}
50-
50+
5151
result = list(dfs_paths(graph, 'A', 'F')) # [['A', 'C', 'F'], ['A', 'B', 'E', 'F']]
5252
print(result)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /