Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

6.00_learner

  • one year 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
  1. Richard_C
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  3. 6.00_learner
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  5. 6.00_learner
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  6. bwCA
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  7. 6.00_learner
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.