The homework problem that I am a bit confused on is as follows:
Suppose that an n-node undirected graph G = (V, E) contains two nodes s and t such that the distance between s and t is strictly greater than n/2. Show that there must exist some node u, not equal to either s or t, such that deleting v from G destroys all s-t paths. (In other words, the graph obtained from G by deleting v contains no path from s to t.) Give an algorithm with running time O(m + n) to find such a node v
I am having trouble with a problem that I have been working on for practice and found a supposed solution using the below algorithm.
Set Discovered[s] = true and Discovered[v] = false for all other v
Let L be a queue and initialize with s.
i = 0
distance = 0
While i < n
For each node u ∈ L
Consider each pair of nodes (u,v)
If Discovered[v] = false then
Set Discovered[v] = true
Add v to queue at next position (position k+1)
Distance = distance + 1
End if
End for
End while
If n/2 >= distance >= (n+1)/2
There must be a node v that deleting (along with all incident edges) would result in all paths between s and t to be disconnected
End if
I know that this is a variation of Breadth first search which makes sense as the BFS will start at node s and explore in level traversal of the graph until it reaches the level with node v and then s. My confusion is in how the above algorithm can determine that because of the inequality in the last if statement means that there is certainly a node v that when deleted will disconnect all paths between s and t. If someone can clarify this or explain a better explained algorithm for this situation it would be greatly appreciated. On a side note I thought that the inequality in itself should be the other way around considering n/2 will always be less than (n+1)/2.
Aucun commentaire:
Enregistrer un commentaire