资源 · 指南或文章
Topological Sorting
定义有向图的拓扑排序及其存在条件:当且仅当图中没有有向环。适合作为课程安排和构建顺序类题目的入门。
审核日期
打开原站: Topological Sorting (在新标签页中打开原网站)练习这个主题打开练习面试官,并带上一道关于 图 的题目。
添加到路线图
把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。
来源内容语言:英语
In the field of computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.
PrepKit 概览
本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。
- 适合人群
- 来源未说明适用级别
- 形式
- 参考资料
涵盖内容
- 无环条件,以及“存在线性时间构造算法”的说法
- 同一个 DAG 的六种合法排序,每种都标明了产生它的规则
- 作业调度和软件包依赖解析等应用
使用建议
这是 PrepKit 的学习建议,并非来源的说法。
在示例图上分别实现 Kahn 算法和 DFS 后序方法,检查每个输出都合法。让两种方法都能报告环。
范围与局限
没有点名任何具体算法,除了说存在线性时间方法外,没有伪代码或复杂度。没有涉及如何报告环。
获取方式与形式
GitHub 上采用 MIT 许可的 trekhleb/javascript-algorithms 仓库中的免费英文 README。
PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88
本概览的依据
- src/algorithms/graph/topological-sorting/README.md
收录此条目的页面
订阅 PrepKit 通讯
可选。使用 PrepKit 并不需要订阅。