YouTube2Text

4.5 0/1 Knapsack - Two Methods - Dynamic Programming — Transcript

by Abdul Bari · 4,447 words · 578 segments · language en · Watch on YouTube

Full transcript

  1. 0:00the problem is 01 Absa
  2. 0:02problem in this video I will explain
  3. 0:05what is 01 napsack problem and how it
  4. 0:09can be solved using dynamic programming
  5. 0:12we will understand its approach next I
  6. 0:15will show you a tabular method for
  7. 0:17solving this one then also I will show
  8. 0:20you a sets method for solving this one
  9. 0:23so there are two methods we will see
  10. 0:25both the methods first of all let us
  11. 0:27understand what the problem is
  12. 0:30here I have some four objects for each
  13. 0:33object there is some profit and there is
  14. 0:35some
  15. 0:36weight and there is a bag of capacity M
  16. 0:39that is 8 is
  17. 0:43given the objective is to fill this back
  18. 0:47with these objects so can I put them all
  19. 0:51see the capacity a is eight but the
  20. 0:54total weights of all these object is 14
  21. 0:57so all objects cannot be filled in the
  22. 0:59bag so I have to carry few of those some
  23. 1:01of those objects that is subset of those
  24. 1:03objects and I have to carry them and
  25. 1:05sell them at other place so once I sell
  26. 1:08I get this
  27. 1:09profit so I have to fill the object such
  28. 1:12that the total profit is
  29. 1:16maximized and I have to give the
  30. 1:18solution in the form of a set for each
  31. 1:21object like for example this is included
  32. 1:24and this is not included or not included
  33. 1:27like this I have to write down which one
  34. 1:28is included and not included so it means
  35. 1:31I can write down each XI either 0 or 1
  36. 1:35means the values can be 0 or 1 but not
  37. 1:38fraction so it means that the object
  38. 1:40that I'm going to carry are not
  39. 1:43divisible breakable so I cannot take the
  40. 1:47fraction of that object so this means
  41. 1:50these are some solid objects maybe a
  42. 1:52mixer or microwave1 or a router it can
  43. 1:56be something like this so which I cannot
  44. 1:59take a half of mixer in the bag so these
  45. 2:02are indivisible objects so either I
  46. 2:04should carry the whole object or don't
  47. 2:07carry it at all so I have to carry the
  48. 2:09object such that the sum of their
  49. 2:13profits should be
  50. 2:15maximized and some of
  51. 2:18their weights should be less than or
  52. 2:22equal to the capacity of the
  53. 2:24back now let us know the approach of
  54. 2:27dynamic programming for solving this one
  55. 2:29now few important things about dynamic
  56. 2:31programming dynamic programming is
  57. 2:32useful for solving optimization problem
  58. 2:35yes this demands maximum results so it's
  59. 2:37optimization problem second thing
  60. 2:41dynamic programming says that a problem
  61. 2:43should be solved in sequence of
  62. 2:45decisions so yes we can take the
  63. 2:47sequence of decisions for every object
  64. 2:49we can take shall I include or not
  65. 2:50include or not include or not so I can
  66. 2:53take decisions I can even start taking
  67. 2:55the decision from the last object also
  68. 2:57include or not include or so usually in
  69. 2:59this one we take the decision from last
  70. 3:01object towards first object so we can
  71. 3:04take sequence of decision next thing one
  72. 3:06more point that dynamic programming says
  73. 3:08that you should try all possible
  74. 3:10solutions and pick up the best one now
  75. 3:14how many possible solutions are there
  76. 3:16see when I'm writing the solution in the
  77. 3:18form of zeros and ones then it can be 0
  78. 3:210 0 means no object is included or 1 one
  79. 3:24one one means all objects are included
  80. 3:27or 0 0 0 1 means only fourth object is
  81. 3:30included or first object is
  82. 3:32included or first two objects are
  83. 3:34included like this there are many
  84. 3:36possible solutions and some of them may
  85. 3:38be feasible some may not be feasible
  86. 3:40like all objects I cannot include so
  87. 3:42anyway I should try all of them and pick
  88. 3:44up the best one so total how many
  89. 3:46solutions will be there so like four
  90. 3:49zeros and ones form if I continue so
  91. 3:51I'll be getting 2^ 4
  92. 3:54Solutions so I should try 2 power 4
  93. 3:56solution for n objects it will be 2
  94. 3:58power n solution
  95. 4:00so if I try out all then the time
  96. 4:02complexity will be 2^
  97. 4:04n this is too much time consuming so
  98. 4:08dynamic programming shows a easy method
  99. 4:10for doing the same thing we will not we
  100. 4:12will be indirectly trying all 2 power n
  101. 4:16right but not directly so we'll not
  102. 4:18spend that much time let us solve this
  103. 4:20problem using tabulation method
  104. 4:23tabulation method let us see how to fill
  105. 4:25this values and how to get the solution
  106. 4:28for this problem so for solving as the
  107. 4:31capacity of the bag is8 so I have taken
  108. 4:34the column so starting from 0 to
  109. 4:378 so this means that though the capacity
  110. 4:41is8 but we'll not consider that eight at
  111. 4:44once so we'll add weight one by one so
  112. 4:48starting from zero then let us assume
  113. 4:49weight is one weight is two and so on
  114. 4:52then rows four objects so I have taken
  115. 4:55five 0 1 2 3 4 so starting from zero so
  116. 4:58it means 1 by we will consider the
  117. 5:00object so initially we will not consider
  118. 5:02any object means we will not include any
  119. 5:04object in the bag so for filling this we
  120. 5:07have a formula so I'll show you formula
  121. 5:10after some time after filling some
  122. 5:12values so let us see first row as zero
  123. 5:16object no object is included then what
  124. 5:18will be the profit so in these boxes
  125. 5:19I'll be writing the profit so there is
  126. 5:21no profit gained when no object is
  127. 5:24included and even when the capacity of
  128. 5:27the bag is zero this are the this is the
  129. 5:29capacity these are the weights right and
  130. 5:31these are weights and the profits of the
  131. 5:33objects so these are the weights and
  132. 5:36there is zero weight is there then all
  133. 5:38these are 0 0
  134. 5:410
  135. 5:43next now we will start filling so for
  136. 5:45that I'll consider first object when I
  137. 5:48consider first object I'll take this row
  138. 5:50and I will ignore all other
  139. 5:52objects and similarly when I go to
  140. 5:55second row I'll ignore the remaining and
  141. 5:57I will take the second object as well as
  142. 6:00the first object I'll consider the first
  143. 6:02object also so it means whenever I am in
  144. 6:05I throw I will consider all the objects
  145. 6:08in the previous rows also so for the
  146. 6:11first row directly I can fill it let us
  147. 6:13see first row what is the weight of the
  148. 6:16first object two so it can be filled
  149. 6:19only when the bag capacity is two so
  150. 6:22here so what will be the profit one so
  151. 6:25fill one here then this means this is
  152. 6:28same value previous value usually we
  153. 6:31write previous value only if required
  154. 6:35then rest of the cells the capacity of
  155. 6:38the bag is increasing but how many
  156. 6:40objects I'm considering only one so I
  157. 6:42don't have anything more to fill in the
  158. 6:44bag so only that object I can fill and
  159. 6:46it will be getting profit as one one one
  160. 6:51only I'll fill the second row also right
  161. 6:55third row also in the same way then I
  162. 6:57will write down the formula let us go to
  163. 6:59second row I'm going to consider second
  164. 7:02object so as I said when I consider
  165. 7:04second object I should also include the
  166. 7:06first object so first let us look at the
  167. 7:09second object see the weight of the
  168. 7:11second object is three it can be filled
  169. 7:13in the bag only if the capacity is three
  170. 7:16so in this cell only it can be filled so
  171. 7:18what is the profit that I'll get two so
  172. 7:21put two here what about this side it
  173. 7:23will be same value same value as the
  174. 7:26previous rle then beyond this what
  175. 7:29should come here so as I said that when
  176. 7:32you are taking second object you should
  177. 7:34also consider first object so if I fill
  178. 7:37the second object also in the back total
  179. 7:39weight required is how much five so this
  180. 7:43is five and total profit will be three
  181. 7:46so both the objects can be filled when
  182. 7:48the capacity is five and the total
  183. 7:50profit will be three so here both of
  184. 7:53them can be
  185. 7:55filled right both of them I'm
  186. 7:57considering both of them so now I have
  187. 7:59have only two objects and this is giving
  188. 8:01for both the objects are filled so rest
  189. 8:03of the values will be 3 3 3 then what
  190. 8:06will be the value here so as this is two
  191. 8:08so this will also be two so I can take
  192. 8:11the previous value or this value
  193. 8:12whichever is maximum I can take the same
  194. 8:15thing now I will fill the third object
  195. 8:18also then for the fourth object I will
  196. 8:20show you the formula third object when I
  197. 8:23consider third object if you look at
  198. 8:25these the maximum weight is this one and
  199. 8:27as they are arranged in the increasing
  200. 8:29order of the weight so this is weight is
  201. 8:31four so this object can be filled in the
  202. 8:34bag only if the capacity of the bag is
  203. 8:36four so this will be included in the bag
  204. 8:40when the capacity is four so the total
  205. 8:41profit that you'll be getting is five so
  206. 8:44this is five then before that whatever
  207. 8:47the previous row values are so 2 1 and
  208. 8:51zero now Beyond this let us see see when
  209. 8:55I on the third object I should also
  210. 8:58consider first first and the second
  211. 9:00object
  212. 9:01also so if I just check them this is
  213. 9:04four and if I take these two objects it
  214. 9:08will be total six weight weight is six
  215. 9:10so these two objects I can fill if the
  216. 9:12weight is six right a if I want to fill
  217. 9:16these two then these two I can fill when
  218. 9:18the weight is
  219. 9:20seven this two I can fill if the weight
  220. 9:23is five and what will do the profit
  221. 9:25three this object itself is five right
  222. 9:29now I will consider these two six and
  223. 9:32the total weight will be six so at six
  224. 9:35it will be six only right and when I
  225. 9:38consider these two so total is seven
  226. 9:42seven and the profit is also seven so at
  227. 9:45seven the profit is seven can I include
  228. 9:48all three it will be 10 but the capacity
  229. 9:51of the bag is only eight so I cannot
  230. 9:53include all three then beyond this the
  231. 9:56value will be seven only and before this
  232. 9:58one the value will be same as this five
  233. 10:05five all right now I will show you the
  234. 10:08formula and I will fill fourth row with
  235. 10:10that formula the formula is like this if
  236. 10:14I call this table as V this table as V
  237. 10:17then V of I comma w i is the row number
  238. 10:21W is the column number is maximum
  239. 10:26of V of i- 1 that is from the previous
  240. 10:30row I should take same value means
  241. 10:32previous row value I should take this is
  242. 10:34the meaning or maximum of this one or
  243. 10:38what V of IUS 1 comma weight minus
  244. 10:43weight of an object
  245. 10:46wi plus profit of an object that you are
  246. 10:52considering now let us the follow the
  247. 10:54formula and fill all
  248. 10:57these first one 4A 1 I will fill 4A 1 so
  249. 11:02V of 4A 1 is maximum
  250. 11:07of V of 3A 1 like this is four so this
  251. 11:12will be three comma V of 3 comma weight
  252. 11:17is how much 1 minus weight of an object
  253. 11:21weight of an object is 5 1 - 5 plus
  254. 11:25profit of that object is six six
  255. 11:31now this becomes 3A
  256. 11:34-4 there is no such location so that
  257. 11:37value becomes undefined so only this
  258. 11:41value will be defined V of 3 comma 1
  259. 11:43will be defined so V of 3 comma 1 is
  260. 11:45what zero so I should take zero
  261. 11:48only there will not be any such index V
  262. 11:50of 3 comma -4 yes for that I have to
  263. 11:54take zero only so it means up to what
  264. 11:57I'll be getting negative numbers up to
  265. 11:59fifth weight up to fifth weight so till
  266. 12:02here I should fill these values as it is
  267. 12:06only so that's what I was saying that
  268. 12:09this can be considered or this can be
  269. 12:11considered in fourth so write on its
  270. 12:13value and all previous values as it is
  271. 12:16so the same thing here because there you
  272. 12:18will be getting negative so till fifth
  273. 12:21weight till fifth weight before that
  274. 12:23till before that I have filled as it is
  275. 12:25now this fifth way how to fill I will
  276. 12:28show you for this value 4A 5 V of 4A 5
  277. 12:35is maximum
  278. 12:37of V of 3 comma 5 comma V of 3 comma
  279. 12:45weight is how much five minus weight of
  280. 12:49this object is how much
  281. 12:51five plus profit of this object is how
  282. 12:54much 6 6 let us see V of 3 comma 5 3A 5
  283. 13:00is how much 5 comma V of 3A 5 - 1 5 - 5
  284. 13:060 V of 3 comma 0 3 comma 0 is 0 plus 6
  285. 13:12so which is greater 6 is greater so fill
  286. 13:15this value with six so that means this
  287. 13:18object is included
  288. 13:20here now 4A 6 I will find out V of 4A 6
  289. 13:26is maximum of V of 3A 6 comma V of 3
  290. 13:33comma weight is 6 right and the weight
  291. 13:36of the object is 5
  292. 13:38plus profit of the object is 6 so how
  293. 13:42much this is V of 3A 6 is how much 3A 6
  294. 13:46is 6 6 comma V of 3 comma 6 - 1 6 - 5
  295. 13:53that is 1 3A 1 3A 1 is how much 0 0 + 6
  296. 14:00so the answer is both are same only so
  297. 14:03take six
  298. 14:05only next value 4A 7 V of 4A 7 maximum
  299. 14:12of V of 3A 7 comma V of 3 comma weight
  300. 14:20is how much 7 so weight of the object is
  301. 14:235 7 - 5 plus profit is 6 so this is 3A 7
  302. 14:28is how much 7 comma this is V of 3A 7 -
  303. 14:335 is 2 3A 2 so 3A 2 is how much 1 + 6 so
  304. 14:39this is 1 + 6 so this is 7 only both I
  305. 14:43am getting s or 7 so they are same only
  306. 14:46take
  307. 14:47seven V of 4A 8 4A 8 is maximum
  308. 14:54of V of
  309. 15:003A 8 comma V of 3 comma weight is 8
  310. 15:05minus the weight of an object is 5 +
  311. 15:07profit is
  312. 15:096 3A 8 how much 3A 8 is 7 comma V of 3A
  313. 15:178 - 5 is 3 3 comma 3 how much 2 so this
  314. 15:21is 2 + 6 so how much this is this is
  315. 15:24seven and this is 8 so answer
  316. 15:27is8 so this is how the table is filled
  317. 15:30so I have used the formula for few cells
  318. 15:33in the last row and this can also be
  319. 15:36filled directly also without the formula
  320. 15:39let me show you how to fill this last
  321. 15:40row
  322. 15:42directly I am considering fourth object
  323. 15:45whose weight is five and the profit is
  324. 15:48six so in fifth column just write six
  325. 15:51it's profit and what to write on the
  326. 15:54cells before that same value as the
  327. 15:57previous row
  328. 15:59this what you do first then beyond this
  329. 16:04now the weight is five Beyond this the
  330. 16:06capacity of the bag is increasing so I
  331. 16:09can include other objects also so let us
  332. 16:11check other objects what I can include
  333. 16:14in the sixth column this object is
  334. 16:16definitely because its profit is maximum
  335. 16:18right 5 + 2 7 at 6 nothing will happen
  336. 16:23so take six only at seven I can consider
  337. 16:26these two these two so this is six + 1 7
  338. 16:307 then at 8 when the bag capacity eight
  339. 16:34which of the objects I can consider 5 +
  340. 16:373 8 so 6 and 2 8 so this is
  341. 16:418 so whichever objects that you can
  342. 16:44consider you just add them and in that
  343. 16:47capacity if they are fitting in you
  344. 16:48write on the Max total profit so this is
  345. 16:51a simple method for filling the cells
  346. 16:53instead of following this complex
  347. 16:55formula you can follow that method so I
  348. 16:57have shown you both
  349. 17:00solution I have to write down X1 X2 X3
  350. 17:05X4
  351. 17:07values now
  352. 17:10these now for finding these answers
  353. 17:13actually I'll be taking sequence of
  354. 17:15decision now see the decisions can be
  355. 17:17taken only if you have the data yes we
  356. 17:19have kept the data ready the formula was
  357. 17:21used for filling this data now I have to
  358. 17:24take the sequence of decision so how to
  359. 17:25solve so actually I have to know which
  360. 17:27object should be included and which
  361. 17:29should not be included in the bag so let
  362. 17:31us come with the maximum profit that is
  363. 17:34eight the last cell this eight is
  364. 17:37generated only in fourth row and in that
  365. 17:40previous row you don't find eight
  366. 17:42anywhere so it means we got this say
  367. 17:45because of including fourth object only
  368. 17:48so include the fourth
  369. 17:51object right profit is eight fourth
  370. 17:54object is included because eight is not
  371. 17:56there in previous row now what is the
  372. 17:58profit of the a a fourth object 8 minus
  373. 18:02profit is six six so this is
  374. 18:05two now remaining profit is two now
  375. 18:08check whether two is there in the third
  376. 18:11row now I have to check for the third
  377. 18:13object fourth then third then second and
  378. 18:15then one so third object two is there
  379. 18:17yes the same value two is there in the
  380. 18:20previous row also yes it is there so it
  381. 18:22means it is not because of third object
  382. 18:25so don't include third
  383. 18:27object now let us consider second object
  384. 18:30is it two there here in the second row
  385. 18:32yes two is there here is it there in the
  386. 18:35first row also no so it means this we
  387. 18:37got because of inclusion of the second
  388. 18:40object so take this as one so now
  389. 18:43remaining is 2 - 2 so
  390. 18:46zero now zero was it there in the first
  391. 18:49object so I have to consider the first
  392. 18:51object yes zero was there in the first
  393. 18:52object row was it there in the zero also
  394. 18:55yes it was there in the zero also this
  395. 18:57row also so it means don't include the
  396. 19:00object so this is the solution so it
  397. 19:03means which objects are included in the
  398. 19:04bag X2 and X4 two objects are included
  399. 19:08in the back so that is X2 is this one X4
  400. 19:11is this one so total profit will be
  401. 19:12eight so this is the maximum profit of
  402. 19:1601 napsack
  403. 19:18problem next I will solve it using sets
  404. 19:21method same problem I will solve it
  405. 19:23using set method now let us solve it
  406. 19:25using set method set method will try to
  407. 19:27find all possible possibilities and pick
  408. 19:29up the best solution so let us see how
  409. 19:32sets are generated we will prepare a set
  410. 19:35of order pay that is profit and weight
  411. 19:38so we'll start with set
  412. 19:40zero set zero in this we say no profit
  413. 19:44no weight means nothing is included in
  414. 19:47the
  415. 19:48bag then we will consider the first
  416. 19:50object that is 1 comma 2 whose profit is
  417. 19:53one and the weight is two so consider
  418. 19:55the first object so prepare s0 of 1 and
  419. 19:58and include this first object in the bag
  420. 20:01so it will be 1 comma
  421. 20:032 so actually add one comma to this
  422. 20:06order pair so we get this one now
  423. 20:08prepare set
  424. 20:10one then merge these two order Pairs and
  425. 20:14prepare this
  426. 20:15one so this means
  427. 20:18that we have considered first object so
  428. 20:21two order pairs are showing that first
  429. 20:24object is not included first object is
  430. 20:26included
  431. 20:29now let us
  432. 20:31prepare next set by considering second
  433. 20:34object so that is 2 + 3 so prepare next
  434. 20:37set that is S11 so add 2 three to these
  435. 20:41order pairs 2 + 3 so this is 2 comma 3
  436. 20:45then 2 + 3 is added so this will become
  437. 20:483 + 3A
  438. 20:525 then this is second set for the second
  439. 20:55object so when you consider second
  440. 20:58object to total four order pairs all
  441. 21:00these are merged so this is 1 2 and 2 3
  442. 21:04and this is
  443. 21:0735 this means that no object is included
  444. 21:11first object is included second object
  445. 21:13is included both objects are included
  446. 21:15four possibilities are there so all the
  447. 21:18order pairs we got then prepare S2 of 1
  448. 21:24by considering third object 5A 4 add 5A
  449. 21:274 to all all so this 5 + 4 so this is 5
  450. 21:31+ 4
  451. 21:34is 5A 4 only so 5 + 4 so this will
  452. 21:38become 6 and 6 so this is 6a 6 5 + 4 so
  453. 21:43this is 7A 7 so five is added to this
  454. 21:47and four is added to this so This become
  455. 21:498 comma 9 8 comma
  456. 21:539 now merge all these and take order
  457. 21:56pair so set three we get it as 0 0 1 2
  458. 22:03then 2
  459. 22:043 then
  460. 22:0735 then
  461. 22:1054 then 6
  462. 22:136
  463. 22:1577 now here 8 comma 99 profit is 8 and
  464. 22:21the weight is 9 so that is exceeding the
  465. 22:23capacity of the bag don't include that
  466. 22:26one
  467. 22:28so we have discarded that right now this
  468. 22:33is set three in this one if You
  469. 22:37observe this is profit this is weight
  470. 22:40profit increase weight increase then
  471. 22:42from this profit increase weight also
  472. 22:44increase profit increased and the weight
  473. 22:47also increased but here profit increase
  474. 22:49weight is decreased from 5 to 4 this is
  475. 22:52not possible profit is increasing so the
  476. 22:55weight is also increasing but weight is
  477. 22:58decreased how this possible so that's
  478. 23:00why this order pair are wrong so we have
  479. 23:03to discard any one so we will discard
  480. 23:05the one with the Lesser profit smaller
  481. 23:08profit so 1 2 3 4 5 6 now we have only
  482. 23:13six order pirs because two were invalid
  483. 23:16one was this was giving wrong values and
  484. 23:18this was exceeding the capacity of the
  485. 23:20back so cutting of this one we call it
  486. 23:23as dominance rule so with the dominance
  487. 23:25rule the value is order pair is
  488. 23:27discarded now I will consider fourth
  489. 23:30object 6A 5 I will include so I will
  490. 23:34prepare set 3 one by considering fourth
  491. 23:38objects 6A 5 so first order pair is 6
  492. 23:41comma 5 next order pair is 6 and five
  493. 23:44are added so this is 7A 7 then 6 and
  494. 23:48five are added so this is 8 comma 8 and
  495. 23:52then 6 and 5 when they are added it will
  496. 23:55become 11 comma
  497. 23:579 6 and 5 added so this become 12 comma
  498. 24:0211 and 6 5 when added to 7 and 7 so this
  499. 24:05becomes 13A
  500. 24:0912 now I have to prepare set four this
  501. 24:12is the final set must these order pairs
  502. 24:15so 0 0 is taken from here 1A 2 and 2
  503. 24:19comma 3 and 5A 4 6A 6 and 7A 7 they are
  504. 24:26coming as it is now in one 6A 5 is there
  505. 24:30so 6A 5 should come before 7A 7 so 6A 5
  506. 24:35now here again you see the profit is
  507. 24:37remaining same but the weight is
  508. 24:39reducing so this should be removed then
  509. 24:427 comma 7 is there then 8A 8 is there
  510. 24:46then remaining 11a 9 exceeding the
  511. 24:49capacity of the Back 9 11 and 12 so all
  512. 24:53three order pairs are gone so these are
  513. 24:55the order pairs I have so if You observe
  514. 24:58the method is generating all
  515. 25:02possibilities so this is one easy method
  516. 25:04of finding all possibilities so the time
  517. 25:07taken by this one is almost 2 power
  518. 25:10n now what is the solution so we have
  519. 25:13already sets now we take the sequence of
  520. 25:15decisions to solve this one now what is
  521. 25:17the maximum order of air 8A 8 so 8 comma
  522. 25:238 Now using that I will solve this one
  523. 25:26so the approach is similar like what we
  524. 25:28saw in the tabular method 8A 8 belongs
  525. 25:32to set
  526. 25:344 but 8A 8 check whether it belonged to
  527. 25:40set three in the set 3 8A 8 was not
  528. 25:43there so it doesn't belong to set three
  529. 25:46therefore fourth object is included
  530. 25:49because of that only we got 4A
  531. 25:524 now I should take an order pair 8
  532. 25:56comma 8 from this I should subtract the
  533. 25:59profit and weight of the fourth object
  534. 26:01so this is profit is six and the weight
  535. 26:03is five so the order pair is how much 2
  536. 26:07comma 3 so now I should consider 2 comma
  537. 26:103 so now this was the first one now
  538. 26:13second one 2A 3 now I have to consider
  539. 26:17third object so check whether it belongs
  540. 26:20to S3 2A 3 yes it belongs to S3 and 2A 3
  541. 26:27belongs to s 2 check whether it belongs
  542. 26:29to S2 s2a 3 is there here also it means
  543. 26:33this is not because of the third object
  544. 26:36so therefore third object is not
  545. 26:38included in the back then now next step
  546. 26:43is I will consider second object 2A 3
  547. 26:47belongs to set two for second object 2
  548. 26:49comma 3 now does it belong to set
  549. 26:521 but 2 comma 3
  550. 26:59doesn't belong to set 1 so 2 comma 3 was
  551. 27:02belonging to set 2 and 2 comma 3 doesn't
  552. 27:05belong to set 1 so therefore this is
  553. 27:07because of the second object that is
  554. 27:09included now what is the profit and
  555. 27:12weight of the second object 2A 3 so when
  556. 27:14you subtract 2 comma 3 from this one 2 -
  557. 27:172 is 0 and 3 - 3 is 0 so this gives 0a 0
  558. 27:24now first object I will consider now the
  559. 27:26step is four so 0 0 belongs to set 1 and
  560. 27:32also 0a 0 belongs to set 0 therefore
  561. 27:37first object is also not
  562. 27:40included 0a 0 belongs to S1 also s0 also
  563. 27:44it means this is obtained not because of
  564. 27:46the first object so first object is also
  565. 27:48not included then the solution is from
  566. 27:50bottom if you see 0 1 0 1 so the answer
  567. 27:55is 0 1 0 1
  568. 27:58so these two objects are included see
  569. 28:00the profit is eight so we got the same
  570. 28:03solution with the help of sets also so
  571. 28:05this is one more
  572. 28:08method that's all about 01 nsect problem
  573. 28:11leave a comment and let me know whether
  574. 28:13it was easy for you to understand so I
  575. 28:15have shown you both the steps for
  576. 28:17solving 01 naap problem right in some
  577. 28:19places we find tabulation method and
  578. 28:21some places we find the sets method

About this transcript

This page contains the full transcript of 4.5 0/1 Knapsack - Two Methods - Dynamic Programming by Abdul Bari, generated from the public captions YouTube serves with the video. The transcript has 4,447 words across 578 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.