This article is from: svitter's blog and GitHub

Graph

*8/8/2014 9:23:16 AM*

Definition of a basic concept Graph

- A graph is a set of vertices.
**(Vertex)**And the set of links between vertices**(Edge)**A Data Structure:> graph = (V, E)

Directed Graph & undirected graph | (directed graph & oriented graph)

In a directed graph, vertex pairs are ordered.

In an undirected graph, vertex pairs (x, y) are unordered.

Full graph Complete Graph

- An undirected graph with n vertices has n (n-1)/two edges.
**Undirected full Graph**(Why ?) <! -- Except him, he can reach an edge with any vertex -->

- If a directed graph with n vertices has n (n-1) edges, this graph is
**Directed full Graph**(Why ?)

Adjacency Vertex)

- If (u, v) is an edge in E (G), the U and V are mutually independent.
**Adjacent Vertex**
- A directed edge exists between two vertices.
**Adjacent**

Subgraph

- There are two graphs, G = (V, E) and G' = (V ', e '). If V' ≤ v and e ≤ 'E, the graph G' is
**Subgraph**

Permission Weights

- The edges of some graphs have numbers related to them.
**Permission**. This weighted graph is called**Network**

Degrees of the vertices)

- The degree of a vertex V is the number of edges associated with it. As TD (V ).
- In a directed graph, the degree of the vertex is equal
**Inbound (in-degree)**And**Outbound (out-degree)**Sum
**Vertex v's inbound**Number of directed edges ending with V as ID (V)
**Output degree of vertex v**Records the number of directed edges starting with V as OD (V)

Path

- In Figure G = (V, E), if starting from vertex VI, some edges go through some vertex CIDR, CIDR ,..., Vpm, reaching the vertex VJ. It is called the vertex sequence (vi cidr Block... vpm vj) as the path from vertex VI to vertex VJ. The edges passing through (Vi, csv4), (csv4, csv4),..., and (VPM, vj) must belong to the edges of E. ### Path length
- The path length of a non-weighted graph refers to the number of entries above the path.
- The path length of the weighted graph refers to the sum of the weights of each edge on the path. ### Simple path

- If the vertices V1, V2,... and VMS in the path do not overlap, the path is called
**Simple path**### Loop
- If the first vertex V1 in the path overlaps with the VM of the last vertex, this path is called
**Loop or loop**

Connected Graph and connected component

- In an undirected graph, if
**Path**Vertices V1 and V2 ** are connected **.
- If any pair of vertices in the graph are connected, this graph is called
**Connected Graph**.
- The maximal connected subgraph of a non-connected graph is called
**Connected Component**.

Strongly Connected Graphs and strongly connected components

- In a directed graph, if each pair of vertices vi and vj have a path from VI to vj and from VJ to VI, this graph is called
**Strongly Connected Graph.**(Any two vertices can reach each other)
- The extremely large strongly connected subgraph of a non-strongly connected graph is called
**Strongly Connected Component**.

Spaning tree)

- The spanning tree of a connected graph is a very small connected subgraph with n-1 edges under N vertices.

The basic knowledge of the graph is here, and you can continue to look at it if necessary.

Special notes on point suspension points

- A vertex with a degree of 1 is a suspension vertex, And the edge associated with it is called a suspension edge.

Handshake Theorem

- The degrees of all vertices are equal to double the number of edges.
- In any vertex, the number of odd vertices is an even number (Why ?)

Europe

- A = path through which all edges in the graph have and only one row passes through all vertices.
**Euler's path**
- B = the loop through which all edges in the graph have and only one row passes through all vertices.
**Euler Loop**
- A & B is
**Europe**, &&~ B is**Semi-EU**

The undirected graph is Euclidean and only G is**Connected Graph**And no**Odd vertices**

- The proof is hard to explain, but I think about it very much. If there is an odd vertex, how can I come back?

Related Literature:*Seven bridges in gonis*

- Directed Graph G is semi-Euclidean. The condition is that G is connected and has exactly two odd vertices.
- A directed graph D is a condition of the European Union, that is, if and only if D is
**China Unicom**And each vertex's**Inbound = outbound**

Hamilton Graph

Empty chart

- An empty vertex set is defined
**Empty chart**

Isolated point

- Vertices without correlated edges are called
**Isolated point**

The Representation Method of the figure. Logical Structure of the C language adjacent matrix (adjacency matrix)

- In the adjacent matrix of a graph, there is a vertex table that records information about each vertex, and an adjacent matrix that represents the relationship between each vertex.
- Let figure A = (V, E) be a graph with n vertices. The adjacent matrix of the graph is a two-dimensional array A. Edge [N] [N], defined

Storage Structure

- The simplest form is to use a two-dimensional array for storage. Because it is too simple, it is not displayed here.

Logical Structure of the adjacent table

- An adjacent table is an improved form of the adjacent matrix. To this end, we need to organize the rows of the adjacent matrix into a single-chain table.
- In the adjacent table, edge links from the same vertex are in the same edge linked list. Each link node represents an edge (edge node ), the subscripts DEST and pointer link of another vertex in the node. For an edge graph, the cost value of the edge must be saved in the edge node.
- The vertex table stores the data of the vertex in vertex I and the header pointer of the edge linked list.
**What do you think?**

Storage Structure

- Use Vector or use new to open up new arrays.
- Code

# Include <iostream> # include <vector> # include <cstdio> using namespace STD; // If G is a tree // half of N is enough; # define maxn 1000 // n indicates the number of nodes typedef vector <int> Vint; vector <Vint> G (maxn); // use the clear () function for traversal, empty space void insert (int A, int I) {G [A]. push_back (I);} void DFS (INT v) {for (INT I = 0; I <G [v]. size (); I ++) DFS (G [v] [I]);} int main () {G. clear (); Return 0 ;}

The method of saving edges is similar to the zipper method in the hash table.

Struct arc {int next_arc; int point ;};# define maxn 1000 # define MaxE 1000int node [maxn]; ARC arc [E]; // starts with U, end int edgecount = 0; with V; void addedge (int u, int v) {arc [edgecount]. next_arc = node [u]; ARC [edgecount]. point = V; node [u] = edgecount; edgecount ++ ;}