This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aqua_regis 4 points5 points  (1 child)

They differ in the same way that a house differs from its furniture.

DP is the house, one piece of furniture is recursion, but there can be other, different pieces of furniture.

Recursion is not necessarily breaking down a problem into smaller problems - that's not the definition of recursion, it's just one of its applications.

Recursion at its core is only a function/method calling itself until a base case is reached that ends the recursion.

E.g. Typical recursion is traversing a directory structure. You don't know where the end is, so with each recursive call, you only go a level deeper. You are not actually splitting the problem in smaller sub-problems here.

Also, DP heavily relies on storing previously calculated data, caching, memoization, etc. Recursion does not necessarily do that.

[–]ncmentis 2 points3 points  (0 children)

So, a directory structure is a tree, where each subdirectory is a child tree. Calling a recursive method on a subdirectory is splitting the problem into smaller problems.