Skip to content

Conversation

@rodrigobnogueira
Copy link

Description

Implements a Merkle tree (hash tree) data structure for efficient and secure verification of large data structures. Merkle trees are fundamental to blockchain, distributed systems, and cryptographic applications.

Features

  • Complete Merkle tree implementation with tree construction
  • Root hash calculation for data integrity verification
  • Merkle proof generation (O(log n) complexity)
  • Proof verification without rebuilding tree
  • Handles odd number of leaves correctly
  • SHA-256 hashing with 64-character hex output
  • Type hints on all methods
  • 37 comprehensive doctests

Real-world Applications

  • Bitcoin and Blockchain: Efficiently verify transactions in blocks
  • Git: Verify repository integrity and commit history
  • IPFS: Content-addressed distributed file system
  • Certificate Transparency: SSL/TLS certificate verification
  • Apache Cassandra: Anti-entropy for data synchronization
  • BitTorrent: Verify pieces of downloaded files

Complexity

  • Build tree: O(n)
  • Generate proof: O(log n)
  • Verify proof: O(log n)
  • Space: O(n)

References

Testing

  • 37 doctests pass
  • Passes ruff linting
  • Passes mypy type checking
  • Verified against online tools

Checklist

  • I have read and followed the contributing guidelines
  • This pull request is not a duplicate
  • The algorithm is implemented from scratch
  • The code follows the repository style
  • I have read CONTRIBUTING.md
  • This pull request is all my own work -- I have not plagiarized
  • I know that pull requests will not be merged if they fail the automated tests
  • This PR only changes one algorithm file
  • All new Python files are placed inside an existing directory (data_structures/hashing/)
  • All filenames are in all lowercase characters with no spaces or dashes
  • All functions and variable names follow Python naming conventions
  • All function parameters and return values are annotated with Python type hints
  • All functions have doctests that pass the automated testing
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation

rodrigo.nogueira added 2 commits December 29, 2025 12:22
- Implements byte order conversions for 16/32/64-bit integers
- Provides bidirectional bytes ↔ int conversions
- Supports both big-endian and little-endian formats
- Includes comprehensive doctests with real-world examples
- Documents use cases: network protocols, cryptography, file formats
- All tests pass: ruff, mypy, doctests
- Implements complete Merkle tree (hash tree) for efficient data verification
- Supports tree construction, root hash calculation, and proof generation
- Includes proof verification without rebuilding tree
- Comprehensive documentation with real-world use cases
- 37 passing doctests covering all functionality
- All tests pass: ruff, mypy, doctests
@algorithms-keeper
Copy link

Multiple Pull Request Detected

@rodrigobnogueira, we are extremely excited that you want to submit multiple algorithms in this repository but we have a limit on how many pull request a user can keep open at a time. This is to make sure all maintainers and users focus on a limited number of pull requests at a time to maintain the quality of the code.

This pull request is being closed as the user already has an open pull request. Please focus on your previous pull request before opening another one. Thank you for your cooperation.

User opened pull requests (including this one): #14053, #14041, #14037, #14036, #14035

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant