Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想找到所有以节点 a 开始并以节点 b 结束的路径。
现在我的解决方案是从 a 开始执行 DFS 并选择路径以 b 结尾。
复杂度是O(egde + node),能优化到O(path + node)吗?
谢谢!
DFS 有 O(n),这意味着linear复杂性,它在非排序图中无法改进。
linear