# 有向图

有向图（directed graph），或称 digraph，是一种边为顶点的有序对的图，因此每条边都可以沿一个指定的方向从一个顶点走到另一个顶点<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup>。形式化地说，有向图是一个二元组 \( G = (V, E) \)，其中 \( V \) 是顶点集合，\( E \) 是满足 \( u, v \in V \) 的有序对 \( (u, v) \) 的集合；若不允许自环，则 \( u \neq v \)<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup>。它与无向图的区别在定义中只差一个词：连接两个顶点的那一对究竟是不是有序的<sup>[2](https://learngraphtheory.org/articles/directed-vs-undirected-graphs.html)</sup>。边 \( \langle u, v \rangle \) 称为离开 \( u \)、进入 \( v \)，画成从 \( u \) 指向 \( v \) 的箭头<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。

| 关键事实 | 详情 |
|---|---|
| 定义 | 边是顶点的有序对 \( (u, v) \)；又称 digraph 或定向图<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup> |
| 度 | 顶点的入度统计进入它的边数，出度统计离开它的边数<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup> |
| 邻接矩阵 | 这个 \( n \times n \) 矩阵在存在一条离开 \( u \)、进入 \( v \) 的边时，第 \( u \) 行第 \( v \) 列的元素为 1；它不必是对称的<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup> |
| 强连通性 | 当且仅当对每一对顶点 \( X \) 和 \( Y \)，都存在从 \( X \) 到 \( Y \) 的路径以及从 \( Y \) 到 \( X \) 的路径时，有向图是强连通的<sup>[4](https://arxiv.org/abs/1802.05387)</sup> |
| DAG | 不含 directed cycle 的有向图；它允许拓扑排序，即一种线性排序，使得对每条边 \( (u, v) \)，\( u \) 都排在 \( v \) 之前<sup>[5](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)</sup> |
| 典型模型 | Twitter、Instagram 等非对称社交网络，含单行道的道路网络，软件依赖图，以及课程先修关系图<sup>[6](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/3-graph/classify_represent.html)</sup> |
| 术语警示 | 不加限定的“图”可能指两种图中的任何一种；图论学者倾向于指无向图，因此语境很重要<sup>[7](https://cse.unl.edu/~cbourke/CSCE235/books/NotesOnDiscreteMathematics-Aspnes.pdf)</sup> |

## 基本概念

由于边有方向，每个顶点都带有两个计数而不是一个。\( v \) 的入度是进入 \( v \) 的边数，出度是离开 \( v \) 的边数<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。一个节点可以有很高的入度，意味着有许多东西指向它，比如一篇被高度引用的论文，同时出度很低，意味着它引用别人很少，或者反过来<sup>[8](https://anvithpothula.github.io/graph-neural-networks-textbook/chapters/01-intro-to-graphs/)</sup>。

有向图中的路径是一串顶点，使得对每两个相邻顶点 \( v_i, v_{i+1} \)，图中都有一条离开 \( v_i \)、进入 \( v_{i+1} \) 的边<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。在有向图中，顶点之间的通行受限于每个箭头所指的方向，而无向图的边则可以双向通行<sup>[9](https://pages.cs.wisc.edu/~skrentny/cs367-common/readings/Graphs/index.html)</sup>。

**与无向图的关系。** 把每条无向边替换为两条方向相反的有向边，就可以把无向图看作有向图的一个特例<sup>[10](https://theory.stanford.edu/~trevisan/cs103-14/keith.pdf)</sup>。同时含有有向边和无向边的图称为混合图<sup>[11](https://csiflabs.cs.ucdavis.edu/~tyfeng/ecs34/C%2B%2B/graphs.html)</sup>。

## 表示

两种标准的计算机表示可以从无向图沿用过来，只需改动一处。含 \( n \) 个顶点的有向图的邻接矩阵是一个 \( n \times n \) 矩阵，当图中存在一条离开 \( u \)、进入 \( v \) 的边时，其第 \( u \) 行第 \( v \) 列的元素为 1，否则为 0<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。对无向图而言，这个矩阵关于对角线对称；对有向图而言，一般并不对称<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。矩阵表示需要 \( O(V^2) \) 的空间，在 \( |E| \) 为 \( O(V) \) 的稀疏图上会浪费空间；而邻接表需要 \( O(V+E) \) 的空间，查找出边很高效，不过查找入边需要扫描整个结构<sup>[12](https://www.cs.cornell.edu/courses/cs2112/2014fa/lectures/lec_graphs/)</sup>。当两个方向的遍历都需要时，一种常见做法是为转置图再保存一份邻接表，转置图中每条边都反向<sup>[12](https://www.cs.cornell.edu/courses/cs2112/2014fa/lectures/lec_graphs/)</sup>。

在软件库中，类结构反映了这一区别。NetworkX 提供 DiGraph 作为其有向图的基类，允许自环，即从顶点指向自身的边，但不允许平行边，并对外提供独立的入度和出度视图、后继与前驱查询，以及一个反向操作<sup>[13](https://networkx.org/documentation/stable/reference/classes/digraph.html)</sup>。

## 连通性与强连通分量

方向把通常的连通性概念一分为二。有向图是强连通的，当且仅当对一对顶点 \( X \) 和 \( Y \)，存在从 \( X \) 到 \( Y \) 的路径以及从 \( Y \) 到 \( X \) 的路径<sup>[4](https://arxiv.org/abs/1802.05387)</sup>。有向图是弱连通的，当忽略边的方向后得到的无向版本是连通的<sup>[6](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/3-graph/classify_represent.html)</sup>。

关系“存在从 \( u \) 到 \( v \) 的路径，且存在从 \( v \) 到 \( u \) 的路径”是一种等价关系，它的等价类称为图的强连通分量<sup>[3](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)</sup>。已有算法能在 \( O(\text{numberOfNodes} + \text{numberOfEdges} \cdot \log^*(\text{numberOfNodes})) \) 时间内求出给定图的这一划分<sup>[4](https://arxiv.org/abs/1802.05387)</sup>。

## 有向无环图与拓扑排序

不含 directed cycle 的有向图称为有向无环图，即 DAG<sup>[5](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)</sup>。给定一个 DAG \( G = (V, E) \)，拓扑排序把它的顶点排成一个序列，使得对属于 \( E \) 的每条边 \( (u, v) \)，\( u \) 都排在 \( v \) 之前<sup>[5](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)</sup>。这样的顺序只有当图无环时才存在：深度优先搜索可以在 \( O(|V| + |E|) \) 时间内通过回边检测出环，如果没有发现环，那么 DFS 完成顺序的逆序就是一个拓扑排序<sup>[5](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)</sup>。一个标准的例子是排程：为每个学生建一个顶点，若 \( a \) 在某个组织中管理 \( b \)，就从学生 \( a \) 向学生 \( b \) 连一条有向边；学生的一种合法排序存在，当且仅当这个图没有环<sup>[5](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)</sup>。

## 应用

有向图可以建模任何非对称的关系。Twitter、Instagram 等非对称社交网络，含单行道的道路网络，以软件包为顶点、依赖关系为边的软件依赖图，以及带先修关系的课程图，都天然是有向的<sup>[6](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/3-graph/classify_represent.html)</sup>。NIST 算法与数据结构词典直接给出了街道的类比：一个街区的街道地图是无向图，而显示邮递员在该街区路线的地图则是有向的，一条普通的双向街道可以看作两条单行道<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup>。

**万维网规模的例子。** 万维网的链接结构被建模为有向图，页面是顶点，超链接是有向边，PageRank 引用排名就是在这个图上提出的<sup>[14](https://citeseerx.ist.psu.edu/document?doi=caaaafdb9fa45d0cb246eacea1f880227fd22c8a&repid=rep1&type=pdf)</sup>。谷歌最初的搜索引擎论文描述了一个原型，它拥有至少 2400 万页面的全文和超链接数据库，正是为了利用超文本中存在的结构<sup>[15](https://research.google/pubs/the-anatomy-of-a-large-scale-hypertextual-web-search-engine/)</sup>。

**数据标准。** 资源描述框架（RDF）是 W3C 制定的万维网数据交换标准模型，它构成一个有向的、带标签的图，其中每个由主语、谓语、宾语组成的三元组都是一条从主语指向宾语的有向弧<sup>[16](https://www.w3.org/TR/rdf10-concepts/)</sup>。属性图是另一种主要的图数据库数据模型，它是图查询语言 GQL 的 ISO/IEC 39075:2024 标准的主题，该标准于 2024 年 4 月发布，规定了一种用于创建、访问、查询和维护属性图的语言<sup>[17](https://www.iso.org/standard/76120.html?browse=tc)</sup>。

## 历史

整个图论可以追溯到莱昂哈德·欧拉（Leonhard Euler）1736 年对柯尼斯堡（Königsberg）七桥问题的解决，他把一个关于七座桥的散步谜题改述为一个图的问题，图的顶点是城市的四个区域<sup>[18](https://www.southampton.ac.uk/courses/2027-28/modules/math3033)</sup>。有向图则另有源流。根据约翰·N·沃菲尔德（John N. Warfield）提供的一则历史注记，奥古斯都·德·摩根（Augustus De Morgan）发明了关系理论，并于 1847 年发表了其关键著作；由于该理论实质上提供了有向图的代数形式，1847 年之前的正式使用被认为不太可能<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup>。同一则注记记载，与德·摩根这一脉络相关的最早的有向图实际绘图，出现在伯特兰·罗素（Bertrand Russell）1919 年的著作《数学哲学导论》（*Introduction to Mathematical Philosophy*）中<sup>[1](https://xlinux.nist.gov/dads/HTML/directedGraph.html)</sup>。在该领域形成过程的学术文献中，德内斯·柯尼希（Dénes Kőnig）在其 1936 年那部开创性的图论著作中称为有向图的基本内容，几乎全部取自保罗·赫兹（Paul Hertz）1922 年关于句子结构推理的文章<sup>[19](https://www.tandfonline.com/doi/abs/10.1080/01445340.2019.1608493)</sup>。

## References

1. [Paul E. Black, "directed graph", Dictionary of Algorithms and Data Structures, NIST](https://xlinux.nist.gov/dads/HTML/directedGraph.html)
2. [Directed vs Undirected Graphs Explained, Learn Graph Theory](https://learngraphtheory.org/articles/directed-vs-undirected-graphs.html)
3. [Lecture Notes 8: Directed Graphs, University of Texas at Austin](https://www.cs.utexas.edu/~vl/teaching/311/ln8.pdf)
4. [Strongly connected components: Algorithm for finding the strongly connected components of a graph, arXiv](https://arxiv.org/abs/1802.05387)
5. [6.006 Introduction to Algorithms, Recitation 10: Topological Sort, MIT OpenCourseWare](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/d9265b3b33d238ff914b0223ac8e7628_MIT6_006S20_r10.pdf)
6. [Graph Classifications and Representations, Oregon State University](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/3-graph/classify_represent.html)
7. [Notes on Discrete Mathematics (Aspnes), Yale University](https://cse.unl.edu/~cbourke/CSCE235/books/NotesOnDiscreteMathematics-Aspnes.pdf)
8. [Chapter 1: Introduction to Graphs and Networks, Graph Neural Networks textbook](https://anvithpothula.github.io/graph-neural-networks-textbook/chapters/01-intro-to-graphs/)
9. [Graphs, CS 367 readings, University of Wisconsin–Madison](https://pages.cs.wisc.edu/~skrentny/cs367-common/readings/Graphs/index.html)
10. [Chapter 4: Graph Theory, Stanford CS103 course notes](https://theory.stanford.edu/~trevisan/cs103-14/keith.pdf)
11. [Introduction to Graphs, ECS 34, UC Davis](https://csiflabs.cs.ucdavis.edu/~tyfeng/ecs34/C%2B%2B/graphs.html)
12. [Lecture notes on graphs, CS 2112, Cornell University](https://www.cs.cornell.edu/courses/cs2112/2014fa/lectures/lec_graphs/)
13. [DiGraph: Directed graphs with self loops, NetworkX 3.7 documentation](https://networkx.org/documentation/stable/reference/classes/digraph.html)
14. [A Survey on PageRank Computing, CiteSeerX](https://citeseerx.ist.psu.edu/document?doi=caaaafdb9fa45d0cb246eacea1f880227fd22c8a&repid=rep1&type=pdf)
15. [Sergey Brin and Lawrence Page, The Anatomy of a Large-Scale Hypertextual Web Search Engine, Google Research](https://research.google/pubs/the-anatomy-of-a-large-scale-hypertextual-web-search-engine/)
16. [Resource Description Framework (RDF): Concepts and Abstract Syntax, W3C](https://www.w3.org/TR/rdf10-concepts/)
17. [ISO/IEC 39075:2024, Information technology — Database languages — GQL, ISO](https://www.iso.org/standard/76120.html?browse=tc)
18. [MATH3033 Graph Theory, University of Southampton](https://www.southampton.ac.uk/courses/2027-28/modules/math3033)
19. [The Role of Structural Reasoning in the Genesis of Graph Theory, History and Philosophy of Logic](https://www.tandfonline.com/doi/abs/10.1080/01445340.2019.1608493)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Graph theory › Graph theory overview and basic objects

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/directed-graph

English original: https://www.edgepedia.org/directed-graph
