# What Is Infix Notation in Data Structure?

//

Heather Bennett

Infix notation is a widely used method for representing mathematical expressions. It is the most common way in which we write expressions in our day-to-day lives. In this article, we will explore what infix notation is, how it works, and its significance in data structures.

## What is Infix Notation?

In infix notation, operators are written between the operands. This means that the operator appears in between the two operands it operates on. For example, the expression 2 + 3 is written using infix notation, where the plus sign (+) is placed between the operands 2 and 3.

In mathematics, infix notation follows a set of predefined rules known as the order of operations. These rules determine the sequence in which operators are evaluated within an expression.

## Why Use Infix Notation?

Infix notation is intuitive and easy to understand for humans as it closely resembles how we write mathematical expressions on paper. It allows us to express complex arithmetic operations in a concise and readable manner.

In addition to its simplicity for human comprehension, infix notation also plays a significant role in data structures and algorithms. Many programming languages use infix notation for arithmetic expressions because it provides a convenient way to evaluate them.

### The Role of Infix Notation in Data Structures

Data structures such as stacks and queues often require us to evaluate arithmetic expressions. Infix notation serves as an intermediate representation that can be easily converted into other notations like postfix or prefix, which are more suitable for evaluation using algorithms like stack-based evaluation.

## Infix to Postfix Conversion

The process of converting an infix expression into postfix (also known as reverse Polish) notation involves rearranging the operators based on their precedence rules. This conversion simplifies the evaluation process.

Let’s consider the infix expression 3 + 4 * 2 / (1 – 5). To convert this to postfix notation, we follow these steps:

• Start scanning the expression from left to right.
• If an operand is encountered, add it to the output.
• If an operator is encountered, push it onto a stack.
• If another operator is encountered, compare its precedence with the top operator on the stack.
• If the top operator has higher precedence, pop it from the stack and add it to the output. Repeat this step until a lower precedence operator is encountered or the stack becomes empty.
• Push the current operator onto the stack.
• If a closing parenthesis is encountered, pop operators from the stack and add them to the output until an opening parenthesis is found. Discard both parentheses.

Following these steps for our example expression, we obtain the postfix notation: 3 4 2 * 1 5 – / +.

## Infix to Prefix Conversion

The process of converting an infix expression into prefix notation (also known as Polish notation) involves rearranging operators similar to postfix conversion. The only difference is that we scan the expression from right to left instead of left to right.

### In Conclusion

Infix notation is a widely used method for representing mathematical expressions. It provides a natural and intuitive way for humans to understand arithmetic operations.

In data structures and algorithms, infix notation serves as an intermediate representation that can be easily converted into other notations for efficient evaluation using algorithms like stack-based evaluation. By understanding infix notation and its conversion to postfix or prefix notations, you can gain a deeper understanding of data structures and algorithms.