数据结构 图形化
What you will learn?
您将学到什么?
In this article we are going to study how graph is being represented?
在本文中,我们将研究图形如何表示 ?
Following is an undirected graph,
以下是无向图,
![Graph image 3](https://www.includehelp.com/data-structure-tutorial/images/graph-3.jpg)
We can represent the same graph by two different methods:
我们可以通过两种不同的方法表示同一张图 :
Adjacency Matrix
邻接矩阵
Adjacency List
邻接表
1)邻接矩阵 (1) Adjacency Matrix)
A graph can represent matrix elements. Initially, all the elements of a matrix are zero. If there is an edge between two vertices (example vertex A and B) then we mark '1' to the element at the position MAB and MBA for undirected graph and for a directed graph, we mark '1' to the element at the position MAB.
图可以表示矩阵元素 。 最初,矩阵的所有元素均为零。 如果存在两个顶点之间“1”的元素在位置M AB和M BA为无向图和有向图的边缘(例如顶点A和B),那么我们标记,我们标记“1”的元素在位置M AB 。
Example:
例:
![Graph image 4](https://i-blog.csdnimg.cn/blog_migrate/f71749999914df408e6f66fcc47697bf.png)
2)邻接表 (2) Adjacency List)
A graph can also be represented by a list. We need an array of the list and for each time if there is an edge exist between two vertices then we push one vertex to another vertex list and vice versa. For the previous graph, we get an Adjacency List like this:
图也可以由列表表示。 我们需要一个列表数组,并且每次在两个顶点之间存在边时,我们都会将一个顶点推到另一个顶点列表,反之亦然。 对于上一个图,我们得到一个邻接列表,如下所示:
![Graph image 5](https://www.includehelp.com/data-structure-tutorial/images/graph-5.jpg)
翻译自: https://www.includehelp.com/data-structure-tutorial/representation-of-a-graph.aspx
数据结构 图形化