Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added base case and return the path as soon as end node is visited #352

Merged
merged 1 commit into from Sep 26, 2020

Conversation

@techntools
Copy link

@techntools techntools commented Sep 26, 2020

Added a base case for BFS like DFS.

No need to use break in loop. Create the path and return it.

Changed the docstests to remove some ambiguity in variable names ( graph vs graph1) and added some more to cover the edge cases.

node = edge_to[node]
path.insert(0, start)
return path
if end in edge_to.keys():

This comment has been minimized.

@techntools

techntools Sep 26, 2020
Author

Using keys() instead values() as do not have to visit the children of end node.

['G', 'E', 'F']
# unreachable node
>>> print(graph_search.find_path_dfs('C', 'H'))

This comment has been minimized.

@techntools

techntools Sep 26, 2020
Author

Node is not reachable

None
# non existing node
>>> print(graph_search.find_path_dfs('C', 'X'))

This comment has been minimized.

@techntools

techntools Sep 26, 2020
Author

End node does not exist in graph

@faif faif merged commit f6adf63 into faif:master Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.