Search /
Docfinder:
Advanced search  |  Help  |  Site map
RESEARCH CENTERS
SITE RESOURCES
Click for Layer 8! No, really, click NOW!
Networking for Small Business
TODAY'S NEWS
The botnet world is booming
What’s driving this university to IPv6? Going green
IT pros continue to lose jobs
How ending exclusivity agreements would change the telecom industry
How to use electrical outlets and cheap lasers to steal data
EMC distances rival NetApp
Crime lab saves energy costs by turning up heat in the data center
IBM security software masks confidential info
Google Native Client provides hints on Chrome OS gambit
Ericsson signs deal to run Sprint wireless, wireline networks
Verizon helping companies assess application vulnerabilities
Internet's biggest issue? IPv6 transition, new ARIN CEO says
Gmail, other Google apps, out of beta
Microsoft may have known about critical IE bug for months
Symantec de-duplication strategy targets data growth, virtual machines
Windows 7 ramp-up will be sharp
Applications /

Recursive call or loop

Related linksToday's breaking news
Send to a friendFeedback

Sign up to receive this and other networking newsletters in your inbox.

It should come as no surprise to you that you can write any recursive call with a " for " or a " while " loop. So why would you consider writing code that makes recursive calls?

Advertisement:

The first answer to this question usually comes in the form of a statement of surprise from many programmers I talk to. " I did not even know there was any other way to do this . . . "

The first rule to consider is that if a problem can be solved effectively and quickly using loop constructs then that should be your first choice. For most algorithms loops are easier and quicker to write and are a natural component of your programming arsenal. Before you start thinking about moving a loop to a recursive call rather explore tightening the loop, make it more efficient.

Recursive method calls or algorithms, however, often offer us a natural and elegant way of dealing with a complex problem, and this is the reason I brought the subject up over the past few weeks. We are going to look at some data structures that can be elegantly manipulated with recursive algorithms.

You will find that many algorithms are inherently recursive and those may be better coded with recursion than loops. Keeping the method and the size of the data structure that is being worked on small is very important. This is because recursive calls tend to impact the call stack, especially when the dataset explodes.

A good example (or a bad example depending on how you look at) of such a case is processing the Fibonacci series:

fibonacci(0) = 0

fibonacci(1) = 1

fibonacci(n) = fibonacci(n-1) + fibonacci(n - 2)

Processing Fibonacci 20 results in 21,891 calls, but processing Fibonacci 30 quickly racks up more than seven million recursive calls - clearly if you keep going you'll send the call stack into oblivion.

Next issue I'll provide a list of specific tips for using recursion as we prepare to get our hands a little green pruning trees and similar data structures.

 

RELATED LINKS

Jeffrey Shapiro is a software development expert and well-known author. He has written several books, which include the widely acclaimed Computer Telephony Strategies, by Hungry Minds, and Visual Basic .NET Headstart by Osborne/McGraw-Hill. You can reach him by e-mail at java-pro@mcity.org.


NWFusion offers more than 40 FREE technology-specific email newsletters in key network technology areas such as NSM, VPNs, Convergence, Security and more.
Click here to sign up!
New Event - WANs: Optimizing Your Network Now.
Hear from the experts about the innovations that are already starting to shake up the WAN world. Free Network World Technology Tour and Expo in Dallas, San Francisco, Washington DC, and New York.
Attend FREE
Your FREE Network World subscription will also include breaking news and information on wireless, storage, infrastructure, carriers and SPs, enterprise applications, videoconferencing, plus product reviews, technology insiders, management surveys and technology updates - GET IT NOW.
* HOME    * RESEARCH CENTERS     * NEWS     * EVENTS

Contact us | Terms of Service/Privacy | How to Advertise
Reprints and links | Partnerships | Subscribe to NW
About Network World, Inc.

Copyright, 1994-2006 Network World, Inc. All rights reserved.