• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How would you teach recursion?

to freshman students. I was thinking about giving them an example, such as factorial, or something simple, but how would you explain it?
 
exponentiation example

edit: didnt see the how to part. my professor did a really good job. he explained what the recursive case and the base case were. then drew the stack of method calls and what parameters they were receiving until the base case was reached, then all the return values. on the blackboard, simple and effective.
 
Originally posted by: chuckywang
to freshman students. I was thinking about giving them an example, such as factorial, or something simple, but how would you explain it?

All jokes aside... to freshman what? High school students? College students?

I think factorial is something simple enough... but it doesn't explain the "why"... as you can easily compute factorials in a much more straightforward fashion.

There are quite a few math problems that easily lend themselves to be solved via recursion... but damn if I can recall any off the top of my head now...

😱
 
Originally posted by: MathMan
Originally posted by: chuckywang
to freshman students. I was thinking about giving them an example, such as factorial, or something simple, but how would you explain it?

All jokes aside... to freshman what? High school students? College students?

I think factorial is something simple enough... but it doesn't explain the "why"... as you can easily compute factorials in a much more straightforward fashion.

There are quite a few math problems that easily lend themselves to be solved via recursion... but damn if I can recall any off the top of my head now...

😱

Yeah, freshman college students.
 
Originally posted by: MathMan
There are quite a few math problems that easily lend themselves to be solved via recursion... but damn if I can recall any off the top of my head now...

Sorting (I can try to find it in my notes when I get home, but I believe there is a really good quick or bubble sort example using a deck of cards)
 
I learned it through factorial. Just a simple program like this:

public int Factorial(int i)
{
int retVal;

if (i = 1)
retVal = 1;
else (i > 1)
retVal i * Factorial(i-1);

return retVal;
}

This introduces them to the base case (i = 1) where the recursion stops. You can then trace it back down the stack for them.
 
I believe directory structure is a good case for recursion. Say you want to know how many empty directories exist but you have to also ensure the subdirectories are empty before removing empty directories above them. Or is that too real world?
 
recursion is nice but i dont like the that it uses alot stack space unless its the only clean way to slove a proble.
 
For some people, you may have to teach what a factorial is first. I did not know what a factorial is, and yet I did some programming, but I can't remember how I was taught it.
 
Originally posted by: logic1485
For some people, you may have to teach what a factorial is first. I did not know what a factorial is, and yet I did some programming, but I can't remember how I was taught it.

I think it's safe to assume that most people learn factorials in middle school.
 
Find a recording of this song and play it for them:

:music: "This is the song that never ends,
Yes it goes on and on, my friends.
" :music:
 
Back
Top