Note: These implementations are for learning purposes only. They may be less efficient than the implementations in the Python standard library. Use them at your discretion.
๐ Get Started โข ๐ Browse Algorithms โข ๐ป Code Examples โข ๐ค Contribute โข ๐ฌ Join Discord
- โจ Why Choose This Repository?
- ๐ Getting Started
- ๐ Algorithm Categories
- ๐ก Usage Examples
- ๐ค Contributing
- ๐ Community Channels
- ๐ Learning Path
- ๐ ๏ธ Development Setup
- ๐งช Testing
- ๐ Project Stats
- ๐ Resources
- ๐ Top Contributors
- ๐ License
- ๐ฌ Get Help
- โญ Show Your Support
- ๐ Perfect for Learning: Clean, well-commented code designed specifically for educational purposes
- ๐ 1300+ Implementations: One of the most comprehensive algorithm collections on GitHub
- โ Quality Assured: Every algorithm includes tests and passes continuous integration
- ๐ Community-Driven: Thousands of contributors worldwide, actively maintained
- ๐ Well-Documented: Detailed docstrings, complexity analysis, and usage examples
- ๐ฌ Multiple Domains: From basic sorting to machine learning, cryptography to computer vision
- ๐ Ready to Use: Copy, learn from, and adapt code for your projects
- ๐ฏ Interview Prep: Perfect resource for coding interviews and competitive programming
- Python 3.8 or higher
- pip (Python package installer)
- Clone the repository:
git clone https://github.com/TheAlgorithms/Python.git
cd Python
- Install dependencies:
pip install -r requirements.txt
- Run any algorithm:
python3 sorts/quick_sort.py
python3 searches/binary_search.py
pytest
Computer Science Fundamentals
Mathematics & Science
|
Machine Learning & AI
Applied Computer Science
|
๐ See our complete DIRECTORY.md for the full list of all 1300+ implementations.
from sorts.quick_sort import quick_sort
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = quick_sort(arr)
print(sorted_arr) # [11, 12, 22, 25, 34, 64, 90]
from searches.binary_search import binary_search
sorted_list = [1, 3, 5, 7, 9, 11, 13, 15, 17]
target = 7
index = binary_search(sorted_list, target)
print(f"Found {target} at index {index}") # Found 7 at index 3
from graphs.dijkstra import dijkstra
# Graph represented as adjacency list
graph = {
'A': {'B': 1, 'C': 4},
'B': {'C': 2, 'D': 5},
'C': {'D': 1},
'D': {}
}
distances = dijkstra(graph, 'A')
print(distances) # {'A': 0, 'B': 1, 'C': 3, 'D': 4}
from machine_learning.linear_regression import LinearRegression
X = [[1], [2], [3], [4], [5]]
y = [2, 4, 6, 8, 10]
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[6]])
print(prediction) # ~12
from ciphers.caesar_cipher import encrypt, decrypt
message = "HELLO WORLD"
encrypted = encrypt(message, shift=3)
print(encrypted) # "KHOOR ZRUOG"
decrypted = decrypt(encrypted, shift=3)
print(decrypted) # "HELLO WORLD"
We love contributions! This project exists thanks to all the people who contribute.
๐ Read through our Contribution Guidelines before you contribute.
- Fork the repository
- Create a new branch (
git checkout -b feature/algorithm-name
) - Make your changes and commit (
git commit -am 'Add new algorithm'
) - Push to the branch (
git push origin feature/algorithm-name
) - Create a Pull Request
We are on Discord and Gitter! Community channels are a great way for you to ask questions and get help. Please join us!
New to algorithms? Follow this recommended learning path:
- Start with Basics:
sorts/
โsearches/
โdata_structures/
- Build Foundation:
recursion/
โbacktracking/
โdivide_and_conquer/
- Advanced Topics:
dynamic_programming/
โgraphs/
โgreedy_methods/
- Specialized Areas:
machine_learning/
โciphers/
โneural_network/
Each directory contains a README with explanations and complexity analysis.
# Create virtual environment
python -m venv venv
# Activate it
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install pre-commit
pre-commit install
This will automatically format your code and run checks before each commit.
# Run all tests
pytest
# Run tests for a specific module
pytest sorts/test_sorts.py
# Run with coverage
pytest --cov=. --cov-report=html
- Total Implementations: 1300+ algorithms
- Lines of Code: 100,000+
- Contributors: 1000+
- Stars: Check the repo!
- Programming Language: Python 3.8+
- ๐ The Algorithms Website
- ๐ Python Algorithm Documentation
- ๐ Contributing Guide
- ๐ค Code of Conduct
- ๐ฅ Video Tutorials
A huge thanks to all our contributors! This project wouldn't be possible without you.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- ๐ซ Create an Issue for bug reports or feature requests
- ๐ญ Join our Discord for discussions
- ๐จ๏ธ Ask questions on Gitter
If you find this project helpful:
- Give it a โญ star on GitHub
- Share it with your friends and colleagues
- Contribute by adding new algorithms or improving existing ones
- Help us translate documentation
Happy Coding! ๐