TheAlgorithms/Python 是 GitHub 上拥有超过 218,000 颗星标的顶级开源项目,由 The Algorithms 组织维护。该项目旨在用 Python 语言实现各种经典算法和数据结构,为全球开发者和学生提供一个高质量的算法学习资源。
所有实现均以教育目的为主,代码清晰易懂,并附有详细注释。虽然在性能上可能不如 Python 标准库中的实现,但它们是理解算法原理的绝佳参考。
| 项目信息 | 详情 |
|---|---|
| GitHub 星标 | 218,570+ |
| 编程语言 | Python |
| 算法类别 | 40+ 个大类 |
| 开源许可 | MIT License |
| 维护组织 | The Algorithms |
| 代码风格 | Ruff 格式化 |
该项目涵盖了计算机科学中几乎所有主要的算法类别,共计 40 余个分类:
算术分析、线性代数、矩阵运算、数学计算、布尔代数
各类搜索算法、排序算法(冒泡、快排、归并等)、字符串匹配(KMP)
链表、树、图、栈、队列、堆、哈希表等经典数据结构
回溯法、分治法、动态规划、贪心算法、位运算
机器学习、神经网络、遗传算法、模糊逻辑、计算机视觉
各类密码学算法、哈希算法、区块链基础实现
图遍历、最短路径、最小生成树、网络流等图算法
数字图像处理、压缩算法、分形、量子计算、调度算法、物理模拟、金融计算
要使用该项目中的算法,你可以按照以下步骤操作:
项目提供了详细的 算法目录(DIRECTORY.md),方便你快速查找所需算法。
你也可以通过 Gitpod 一键在线打开项目,无需本地安装任何环境。
阅读 贡献指南,了解如何为项目添加新的算法实现。
| 类别 | 说明 | 典型算法 |
|---|---|---|
| 排序算法 (Sorts) | 各种经典排序方法的实现 | 冒泡、快排、归并、堆排序、基数排序 |
| 搜索算法 (Searches) | 在数据集合中查找目标元素 | 二分查找、线性查找、跳跃搜索 |
| 动态规划 (Dynamic Programming) | 利用子问题的解来构建最终解 | 背包问题、最长公共子序列、编辑距离 |
| 图算法 (Graphs) | 处理图结构的各类算法 | Dijkstra、BFS、DFS、最小生成树 |
| 机器学习 (Machine Learning) | 基础ML算法的纯Python实现 | 线性回归、KNN、决策树、K-Means |
| 密码学 (Ciphers) | 经典加密和解密算法 | 凯撒密码、RSA、AES、维吉尼亚密码 |
| 数据结构 (Data Structures) | 常用数据结构的实现 | 二叉树、链表、堆、哈希表、Trie |
以下是该项目当前开放的 Issue(按评论数排序),共 39 条,标题已翻译为中文供参考。
| 编号 | 议题标题(中文翻译 / 英文原文) | 创建日期 | 评论 |
|---|---|---|---|
| #8818 |
修复 failing: `pytest quantum/q_fourier_transform.py`
Fix failing: `pytest quantum/q_fourier_transform.py` 缺陷 |
2023-06-13 | 20 |
| #12809 |
需要 help for my age controller
Need help for my age controller 增强 |
2025-06-26 | 16 |
| #12192 |
topological sort returns reversed 列表
topological sort returns reversed list 缺陷 |
2024-10-19 | 15 |
| #13008 |
Suggestion: 添加 basic crypto price converter
Suggestion: add basic crypto price converter awaiting triage |
2025-09-29 | 14 |
| #6216 |
Some algorithms are "how-to" 示例
Some algorithms are "how-to" examples 需要帮助 |
2022-06-23 | 13 |
| #13226 |
缺陷: Inconsistent behavior for 缺失 values in coordinate_compression.py
Bug: Inconsistent behavior for missing values in coordinate_compression.py 缺陷 |
2025-10-05 | 12 |
| #8847 |
`machine_learning/linear_regression.py` doesn't give optimal coefficients
`machine_learning/linear_regression.py` doesn't give optimal coefficients 增强 |
2023-06-30 | 12 |
| #13904 |
Favour Chidinma - Python project
Favour Chidinma - Python project awaiting triage |
2025-11-13 | 10 |
| #6252 |
Suggestion: adopt a 文档 format for docstring
Suggestion: adopt a documentation format for docstring |
2022-07-14 | 10 |
| #12714 |
Calc.py
Calc.py |
2025-05-08 | 9 |
| #13845 |
添加 input validation for division by zero in divide_numbers()
Add input validation for division by zero in divide_numbers() 增强 |
2025-11-03 | 8 |
| #12233 |
Avoid log(0) in KL divergence
Avoid log(0) in KL divergence 缺陷 |
2024-10-21 | 8 |
| #12127 |
添加 binary 搜索
Add binary search awaiting triage |
2024-10-17 | 8 |
| #10713 |
More detailed information on 测试 failures in Actions 页面
More detailed information on test failures in Actions page 增强 |
2023-10-19 | 8 |
| #8594 |
Optimize Project Euler solutions
Optimize Project Euler solutions 增强需要帮助optimization |
2023-04-01 | 8 |
| #13509 |
缺陷
Bugs 缺陷 |
2025-10-15 | 7 |
| #13304 |
Hangman game program in python
Hangman game program in python awaiting triage |
2025-10-07 | 7 |
| #12987 |
Snake water gun game program in python
Snake water gun game program in python |
2025-09-22 | 7 |
| #12968 |
SYNTAX 错误
SYNTAX ERROR 缺陷 |
2025-09-15 | 7 |
| #10837 |
Nested functions can't be tested by doctest
Nested functions can't be tested by doctest 增强 |
2023-10-23 | 7 |
| #10563 |
`pytest` 警告 in builds
`pytest` warnings in builds 缺陷 |
2023-10-15 | 7 |
| #13417 |
添加 some more programs
Adding some more programs 增强 |
2025-10-10 | 6 |
| #12622 |
添加 PID and ADRC algorithm
Add PID and ADRC algorithm 增强 |
2025-03-17 | 6 |
| #11517 |
想要 to 添加 sliding window algorithm
Want to add sliding window algorithm 增强 |
2024-08-14 | 6 |
| #13445 |
Issue Title: 添加 示例 Code Using Popular Python Libraries
Issue Title: Add Example Code Using Popular Python Libraries 增强 |
2025-10-12 | 5 |
| #13320 |
想要 to 添加 [ML] 实现 PCA, Logistic Regression (Vectorized), Naive Bayes with Laplace Smoothing, and Decision Tree Pruning from Scratch
Want to add [ML] Implement PCA, Logistic Regression (Vectorized), Naive Bayes with Laplace Smoothing, and Decision Tree Pruning from Scratch 增强 |
2025-10-07 | 5 |
| #12569 |
添加 a collision detection algorithm
Add a collision detection algorithm 增强 |
2025-02-09 | 5 |
| #12379 |
Find:audio_filters/butterworth_filter.py issure
Find:audio_filters/butterworth_filter.py issure 缺陷 |
2024-11-17 | 5 |
| #10703 |
Duplicate algorithms in `maths/primelib.py`
Duplicate algorithms in `maths/primelib.py` 增强 |
2023-10-19 | 5 |
| #8070 |
`mypy` produces 错误 when run on its own
`mypy` produces errors when run on its own 增强 |
2023-01-03 | 5 |
| #14050 |
Python Mini Project: Grocery Store Cart System
I built a simple console-based Grocery Store application using Python 🐍 to strengthen my understanding of core programming concepts.
🔧 Features:
添加 items to cart
移除 items from cart
Calculate total price dynamically
Menu-driven program using loops
📚 Concepts Used:
Dictionaries
Loops (while)
Conditional statements
User input handling
This project helped me practice logic building and real-world problem solving using Python.
💡 More improvements coming soon!
#Python #Programming #MiniProject #LearningByDoing #AIML #EngineeringStudent
Python Mini Project: Grocery Store Cart System I built a simple console-based Grocery Store application using Python 🐍 to strengthen my understanding of core programming concepts. 🔧 Features: Add items to cart Remove items from cart Calculate total price dynamically Menu-driven program using loops 📚 Concepts Used: Dictionaries Loops (while) Conditional statements User input handling This project helped me practice logic building and real-world problem solving using Python. 💡 More improvements coming soon! #Python #Programming #MiniProject #LearningByDoing #AIML #EngineeringStudent |
2025-12-28 | 4 |
| #13840 |
不正确 output for Binary 搜索 when 列表 contains duplicates
Incorrect output for Binary Search when list contains duplicates 缺陷 |
2025-11-02 | 4 |
| #13714 |
添加 “Usage 示例” section to README
Add “Usage Example” section to README 增强 |
2025-10-23 | 4 |
| #13372 |
添加 Vision Transformer (ViT) Demo to computer_vision Module
Add Vision Transformer (ViT) Demo to computer_vision Module 增强 |
2025-10-09 | 4 |
| #13315 |
添加 Pattern printing programmes
Add Pattern printing programmes awaiting triage |
2025-10-07 | 4 |
| #13205 |
Upgrade Linear Regression with Fully Vectorized 实现 and 添加 a naive 实现 for beginners
Upgrade Linear Regression with Fully Vectorized Implementation and add a naive implementation for beginners 增强 |
2025-10-05 | 4 |
| #12949 |
data type syntax 错误
data type syntax error 缺陷 |
2025-09-03 | 4 |
| #12513 |
错误 regarding imports in replit
Error regarding imports in replit awaiting triage |
2025-01-08 | 4 |
| #12321 |
添加 ART1 algorithm in neural network
Add ART1 algorithm in neural network 增强 |
2024-10-29 | 4 |