ArticleslgStudy

computer science

Wavelet Tree

Wavelet Tree is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Wavelet Tree rather than just read about it. In short: The wavelet tree is a succinct data structure to store strings in compressed space. It generalizes the r a n k q {\displaystyle \mathbf {rank} _{q}} and s e l e c t q {\displaystyle \mathbf {select} _{q}} operations defined on bitvectors to arbitrary alphabets.

Wavelet Tree — main illustration
Wavelet Tree — illustration

Key takeaways

  • Wavelet Tree belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Wavelet Tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Wavelet Tree from memory before moving on to harder problems.

Reference excerpt

The wavelet tree is a succinct data structure to store strings in compressed space. It generalizes the r a n k q {\displaystyle \mathbf {rank} _{q}} and s e l e c t q {\displaystyle \mathbf {select} _{q}} operations defined on bitvectors to arbitrary alphabets. Originally introduced to represent compressed suffix arrays, it has found application in several contexts. The tree is defined by recursively partitioning the alphabet into pairs of subsets; the leaves correspond to individual symbols of the alphabet, and at each node a bitvector stores whether a symbol of the string belongs to one subset or the other. The name derives from an analogy with the wavelet transform for signals, which recursively decomposes a signal into low-frequency and high-frequency components.

Properties Let Σ {\displaystyle \Sigma } be a finite alphabet with σ = | Σ | {\displaystyle \sigma ={|\Sigma |}} . By using succinct dictionaries in the nodes, a string s ∈ Σ ∗ {\displaystyle s\in \Sigma ^{*}} can be stored in | s | H 0 ( s ) + o ( | s | log ⁡ σ ) {\displaystyle {|s|}H_{0}(s)+o({|s|}\log \sigma )} , where H 0 ( s ) {\displaystyle H_{0}(s)} is the order-0 empirical entropy of s {\displaystyle s} . If the tree is balanced, the operations a c c e s s {\displaystyle \mathbf {access} } , r a n k q {\displaystyle \mathbf {rank} _{q}} , and s e l e c t q {\displaystyle \mathbf {select} _{q}} can be supported in O ( log ⁡ σ ) {\displaystyle O(\log \sigma )} time.

Access operation A wavelet tree contains a bitmap representation of a string. If we know the alphabet set, then the exact string can be inferred by tracking bits down the tree. To find the letter at ith position in the string :-

In this context, the rank of a position i {\displaystyle i} in a bitvector b {\displaystyle b} is the number of ones that appear in the first i {\displaystyle i} positions of b {\displaystyle b} . Because the rank can be calculated in O(1) by using succinct dictionaries, any S[i] in string S can be accessed in O ( log ⁡ σ ) {\displaystyle O(\log \sigma )} time, as long as the tree is balanced.

Extensions Several extensions to the basic structure have been presented in the literature. To reduce the height of the tree, multiary nodes can be used instead of binary. The data structure can be made dynamic, supporting insertions and deletions at arbitrary points of the string; this feature enables the implementation of dynamic FM-indexes. This can be further generalized, allowing the update operations to change the underlying alphabet: the Wavelet Trie exploits the trie structure on an alphabet of strings to enable dynamic tree modifications.

Further reading Wavelet Trees. A blog post describing the construction of a wavelet tree, with examples.

References

External links Media related to Wavelet Tree at Wikimedia Commons

Illustrations

Wavelet Tree: A wavelet tree on the string "abracadabra". At each node the symbols of the string are projected onto two partitions of the alphabet, and a bitvector denotes to which partition each symbol belongs. Note that only the bitvectors are stored; the strings in the nodes are only for illustratory purposes.
A wavelet tree on the string "abracadabra". At each node the symbols of the string are projected onto two partitions of the alphabet, and a bitvector denotes to which partition each symbol belongs. Note that only the bitvectors are stored; the strings in the nodes are only for illustratory purposes.

Worked examples

Example 1 — a first encounter with Wavelet Tree

Start with the simplest possible case. Write down what Wavelet Tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Wavelet Tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Wavelet Tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Wavelet Tree

In research
Wavelet Tree appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Wavelet Tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Wavelet Tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics String data structures, Succinct data structure, Trees (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for Wavelet Tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Wavelet Tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Wavelet Tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Wavelet Tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Wavelet Tree in simple terms?

The wavelet tree is a succinct data structure to store strings in compressed space. It generalizes the r a n k q {\displaystyle \mathbf {rank} _{q}} and s e l e c t q {\displaystyle \mathbf {select} _{q}} operations defined on bitvectors to arbitrary alphabets.

Why does Wavelet Tree matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Wavelet Tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Wavelet Tree.

Tags

  • String data structures
  • Succinct data structure
  • Trees (data structures)

Keep exploring