longest-path

Computational complexity of a longest path algorithm witn a recursive method

蹲街弑〆低调 提交于 2019-12-01 05:51:11
I wrote a code segment to determine the longest path in a graph. Following is the code. But I don't know how to get the computational complexity in it because of the recursive method in the middle. Since finding the longest path is an NP complete problem I assume it's something like O(n!) or O(2^n) , but how can I actually determine it? public static int longestPath(int A) { int k; int dist2=0; int max=0; visited[A] = true; for (k = 1; k <= V; ++k) { if(!visited[k]){ dist2= length[A][k]+longestPath(k); if(dist2>max){ max=dist2; } } } visited[A]=false; return(max); } Your recurrence relation is

How to find the longest simple path in a graph?

丶灬走出姿态 提交于 2019-12-01 05:49:20
问题 I know that for non-directed graph this problem is NP-complete hence we should do Brute Force in order to check all possible paths. How we can do that? Please suggest a pseudo code and tell me the complexity of that algorithm. If there are optimizations, then that would be awesome! 回答1: A naïvem approach could run through all possible vertex permutations. For every permutation {v1, ..., vN} you check if you can get from v1 to v2 , then from v2 to v3 etc. If you can, add corresponding edge

Computational complexity of a longest path algorithm witn a recursive method

末鹿安然 提交于 2019-12-01 04:00:32
问题 I wrote a code segment to determine the longest path in a graph. Following is the code. But I don't know how to get the computational complexity in it because of the recursive method in the middle. Since finding the longest path is an NP complete problem I assume it's something like O(n!) or O(2^n) , but how can I actually determine it? public static int longestPath(int A) { int k; int dist2=0; int max=0; visited[A] = true; for (k = 1; k <= V; ++k) { if(!visited[k]){ dist2= length[A][k]

How do find the longest path in a cyclic Graph between two nodes?

时间秒杀一切 提交于 2019-11-30 07:27:40
问题 I already solved most the questions posted here, all but the longest path one. I've read the Wikipedia article about longest paths and it seems any easy problem if the graph was acyclic, which mine is not. How do I solve the problem then? Brute force, by checking all possible paths? How do I even begin to do that? I know it's going to take A LOT on a Graph with ~18000. But I just want to develop it anyway, cause it's required for the project and I'll just test it and show it to the instructor

Dijkstra for longest path in a DAG

倖福魔咒の 提交于 2019-11-27 16:11:58
问题 I am trying to find out if it is possible to use Dijkstra's algorithm to find the longest path in a directed acyclic path. I know that it is not possible to find the longest path with Dijkstra in a general graph, because of negative cost cycles. But it should work in a DAG, I think. Through Google I found a lot of conflicting sources. Some say it works in a dag and some say it does not work, but I didn't find a proof or a counter example. Can someone point me to a proof or a counter example?