Graph theory: understanding of the basic concepts of cross-linked lists

<Writing a blog is to learn and understand more deeply>

        I was a little bit confused when I was learning the cross-linked list of the soft-shelled turtle class. After searching in station C, I found that there was no description or explanation that was more familiar to Xiaobai. I wrote this blog with the attitude of letting myself understand more deeply and sharing it with everyone. Please point out any mistakes.

The introduction of the cross list:

        The use of the adjacency list is simple and convenient, but in the processing of the directed graph, the single adjacency list can only represent the out degree (as shown in Figure 1)

But in a specific case, if the in-degree of the point of concern is needed, an inverse adjacency list needs to be established.

818259a9cddb48febe4b002a1fb1f3ec.jpeg                                        436f9b0132f9420b9e66492047bec836.jpeg

 (Figure 1) The adjacency list of A, indicating the outgoing edge list (Figure 2) The incoming edge list and outgoing edge list of A

Therefore, it is advisable to combine the adjacency list and the inverse adjacency list to create a cross-linked list, which can represent both the in-degree and the out-degree. (Picture 2, is it a cross?)

The construction method of cross linked list:

① Redefine the header structure

        It is only necessary to slightly modify the header structure, and add two pointer fields firstIn and firstOut, respectively pointing to the address of the first vertex with A as the end of the arc and A as the head of the arc. In this way, the in-degree and out-degree can be obtained by iteratively searching the in and out pointer fields. (You can compare and observe the head structure in Figure 1 and Figure 2 to help you understand)

data firstIn firstOut

 

data: vertex data firstIn: pointer to the first edge table firstOut: pointer to the first edge table

② Redefine the node structure of the edge table       

(The adjacency list removes the linked list structure of the head node, and each node represents an edge, so it is called an edge list)

        The structure of each node in the edge table is as follows:

        tailvex: the subscript of the starting point of the arc            headvex: the subscript of the end point of the arc headlink: the pointer to the edge taillink: the pointer to the edge

tailVex headVex headLink tailLink

Each node contains a complete edge information tailvex->headvex; the address headlink of the next incoming edge; the address taillink of the next outgoing edge.

A cross linked list can be formed by filling the four fields.

                        A bit abstract, give a concrete example to help understand:

        1. As shown in the lower left corner of the figure, establish the vertex structure according to step ①

        2. Establish the node structure as shown in ②, which is the same as the establishment method of the adjacency list. Point the firstOut pointer field to the first outbound edge, and then fill in the tailLink pointer field in turn to complete the outbound edge table.

751fd6eebaa943119e59295e76571d24.png(Kind of a clown T_T)

        3. In the same way as establishing the inverse adjacency list, point the firstIn pointer field to the first incoming edge address, and then fill in the headLink pointer field in turn to complete the incoming edge table.

 6154ee5ee0b646d4b62f4372ce132e69.png(Take V0 as an example)

        4. In the end, the messy cross-linked list diagram in other posts was formed

fdb14eab87c9442e81673eb33aa19527.png(The picture is taken from "Data Structure and Algorithm" by bilibili fish C-Little Turtle)

In this way, the cross linked list is established. Using a table, the in-degree and out-degree of each vertex in the graph can be obtained.

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_67441224/article/details/126539668