Infix, Prefix and Postfix Expressions in Data Structure With Examples

CHAPTER 24 • DATA STRUCTURE

Infix, Prefix and Postfix Expressions in Data Structure With Examples

Understand expression notation, operator precedence, associativity, conversion using Stack, evaluation algorithms, C programs, solved examples and exam questions.

Infix Prefix Postfix Stack C Programming

In Mathematics, we normally write expressions such as A + B or A + B * C. These expressions look simple because we know the rules of BODMAS.

But in Data Structure, the same expression may be written as + A B or A B +. This is where many students become confused.

Students often ask why we need three different expression formats and how a Stack helps convert one format into another.

The concept is actually simple. The main difference is the position of the operator compared with the operands.

Quick Answer: Infix, Prefix and Postfix are three methods of writing arithmetic expressions. In Infix notation, the operator is written between operands. In Prefix notation, it is written before operands. In Postfix notation, it is written after operands. Stacks are commonly used for expression conversion and evaluation.

Before understanding the algorithms, you can revise the Stack in Data Structure: Operations, Implementation and Applications .

What is an Expression in Data Structure?

Infix, Prefix and Postfix Expressions in Data Structure With Examples

An expression is a combination of operands and operators that represents a calculation.

A + B

In this example, A and B are operands, while + is the operator.

Operand

Values or Variables

An operand is a value or variable on which an operation is performed. Examples: A, B, 5, 10.

Operator

Mathematical Symbol

An operator performs a calculation. Examples: +, -, *, / and ^.

Basic Example

5 + 3 * 2

Here, 5, 3 and 2 are operands. The symbols + and * are operators.

Multiplication has higher precedence than addition, so multiplication is performed first.

5 + (3 × 2) = 11

Types of Expressions in Data Structure

There are three commonly studied expression notations: Infix, Prefix and Postfix.

Type 01

Infix

A + B

The operator is between the operands.

Type 02

Prefix

+ A B

The operator comes before its operands.

Type 03

Postfix

A B +

The operator comes after its operands.

1. Infix Expression

Infix is the normal form of writing mathematical expressions. The operator is placed between its two operands.

A + B

Infix expressions may need parentheses and precedence rules to indicate the correct order of operations.

A + B
Figure 1: Infix notation. Operator is positioned between operands.

2. Prefix Expression

Prefix notation places the operator before its operands. It is also known as Polish Notation.

+ A B
+ A B
Figure 2: Prefix notation. Operator appears before operands.

3. Postfix Expression

Postfix notation places the operator after its operands. It is also known as Reverse Polish Notation (RPN).

A B +
A B +
Figure 3: Postfix notation. Operator appears after operands.

Examples of All Three Notations

Infix Prefix Postfix
A + B + A B A B +
A - B - A B A B -
A * B * A B A B *
(A + B) * C * + A B C A B + C *
A + B * C + A * B C A B C * +
(A - B) / C / - A B C A B - C /
Easy Memory Trick:

Infix = Operator In-between
Prefix = Operator Before
Postfix = Operator After

Remember these three lines to identify expression types in MCQs.

Operator Precedence and Associativity

Before converting expressions, we must understand operator precedence and associativity.

Operator precedence decides which operation is performed first. Associativity decides how operators of equal precedence are grouped.

Operator Precedence Table

Operator Meaning Priority Associativity
^ Exponentiation Highest Right to Left
* and / Multiply and Divide Medium Left to Right
+ and - Add and Subtract Lowest Left to Right
^ > * / > + -

Parentheses are processed as a group before outside operations. The table describes binary operators. Unary minus is not included here.

What is Associativity?

When two operators have equal precedence, associativity decides their grouping.

Left Associativity

A - B - C

It is grouped as (A - B) - C.

Right Associativity

A ^ B ^ C

It is grouped as A ^ (B ^ C).

Important Exam Mistake: Two operators with the same precedence do not always follow the same associativity. In our expression notation, exponentiation (^) is right-associative.

Infix to Postfix Conversion Using Stack

Infix to Postfix Conversion means changing an expression where operators are between operands into an expression where operators appear after operands.

Quick Answer: To convert Infix to Postfix using a Stack, send operands directly to the output and temporarily store operators in the Stack. Before pushing an operator, pop operators that must be processed first according to precedence and associativity. Parentheses control grouping.

Rules for Infix to Postfix Conversion

1
Read the expression from left to right.

Process one token at a time.

2
If an operand appears, send it to output.

Examples: A, B, 10 or 25.

3
If '(' appears, push it.

It marks the start of a parenthesised expression.

4
If an operator appears, compare precedence.

Pop higher-priority operators first. For equal priority, also pop if the incoming operator is left-associative. Then push the incoming operator.

5
If ')' appears, pop until '('.

Send those operators to output and remove the matching '('.

6
After scanning, pop remaining operators.

Append them to the output to obtain the final Postfix expression.

Solved Example: Infix to Postfix

Convert the following expression:

A + B * (C - D)

We read the expression from left to right and maintain an operator Stack.

Step-by-Step Dry Run Table

Symbol Action Stack (Bottom → Top) Output
A Output operand Empty A
+ Push + A
B Output operand + A B
* Push higher priority + * A B
( Push + * ( A B
C Output operand + * ( A B C
- Push + * ( - A B C
D Output operand + * ( - A B C D
) Pop - and remove ( + * A B C D -
End Pop * then + Empty A B C D - * +
Final Postfix Expression:
A B C D - * +

Pictorial Representation

A B C D - * +
Figure 4: Postfix result of A + B * (C - D).

Infix to Postfix Algorithm

START

CREATE EMPTY OPERATOR STACK
OUTPUT = EMPTY

FOR EACH TOKEN FROM LEFT TO RIGHT

    IF TOKEN IS OPERAND
        ADD TOKEN TO OUTPUT

    ELSE IF TOKEN == '('
        PUSH TOKEN

    ELSE IF TOKEN == ')'
        POP OPERATORS TO OUTPUT UNTIL '('
        REMOVE '('

    ELSE IF TOKEN IS OPERATOR

        WHILE TOP IS OPERATOR AND
              (TOP HAS HIGHER PRECEDENCE OR
              SAME PRECEDENCE AND TOKEN
              IS LEFT-ASSOCIATIVE)

            POP TOP TO OUTPUT

        END WHILE

        PUSH TOKEN

    END IF

END FOR

POP REMAINING OPERATORS TO OUTPUT

RETURN OUTPUT

STOP
Memory Trick for Postfix:

Operands Out, Operators Stack.

An operand goes directly to output. An operator waits in the Stack until the rules allow it to be removed.

Infix to Prefix Conversion Using Stack

Infix to Prefix Conversion changes an expression into a format where the operator comes before its operands.

Infix: A + B * C
Prefix: + A * B C

There are different methods of converting Infix to Prefix. One easy and reliable method uses an Expression Tree.

Expression Tree Method

First convert the Infix expression into Postfix. Then use a Stack to build an Expression Tree from the Postfix tokens.

Finally, read the tree in Preorder (Root, Left, Right) to obtain Prefix notation.

Step-by-Step Example

Consider:

A + B * (C - D)
1
Convert Infix to Postfix.

A B C D - * +

2
Build an Expression Tree.

For every operand, create a node. For every binary operator, pop the right child, then the left child, and create their parent node.

3
Read Root, Left, Right.

This produces the Prefix expression.

Expression Tree Diagram

Figure 5: Simplified level-by-level representation of the expression tree. Preorder visits +, A, *, B, -, C, D.
Final Prefix Expression:
+ A * B - C D

Expression Tree Construction Algorithm

START

CONVERT INFIX TO POSTFIX
CREATE EMPTY NODE STACK

FOR EACH TOKEN IN POSTFIX

    IF TOKEN IS OPERAND

        CREATE NODE
        PUSH NODE

    ELSE IF TOKEN IS BINARY OPERATOR

        RIGHT = POP()
        LEFT = POP()

        CREATE OPERATOR NODE

        NODE.left = LEFT
        NODE.right = RIGHT

        PUSH NODE

    END IF

END FOR

ROOT = POP()

PRINT PREORDER(ROOT)

STOP

Prefix Conversion Memory Trick

Prefix = Preorder = Root → Left → Right

If the Expression Tree is correct, Preorder traversal gives the corresponding Prefix expression.

Important: Some textbooks teach Prefix conversion by reversing an Infix expression, converting it and reversing the result. That method also needs careful handling of parentheses and equal-precedence associativity. The Expression Tree method makes the operand order clearer.

Postfix to Infix and Prefix to Infix Conversion

We can also convert Prefix or Postfix back into Infix using an operand Stack.

Postfix to Infix

Read Postfix from left to right. Push operands. When an operator appears, pop the right operand and then the left operand.

Combine them as:

(Left Operator Right)

Example:

A B + C * → ((A + B) * C)

Prefix to Infix

Read Prefix from right to left. Push operands. When an operator appears, pop the left operand first and then the right operand.

* + A B C → ((A + B) * C)
Exam Tip: Keep parentheses in the converted Infix expression while learning. They preserve the exact grouping and avoid precedence mistakes.

Evaluation of Postfix and Prefix Expressions

Expression Evaluation means finding the numerical result of an expression.

We can use a Stack to evaluate Postfix and Prefix expressions without repeatedly applying ordinary Infix precedence rules.

1. Postfix Expression Evaluation

Quick Rule: Read the Postfix expression from left to right. Push operands. When an operator appears, pop the right operand, then the left operand, perform the calculation and push the result.

Solved Numerical Example

Evaluate the following Postfix expression:

5 6 2 + * 12 4 / -

Postfix Evaluation Dry Run

Token Action Stack (Bottom → Top)
5Push 55
6Push 65, 6
2Push 25, 6, 2
+6 + 2 = 85, 8
*5 * 8 = 4040
12Push 1240, 12
4Push 440, 12, 4
/12 / 4 = 340, 3
-40 - 3 = 3737
Final Answer:
37

Visualise the Final Stack

TOP
37
Figure 6: Final Postfix evaluation Stack contains one value, 37.

Postfix Evaluation Algorithm

START

CREATE EMPTY STACK

READ TOKENS FROM LEFT TO RIGHT

FOR EACH TOKEN

    IF TOKEN IS NUMBER
        PUSH TOKEN

    ELSE IF TOKEN IS OPERATOR

        RIGHT = POP()
        LEFT = POP()

        RESULT = LEFT OPERATOR RIGHT

        PUSH RESULT

    END IF

END FOR

RETURN POP()

STOP

2. Prefix Expression Evaluation

Prefix Evaluation is similar to Postfix, but the direction changes.

We read Prefix from right to left.

- * 5 + 6 2 / 12 4

This Prefix expression represents the same calculation as the previous Postfix example.

1
Scan from right to left.

Push numerical operands when encountered.

2
Process an operator.

Pop the left operand first and the right operand second.

3
Calculate and push.

Apply the operator and store the result.

4
Finish scanning.

The final Stack value is the answer.

Result = 5 × (6 + 2) - (12 / 4) = 37

Prefix Evaluation Algorithm

START

CREATE EMPTY STACK

SCAN PREFIX FROM RIGHT TO LEFT

FOR EACH TOKEN

    IF TOKEN IS NUMBER

        PUSH TOKEN

    ELSE IF TOKEN IS OPERATOR

        LEFT = POP()
        RIGHT = POP()

        RESULT = LEFT OPERATOR RIGHT

        PUSH RESULT

    END IF

END FOR

RETURN POP()

STOP
Common Mistake: Operand order matters in subtraction and division. For Postfix, pop RIGHT first. For Prefix scanned right to left, pop LEFT first.

C Program for Infix, Prefix and Postfix Conversion

The following C program accepts an Infix expression and displays its Postfix and Prefix forms.

It uses an operator Stack for Infix-to-Postfix conversion and an Expression Tree to generate Prefix notation.

This example supports binary +, -, *, / and ^, parentheses, alphanumeric operands and underscores in operand names.

Complete C Program: Expression Conversion

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX 256
#define WORD 32

typedef struct Node {
    char value[WORD];
    struct Node *left, *right;
} Node;

char ops[MAX];
int opTop = -1;
char post[MAX][WORD];
int count = 0;

int isOp(char c) {
    return strchr("+-*/^", c) != NULL && c != '\0';
}

int precedence(char c) {
    if (c == '^') return 3;
    if (c == '*' || c == '/') return 2;
    return 1;
}

void error(const char *message) {
    fprintf(stderr, "Error: %s\n", message);
    exit(EXIT_FAILURE);
}

void addOp(char op) {
    if (count >= MAX)
        error("expression is too long");

    post[count][0] = op;
    post[count][1] = '\0';
    count++;
}

void convert(const char *s) {
    int expectValue = 1;

    for (size_t i = 0; s[i]; ) {
        unsigned char c = (unsigned char)s[i];

        if (isspace(c)) {
            i++;
            continue;
        }

        if (isalnum(c) || c == '_') {
            if (!expectValue || count >= MAX)
                error("unexpected operand");

            size_t j = 0;

            while (isalnum((unsigned char)s[i]) ||
                   s[i] == '_') {
                if (j >= WORD - 1)
                    error("operand is too long");

                post[count][j++] = s[i++];
            }

            post[count++][j] = '\0';
            expectValue = 0;

        } else if (c == '(') {
            if (!expectValue || opTop >= MAX - 1)
                error("unexpected (");

            ops[++opTop] = '(';
            i++;

        } else if (c == ')') {
            if (expectValue)
                error("unexpected )");

            while (opTop >= 0 && ops[opTop] != '(')
                addOp(ops[opTop--]);

            if (opTop < 0)
                error("unmatched )");

            opTop--;
            i++;

        } else if (isOp(c)) {
            if (expectValue)
                error("operator without left operand");

            while (opTop >= 0 && ops[opTop] != '(' &&
                   (precedence(ops[opTop]) > precedence(c) ||
                   (precedence(ops[opTop]) == precedence(c)
                    && c != '^'))) {
                addOp(ops[opTop--]);
            }

            if (opTop >= MAX - 1)
                error("operator stack full");

            ops[++opTop] = c;
            expectValue = 1;
            i++;

        } else {
            error("unsupported character");
        }
    }

    if (expectValue)
        error("incomplete expression");

    while (opTop >= 0) {
        if (ops[opTop] == '(')
            error("unmatched (");

        addOp(ops[opTop--]);
    }
}

Node *makeNode(const char *value,
               Node *left, Node *right) {
    Node *p = malloc(sizeof *p);

    if (!p)
        error("not enough memory");

    strcpy(p->value, value);
    p->left = left;
    p->right = right;
    return p;
}

void printPrefix(const Node *node) {
    if (!node)
        return;

    printf("%s ", node->value);
    printPrefix(node->left);
    printPrefix(node->right);
}

void release(Node *node) {
    if (!node)
        return;

    release(node->left);
    release(node->right);
    free(node);
}

int main(void) {
    char infix[512];
    Node *stack[MAX];
    int top = -1;

    if (!fgets(infix, sizeof infix, stdin))
        return 1;

    convert(infix);

    printf("Postfix: ");

    for (int i = 0; i < count; i++)
        printf("%s ", post[i]);

    puts("");

    for (int i = 0; i < count; i++) {
        if (strlen(post[i]) == 1 &&
            isOp(post[i][0])) {

            if (top < 1)
                error("invalid expression");

            Node *right = stack[top--];
            Node *left = stack[top--];

            stack[++top] =
                makeNode(post[i], left, right);

        } else {
            stack[++top] =
                makeNode(post[i], NULL, NULL);
        }
    }

    if (top != 0)
        error("invalid expression");

    printf("Prefix:  ");
    printPrefix(stack[0]);
    puts("");

    release(stack[0]);
    return 0;
}

Example Input

A+B*(C-D)

Expected Output

Postfix: A B C D - * +
Prefix:  + A * B - C D

Explanation of the Program

precedence()

Defines the priority of operators.

convert()

Uses the operator Stack to create Postfix notation.

makeNode()

Creates an Expression Tree node containing an operand or operator.

printPrefix()

Performs Preorder traversal to display Prefix notation.

Programming Note: The program treats ^ as exponentiation in expression notation. In actual C arithmetic, ^ is the bitwise XOR operator, not exponentiation. This conversion program does not evaluate the expression.
Limitation: The conversion program handles binary operators only. Unary minus, implicit multiplication, function calls and decimal numbers are outside this classroom example.

C Program for Postfix Expression Evaluation

This second program evaluates a space-separated numerical Postfix expression using a Stack.

It supports integer operands and the four binary operators +, -, * and /.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define MAX 256

int main(void) {
    char line[1024];
    long long stack[MAX];
    int top = -1;

    printf("Enter postfix (space-separated): ");

    if (!fgets(line, sizeof line, stdin))
        return 1;

    char *token = strtok(line, " \t\r\n");

    while (token) {

        if (strlen(token) == 1 &&
            strchr("+-*/", token[0])) {

            if (top < 1) {
                puts("Invalid postfix expression");
                return 1;
            }

            long long b = stack[top--];
            long long a = stack[top--];
            long long result;

            switch (token[0]) {
                case '+':
                    result = a + b;
                    break;

                case '-':
                    result = a - b;
                    break;

                case '*':
                    result = a * b;
                    break;

                default:
                    if (b == 0) {
                        puts("Division by zero");
                        return 1;
                    }
                    result = a / b;
            }

            stack[++top] = result;

        } else {
            char *end;
            errno = 0;

            long long value =
                strtoll(token, &end, 10);

            if (errno || *end ||
                top >= MAX - 1) {
                puts("Invalid number or stack full");
                return 1;
            }

            stack[++top] = value;
        }

        token = strtok(NULL, " \t\r\n");
    }

    if (top != 0) {
        puts("Invalid postfix expression");
        return 1;
    }

    printf("Result: %lld\n", stack[top]);
    return 0;
}

Example Input

12 3 4 * +

Output

Enter postfix (space-separated): 12 3 4 * +
Result: 24

First, 3 × 4 gives 12. Then the expression adds the first 12 to the result.

12 + (3 × 4) = 24
Code Limitations: This evaluator uses integer division, so 5 / 2 produces 2. It does not support ^, floating-point numbers or arithmetic overflow detection. Use integer values small enough to fit in the supported range.

Difference Between Infix, Prefix and Postfix

Basis Infix Prefix Postfix
Operator Position Between operands Before operands After operands
Example A + B + A B A B +
Alternative Name Standard notation Polish notation Reverse Polish notation
Parentheses May be needed Not needed for unambiguous binary notation Not needed for unambiguous binary notation
Precedence Rules Important for interpretation Encoded by ordering Encoded by ordering
Typical Evaluation Direction Parsing required Right to left Left to right
Human Readability Usually easiest Requires practice Requires practice

Time Complexity of Expression Conversion and Evaluation

Stack-based conversion and evaluation generally process each token a constant number of times.

Operation Time Extra Space
Infix to Postfix O(n) O(n)
Infix to Prefix using Tree O(n) O(n)
Postfix Evaluation O(n) O(n)
Prefix Evaluation O(n) O(n)
Expression Tree Traversal O(n) O(h) recursion stack

Here, n represents the number of expression tokens and h represents the height of an Expression Tree. These bounds assume constant-time basic token and Stack operations.

Applications of Infix, Prefix and Postfix Expressions

Expression Parsing

Parsers use expression structure and precedence rules to identify how operations should be grouped.

Compiler Design

Compilers build syntax trees and intermediate representations to process programming expressions.

Stack-Based Calculators

Postfix notation is useful for calculations performed through operand Stacks.

Expression Trees

Prefix and Postfix traversal can represent the structure of mathematical expressions.

Common Mistakes Students Make

1. Ignoring Precedence

A + B * C is not the same as (A + B) * C.

2. Wrong Operand Order

For Postfix subtraction, the first popped item is the right operand.

3. Ignoring Associativity

A ^ B ^ C is normally grouped as A ^ (B ^ C) in this notation.

4. Copying Parentheses

Parentheses help conversion, but they do not appear as grouping symbols in the final Prefix or Postfix output.

5. Confusing Prefix and Postfix

Prefix places the operator before operands. Postfix places it after operands.

6. Forgetting Multi-Digit Values

Separate numeric operands clearly using spaces or proper tokenisation.

Memory Tricks for Semester Exams

Trick 01

Operator Position

Infix = Inside
Prefix = Before
Postfix = After

Trick 02

Scanning Direction

Postfix Evaluation = Left to Right
Prefix Evaluation = Right to Left

Trick 03

Postfix Conversion

Operand → Output
Operator → Stack

Trick 04

Expression Tree

Prefix = Preorder
Postfix = Postorder
Infix = Inorder with grouping

Important Exam Questions With Answers

2 Marks

Q1. What is an Infix Expression?

An Infix Expression is an expression in which the operator is placed between two operands. Example: A + B.

2 Marks

Q2. Define Prefix Expression.

A Prefix Expression places the operator before its operands. It is also known as Polish Notation. Example: + A B.

2 Marks

Q3. Define Postfix Expression.

A Postfix Expression places the operator after its operands. It is also known as Reverse Polish Notation. Example: A B +.

2 Marks

Q4. What is Operator Precedence?

Operator precedence is the priority assigned to operators for determining the order of operations in an expression.

5 Marks

Q5. Explain Infix to Postfix Conversion Using Stack.

Infix to Postfix Conversion uses a Stack to store operators temporarily.

  1. Read the Infix expression from left to right.
  2. Send operands directly to the output.
  3. Push opening parentheses onto the Stack.
  4. Process operators using precedence and associativity.
  5. On closing parentheses, pop until the matching opening parenthesis.
  6. At the end, pop all remaining operators.

Example: A + B * C

Postfix = A B C * +
5 Marks

Q6. Explain Postfix Evaluation With Example.

Postfix Evaluation uses an operand Stack. The expression is scanned from left to right.

Operands are pushed onto the Stack. When an operator is found, two operands are popped, the calculation is performed, and the result is pushed back.

Example:

5 3 2 * +

First, 3 × 2 = 6. Then 5 + 6 = 11.

Answer = 11
10 Marks

Q7. Explain Infix, Prefix and Postfix Expressions With Conversion and Evaluation.

Infix, Prefix and Postfix are three notations used to represent arithmetic expressions.

1. Infix Expression

The operator is written between operands. Example: A + B.

2. Prefix Expression

The operator appears before operands. Example: + A B.

3. Postfix Expression

The operator appears after operands. Example: A B +.

Conversion Using Stack

During Infix to Postfix conversion, operands go directly to output, while operators are handled through a Stack using precedence and associativity rules.

Expression Evaluation

Postfix expressions are commonly evaluated from left to right. Prefix expressions are commonly evaluated from right to left. Both can be evaluated using an operand Stack.

Applications

  • Expression parsing
  • Compiler design
  • Stack-based calculators
  • Expression Trees

Conclusion: These notations provide different ways of representing the same mathematical expression. Prefix and Postfix notations are particularly useful for Stack-based processing.

Practice Questions With Answers

Practice 1

Convert A + B * C into Postfix.

Show Answer

A B C * +

Practice 2

Convert (A + B) * C into Prefix.

Show Answer

* + A B C

Practice 3

Evaluate Postfix: 8 2 / 3 +

Show Answer

8 / 2 = 4. Then 4 + 3 = 7.

Practice 4

Convert A - B - C into Postfix.

Show Answer

A B - C -. Subtraction is left-associative.

Practice 5

Convert A ^ B ^ C into Postfix.

Show Answer

A B C ^ ^. Exponentiation is right-associative.

Practice 6

Convert A B + C * into Infix.

Show Answer

(A + B) * C

Quick Revision Before Exam

Remember these important points for your last-minute preparation.

Infix: Operator between operands. Example: A + B.

Prefix: Operator before operands. Example: + A B.

Postfix: Operator after operands. Example: A B +.

Precedence: ^ is higher than * and /, which are higher than + and -.

Conversion: Operator Stack handles precedence and associativity.

Postfix Evaluation: Scan left to right.

Prefix Evaluation: Scan right to left.

Complexity: O(n) time for the standard Stack-based algorithms.

Frequently Asked Questions

What is the difference between Infix and Postfix?

In Infix notation, the operator appears between operands. In Postfix notation, the operator appears after operands.

What is Prefix notation?

Prefix notation places operators before their operands and is also called Polish Notation.

Why are Stacks used in expression conversion?

A Stack helps manage operators, precedence and parentheses while producing the required expression order.

How do we evaluate a Postfix expression?

Scan from left to right. Push operands and apply each operator to the two operands popped from the Stack.

How do we evaluate a Prefix expression?

Scan from right to left. Push operands. When an operator appears, pop operands in the correct order, calculate and push the result.

What is the time complexity of Infix to Postfix conversion?

The standard Stack-based algorithm takes O(n) time, where n is the number of expression tokens.

What happens to parentheses in Prefix and Postfix?

Parentheses are used to determine grouping during conversion. For unambiguous binary expressions, the final Prefix and Postfix forms do not need them.

Conclusion

Infix, Prefix and Postfix Expressions become easy when we understand the position of operators.

In Infix, operators appear between operands. In Prefix, operators appear before operands. In Postfix, operators appear after operands.

Stacks are important for expression conversion and evaluation because they help manage operators and temporary calculation results.

To convert Infix into Postfix, remember operator precedence, associativity and parentheses. To evaluate Postfix, scan from left to right. To evaluate Prefix, scan from right to left.

Final Memory Trick: Infix = In-between, Prefix = Before, Postfix = After.

Practise the conversion tables and Stack dry runs to prepare for semester examination questions.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources