You are not logged in. Please login at to post your questions!


Can anyone suggest me how can i find longest chain of nodes ?

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

shubh_coder's gravatar image

accept rate: 0%

edited 14 Apr '15, 09:48

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

retrograd's gravatar image

accept rate: 12%

edited 30 Jun '15, 01:55

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 14 Apr '15, 09:47

question was seen: 3,679 times

last updated: 30 Jun '15, 01:55