Trees & Ordered Maps Medium
Word Frequency Map (TreeMap)
Count exact, already separated strings with a TreeMap. The supplied items are the words: this lesson does not tokenize text or normalize keys.
TreeMap<String, Integer>
Input
Exact stringsEach JSON string is one supplied word. Whitespace, case, and accents stay exactly as entered.
Scenarios
Ordered word map
Distinct keys in Java natural string order
TreeMap keyCount
The TreeMap orders keys; frequencies do not change their position.
Current operation
Trace stateKey—
Lookup result—
Iterator position—
Map writes 0Queries 0Keys yielded 0
BestO(log U)
AverageO(log U)
WorstO(log U)
U is the number of distinct keys; TreeMap keeps its search tree balanced.
Algorithm code
JavaWordCounter.java · algorithms_exercises @ 9cf5b34Step linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1