Someone managed to solve the problem 3 set 2: Using Bisection Search to Make the Program Faster. I need help to understand this problem.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.
Not the answer you are looking for? Search for more explanations.
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.
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.
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).
which course (2008 or 2011)? which ps? which problem?
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).
the problem set and lecture order is different for the 2008 and 2011sc series
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
- 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