Skip to content
StackDecode
Dynamic programmingExplained

DP on Graphs

Run DP over a DAG in topological order.

Time

O(V + E)

Extra space

O(V)

Use it for

Longest paths, counting routes.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.