Storage structure and achieve 02 map

FIG storage structure are used adjacency matrix, adjacency list, adjacency lists and cross multiple tables.
Here Insert Picture Description

  1. FIG array notation - adjacency matrix

Logical structure is divided into a set of vertices and the set of edges of two parts, a vertex is an element, it is possible to use a one-dimensional array to store the vertex data; is represented by an edge of its associated two vertices, i.e., a side element has two data fields, it is possible to store the relationship between adjacent vertices (i.e., edges or arcs) with a matrix, the two-dimensional array is also known as the adjacency matrix. If two vertices are linked, then the values of the matrix may be referred to as 1, 0 otherwise.
Here Insert Picture Description
Definition of the adjacency matrix
Here Insert Picture Description
(1) undirected adjacency matrix
Here Insert Picture Description
(2) directed graph adjacency matrix
Here Insert Picture Description
adjacency matrix (3) network
Here Insert Picture Description
data structure descriptor adjacency matrix

(1) Structure Description

#define  VERTEX_NUM  6        //图的顶点数
#define  VERTEX_MAX_NUM 64   //图的最大顶点数
#define  EDGE_MAX_NUM  20   //图的最大边数
typedef char VexType;   //顶点的数据类型
typedef int InfoType;   // 弧(边)的类型,如权值、边存在或不存在等

Adjacency matrix Adjacency Matrix - AM

typedef struct
{   VexType  VertexArray[VERTEX_NUM];  //顶点数组
    InfoType  AdjMatrix [VERTEX_NUM][ VERTEX_NUM];  //邻接矩阵
} AM_Graph;

(2) Analysis of the complexity of the adjacency matrix
Here Insert Picture Description
2. margination array notation

(1) Design of arrays side
edge set only memory map array of all edges (or arcs) information, storing the starting point of an edge of the end (for undirected graphs, the edge may be selected at either end of the start or end point) and side information (e.g., weight), the order of the sides in the array can be arbitrarily arranged, also according to the specific requirements. For storing vertex information, a one-dimensional array need VERTEX_NUM elements.
Here Insert Picture Description
(2) the edge of arrays (Edgeset Array) described in a data structure

typedef  struct  //边集数组单元结构
{   VexType  from_vex;  //起点
    VexType  end_vex;  //终点
    InfoType  weight;  //权值项可以根据需要设置
} EdgeStruct;
EdgeStruct  EdgeSet[EDGE_MAX_NUM];  //边集数组

(3) the complexity of the analysis of arrays edge
Here Insert Picture Description
3. The linked list representation of FIG. 1-- adjacent table

Adjacency matrix arrangement readily intuitively understood that if the structure of FIG itself needs to be generated dynamically in the problem-solving process, each adding or deleting a vertex adjacency matrix size needs to be changed, this is clearly a very low efficiency. In addition, the number of memory cells occupies only adjacency matrix with the number of vertices in the relevant figures, regardless of the number edge (arc), for a small number of edges opposite vertices of FIG sparse, this wasted storage space than Big.

(1)邻接表的存储结构设计
对图的每个顶点建立一个单链表( n 个顶点建立 n 个单链表),第 i 个单链表中的结点包含顶点 Vi 的所有邻接结点。
对 n 个同类单链表并行管理,是采用“带行向量的链表表示方法”,这种存储结构称为邻接表。邻接表由头结点表和邻接结点链表两部分组成。

无向图邻接表
Here Insert Picture Description
对于无向图来说,使用邻接表进行存储也会出现数据冗余,头结点 V1 所指链表中存在一个指向 V4 的邻接结点的同时,头结点 V4 所指链表也会存在一个指向 V1 的邻接结点。

有向图邻接表(出边表)
Here Insert Picture Description
逆邻接表(入边表)

有时为了便于确定顶点的入度或以顶点为弧头的弧,可以建立一个有向图的逆邻接表。
Here Insert Picture Description
带权邻接表

数据结构与邻接表基本一致,只在邻接结点中增加一个记录边的权值的数据域。
Here Insert Picture Description
(2)邻接表数据结构描述
Here Insert Picture Description
邻接表Adjacency List——AL

typedef struct AdjNode  //邻接结点结构
{     
   int adjvex;        //邻接点
   AdjNode *next;   // 邻接点指针
} AL_AdjNode; 

typedef struct  //邻接表顶点结点结构
{             
   VexType  vertex;   //顶点
   AdjNode *link;     // 邻接点头指针
} AL_VexNode; 

typedef struct  //总的邻接表结构
{                 
   A_VexNode  VexList[VERTEX_MAX_NUM];  //顶点表
   int VexNum, ArcNum;    //顶点数,弧(边)数
} AL_Graph; 

建立邻接表

/*==========================================
函数功能:建立邻接表
函数输入:无
函数输出:无
共享数据:图的邻接矩阵
=============================================*/
void Create_AdjList()
{
	AL_VexNode VexList[N]={0,NULL};  //顶点表
	int j;
	AL_AdjNode *Ptr,*nextPtr;
?
	for(int i=0; i<N; i++)
	{
		VexList[i].vertex=i;
		VexList[i].link=NULL;
		j=0;
		while(j<N)
		{
			if (AdjMatrix[i][j]!=0)//有邻接点
			{
				Ptr=(AL_AdjNode*)malloc(sizeof(AL_AdjNode));
				Ptr->adjvex=j;
				Ptr->next=NULL;
				if (VexList[i].link==NULL)//首次加入邻接点
				{
					VexList[i].link=Ptr;
				    nextPtr=Ptr;
				}
				else 
				{
					nextPtr->next=Ptr;
					nextPtr=Ptr;
				}
			}
			j++;
		}
	}
}

邻接表的空间复杂度分析
Here Insert Picture Description
4. 十字链表

图的十字链表是有向图的另一种链式存储结构。该结构以入弧和出弧为线索,将有向图的邻接表和逆邻接表结合起来得到的,有顶点表和边表组成。十字链表结构也可以理解为将行的单链表和列的单链表结合起来存储稀疏矩阵,每个结点表示一个非零元素。

在十字链表中,对应于有向图中每一条弧都有一个弧结点,对应于每个顶点也有一个顶点结点。
Here Insert Picture Description
Here Insert Picture Description
十字链表复杂度分析
Here Insert Picture Description
5. 邻接多重表

Similarly the adjacent multi-table storage structure and cross linked list, but also by the vertices and edges table tables, the adjacent multi-table, each edge information is described by a node, an edge corresponding to an edge node. Side junctions of the edge node, in addition to two associated vertices ivex edges, jvex outside, coupled with ivex connected with the junction edges jvex connected position.
Here Insert Picture Description
Here Insert Picture Description

//邻接多重表的顶点结构
typedef   struct vnode
{     VexType   vertex;   	 //顶点信息
      struct node *firstedge; //指向第一条依附于该顶点的边
} AML_VertexNode;
//邻接多重表的顶点表
AML_VertexNode  G[VERTEX_NUM]; 
//邻接多重表的边结点结构
typedef  struct node
{   int  ivex, jvex;  		//边的两个关联点
    struct node *ilink,*jlink; //分别指向依附于ivex和jvex的下一条边
}  AML_EdgeNode;

Table complexity analysis of multiple adjacent
Here Insert Picture Description
storage structure attributed storage structure due Comparative Comparative

  1. Watch storage structure vertices
    Here Insert Picture Description
  2. Storage structure concerned sides
    Here Insert Picture Description
  3. FIG storage structure selection principle
    Here Insert Picture Description
    Here Insert Picture Description
Published 26 original articles · won praise 3 · Views 1465

Guess you like

Origin blog.csdn.net/herui7322/article/details/104328252