views:

243

answers:

3

Hi,

I'm designing an algorithm for class that will determine if a graph is unique with respect to a vertex v such that for any u <> v there is at most one path from v to u. I've started by using BFS to find the shortest path from v to another vertex u, and then running BFS again to see if an alternate path can be found from v to u. I think this is too time consuming however. Does anyone have any hints as to how the solution can be found with a shorter execution time?

thanks

+1  A: 

Look at the Max Flow Min Cut algorithm.

Charlie Martin
+3  A: 

Use BFS to work backwards from v, flagging each vertex as 'visited' as you go. If you ever hit a vertex you've previously visited, your graph doesn't have the uniqueness property. Otherwise, it does.

Gwildore
+1  A: 

It's a simple modification of any graph traversal: if you find an edge to a previously marked node, then you have multiple paths.

comingstorm