A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 3 years ago
Hi guys, the ideas of graph and dynamic programming seem confuse me a lot. In lec22's code. the subtitles indict that there is a bug in function dpShortestPath(). I don't understand that code very well. How does the bug arise?
Could any one explain that problem more concretely or just give the correct code?
lec22's code
http://dpaste.com/hold/1396904/
anonymous
 3 years ago
Hi guys, the ideas of graph and dynamic programming seem confuse me a lot. In lec22's code. the subtitles indict that there is a bug in function dpShortestPath(). I don't understand that code very well. How does the bug arise? Could any one explain that problem more concretely or just give the correct code? lec22's code http://dpaste.com/hold/1396904/

This Question is Closed

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0It's fun to watch the video lectures, but it's a headache to just go through the codes...

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0you need to work with it till you understand how it works. you might have to watch the lecture a few times. just keep at it till you understand it then look for the bug. to be candid it has been a long while since i went thru it and i don't recall what the bug was. maybe go back and rewatch lecture 21 also

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0In lec23 about 24:30 , Prof Guttag claims there is a dirty little secret in python. initializing the memo = None and doing a little bit change of code may be helpful.

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0why wouldn't you want to use a mutable object as a function argument default value ?

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0Initializing the memo = None turns out to be a wrong answer…It makes no expecting change to the program. I think I can understand the function shortestPath() now, but still confuse about the dpShortestPath(). The only thing I am sure now is that dpShortestPath() indeed has a bug(s), and the bug must hide in the memo.

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0here is one of many explanations available for this gotcha http://effbot.org/zone/defaultvalues.htm

anonymous
 2 years ago
Best ResponseYou've already chosen the best response.0thanks, it begins to make a little sense to me. But those recursive relations are still very messy. Maybe I should take an algorithm course, then i can fully understand it.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.