Question: Explain recursion as an application of stack with examples
0

Mumbai University > Computer Engineering > Sem 3 > Data Structures

Marks: 10M

Year: May 2016

ADD COMMENTlink
modified 2.1 years ago  • written 2.1 years ago by gravatar for Barkha Barkha750
0
  1. The High level Programming languages, such as Pascal , C etc. that provides support for recursion use stack for book keeping.
  2. Remember, in each recursive call, there is need to save the current values of parameters, local variables and the return address (the address where the control has to return from the call).
  3. Also, as a function calls to another function, first its arguments, then the return address and finally space for local variables is pushed onto the stack.
  4. Since each function runs in its own environment or context, it becomes possible for a function to call itself a technique is known as recursion.
  5. This capability is extremely useful and extensively used because many problems are elegantly specified or solved in a recursive way.
  6. The example of recursion as an application of stack is keeping books inside the drawer and the removing each book recursively.
ADD COMMENTlink
written 2.1 years ago by gravatar for Barkha Barkha750
Please log in to add an answer.