Algorithms

Optimal substructure

When the best solution to a problem is built from the best solutions to its subproblems.

Example

The cheapest path to stair 5 comes from the cheapest to stair 4 or to stair 3, plus the cost of stair 5.

Test yourself: Optimal substructure

When DP works

With costs 1, 10 and 1 on stairs 1, 2 and 3, the cheapest way to reach 3 costs ___.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.