First explain the conceptual question:
Joint point: If you delete a vertex in an undirected graph, and a vertex-related edge, a connected component of the graph becomes more than two connected components. Such vertices are called joint points .
undirected graphs without joint points are called re- connected graphs . Any two vertices in a re-connected graph have at least two or more paths.
If you delete the K nodes on the connected graph to disrupt his connectivity, then the connectivity graph is K.
the following algorithm is to find the joint point of the graph , and do not consider the joint point of the map, but it is not difficult to change the joint point of the graph, just add a For i = 0,... g.vernum can be.
To find the joints, there are two ways I know:
1. Definition method: Delete the node of the connected graph, then the depth first traverse the connected graph to see if the connected graph is connected. Assuming n vertices, e edges, and time complexity O (n * (n+e))
2. Depth-first traversal of the connected graph according to the two characteristics of the joint point. Time complexity O (n+e)
Of course the second method is better.
Two characteristics of joint points are given in the book.
The following code is written entirely in terms of these two characteristics.
The following code is given:
The Findarticul function determines the number of child nodes in the depth-first spanning tree of the connected graph according to the first characteristic, if more than 2, the root node must be the joint point.
The diagram must be a connected graph. void Findarticul (graph g) {int Visited[max_vertex_num] = {0};//The order of access nodes int count = 1;visited[0] = count;//Set the root section Point has been visited. printf ("The joint point of the graph is:");//Find out if the root node has a second subtree. Arcnode * Firstarc = G.list[0].head->nextarc;dfsarticul (g,firstarc->adjvex,&count,visited);//Now Count = root node (1) + first subtree (all nodes) if (Count < G.vexnum) {///root node has a second subtree, continue to traverse the remaining subtree, otherwise the function exits//prints the root joint point printf ("%c", g.list[0].vexname);// Traversing the remaining subtree Arcnode * next = Firstarc->nextarc;while (next! = NULL) {/////root node's adjacency node may have accessed an int v = next->adjvex;if (visited [v] = = 0) {dfsarticul (g,v,&count,visited);}}} printf ("\ n");}
The Dfsarticul function determines whether node V is a joint point according to the characteristics.
Look for joint points. Low (v) = min (Visited (v), Low (W), visited (k)), W is the child node of K, K is the ancestor of V back side. Condition: Low (W) >= visited (v), at which point V is the joint, W and its descendants have no back side pointing to the V ancestor.//function return value low (v) int dfsarticul (Graph g,int v,int * Count,int * VI sited) {int min = Visited[v] = + + (*count);//set access order//slightly different from book, Head->nextarc is the first edge of v vertex arcnode * next = g.list[v].head- >nextarc;for (; next! = NULL; next = next->nextarc) {int w = next->adjvex;if (visited[w] = = 0) {//not accessed int low = DFS Articul (g,w,count,visited), if (Min > Low) {min = low;} if (Low >= visited[v]) {//w subtree without back edge printf ("%c", G.list[v].vexname);}} else if (min > Visited[w]) {//accessed, W is the ancestor node of the v node. min = Visited[w];}} return min;}
Find the joint point of the above connected graph G5, as follows:
Full code project File Web address: Click to open link
Look at the data structure write code (43) Joint point