## Why can't we use Dijkstra's algorithm for longest path problem?

## What is Dykstra's projection algorithm?

- Not to be confused with Dykstra's projection
**algorithm**.**Dijkstra**'s**algorithm**to find the shortest**path**between a and b. It picks the unvisited vertex with the lowest distance, calculates the distance through it to each unvisited neighbor, and updates the neighbor's distance if smaller.

## How do you find the shortest and longest simple path?

- Notice that if -G has no negative cycles, finding the shortest simple
**path**is the same as finding the shortest**path**which can be solved in polynomial time using above algorithms. Finding the**longest**simple**path**in general is NP-Hard. This can easily be shown by reducing from the Hamiltonian Cycle problem.

## What is the difference between Dijkstra and Bellman Ford algorithm?

- Unlike Dijkstra's algorithm, the Bellman–Ford algorithm can be used on graphs with negative edge weights, as long as the graph contains no negative cycle reachable from the source vertex s. The presence of such cycles means there is no shortest path, since the total weight becomes lower each time the cycle is traversed.

Share this Post: