Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph longest path

Tags:

graph

How can I find the longest path in a graph? I thought I can use depth first search but I couldn't find any easier implementation for it ?

like image 663
iva123 Avatar asked Aug 23 '26 19:08

iva123


2 Answers

As brainjam pointed out in the comments this is NP complete. it is only polynomial if the graph is acyclic. if its a DAG its even linear. again see the wikipage for more info.

like image 99
Karussell Avatar answered Aug 26 '26 23:08

Karussell


try using topological sort for directed graph. it is meant specifically for the purpose of task scheduling...

http://en.wikipedia.org/wiki/Topological_sorting

like image 32
Shivendra Avatar answered Aug 26 '26 22:08

Shivendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!