Search

Tuesday, March 11, 2014
0 comments

Recursion for Data Structure in C programming

7:03 AMTuesday, March 11, 2014
Recursion:


          Recursion is another good example of programming field where STACK is used. Recursion is an art of programming or a technique in programming in which the subprogram calls itself. In programming usually when a subprogram is written it is called in main program. Using a statement in the main program can do a call to the subprogram. If a call statement of the subprogram is used within the definition of the same subprogram then it is termed as recursion.
                                        Whenever a function (in case of C the subprogram is function) call is made in main program the control transfers to the function, the function is executed and control transfers back to the calling point. Note here that the internal STACK is used to store the address of the next instruction that is to be execution completes.

                                   main()
                                  {
                                     -----;
                                     fun();
                                     -----;<------------address of this instruction is stored in STACK
                                  }
                                   fun()
                                   {
                                      ----:
                                    }
                   The recursion can be used to solve certain problems where the problems have base condition. When the base condition is satisfied the call should terminate otherwise a call is made again with changed value. Means recursion is used only in those cases when the same set of statements are to be executed again and again with changed value and that changed value reaches to base condition the recursive call should terminate.

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top