Sign up ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

I'm designing an algorithm for a class that will determine if a directed graph is unique with respect to a vertex $v$ such that for any $u \ne v$ there is at most one path from $v$ to $u$. I've started by using BFS (breadth-first search) 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?

share|cite|improve this question

migrated from Sep 24 '12 at 13:49

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 8 down vote accepted

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.

share|cite|improve this answer

Look at the Max Flow Min Cut algorithm.

share|cite|improve this answer

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

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.