Advanced Data Structures – Summer 2026 – Lecture 2


A static bit vector is an implicit data structure storing \(n\) bits \(b_0, \dots, b_{n-1}\) with constant overhead.
Implemented using e.g. Vec<u64>.
fn get(data: &Vec<u64>, i: usize) -> bool {
let word = data[i / 64]; // compiled to >> 6
let idx = i % 64; // compiled to & 0b0011_1111
return ((word >> idx) & 1) > 0;
}
Little Endian: the low-order bits are first in memory.
\[ \newcommand{\rank}{\mathsf{rank}} \newcommand{\select}{\mathsf{select}} \]

A rank query on a bit vector counts 1-bits before a position \(i\) (for \(0\leq i\leq n\)).
A select query on a bit vector returns the position of the \(j\)'th 1 (zero-based, for \(0\leq j < \rank(n)\)).
Also: \(\rank_0\) and \(\select_0\) for counting/finding 0-bits.
What is \(\rank_1(\select_1(j))\)?
And \(\select_1(\rank_1(i))\)?
\(\rank_1(\select_1(j))\) equals \(j\).
\(\select_1(\rank_1(i))\) finds the position of the first 1 at position \(\geq i\).

There exists a data structure that answers rank and select queries:

Compute the answer on-demand:
Pre-compute and store all answers:

Store positions of all 1-bits. Then binary search to get the number of them at position \(\lt i\):

Store a checkpoint every \(s\) bits: \(R_k := \rank(k\cdot s)\).
For \(s=w = \Theta(\log n)\):


Instead, we can take \(s = (\log_2 n)/2\), and pre-compute popcounts for all \(2^s\) masks:
\[2^s \cdot s \cdot \log_2 s = O(\sqrt n \cdot \log_2 n \cdot \log_2\log_2 n) = o(n).\]

In practice, we don't need succinct. Compact with small constant overhead is enough. See QuadRank slides.
u64.
Assume we have \(k\) 1-bits.
The position of \(i\)'th 1-bit in a word can be found in constant time (in the "modern" word RAM model) using
(1 << i).deposit_bits(word).trailing_zeros()
which uses pdep and tzcnt instructions (wikipedia, deposit_bits).

Dense blocks with \(|B| < \log^4 n\):
Split again into variable-sized blocks of \(b'=\sqrt{\log n}\) ones.
select_in_wordTo answer \(\select(j)\):
There exists a data structure with \(o(n)\) space overhead that allows \(O(1)\) rank and select queries.







