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

find a path to visit every node in graph not necessarily once

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

Problem

I meet a problem but when I google, there are all Hamiltonian Path Problem: How to find a path to visit every node in directed graph(not necessarily once)?

This problem is different from Hamiltonian Path.

For example:

1 --> 2 -->  3 ↔ 4 
             ↕ 
             5


I have a path $1\rightarrow 2\rightarrow3\rightarrow4\rightarrow3\rightarrow5$ to visit all nodes in this graph, however this graph has no hamiltonian path.

My questions:

-
What's the terminology of this problem?

-
Is there algorithm or theorem to determine whether a general graph has such path? If a graph has such graph, how to find the detailed
path?

Thanks

Solution

You probably haven't found anything in your searches because this problem is fairly easy to solve, without needing any fancy methods.

If the graph is strongly connected, then it is easy. Let $s$ be the starting node. Pick any vertex $v$ you haven't visited yet, and append a path $s \leadsto v$ followed by some path $v \leadsto s$ (both must exist, since the graph is strongly connected). Repeat, appending to the end of the path, until every vertex has been visited.

If the graph isn't strongly connected, decompose it into a dag of scc's. Then you can reduce the problem to finding a path through this dag (within a scc, use the algorithm of the first paragraph). You can find a path to visit every node in a dag iff the dag is itself a path, i.e., it has the structure $v_1 \to v_2 \to \dots \to v_k$, and then it is trivial to write down this path.

This is not a Hamiltonian path, since it may visit the same vertex multiple times.

Context

StackExchange Computer Science Q#139327, answer score: 3

Revisions (0)

No revisions yet.