applications of stacks and their uses?
Answer Posted / shreyank
Keeping track of nested invocation calls in a procedural
programming language, such as C/C++.
Each function call results in a new entry being placed into
the program run-time stack. This new
entry contains memory space for local variables (which can
grow dynamically) and for a return
pointer to the instruction in the function that invoked the
current function (caller/callee). As
functions terminate, their stack entry is "popped out," with
the return values written to the proper
location in the caller.
Since nested procedural/ function invocation levels are
entered and exited in LIFO order, a stack
is the most appropriate data structure to handle this
functionality.
Evaluating arithmetic expressions.
Stacks can be used to parse arithmetic expressions and
evaluate them efficiently, as we shall
see as part of this assignment.
To eliminate the need for direct implementation of recursion.
As recursive function calls require a lot of overhead, it is
often the case that recursive algorithms
are "unrolled" into non-recursive ones. Since recursive
calls are entered/exited in LIFO order the
use of stacks to mimic recursion is a natural choice.
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is heap and its types?
List out the applications of a linked list?
What is a dequeue?
How many pointers are necessary to implement a simple linked list?
Can arraylist store primitives?
What is the time complexity of selection sort?
What is the Difference between treemap and hashmap?
How do you assign an address to an element of a pointer array ?
What is the Role of push() and pop() method?
What is complexity of quicksort?
What do you mean by sorting?
What do you know about traversal in linked lists?
What is queue example?
Can we add heterogeneous elements into treemap?
What is sequential search? What is the average number of comparisons in a sequential search?