Live data from Hacker News

Stop Telling Students Recursion is Hard

jinfiesto.posterous.com

1–10 of 111 posts

Re: Stop Telling Students Recursion is Hard

#2
I think the main fault of recursion is that students end up with "stack overflow". The JVM and C++ also don't have tail recursion. Performance is really the biggest perception difficulty. Would also help if students learned about inductive proofs in mathematics earlier on.

Re: Stop Telling Students Recursion is Hard

#3
I don't think that teachers are telling students recursion is hard. I think that through observations, good teachers who have taught for many years have seen that many, many students will just never get recursion. And that's the basis of teachers saying that recursion is hard.

Re: Stop Telling Students Recursion is Hard

#4
It's funny. I've JUST finished spending a week or so on recursion with my students. The FIRST thing I did was have the entire class repeat after me: "Recursion isn't hard. It's just different."

And I've been teaching CS at the high-school level for 13(?) years now, and I've never had a student who just couldn't get recursion. On the contrary, most of the them pick it up pretty quickly. There's initial confusion, followed by the flash of insight, and then they're pretty much golden.

Re: Stop Telling Students Recursion is Hard

#5
post #3

I don't think that teachers are telling students recursion is hard. I think that through observations, good teachers who have taught for many years have seen that many, many students will just never get recursion. And that's the basis of teachers saying that recursion is hard.

The idea behind recursion is I have X, if I know Y then this would be easy. But, picking the correct Y and finding a simple path to get Y is hard for many people.

Consider something as simple as factorials. 1! = 1 and N! = N * N-1! but try to code it as: N! = N! / 1! * 1 = N! / 2! * 2 = N! / 3! * 6. Then with a lot of time and effort they get something that works, but it's not intuitive.

Re: Stop Telling Students Recursion is Hard

#6
post #5
post #3

I don't think that teachers are telling students recursion is hard. I think that through observations, good teachers who have taught for many years have seen that many, many students will just never get recursion. And that's the basis of teachers saying that recursion is hard.

The idea behind recursion is I have X, if I know Y then this would be easy. But, picking the correct Y and finding a simple path to get Y is hard for many people. Consider something as simple as factorials. 1! = 1 and N! = N * N-1! but try to code it as: N! = N! / 1! * 1 = N! / 2! * 2 = N! / 3! * 6. Then with a lot of time and effort they get something that works, but it's not intuitive.

Perhaps the other problem is that it's not obvious to students what the point of doing things recursively is. OK, it can shave a few characters off your factorization code. Or your Fibonacci code. That's neat, but why get excited?

Re: Stop Telling Students Recursion is Hard

#7
post #6
post #5

Earlier quoted context omitted.

The idea behind recursion is I have X, if I know Y then this would be easy. But, picking the correct Y and finding a simple path to get Y is hard for many people. Consider something as simple as factorials. 1! = 1 and N! = N * N-1! but try to code it as: N! = N! / 1! * 1 = N! / 2! * 2 = N! / 3! * 6. Then with a lot of time and effort they get something that works, but it's not intuitive.

Perhaps the other problem is that it's not obvious to students what the point of doing things recursively is. OK, it can shave a few characters off your factorization code. Or your Fibonacci code. That's neat, but why get excited?

I usually show them a recursive Towers of Hanoi solver. It's alarmingly simple (fewer than 10 LOC) and most of them can't even imagine how to write it iteratively.

I tell them that recursive code is rarely better than iterative code, but for certain types of problems, it's SO much easier to come up with a recursive solution that it's worth knowing how to do.

Re: Stop Telling Students Recursion is Hard

#8
post #7
post #6

Earlier quoted context omitted.

Perhaps the other problem is that it's not obvious to students what the point of doing things recursively is. OK, it can shave a few characters off your factorization code. Or your Fibonacci code. That's neat, but why get excited?

I usually show them a recursive Towers of Hanoi solver. It's alarmingly simple (fewer than 10 LOC) and most of them can't even imagine how to write it iteratively. I tell them that recursive code is rarely better than iterative code, but for certain types of problems, it's SO much easier to come up with a recursive solution that it's worth knowing how to do.

I tell them that recursive code is rarely better than iterative code

As a general statement, this is wrong. Recursive code is almost always better than imperative code in languages designed to encourage recursion -- I'm thinking of functional languages here, of course. Please qualify your statements to your students, lest they get the idea that it is a problem with recursion as a principle rather than a problem with the language they're working in.

Re: Stop Telling Students Recursion is Hard

#9
post #7
post #6

Earlier quoted context omitted.

Perhaps the other problem is that it's not obvious to students what the point of doing things recursively is. OK, it can shave a few characters off your factorization code. Or your Fibonacci code. That's neat, but why get excited?

I usually show them a recursive Towers of Hanoi solver. It's alarmingly simple (fewer than 10 LOC) and most of them can't even imagine how to write it iteratively. I tell them that recursive code is rarely better than iterative code, but for certain types of problems, it's SO much easier to come up with a recursive solution that it's worth knowing how to do.

I am not sure if I understand recursion or not. My definition of recursion is a function that calls itself repeatedly until an exit condition occurs (the first chapters of little schemer define this as an empty list). If the exit condition never occurs, and the computer lacks infinite computing power, you will probably get a stack overflow. As far as I can tell, recursion and a for-loop accomplish the same thing.

Am I missing anything?

EDIT: I wrote this before reading the article

Re: Stop Telling Students Recursion is Hard

#10
A lot of the disagreement here comes from what people consider recursion. As in all things, the basic idea behind recursion is quite simple to understand. It's just a function calling itself.

There are, however, some non-trivial uses of recursion such as quicksort and analyzing its runtime.

Thus, to say simple recursion isn't hard is true. But I'm sure that we can all find a recursive problem that we wouldn't consider easy.

Post reply on HN