Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 115 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,115 @@
<div align="center">
<!-- Title: -->
<a href="https://github.com/TheAlgorithms/">
<img src="https://raw.githubusercontent.com/TheAlgorithms/website/1cd824df116b27029f17c2d1b42d81731f28a920/public/logo.svg" height="100">
</a>
<h1><a href="https://github.com/TheAlgorithms/">The Algorithms</a> - Python</h1>

<!-- Labels: -->
<!-- First row: -->
<a href="https://gitpod.io/#https://github.com/TheAlgorithms/Python">
<img src="https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square" height="20" alt="Gitpod Ready-to-Code">
</a>
<a href="https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md">
<img src="https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square" height="20" alt="Contributions Welcome">
</a>
<img src="https://img.shields.io/github/repo-size/TheAlgorithms/Python.svg?label=Repo%20size&style=flat-square" height="20">
<a href="https://the-algorithms.com/discord">
<img src="https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=7289DA&style=flat-square" height="20" alt="Discord chat">
</a>
<a href="https://gitter.im/TheAlgorithms/community">
<img src="https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square" height="20" alt="Gitter chat">
</a>

<!-- Second row: -->
<br>
<a href="https://github.com/TheAlgorithms/Python/actions">
<img src="https://img.shields.io/github/actions/workflow/status/TheAlgorithms/Python/build.yml?branch=master&label=CI&logo=github&style=flat-square" height="20" alt="GitHub Workflow Status">
</a>
<a href="https://github.com/pre-commit/pre-commit">
<img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" height="20" alt="pre-commit">
</a>
<a href="https://docs.astral.sh/ruff/formatter/">
<img src="https://img.shields.io/static/v1?label=code%20style&message=ruff&color=black&style=flat-square" height="20" alt="code style: black">
</a>

<!-- Short description: -->
<h3>All algorithms implemented in Python - for education 📚</h3>
</div>

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

## 🚀 Getting Started

📋 Read through our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.

## 🌐 Community Channels

We are on [Discord](https://the-algorithms.com/discord) and [Gitter](https://gitter.im/TheAlgorithms/community)! Community channels are a great way for you to ask questions and get help. Please join us!

## 📜 List of Algorithms

See our [directory](DIRECTORY.md) for easier navigation and a better overview of the project.
# 🐍 The Algorithms - Python

> **The definitive, open-source collection of all algorithms implemented in Python.**
>
> A collaborative educational project dedicated to providing clear, executable, and well-documented examples for fundamental and advanced computer science algorithms.

---

## 📈 Stats & Status

| Metric | Status |
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Stars** | [![GitHub Stars](https://img.shields.io/github/stars/TheAlgorithms/Python?style=flat-square&color=FFC72C&label=)](https://github.com/TheAlgorithms/Python/stargazers) |
| **Forks** | [![GitHub Forks](https://img.shields.io/github/forks/TheAlgorithms/Python?style=flat-square&color=41B8D4&label=)](https://github.com/TheAlgorithms/Python/network/members) |
| **Contributors** | **1,250+** Active Community Members |
| **License** | [![License: MIT](https://img.shields.io/badge/License-MIT-41B8D4.svg?style=flat-square)](https://github.com/TheAlgorithms/Python/blob/master/LICENSE.md) |
| **Code Style** | [![Pre-Commit Code Style](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black) |
| **Ready-to-Code** | [![Open in Gitpod](https://img.shields.io/badge/Gitpod-Ready--to--Code-576A96?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/TheAlgorithms/Python) |

---

## 🎯 Project Goals

This repository is an invaluable resource for:

- **Students:** To see working examples of algorithms learned in class.
- **Developers:** To quickly reference or refresh knowledge on a specific implementation.
- **Interview Preparation:** To practice and understand the underlying logic of common interview problems.

**Our Core Philosophy:** **Clarity over Performance.** _Implementations prioritize readability and educational value. They are not optimized for production-grade speed._

---

## 📂 Repository Structure & Key Domains

The project is meticulously organized into folders, each representing a core domain in computer science.

| Domain | Example Topics |
| :---------------------- | :--------------------------------------------------------------- |
| **Data Structures** | Linked Lists, Trees, Heaps, Hash Maps |
| **Searching & Sorting** | Binary Search, Bubble Sort, Merge Sort, Quickselect |
| **Mathematics** | Number Theory, Prime Sieve, Matrix Operations, Geometry |
| **Advanced CS** | Dynamic Programming, Greedy Methods, Divide and Conquer |
| **Graph Theory** | BFS, DFS, Dijkstra's, Kruskal's, Network Flow |
| **Security & Privacy** | Ciphers (Caesar, Vigenere), Hashes (SHA, MD5) |
| **Modern Tech** | Machine Learning, Computer Vision, Blockchain, Quantum Computing |

➡️ **Explore All Algorithms:** View the full, categorized list in our **[DIRECTORY.md](https://github.com/TheAlgorithms/Python/blob/master/DIRECTORY.md)**.

---

## 🛠️ Getting Started: Your First Run

### Prerequisites

- Python **3.8+**
- (Optional but Recommended) A Python virtual environment.

### Installation

Clone the repository and install necessary dependencies:

```bash
# 1. Clone the repository
git clone [https://github.com/TheAlgorithms/Python.git](https://github.com/TheAlgorithms/Python.git)
cd Python

# 2. Install dependencies (We recommend 'uv' for speed)
# pip install uv
# uv sync

# OR using pip
pip install -r requirements.txt
Running an Example
Algorithms are designed to be run directly for testing. Many include doctests for built-in verification.

Bash

# Example: Running the Fibonacci sequence algorithm
python maths/fibonacci_sequence.py

# Example: Running a Graph algorithm
python graphs/depth_first_search.py
```

# 🚀 Contribute and Grow

This is a 100% community-driven project. Your contributions are the lifeblood of this repository!

How to Get Involved
Read the Guidelines: Start with the comprehensive CONTRIBUTING.md for a step-by-step guide.

Find an Issue: Look for open issues labeled good first issue if you're new, or tackle a high-priority bug or missing algorithm.

Submit a Pull Request (PR): Ensure your code is clean, well-commented, and adheres to the Black code style standard.

Your contribution helps millions learn computer science!

# 💬 Community & Support

Need help, have a suggestion, or just want to discuss an algorithm? Join our vibrant community!

Platform Link Purpose
Discord Join our Server Real-time chat, quick help, and contribution coordination.
Gitter Join our Chat General discussion and support channel.

Export to Sheets
⚠️ Important Disclaimer
The code in this repository is designed for education and demonstration. While functionally correct, it is often written to be maximally clear rather than maximally fast.

Do not use this code in a high-performance or production environment. For optimal performance in a production setting, rely on the optimized functions within Python's Standard Library or well-established third-party libraries.

# © License

This project is open source and available under the MIT License.