Data structure-definition and realization of graphs

Before introducing the adjacency matrix, introduce the related concepts of the graph (the concept is slightly more complicated than the surface of the previous tree)

Definition of graph

I learned linear tables, strings, and trees before. They are all one-to-one or one-to-many relationships-suitable for parents to children

But in addition, there is a network structure in life, namely friend to friend, and there is a many-to-many relationship between them.

This leads to the graph.
Insert picture description here
G(V,E) represents
G represents a graph
V represents a collection of vertices (used to store data)
E represents a collection of edges (paths). An edge can have a direction or no direction, and it can also have a weight


Definition of various graphs

Undirected edge

As the name implies, it refers to the non-directional edge between two vertices (Edge),
using **disordered pair (V1, V2)** to indicate a specific edge

A graph whose edges are all undirected is called an undirected graph

Insert picture description here
As shown in the figure above, G1=(V,(E)) The set of vertices V is V=(V0,V1,V2,V3)
The set of edges E=((V0,V1),(V0,V2),(V0,V3 ),(V1,V2),(V3,V2))

Directed edge

Insert picture description here
The edges of the directed graph use ** ordered pair <V1, V2>** to indicate that V1 indicates the end of the arc, V2 indicates the beginning of the arc,
and the directed graph G2=(V,(E)) indicates that
the set of vertices V is V=(V1, V2,V3,V4)
set of arcs E={<V1,V2>,<V1,V4>,<V2,V3>,<V3,V4>}

Indicating the difference is that there are parentheses to the edge of the arc directed graph and no
----
if there are no side view of the repeat itself and to the side that is simple diagram
The figure below points to himself as self-circulation
Insert picture description here
in the absence of The existence of edges at any two vertices in a directed graph is called an undirected complete graph.
In a directed graph, the existence of two arcs with opposite directions at any two vertices is called a directed complete graph.

A few edges or arcs are called a sparse graph, otherwise it is called a dense graph

There can be weights on edges or arcs. A graph with weights is called a net.

Of course, a large graph also has subgraphs (equivalent to the meaning of a set). As long as the graph exists, there must be subgraphs. A vertex can also be a subgraph.

The relationship between the vertices and edges of the graph

1. For an undirected graph, if there is an edge between two vertices, then these two vertices are called adjacent vertices , and the two edges are attached to the two vertices.
The degree of the vertices refers to a certain The number of vertices and its edges.
For an undirected graph, the sum of the degrees of the vertices is twice the number of
edges because the edges have no direction and are counted twice each time.

For a directed graph, the arc <V1, V2> exists, then vertex V1 is adjacent to vertex V2,
vertex V2 is connected to vertex V1
, and the degree of a vertex is divided into out degree and in degree, as the name implies,
degree = out degree + in degree

Overall speaking out degree = in degree

3. The length of a path is the number of edges (arcs) from
one vertex to another. The same path from the first vertex to the last vertex is called a loop or
the path between two vertices of a loop , either The vertices do not appear repeatedly and are called simple loops or simple loops

4. In an undirected graph , if there is a path between any vertex V1 and another vertex V2, it is called a connected graph

The maximum connected subgraph in the undirected graph is called the connected component of the undirected graph

5. In the digraph any pair of vertices is called a path exists strong graph
has referred to the maximum drawing strongly connected subgraphs are connected components of the FIG.

Connected graph spanning tree

The spanning tree of a connected graph is a very small connected subtree, which contains all n vertices in the graph, but only has n-1 edges sufficient to form a tree.

For a directed graph, there is exactly one vertex with an in-degree of 0, and other vertices with an in-degree of 1, which is a directed tree

Various realizations of the graph

Data structure-graph adjacency matrix to achieve
data structure-graph adjacency list to achieve
data structure-graph cross-linked list to achieve
data structure-graph adjacency multiple table to achieve
data structure-adjacency matrix depth-first traversal (DFS) And breadth-first traversal (BFS) understanding and realization of
data structure-the minimum spanning tree and maximum spanning tree of the
graph understanding and realization of the Prim algorithm data structure-the minimum spanning tree and maximum spanning tree of the graph Kruskal algorithm understanding and realization of
data understood and Dijkstra shortest path algorithm of Dijkstra graph - structure
data structure - FIG Freud's shortest path algorithm FLOYD understanding and implementation of
data structures - topological sorting algorithm to understand and implement
the data structure —— Critical Path AOV (Picture)

Guess you like

Origin blog.csdn.net/weixin_46096297/article/details/112999415