ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
What are advantages and disadvantages of recursive 
calling ?
 Question Submitted By :: Leossk
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 1
advantage:using recursion we can avoid unnecessary calling 
of functions.
disadvantage:by too many recursive functions there may be 
confusion in the code.
 
Is This Answer Correct ?    15 Yes 6 No
Santhi
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 2
Advantages:
Through Recursion one can Solve problems in easy way while
its iterative solution is very big and complex.
Ex : tower of Hanoi 
You reduce size of the code when you use recursive call.

Disadvantages :
Recursive solution is always logical and it is very
difficult to trace.(debug and understand)

Before each recursive calls current values of the varibles
in the function is stored in the PCB, ie process control
block and this PCB is pushed in the OS Stack. 
So sometimes alot of free memory is require for recursive
solutions.

Remember : whatever could be done through recursion could be
done through iterative way but reverse is not true.

 
Is This Answer Correct ?    10 Yes 7 No
Sachin Mahajan
 
 
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 3
advantages ;
recursive functions can be effectively used to solve 
problems where the solution is expressed in terms of 
applying the same solution.
disadvantages ;
in recursive we must have an if statement somewhere to 
force the func. to return without the recursive call being 
executed.otherwise the funct. will never return.
 
Is This Answer Correct ?    1 Yes 8 No
Swapna
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 4
Advantage :

Recursion is used to divide the problem into same problem 
of subtypes and hence replaces complex nesting code.

Disadvantage :

Recursion takes a lot of stack space, usually not 
considerable when the program is small and running on a PC.

It is very hard to debug or extend the functionality in 
case of recursive logic.
 
Is This Answer Correct ?    7 Yes 1 No
Anonymous
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 5
advantage:using recursion we can avoid unnecessary callingof
functions.
disadvantage:recursive calling increase the space complexity.
 
Is This Answer Correct ?    4 Yes 5 No
Rahul
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 6
Why is recursion frowned upon??

User space programs: memory consumption
----------------------------------------
User stack is a dynamic stack i.e. we page fault on the 
stack virtual addresses and resolve the fault by allocating 
a physical page. Many recursions can lead to a lot of (user 
stack) memory being consumed. In a traditional programming 
model, when a thread blocks, then all the memory is stuck 
with the thread, until the paging daemon kicks it out. So, 
effectively, many threads doing recursive calls can consume 
a lot of memory and force memory pressure to occur in the 
system i.e. system slows down.
 
Kernel Space program: stack depth
---------------------------------
A kernel stack is fixed in size i.e. 8K or 16K usually. And 
this stack does not grow dynamically in most OSes. So, 
there is a bound on how much memory can be used for the 
kernel stack, unlike user programs. But, this bound on the 
stack size is the reason why recursion is discouraged. More 
recursive levels can lead to a stack overflow and this will 
panic the box. One might say: hey, my recursive depth is 
only 10. But, what is unknown is what amount of kernel 
stack is already used up && the stack frame consumption 
depends on the chip architecture that is being used.
 
For both of the above reasons, recursion is avoided in 
general kernel programming.
 
Is This Answer Correct ?    5 Yes 2 No
Sk_seeker
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 7
Use of recursion in an algorithm has both advantages and 
disadvantages. The main advantage is usually simplicity. 
The main disadvantage is often that the algorithm may 
require large amounts of memory if the depth of the 
recursion is very large. High memory consumption is due to 
large function call number (recursion means that function 
calls itself multiple times).
 
Is This Answer Correct ?    2 Yes 1 No
Morfy
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 8
the advantage of recursion is      
1). by using this tag we call a function continuosly uptill 
to specific condion
 
Is This Answer Correct ?    0 Yes 2 No
Deepak Soni
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 9
by using this tag we call a function continuosly uptill 
to specific condion
 
Is This Answer Correct ?    0 Yes 1 No
Poonam Yadav
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 10
advantage : A recursive definition defines an object in simpler cases of itself reducing nested looping complexity

disadvantage : less efficient as compared to the non-recursive counterparts as the overhead involved in entering,re-entering and exiting a block is avoided in case of the non recursive forms. its also possible to identify a number of local variables which need not be saved and restored with the help of stacks and this unwanted stacking activity is avoided in the non-recursive versions.
 
Is This Answer Correct ?    3 Yes 0 No
Ganesh Narayanan
 
  Re: What are advantages and disadvantages of recursive calling ?
Answer
# 11
disadvantage:
Recursive procedures are huge memory hogs. Also, they're a 
nightmare to debug. Finally, it's pretty rare to find an 
application that actually needs recursion as opposed to a 
simpler, more friendly methodolgy.
 
Is This Answer Correct ?    0 Yes 0 No
Nishu
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]  2
Study the Following Points: a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static 1. Which of the Following Statements are true w.r.t Bit- Fields A)a,b&c B)Only a & b C)Only c D)All Accenture2
5. distance conversion: Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer  1
if ENTERED FIVE DIGITS DESIGN A PROGRAM THAT WILL FIND CORRESPONDING VALUE FROM ASCII TABLE  1
write a 'c' program to sum the number of integer values  5
Write code for initializing one dimentional and two dimentional array in a C Program? Deshaw5
what is the use of #pragma pack, wer it is used? Wipro1
Name the language in which the compiler of "c" in written? Bajaj1
find largest element in array w/o using sorting techniques. Zycus-Infotech2
write the program for prime numbers? TCS10
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE? Wipro2
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means.... TCS1
Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.  7
disadvantages of realloc ? HCL1
what's the o/p int main(int n, char *argv[]) { char *s= *++argv; puts(s); exit(0); } Motorola1
write a program in c language for the multiplication of two matrices using pointers? Ignou5
what is the different between if-else and switch statment (other than syntax) CTS9
Given an unsigned integer, find if the number is power of 2?  4
f=(x>y)?x:y a) f points to max of x and y b) f points to min of x and y c)error HCL4
class foo { public: static int func(const char*& p) const; }; This is illegal, why? Google6
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com