General information
Category:
Coding, syntax & commands
>What 'types' of programs do you recommend using recursion? I've used them for multi-level types of organizations and relationships where they seem to do well. I'm curious as to other types of applications as well.
Here's the rule of thumb given by one of my professors:
You assume that:
1. You have a little devil-slave that knows how to calculate MyProblem(x)
and
2. You know how to go from y to x
and
3. You know when to stop
Then it's easy to apply a recursive solution:
func MyProblem
lparam y
if MyStopCondition(y)
return whatever && This is my precious knowledge
else
x = NextStepParam(y) && Again, my knowledge
a = MyProblem(x) && Again, my knowledge
return Operate(a, y) && Again, my knowledge
endif
And, as it can be seen, there's no little devil involved at all... :) The devil-slave is just the above pattern. In practice,
there are three important things: the above pattern, the stop condition (very important to be sure that it will
be meet for all cases) and the formula to go from one step to the other (params and result).
Obviously, NextStepParam and Operate can be simple formulas.
Vlad
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only