BFS的基本算法:
set start vertex to visited
load it into queue
while queue not empty
for each edge incident to vertex
if its not visited
load into queue
mark vertex
所以我认为时间复杂度是:
v1 + (incident edges) + v2 + (incident edges) + .... + vn + (incident edges)
v
顶点1
到哪里n
首先,我所说的正确吗?其次,这是如何的O(N + E)
,以及关于其原因的直觉将非常好。谢谢