Advanced Topic 50 of 52 Data Structures
Merkle Trees
Hash trees enabling efficient integrity verification.
How it works
A Merkle tree hashes each leaf data block, then repeatedly hashes pairs of child hashes upward until a single root hash summarizes all data. Changing any block changes its leaf hash and every hash on the path to the root. A short proof of O(log n) sibling hashes lets anyone verify that a block belongs to the tree without holding the whole dataset.
Where it is used
Git and other version control systems, Bitcoin and Ethereum blocks, certificate transparency logs, distributed databases like Cassandra for anti-entropy repair and file-sharing systems like BitTorrent use Merkle trees.
Common pitfall
Use a collision-resistant hash. Without domain separation between leaf and internal nodes, second-preimage attacks are possible. Handling an odd number of nodes needs a clear rule such as duplicating or promoting the last node. The root must come from a trusted source.
Where it fits in the course
Merkle Trees is topic 50 of 52 in Data Structures, rated Advanced. It follows HyperLogLog. The next topic is Rope Data Structure.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
- Explore the Binary Search Tree visualizer: Insert keys and run traversals.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Merkle Trees?
Where do people use Merkle Trees?
What is the most common mistake with Merkle Trees?
What should I learn before this topic?
How can I practice it?
Is Merkle Trees hard to learn?
How long does it take to learn Merkle Trees?
Which topics are related to Merkle Trees?
What should I study after Merkle Trees?
Related topics
- HyperLogLog (Data Structures)
- Rope Data Structure (Data Structures)
- Count-Min Sketch (Data Structures)
- Union of Sets with Bitsets (Data Structures)
- Decision Trees (AI & Machine Learning)
- Trees in Graph Theory (Theory & Discrete Math)
- Abstract Syntax Trees (Languages & Compilers)