Overview
Dijkstra's two-stack algorithm scans expression tokens, pushing values and operators until a closing parenthesis triggers one pending operation. The basic form assumes full parenthesization to avoid precedence decisions.
Evaluates fully parenthesized expressions with separate stacks for operators and values.
Compact metadata for implementation and discovery.
Dijkstra's two-stack algorithm scans expression tokens, pushing values and operators until a closing parenthesis triggers one pending operation. The basic form assumes full parenthesization to avoid precedence decisions.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(n)
value = apply(operator, left_value, right_value)Reduces a parenthesized expression when a closing parenthesis is reached.
Show value and operator stacks evaluating a parenthesized expression.
The two-stack method is intentionally simple because full parentheses encode the evaluation order.
What each reference supports for this entry.
Algorithms textbook support for Dijkstra's Two-Stack Algorithm's data-structure operations and practical implementation model.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Both use stacks to process expression operators and operands.
Pratt parsing handles precedence directly, while the two-stack form assumes full parenthesization.