





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






CMPS 214 Problem Set 6
Above, discover means the time that the algorithm rst reaches the vertex. [We are expecting: A drawing of your two graphs and an ordered list of vertices discovered by BFS and DFS for each of them.]
A
B
C D
Both DFS and BFS visit the vertices in rst graph in the following order: A, B, C, D. DFS and BFS visit the vertices in the second graph in dierent orders: DFS: A, B, C, D BFS: A, B, D, C
D
Given the above graph G and the assumption that subsequent DFS calls visit the vertices in alphabetical order the following would happen: The rst DFS call would traverse A, B. The second DFS call would traverse only C, since B is already visited. Finally the third DFS call would visit only D, since C is already visited. The resultant DFS forest can be seen below:
D
Algorithm 1 exactTraversalExists(G) 1: Compute a topological order T on G 2: for i = 0 to n 2 do 3: if Edge (T [i]; T [i + 1]) does not exists then 4: return false 5: end if 6: end for 7: return true
This algorithm clearly runs in O(m + n)-time since the for loop runs in O(n) and since computing a topological order on a DAG takes O(m+n) using the topological sorting algorithm you've seen class.
So using the above proof we can construct a O(m + n) algorithm to solve the problem. Simply pick an arbitrary vertex u and apply BFS/DFS and keep track of the distances between the discovered vertices and u. Once BFS/DFS is complete simply nd the farthest vertex v from u, if there are multiple pick one arbitrarily and delete it. Vertex v represents the guest that when uninvited maintains that the fun party property, or in other words, maintains that the graph is still connected since it is not a cut vertex.
There is a way to transport fuel from any node in the graph to any other node in the graph. Your algorithm should run in O(n + m). [We are expecting: A description of the algorithm, a brief explanation of why the algorithm works and an informal justication of the algorithm's running time.] First compute the meta-graph G^0 = (V 0 ; E^0 ) of the directed graph G = (V; E) which runs in O(n + m) (recall the meta-graph of a directed is the graph of its SCCs). If jV 0 j = 1 then all of G is strongly connected and the fuel distribution system has a way to transport fuel from any node to any node to any other node so we return true, otherwise this is not the case and return false. (b) Design an algorithm that veries if the fuel distribution system has the following property: No single pipe failure can isolate any node from either distributing fuel to the rest of the system or consuming fuel from the rest of the system. That is, removing a single edge cannot cause any node to be unreachable from any other node. Your algorithm should run in O(mn + m^2 )). You may assume an algorithm that satises the property in part (a) exists and use it directly.