当前位置:网站首页>图的存储结构(邻接矩阵)
图的存储结构(邻接矩阵)
2022-06-22 18:28:00 【单单一个越字】
- 图的邻接矩阵(Adjacency Matrix)存储方式是用两个数组来表示图。一个一维数组存储图中顶点信息,一个二维数组(称为邻接矩阵)存储图中的边或弧的信息。
- 无向图
我们可以设置两个数组,顶点数组为vertex[4]={V0,V1,V2,V3},边数组arc[4][4]为对称矩阵(0表示不存在顶点间的边,1表示顶点间存在边)。
对称矩阵:所谓对称矩阵就是n阶矩阵的元满足a[i][j]=a[j][i] (0<=i,j<=n)。即从矩阵的左上角到右下角的主对角线为轴,右上角的元与左下角相对应的元全都是相等的。
有了这个二维数组组成的对称矩阵,我们就可以很容易地知道图中的信息:
– 要判定任意两顶点是否有边无边就非常容易了;
– 要知道某个顶点的度,其实就是这个顶点Vi在邻接矩阵中第i行(或第i列)的元素之和;
– 求顶点Vi的所有邻接点就是将矩阵中第i行元素扫描一遍,arc[i][j]为1就是邻接点。

3. 有向图
可见顶点数组vertex[4]={V0,V1,V2,V3},弧数组arc[4][4]也是一个矩阵,但因为是有向图,所以这个矩阵并不对称,例如由V1到V0有弧,得到arc[1][0]=1,而V0到V1没有弧,因此arc[0][1]=0。
另外有向图是有讲究的,要考虑入度和出度,顶点V1的入度为1,正好是第V1列的各数之和,顶点V1的出度为2,正好是第V1行的各数之和。
4. 每条边或弧带权重的图(网)
无穷值设为一个异常的权值即可,通过判断这个值是否异常来看边或弧是否存在。
边栏推荐
- c# winform 嵌入flash
- 第一篇 热身--隐式类型转换还是其他?
- Assign values to objects
- 实验七 触发器
- 深入浅出聊布隆过滤器(Bloom Filter)
- Openpnp调试 ------ 0816飞达推0402编带
- MySQL约束
- How to use yincan IS903 to master DIY's own USB flash disk? (good items for practicing BGA welding)
- The custom control autoscalemode causes the problem of increasing the width of font
- 知识蒸馏之Focal and Global Knowledge Distillation for Detectors
猜你喜欢

84.(cesium篇)cesium模型在地形上运动

安装Office的一些工具

记可视化项目代码设计的心路历程以及理解

Openpnp调试 ------ 0816飞达推0402编带

0.1----- process of drawing PCB with AD

0816 shortcomings of Feida (improvement direction)

Flutter series - build a flutter development environment

3D打印机耗材受潮

Altium Designer中off grid pin解决方法

Nrf51822 peripheral learning
随机推荐
数字货币钱包开发不知道怎么选?
K8s deploy MySQL
Interface development component devaxpress asp Net core v21.2 - UI component enhancements
从11小时到25秒--还有优化空间吗?
0816飞达的缺点(改进方向)
A homekit enabled camera? Zhiting IPC camera IC1 unpacking experience
小波变换db4进行四层分解及其信号重构—matlab分析及C语言实现
记可视化项目代码设计的心路历程以及理解
C #, introductory tutorial -- a little knowledge about function parameter ref and source program
如何在 FlowUs和Notion 等笔记软件中进行任务管理?
Teachers, I want to ask you a question. I run flinkcdc locally to synchronize MySQL data. The timestamp field parsing is normal,
About Random Forest
详解openGauss多线程架构启动过程
c# winform 嵌入flash
Intelligent procurement system solution for processing and manufacturing industry: help enterprises realize integrated and Collaborative Procurement in the whole process
Mini web framework: template replacement and routing list function development | dark horse programmer
Altium Designer中off grid pin解决方法
Install some office tools
84. (cesium chapter) movement of cesium model on terrain
Array objects can be compared one by one (the original data with the same index and ID will be retained, and the data not in the original array will be added from the default list)