Trees & Ordered Maps Hard
Expression Tree Evaluation
Trace Advent of Code's named monkey jobs through a HashMap and depth-first recursive evaluation.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(n + e) for the evaluated dependency expansion
AverageO(n + e)
WorstO(n + e), bounded here by the recursive call cap
SpaceO(n + h + e) for definitions, call stack, and traced calls
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Build the last-definition-wins name map, then evaluate root with Java long arithmetic, finishing each left dependency before the right.
- HashMap.put replaces the value for an equal name; the last input definition becomes the active monkey.
- Each OperationMonkey yells its left child completely before looking up and yelling its right child.
- The source does not memoize: a shared dependency is recursively evaluated again for every reference.
- YellingMonkey numbers are Java int values, but operation results are signed Java long values with wraparound.
- Java integer division truncates toward zero; division by zero is rejected because the source would throw ArithmeticException.
Algorithm code
JavaMonkeys.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1