Math, asked by kshrd4738, 1 year ago

Discuss the purpose of a stack in implementing a recursive procedure? Explain.

Answers

Answered by BrainlyHeroSumit
7

Answer:

there is no a prior limit on the depth of nested recursive calls (that a recursive function may call itself any no. of times), we may need to save an arbitrary number of register values(return values of the recursive functions, that may be used latter to find the actual solution). These values must be restored in the reverse of the order in which they were saved, since in a nest of recursions the last subproblem to be entered is the first to be finished. This dictates the use of a stack, or ``last in, first out'' data structure, to save register values. We can extend the register-machine language to include a stack by adding two kinds of instructions: Values are placed on the stack using a save instruction and restored from the stack using a restore instruction. After a sequence of values has been saved on the stack, a sequence of restores will retrieve these values in reverse order.

Similar questions