DSAVisualiseData Structures & Algorithms Studio
Trees & Ordered Maps Hard

TreeMap Range Queries

Follow the source's TreeMap from exact birthday strings to insertion-ordered lists of distinct Person objects.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(log n + k) per query
AverageO(log n + k) per query
WorstO(log n + k) per query
SpaceO(p + n) for p people across n distinct birthday keys

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Add people, retrieve all people with an exact birthday, then flatten a half-open sorted-map range for one calendar year.

  • TreeMap orders exact date strings lexicographically; valid zero-padded dates sort chronologically.
  • Equal date strings share one list, but distinct Person objects with equal names and dates remain separate entries.
  • The exact-date query preserves add order; the year query visits dates in sorted order and then preserves each date list's order.
  • The year range is start-inclusive and next-year-exclusive, built exactly as `year + '-01-01'` to `(parseInt(year) + 1) + '-01-01'`.
  • The pinned source's valid year 9999 produces a reversed lexical range and TreeMap throws IllegalArgumentException.

Algorithm code

Java
BirthdayMap.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1