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.
Vishal Srivastava
MCA, LU
source : http://mitpress.mit.edu/sicp/full-text/sicp/book/node110.html
A recursive approach to a problem solution involves doing something, and then setting the results aside for a moment while you go do that same something again with different parameters in a nested fashion. That nested call may yet make another nested call, setting aside its results, and on and on...
Ultimately, one of the nested calls returns. When that happens, you want to go back to where you were before you made that last nested call, and pick up the calculation where you left off, finish it, and return. This process repeats, effectively unwinding the nesting sequence in the reverse order in which it was made.
A stack is a perfect vehicle to accomplish this with, because the order in which things get popped off of the stack is the reverse order in which they were originally pushed on. Typically, the stack contains saved registers, local variables, and formal parameters, all intermingled in the order in which they were saved, all returned in the reverse order.
A stack is a data structure that contains information that is retrieved in the reverse order of it being stored. In other words, it is a LIFO - Last In First Out, type of structure. The stack is perfectly suited for recursive functions because the stack can store the function parameters and local variables, LIFO, as the recursion depth increases. This "saves" the state of the function at the point of recursion, and then unwinds the stack when the function finally does return.
The classic example of a recursive function is the factorial function...
int nfact (n) if (n < 2) return n; else return n * nfact (n - 1);
...if you analyze the stack, you will see that it contains alternating copies of partial products along with decrementing N's, until N reaches 1, at which point everything unwinds.
The role of the call stack is the same regardless of whether a function call is recursive or not. The call stack is used to store the return address of the calling function. It is also used to provide storage for the function's local variables including its formal arguments.
Return addresses remain on the call stack until a function ends or returns, at which point the return address is popped from the stack and control is returned to that address. In this way, functions can call other functions (including themselves) without ever losing track of where those calls originated.
Using the call stack to store formal arguments and local variables is faster than allocating memory from the heap because the call stack is already allocated. Each thread has its own call stack which is allocated when the thread is instantiated and is released when the thread terminates. A call stack pointer keeps track of the top of the call stack (the next unused address), thus pushing and popping values to and from the call stack has minimal runtime cost. However, the call stack is fixed size (determined at compile time) and the caller cannot reference call stack memory utilised by the callee upon return from the callee because that memory is no longer in scope and may change at any time. Hence we use the heap to maintain large data structures as well as to allow the caller and callee to share memory.
A Java class is expected to have all functions defined. The purpose of defining the methods is to decide on its expected functionality and behavior. Only in case of Interfaces we declare methods but leave the method definitions to the implementing classes.
the purpose of a subheading is to explain a little more about the heading
The goal of the procedure is to improve valve function and blood flow by enlarging the valve opening. It is sometimes used to avoid or delay open heart surgery and valve replacement.
It is a set of rules or a procedure for carrying out certain calculations.
It is an organized procedure for a group of peers to review and discuss the technical products such as requirements,design,source code documentation to detect faults,violations of development standards and other problems of a system.NOTE:The purpose of structured walk-through is to detecterror correction and not discuss error correction.objectives:to detect errors and to improve the quality of the system.to detect faults and violations of development standards.to improve organizations confidence in newly developed system.
active control method
The purpose of Parliamentary Procedure is to keep a meeting running smoothly and to make sure everyone has a fair say in what is proposed to do.
the purpose...... it yet to be known
the purpose is to entertain and explain
explain info
briefly explain purpose of kohler illumination
to explain the process currently
social audit
COSO
the purpose of a subheading is to explain a little more about the heading
briefly explain purpose of kohler illumination
The purpose of the general format and layout is that it gives you a standard procedure.