Recursion questions can be good if they test practical skills. For example, tell me what this code returns when given 10:
int func(int n)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return n + func(n / 2);
else
return n + func(n - 1);
}
If you have actual software experience, you shouldn't have any trouble figuring it out especially if you show your work. But if all you do is import modules and copy from StackOverflow, you might be in trouble.
On the other hand, asking them to write code and then saying "not like that, you have to use recursion" is a bad question.
And I'd tell the interviewer I would have added an 'else if' in the middle because while the function currently has 'return' in every branch, it could cause unexpected behavior if someone changed it in the future to modify a variable and return it at the end, since '0' would trigger both the first branches.
At this point the interviewer would thank me for my time and go to joke around with his co-workers about the weirdo he just interviewed.
Recursion is ridiculously easy and it's perfectly reasonable for junior developers to learn.
Blame Java for failure to tech recursion.
(*) Specifically speaking about trail recursion. Recursion schemes may actually extend that to order forms, but they are useful themselves in more complex scenarios so...
Don't blame Java for that. Yes, it has issues with tail recursion optimization, but I've done a fair amount of work with recursion in Java. It's not like it really sucks unless you're trying to recurse in a situation where looping is what the JVM expects you to do in this case.
Blame bad teachers. Recursion is a topic that's notoriously difficult to explain.
Asking junior developers questions about recursion, for example, is ridiculous.
I would expect the average junior developer to be better at implementing a recursive solution due to being recently out of college. Recursion is much more prevalent in academics than in actual software development (in fact NASA banned recursive code because it is problematic in practical settings.)
0
u/[deleted] Mar 29 '21
[deleted]