Sparse Tables: O(1) Range Minimum

Data Structures & Algorithms · Advanced Trees & Queries · Advanced · 20 min

Precompute the minimum of every power-of-two block in O(n log n), then answer any range minimum (or maximum, or gcd) query in O(1) with two overlapping blocks.

This lesson is part of TuringPath Pro. See plans.

What you will learn

  • Static data, many questions
  • The table: minimums of power-of-two blocks
  • The O(1) query: two overlapping blocks
  • Why it only works for idempotent operations
  • Sparse table or segment tree?

More in Advanced Trees & Queries

Previous: LCA & Binary Lifting · Next: Offline Queries & Mo's Algorithm