Graph Theory37 sections · 1633 units
Open in Course

Common Mistake - Initialization

Base case matters

A common mistake is initializing dp[source] = 0 instead of dp[source] = 1. If dp[1] = 0, then all subsequent updates stay at 00 because you are adding 00 to everything. For counting paths, dp[source] = 1 means there is one way to be at the starting point: you start there.

For shortest paths, dp[source] = 0 means the distance from the source to itself is 00. Always think about what the base case represents. The initialization must match the problem semantics.