Data structure-6.1 figure

Preface-Data Structure

The data structure needs to be chewed repeatedly, and the answers to the problems encountered in the development can be obtained at any time.

What is a graph

Definition of graph

  • A graph is a data structure composed of a set of vertices V and a set of relations between vertices E (a set of edges), which can be defined as a binary ancestor: G = (V,E)

  • The directed graph G1 can be described as: G1=(v1,E1), where v1={1,2,2,4}, E1={<1,2>,<1,2>,<2,4> <2,4>,<4,1>} (note the angle brackets)

  • The undirected graph G2 can be described as: G2=(v2,E2), where v2={1,2,2,4,5}, E2={(1,2),(1,4),(2, 2), (2, 5), (2, 4), (2, 5), (4, 5)} (note the parentheses)

Basic terms of graphs

  • Directed graph and undirected graph
  • In the figure, if the shoulders indicate that the edges are directional, the graph is called a directed graph, otherwise it is called an undirected graph
  • The number of edges of the complete graph
  • Undirected graph: 0 <= e <= n(n-1)
  • Directed graph: 0 <= e <= n(n-1) / 2
    Insert picture description here
  • Dense graph e (number of edges)> half of the number of complete edges
  • Sparse graph e (number of edges) <half of the number of complete edges

Degree in degree out degree

  • The degree of vertex v in an undirected graph: In an undirected graph, the degree of vertex v refers to the number of edges attached to the vertex, usually denoted as D(v).
  • The in-degree of a vertex: In a directed graph, the in-degree of a vertex v refers to the number of arcs with the vertex as the arc head, denoted as ID(v).
  • Out-degree of a vertex: In a directed graph, the out-degree of a vertex v refers to the number of arcs with the vertex as the arc tail, denoted as OD(v).
  • The degree of vertex v in a directed graph: In a directed graph, the degree of vertex v is defined as the sum of the in-degree and out-degree of the vertex, that is, D(v)=ID(v)+OD(v).

Connected graph and strongly connected graph

  • Connected graph (any two vertices have a path from v to u, referring to an undirected graph)
  • Strongly connected graph (any two vertices have a path from v to u, referring to a directed graph)
  • In the undirected graph G=(V, {E}), if there is a path from v to u for any two vertices v, u, then G is called a connected graph (strongly connected graph).
    Insert picture description here

network

  • The correlation number of the edge or arc in the graph is called the weight, which indicates the distance or cost from one vertex to another. Weighted graphs are called nets.

Subgraph

  • Given two graphs G= (V, {E}), G1= (V1, {E1}), V1⊆V, E1⊆E, then G1 is called a subgraph of G.
  • Example: (b), (c) are subgraphs of (a)
    Insert picture description here

note

  • When a connected graph of n vertices is represented by adjacency proof, the matrix has at least 2 (n-1) non-zero elements. Because at least the connected graph can be regarded as a tree, the tree e has at least n-1 edges, so the graph has 2 (n-1) non-zero elements.

Guess you like

Origin blog.csdn.net/weixin_41732253/article/details/109569410