Tail Recursion

Basically there are two types of recursion in programming.

The normal recursion and the tail recursion.

What is special about tail recursion is that the recursive statement is called at the end of the code.

Let’s identify the difference between normal recursion and the tail recursion.

Capture
Normal Recursion

Check out the tail recursion.

Capture2
Tail recursion

First don’t really think about the way this works. First identify the difference between normal recursion and the tail recursion.

If you can identify, the time that the calling of the function changes the recursion type.

In Tail Recursion the recursive call is the last thing to happen in the each recursion.

But in normal recursion, multiplication happens last.

OK. Now go ahead workout the behavior of the two code segments.

Thank you.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s