I recently solved a problem of the longest path by using BFS twice. I also learned that dynamic programming can be used to solve the longest path in a directed acyclic graph. What would the pseudocode and recursion equation/runtime be for finding the longest path in an undirected weighted tree given a random node using dynamic programming?
Asked
Active
Viewed 198 times
0
-
What does "longest path" have to do with "given a random node" ? How does that random node matters ? – รยקคгรђשค Nov 06 '20 at 08:21
-
@รยקคгรђשค it means that given any node in the tree, how do you find the longest path within a tree using dynamic programming? – wildcat12 Nov 06 '20 at 10:34
-
My point was longest path may or may not pass through given node. Do you want the longest path passing through a given node? Giving a concrete example might help everyone to understand the question clearly. – รยקคгรђשค Nov 06 '20 at 18:03