INFIX, PREFIX, - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

INFIX, PREFIX,

Description:

This is called infix notation, because the operator (' ') is inside the expression ... Infix form : identifier operator identifier ... – PowerPoint PPT presentation

Number of Views:765
Avg rating:3.0/5.0
Slides: 9
Provided by: GSU50
Learn more at: http://www.cs.gsu.edu
Category:
Tags: infix | prefix | infix

less

Transcript and Presenter's Notes

Title: INFIX, PREFIX,


1
INFIX, PREFIX, POSTFIXEXPRESSIONS
  • Saurav Karmakar
  • Spring 2007

2
Infix Notation
  • We usually write algebraic expressions like this
  • a b
  • This is called infix notation, because the
    operator () is inside the expression
  • A problem is that we need parentheses or
    precedence rules to handle more complicated
    expressions
  • For Example
  • a b c (a b) c ?
  • a (b c) ?

3
Infix, Postfix, Prefix notation
  • There is no reason we cant place the operator
    somewhere else.
  • How ?
  • Infix notation a b
  • Prefix notation a b
  • Postfix notation a b

4
Other Names
  • Prefix notation was introduced by the Polish
    logician Lukasiewicz, and is sometimes called
    Polish notation.
  • Postfix notation is sometimes called reverse
    Polish notation or RPN.

5
Why ?
  • Question Why would anyone ever want to use
    anything so unnatural, when infix seems to work
    just fine?
  • Answer With postfix and prefix notations,
    parentheses are no longer needed!

6
Example
  • infix postfix prefix
  • (a b) c a b c a b c
  • a (b c) a b c a b c
  • Infix form ltidentifiergt ltoperatorgt ltidentifiergt
  • Postfix form ltidentifiergt ltidentifiergt
    ltoperatorgt
  • Prefix form ltoperatorgt ltidentifiergt ltidentifiergt

7
Convert from Infix to Prefix and Postfix
(Practice)
  • x
  • x y
  • (x y) - z
  • w ((x y) - z)
  • (2 a) / ((a b) (a - c))

8
Convert from Postfix to Infix (Practice)
  • 3 r -
  • 1 3 r -
  • s t 1 3 r -
  • v w x y z -
Write a Comment
User Comments (0)
About PowerShow.com