Thursday, June 16, 2005

 

Recursive Functions

A recursive function is one which calls itself. This is another complicated idea which you are unlikely to meet frequently. We shall provide some examples to illustrate recursive functions.

Recursive functions are useful in evaluating certain types of mathematical function. You may also encounter certain dynamic data structures such as linked lists or binary trees. Recursion is a very useful way of creating and accessing these structures.

Here is a recursive version of the Fibonacci function. We saw a non recursive version of this earlier.

int fib(int num)
/* Fibonacci value of a number */
{ switch(num) {
case 0:
return(0);
break;
case 1:
return(1);
break;
default: /* Including recursive calls */
return(fib(num - 1) + fib(num - 2));
break;
}
}

We met another function earlier called power. Here is an alternative recursive version.

double power(double val, unsigned pow)
{
if(pow == 0) /* pow(x, 0) returns 1 */
return(1.0);
else
return(power(val, pow - 1) * val);
}

Notice that each of these definitions incorporate a test. Where an input value gives a trivial result, it is returned directly, otherwise the function calls itself, passing a changed version of the input values. Care must be taken to define functions which will not call themselves indefinitely, otherwise your program will never finish.
The definition of fib is interesting, because it calls itself twice when recursion is used. Consider the effect on program performance of such a function calculating the fibonacci function of a moderate size number.

If such a function is to be called many times, it is likely to have an adverse effect on program performance.

Don't be frightened by the apparent complexity of recursion. Recursive functions are sometimes the simplest answer to a calculation. However there is always an alternative non-recursive solution available too. This will normally involve the use of a loop, and may lack the elegance of the recursive solution.


Comments:
Powerful blog. The site was incredible and will be
back again! Web surfing helps to find good blogs like
this one.
Everyday of the month you need to peep my online credit card blog.
 
Cool blog. I dig your site outline and I plan on
returning again! I just love finding blogs like this
when I have the time.
No matter when you are, just stop by and check for my plastic surgery hawaii blog site.
 
Super blog. I enjoyed the site and when I have the
time, shall visit the site again. Finding blogs this
good on the internet.
You got me! I will check out your orange county plastic surgery blog a.s.a.p!
 
Enchanting blog. Your site was off the chain and I
will return! I peep the web for blogs just like this
one.
It may look like it was hard work, but my business credit card blog was simple.
 
I look for blogs as great as your work. Fine
blog. I found your site suitable for another visit!
I'm looking at the possibility of checking your southern california plastic surgery blog.
 
Incredible blog. I admired your site and I will be
back once again to view it! I use much of my spare
time searching for blogs like yours.
You got me! I will check out your bad plastic surgery picture blog a.s.a.p!
 
Unusual blog. I liked the site its from so much I
have to visit it again! I surf the web for blogs like
yours in my spare time.
Click on my celebrity plastic surgery photo blog before its to late.
 
Irresistible blog. I look for blogs like this one
when time allows me to. I enjoyed the site and I'll
check it next time!
I want you to look for my plastic surgery philadelphia blog.
 
Unusual blog. I liked the site its from so much I
have to visit it again! I surf the web for blogs like
yours in my spare time.
Come as you are and look at my southern california plastic surgery blog.
 
I surf the web looking for blogs like this one.
Your site was on point and will be back again! Awesome
blog.
Please proceed to my good plastic surgery blog when you find the time.
 
Charming blog. Your site was off the chain and I
will return! When I get the time I look for blog like
this one.
Click on my plastic surgery nj blog before its to late.
 
Irresistible blog. I look for blogs like this one
when time allows me to. I enjoyed the site and I'll
check it next time!
Where you been? You have got to look at my disapointments plastic surgery blog!
 
Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
Want to see top notch work, peep my plastic surgery breast enlargement blog site for the bomb work!
 
I took pleasure in the site and I will go back!
Surfing online for blogs like this one is worth my
time. Sensational blog.
I beg of you, just check out my plastic surgery minneapolis blog.
 
Unbelievable blog. I can hardly wait to vist this
site again.I'm consistently looking up blogs like
this.
I wish I was like you, but I'll go and peep your plastic surgery before and after picture blog.
 
Prodigious blog. Loved it so much I went to it
again! Just go online and search for blogs that are
worth the value as yours.
Look into my plastic surgery san francisco blog.
 
Remarkable blog. I take the neccesary time to find
blogs that are just as good as the ones you do.
My costa rica plastic surgery blog, is something you need to peep out!
 
Great blog.  I just like the site and I will get a
visit again! In my spare time I usually try and look
for blogs just as neat as yours.
In my spare time I will look for your plastic surgery breast implant blog.
 
Wondrous blog. Your site was very pleasing and I
will go back again! I like surfing the net for blogs
as good as yours.
Search for my plastic surgery photo blog, it will leave you speechless.
 
Enchanting blog. Your site was off the chain and I
will return! I peep the web for blogs just like this
one.
Go and click my plastic surgery denver blog.
 
Super blog. I enjoyed the site and when I have the
time, shall visit the site again. Finding blogs this
good on the internet.
Please examine my plastic surgery houston blog as soon as you can.
 
Hot blog. When I get to seraching on the web for
blogs, its got to be like yours! And the site is off
the hook! I just kept coming back!
Sweetie, go and search my plastic surgery prices blog for what you need.
 
Nice blog. I seen the site and I adored the work,
that I want to visit it more each day! I like
searching for blogs that have the same content like
this one!
Search for my orange county plastic surgery blog, it will leave you speechless.
 
Enchanting blog. Your site was off the chain and I
will return! I peep the web for blogs just like this
one.
Please take a journey to my nose plastic surgery blog.
 
Extraordinary blog. Your site was hip and fresh
and we'll visit it again! I love surfing the internet
for blogs.
Check out my plastic surgery breast enlargement blog, you won't be sorry!
 
Great blog.  I just like the site and I will get a
visit again! In my spare time I usually try and look
for blogs just as neat as yours.
If your look to uncover information, please visit my unsecured credit card blog
 
Awesome blog. I'm loving the site and I have to
return there soon! Going online, when I have the time,
I look for blogs close to your work!
Jump into my plastic surgery before and after picture blog.
 
I surf the web looking for blogs like this one.
Your site was on point and will be back again! Awesome
blog.
Please examine my plastic surgery michigan blog as soon as you can.
 
Powerful blog. The site was incredible and will be
back again! Web surfing helps to find good blogs like
this one.
Check out the blog site with my plastic surgery photo in it!
 
Exciting blog. Your site was amazing and will be
back again! I never get tired of looking for blogs
just like this one.
I want you to look for my michael jackson plastic surgery blog.
 
I peep the web for blogs just like this one.
Airtight blog. Your site was off the chain and I will
return!
I wish I was like you, but I'll go and peep your plastic surgery pic blog.
 
Awesome blog. I'm loving the site and I have to
return there soon! Going online, when I have the time,
I look for blogs close to your work!
I know that you love my work so, look up my nose plastic surgery blog.
 
Nice blog. I seen the site and I adored the work,
that I want to visit it more each day! I like
searching for blogs that have the same content like
this one!
If your look to uncover information, please visit my lil kim plastic surgery blog
 
Excellent blog. It was so great and I bet I will
go back to it! I get to look online for blogs like
yours is a blessing.
I can't explain, but you need to check my awful plastic surgery celebrity blog!
 
Incredible blog. I admired your site and I will be
back once again to view it! I use much of my spare
time searching for blogs like yours.
Oh please, check for the blog site with my plastic surgery center!
 
Wondrous blog. Your site was very pleasing and I
will go back again! I like surfing the net for blogs
as good as yours.
Go and find my disapointments plastic surgery blog.
 
Suitable blog, its very good. I liked the site its
from so much I have to visit it again! I surf the web
for blogs like yours in my spare time.
You got me! I will check out your plastic surgery new york blog a.s.a.p!
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
Once you sign on, check for my plastic surgery gone bad blog.
 
Fine blog. I found your site suitable for another
visit! And when I'm able to surf the web, I look for
blogs as great as your work.
Please take a journey to my credit card debt help blog.
 
Fruitful blog. I favor your site and I shall
return to it! I go to sites like this when I get the
chance, and find blog just like this.
Stop by and visiit my pro and cons of plastic surgery blog!
 
Excellent blog. Your site was great and will be
finding it again!  I surf the net for blogs like
yours.
I hope you can look through my online credit card approval blog.
 
Exciting blog. Your site was amazing and will be
back again! I never get tired of looking for blogs
just like this one.
I can't explain, but you need to check my awful plastic surgery blog!
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
Oh please, check for the blog site with my orange county plastic surgery!
 
Great blog.  I just like the site and I will get a
visit again! In my spare time I usually try and look
for blogs just as neat as yours.
My plastic surgery minneapolis blog, is something you need to peep out!
 
I surf the web looking for blogs like this one.
Your site was on point and will be back again! Awesome
blog.
Go and click my american board of plastic surgery blog.
 
Hot blog. When I get to seraching on the web for
blogs, its got to be like yours! And the site is off
the hook! I just kept coming back!
I beg of you, just check out my cosmetic plastic surgery blog.
 
