PerlSensitive Sunglasses  
PerlMonks 
Re: Behold! The power of recursion.by davido (Archbishop) 
on Oct 18, 2004 at 01:52 UTC ( #400027=note: print w/replies, xml )  Need Help?? 
I wanted to point out that your "guess the number" algorithm is O(log N) in its computational efficiency. What that means is that as the dataset (or in this case, the size of the range in which the secret number may be hidden) grows by "N", the amount of work needed to find the secret number grows by "log N". This happens to be, roughly, the same algorithm used in a binary search, which is known to be O(log N) too (of course). The recursion is mostly a convenience here. An iterative approach could be used to implement the same basic algorithm, but recursion is kinda cool. :) By the way, Perl (with warnings turned on) warns you when your recursion level reaches 100 levels deep. You can turn this off, if I recall, with "no warnings qw/recursion/;". Dave
In Section
Seekers of Perl Wisdom

