Applications of Stack Data Structure - IT magazine

IT magazine

Knowledge that matters

Applications of Stack Data Structure

Share This



  • Infix to Postfix or Infix to Prefix Conversion: The stack can be used to convert some infix expression into its postfix equivalent, or prefix equivalent. These postfix or prefix notations are used in computers to express some expressions. These expressions have some great advantages. We do not need to maintain operator ordering, and parenthesis.
  • Postfix or Prefix Evaluation: After converting into prefix or postfix notations, we have to evaluate the expression to get the result. For that purpose, also we need the help of stack data structure.
  • Function Call: Another great use of stack is during the function call and return process. When we call a function from one other function, that function call statement may not be the first statement. After calling the function, we also have to come back from the function area to the place, where we have left our control. So we want to resume our task, not restart. For that reason, we store the address of the program counter into the stack, then go to the function body to execute it. After completion of the execution, it pops out the address from stack and assign it into the program counter to resume the task again.
  • Undo mechanism in most text editors.
  • Language processing:
    • space for parameters and local variables is created internally using a stack.
    • compiler's syntax check for matching braces is implemented by using stack.
    • support for recursion. 
  • Memory management, run-time environment for nested language features. etc
  • Backtracking (game playing, finding paths, exhaustive searching) 
    • Backtracking Procedure: Backtracking is one of the algorithm designing technique. For that purpose, we dive into some way, if that way is not efficient, we come back to the previous state and go into some other paths. To get back from current state, we need to store the previous state. For that purpose, we need stack. Some examples of backtracking is finding the solution for Knight Tour problem or N-Queen Problem etc.

No comments:

Post a Comment