Wavelet Trees

Wavelet trees answer 'count of values in range [l,r] within [a,b]' in O(log max_val).

37 lessons
138 min

Lessons

1. Intro

Why wavelet trees matter

2m

2. The Range Counting Problem

Why standard tools fail

3m

3. Binary Representation Insight

The key idea

3m

4. Wavelet Tree Structure

How it's organized

3m

5. Building the Wavelet Tree

Recursive construction

4m

6. Example: Building Step by Step

Concrete walkthrough

3m

7. Bitvector Rank Operation

Count bits up to position

3m

8. Efficient Rank with Prefix Sums

O(1) rank queries

3m

9. Position Mapping

Parent to child indices

3m

10. Count of Value in Range

Frequency query

4m

11. Range Count by Value Range

Count values in [a, b]

4m

12. Problem - Range Frequency Query

Count specific value

2m1 problems

13. Range Frequency: Hash Map Approach

Alternative solution

3m

14. Range Frequency Solution

Implement your solution

12m1 problems

15. K-th Smallest in Range

Range quantile query

4m

16. K-th Smallest: Why It Works

Binary search on values

3m

17. Problem - Kth Smallest in Range

Online quantile queries

2m2 problems

18. Kth Smallest: Merge Sort Tree

Alternative approach

4m

19. Wavelet vs Merge Sort Tree

Trade-offs

3m

20. Count Less Than in Range

Rank query

4m

21. Count Greater Than in Range

Complement query

3m

22. Successor in Range

Next greater value

4m

23. Problem - Count Smaller After Self

Inversion count variant

2m1 problems

24. Count Smaller: Multiple Approaches

BIT, segment tree, or wavelet

3m

25. Count Smaller Solution

Implement your solution

15m1 problems

26. Space Optimization

Reducing memory usage

3m

27. Coordinate Compression

Shrinking the alphabet

3m

28. Dynamic Wavelet Trees

Supporting updates

3m

29. Wavelet Matrix

More efficient variant

3m

30. Wavelet Matrix Operations

Query implementation

4m

31. Application: Mode in Range

Most frequent element

3m

32. Application: Range Majority

Element appearing > half

3m

33. Application: Distinct Count

Unique values in range

3m

34. Implementation Tips

Practical considerations

3m

35. Common Bugs

Debugging wavelet trees

3m

36. Quiz: Wavelet Trees

Test your understanding

5m1 problems

37. Section Recap

What you learned

3m

Ready to start learning?

Access all 37 lessons with interactive content and progress tracking.