正在加载图片...
Breadth-first search(BFS) Intuition:find the neighbors of the neighbors Additional structure:a queue Q ·Pseudocode: o Initialize: ·dist[s】=O;dist[u=∞for all other vertices u o Q=[s] o While Q is not empty Dequeue the top element u of Q 。For all neighbors v of u,if dist[v]=∞, o Put v in Q o Set dist[v]=dist[u]+1 ● ●Breadth-first search (BFS) • Intuition: find the neighbors of the neighbors • Additional structure: a queue Q • Pseudocode: o Initialize: • dist[s] = 0; dist[u] = ∞ for all other vertices u o Q = [s] o While Q is not empty • Dequeue the top element u of Q • For all neighbors v of u, if dist[v] = ∞, o Put v in Q o Set dist[v] = dist[u] + 1
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有