Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded base case and return the path as soon as end node is visited #352
Conversation
| node = edge_to[node] | ||
| path.insert(0, start) | ||
| return path | ||
| if end in edge_to.keys(): |
techntools
Sep 26, 2020
Author
Using keys() instead values() as do not have to visit the children of end node.
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')) |
techntools
Sep 26, 2020
Author
Node is not reachable
Node is not reachable
| None | ||
| # non existing node | ||
| >>> print(graph_search.find_path_dfs('C', 'X')) |
techntools
Sep 26, 2020
Author
End node does not exist in graph
End node does not exist in graph
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
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.