Introduction to Merkle Tree
Merkle tree also known as hash tree is a data structure used for data verification and synchronization.
It is a tree data structure where each non-leaf node is a hash of it’s child nodes. All the leaf nodes are at the same depth and are as far left as possible.
It maintains data integrity and uses hash functions for this purpose.
So before understanding how Merkle trees work, we need to understand how hash functions work.
A hash function maps an input to a fixed output and this output is called hash. The output is unique for every input and this enables fingerprinting of data. So, huge amounts of data can be easily identified through their hash.
This is a binary merkel tree, the top hash is a hash of the entire tree.
- This structure of the tree allows efficient mapping of huge data and small changes made to the data can be easily identified.
- If we want to know where data change has occurred then we can check if data is consistent with root hash and we will not have to traverse the whole structure but only a small part of the structure.
- The root hash is used as the fingerprint for the entire data.
For a Binary Merkel tree
- Merkle trees are useful in distributed systems where same data should exist in multiple places.
- Merkle trees can be used to check inconsistencies.
- Apache Cassandra uses Merkle trees to detect inconsistencies between replicas of entire databases.
- It is used in bitcoin and blockchain.
...a628f9ed881e2d784cb9cd85f3d5d04a6489 Value: 4fcfb77eaf9a279c4ff2d20171c1626c2823a82a2cec1ddc0c23dbcb48822e80 Content: Portal+For+Geeks+Geeks Left: b65ffe0cec61786d5d090268b99a14a807101d847fe4f5fbb4daa2764b73cd84 Right: ca15ebc05a3c5c1348753b209c4452c54022dbe565d9943b11c795e3af9eb0b0 Value: 67da93d6580ec1ef25cd9589147fcf93c7612f1063c37e92b0c441627afdd8bb Content: Portal+For Input Value: b65ffe0cec61786d5d090268b99a14a807101d847fe4f5fbb4daa2764b73cd84 Content: Portal Input Value: ca15ebc05a3c5c1348753b209c4452c54022dbe565d9943b11c795e3af9eb0b0 Content: For Left: 0c0dcd8c8d8c6c0dfba6677e1e11076ff864f3351e3cbd1a6c9571269b4d655d Right: 0c0dcd8c8d8c6c0dfba6677e1e11076ff864f3351e3cbd1a6c9571269b4d655d Value: 9855c9f31157005f7f2ff1c7ca91a628f9ed881e2d784cb9cd85f3d5d04a6489 Content: Geeks+Geeks Input Value: 0c0dcd8c8d8c6c0dfba6677e1e11076ff864f3351e3cbd1a6c9571269b4d655d Content: Geeks Input (Padding) Value: 0c0dcd8c8d8c6c0dfba6677e1e11076ff864f3351e3cbd1a6c9571269b4d655d Content: Geeks