Re:Data structures and algorithms I actually used while work...
by tchaffee on Wednesday July 15, 2020 @05:53AM
(#23843119)
In my decades of programming I've never had to seriously consider these issues. I have used recursion and have written some pretty deep stuff like cryptography and writing my own interpreter (for a business - not a school project). I've even implemented recursion in a language that didn't support it. I have read about tail recursion several times. I still barely remember what it is. But I know a few books to reach for if I had to use recursion again. This is why the interview process is broken. I've written lots of production code and end up being seen as a lead programmer within weeks of a new job. And your questions would make me look like I don't know what I'm talking about.
Re:Data structures and algorithms I actually used while work...
by TedDoesntTalk on Wednesday July 15, 2020 @09:40AM
(#23845057)
I’ve worked with some interviewers who are out to prove they are smarter than the candidate because they remember a bit of something that the candidate does not.
Only when the interviewer finds someone “smarter” than himself does he approve of hiring the candidate.
It is an ego game.
Perhaps this describes OP.
Re:Data structures and algorithms I actually used while work...
by dotancohen on Wednesday July 15, 2020 @05:44AM
(#23843057)
Serious request, as a developer who would probably code a naive Fibonacci that doesn't meet your standard: Could you provide a code sample that does meet your standard? This looks like an important learning opportunity for me. Thanks.
Re:Data structures and algorithms I actually used while work...
by Smaug123 on Wednesday July 15, 2020 @06:20AM
(#23843293)
Instead of recursing twice, recurse once, by carrying around not fib(n-1) but the pair (fib(n-2), fib(n-1)).
Re:Data structures and algorithms I actually used while work...
by dotancohen on Wednesday July 15, 2020 @07:27AM
(#23843713)
True, but then the "worker" fib() method should be called fib_calculate() and should be wrapped by fib() which then returns a single integer. I believe that breaks the spirit of the question.
Re:Data structures and algorithms I actually used while work...
by Taek on Wednesday July 15, 2020 @09:39AM
(#23845037)
Really it's about this type of discussion. Already with your 'but then' you are showing that you know your way around a program.
I'd still have you write the full thing out, but I'm guessing you'd do just fine.
Re:Data structures and algorithms I actually used while work...
by Smaug123 on Friday July 17, 2020 @03:02AM
(#23867927)
I'd use `go`, by ancient Haskell law and custom ;)
Re:Data structures and algorithms I actually used while work...
by WJW on Wednesday July 15, 2020 @07:31AM
(#23843746)
There should be a fourth level where they use the closed form solution to get to the solution they want without any recursion or looping for reasonable values of N. Maybe even a fifth level using the O(log(N)) matrix exponentiation method.
Re:Data structures and algorithms I actually used while work...
by sk5t on Wednesday July 15, 2020 @08:17AM
(#23844107)
I’m a bit puzzled at the idea of using recursion for an infinite sequence (did OP mean factorial?). Give me a LazyList / generator / IEnumerable instead any day for Fib.
Re:Data structures and algorithms I actually used while work...
by deadgunslinger on Thursday July 16, 2020 @04:21AM
(#23856927)
It's easy to memorise all those too without necessarily understanding them.
Second level is how they explain the simple recursion that’ll hit stack limits (i.e. without tail recursion)
Third level is using accumulator/tail recursion.
See how they can express these ideas and are they able to effectively communicate their intentions.