News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Understanding Recursion
June 06, 2013 @ 09:32:41

On PHPMaster.com today there's a new tutorial posted that talks about something that can be a more difficult concept for budding developers to grasp - recursion.

In one of my previous articles I wrote about iterators and how you can use them. Today I'd like to look at the fraternal twin of iteration: recursion. A recursive function is one that calls itself, either directly or in a cycle of function calls. Recursion can also refer to a method of problem solving that first solves a smaller version of the problem and then uses that result plus some other computation to formulate an answer to the original problem.

He starts with an example - one function showing how to calculate a factorial using just looping and the other by having the function call itself. He talks some about the different types of recursion (direct/indirect) and gives a more practical example, a "find in array" function for one with nested subarrays. He also briefly mentions "head" and "tail" recursion, the difference being if it waits for a return value or not. He also offers some general advice when it comes to using recursion and how you have to watch for optimization issues.

0 comments voice your opinion now!
recursion tutorial introduction head tail direct indirect

Link: http://phpmaster.com/understanding-recursion

blog comments powered by Disqus

Similar Posts

Web Development Blog: Sending e-mails via SMTP with PHPmailer and Gmail

DevShed: An Introduction to Simulating the Model-View-Controller Schema in PHP

Jason Gilmore's Blog: How I Learned to Stop Worrying and Love Zend_Form

Markus Pullmann's Blog: Remote Debugging in PHP with XDebug

PHP-GTK Community Site: Accessing geo-nick with Zend Framework (Zend_XmlRpc_Client)


Community Events





Don't see your event here?
Let us know!


install interview code framework introduction threedevsandamaybe series release unittest list refactor wordpress opinion laravel configure podcast testing community language developer

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework