Class notes: the logical structure of the graph

The graph definition
graph is composed of a finite set of vertices and a set of edges between the vertices, usually expressed as: G = (V, E), where: G represents a graph, V is the set of vertices in graph G, E is the set of edges between vertices in graph G.
In a linear table, the number of elements can be zero, called an empty table; in a tree, the number of nodes can be zero, called an empty tree; in a graph, the number of vertices cannot be zero, but there can be no edges.
If the edge between the vertices vi and vj has no direction, the edge is called an undirected edge and is expressed as (vi, vj).
If the edge between any two vertices of a graph is an undirected edge, the graph is called an undirected graph .
If the edge from the vertex vi to vj has a direction, then this edge is called a directed edge and is expressed as <vi, vj>.
If the edge between any two vertices of a graph is a directed edge, the graph is called a directed graph .
The basic term of the graph is a
simple graph : in the graph, if there is no vertex to its own edge, and the same edge does not appear repeatedly.
In an undirected graph, for any two vertices vi and vj, if there is an edge (vi, vj), the vertex vi and the vertex vj are said to be adjacent to each other , and the edge (vi, vj) is also attached to the vertex vi and the vertex vj.
In a directed graph, for any two vertices vi and vj, if there is an arc <vi, vj>, then the vertex vi is said to be adjacent to the vertex vj, the vertex vj is adjacent to the vertex vi, and the arc <vi, vj> is attached toVertex vi and vertex vj.
Comparison of logical relationships in different structures :
in a linear structure, there is only a linear relationship between data elements; in a tree structure, there is a hierarchical relationship between nodes; in a graph structure, there may be a relationship between any two vertices .
Undirected complete graph : In an undirected graph, if there are edges between any two vertices, the graph is called an undirected complete graph.
Directed complete graph : In a directed graph, if there are two arcs in opposite directions between any two vertices, the graph is called a directed complete graph.
Sparse graph : A graph with few edges is called a sparse graph; a
dense graph : a graph with many edges is called a dense graph.
Degree of vertex : In an undirected graph, the degree of vertex v refers to the number of edges attached to the vertex, usually denoted as TD (v).
Vertex in-degree : In the directed graph, the vertex in-degree refers to the number of arcs with the vertex as the arc head, which is recorded as ID (v);
vertex out-degree : in the directed graph, the vertex The outgoing degree refers to the number of arcs with the vertex as the tail, and is recorded as OD (v).
Weight : refers to the meaningful numerical value assigned to the edge.
Net : A graph with weights on the side, also known as a net graph.
Path : In an undirected graph G = (V, E), the path from vertex vp to vertex vq is a sequence of vertices (vp = vi0, vi1, vi2,…, vim = vq), where (vij- 1, vij) ∈ E (1≤j≤m). If G is a directed graph, the path is also directed, and the sequence of vertices satisfies <vij-1, vij> ∈E.
Path length: (1) Non-weighted graph-the number of edges on the path; (2) Weighted graph-the sum of the weights of the edges on the path.
Loop (loop) : The path between the first vertex and the last vertex is the same.
Simple path : A path where vertices in the sequence do not repeat.
Simple loop (simple loop) : Except for the first vertex and the last vertex, the rest of the vertices do not appear repeatedly.
Subgraph : FIG if G = (V, E), G '= (V', E '), and if V'V E'  E, FIG called G 'is a subgraph of G.
Connected graph : In an undirected graph, if there is a path from one vertex vi to another vertex vj (i ≠ j), the vertex vi and vj are said to be connected. If any two vertices in the graph are connected, the graph is called a connected graph.
Connected components : The maximally connected subgraphs of unconnected graphs are called connected components. (1. Contains the maximum number of vertices; 2. All edges attached to these vertices.)
Strongly connected graph : in a directed graph, for any pair of vertices vi and vj (i ≠ j) in the graph, if from the vertex vi There are paths to vertex vj and from vertex vj to vertex vi, and the directed graph is said to be a strongly connected graph.
Strongly connected component : a strongly connected subgraph of a non-strongly connected graph.
Spanning tree : The connected graph of n vertices G. The spanning tree is a minimal connected subgraph containing all the vertices in G. (Contains n-1 edges, more-constitutes a loop, less-not connected) Spanning
forest : In a non-connected graph, each connected component can get a spanning tree, and these connected components of the spanning tree are composed A generation forest for non-connected graphs.
Graph traversal operation The
graph traversal starts from a vertex in the graph, and visits all vertices in the graph once and only once.
The key problems to be solved by the traversal operation of the graph
(1) In the graph, how to select the starting vertex of the traversal?
Solution: Start with the lowest numbered vertex.
In the linear table, the number of the data element in the table is the position of the element in the sequence, so its number is unique;
in the tree, the nodes are numbered in order, because the tree is hierarchical, so the order number It is also unique;
in the graph, there may be edges between any two vertices, and the vertices have no definite order, so the number of vertices is not unique. For the convenience of defining operations, arrange the vertices in the graph in any order, for example, according to the storage order of the vertices.
(2) What can I do if I cannot reach all other vertices from a certain starting point?
Solution: Call the algorithm to traverse the graph starting from a vertex multiple times.
(3) Because there may be loops in the graph, some vertices may be repeatedly accessed, so how to avoid traversal will not fall into an endless loop due to loops?
Solution: Attached visit flag array visited [n].
(4) In the figure, a vertex can be connected with other vertices. After such a vertex has been visited, how to select the next vertex to be visited?
Solution: depth-first traversal and breadth-first traversal.
1. The basic idea of Depth First Search (DFS: Depth First Search)
: (
1) visit vertex v; (
2) select a vertex w from the unvisited neighboring points of v, and proceed with depth-first traversal from w;
(3) repeat the above two steps, Until all the vertices in the graph that have a path to v are accessed.
2,The
basic idea of BFS: Broad First Search :
⑴ visit vertex v;
⑵ visit each unvisited adjacent point v1, v2,…, vk of v in sequence;
⑶ start from v1, v2,…, vk respectively Visit their neighbors that have not been visited, and make "the neighbor of the vertex visited first" be visited before the "neighbour of the vertex visited next". Until all the vertices in the graph that have a path connection with the vertex v are accessed.

Published 48 original articles · Like 25 · Visit 2453

Guess you like

Origin blog.csdn.net/qq_43628959/article/details/103247844