Hacker News new | past | comments | ask | show | jobs | submit login

Newton's method is dead simple to implement, you just have to remember it. http://mitpress.mit.edu/sicp/chapter1/node9.html



Esoteric algorithms would be much more useful questions, IMO, if the interviewer gave you a birds-eye overview of an algorithm you cannot possibly have heard of and then have you implement it. That actually tests your chops rather than your memory.

For example, everybody knows merge sort, but assuming they didn't, draw out a couple iterations in a graph and ask them to code it.


If you're handy with simple algebra (and can remember that the derivative of x^2 is 2x) then you can remember the picture. If f(x) = x^2 - N, then you're looking for the (positive) zero of f. You take a succession of tangent lines and look at the zeros of those. So, you start with a guess (call it x_0), take the tangent line at your guess (so it has slope 2x_0 and goes through (x_0, x_0^2 -N)), then find the x-intercept of this line and make it your new guess. This is all Newton's method is. With square roots, it takes the form of averaging your previous guess and N over it.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: