Replies To: Recursion

Re: Recursion

Posted 29 July 2008 - 08:30 AM

On the fence, voted no ( currently only one out of five to do so ).

Recursion is very clever. It can do vary particular things in an elegant way. It can functionally create a limited dynamic array by using the stack in an out side the box kind of way. I've used it for a number of cases where it was the cleanest, shortest path to the answer, but...

Recursion also seems to propagate the kind of mystical non intuitive snippets that C programmers take such joy in. In one sense, it's hard to truly grasp whats initially going on. Then, when the beginner inevitably gets there stack overflow, that answer to why it happened can be even less clear.

Recursion makes for very clean implementation of very complex algorithms, particularly the divide and conquer stuff. However, I suspect it is generally offered too soon in a curriculum to do the beginner any favors. Also, in the end, it is kind of a hack.

Re: Recursion

Posted 29 July 2008 - 10:52 AM

baavgai, on 29 Jul, 2008 - 11:30 AM, said:

Recursion also seems to propagate the kind of mystical non intuitive snippets that C programmers take such joy in. In one sense, it's hard to truly grasp whats initially going on. Then, when the beginner inevitably gets there stack overflow, that answer to why it happened can be even less clear.

That's true, but I think for something like crawling a tree of nodes the alternatives are worse.

I never learned about recursion in any of my computer science classes. I actually picked it up while reading a book on Lisp.

Re: Recursion

Re: Recursion

Posted 30 July 2008 - 05:03 AM

A poll about how awesome recursion is. Seems kind of random. Why not have a poll about how cool derivatives are? Nevertheless, I'll weigh in and say that, while recursion does solve many problems cleanly and often is easily translated from a proof by induction, it is not as efficient as one would hope on today's typical architectures and should be used sparingly. First, space is a factor as the stack must store state at each recursive function call. Second, speed (time) is a factor. A function call is almost always more expensive that a jump (used in iteration) as it requires allocating and later releasing local memory, copying parameter values into local memory, and branching and returning. Elegance and conciseness are nice to have, but they are usually never as important as efficiency and readability.

Re: Recursion

Posted 30 July 2008 - 05:31 AM

However the recursive divide and conquer algorithms tend to lend themselves to the creation of concurrent algorithms. With Intel working on packing as many cores onto a die as they can cram in, it would seem that the future of computing is going to require more and more work in concurrency.

I voted for awesome. (course that may just be because I have been working in concurrent programming recently.)

Re: Recursion

Posted 30 July 2008 - 01:25 PM

I wasn't sure what to vote because I can see the use of recursion, but I try to use it sparingly as Programmist pointed out. Basically I don't use recursion just for recursions sake, but for the increase in efficiency or speed compared to the alternatives. So if you could make that bold part an answer, it would be perfect

Re: Recursion

Posted 31 July 2008 - 06:06 AM

NickDMax, on 30 Jul, 2008 - 05:31 AM, said:

However the recursive divide and conquer algorithms tend to lend themselves to the creation of concurrent algorithms. With Intel working on packing as many cores onto a die as they can cram in, it would seem that the future of computing is going to require more and more work in concurrency.

I voted for awesome. (course that may just be because I have been working in concurrent programming recently.)

True. This is what I meant when I said it solves some problems cleanly. I'd be interested to hear any data on the increase in speed, on a multicore/SMP machine, from a regular merge sort to one that spins off a new threads on a split.

Re: Recursion

Posted 01 August 2008 - 04:20 AM

I hate recursion for every reason presented on the hater fence. a) Every time I tried to do it in C# or VB.NET it would give me a stack overflow, b ) It's messy (do you call frizzy red heads elegant?) and c) iterations are easier for my mind to comprehend.