当前位置:网站首页>Adjacency matrix and adjacency table structure of C # realization graph
Adjacency matrix and adjacency table structure of C # realization graph
2022-06-29 12:47:00 【Dusk and starry sky】
In this paper, C# Adjacency matrix and adjacency table structure of realization graph .
The logical structure is divided into two parts :V and E aggregate , among ,V Is the vertex. ,E Is the edge . therefore , Use a one-dimensional array to store all vertex data in the graph ; Use a two-dimensional array to store the relationship between vertices ( Edge or arc ) The data of , This two-dimensional array is called adjacency matrix . Adjacency matrix is divided into directed graph adjacency matrix and undirected graph adjacency matrix
Adjacency matrix (Adjacency Matrix) Is a matrix representing the adjacency relationship between vertices . set up G=(V,E) It's a picture , among V={v1,v2,…,vn} [1] .G The adjacency matrix of is a matrix with the following properties n Square matrix :
① For undirected graphs , Adjacency matrix must be symmetric , And the main diagonal must be zero ( Only undirected simple graphs are discussed here ), The sub diagonal is not necessarily 0, This is not necessarily the case for directed graphs .
② In the undirected graph , Any vertex i It's the third degree i Column ( Or the first i That's ok ) The number of all non-zero elements , In a directed graph, vertices i The output of is the i The number of all non-zero elements in the row , And the penetration is the second i The number of all non-zero elements of the column .
③ Representation of graph common needs by adjacency matrix method n^2 Space , Because the adjacency matrix of an undirected graph must have symmetry , So after deducting that the diagonal is zero , You only need to store the data of the upper triangle or the lower triangle , So just n(n-1)/2 Space .
Adjacency list , The storage method is similar to the child chain representation of a tree , It is a storage structure combining sequential allocation and chain allocation . If the vertex corresponding to this header node has adjacent vertices , Then the adjacent vertices are placed in order in the list that the header points to .
For undirected graphs , Using adjacency table for storage will also lead to data redundancy , Header node A There is a point in the linked list C At the same time , Header node C The linked list will also have a point to A Table node . [1]
The program code is as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace The storage structure of the graph
{
using VertexType = System.Char;// Vertex data type alias declaration
using EdgeType = System.Int16;// Data type alias declaration of edge weight in weighted graph
class Program
{
public const int MAxVertexNum =100;// The maximum number of vertices
static void Main(string[] args)
{
}
/// <summary>
/// Definition of graph -- Adjacency matrix
/// </summary>
public struct MGraph {
public VertexType[] vex;// Vertex table array
public EdgeType[][] Edge;// Adjacency matrix 、 Side table
public int vexnum,arcnum;// The current vertex and arc number of a graph
}
/// <summary>
/// Definition of graph -- Adjacency table method
/// </summary>
public class ArcNode {// Edge table node
public int adjvex;
public ArcNode next;
}
public class VNode { // Vertex table node
VertexType data;// Vertex information
ArcNode first;// Just think of the pointer to the first arc attached to the vertex
}
public class ALGraph {
VNode[] vertices; // Adjacency list
int vexnum, arcnum;// The number of vertices and arcs of a graph
}
}
}
边栏推荐
- Method area of JVM
- oracle 19c : change the user sys/system username pasword under Linux
- Recommended model reproduction (II): fine arrangement model deepfm, DIN
- Gbase8s database for read only clause
- Gbase8s database into external clause
- Pangolin compilation error: 'numeric_ limits’ is not a member of ‘std’
- 地球观测卫星数据
- MySQL数据库主从同步,一致性解决方案
- 云龙开炮版飞机大战(完整版)
- 推荐模型复现(四):多任务模型ESMM、MMOE
猜你喜欢

LeetCode_ Double pointer_ Medium_ 328. parity linked list

Understanding of P value

Qt的信号与槽

C#通過中序遍曆對二叉樹進行線索化

Weekly recommended short video: How did Einstein think?

After class assignment of module 5 of the construction practice camp

解决问题:ModuleNotFoundError: No module named ‘pip‘

oracle 19c : change the user sys/system username pasword under Linux

Comment calculer Win / Tai / Loss in paired t - test

多项目开发入门-业务场景关联基础入门测试 工资表
随机推荐
Newton inequality
如果我在深圳,到哪里开户比较好?另外想问,现在在线开户安全么?
Blurred pictures become clear, one button two-color pictures, quickly organize local pictures These 8 online picture tools apply to join your favorites!
[环境配置]PWC-Net
MIT线性代数中文笔记
Go Senior Engineer required course | I sincerely suggest you listen to it. Don't miss it~
MySQL数据库主从同步,一致性解决方案
Understanding of P value
Qt的信号与槽
Gbase8s database select has order by Clause 2
Matlab简单入门
推荐模型复现(二):精排模型DeepFM、DIN
【LeetCode】14、最长公共前缀
牛顿不等式
AGCO AI frontier promotion (6.29)
MySQL master-slave synchronous asynchronous replication semi synchronous replication full synchronous replication
Pygame 精准检测图像碰撞
面试突击61:说一下MySQL事务隔离级别?
Syntax of gbase8s database incompatible with for update clause
Qt中的UI文件介绍