Infix Prefix postfix expressions – datastructures

Infix prefix postfix expressions

These notations are used because the prefix and postfix expressions are evaluated faster than infix expression (one used by humans) by the computer, especially in compilers. The prefix and postfix expressions do not contain parenthesis.

infix, postfix and prefix expressions
infix  prefix postfix expressions

Infix:

An infix expression is a single letter, or an operator, proceeded by an infix string and followed by another infix string.

eg: A, a*b.

Prefix(Polish notation):

A prefix expression is a single letter, or an operator, followed by two prefix strings.

eg: a, *ab

READ  Split a circular linked list into two equal parts

Postfix(Reverse polish notation):

A postfix expression is a single letter, or an operator, preceded by two postfix strings.

eg : a, ab*

More Examples:
 
Infix Expression Prefix Expression Postfix Expression
A + B * C + D + + A * B C D A B C * + D +
(A + B) * (C + D) * + A B + C D A B + C D + *
A * B + C * D + * A B * C D A B * C D * +
A + B + C + D + + + A B C D A B + C + D +

OTHER RESOURCES

 

Related Post

Rating: 5.0. From 1 vote.
Please wait...