Data Structures19 sections · 729 units
Open in Course

Position Mapping

Parent to child indices

When we descend from a node to its child, you need to map positions.

If you're tracking range [l,r][l, r] at a node, and we go left (to elements with bit 0):

  • New left index: rank0(B,l)\text{rank}_0(B, l)
  • New right index: rank0(B,r+1)1\text{rank}_0(B, r + 1) - 1

Going right (to elements with bit 1):

  • New left index: rank1(B,l)\text{rank}_1(B, l)
  • New right index: rank1(B,r+1)1\text{rank}_1(B, r + 1) - 1

This mapping is the core of all wavelet tree queries. It tells us which positions in the child correspond to your query range.