Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFS-广度优先遍历 #2

Open
yihan12 opened this issue Jan 18, 2024 · 0 comments
Open

BFS-广度优先遍历 #2

yihan12 opened this issue Jan 18, 2024 · 0 comments
Labels
BFS 广度优先遍历

Comments

@yihan12
Copy link
Owner

yihan12 commented Jan 18, 2024

广度优先遍历是一种图的遍历算法,它从图的起始顶点开始,先访问起始顶点的所有邻接顶点,然后再依次访问这些邻接顶点的邻接顶点,以此类推,直到遍历完所有顶点。

广度优先遍历通常使用队列来实现,具体步骤如下:

  • 将起始顶点入队;
  • 当队列不为空时,取出队列头部的顶点,并将其所有未访问的邻接顶点入队;
  • 标记当前顶点为已访问;
  • 重复步骤2和步骤3,直到队列为空。

广度优先遍历的特点是能够按层次遍历图的顶点,从而找到起始顶点到其他顶点的最短路径。它适合应用于寻找最短路径、拓扑排序等问题。

@yihan12 yihan12 added the BFS 广度优先遍历 label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFS 广度优先遍历
Projects
None yet
Development

No branches or pull requests

1 participant