Skip to content

DivyanshRajSoni/Python

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Gitpod Ready-to-Code Contributions Welcome Discord chat Gitter chat
GitHub Workflow Status pre-commit code style: black

All algorithms implemented in Python - for education ๐Ÿ“š

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.


๐ŸŒŸ Quick Links

๐Ÿš€ Get Started โ€ข ๐Ÿ“– Browse Algorithms โ€ข ๐Ÿ’ป Code Examples โ€ข ๐Ÿค Contribute โ€ข ๐Ÿ’ฌ Join Discord


๐Ÿ“‘ Table of Contents

โœจ Why Choose This Repository?

  • ๐ŸŽ“ 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

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)

Installation

  1. Clone the repository:
git clone https://github.com/TheAlgorithms/Python.git
cd Python
  1. Install dependencies:
pip install -r requirements.txt
  1. Run any algorithm:
python3 sorts/quick_sort.py
python3 searches/binary_search.py

Running Tests

pytest

๐Ÿ“š Algorithm Categories

Computer Science Fundamentals

  • ๐Ÿ—‚๏ธ Data Structures (Arrays, Trees, Graphs, Heaps)
  • ๐Ÿ”„ Sorting (Quick, Merge, Heap, Radix, etc.)
  • ๐Ÿ” Searching (Binary, Ternary, Jump, etc.)
  • ๐Ÿ”™ Backtracking (N-Queens, Sudoku, Maze)
  • ๐ŸŒŠ Divide and Conquer
  • ๐Ÿ’ฐ Dynamic Programming
  • ๐ŸŽฏ Greedy Algorithms
  • ๐Ÿ“Š Graph Algorithms (BFS, DFS, Dijkstra, Floyd-Warshall)

Mathematics & Science

  • โž• Mathematical Algorithms
  • ๐Ÿ”ข Number Theory
  • ๐Ÿ“ Geometry & Computational Geometry
  • ๐Ÿงฎ Linear Algebra & Matrix Operations
  • ๐Ÿ“ˆ Statistics & Probability
  • โš›๏ธ Physics Simulations
  • ๐ŸŒ Geodesy

Machine Learning & AI

  • ๐Ÿค– Machine Learning (Regression, Classification)
  • ๐Ÿง  Neural Networks
  • ๐Ÿงฌ Genetic Algorithms
  • ๐ŸŽฒ Fuzzy Logic
  • ๐Ÿ“Š Data Mining

Applied Computer Science

  • ๐Ÿ” Cryptography & Ciphers
  • ๐Ÿ–ผ๏ธ Computer Vision
  • ๐ŸŽจ Digital Image Processing
  • ๐ŸŽต Audio Filters
  • ๐ŸŒ Web Programming
  • ๐Ÿ“ก Networking & Data Transfer
  • ๐Ÿ—œ๏ธ Data Compression
  • ๐Ÿ’น Financial Algorithms
  • โšก Electronics & Circuit Design

๐Ÿ“– See our complete DIRECTORY.md for the full list of all 1300+ implementations.

๐Ÿ’ก Usage Examples

Quick Start - Sorting

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]

Binary Search

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

Graph Algorithms - Dijkstra's Shortest Path

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}

Machine Learning - Linear Regression

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

Cryptography - Caesar Cipher

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"

๐Ÿค Contributing

We love contributions! This project exists thanks to all the people who contribute.

๐Ÿ“‹ Read through our Contribution Guidelines before you contribute.

How to Contribute

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/algorithm-name)
  3. Make your changes and commit (git commit -am 'Add new algorithm')
  4. Push to the branch (git push origin feature/algorithm-name)
  5. Create a Pull Request

๐ŸŒ Community Channels

We are on Discord and Gitter! Community channels are a great way for you to ask questions and get help. Please join us!

๐ŸŽ“ Learning Path

New to algorithms? Follow this recommended learning path:

  1. Start with Basics: sorts/ โ†’ searches/ โ†’ data_structures/
  2. Build Foundation: recursion/ โ†’ backtracking/ โ†’ divide_and_conquer/
  3. Advanced Topics: dynamic_programming/ โ†’ graphs/ โ†’ greedy_methods/
  4. Specialized Areas: machine_learning/ โ†’ ciphers/ โ†’ neural_network/

Each directory contains a README with explanations and complexity analysis.

๐Ÿ› ๏ธ Development Setup

Using Virtual Environment

# 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

Using pre-commit hooks

pip install pre-commit
pre-commit install

This will automatically format your code and run checks before each commit.

๐Ÿงช Testing

# Run all tests
pytest

# Run tests for a specific module
pytest sorts/test_sorts.py

# Run with coverage
pytest --cov=. --cov-report=html

๐Ÿ“Š Project Stats

  • Total Implementations: 1300+ algorithms
  • Lines of Code: 100,000+
  • Contributors: 1000+
  • Stars: Check the repo!
  • Programming Language: Python 3.8+

๐Ÿ“– Resources

๐Ÿ† Top Contributors

A huge thanks to all our contributors! This project wouldn't be possible without you.

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE.md file for details.

๐Ÿ’ฌ Get Help

  • ๐Ÿ“ซ Create an Issue for bug reports or feature requests
  • ๐Ÿ’ญ Join our Discord for discussions
  • ๐Ÿ—จ๏ธ Ask questions on Gitter

โญ Show Your Support

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

Made with โค๏ธ by contributors around the ๐ŸŒ
Happy Coding! ๐Ÿš€

About

All Algorithms implemented in Python

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.8%
  • Other 0.2%