SlideShare a Scribd company logo
Reverse
Polish
Notation
BEDMAS
BIDMAS
BODMAS
PEMDAS
6,2/1,2+*
                *
    /                     +
6       2           1          2
            /           6,2,1,2,+*/

                    *
                         +

6       2           1         2
Evaluating RPN
• Uses a stack and two simple rules. Reading
  left to right …….
• 1. If a value appears next in the
  expression, push this value on to the stack.
• 2. If an operator appears next, pop two items
  from the top of the stack and push the result
  of the operation on to the stack.
Reverse Polish Notation Examples

    7,4+3-        7+4-3

    1,2*3+        1*2+3

    1,2+3*        (1+2) *3

    5,9,2*+       5+9*2

    1,2*3,4*+     1*2+3*4
Converting from infix to postfix
         ‘Shunting yard algorithm’

• Read each character                  • Calculator - another
• If its an operand, add it to
  the output
• If it’s an operator then
   – If there’s a higher BODMAS
     priority operator at the top of
     the stack, pop it
   – Push it on the stack
• At the end, pop everything
  off the operator stack
Reverse polish notation

More Related Content

What's hot

Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
Soumen Santra
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
Keval Bhogayata
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Priority queues
Priority queuesPriority queues
Priority queues
Priyanka Rana
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
JeeSa Sultana
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
Sanjeev Patel
 
Stacks
StacksStacks
Stacks
sweta dargad
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Bucket sort
Bucket sortBucket sort
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
Balakrishna Chowdary
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
LavanyaJ28
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
Soumen Santra
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
Meghaj Mallick
 
Queue
QueueQueue

What's hot (20)

Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Hash table
Hash tableHash table
Hash table
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
 
Stacks
StacksStacks
Stacks
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 
Queue
QueueQueue
Queue
 

More from grahamwell

Pseudocode
PseudocodePseudocode
Pseudocode
grahamwell
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
grahamwell
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
grahamwell
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
grahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
grahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
grahamwell
 
The software story
The software storyThe software story
The software story
grahamwell
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
grahamwell
 
Database field types
Database field typesDatabase field types
Database field types
grahamwell
 
Databases 101
Databases 101Databases 101
Databases 101
grahamwell
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
grahamwell
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
grahamwell
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
grahamwell
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
grahamwell
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
grahamwell
 
The rail fence
The rail fenceThe rail fence
The rail fence
grahamwell
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
grahamwell
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
grahamwell
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
grahamwell
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
grahamwell
 

More from grahamwell (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
The software story
The software storyThe software story
The software story
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Database field types
Database field typesDatabase field types
Database field types
 
Databases 101
Databases 101Databases 101
Databases 101
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
 
The rail fence
The rail fenceThe rail fence
The rail fence
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
 

Reverse polish notation

  • 3. 6,2/1,2+* * / + 6 2 1 2 / 6,2,1,2,+*/ * + 6 2 1 2
  • 4. Evaluating RPN • Uses a stack and two simple rules. Reading left to right ……. • 1. If a value appears next in the expression, push this value on to the stack. • 2. If an operator appears next, pop two items from the top of the stack and push the result of the operation on to the stack.
  • 5. Reverse Polish Notation Examples 7,4+3- 7+4-3 1,2*3+ 1*2+3 1,2+3* (1+2) *3 5,9,2*+ 5+9*2 1,2*3,4*+ 1*2+3*4
  • 6. Converting from infix to postfix ‘Shunting yard algorithm’ • Read each character • Calculator - another • If its an operand, add it to the output • If it’s an operator then – If there’s a higher BODMAS priority operator at the top of the stack, pop it – Push it on the stack • At the end, pop everything off the operator stack