TExcelTAD
Home › Advanced & Succinct Data Structures › Information-Theoretic Space Lower Bounds

Information-Theoretic Space Lower Bounds

How small can a data structure be? If a structure must be able to represent any one of LL different objects, then some object needs at least ⌈lg⁡L⌉\lceil \lg L \rceil bits: with fewer bits there are fewer than LL distinct memory contents. That count, the information-theoretic lower bound OPT=⌈lg⁡L⌉\mathrm{OPT} = \lceil \lg L \rceil, is the yardstick for the rest of this section. It is the same counting as the decision-tree lower bound for sorting and the source coding theorem of information theory, applied to space.

Three levels of compactness

Following the terminology of Jacobson (1989) and Navarro's book on compact data structures, a structure that uses OPT\mathrm{OPT} bits plus

Name Space Example
implicit OPT+O(1)\mathrm{OPT} + O(1) bits a sorted array searched by binary search; a binary heap
succinct OPT+o(OPT)\mathrm{OPT} + o(\mathrm{OPT}) bits rank/select bit vectors, balanced-parentheses trees
compact O(OPT)O(\mathrm{OPT}) bits most compressed indexes

and, the point of the whole field, still answers its queries fast, usually in O(1)O(1) or O(lg⁡n)O(\lg n) time on a word-RAM with w=Θ(lg⁡n)w = \Theta(\lg n). Storing OPT\mathrm{OPT} bits is easy (number the objects and write down the number); answering queries on such a code without decompressing it is the hard part.

Common bounds

Object Number of objects LL lg⁡L\lg L (bits)
a subset of size nn of {0,…,U−1}\{0, \ldots, U - 1\} (Un)\binom{U}{n} nlg⁡Un+O(n)n \lg \frac{U}{n} + O(n)
a bit vector of length nn with mm ones (nm)\binom{n}{m} ≈nH0\approx n H_0, $H_0 = $ the entropy of the ones' density
a permutation of nn elements n!n! nlg⁡n−nlg⁡e+O(lg⁡n)n \lg n - n \lg e + O(\lg n)
a binary tree with nn nodes (shape only) Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n} 2n−32lg⁡n+O(1)2n - \frac{3}{2}\lg n + O(1)
an ordinal (rooted, ordered) tree with nn nodes Cn−1C_{n-1} 2n−O(lg⁡n)2n - O(\lg n)

The Catalan numbers CnC_n count binary tree shapes; Stirling's formula gives Cn≈4nn3/2πC_n \approx \frac{4^n}{n^{3/2}\sqrt{\pi}}, so about 2 bits per node suffice for a tree's shape. A pointer-based binary tree uses two pointers of lg⁡n\lg n bits each per node, 2nlg⁡n2n \lg n bits: for a million nodes, 40 times the minimum. Entropy explains the bit-vector row: lg⁡(nm)=nH(m/n)−O(lg⁡n)\lg \binom{n}{m} = n H(m/n) - O(\lg n).

python · try it yourself
import math

def lg_comb(n, k):                               # fine for moderate n
    return (math.lgamma(n + 1) - math.lgamma(k + 1) - math.lgamma(n - k + 1)) / math.log(2)

def lg_comb_big(U, n):                           # lg C(U, n) for huge U, without cancellation
    s = sum(math.log1p(-i / U) for i in range(n))  # ln of (U - i) / U for i < n
    return (n * math.log(U) + s - math.lgamma(n + 1)) / math.log(2)

print("binary tree shapes:")
for n in [10, 1000, 10 ** 6]:
    lg_catalan = lg_comb(2 * n, n) - math.log2(n + 1)
    print(f"  n = {n:>7}: lg C_n = {lg_catalan:12.1f} bits ({lg_catalan / n:.3f} per node); "
          f"pointers need 2n lg n = {2 * n * math.log2(n):14.0f}")
print("subsets of size n of a universe of size U:")
for U, n in [(2 ** 32, 10 ** 5), (2 ** 64, 10 ** 5), (10 ** 6, 5 * 10 ** 5)]:
    print(f"  U = {U:.3g}, n = {n:.0e}: lg C(U, n) = {lg_comb_big(U, n) / n:6.2f} bits per element, "
          f"n lg(U/n) + n lg e = {(math.log2(U / n) + math.log2(math.e)):6.2f}, plain array {math.log2(U):5.1f}")
binary tree shapes:
  n =      10: lg C_n =         14.0 bits (1.404 per node); pointers need 2n lg n =             66
  n =    1000: lg C_n =       1984.2 bits (1.984 per node); pointers need 2n lg n =          19932
  n = 1000000: lg C_n =    1999969.3 bits (2.000 per node); pointers need 2n lg n =       39863137
subsets of size n of a universe of size U:
  U = 4.29e+09, n = 1e+05: lg C(U, n) =  16.83 bits per element, n lg(U/n) + n lg e =  16.83, plain array  32.0
  U = 1.84e+19, n = 1e+05: lg C(U, n) =  48.83 bits per element, n lg(U/n) + n lg e =  48.83, plain array  64.0
  U = 1e+06, n = 5e+05: lg C(U, n) =   2.00 bits per element, n lg(U/n) + n lg e =   2.44, plain array  19.9

The last row shows the approximation nlg⁡Un+nlg⁡en \lg \frac{U}{n} + n \lg e failing for dense sets: with n=U/2n = U/2 the exact count is 2 bits per element, that is, 1 bit per element of the universe, which a plain bit vector of UU bits already achieves.

Reaching about 2 bits per node: encoding a tree

