Skip to content

devvratpathak/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 πŸ“š

Implementations are for learning purposes only. They may be less efficient than the implementations in the Python standard library. Use them at your discretion.

οΏ½ Table of Contents

οΏ½ About

This repository contains Python implementations of various algorithms and data structures for educational purposes. Whether you're a student learning algorithms, a developer preparing for technical interviews, or someone interested in computer science fundamentals, this collection provides clear and well-documented examples.

✨ Features

This repository includes implementations of algorithms across multiple categories:

  • Sorting Algorithms: Bubble sort, Quick sort, Merge sort, Heap sort, and more
  • Searching Algorithms: Binary search, Linear search, Jump search, Interpolation search
  • Data Structures: Linked lists, Stacks, Queues, Trees, Graphs, Hash tables
  • Graph Algorithms: BFS, DFS, Dijkstra's algorithm, Floyd-Warshall, Bellman-Ford
  • Dynamic Programming: Knapsack, Longest Common Subsequence, Edit Distance
  • Machine Learning: Neural networks, Linear regression, K-means clustering
  • Mathematical Algorithms: Prime number algorithms, GCD, LCM, Number theory
  • String Algorithms: Pattern matching, String manipulation, Parsing
  • Cryptography: Various cipher implementations
  • Computer Vision: Image processing algorithms
  • And many more!

All implementations include:

  • Clear documentation and explanations
  • Type hints for better code readability
  • Doctests for validation
  • Educational comments

πŸš€ Getting Started

Installation

  1. Clone the repository

    git clone https://github.com/TheAlgorithms/Python.git
    cd Python
  2. Set up a virtual environment (recommended)

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

Usage

Each algorithm is self-contained in its own file. You can run any algorithm directly or import it into your own projects.

Example 1: Running an algorithm directly

python sorts/quick_sort.py

Example 2: Importing and using an algorithm

from sorts.quick_sort import quick_sort

# Sort a list
numbers = [64, 34, 25, 12, 22, 11, 90]
sorted_numbers = quick_sort(numbers)
print(sorted_numbers)  # Output: [11, 12, 22, 25, 34, 64, 90]

Example 3: Running doctests

python -m doctest -v sorts/bubble_sort.py

πŸ“‚ Algorithm Categories

For a complete list of all implemented algorithms organized by category, see our DIRECTORY.md file.

🌐 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!

🀝 Contributing

We welcome contributions from the community! Before contributing:

  1. πŸ“‹ Read through our Contribution Guidelines
  2. πŸ” Check existing implementations to avoid duplicates
  3. βœ… Ensure your code follows our coding standards
  4. πŸ§ͺ Include doctests and proper documentation
  5. 🎯 Make sure all tests pass before submitting

Quick Start for Contributors:

# Install pre-commit hooks
pip install pre-commit
pre-commit install

# Run tests
python -m pytest

# Format code
pip install ruff
ruff check

Contributions that are most welcome:

  • New algorithm implementations
  • Improvements to existing algorithms
  • Better documentation and explanations
  • Bug fixes
  • Test coverage improvements

πŸ“„ License

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

This means you are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software.

πŸ“œ List of Algorithms

See our directory for easier navigation and a better overview of the project.

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%