In graph_search there's a sub optimal algorithm for shortest path
keobox opened this issue · comments
find_shortest_path can be done in linear time using BFS (Breadth First Search).
The original article mentioned in the comments in graph_serach.py is providing the code using BFS.
Also all paths can be implemented with a BFS or DFS (Depth First Search).
Here some examples in Java:
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/DepthFirstPaths.java.html
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/BreadthFirstPaths.java.html
Feel free to open a pull request with improvements. I have my doubts about whether it's better to remove the algorithms examples from this repo, since they are not design pattern related.
I'll implement BFS in graph_search.py. The current DFS solutions are good, and I will not remove them. They'll get renamed to include "dfs" and I'll add some new methods.
What you did looks fine, thanks :)