Can anyone suggest me how can i find longest chain of nodes in unweighted acyclic graph .It is also given that u can choose any node as a first node. asked 14 Apr '15, 09:47 ![]()
|
If the graph is a DAG, then the first idea that would come into my head is a DP with memoization: DP[v] -> the longest chain starting from vertex v. Then DP[v] = 1+max{DP[w], w in Adj(v)}. You can easily compute this with memoization Your answer is then max{DP[v]} for each vertex If the graph is undirected, then it is a forest of trees, and this is a whole different problem (diameter of a tree) answered 30 Jun '15, 01:54 ![]()
|