This lecture covers recursion, memoization, and dynamic programming. We look at two common problems in dynamic programming: longest common subsequences and knapsack problems.
Asking/Answering Questions :
Reply to this thread to ask questions. Before asking, scroll through the thread and check if your question (or a similar one) is already present. If yes, just like it. We will give priority to the questions with the most likes. The rest will be answered by our mentors or the community. If you see a question you know the answer to, please post your answer as a reply to that question. Let’s help each other learn!
Has anyone worked out how to return all the items in the knapsack using recursion? I’ve been trying to work it out for a few hours and I just keep digging a bigger hole for myself. I’ve searched online and can’t find an answer there either.
Oh the knapsack memoization solution?..i can share an online lecture on knapsack memoization…https://youtu.be/dT6dvdbpChA. And i also need to work on it too. Sorry for late reply. Thanks
hello guys, i was thinking too much about how to get the road of what recursion chose ? i mean for example we get max_profit or max-subsequence , the answer is only the result of the best road to get best result , so what should i do if i want to see the road what we have taken, for example not only the range of subsequence , i want to know what largest subsequence those both sequence have too, so pls dont give me new code about other problem just change those examples from lesson 4
I read the explanation of complexity of lcs_recursive function written in the above notebook by Aakash sir. It says that all the leaf nodes would become (0,0) meaning the length of both the sequences would boil down to 0.
But I disagree.
The terminating condition is following:
if len(seq1) == idx1 or len(seq2) == idx2:
return 0
This condition will not allow both the sequences to boil down to a length of 0. Then how can we calculate the complexity assuming the leaf nodes to be (0,0).
By the way I am refering to the following tree:
Also working on this.
If you comment out the #return recurse(0,0) and run, the tests will output None.
I’m guessing the way the key is initially assigned, doesn’t trigger a True or False return from the if-else, and returns nothing.
Then the recurse(0,0) at the bottom, starts off the initial recursion.
Why that is, looks like something I have to review.