r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

Show parent comments

3

u/EdenStrife Apr 05 '22

Sure, recursion is not a substitute for a loop in all cases. It's useful for specific problems.

I do have a bit of an issue with defining recursion the way you do. Recursive problems and their solution structure is one thing and recursion as a concept seems to me to be different things.

The idea is just that a function calls itself. That you can use that to solve a specific kind of problem seems to me at least to be an arbitrary add-on to the definition.

4

u/KimPeek Apr 05 '22

Right, but "a function calls itself" is an oversimplified description, not a definition of recursion. It reduces recursion down the point of being useless and is probably why people struggle with applying it. It doesn't help anyone in this thread who doesn't know how to apply recursion to solve a problem.

The definition I gave is not mine. It's from Robert Sedgewick who is the author of one of the most widely used Data Structure and Algorithms books. Page 25 of Algorithms Fourth Edition, halfway down the page. I'm also not the only one to use this definition in this thread.

3

u/EdenStrife Apr 05 '22

It reduces recursion down the point of being useless and is probably why people struggle with applying it

Sure, i just disagree that the definition of a term should also include a tutorial on how to use that thing in practice.

Plenty of other places use the more general definition of just being a function calling itself.

It's as if a wheel could not be referred to in isolation but only as a part of a holistic transport solution. Like the wheel would have no name if not attached to a car.

Figuring out how to use a thing, and what that thing is don't have to be connected, i think.

1

u/KimPeek Apr 05 '22 edited Apr 05 '22

Fair. I thought since this thread was about explaining concepts that it warranted more precision. u rite tho

1

u/Aggravating_Moment78 Apr 06 '22

Actually a thing and it’s reason for existence are quite connected, i mean without knowing what you would use a wheel for the wheel is just a useless round thing...

1

u/EdenStrife Apr 06 '22

But it's still called a wheel right? Even if you don't use it it's still a wheel.

1

u/Aggravating_Moment78 Apr 06 '22

Nope that’s actually WHY the function would call itself, because in and of itself a function calling itself is not very useful unless you are using it to solve a problem in the way described above or a similar way...

1

u/EdenStrife Apr 06 '22

This is specifically about the definition and name of the practice.

I think we can agree a wheel is still called a wheel even if it isn't actively being used.