r/programming • • Mar 29 '21

Why Do Interviewers Ask Linked List Questions?

https://www.hillelwayne.com/post/linked-lists/
1.1k Upvotes

668 comments sorted by

View all comments

0

u/[deleted] Mar 29 '21

[deleted]

0

u/[deleted] Mar 29 '21

[deleted]

3

u/maest Mar 30 '21

Programming is hard, so I prefer not asking anything about programming in my programming interview, lest the question is too hard.

0

u/[deleted] Mar 29 '21

[deleted]

→ More replies (25)

24

u/angrymonkey Mar 29 '21

Asking junior developers questions about recursion, for example, is ridiculous

Uh, recursion is literally a CompSci 101 concept. I would hope that anyone aiming to get paid for programming would be able to understand it.

→ More replies (4)

0

u/[deleted] Mar 29 '21

[deleted]

6

u/hairibar Mar 29 '21

Wait, where is recursion used in graphics? I work in videogames and can't think of any example right now. Is it a raytracing thing?

13

u/firefly431 Mar 29 '21

Not OP, but:

  1. raytracing (rendering equation)

  2. BVHs (including quad/octrees, etc.)

  3. animation (calculating skeleton transforms, parent-child hierarchies)

  4. stuff with bezier curves (rendering, intersection, closest-point finding, etc.)

  5. adding on to that, procedural geometry in general

Tree structures are pretty common throughout most types of software, so there's plenty of places to use recursion.

4

u/hairibar Mar 29 '21

Ah of course, I didn't think of transform hierarchies.

→ More replies (7)

5

u/angrymonkey Mar 29 '21

BVHs, BSPs, object and transform hierarchies, ray tracing, subdivision surfaces, B-splines, fractal noise, constraint propagation, linear interpolation...

→ More replies (2)
→ More replies (3)
→ More replies (1)

17

u/telionn Mar 29 '21

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.

8

u/gastrognom Mar 29 '21

23?

5

u/yakoudbz Mar 29 '21

10+5+4+2+1+1=23

Seems about right

1

u/demon_ix Mar 29 '21
func(10) = 10 + func(5) = 10 + 5 + func(4) = 10 + 5 + 4 + func(2) = 10 + 5 + 4 + 2 + func(1) = 10 + 5 + 4 + 2 + 1 + func(0) = 23

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.

2

u/gastrognom Mar 30 '21

I'd rather remove the else and just make it the default return to be honest.

→ More replies (1)

4

u/sammymammy2 Mar 29 '21

I was so confused as to what that function was supposed to compute and then I saw you had given a specific input, d'oh!

7

u/thephotoman Mar 29 '21

I'd expect someone fresh out of college to know how to traverse an arbitrary but finite tree.

7

u/przemo_li Mar 29 '21

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...

7

u/thephotoman Mar 29 '21

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.

→ More replies (1)

3

u/Varanite Mar 30 '21

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.)

2

u/quadrilateraI Mar 30 '21

NASA found it problematic in embedded software for spacecraft, that is a very tiny niche of 'practical settings'.

→ More replies (1)

2

u/Riael Mar 30 '21

Asking junior developers questions about recursion, for example, is ridiculous. Yet, I see it happen all the time.

Excuse you what?

...these are things you did in high school

...you should know them...

Where the fuck can I find companies that have these kind of interviews??????

→ More replies (1)