Data Structure and Algorithm_
Data Structure and Algorithm_
BRANCH : CSE
1. Introduction
2. Infix Notation
3. Postfix Notation
❑ Mathematical formulas are often made more accessible by using parenthesis. However, in
computers, expression with multiple parentheses can be inefficient. So, mathematicians have created
different notations such as infix, prefix, and postfix expressions to reduce computational work.
❑ The way to write arithmetic expression is known as a notation. An arithmetic expression can be written in three
different but equivalent notations, i.e., without changing the essence or output of an expression. These notations
are −
1. Infix Notation
❑ Infix Notation:
We write expression in infix notation, e.g. a - b + c, where operators are used in-between
operands. It is easy for us humans to read, write, and speak in infix notation but the same does not
go well with computing devices. An algorithm to process infix notation could be difficult and costly
in terms of time and space consumption.
❑ Postfix Notation:
This notation style is known as Reversed Polish Notation. In this notation style, the operator
is postfixed to the operands i.e., the operator is written after the operands. For example, ab+. This is
equivalent to its infix notation a + b.
conversion
❑ Question:(T*I/G^Y)-(A^B/C-D)/H
Infix character scanned stack Postfix expression
( (
T ( T
* (* T
I (* TI
/ (*/ TI
G (*/ TIG
^ (*/^ TIG
Y (*/^ TIGY
) (*/^) TIGY^/*
- - TIGY^/*
( -( TIGY^/*
A -( TIGY^/*A
^ -(^ TIGY^/*A
B -(^ TIGY^/*AB
/ -(/ TIGY^/*AB^
C -(/ TIGY^/*AB^C
- -(- TIGY^/*AB^C/
D -(- TIGY^/*AB^C/D
) -(-) TIGY^/*AB^C/D-
/ -/ TIGY^/*AB^C/D-
H -/ TIGY^/*AB^C/D-H/-
CONCLUSION
The infix, prefix, and postfix notations are three different ways of writing and evaluating
expressions.
While infix expressions are common and intuitive for humans to read and write, prefix and postfix
notations are computationally efficient and valuable for creating computer programs that
manipulate expressions.
In particular, we can easily evaluate the postfix expressions with a stack data structure, making
them appropriate for implementing some algorithms, such as parsers.
DECLARATION
I heíeby declaíe that this ppt is made by me only and not downloaded oí copied fíom any
otheí souíces.
Date: 07.08.2023
Name-Kusumita Das
Roll no- 33200122111