Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Argument starter - The roots of all evil
Message
 
To
12/09/2004 14:08:33
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00938079
Message ID:
00942692
Views:
35
>Hi george,
>
>>I don't know about "...thread recursive" here< s >, but some of the basic algorithms I have seen do implement this recursively. My problem with that is that it not only tends to "cloud" things, but doesn't perform as well because of the recursive calls.
>
>A basic example how to this recursively is the following.
>
>
FUNCTION SearchArray2(aArray, cSearchValue, nStart, nEnd, nIndex)
>
>RETURN IIF(nStart > nEnd, 0, ;
>	IIF(aArray[nIndex] > cSearchValue, SearchArray2(@aArray, @cSearchValue, @nStart, nIndex - 1, INT((nStart + nIndex -1)/2)),;
>	IIF(aArray[nIndex] < cSearchValue, SearchArray2(@aArray, @cSearchValue, nIndex+1, @nEnd, INT((nIndex+1+nEnd)/2)), nIndex)))
>
>And indeed it clouds things and because of the stack overhead in calling functions causes this algorithm to be significantly slower than a DO WHILE or FOR NEXT solution.
>
>However some circumstances do call for a recursive solution, like the programming challenge calvin hsia did attend to to solve a phone number - words problem. Just when using private or local variables that can be totally hidden from the calling level and reusing the same code in which the same variable name is used. Not using recursivism would just complicate things as calvins code did demonstrate.
>
Walter,

This problem doesn't require a recursive solution, even though one could be implemented. However, in some cases a recursive solution isn't only the best way, it's the only way.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform