Professional Documents
Culture Documents
Case Study IA3
Case Study IA3
1 Evaluation Expression
Conversion of infix to postfix expression.
Computation to postfix (reverse polish) expression.
In this, the arithmetic operation which is a high-level programming language is
converted into machine language. This is because machine can understand only
binary language (0 and 1). It assumes that an arithmetic operation can take place
in two operands only like A+B, C*D, F/E etc. But the arithmetic expression
may contain more than one operator and many operands like A+(B+C-
(D/E^F)*G)*H). These complex expressions can be converted and can be
executed in two operands and an operator form.
2. Backtracking
Backtracking is an algorithm technique that tries to find each and every possible
combination of the technique and find the solution to a problem.
Suppose we are coding a chess-playing algorithm and at a certain point, the
algorithm finds that a set of steps fails to win. In this situation, the algorithm
will reverse back to the safe state and try another possible set of steps.
This "reverse back" (undo) is powered by the stack data structure which keeps
track of the steps for rollback if anything goes wrong.
3. Parenthesis Balance Checking
It is a common question during interviews to write a program to check if the
parenthesis is balanced or not.
We use the stack data structure to check unbalanced parenthesis by pushing
open brackets into the stack and pop out after a closing bracket. If nothing lasts
at the end then all parenthesis are matched.
4. Track nested function calls
Nested function calls are common things but complicated ones. The stack data
structure is used to track the order in which the functions were invoked and
return data in the same manner.
5. Undo Button
As explained in backtracking example, the stack data structure has many
applications in the Undo functionality of many applications. It keeps track on
the work and recovers the previous stage as saved in the stack.
6. Recursion
Recursion is a beautiful but dangerous (infinity) part of programming. Stack
data structure is used to keep track of recursive calls and return data in a
particular order.