Let your graph be G=(V,E)
. Create a subset of U
of V
such that U = { u | there is a path from u to the target }
U = { u | there is a path from u to the target }
.
- Note that finding this subset of
U
easy and can be done linearly using DFS or BFS at the back edges of the target.
Using this subset, create a graph G'=(U,E')
, where U
defined above, and E' = E [intersection] UxU
[These edges, but apply only to vertices in U
].
Run a randomized (choosing which vertex to explore next randomly) DFS on G'
, until you reach the goal.
- Note. The idea is to find a path - not necessarily a simple one, and therefore you should not support the
visited
set. - You can add the “break” rule, which, if you reach a certain depth, you will look for a goal - non-randomized, to avoid endless cycles in circles.
- Perofrmance is expected to be different, as it is linear in the length of the path found, which can be very long or very short ...
source share