[Math] Algorithm to find max no. of nodes that can be visited

algorithmsgraph theory

Given an undirected non-weighted graph edges.
'1#2', '2#3', '1#11', '3#11', '4#11', '4#5', '5#6', '5#7', '6#7', '4#12', '8#12', '9#12', '8#10', '9#10', '8#9'
where for example node 1 and node 2 is having a direct edge

now the question is, which algorithm can be used to find the maximum no. of nodes that can be visited (starting from any node), visiting a node atmost once and no traversing back by any edge

Best Answer

Your problem is the Longest path problem and is known to be NP-hard.

Hence there is no known polynomial time algorithm to answer your problem, and unless P=NP there are no such algorithm.

So to answer your question you may as well enumerate all the possible path visiting at most once each vertex and find the longest.

Related Question