Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 11 Online
OpenStudy (anonymous):

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/

OpenStudy (anonymous):

It's fun to watch the video lectures, but it's a headache to just go through the codes...

OpenStudy (anonymous):

you 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 re-watch lecture 21 also

OpenStudy (anonymous):

In 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.

OpenStudy (anonymous):

why wouldn't you want to use a mutable object as a function argument default value ?

OpenStudy (anonymous):

Initializing 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.

OpenStudy (anonymous):

here is one of many explanations available for this gotcha http://effbot.org/zone/default-values.htm

OpenStudy (anonymous):

thanks, 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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!