1,211 views

1 Answer

Best answer
1 votes
1 votes

The longest path problem is the problem to find the longest simple path between pair of vertices. 

A path is simple if vertices are not repeated in the path , otherwise the path length can be ifinite.

And the longest path problem is NP hard problem cannot be solved in polynomial, but for directed acyclic graph , 

it can be solved.

Link :  http://www.geeksforgeeks.org/find-longest-path-directed-acyclic-graph/ 

If you can't understand the above algorithm then feel free to ask your queries.

And  one more method for DAG   is to convert all weight of edges to negative and then apply Bellman-Ford  algorithm ( But works only when there are no negative weight cycle present )   but graph is directed acyclic we can use Bellman-Ford .

For other type of graph like undirected, we can use dynamic programming approach with recursion like DFS/BFS

Everytime we just update the node ajacent to the current node only when the current_cost_on_node + edge-weight is greater then the oldest cost on adjacent node,  then so on... till the recursion end.

But it will work only in case of no cycle and graph is not so big , because its complexity is little much high. 

selected by

Related questions

1 votes
1 votes
2 answers
2
saptarshiDey asked Feb 1, 2019
857 views
What will be the path from A-H if BFS is used in the following graph?
0 votes
0 votes
0 answers
3
Vaishnavi01 asked Nov 19, 2018
302 views