Dynamic Programming

Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems andstores the results of subproblems to avoid computing the same results again. Following are the two main properties of a problem thatsuggest that the given problem can be solved using Dynamic programming.


1) Overlapping Subproblems: Like Divide and Conquer, Dynamic Programming combines solutions to sub-problems. Dynamic Programming is mainly used when solutions of same subproblems are called again and again. In dynamic programming, computed solutions to subproblems are stored  so that these don’t have to be recomputed. There are following two different ways to store the values so that these values can be reused.

a) Memoization: The memoized program for a problem is similar to therecursive version with a small modification that itlooks into a lookup table before computing solutions. We initialize a lookup array with all initial values as NIL. Whenever we need solution to a subproblem, we first look into the lookup table. If the value wanted is there then we just return the value, otherwise we calculate the value and put the result inlookup table so that it can be reused later.

b) Tabulation: The tabulated program for a given problembuilds a table iteratively and returns the wanted entry from table.

Both tabulated and Memoized store the solutions of subproblems. In Memoized version, table is filled on demand while in tabulated version, it is filled iterativelyUnlike the tabulated version, all entries of the lookup table are not necessarily filled in memoized version. So how should us choose between Memoization and Tabulation?


2) Optimal Substructure: A given problems has Optimal Substructure Property if optimal solution of the given problem can be obtained by using optimal solutions of its subproblems.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI记忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值