Data structure of C + + implementation of the graph of the storage structures of the adjacency table

Source: Internet
Author: User

For graphs, the adjacency matrix is a good graph storage structure, but we also find that for graphs with fewer edges relative to vertices, this structure has a great waste of storage space. So we consider another type of storage structure: adjacency table (adjacency list), that is, the combination of array and linked list of storage methods.

The method of dealing with the adjacency table is this.

1, the vertex in the graph is stored in a one-dimensional array, in addition, for the vertex array, each data element also needs to store a pointer to the first adjacency point to facilitate the lookup of the vertex's edge information.

2, the graph of each vertex VI of all adjacent points constitute a linear table, because the number of adjacent points is uncertain, so with a single chain table storage, the non-map is called Vertex vi edge table, there is to the graph called Vertex VI as the arc tail of the edge table.

For example, the graph 7-4-6 is an adjacency table structure of a non direction graph.

If there is a direction graph, the structure of the adjacency table is similar, such as Figure 7-4-7, it is easy to get the degree of each vertex by the vertex as the arc tail, and the table with the vertex as the arc head is easy to get the vertex's entry degree, namely the inverse adjacency table.

For a network map with weights, you can add a weight data field to the definition of the side table node and store the weight information, as shown in Figure 7-4-8.

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.