Alsalamu Alikum,

So, It's my first time to study and work on recursion functions, and it was said in the lecture that it is better than the iterative function because

they are shorter, more elegant, more readable, naturally developing and it's code is easier to understand.It comes with more cost in memory space and execution speed. and however the performance penalty is negligible and it's worth the extra clarity.

and I've asked my TA in the collage and he said that there is no a real programmer who doesn't deal with recursive functions.

But I've worked on some programs made by the prof. , and in each one I found that the iterative function is simpler in the idea, more readable and easier in understanding.
So would anyone tell me more about recursion and it' advantages and disadvantages.

It's my first post , so sorry for talking so much.and thanks in advance

Don't you think Googling it and finding it out for yourself would be a better and more learning oriented approach ?

I would argue that the majority of code people write is iterative rather than recursive. Because recursion has more overhead in terms of memory and speed, iterative approaches are generally preferred unless the recursive version is much simpler to understand and implement. I'd say the biggest downside to recursion is that function calls require stack space which is usually very limited, and if you try to recurse too deeply you will stack overflow and crash your program (try recursing a million times and you'll see).

I find recursion simpler to understand when it's applied to some sorting algorithms (mergesort, quicksort), and tree structures (you will see these in a data structures course). Of course, when you first start learning recursion, almost every problem will seem easier to understand iteratively. Once you gain more experience with recursion it will become easier to understand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.