SlideShare a Scribd company logo
Convert the following expressions from infix to Reverse Polish Notation (postfix). Think of
Squareroot and tan as unary operators: ((2 - 1) (4 * 3)) + 15 -b+ Squareroot b^- 4ac/2a tan
alpha + tan beta/1 - tan alpha tan beta
Solution
To convert an expression from infix to postfix, the method is:
1. If it is an operand at it to output expression.
2. If it is an operator, if stack is empty, or if the operator on top of stack is of lower precedence
than this, push it onto stack.
3. Else, pop operators from the stack, till the operators on stack are of higher precedence than the
one in hand, and add them to the output. Then, add this operator to the stack.
So, applying this logic to the expressions:
1. ((2-1) / (4 / 3)) + 15
(, Push it onto stack.
(, Push it onto stack.
2 Add it to output, so output expression now is: 2
- Push it onto stack.
1 Add it to output, so output expression now is: 2 1
) Now, pop elements and add it to output, till a open brace. So, output expression is: 2 1 -, and
stack will now hold (.
/ Push it onto stack.
( Push it onto stack.
4 Add it to output, so output expression now is: 2 1 - 4
* Push it onto stack.
3 Add it to ouput, so output expression now is: 2 1 - 4 3
) Now, pop elements and add it to output, till a open brace. So, output expression is: 2 1 - 4 3 *,
and stack will now hold ( /.
) Now, pop elements and add it to output, till a closed brace. So, output expression is: 2 1 - 4 3 *
/, and stack is now empty.
+ Push it onto stack.
15 Add it to output, so output expression now is: 2 1 - 4 3 * / 15.
As it is the end of expression, pop all elements from stack, and add it to output: So, now the
expression is: 2 1 - 4 3 * / 15 +.
Finally, the postfix equivalent of the given expression is:
2 1 - 4 3 * / 15 +.

More Related Content

PPTX
DSA_chapter_04_Stack and data structure and Queue.pptx
PDF
Data structure lab manual
PPTX
Applicationofstack by Ali F.RAshid
PPTX
Application of Stack - Yadraj Meena
PDF
Data Structures And Algorithms(stacks queues)
PPT
PPTX
Programming Homework Help
PPTX
Stacks and queues using aaray line .pptx
DSA_chapter_04_Stack and data structure and Queue.pptx
Data structure lab manual
Applicationofstack by Ali F.RAshid
Application of Stack - Yadraj Meena
Data Structures And Algorithms(stacks queues)
Programming Homework Help
Stacks and queues using aaray line .pptx

Similar to Convert the following expressions from infix to Reverse Polish Notati.pdf (20)

PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
PPTX
Implementation of stacks and queues in C
PPT
16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt
PPTX
PPSX
Data structure_Stack Introduction & app.
PPT
Stack in Data Structure
PDF
Stacks,queues,linked-list
PPTX
DS MOD2 (1) (1).pptx
PPTX
Conversion of Infix to postfix.pptxjjjjj
PDF
Using RustBecause postfix expressions are simpler and faster to ev.pdf
PPTX
Lecture_04.2.pptx
PPTX
COMP1603 Stacks and RPN 2023 Recording (2).pptx
PPTX
Data strutcure and annalysis topic stack
PPTX
Introduction to information about Data Structure.pptx
PPTX
Stacks in c++
PDF
Data structures stacks
PPTX
stack-Intro.pptx
PPTX
Unit 3 Stacks and Queues.pptx
PDF
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Implementation of stacks and queues in C
16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt
Data structure_Stack Introduction & app.
Stack in Data Structure
Stacks,queues,linked-list
DS MOD2 (1) (1).pptx
Conversion of Infix to postfix.pptxjjjjj
Using RustBecause postfix expressions are simpler and faster to ev.pdf
Lecture_04.2.pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptx
Data strutcure and annalysis topic stack
Introduction to information about Data Structure.pptx
Stacks in c++
Data structures stacks
stack-Intro.pptx
Unit 3 Stacks and Queues.pptx
Ad

More from feetshoemart (20)

PDF
Andy and Joan are married and under 65 years of age. They have two c.pdf
PDF
Compare the methods by which the Parsees of India benefitted from th.pdf
PDF
Computer Forensics MethodologiesList them and explain each one.P.pdf
PDF
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
PDF
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
PDF
calculate the hydrogen ion concentration in mol for the following s.pdf
PDF
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
PDF
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
PDF
wk3 reply to prof.I need help with this question below a 200 words.pdf
PDF
Write a program that prompts the user to enter a positive integer and.pdf
PDF
Write a function called countElements that counts the number of times.pdf
PDF
This is a java lab assignment. I have added the first part java re.pdf
PDF
There is no video, All you have to do is show how you reference the .pdf
PDF
The process of Imperialism and Colonialism played a role in the esta.pdf
PDF
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
PDF
What do viral genomes look like compared to those of living organism.pdf
PDF
Verify the identity Verify the identity by transforming the left-han.pdf
PDF
Using following main file and solve the taskInst.pdf
PDF
Suppose there are 14 children trying to form two teams with seven ch.pdf
PDF
11. Define a simple deformable model to detect a half-circular shape.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdf
Compare the methods by which the Parsees of India benefitted from th.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
calculate the hydrogen ion concentration in mol for the following s.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
wk3 reply to prof.I need help with this question below a 200 words.pdf
Write a program that prompts the user to enter a positive integer and.pdf
Write a function called countElements that counts the number of times.pdf
This is a java lab assignment. I have added the first part java re.pdf
There is no video, All you have to do is show how you reference the .pdf
The process of Imperialism and Colonialism played a role in the esta.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
What do viral genomes look like compared to those of living organism.pdf
Verify the identity Verify the identity by transforming the left-han.pdf
Using following main file and solve the taskInst.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdf
11. Define a simple deformable model to detect a half-circular shape.pdf
Ad

Recently uploaded (20)

PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
RMMM.pdf make it easy to upload and study
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
Classroom Observation Tools for Teachers
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Pre independence Education in Inndia.pdf
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
RMMM.pdf make it easy to upload and study
Abdominal Access Techniques with Prof. Dr. R K Mishra
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
STATICS OF THE RIGID BODIES Hibbelers.pdf
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Basic Mud Logging Guide for educational purpose
Classroom Observation Tools for Teachers
Module 4: Burden of Disease Tutorial Slides S2 2025
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
Pre independence Education in Inndia.pdf

Convert the following expressions from infix to Reverse Polish Notati.pdf

  • 1. Convert the following expressions from infix to Reverse Polish Notation (postfix). Think of Squareroot and tan as unary operators: ((2 - 1) (4 * 3)) + 15 -b+ Squareroot b^- 4ac/2a tan alpha + tan beta/1 - tan alpha tan beta Solution To convert an expression from infix to postfix, the method is: 1. If it is an operand at it to output expression. 2. If it is an operator, if stack is empty, or if the operator on top of stack is of lower precedence than this, push it onto stack. 3. Else, pop operators from the stack, till the operators on stack are of higher precedence than the one in hand, and add them to the output. Then, add this operator to the stack. So, applying this logic to the expressions: 1. ((2-1) / (4 / 3)) + 15 (, Push it onto stack. (, Push it onto stack. 2 Add it to output, so output expression now is: 2 - Push it onto stack. 1 Add it to output, so output expression now is: 2 1 ) Now, pop elements and add it to output, till a open brace. So, output expression is: 2 1 -, and stack will now hold (. / Push it onto stack. ( Push it onto stack. 4 Add it to output, so output expression now is: 2 1 - 4 * Push it onto stack. 3 Add it to ouput, so output expression now is: 2 1 - 4 3 ) Now, pop elements and add it to output, till a open brace. So, output expression is: 2 1 - 4 3 *, and stack will now hold ( /. ) Now, pop elements and add it to output, till a closed brace. So, output expression is: 2 1 - 4 3 * /, and stack is now empty. + Push it onto stack. 15 Add it to output, so output expression now is: 2 1 - 4 3 * / 15. As it is the end of expression, pop all elements from stack, and add it to output: So, now the expression is: 2 1 - 4 3 * / 15 +. Finally, the postfix equivalent of the given expression is: 2 1 - 4 3 * / 15 +.