HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Unique path in a directed graph

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
uniquepathdirectedgraph

Problem

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?

Solution

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.

Context

StackExchange Computer Science Q#4711, answer score: 9

Revisions (0)

No revisions yet.