Chapter 2: basic graph algorithms

Source: Internet
Author: User

For answers to the exercises in this chapter, refer:Https://sites.google.com/site/algorithmssolution/home/c22


I. Concepts of Graphs

Graph category:

  Indicates whether a ring exists. Whether there is a duplicate edge Directed edge?
Simple undirected graph (simple undirected graph) × × ×
Multigraph) × ×
Pseudo Graph) ×
Simple directed graph (simple directed graph) × ×
Directed multigraph)
Mixed graph (hybrid graph) Undirected and undirected edge coexistence

Infinite Graph: A graph with infinite vertices.Finite Graph: A graph with a finite vertex.Multiedge: Duplicate edge.Isolated Vertex: A point with a degree of 0.Pendant Vertex: The point with a degree of 1.Pendant edge: Link the edges of two hanging points.Full graph (kN): An edge exists between any two points.Complement of Graph): It has the same vertex as G, but if a side exists in the supplementary graph, the graph does not.Note:1. Small images use commonly used adjacent matrices. 2. Generally, graph algorithms use an adjacent table. 3. The storage space of the adjacent table is O (V + E ). 4. The storage space of the adjacent matrix is O (V ^ 2 ). 5. For an undirected graph, if the adjacent matrix is used for storage, only the parts of the main diagonal line and above the main diagonal line can be stored, saving General space. 6. The directed edge is represented by (u, v), and the undirected edge is represented by {u, v. 7. For a weighted graph, the list of adjacent tables indicates that a weight can be added to each node of the List, and the list of adjacent matrices can be replaced by weights at the position of cells. 8. In an undirected graph, a ring has two degrees. 9. sum (DEG (V) = 2E in an undirected graph, so the sum of degrees must be an even number. If the sum of given degree sequences is an odd number, it is certainly not an undirected graph. 10. sum (deg-(v) = sum (deg + (V) = | E | in a directed graph. Note that if A is connected to B, C, and D, the order of A's adjacent tables may be D, C, and B, it may also be C, D, or B. The following is the concept of a tree, which is used when DFS and BFS generate a depth-priority tree and a breadth-priority tree:V's ancestor: Including the true ancestor of V and V. V'sTrue ancestor: If U (excluding v) exists, so that there is a path between U and V, then u is the true ancestor of v. V'sDescendant: Including the true descendants of V and V. V'sAuthentic descendant: If U (excluding v) exists, so that there is a path between V and U, then u is the true descendant of v.Strongly Connected Graph: Any two vertex u, v, u to V and V to u have paths.Weak Connected Graph: This graph is a directed graph. It is not a strongly connected graph. However, if a directed edge is converted into a undirected edge and the graph is connected, this graph is a weak connected graph.Bipartite Graph(Bipartite Graph): If a vertex set of a graph can be divided into two non-Intersecting subsets V1 and V2, each edge is connected by a vertex in V1 and a vertex in V2.Full Bipartite Graph: After a point set is divided into two subsets, each subset extracts any vertex, and each vertex has an edge.Coloring Theorem: If a graph is a binary graph and only one of the red and blue colors is assigned to each vertex in the graph, the two vertices without one edge are of the same color. The coloring theorem can be implemented through BFs, that is, the vertex with an odd distance is colored in blue, the vertex with an even number is colored in red, and O (V + E) is required after coloring ), then, traverse each edge and check whether the color is correct, O (V + E ). Theorem: a graph is a bipartite graph. If it is not possible to start from a vertex, it returns to the starting point after an odd number of edges.Cut Point: If a vertex is removed and the number of connected branches increases, This vertex is a cut vertex.Edge Cutting(BRIDGE): If an edge is removed and the number of connected branches increases, this edge is a cut edge.Euler Loop: You can find a simple loop that traverses each edge once in the graph (note that it is a simple loop );Euler's path: You can find a simple path that traverses each edge once in the graph. In an undirected graph, there is an Euler loop in the graph. if and only when the degree of each vertex is an even number, in the directed graph, there is an Euler loop in the graph, and only when the degree of output of each vertex in the graph is the same as that of the inbound vertex. In an undirected graph, there is an Euler path in the graph. When there are only two vertices in the graph, the degree is odd; in a directed graph, there is an Euler's path. If there are only two vertices in the graph, there is an odd difference in the inbound degree of exit;Hamilton Loop: A simple loop that can traverse each vertex can be found in the figure;Hamilton path: You can find a simple path that can traverse each vertex once in the graph;Connected Branch: A set of connected points. For example, {a, B, c} is a connected branch of the graph. In an undirected graph, determine whether a loop exists: | E |> | v |-1 and connected graph, there must be a loop. Determine whether a loop exists in a directed graph: DFS has a reverse edge.Ii. BFSPurpose: (1) traverse a graph. (2) Calculate the shortest path on the premise that the weight of each edge of the graph is 1. Note: (1) any side (u, v), d [v] <= d [u] + 1; (2) in the queue, set the team header to U, the team end is V, d [v] <= d [u] + 1. The most important thing is that BFS can generate the Shortest Path Tree, however, not all shortest path trees can be generated through BFs. For example:

Iii. DFS

Tree edge: Edge in the depth priority tree.Forward edge: The edge from u to a non-direct descendant.Reverse Side: U to the side of the ancestor (including itself.Cross edge: The relationship between U and V is not the ancestor descendant. In an undirected graph, only the tree side and the reverse side are supported.Iv. topological sortingIf (u, v) exists, F [u]> F [v].
There are two ways to achieve topological sorting:(1) Sort DFS in descending order by F. (2) Delete a point with an inbound value of 0 each time.

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.