##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Wavelet trees answer 'count of values in range [l,r] within [a,b]' in O(log max_val).
Why wavelet trees matter
Why standard tools fail
The key idea
How it's organized
Recursive construction
Concrete walkthrough
Count bits up to position
O(1) rank queries
Parent to child indices
Frequency query
Count values in [a, b]
Count specific value
Alternative solution
Implement your solution
Range quantile query
Binary search on values
Online quantile queries
Alternative approach
Trade-offs
Rank query
Complement query
Next greater value
Inversion count variant
BIT, segment tree, or wavelet
Implement your solution
Reducing memory usage
Shrinking the alphabet
Supporting updates
More efficient variant
Query implementation
Most frequent element
Element appearing > half
Unique values in range
Practical considerations
Debugging wavelet trees
Test your understanding
What you learned