2

The proof is needed:

Finding all possible simple path in an undirected graph is NP hard/ NP complete. The graph may contain multiple edges between same pair of nodes, and loops.

I have searched over, got some idea or discussion. But I need a direct proof/link stating the complexity is NPC/ NP-Hard.

2 Answers2

2

Problems of the form "find all objects of some type" aren't NP-complete, because NP consists purely of decision problems, questions that have a yes/no answer. So this problem can't be NP-complete.

If you specifically have to list the paths in descending order of size, then the problem would be NP-hard. If you can list all paths in descending size order, then you can just check the first path to see if it passes through all nodes. If so, great! Your graph has a Hamiltonian path, and finding Hamiltonian paths is NP-hard.

On the other hand, if you listed the paths in ascending order of length, then assuming you're working with Turing machines the cost of simply reading all the paths to get to the last one would take more than polynomial time, so this reduction wouldn't work. A similar argument shows that this reduction won't work if the paths come back in arbitrary order. I suspect, but am not fully sure, that it's unknown whether that version of the problem is NP-hard, but I'm open to being corrected on that.

This is all the more interesting given that the number of simple paths in a graph can be O(n!), which happens when the graph is a complete graph (all pairs of nodes are linked by edges). The fact that something takes a long time to complete doesn’t immediately mean that it’s NP-hard or NP-complete.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • can the longest path problem (finding path length at least k) be used somehow? What if I use k=1 to |V|-1, for a given graph G(V,E)? does it prove this problem to be NP-hard? – Shuvra Chakraborty Jun 29 '20 at 16:35
  • If you’re allowed to restrict the lengths of the paths that come back so that they’re always of length |V|-1, then yes, you’d have NP-hardness. But that’s a different question than the one you mentioned earlier. – templatetypedef Jun 29 '20 at 17:23
  • Sorry if I was wrong in my question. Since I meant simple path, that restricts its length from 1 to |V|-1, right? – Shuvra Chakraborty Jun 29 '20 at 20:51
  • It does, but if you don’t have any guarantees about the order in which those paths would be reported to you, you may end up spending most of your time simply looking over the paths reported and seeing if any have length |V|-1. – templatetypedef Jun 29 '20 at 21:14
1

The complexity of this problem appears to be O(n!) which is worse than the O(2^n) of the NP-Hard / NP-Complete series. Additionally, this is not NP-Hard / NP-Complete because it isn't even in NP.
Requirement for NP:
"A problem is called NP (nondeterministic polynomial) if its solution can be guessed and verified in polynomial time"[1]
Your problem is not in NP, since checking your solution has a complexity of O(n!) just like calculating your results, because in an (n-1)-Simplex (fully interconnected graph with n vertices)[2] the solution of all possible simple paths will be for(i = {1 to n}){sum(n!/(n-i)!)} + 1 for the empty set paths (please look at templatetypedef's comment[3] for proof), which is O(n!) and more specifically does not fall into polynomial time solution. Example
In the image above[4] you have an example of a 3 simplex.
Full enumeration will consist of for(i = {1 to 4}){sum(4!/(4-i)!)}+1 = (4!÷3!)+(4!÷2!)+(4!÷1!)+(4!÷0!)+1 = 65 paths:

{}

{A}
{A->B}
{A->B->C}
{A->B->D}
{A->B->C->D}
{A->B->D->C}
{A->C}
{A->C->B}
{A->C->D}
{A->C->B->D}
{A->C->D->B}
{A->D}
{A->D->B}
{A->D->C}
{A->D->B->C}
{A->D->C->B}

{B}
{B->A}
{B->A->C}
{B->A->D}
{B->A->C->D}
{B->A->D->C}
{B->C}
{B->C->A}
{B->C->D}
{B->C->A->D}
{B->C->D->A}
{B->D}
{B->D->A}
{B->D->C}
{B->D->A->C}
{B->D->C->A}

{C}
{C->B}
{C->B->A}
{C->B->D}
{C->B->A->D}
{C->B->D->A}
{C->A}
{C->A->B}
{C->A->D}
{C->A->B->D}
{C->A->D->B}
{C->D}
{C->D->B}
{C->D->A}
{C->D->B->A}
{C->D->A->B}

{D}
{D->B}
{D->B->C}
{D->B->A}
{D->B->C->A}
{D->B->A->C}
{D->C}
{D->C->B}
{D->C->A}
{D->C->B->A}
{D->C->A->B}
{D->A}
{D->A->B}
{D->A->C}
{D->A->B->C}
{D->A->C->B}

Hope this helps and good luck with solving this problem.

Aleksandr
  • 96
  • 7
  • Can you elaborate on how the complexity is O(2^n)? In a complete graph there can be at least n! paths. – templatetypedef Jun 29 '20 at 15:23
  • 1
    More specifically - it’s not that the remaining paths are ones of the form “doesn’t contain A,” but rather they’re paths that don’t start with A. A can appear in those other paths, just not at the front. This increases the number of paths beyond what you’ve listed. – templatetypedef Jun 29 '20 at 15:49
  • @templatetypedef you are right, on the doesn't start with A comment ... modifying it now. – Aleksandr Jun 29 '20 at 19:12
  • 1
    Are you sure that’s the right formula? There are n paths of length zero, n(n-1) of length one, n(n-1)(n-2) of length two, ..., and n! of length n-1. Rewriting, that’s n = n! / (n-1)! paths of length zero, n(n-1) = n!/(n-2)! paths of length one, n(n-1)(n-2) = n!/(n-3)! paths of length two, ..., and n! = n! / 1! paths of length n-1. Summing gives n! / 1! + n! / 2! + n! / 3! + ... + n! / (n-1)! = n!(1/1! + 1/2! + ... + 1/(n-1)!), which is approximately e * n!. – templatetypedef Jun 29 '20 at 21:13