Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Drawbacks of Recursive function

Status
Not open for further replies.

A.Rashad

Member level 4
Joined
Jul 27, 2011
Messages
69
Helped
6
Reputation
10
Reaction score
5
Trophy points
1,288
Location
Pune
Activity points
1,792
HI ,
can any one suggest , what are the disadvantages of recursive functions ?
 

A.Rashad said:
what are the disadvantages of recursive functions ?
The main disadvantage is often that the algorithm may require large amounts of memory if the depth of the recursion is very large.
Recursion - Wikipedia, the free encyclopedia

This could be stack or heap space (it depends what it is used in the recursive function). Also there is the possibility to fall into an infinite loop if you call it in a wrong way, which will lead to stack or heap overflow and code hang. Finally, it could sometimes be difficult for someone to understand and analyse the code.
 
Last edited:

Recursion - Wikipedia, the free encyclopedia

This could be stack or heap space (it depends what it is used in the recursive function). Also there is the possibility to fall into an infinite loop if you call it in a wrong way, which will lead to stack or heap overflow. Finally, it could sometimes be difficult for someone to understand and analyse the code.

Hi,
Does In recursive functions push and pop operations onto stack happens ? I am confused that , fucnction calls itself , so all the current variables are same in called function , so why to store them on stack ?
 

A.Rashad said:
Does In recursive functions push and pop operations onto stack happens ? I am confused that , fucnction calls itself , so all the current variables are same in called function , so why to store them on stack ?
Having the same name doesn't mean that they share the same address as well. Otherwise recursive functions could not work.
Every time the function calls itself, the stack size is incremented equally to the variables which must be stored in there by the recursive function. If you want to share the load so that the stack will not be overloaded, you also have the heap option, which means that you 'll be using memory as you go dynamically. You can achieve this with memory allocation.
C dynamic memory allocation - Wikipedia, the free encyclopedia


Hope this helps,
Alexandros
 

Nice , Now I got clear ...Actually yesterday INTEL asked me this question in Interview...:)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top