










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to dynamic programming and the knapsack problem. It explains the concept of memoization and provides code examples for both recursive and bottom-up approaches. The document also covers variations of the knapsack problem, including the unbounded knapsack and the bounded knapsack. Additionally, it discusses the subset sum problem and provides code examples for finding the minimum difference between subsets. suitable for students studying computer science or related fields.
Typology: Schemes and Mind Maps
1 / 18
This page cannot be seen from the preview
Don't miss anything!
Date......***
Dynamic0unmina
Page.. ******************
once.d (^) Ketunsíon
hen apbly DP-
Choices i) phma (2 on mone)
Newstant qfoluing (^) Dp_p10blarna (^) dimctl
y makng table U(Gahn- Uh Manner
Ho (^) tg (^) tant (^) Wilin (^) QP (^) Code
hesi K ppnaachz
Memoiz aHon
Bottom-Dp_(9abulahon
O: Kaapsack
i)nbaunded Knalosack-
di 9ibonacci
LCS
(y 1L
i DP eh anid
ate..********** Page.********. Knap Sock_ Paoblan
Knalp.sa.ck (^) a kindobag^
hich
maxinum
0e ha
to qstong^ ha^
items
no
ohnapsath
hnapsack
nachona
O
Unbouncded.
,
Iaa gneody^ pnoblen^ in^
udhich, p^ nee.d
QSono aMaMumvallsaeighf^ into
Can (^) g$torn
anHemb Cuhn
O11 Knapsack
Tn tho bnoblom e
e.ithe nc lud! an ikom_into hL
bag Jst_exclude it
Uabounded E4 ane 0a 011 butL
hau n
i) ban^ Condihon^
înbut
hapablemit will^ he^
when "oe.
anna
i
he
Choice Diag nom
pn on^ element^ tem
Val
wok
Wtiiw ttis
in he
hdo ChoiceS abo
left Subtn 11 bpO
GnSLen
Tt ConL (^) be snimh nht ubte
Page.. ****************
Hecuive Coda
atKnap sack (^) Cint
ot 1,at valta, (^) nt (^) w, (^) intn) tefit )
ifn= o 1| W=0ne kwn 0,
if wt[h-11< W)
else ifat [n-1 )W
etun Kaaksackwt,val, W,n:1)
Date...************ Pa ragea*nseee**************
abulaion Code. (Bottom Dp Codle :
hebaaic iclea Behind abuleHon e
1Cuaive Calls _fhat Ae_hanl
oSeenin he Memoitation techniauo inle
ternah onm
abulaion_can be pn sonmed to Hhe plowina
hoo steps
Tnitializahion
boical hse
in itenahue one.
an
y0Cunaiàn
ntdh [n1i1[wt1,
iiq lisation
Hon int i=0.ien+1 itt)
fonintjz0,<w41,jt)
dp CiC{) 0
7Ttenative Veròn
ton (int^ izL^ kn+1^ itt
Ewt i114 Wj)
dpilLEmadpLAIj-wtL-1tvel li,
el5dp £13C] dpri-1Ejat
Netunn dCnItW
Date.******* Page...*** g
Intnoducion evision e knagbsackad
A
voniaions unhn_pnoblor
iO
Tdoni
a (^) a
problemin dh^ cap
DePnluedwin Knapsack_
e e haug
Whn e^ gee^
a_lonn hene
Capacty and
ha
aßaciyaith opmal^ banti
noblem
an itema hat
Vlls unden Knapsack.
hapben that
1athonhen
oimeime his
towtL1 ovalc^
hon 22
h yaluo
anc conaicton nglecE oeiht
Lzample.
athnn)-
ono aCon.stnain^
aA W
alu MOne hat
Choices
that we_cnE taKe
Ow anS
Date..**********Page..*.
ThihalisaHon
a1ags11e dOmmorpn^
d_Surn i^ O
possible le^ ei^
bun_
always
essible empp^
ubse
Hes it
dum gntaken^
hai 0
it
bossibleto
AetSn?
NO.
DO e^ 9ot^ Oun^
initialisaton
dpCat11T Sumt1),
on int i =0; i<htl;_itt)
foninlj0,j4 Sumt|JH)
f (i=z0) dprillil
Liy Main^ Colo^
wEr
W Sun
int ax^
nof 0/P
oubiC Vaniq hon
Date.. ***** ****** Page.
ernofunchonin (^) bolesn O Le usl ) onuiton
dpti3t (^) =(dÞtiJ Li- (^) anm[i-13] (^) dpti-11Cj
else
dpriir (^) dpL1:19 i
han
Desak anso
Mekutn elp[n1LSuml
Egua (^) unanhihian
Problern
G en an atauy Can0e_onnHhon i in e
to qubseb Such^ hat
lemont and u itin hifhaae_
qubs.ek e i ak ecual sun in heul
9u h 6e6.
Op Tiue^ nce^ S,
Op alse
Date.... Page....
hool (^) Eual (^) Sun Panlnl anL1, înt nintsu
i
MetounSubset Sun int annLI,intnint 5un
roblem
ind lun ftad^ ho:
an_passf hle.
man (^) oub.Ses inon
X bi
10
Eplaakon S5 2,
Pagt*********
2ilarity
wih pubset^
oSun (^) i
noubsetoumnobem^
1 ny^
ne
outu Aubsef^
o un
possible 1 not
But
home_,in thio^ roblom^
de
alse (^) niecl
Couni0 the ubset
Tashaisaion
for int i0 iknrlÍtt
son[int jznjkSmtj
dpi1j
MainCede
fo11Li:11 )Su dpriCj1-dpti
else dp1cj1: deri-11rj-amti-11] tdli
Cun
bo
p1oued
eaailSince,
Sum ann
out the diftenc
Coun
giuenlann-S)-8, dift
"
di ounlana-2x51H
int lh[nt
11LSum^
t41,
4onlint izD10t11, it
pindj-0,jK[untiJt
iffiszo d6rirj1=nlsa
ifljz-o
dpri gI=tnul
fonint i2^ Kht^
tt
onintj j{Suntljt)
ifannfi-11 < Sum
dpi11j1dpt:21j-dnoLi-13]dpli-
else
Dat*******************| Page...
fon (^) inki Sum 2 iz0,i
xi
bneak
Aetunn dif
nlon
aien anainaoncidifleninca betoe.en fhe
0Subset Sum CAuNt
Subsek ilh Tha dtewnce
Ex
1/P o1,4,2,
Explan ahioniL2nd3 L22nd
71ands