0% found this document useful (0 votes)
351 views

Conversion of Infix Expression To Prefix and Postfix Expression Without Using Stack

This document provides information about converting infix expressions to prefix and postfix expressions without using a stack. It defines precedence and associativity rules for operators. It gives examples of infix, prefix, and postfix expressions and their conversions. At the end, it provides an example infix expression for the reader to try converting on their own.

Uploaded by

Rohini Aravindan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
351 views

Conversion of Infix Expression To Prefix and Postfix Expression Without Using Stack

This document provides information about converting infix expressions to prefix and postfix expressions without using a stack. It defines precedence and associativity rules for operators. It gives examples of infix, prefix, and postfix expressions and their conversions. At the end, it provides an example infix expression for the reader to try converting on their own.

Uploaded by

Rohini Aravindan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRESIDENCY UNIVERSITY

Bengaluru, Karnataka
Computer Science & Engineering
School of Computer Science & Engineering

Subject: CSE2001 - Data Structures & Algorithms Semester: III


Date: 21/09/2023

Conversion of infix expression to prefix and postfix expression without using stack
Precedence & Associativity
Parenthesis ( ), [ ], { } L to R
Exponents ^ R to L
Multiplication & Division *, / L to R
operator
Addition & Subtraction +, - L to R
operator

Infix expression :
Op1 operator Op2 (Operator in between operands is called as infix expression)
Example: a + b, a – b, a * b, a / b, a + b * c, a + (b – c), 1 + 2 – (b + c),……..
Prefix expression : (operator ahead of operands)
+ab, -ab, *ab, /ab,…..
Postfix expression : (Operator after operands)
ab+, ab-, ab*, ab/,…….
Conversion of infix to prefix and postfix:
Infix expression Prefix expression Postfix expression
a+b +ab ab+
a+b*c =a+b*c =a+b*c
= a + (b * c) = a + (b * c)
= a + (*bc) = a + (bc*)
= +a*bc = abc*+
a+b–c =a+b–c =a+b–c
= (a + b) – c = (a + b) – c
= (+ab) – c = (ab+) – c
= -+abc = ab+c-
a + (b – c) = a + (b – c) = a + (b – c)
= a + (-bc) = a + (bc-)
= +a-bc = abc-+
a+b–c*d–e^f = a+b-c*d-e^f = a+b-c*d-(e^f)
= a+b-c*d-(e^f) = a+b-{c*d}-(ef^)
= a+b-c*d-(^ef) = {a+b}-(cd*)-(ef^)
= a+b-{c*d}-(^ef) = {(ab+)-(cd*)}-(ef^)
Prepared by,
Ms. Sridevi S, AP/SoCSE, Ms. Meena Kumari, AP/SoCSE, Ms. Rohini A, AP/SoCSE 1
= a+b-(*cd)-(^ef) = (ab+cd*-)-(ef^)
= {a+b}-(*cd)-(^ef) = ab+cd*-ef^-
={(+ab)-(*cd)}-(^ef)
=(-+ab*cd)-(^ef)
= --+ab*cd^ef

Try this
Infix expression:
a + b – c * d – (e ^ f) * g / h * i + j

Prepared by,
Ms. Sridevi S, AP/SoCSE, Ms. Meena Kumari, AP/SoCSE, Ms. Rohini A, AP/SoCSE 2

You might also like