From: Sam Kong Date: 2007-01-24T04:35:17+09:00 Subject: Re: I need a more efficient algorithm for this problem. James Edward Gray II wrote: > On Jan 23, 2007, at 11:40 AM, Sam Kong wrote: > > > Hi James, > > > > James Edward Gray II wrote: > >> You can always unroll recursive code into an iterative solution: > > > > Right. But some recursions are harder to unroll than others.^^ > > You're not the first person to say that to me, but I still don't > believe it. ;) > > Think of it this way. All recursion is doing for you is managing the > call stack. You can always do that yourself. > > Just use an Array for the stack and put all the local variable in > it. That's always works for unrolling recursion. Period. > > Frequently you can get away with much less too. In my example > earlier in this thread, note that I didn't even need all the local > values to unroll it. > > It just takes practice to think this way. I'll take your words. Thank you very much for your advice.:-) > > James Edward Gray II Sam