This repository contains my code implementations and notes while working through the book "Grokking Algorithms: An Illustrated Guide for Programmers and Other Curious People (2nd Edition)" by Aditya Bhargava.
-
Visual Complexity Analysis
- Real-time plotting of algorithm performance
- Comparison with theoretical complexity curves (O(log n), O(n), O(n log n), O(n²))
- Interactive visualization using matplotlib
- Logarithmic scaling for better pattern visibility
-
Comprehensive Testing Framework
- Parallel test execution
- Automatic complexity detection
- Support for both numeric and string inputs
- Configurable timeout settings
- Detailed performance reporting
-
Search Algorithms
- Binary Search (O(log n))
- Simple Search (O(n))
- Type-safe implementations
- Support for both numbers and strings
algo_grokking_algorithm_2nd_ed/
├── ch01_introduction_to_algorithms/
│ ├── 01a_simple_search.py # Simple linear search implementation
│ └── 01b_binary_search.py # Binary search implementation
└── utils/
├── input_generator.py # Test data generation utilities
└── test_utils.py # Testing and analysis framework
- Make sure you have Python 3.12+ installed
- Install Poetry (dependency management tool)
- Clone this repository
- Run
poetry installto install dependencies - Run
poetry shellto activate the virtual environment
To run a specific search algorithm with visualization:
poetry run python -m algo_grokking_algorithm_2nd_ed.ch01_introduction_to_algorithms.01b_binary_searchThis will:
- Run the algorithm against various input sizes
- Display a real-time plot of performance characteristics
- Compare actual performance with theoretical complexity curves
- Show detailed test results in the console
- Python 3.12+
- Poetry for dependency management
- Key packages:
- matplotlib: For complexity visualization
- numpy: For numerical computations
- pytest: For testing (coming soon)
- More search algorithm implementations
- Additional visualization options
- Comprehensive test suite
- Performance benchmarking tools
- Interactive algorithm demonstrations
Feel free to open issues or submit pull requests if you have suggestions for improvements or find any bugs.
This project is licensed under the MIT License - see the LICENSE file for details.