A binary tree shape can be written in 2n+12n + 1 bits: traverse it in preorder and write 1 for each node and 0 for each empty subtree (there are n+1n + 1 of those). The sequence can be decoded uniquely, because a preorder walk knows when a subtree is complete. This is a succinct encoding but not yet a succinct data structure: to find the parent or the ii-th child of a node, one would have to decode from the start. The next two lessons add the o(n)o(n)-bit indexes (rank and select, then balanced parentheses) that make such navigation O(1)O(1).

python · try it yourself
import random

def random_tree(n, rng):                         # a random binary tree shape as nested tuples
    if n == 0:
        return None
    left = rng.randrange(n)
    return (random_tree(left, rng), random_tree(n - 1 - left, rng))

def encode(t, out):                              # preorder: 1 = node, 0 = empty subtree
    if t is None:
        out.append(0); return
    out.append(1); encode(t[0], out); encode(t[1], out)

def decode(bits, i=0):                           # returns (tree, next position)
    if bits[i] == 0:
        return None, i + 1
    left, i = decode(bits, i + 1)
    right, i = decode(bits, i)
    return (left, right), i

def size(t):
    return 0 if t is None else 1 + size(t[0]) + size(t[1])

rng = random.Random(1989)
t = random_tree(12, rng)
bits = []
encode(t, bits)
print("12-node tree in", len(bits), "bits:", "".join(map(str, bits)))
back, used = decode(bits)
print("decodes to the same shape:", back == t, "| bits read:", used)
for n in [100, 500]:
    t = random_tree(n, rng); bits = []; encode(t, bits)
    assert decode(bits)[0] == t and size(t) == n
    print(f"n = {n}: {len(bits)} bits = 2n + 1; pointer representation with 32-bit pointers: {64 * n} bits")
12-node tree in 25 bits: 1111000111100001010010100
decodes to the same shape: True | bits read: 25
n = 100: 201 bits = 2n + 1; pointer representation with 32-bit pointers: 6400 bits
n = 500: 1001 bits = 2n + 1; pointer representation with 32-bit pointers: 32000 bits

In C++

The same preorder encoding into a std::vector<bool> and back, on a fixed tree written as a string ("(LR)" for a node with subtrees L and R, "." for an empty subtree).

cpp · try it yourself
#include <cstdio>
#include <memory>
#include <string>
#include <vector>

struct Node {
    std::unique_ptr<Node> left, right;
};

std::unique_ptr<Node> parse(const std::string& s, std::size_t& i) {   // "(LR)" or "."
    if (s[i] == '.') { ++i; return nullptr; }
    ++i;                                                            // '('
    auto n = std::make_unique<Node>();
    n->left = parse(s, i);
    n->right = parse(s, i);
    ++i;                                                            // ')'
    return n;
}
void encode(const Node* t, std::vector<bool>& bits) {
    bits.push_back(t != nullptr);
    if (t) { encode(t->left.get(), bits); encode(t->right.get(), bits); }
}
std::unique_ptr<Node> decode(const std::vector<bool>& bits, std::size_t& i) {
    if (!bits[i++]) return nullptr;
    auto n = std::make_unique<Node>();
    n->left = decode(bits, i);
    n->right = decode(bits, i);
    return n;
}
std::string show(const Node* t) { return t ? "(" + show(t->left.get()) + show(t->right.get()) + ")" : "."; }

int main() {
    std::string text = "((..)((.(..)).))";
    std::size_t i = 0;
    auto tree = parse(text, i);
    std::vector<bool> bits;
    encode(tree.get(), bits);
    std::printf("tree %s -> %zu bits: ", text.c_str(), bits.size());
    for (bool b : bits) std::printf("%d", b ? 1 : 0);
    std::size_t j = 0;
    auto back = decode(bits, j);
    std::printf("\ndecoded: %s (%s)\n", show(back.get()).c_str(), show(back.get()) == text ? "same" : "different");
}
tree ((..)((.(..)).)) -> 11 bits: 11001101000
decoded: ((..)((.(..)).)) (same)

Lower bounds on time as well as space

Space and time trade off. A classic example is the bit-probe complexity of membership: storing a set of nn elements from a universe of size UU in close to lg⁡(Un)\lg \binom{U}{n} bits and answering membership with few bit probes. Buhrman, Miltersen, Radhakrishnan and Venkatesh (2000) showed that randomized schemes can use O(nlg⁡U)O(n \lg U) bits and one bit probe (with a small error probability), while deterministic schemes with one probe need much more space. For rank and select, Pătrașcu (2008) showed that O(1)O(1)-time rank can be achieved with n+n/(lg⁡n/t)t+O~(n3/4)n + n / (\lg n / t)^t + \tilde{O}(n^{3/4}) bits for any constant tt, and Pătrașcu and Viola (2010) proved that this redundancy is essentially optimal. So "o(n)o(n) extra bits" in the next lesson is not a fixed quantity: the extra space can be made very small, at a cost in time.

Test yourself

About how many bits per node are needed, in the worst case, to store the shape of a binary tree with nn nodes?

  1. 1
  2. 2
  3. lg⁡n\lg n
  4. 2lg⁡n2 \lg n

A structure using OPT+o(OPT)\mathrm{OPT} + o(\mathrm{OPT}) bits is called...

  1. implicit
  2. succinct
  3. compact
  4. compressed

How many bits does the information-theoretic bound give for storing nn elements of a universe of size U≫nU \gg n?

  1. nlg⁡Un \lg U
  2. lg⁡(Un)≈nlg⁡(U/n)+nlg⁡e\lg \binom{U}{n} \approx n \lg (U/n) + n \lg e
  3. UU
  4. lg⁡U\lg U