C # data structure and algorithm secrets 10

Source: Internet
Author: User

In this article, we will discuss graph-related knowledge.

I. What is the structure of a graph? The so-called graph is a graph-like structure for short. It is another non-linear structure that is more complex than a tree structure. The nodes in the tree structure are one-to-many relationships with obvious hierarchy and branch relationships between nodes. The nodes at each layer can be related to multiple nodes at the next layer, but they can only be related to one node at the previous layer. Vertices in a graph (the data elements in the graph are called vertices) are many-to-many relationships, that is, the relationships between vertices are arbitrary, and any two vertices in the graph may be related. That is to say, there is no obvious hierarchical relationship between the vertices of the graph. This relationship exists in a large number in the real world. Therefore, graphs are widely used in natural sciences, social sciences, humanities, and other fields. Such as search engines and maps. :

A graph is a set of vertex and edges or arcs that describe the relationship between vertices. Its formal definition is as follows:
G = (V, E)
V = {Vi | Vi ε a set of data elements}
E = {(Vi, vj) | Vi, VJ ε v ∧ P (Vi, vj)} Or e = {<VI, VJ> | Vi, vjε v ∧ P (Vi, vj )}
G indicates the graph, V indicates the vertex set, and E indicates the edge or arc set. In set E, P (Vi, vj) indicates that vertex VI and vertex vj are connected by edges or arcs. The figure shows an example of a computer diagram.

In, V = {a, B, c, d, e}
E = {(A, B), (B, E), (E, C), (c, d), (D, )}

 

The following is an introduction to some graph terms.

1. undirected graph: in a graph, if any of the two vertex VI and vj constitute an even pair (a, B) ε E, that is, the link between the vertex has no direction, this graph is called an undirected graph ). :

 

2. Directed Graph: in a graph, if any two vertex I and j constitute an even pair <I, j> ε E (I, j ε (a-z), it is ordered, that is, the line between vertices has a direction. This graph is called a directed graph ). Is a directed graph.

3. edges, arcs, arc headers, and arc tails: The line between two vertices in an undirected graph is called an edge. The edges are represented by an unordered even pair (I, j) of the vertex, vertex I and vertex J are called adjacency points, and (I, j) edge is attached to vertex I and vertex J. The line between two vertices in a directed graph is called an arc. An arc is represented by an ordered pair of vertex <I, j>, the first node I of the ordered even pair is called the start point (or the end of the arc), and one end without an arrow in the figure. The second node J of the ordered even pair is called the end point (or the arc header ), the end with an arrow in the figure. :

4. undirected full graph: In an undirected graph, if any two vertices are connected by edges, this graph is called an undirected full graph (undirected complete graph ). It can be proved that N (n-1)/two edges exist in an undirected complete graph containing n vertices.

5. Directed full graph: In a directed graph, if any two vertices are connected by an arc, this graph is called a directed full graph (directed complete graph ). It can be proved that there are N (n-1) arcs in a directed complete graph containing n vertices. :

6. vertex degree, inbound and outbound degree: In an undirected graph, vertex v degree (degree) refers to the number of edges attached to vertex v, which is usually recorded as TD (V ). In a directed graph, the vertex degree is equal to the sum of the vertex's inbound (in degree) and vertex's outbound degree. The input degree of vertex v refers to the number of arcs with the vertex v as the arc header, which is recorded as ID (v); the output degree of vertex v (out degree) refers to the number of arcs ending with the vertex v, which is counted as OD (V ). Therefore, the degree TD (v) = ID (v) + OD (V) of vertex v ).

 

7. Weight and network: some edges (or arcs) of graphs are attached with some data information. These data information is called the weight of edges (or arcs ). In practice, a permission can indicate a meaning. For example, in a local traffic map, the weight on the edge indicates the length or level of the line. In a project progress chart, the arc weight can represent the time or other costs required for the previous project to the next project. A weighted graph on an edge (or an arc) is called a network ). Is an example with a weight chart

8. subgraphs: There are two graphs: G1 = (V1, E1), G2 = (V2, E2). If V1 is a subset of V2, V1 is also a subset of E2, the figure G1 is a subgraph of G2 ). Is an example of a subgraph.

9. Path and path length: In undirected graph G, if a vertex sequence VP, vi1, vi2,… exists ,..., Vim, VQ, making (VP, vi1), (vi1, vi2 ),..., (Vim, VQ) all belong to E (G ). There is a path between the vertex VP and VQ ). If G is a directed graph, the path is also directed. It consists of the arc <vp, vi1>, <vi1, vi2> ,..., <Vim, VQ>. The path length is defined as the number of top paths or arcs. In, there are four paths from vertex A to vertex B, with the lengths of 10, 100, and 120, respectively. In Figure 6.2, there are two paths from vertex A to vertex F, with two and three lengths respectively.

 

10. Simple path, loop, and simple loop: If a vertex in a path does not appear repeatedly, it is called a simple path ). The path of the first vertex and the last vertex is called a loop or a ring. A loop in which the first vertex and the last vertex are the same and the other vertices are not repeated is called a simple cycle or a simple loop. :

11. Connectivity, connectivity graph, and connectivity component: In an undirected graph, if two vertices have paths, these two vertices are connected ). If any two vertices in an undirected graph G are connected, graph G is called a connected graph ). The connected component (connected compenent) is an undirected graph G:

12. Strongly Connected Graph and strongly connected component: In a directed graph, if any two vertices in the graph have a path from one vertex to another, the directed graph is a strongly connected graph ). A very strong connected subgraph of a directed graph is called a strongly connected component ). A strongly connected subgraph is a strongly connected subgraph of a directed graph. This subgraph is not a subgraph of other strongly connected subgraphs of the graph. Figure A is a strongly connected graph, and Figure B is an example of a strongly connected component.

Spanning Tree: the so-called graph G spanning tree (Spanning Tree) refers to a very small connected subgraph of G that contains all its vertices. A very small connected subgraph refers to a subgraph that contains all vertices and ensures connection.
Include the smallest edge in the source image. The generation tree of a connected graph G with n vertices has n-1 edges. If one edge is missing, it is not a connected graph. If one edge is more than one, it must have a ring. However, there are n-1
An edge graph is not necessarily a spanning tree. Is a generated tree of the graph.

The above is my introduction to the graphic structure. The next article introduces the source code implementation of the graphic structure. Heheh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.