roughly like this: it's the square root of 1234.56 * 100, so it's 10 times root of 1234.56. which in turn is root of 100 * 12.3456, so 10 times root of 12.3456. so it's 100 times root of 12.3456, root of 12.3456 is root of 4 times c. 3, so it's 200 times root of c. 3, approximate root of 3 as 1.732 (using birth of George Washington as the rule of thumb), so you get 200 * c. 1.8, = 200 + 160 = c. 360
(Original post by Jamil1987)
If you were asked this at an interview how would you tackle it given just a pen and paper. (No Calculator im afraid lol)
Yeah probably as teenage pirate did, or simple interval bisection will cause you to guess 350. When you try that you'll get pretty damn close (I imagine they set it up to be fairly close to an obvious number).
(Original post by Jamil1987)
lol, this particular question was IB Tech @ Nomura
I don't really understand the need in such a question. No ones ever going to need to randomly approximate a difficult calculation. It takes longer to work it out than to get your phone out and click calculator
I guess it somewhat shows critical thinking if you'd never done this kind of thing before, but if you had it seems completely useless/unfair on the people who hadn't.
Last edited by Intriguing Alias; 21-05-2012 at 11:02.
(Original post by uxa595)
How long did you have. It took me 1min to get it through trial and error.
did 500x500, too big
400x400, too big
300x300, too small
350x350, about right.
351x351, close enough
Although that's how most people would do it, your method isn't algorithmic.
When you get to 350^2 and see that this is too small, so the square root lies in the interval (350,400). A bisection method would go to 375, not 350. The only reason you go to 351 is because |350^2 - 123456| << |400^2 - 123456| so you know the square root is going to be much closer to 350 than it is to 400. Putting this into an algorithm is a trickier (requires a fair amount of pen and paper work at least) than a bisection method, but it's a lot faster. I suppose this is the crux of the question, and is why they've asked it.
Although it could be that they just want to see the candidate they are interviewing can multiply.
I did not see the 'pen and paper' comment so that's how I did it in my mind:
300^2 = 90,000
400^2 = 160,000
so it's between 300 and 400
I know by heart that 35^2 = 1225 and 36^2 = 1296. 1296 - 1225 ¬ 70, 360-350=10, so for an increase of ¬10 (from 1225 to 1235) we should go up by 10/70*10 ¬ 1.4, so it's 351,4 which is as close as I could get.
On an interview, however, I'd just say 350 in about 10 seconds. I believe they will be more impressed that I know 35^2 by heart and can answer the question quickly than if I take like a minute to solve it on the paper and give them a more precise answer.
(Original post by miml)
When you get to 350^2 and see that this is too small, so the square root lies in the interval (350,400). A bisection method would go to 375, not 350. The only reason you go to 351 is because |350^2 - 123456| << |400^2 - 123456| so you know the square root is going to be much closer to 350 than it is to 400. Putting this into an algorithm is a trickier (requires a fair amount of pen and paper work at least) than a bisection method, but it's a lot faster. I suppose this is the crux of the question, and is why they've asked it..
If you wanted to be efficient then you wouldnt use bisection, you'd interpolate between the values since you know its monotonic increasing, then pick your next guess based on that. A linear interpolation is going to be inefficient (since the square function is nowhere near linear) but its still a lot better than a bisection. If you linearly interpolate between 350^2 = 122500 and 400^2 = 160000, then your next guess for x^2 = 123456 is going to be much closer to 350 than to 400.
But for me, it took longer (more math steps) to do by linear interpolation than by the babylonian method.
Would be interesting to know the percentage of people that were able to come up with a good answer...say within 5 minutes.
If I were the interviewer, I would ask how would you go about finding the answer....and listen....to see how their brain works. If they already knew a set way to do it, I would have a backup question.