AlgoScope

Expression Evaluation

AlgorithmintermediateStack Patterns

Two stacks, values and operators, evaluate infix in one pass; brackets fence the operator stack.

Decision · step 2 of 13Stacks for Expressions: Evaluate infix with two stacks
invalops(3+4)*2-8/4(

'('. An opening bracket fences the operator stack.

Open in the player →or start at step 2

What you will see

Tokens flow into stacks; an operator pops operands and pushes a result.

How stacks for expressions works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Items announce position from the top or front and value; each step announces the operation and the new top or front.

Reduced motion: Items appear or disappear in place with a crossfade instead of sliding in or out.

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

Stacks for Expressions covers these too, in the same run.