Tarjan algorithm: The cutting point and the bridge (cutting edge) of the solution graph

Source: Internet
Author: User
Tags dashed line

Introduction :

The definition of trimming and cutting points is limited to the non-direction diagram. We can solve all the cut and cut edges of the non-direction graph by the definition of brute force, but the method is inefficient. Tarjan presents a quick solution to solve all the cutting and cutting edges in the graph through a Dfs.

Welcome to discuss, if there are errors please correct me

If you want to reprint, please specify the source http://www.cnblogs.com/nullzx/

1. Definition of cutting point and bridge (cutting edge)

The definition of cutting edge and cutting point in the non-direction diagram

cut point : An undirected connected graph, removing a vertex and all the edges adjacent to it, the number of connected components in the graph increases, the vertex is called the cut point.

Bridge (cut Edge): undirected unicom diagram, remove an edge, the number of connected components in the graph increases, then this edge, called the bridge or cut edge.

the relationship between the cutting point and the bridge (cutting edge) :

1) There is not necessarily a cut point bridge, there must be a bridge cut point

2) The bridge must be the edge of the attachment.

The middle vertex c is a cut point, but the edges connected to C are not bridges.

2. Violent solutions to solve cut point sets and cut edge sets

The principle of brute force law is to solve cutting points and cutting edges by definition. Remove a vertex from the diagram and then perform a DFS traversal, and if the connected component increases, the vertex is a cut point. If you remove an edge from the diagram and then perform a DFS traversal, if the connected component increases, the edge is cut edge. Once each vertex or edge is done, you can find all the cut and cut edges of the graph, which we call the cut-point set of the graph and the cut-edge set.

In a specific code implementation, it is not necessary to actually delete the vertex and delete all edges that are attached to the vertex. For the cut point, we only need to set the vertex to ture for the access before DFS, and then Dfs from the other vertices for the root. For trimming, we only need to prohibit Dfs from this side, if the Unicom component increases, then this edge is cut edge.

3. Principles of the Tarjan algorithm

Judging whether a vertex is a cut point in addition to the definition, you can also start from the perspective of DFS (depth-first traversal). We first define two concepts through DFS.

Assuming that we have access to vertex v from vertex u in DFS (at which point V has not been accessed), we call vertex u the parent vertex of Vertex V, and V is the child vertex of U. The vertex you visited before vertex u is called the ancestor vertex of U.

Obviously if all the child vertices of the vertex u can access the ancestor vertices of u without the parent vertex u, then it is clear that the vertex u is not affected by the connectivity of the graph, and U is not a cut point. Conversely, if vertex u has at least one child vertex, you must pass the parent vertex u to access the ancestor vertex of u, then when you remove the vertex u, the ancestor vertex of vertex u and the child vertex are disconnected, indicating U is a cut point.

The arrows in indicate the order of DFS access (rather than the undirected graph), and for Vertex D, the child vertex of D can go back to the ancestor vertex C of D by the 1 red edge of the connected area (C has been visited at this time), so D is not a cut point at this point.

The vertex in the connected Region 2 in, must pass D to access to the ancestor vertex of D, so that at this point D is a cut point. Again, the arrows represent only the order in which the DFS is accessed, not the graph that is a forward graph.

Here we also need to consider a special case, that is, the root vertex of Dfs (typically a vertex numbered 0), because the root vertex does not have an ancestor vertex. In fact, the root vertex is not cut point is also very good judgment, if starting from the root vertex, a Dfs can access all the vertices, then the root vertex is not a cut point. Conversely, if you go back to the root vertex and have an unreachable vertex, you need to do DFS again on the adjacency vertex, which is the cut point.

4. Implementation details of the Tarjan algorithm

On the implementation of the Tarjan algorithm, we need to define an additional three arrays in DFS (depth-first traversal) dfn[],low[],parent[]

1 The subscript of the DFN array represents the number of vertices, the values in the array indicate the order in which the vertices are traversed in DFS (or timestamps), and each access to an unreachable vertex, the value of the Access order (timestamp) increases by 1. the DFN value of a child vertex must be larger than the DFN value of the parent vertex (but not necessarily 1, such as when the parent vertex has two and more than two branches). After accessing a vertex, the value of its DFN is determined and no more changes are made.

2 The subscript of the low array represents the number of the vertex, and the value in the array represents the smallest sequential value (or timestamp) in the ancestor vertex that the vertex in DFS does not have access to from the parent vertex.

The initial low value of each vertex should be the same as the DFN value, and in DFS we keep updating the value of low as appropriate.

Assume that the vertex u accesses to the vertex v. When you trace from vertex v to vertex u,

If

DFN[V] < Low[u]

So

Low[u] = Dfn[v]

If the vertex u also has branches, and each branch is backtracking, the vertex low[u] represents the earliest ancestor node that is accessible from the parent node of the vertex U.

Now let's look at an example where the simulation program calculates the DFN value and the low value of each vertex. A solid blue arrow indicates a path that has been visited, and a dashed line with no arrows indicates an unreachable path. The vertices that have been visited are marked with yellow, the vertices that are not visited are marked with white, and the vertices currently being processed by DFS are represented in green. A blue dashed line with arrows indicates the return path when DFS is backtracking.

When Dfs goes to vertex h, there are three branches, we assume we go first h-i, then go h-f, and finally go h-j. When I was accessed from H, vertex I was not visited, so I dfn and low were 9. Based on the traversal order of DFS, we should continue to access from vertex i.

Indicates that vertex d is accessed by vertex I, at which point D has been accessed, and when it is traced from D to I,

DFN[D] < Dfn[i]

Indicates that D is the ancestor vertex of I, so until now, vertex I has not been able to access the small timestamp 4 by the parent vertex H.

Tarjan algorithm: The cutting point and the bridge (cutting edge) of the solution graph

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.