Skip to content

Add Dynamic Programming on DAG (Kahn's Algorithm) with test cases#1313

Merged
williamfiset merged 3 commits intowilliamfiset:masterfrom
sujalxverma:add-dag-dp
Apr 1, 2026
Merged

Add Dynamic Programming on DAG (Kahn's Algorithm) with test cases#1313
williamfiset merged 3 commits intowilliamfiset:masterfrom
sujalxverma:add-dag-dp

Conversation

@sujalxverma
Copy link
Copy Markdown
Contributor

This PR adds an implementation of dynamic programming on directed acyclic graphs (DAGs)
using topological sorting (Kahn's algorithm).

The implementation demonstrates how to compute values in a DAG using a DP formulation
where transitions follow a topological order.

Included:

  • Kahn-based topological sort
  • Example DP: counting number of ways from a source
  • Unit tests covering:
    • Standard DAG
    • Disconnected graph
    • Cycle detection

Time complexity: O(V + E)

Comment thread src/main/java/com/williamfiset/algorithms/dp/DagDynamicProgramming.java Outdated
Comment thread src/main/java/com/williamfiset/algorithms/dp/DagDynamicProgramming.java Outdated
@williamfiset williamfiset merged commit 3d3a885 into williamfiset:master Apr 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants