Need suggestions

This is a discussion on Need suggestions within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hi! I have to find a programming problem that can be solved with iterative and recursion way (sorry for bad ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Lightbulb Need suggestions

    Hi!

    I have to find a programming problem that can be solved with iterative and recursion way (sorry for bad English ). So if you have an idea please post it.

    Thanks.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Most, if not all, recursive functions can be made iterative by removing the recursion. For example the faculty function, this is usually given as a recursive definition:

    n! = n * (n-1)!

    When expanded it is:

    n! = n * (n-1) * ... * 2 * 1

    From this it can be seen that you could remove the recursion by introducing a variable i so that:

    n! = P (i=1 to n) i

    Where P is the product quantor.

    [edit]
    So I'd suggest you take a recursive solution to a problem and make it iterative. Using Google to search for "examples of recursion" leads you to a lot of applications which make use of recursion. Like sorting, the towers of Hanoi, etc.
    [/edit]
    Last edited by Shiro; 10-31-2002 at 12:04 PM.

  3. #3
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    k-approximation. A lovely little algorithm which is used for finding alternative spellings in spell checkers.

    Here, I've done 99% of your home work for you:

    help on recursion.

    See the last post.

    You would probably want to pull out the AnsiStrings & use char* instead. This would actually be much quicker & memory efficient, as currently it is actually creating a new string on the stack each time it recurses.
    Last edited by Davros; 10-31-2002 at 12:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions?!
    By liljp617 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-20-2008, 12:12 PM
  2. Free Book Suggestions!
    By valaris in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-08-2008, 11:25 AM
  3. Math Book Suggestions
    By curlious in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-09-2003, 11:43 AM
  4. Learning C for OSX, tutorial suggestions please
    By Nexum in forum C Programming
    Replies: 2
    Last Post: 02-17-2003, 04:57 AM
  5. Suggestions.
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 02-06-2002, 12:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21