Super blog. I enjoyed the site and when I have the
time, shall visit the site again. Finding blogs this
good on the internet.
Please examine my picture of plastic surgery gone wrong blog as soon as you can.
 
Captivate blog. I surf the web for blogs this
nature.The site are wonderful and will be returned to
again!
I want you to look for my michael jackson plastic surgery blog.
 
I look for blogs as great as your work. Fine
blog. I found your site suitable for another visit!
Hey why don't you peep my plastic surgery breast augmentation blog site.
 
Cool blog. I dig your site outline and I plan on
returning again! I just love finding blogs like this
when I have the time.
Check out my plastic surgery new jersey blog, you won't be sorry!
 
Exciting blog. Your site was amazing and will be
back again! I never get tired of looking for blogs
just like this one.
Please proceed to my pro and cons of plastic surgery blog when you find the time.
 
Unusual blog. I liked the site its from so much I
have to visit it again! I surf the web for blogs like
yours in my spare time.
You got me! I will check out your teen credit card debt statistics blog a.s.a.p!
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
I hope you can look through my lil kim plastic surgery blog.
 
Creative blog.  I thought it was the best site out
and we had to go back to it! Every chance I get on the
net I search for blogs just like your site.
Oh please, check for the blog site with my plastic surgery minneapolis!
 
Irresistible blog. I look for blogs like this one
when time allows me to. I enjoyed the site and I'll
check it next time!
Click on my plastic surgery center blog before its to late.
 
Excellent blog. It was so great and I bet I will
go back to it! I get to look online for blogs like
yours is a blessing.
Go and click my plastic surgery seattle blog.
 
Unusual blog. I liked the site its from so much I
have to visit it again! I surf the web for blogs like
yours in my spare time.
Check out my plastic surgery new york blog, please!
 
Creative blog. I just kept looking at it over and
over! Im always looking for blogs like this!
Go and click my bad credit plastic surgery financing blog.
 
Terrific blog. I search the internet everytime I
get a moment to find blogs. Its better than cold iced
tea and I have to visit it one more time!
Look who checking out my plastic surgery michigan blog?
 
Captivating blog. I love surfing the web for the
type of blogs that you do. It had me on the edge of my
seat and I kept going back to again and again!
Please go over my plastic surgery seattle blog.
 
I look for blogs as great as your work. Fine
blog. I found your site suitable for another visit!
Look who checking out my bad plastic surgery blog?
 
Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
I will give you access to jump to my american express credit card blog.
 
Incredible blog. I admired your site and I will be
back once again to view it! I use much of my spare
time searching for blogs like yours.
Please take a journey to my plastic surgery texas blog.
 
Creative blog. I just kept looking at it over and
over! Im always looking for blogs like this!
Hey why don't you peep my plastic surgery tummy tuck blog site.
 
Energizing blog. It blew me away and I loved your
site. when I have the time to surf the net, i try
finding blogs as good as your site.
If your look to uncover information, please visit my liposuction plastic surgery blog
 
Captivate blog. I surf the web for blogs this
nature.The site are wonderful and will be returned to
again!
Search for my plastic surgery procedure blog, it will leave you speechless.
 
Powerful blog. The site was incredible and will be
back again! Web surfing helps to find good blogs like
this one.
Hey son, you need to check out my plastic surgery kansas city blog!
 
Suitable blog, its very good. I liked the site its
from so much I have to visit it again! I surf the web
for blogs like yours in my spare time.
I want you to stop and compare with my bad celebrity plastic surgery picture blog.
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
I beg of you, just check out my online credit card blog.
 
Awesome blog. I'm loving the site and I have to
return there soon! Going online, when I have the time,
I look for blogs close to your work!
Search for my bad celebrity plastic surgery picture blog, it will leave you speechless.
 
Suitable blog, its very good. I liked the site its
from so much I have to visit it again! I surf the web
for blogs like yours in my spare time.
Please examine my free credit card blog as soon as you can.
 
Striking blog. I liked the site I will be back
again! Websurfing is a good way to find blogs like
yours.
Want to see top notch work, peep my plastic surgery chicago blog site for the bomb work!
 
Energizing blog. It blew me away and I loved your
site. when I have the time to surf the net, i try
finding blogs as good as your site.
Jump into my pro and cons of plastic surgery blog.
 
Extraordinary blog. Your site was hip and fresh
and we'll visit it again! I love surfing the internet
for blogs.
Check out my celebrity plastic surgery photo blog, please!
 
Unique blog my friend, I can hardly wait to vist
this site again. I just worship the site its comes
from! Believe me in my extra time I'm consistently
looking up blogs like this.
Please take a journey to my plastic surgery fort worth blog.
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
I wish I was like you, but I'll go and peep your plastic surgery picture blog.
 
Inspiring blog. I love finding blogs this good on
the internet, when I have the time. I'm going to go
back to it!
You must peep out my plastic surgery for man blog.
 
Powerful blog. The site was incredible and will be
back again! Web surfing helps to find good blogs like
this one.
Hey playa! You need to check out my bad plastic surgery blog.
 
I look for blogs as great as your work. Fine
blog. I found your site suitable for another visit!
In my spare time I will look for your blog.
 
Fine blog. I found your site suitable for another
visit! And when I'm able to surf the web, I look for
blogs as great as your work.
I want you to stop and compare with my plastic surgery financing blog.
 
Great blog. I'm always finding blog like yours. It
got my attention and I will go to the site again!
I hope you can look through my credit card for people with bad credit blog.
 
Prodigious blog. Loved it so much I went to it
again! Just go online and search for blogs that are
worth the value as yours.
I beg of you, just check out my travel reward credit card blog.
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
Check out my demi moore plastic surgery blog, you won't be sorry!
 
Excellent blog.  I go though the web in search of
blogs like this one. Its so good, that I plan on
returning to its site!
Hey son, you need to check out my plastic surgery florida blog!
 
Inspiring blog. I love finding blogs this good on
the internet, when I have the time. I'm going to go
back to it!
Click on my picture of plastic surgery gone wrong blog before its to late.
 
I surf the web looking for blogs like this one.
Your site was on point and will be back again! Awesome
blog.
Go by and hit my male plastic surgery blog, you'll be glad you did.
 
Hot blog. When I get to seraching on the web for
blogs, its got to be like yours! And the site is off
the hook! I just kept coming back!
In my spare time I will look for your ear plastic surgery blog.
 
Striking blog. I liked the site I will be back
again! Websurfing is a good way to find blogs like
yours.
I'm looking at the possibility of checking your plastic surgery breast implant blog.
 
Energizing blog. It blew me away and I loved your
site. when I have the time to surf the net, i try
finding blogs as good as your site.
Once you sign on, check for my breast plastic surgery blog.
 
Energizing blog. It blew me away and I loved your
site. when I have the time to surf the net, i try
finding blogs as good as your site.
Hey why don't you peep my plastic surgery houston blog site.
 
Delightful blog. I devote my spare time just
looking for great blogs such as yours. I treasure this
site and will go back!
It may look like it was hard work, but my plastic surgery before and after photo blog was simple.
 
Super blog. I enjoyed the site and when I have the
time, shall visit the site again. Finding blogs this
good on the internet.
Stop by and look at my plastic surgery las vegas blog site.
 
Wondrous blog. Your site was very pleasing and I
will go back again! I like surfing the net for blogs
as good as yours.
Search for my risk of plastic surgery blog, please!
 
Fine blog. I found your site suitable for another
visit! And when I'm able to surf the web, I look for
blogs as great as your work.
I can't explain, but you need to check my credit card company blog!
 
Exciting blog. Your site was amazing and will be
back again! I never get tired of looking for blogs
just like this one.
Come as you are and look at my online credit card application blog.
 
Terrific blog. I search the internet everytime I
get a moment to find blogs. Its better than cold iced
tea and I have to visit it one more time!
It may look like it was hard work, but my nose plastic surgery blog was simple.
 
Excellent blog. It was so great and I bet I will
go back to it! I get to look online for blogs like
yours is a blessing.
My plastic surgery for man blog, is something you need to peep out!
 
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
Check out my plastic surgery loan blog, you won't be sorry!
 
Unbelievable blog. I can hardly wait to vist this
site again.I'm consistently looking up blogs like
this.
You got me! I will check out your breast plastic surgery blog a.s.a.p!
 
Astonshing blog. I relished in the site and you
know I will be going to it again! Surfing the internet
hepls me to find blogs that arfe just as good.
Sweetie, go and search my breast plastic surgery blog for what you need.
 
Excellent blog. Your site was great and will be
finding it again!  I surf the net for blogs like
yours.
Please come by and see my plastic surgery for man blog.
 
Great blog. I surf the web looking for blogs like
this. Your site was on point and will be back again!
I'm looking at the possibility of checking your plastic surgery before and after photo blog.
 
Fruitful blog. I favor your site and I shall
return to it! I go to sites like this when I get the
chance, and find blog just like this.
Check out my plastic surgery california blog, you won't be sorry!
 
Exciting blog. Your site was amazing and will be
back again! I never get tired of looking for blogs
just like this one.
Check out the blog site with my long island plastic surgery in it!
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?