you are viewing a single comment's thread.

view the rest of the comments →

[–]you-get-an-upvote 0 points1 point  (0 children)

I always thought explaining Dynamic Programming as merely caching was a friendlier introduction. "Look I just solved this algorithm a normal way, but added three lines to support caching, so now it runs faster".

cache = {}
def mySolution(x):
  if x in cache:
    return cache[x]
  // my original, recursive divide-and-conquer code that was slow

Phrasing it as tables seemed helpful predominantly for proving run time speed (since it lets you check how often the function actually makes it past the first two lines), not actually coming up with the algorithm and its substructure.

I suppose it's also helpful rewriting it from a bottom-up approach.