graphtheoryproofnplongest-path

Example of longest path problem having a NP complexity?


I saw on the internet that finding the longest path problem is NP-Complete problem.

For some reason, my teacher tells me that it isn't an NP-complete problem. So now I am looking for an example that shows the amount of computation needed for getting the longest path is bigger then polynomial time.

for now, I saw only examples of it having a polynomial complexity time.

anyone can bring me a proof for this problem being NP-complete?


Solution

  • For starters, depending on how you phrase the longest path problem, it may actually be the case that the problem is NP-hard but not NP-complete. The NP-complete version of this problem is the following:

    Given a graph G and a length k, does G have a simple path of length k or more?

    This problem is known to be NP-complete for reasons I'll detail later on. However, this closely-related problem is not actually NP complete:

    Given a graph G, what is the longest simple path in G?

    This second problem is NP-hard but not NP-complete. For a problem to be NP-complete, the problem has to be a decision problem, a problem whose answer is a boolean "yes" or "no." This second version of the problem, however, isn't a decision problem, and so it can't be in NP, and so it can't be NP-complete. It's entirely possible that your teacher was thinking about this when saying that the longest path problem isn't NP-complete, though I can't say for certain.

    As for why the longest path problem is NP-complete, we need to argue two points:

    1. This problem is in NP. Intuitively, there's an efficient way to check yes answers to the problem.

    2. This problem is NP-hard. That is, there's an NP-hard problem that reduces to it.

    For point (1), the intuition is that if the answer to the question "does this graph have a simple path of length 137 or more?" is "yes," there's some easy way to demonstrate this to someone. Just give them that simple path. Once they have the path, it's easy for them to check that, indeed, it meets the requirements. (Now, finding that path might be really hard. But once we've somehow isolated it, it's not hard to convince people that it works.)

    For point (2), the general way to do this is to start with an existing NP-hard problem and to reduce it to our problem. Here, we'll start with the Hamiltonian path problem, which is the following:

    Given a graph G, is there a simple path that passes through every node in G once and exactly once?

    Here's how we reduce that problem to the longest path problem. Start with the graph G. Now, ask the question: does G have a simple path of length at least n - 1, where n is the number of nodes in G? If so, then that simple path has to visit every node once and exactly once, since otherwise there aren't enough nodes in the path to make its length at least n - 1. And conversely, if not, then there's no Hamiltonian path, since any Hamiltonian path would fit the bill. Therefore, if we can solve the longest path problem efficiently, we can solve the Hamiltonian path problem efficiently. Since the Hamiltonian path problem is NP-hard, so is the longest path problem.

    Now, the fact that this problem is NP-complete doesn't mean that there is no polynomial-time solution for it. The P versus NP problem still hasn't been resolved, and without knowing whether P = NP or PNP we can't say whether there's a polynomial-time algorithm for the longest path problem. What we can say is that no known algorithms for it run in polynomial time (you mentioned some sites claim they have polynomial-time algorithms for this problem, but that doesn't sound right; if so, whoever found that algorithm would be a millionaire).

    Now, there's a follow-up question you can ask: why is the Hamiltonian path problem NP-hard? The usual way to prove this is to start with 3SAT and to do a clever, gadget-based reduction. That's way too long to explore here, but most intro theory textbooks (including Sipser's famous one) do a great job of explaining this.