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

DFS-深度优先遍历 #1

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

DFS-深度优先遍历 #1

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

Comments

@yihan12
Copy link
Owner

yihan12 commented Jan 18, 2024

深度优先遍历是一种图的遍历算法,它从图的起始顶点开始,沿着一条路径一直访问到最深的顶点,然后再回溯到上一个顶点,继续沿着另一条路径访问,直到遍历完所有顶点。

深度优先遍历通常使用递归或者栈来实现,具体步骤如下:

  • 从起始顶点开始,访问该顶点,并标记为已访问;
  • 递归访问该顶点的未访问邻接顶点,直到所有邻接顶点都被访问过;
  • 如果当前顶点的所有邻接顶点都被访问过,回溯到上一个顶点,继续递归访问其未访问邻接顶点;
  • 重复步骤2和步骤3,直到所有顶点都被访问过。

深度优先遍历的特点是能够沿着一条路径一直向下访问,直到最深的顶点,然后再回溯到上一个顶点,继续向下访问。它适合应用于寻找连通分量、拓扑排序等问题。

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

No branches or pull requests

1 participant