codeintuition-logo

Understanding the evaluation of prefix expressions


Evaluation of the prefix notation of a mathematical expression is very similar to the postfix notation. Since the placement of operators and operands in the notation implicitly enforces precedence, we traverse the sequence and incrementally evaluate results as we see the operands. The only between evaluation postfix and prefix notation is that for evaluating a prefix notation we traverse the sequence in reverse from end to start.

Consider we are given the prefix notation of a mathematical expression as a string given below, where every operand is a single-digit number.

Loading Image

Prefix expression with only single digit numbers as a string.

Liking the course? Check our discounted plans to continue learning.