这是一个通用的 BFS 实现:
V对于具有节点和总边数的 连通图E,我们知道每条边在内循环中都会被考虑两次。那么,如果 BFS内循环的迭代总数为2 * number of edges E,那么运行时间不是会是O(E)吗?
V
E
2 * number of edges E
O(E)
algorithm big-o breadth-first-search time-complexity depth-first-search
algorithm ×1
big-o ×1
breadth-first-search ×1
depth-first-search ×1
time-complexity ×1