> His questions are not about writing code, they are about writing algorithms.
What's the distinction between those? He isn't asking the candidates to invent algorithms, just to implement simple ones. The answer to the second question is "return Pi * radius * radius", isn't that just writing code?
The first one (find pi to 5 decimal places from the sequence) is asking candidates to remember or invent algorithms - in fact, I'm not immediately sure how to generate the error bound there.
No, he provided the sequence. There remains the question of how you make sure that calculating n terms of it puts you within 10^-5 of the true value of pi. If he provided that as well, then yes, it should be a trivial exercise. If not, it's nontrivial (although not, I think, hugely difficult) mathematics followed by trivial programming.
The sequence is enough, you just keep going till your fractions (multiplied by 4) do not change 10^-5 any more. You do not need the actual value of pi.
As soon as 4 * 1/(2n+1) < 0.00001, then you can stop looping. The sequence is the algorithm.
This is not true for the general sequence, and I would be hesitant to give that answer without an understanding that it is true for the given sequence. It is, and I sketched the proof in reply to your sibling comment, but it takes more figuring out than I could do before coffee.
You are correct, but I think underestimating the insight required for it to be "obviously" correct.
That the error must be less than the nth term does follow from 1) the fact that he says "more terms giving greater accuracy", which means the error must be monotonic, and 2) the fact that the sequence is alternating. Together, this means the two must be bouncing around the answer instead of inching toward it, and so the sum of the tail must be less than the current increment.
It won't work, however, for the general sequence (or even the general convergent sequence).
This is a worthwhile point. The non-alternating sequence, 1/(2n + 1), when summed, diverges. So if you cut it at the 100th term, or the 1000000th term, the sum of the tail will not be negligible, it will be infinite.
It's only the fact that it's alternating that makes it summable. The alternating series converges like 1/n^2.
This is the kind of thing that, if it's noted in an interview situation, marks a better than average candidate. It could also allow such a candidate to go on about problems with summing series, and really show off. (One secret to interviewing well being to make the given question into a question you know something about already.)
Ah yes, the old "it's simple to me therefore it must be simple to everyone else" thought.
I didn't say "invent" algorithms, I said write them. If I didn't happen to have that "simple" algorithm in my head already then it would not necessarily be trivial to implement it. Especially if it's been a while since you've worked with similar equations.
Now, if the goal is to see how the person would try to work it out allowing for questions to take the place of research then I could possibly see the benefit.
I'm still fuzzy on the distinction you are trying to make between "writing algorithms" and "writing code". If someone told me they were "writing an algorithm", I'd understand it as them trying to come up with a new algorithm, either on paper or in code.
If you're given the outline for an algorithm, and asked to write code to implement it, is that writing algorithms or writing code?
This is just me, but in the two examples the first one is algorithm and the second is code. The difference being that in the first one he starts to explain the sequence he wants but apparently expects you to complete the sequence to code the function. Granted he does give you enough of the sequence that you can probably see the pattern. The second he basically tells you the equation he wants to see in code.
The first one requires an ability, even if minor, beyond just coding while the second is all about coding. I also find it interesting that he says the second version was more difficult for his applicants than the first. Maybe instead of "algorithm" it's more about pattern recognition that leads to minor math skills to then coding.
What's the distinction between those? He isn't asking the candidates to invent algorithms, just to implement simple ones. The answer to the second question is "return Pi * radius * radius", isn't that just writing code?