← Back

Infix to Prefix Converter

What is Prefix Notation?

In infix notation, an operator appears between its operands, such as A + B. In prefix notation, the operator appears first: + A B. Prefix expressions do not require parentheses because the evaluation order is encoded by token order.

TokenizationO(n)
ConversionO(n)
Auxiliary spaceO(n)
SupportedIdentifiers and numbers

Expression and playback controls

500 ms

Step-by-step process

Click Convert to validate and prepare the expression.
Postfix output being built
Prefix result

Enter an expression and click Convert.

Current token
Operators popped0
Progress0 / 0
ComplexityO(n)

Token table

# Token Type Status

Conversion algorithm

tokens = tokenize(infix)
postfix = shuntingYard(tokens)

prefixStack = empty stack
for token in postfix:
    if token is an operand:
        prefixStack.push(token)
    else:
        right = prefixStack.pop()
        left  = prefixStack.pop()
        prefixStack.push(operator + left + right)

prefix = prefixStack.pop()

Important concepts

Operator precedence

Exponentiation has higher precedence than multiplication and division, which have higher precedence than addition and subtraction.

Associativity

Exponentiation is right-associative, so A ^ B ^ C means A ^ (B ^ C). The converter preserves this rule.

Tokenization

Multi-character operands such as value1, total, and 123 are treated as single tokens instead of separate characters.

Validation

The converter rejects mismatched parentheses, missing operands, adjacent operands, and unsupported characters before starting the visualization.

Operator rules

Operator Precedence Associativity
Unary +, unary −4Right
^3Right
*, /, %2Left
+, −1Left