Data structure - basic concepts of graphs

High energy warning! ! ! This section contains tons of concepts! ! !

——The content of this section is the video content notes of P54 of Bilibili Wangdao Postgraduate Entrance Examination "Data Structure".


Table of contents

1. Definition of graph

2. Undirected graph and directed graph

1. Undirected graph

2. Directed graph

3. Simple graphs and multiple graphs

1. Simple diagram:

 2.Multiple pictures:

4. Degree, in-degree, out-degree of vertex

1. Degree of undirected graph

2. Degree, in-degree and out-degree of directed graph

5. Description of the relationship between vertices

1.Path

2.Circuit

3. Simple path

4. Simple loop

5. Path length

6. Distance from point to point

7. Connected

6. Sub-picture

1.Definition

2.Illustration

7. Connected components

1. Connected components

2. Strongly connected components

8. Spanning tree

1. Spanning tree

2. Generate a forest

9. The rights of edges and the pictures/nets with rights

1. The right of the edge

2. Authorized pictures/nets

3. Weighted path length

4.Illustration

10. Several special forms of pictures

1. Undirected complete graph

 2. Directed complete graph

 3. Sparse graphs and dense graphs

4.Tree

Attached are test points for regular exams 



 1. Definition of graph

1. Graph G consists of vertex set V and edge set E composed of G=(V,E), where V(G) represents the finite non-empty set of vertices in graph G; E (G) represents the set of relationships (edges) between vertices in graph G.

2. IfV=\left \{ v_{1},v_{2},...,v_{n} \right \}, then use |V| to represent the number of vertices in the graph G, also called the order of the graph G;

3.E=\left \{ (u,v)| u\in V,v\in V \right \}, use |E| to represent the number of edges in graph G;

4. The linear list can be an empty list, and the tree can be an empty tree, but the graph cannot be an empty graph, that is, V must be a non-empty set, but E can be an empty set, as follows:


2. Undirected graph and directed graph

1. Undirected graph

        If E is a finite set of undirected edges (edges for short), then the graph G is an undirected graph. An edge is an unordered pair of vertices, denoted as (v,w) or (w,v), because(v,w)=(w,v), where v and w are vertices. It can be said that vertex w and vertex v are adjacent points to each other, and edge (v, w) is attached to vertices w and v, or edge (v, w) is associated with vertices v and w. As shown below:

G_{2}=(V_{2},E_{2})

V_{2}=\left \{ A,B,C,D,E \right \}

E_{2}=\left \{ (A,B),(B,D),(B,E),(C,D),(C,E),(D,E) \right \}

2. Directed graph

        If E is a finite set of directed edges (also called arcs), then the graph G is a directed graph. An arc is an ordered pair of vertices, denoted as <v,w>, where v and w are vertices, v is called the tail of the arc, and w is called the head of the arc, <v,w> is called the arc from vertex v to vertex w. It is also called v adjoining w, or w adjoining v. <v,w>\neq <w,v>, as shown below:

G_{1}=(V_{1},E_{1})

V_{1}=\left \{ A,B,C,D,E \right \}

E_{1}=\left \{ <A,B>,<A,C>,<A,D>,<A,E>,<B,A>,<B,C>,<B,E>,<C,D> \right \}


3. Simple graphs and multiple graphs

1. Simple diagram:

(1) There are no duplicate edges;

(2) There is no edge from the vertex to itself;

(3)Main research department;

 2.Multiple pictures:

(1) There is more than one edge between two nodes in graph G, and the vertices are allowed to be associated with themselves through the same edge, then G is a multigraph;


4. Degree, in-degree, out-degree of vertex

1. Degree of undirected graph

(1) Forundirected graph, the degree of vertex v refers to the number of edges attached to the vertex, denoted by isTD(v);

(2) In an undirected graph with n vertices and e edges, the sum of the degrees of all vertices is equal to twice the number of edges, that is:

\sum_{i=1}^{n}TD(v_{i})=2e

2. Degree, in-degree and out-degree of directed graph

(1)对于directional image对言,

        In-degree is the number of directed edges ending with vertex v, recorded asID(v);

        Out-degree is the number of directed edges starting from vertex v, recorded asOD(v);

(2) The degree of vertex v is equal to the sum of its in-degree and out-degree, that is,TD(v)=ID(v)+OD(v) ;

(3) In a directed graph with n vertices and e edges, the sum of in-degrees and out-degrees of all vertices are equal and equal to the number of edges, that is:

\sum_{i=1}^{n}ID(v_{i})=\sum_{i=1}^{n}OD(v_{i})=e


5. Description of the relationship between vertices

1.Path

        A path from one vertex to another vertex refers to a sequence of vertices. There is no limit to the path direction of an undirected graph, but the path direction of a directed graph can only be consistent with the direction of the arc;

2.Circuit

        The path in which the first vertex and the last vertex are the same is called a loop or loop;

3. Simple path

        In the path sequence, a path whose vertices do not appear repeatedly is called a simple path;

4. Simple loop

        A loop in which the vertices do not appear repeatedly except for the first vertex and the last vertex are called simple loops;

5. Path length

        The number of edges in the path;

6. Distance from point to point

        If the shortest path from vertex u to vertex v exists, the length of this path is called the distance from u to v; if there is no path from u to v at all, then the distance is recorded as infinity (∞);

7. Connected

a>connected;

        (2)Directed graph, if there are paths from vertex v to vertex w and from vertex w to vertex v , then the two vertices are said to be strongly connected;

        (3) If any two vertices in undirected graphG are connected, then the graph G is called Connected graph, otherwise it is calledDisconnected graph;

        (4) If any pair of vertices in the directed graph is strongly connected, then the graph is called Strongly connected graph;

(5) For an undirected graph G with n vertices, if G is a connected graph, there will be at least n-1 edges; if G is a non-connected graph, there may be at most C_{n-1}^{2}\textrm{}edge;

(6) For a directed graph G with n vertices, if G is a strongly connected graph, there will be at least n edges (forming a cycle);


6. Sub-picture

1.Definition

(1) There are two graphs G=(V,E) and G'=(V',E'), if V' is a subset of V, and E' is a subset of E, then G' is said to be a subgraph of G;To put it bluntly, it is to extract a part from the original picture, but this part must be called the upper picture. ;

(2) If there is a subgraph G' that satisfies V(G')=V(G), it is called a generated subgraph of G; To put it bluntly, all the vertices are picked out, and the edges are arbitrary;

2.Illustration


7. Connected components

1. Connected components

(1)The maximal connected subgraph in the undirected graph is called the connected component< /span>;

(2)The subgraph must be connected and contain as many vertices and edges as possible;

(3) Illustration:

2. Strongly connected components

(1)The maximal strongly connected subgraph in the directed graph is called the directed graphStrongly connected component;

(2)The subgraph must be strongly connected while retaining as many edges as possible;

(3) Illustration:


8. Spanning tree

1. Spanning tree

(1)The spanning tree of a connected graph is a minimal connected subgraph that contains all the vertices in the graph;

(2) There should be as few edges as possible, but they should be connected;

(3) If the number of vertices in the graph is n, its spanning tree contains n-1 edges. For a spanning tree, if one of its edges is cut off, it will become a non-connected graph, and if an edge is added, it will form a cycle;

(4)Illustration:

2. Generate a forest

(1) Innon-connected graph, the spanning tree of connected components constitutes the spanning forest of the non-connected graph;

(2) Illustration:


9. The rights of edges and the pictures/nets with rights

1. The right of the edge

        In a graph, each edge can be marked with a value with a certain meaning, which is called the weight of the edge;

2. Authorized pictures/nets

        A graph with weighted edges is called a weighted graph or network;

3. Weighted path length

        When the graph is a weighted graph, the sum of the weights of all edges on a path is called the weighted path length of the path;

4.Illustration


10. Several special forms of pictures

1. Undirected complete graph

(1) Definition: There is an edge between any two vertices;

(2)边数应为C_{n}^{2}

(3) If the number of vertices of the undirected graph |V|=n, then|E|\in [0,C_{n}^{2}]=[0,\frac{n(n-1)}{2}];

(4)Illustration:

 2. Directed complete graph

(1) Definition: There are two arcs in opposite directions between any two vertices;

(2)边数应为2C_{n}^{2}

(3) If the number of vertices of the directed graph |V|=n, then|E|\in [0,2C_{n}^{2}]=[0,n(n-1)];

(4)Illustration:

 3. Sparse graphs and dense graphs

(1) Sparse graph: a graph with a small number of edges;

(2) Dense graph: a graph with many edges;

(3) There is no absolute limit. Generally speaking, when |E|<|V|log|V|, G can be regarded as a sparse graph;

4.Tree

(1) An undirected graph that does not exist and is connected;

(2) A tree with n vertices, must have n-1 edges;

(3) A graph with n vertices,If |E|>n-1, there must be a cycle;

(4) Directed tree: a directed graph in which the in-degree of one vertex is 0 and the in-degree of the other vertices is 1;

(5)Illustration:


Attached are test points for regular exams 

Guess you like

Origin blog.csdn.net/weixin_64084604/article/details/128305355