To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 4983
4982  |  4984
Subject: 
RE: Would-be hacker queries.
Newsgroups: 
lugnet.robotics
Date: 
Tue, 11 May 1999 15:50:14 GMT
Original-From: 
Joel Shafer <JOEL@spamcakeCONNECT.NET>
Viewed: 
750 times
  
Searching and replacing is a good example of recursion.  Suppose that you
are editing a document and want to replace every occurrence of the word
"the" with the word "then".  Here is one way that the program could handle it.


Function Replace(OriginalText,SearchFor,ReplaceWith) returns modified string

Find the first occurance of SearchFor within OriginalText
If SearchFor wasn't found then just return the OriginalText

Return the text before the first occurrence + ReplaceWith + Replace(Text
after first occurrence)   /*  This is where the recursion occurs */

End Function

This function solves the first little piece of the problem by replacing the
first occurrence, and then uses recursion to solve the rest of the problem.




At 07:46 AM 5/11/99 -0700, you wrote:
At 05:44 PM 5/10/99 -0400, Blake Winton wrote:

Eric Lind wrote:
recursion - the process of one function calling itself to solve a • problem.

You might want to add the recursive part of this example
(namely 6! = 6*(5!), and 5! = 5*(4!), and so on,

You know, I have never really liked the factorial example of recursion.
Honestly, how many times have you really needed to generate a factorial in
general experience?

I feel a better example is building stuff with LEGO. In this case, you are
the function and the LEGO is the data.

The basic function you perform is sticking blocks together. So to build a
rocket ship, you first need to attach the body to the engine. To build the
engine you need to attach the intake to the exhaust, and so on. As you
progress, you may be generating very complex items, but you are still
performing the same basic action, attaching one block to another.



        Aloha,
        JR
- - - - - - - - - -
JR Conlin                  jrconlin@email.com
Techno-Athiest          yahooPage: jrconlin
                           <http://home.earthlink.net/~jrconlin>
--
Did you check the web site first?: http://www.crynwr.com/lego-robotics


Joel Shafer    joel@connect.net

--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



Message has 2 Replies:
  RE: Would-be hacker queries.
 
(...) You are right, but recursion carries a terrible price in terms of stack usage. Most recursion is useful for implementing search and traversal algorithms, but unless the hardware supports DEEP stacks for the worst case, the problem is almost (...) (25 years ago, 11-May-99, to lugnet.robotics)
  RE: Would-be hacker queries.
 
It's too bad that recursion pays the price of stack usage. Recursion is almost always a more elegant solution and is more easily maintained. But as it is, recursion should only be used when you know that the worst case scenario won't overflow the (...) (25 years ago, 11-May-99, to lugnet.robotics)

Message is in Reply To:
  RE: Would-be hacker queries.
 
(...) problem. (...) You know, I have never really liked the factorial example of recursion. Honestly, how many times have you really needed to generate a factorial in general experience? I feel a better example is building stuff with LEGO. In this (...) (25 years ago, 11-May-99, to lugnet.robotics)

21 Messages in This Thread:






Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR