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
Run Code Online (Sandbox Code Playgroud)
所以我认为时间的复杂性将是:
v1 + (incident edges) + v2 + (incident edges) + .... + vn + (incident edges)
Run Code Online (Sandbox Code Playgroud)
v
顶点1
到哪里n
首先,我说的是正确的吗?其次,这是怎样的O(N + E)
,直觉为什么会非常好.谢谢