calling ?

Answers were Sorted based on User's Feedback

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 ? 133 Yes 53 No

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.

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 ? 102 Yes 30 No

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

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 ? 66 Yes 8 No

advantage:using recursion we can avoid unnecessary callingof
functions.
disadvantage:recursive calling increase the space complexity.

 Is This Answer Correct ? 45 Yes 15 No

Use of recursion in an algorithm has both advantages and
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 ? 26 Yes 5 No

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 ? 26 Yes 7 No

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 ? 20 Yes 12 No

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 ? 6 Yes 1 No

1. It is requires extra storage space. The recursive calls and automatic variable a stored on the stack. For every calls separate memory is allocated to automatic variable with the same name.
2. the recursion function is not efficient in execution speed and time.
3. Some function called inside recursion are repeated or duplicated just like Fibonacci.

 Is This Answer Correct ? 2 Yes 0 No

recursive functions can be effectively used to solve
problems where the solution is expressed in terms of
applying the same solution.
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 ? 22 Yes 35 No

More C Interview Questions

What is the difference between big endian form and little endian form? write a code to convert big endian form to little endian and vice versa..

Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

how can make variable not in registers

what is the differnce between AF_INET and PF_INET?

Write a c program using for loop in switch case?

What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort

what are bit fields? What is the use of bit fields in a structure declaration?

1. Write a c pgm to print 1 to 100 without using loops. 2. Write a c pgm for leap year 3. Write a c pgm fibbonacci series,factorial 4. Write a c pgm count no of lines , blanks, tabs in a para(File concept) 5. Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6.how do get the o/p in number from 1 to 100 in the screen without using control statement? 7. who do u print the word "hello world" without using "printf" statement? 8. write sql program to get the detail of student in a class? Definitions: structure union arrays linkedlist macros directives difference b/w pre processorsDiffrence: 1.Constructors and destructors 2.Structure and Union 3.Array and Lists 4.pre processor... 5. Privillages in C++ 6.structure and union 7.break and continue 8.while and dowhile Pgm..

can u suggest me am in a confusion to choose whether to go to c programming or a software testing . am a graduate in B.sc(electronics).

34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

what do structure language means?

Categories