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

Someone managed to solve the problem 3 set 2: Using Bisection Search to Make the Program Faster. I need help to understand this problem.

OpenStudy (anonymous):

Do you mean problem 3 of set 1? Because the first set was number 0? That is the one I recall that needed to go faster by binomial search. If so, I just finished it. If you did the previous one, then your loops should pretty much work the same (mine did). Next, you have to find an upperbound and lowerbound to test against, which the problem set tells you how to do, so that part is pretty easy. Next, you set your payment halfway between the upperbound and lowerbound: payment = (upperbound+lowerbound)/2. After that, this was my logic: 1) if remaining balance after 12 months is too high, raise your payment. 2) if remaining balance after 12 months is too low, lower your payment. 3) if remaining balance after 12 months is correct, then stop. To raise your payment, set payment = (payment+upperbound)/2. REMEMBER to also set your new lowerbound to equal your old payment. Actually, it's easier to do it in reverse order. Set lowerbound = payment, then raise payment. To lower payment, do the opposite. To recognize when you are done, basically since you are going in 1 cent increments and everything has to be the same, you could overpay by up to 11 cents. So, that is your range -11 to 0 for being done. I think that's right. I got the same answers as the professor within 2 cents, which I think is probably rounding and I'm not worried about it. If you want, I can post code.

OpenStudy (anonymous):

paste the code

OpenStudy (anonymous):

I wish!

OpenStudy (anonymous):

OK, here is my code. It works (gives the right answer). You might not like it because I used a function. The same basic logic should work without a function, I just thought the function was easier that way. Also, of course, the professor posted his own solution in a .zip file in the lesson 4 materials. http://pastebin.com/e5UiBiVE

OpenStudy (anonymous):

Thanks RCMorea! I tested your code, but the results are different tests. Could you post the link of the file where I can download the solution of the teacher.

OpenStudy (anonymous):

Interesting. It's giving me 29643.04 for the first payment. I believe the "book answer" is 29643.05, but that is a rounding error. Also, it is giving me 91679.91 as the second payment, which is right on the book answer. The final balances I am getting -.03 for the first one (book answer -.1) and -.06 for the second one (book answer -.12) but again that is rounding, and I think mine is actually more accurate than the professors (he rounds before the math but I round after). If anyone else checks this, I would be curious what you get. But...I will say the professors code is a better example to look at anyway (no surprise, of course).

OpenStudy (anonymous):

which course (2008 or 2011)? which ps? which problem?

OpenStudy (anonymous):

this was course 2011 (well, at least that is the one i did, maybe others did a different one that could account for some differences), second problem set (but numbered ps1), last problem (the one where you use bisecgtion search).

OpenStudy (anonymous):

the problem set and lecture order is different for the 2008 and 2011sc series

OpenStudy (anonymous):

if it is the problem for paying off debt then: - initialize the lower limits of your bisection search to 0 and the upper limit to the original balance. - make a guess at the halfway point - run the guess through the payment cycle - if the guess was too big, set the upper limit to the guess and repeat - if the guess was tool small, set the lower limit to the guess and repeat

OpenStudy (anonymous):

http://dpaste.com/994192/

OpenStudy (anonymous):

Thank bwCa and RcMorea for your help.

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!