9.2.2 storage method of the adjacent table

Source: Internet
Author: User

The storage method of the graph's adjacent table is a storage method that combines sequential allocation and chain allocation. In the adjacent table, a single-chain table is created for each vertex in the graph. The node in the I-th single-chain table is the edge attached to the vertex VI (the directed graph is an arc ending with vertex VI .) Each single-chain table has a header node. The structure of the table node and the header node is as follows:

The table node consists of three fields. adjvex indicates the position of the vertex VI adjacent to the vertex in the graph, and nextarc indicates the node of the next edge or arc, info stores information related to edges or arcs, such as weights. The header node is composed of two fields. data stores the vertex VI name or other information. firstarc points to the first node in the linked list.

The features of the adjacent table are as follows:

  • The list of adjacent tables is not unique. This is because in the single-link table corresponding to each vertex, the link order of each edge node can be arbitrary, depending on the algorithm used to establish the adjacent table and the edge input order.
  • For an undirected graph with n vertices and e edges, the adjacent table has n vertex nodes and 2e edge nodes. Obviously, for sparse graphs, the adjacent tables are less space than the adjacent matrix.
  • For undirected graphs, the number of edge nodes in the I-th linked list corresponding to vertex VI in the adjacent table is exactly the degree of vertex VI.
  • For directed graphs, the number of edge nodes in the I-th linked list corresponding to vertex VI of the adjacent table is only the degree of exit of VI. The entry level is the number of edge nodes with the adjvex Domain value I in the adjacent table.

The storage representation of the adjacent table is defined as follows:

Typedef struct anode/* node Structure Type of the arc */{int adjvex;/* end point of the arc */struct anode * nextarc; /* pointer to the next arc */infetype Info;/* information about the arc */} arcnode; typedef struct vnode/* type of the adjacent header node */{vertex data; /* vertex information */arcnode * fristarc;/* points to the first arc */} vnode; typedef vnode adjlist [maxv]; /* adjlist is an adjacent table type */typedef struct {adjlist;/* the adjacent table */int n, E; /* vertex number N and edge number E */} algraph;/* graph type */

Because only an arc starting from a vertex is stored in the adjacent table of the directed graph, it is difficult to find the arc pointing to the vertex. To this end, we can design a directed graph inverse neighbor table. The inverse adjacent table refers to the arc pointing to each vertex in the directed graph's adjacent table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.