How a shortest path problem with negative cost cycles can be polynomially reduced to the Hamiltonian cycle problem to demonstrate NP-completeness - algorithm

I know that if there are negative cost cycles in a graph, the relative shortest path problem belongs to the np-complete class. I need to prove this by performing a polynomial reduction using the Hamiltonian cycle problem. Could anyone explain it? It would be very helpful.

Related

Is Shortest Hamiltonian path NP-hard?

Hamiltonian Path is a path that connects all nodes without repeat and it is an NP-complete problem.
Is the Shortest Hamiltonian Path (SHP) NP-hard?
What is the difference between travelling salesman problem with SHP?
I assume the SHP problem is the Hamiltonian problem on the edge weighted graph. It is NP-hard because it is at least as hard as the Hamiltonian problem. Assume you have an algorithm to solve the SHP problem, then you apply the algorithm on a weighted graph with all edge weights are 1, it will solve the Hamiltonian problem with the same time complexity.
TSP requires to return to the original vertex and you can visit each vertex more one once. SHP asks for the path which visits every vertex exactly once.

Can I use Dijkstra's algorithm for longest path in directed cyclic graph?

I have weights from 0 - 10. 0 is the shortest, 10 is longest.
Can I traverse the numbers, 10-x and use Dijkstra for shortest path?
In general finding longest path is NP.
In contrast to the shortest path problem, which can be solved in
polynomial time in graphs without negative-weight cycles, the longest
path problem is NP-hard, meaning that it cannot be solved in
polynomial time for arbitrary graphs unless P = NP.
https://en.wikipedia.org/wiki/Longest_path_problem
No. A cyclic graph will have paths of infinite length, and Dijkstra's marking of visited nodes will not allow you to find long paths.
Generally, finding the longest path kind of feels like a very hard problem.

NP-Complete and some decision problems on graph?

We know about NP-Complete and NP-Hard, and NP Class. I want to conclude some tips on following problem, that take from 2008 Mid exam on MIT.
Decision Version of which of the following problem for a connected undirected weighted graph G is NP-Complete?
a) finding maximal matching.
b) finding maximum Hamiltonian cycle
c) finding maximum Eulelrian cycle
d) finding maximum cut
How can categorized these problem in a simple manner for me? i.e. NP or NP-Complete or NP-Hard.
There are poly-time algorithms for computing maximal matchings (e.g., greedy; Edmonds's Blossom algorithm computes a maximum matching in poly-time) and Eulerian cycles. The decision versions trivially belong to NP (P, in fact).
Hamilton cycle and max cut are well-known NP-hard problems. The decision versions are in NP so thus are NP-complete.

Why cannot we turn longest path into shortest graph?

Today I read on Introduction to Algorithms of the longest path problem, which asked in a weighted, directed graph what is the longest simple path passing two vertices. The author used a wonderful example showing that dynamic programming fails for the longest path problem because there does not exist a nice optimal structure that always comes with an optimal substructure. It was commented that this problem is actually NP-complete. So it must be really hard.
Now here is my question: Instead of assign every edge a positive weight k>0, what if we simply assign negative weights to each edge with weight-k? Then each "longest path" would automatically be the shortest path, and if there is no loops in the shortest path by definition, there should not be any loops in the corresponding longest path. Hence using a quite common trick we "can" turn the longest path problem into the shortest path problem.
Can someone point out my mistake in the reasoning? I figure something must be wrong but do not really know what it is. It is extremely unlikely my argument is correct, for obvious reasons. Reading the pseudo code provided in the book, it seems the algorithm for shortest path does not prohibit using negative weights, and after all everything can be "elevated" by adding a large enough constant to make them positive. I am a beginner in algorithms so this question might be trivial to experts.
The mistake in your reasoning is this line:
if there is no loops in the shortest path by definition, there should not be any loops in the corresponding longest path.
If you have a graph where all edges have negative weight (which can happen in the transformation you're describing) and there's a negative cycle, then there is no shortest path between any two nodes on that cycle, since any path between them can have its cost reduced by following the cycle more and more times. Since there is no shortest path in that case, your reasoning breaks down.
Now, you can argue that you should instead look for the shortest simple path between the nodes (that is, a path with no duplicated edges). Unfortunately, though, that problem is also NP-hard, so this reduction doesn't actually buy you anything.
Hope this helps!
if there is no loops in the shortest path by definition, there should
not be any loops in the corresponding longest path
...and so that particular original problem is solvable in polynomial time. And if the particular original problem is a DAG then this method solves it in linear time.
The complexity statement doesn't say that all graphs are that hard to solve, just that some are.
From your own link:
In contrast to the shortest path problem, which can be solved in
polynomial time in graphs without negative-weight cycles, the longest
path problem is NP-hard, meaning that it cannot be solved in
polynomial time for arbitrary graphs unless P = NP.
[...]
For most graphs, this transformation is not useful because it creates
cycles of negative length in −G. But if G is a directed acyclic graph,
then no negative cycles can be created, and longest paths in G can be
found in linear time by applying a linear time algorithm for shortest
paths in −G, which is also a directed acyclic graph.

How to get Single Source Shortest Path for graphs having a negative weight cycle

Hey i have been studying the bellman ford algorithm for "single source shortest path" problems.
Now i am stuck at one point where i need to find out the solution for a graph having negative weight cycle.
But Bellman ford algorithm does not work here.
Can some one suggest me what to do. How to solve a problem having negative weight cycle?
Thanks for your time.
If there is a negative cycle which is reachable from the origin, which Bellman-Ford can detect, then you have two choices: either allow repeating edges, or do not. If you allow repeating edges, your shortest path could be considered to be infinitely negative. Otherwise, if you do not, the problem is NP complete. From Wikipedia:
One NP-Complete variant of the shortest-path problem asks for the shortest path in G (containing a negative cycle) such that no edge is repeated.
In a paper here discussed here the authors (Wulff-Nilson, Nanongki, Berstein) mention that a graph with negative-weight cycles can be reduced to one without such cycles and then they give a method that finds the shortest path in nearly linear time.

Resources