Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dc1b200
[pre-commit.ci] pre-commit autoupdate (#12930)
pre-commit-ci[bot] Aug 26, 2025
55db5a1
Add new solution for the euler project problem 9 (#12771)
mindaugl Aug 26, 2025
44cf167
Create cyclic_sort.py (#9256)
sharansukesh1003 Aug 26, 2025
4961b3a
Enhancement of the knapsack algorithm with memorization and generalis…
Jiang15 Aug 26, 2025
b486ac6
added coordinate_compression (#9317)
om-ashish-soni Aug 27, 2025
2fa65c7
Improve blockchain/README.md (#9630)
SYK-08 Aug 27, 2025
0c39e43
Algorithm to find unique prime factors (#9935)
Mary-0165 Aug 27, 2025
e6b5d26
Combination sum fix and test cases (#10193)
architmaheshwari99 Aug 27, 2025
84f101c
Add/generate parentheses iterative approach (#10024)
Pr0-C0der Aug 27, 2025
54aa73f
Fixes bugs in graphs/dijkstra_algorithm.py (#10092)
Kpraful Aug 27, 2025
4394fd9
Weierstrass Method (#12877)
aditya7balotra Aug 29, 2025
5c50572
Fixing stock_span_problem.py (#10540)
AasheeshLikePanner Aug 29, 2025
488f143
Performance: 25% faster Project Euler 73 #10503 (#11553)
RamanaMenda Aug 30, 2025
c5de395
Add new test for bucket sort algorithm in sorts/bucket_sort.py (#11605)
byteninjaa0 Aug 30, 2025
1e0d317
Specify space complexity for merge sort (#11749)
IAteNoodles Aug 30, 2025
b092045
Add unit tests to binary_tree_path_sum.py (#11833)
ronaldngounou Aug 30, 2025
501576f
Update README.md (#12345)
aniruddhaadak80 Aug 30, 2025
e3a263c
Adding a 3D plot to the k-means clustering algorithm (#12372)
lorenzo30salgado Aug 30, 2025
9d52683
Create stalin_sort.py (#11989)
anant-jain01 Aug 30, 2025
0876a87
[pre-commit.ci] pre-commit autoupdate (#12944)
pre-commit-ci[bot] Sep 1, 2025
544f48f
Fix is_palindrome_recursive logic in strings/palindrome.py (#12946)
PYDIMARRI-HEMA-HARSHINI-23-586 Sep 4, 2025
4ce1185
Bump actions/setup-python from 5 to 6 (#12952)
dependabot[bot] Sep 5, 2025
8f1a6b0
Adding the function is_proth_number (#12399)
Juanitoupipou Sep 7, 2025
18c853d
[pre-commit.ci] pre-commit autoupdate (#12961)
pre-commit-ci[bot] Sep 8, 2025
63180d7
pre-commit autoupdate 2025-09-11 (#12963)
cclauss Sep 12, 2025
0ee534e
[pre-commit.ci] pre-commit autoupdate (#12969)
pre-commit-ci[bot] Sep 15, 2025
4ec71a3
fix covid_stats_via_xpath.py (#12975)
lighting9999 Sep 18, 2025
e696e4d
[pre-commit.ci] pre-commit autoupdate (#12988)
pre-commit-ci[bot] Sep 23, 2025
8d1fb26
Added edit_distance test cases (#12984)
kathrynpete Sep 23, 2025
c0ad5bb
Add doctests for cross function. Contributes to #9943 (#12991)
Dylanskyep Sep 24, 2025
a71618f
[pre-commit.ci] pre-commit autoupdate (#13006)
pre-commit-ci[bot] Sep 29, 2025
ebe0046
Added search in a rotated sorted array in searches
Tarannum9623 Oct 5, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: 3.x
allow-prereleases: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/directory_writer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: 3.x
- name: Write DIRECTORY.md
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/project_euler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: 3.x
- run: uv sync --group=euler-validate --group=test
Expand All @@ -26,7 +26,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: 3.x
- run: uv sync --group=euler-validate --group=test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: 3.13
allow-prereleases: true
Expand Down
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand All @@ -16,7 +19,7 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.9
rev: v0.13.2
hooks:
- id: ruff-check
- id: ruff-format
Expand Down Expand Up @@ -47,7 +50,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
rev: v1.18.2
hooks:
- id: mypy
args:
Expand Down
6 changes: 6 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [Combination Sum](backtracking/combination_sum.py)
* [Crossword Puzzle Solver](backtracking/crossword_puzzle_solver.py)
* [Generate Parentheses](backtracking/generate_parentheses.py)
* [Generate Parentheses Iterative](backtracking/generate_parentheses_iterative.py)
* [Hamiltonian Cycle](backtracking/hamiltonian_cycle.py)
* [Knight Tour](backtracking/knight_tour.py)
* [Match Word Pattern](backtracking/match_word_pattern.py)
Expand Down Expand Up @@ -174,6 +175,7 @@

## Data Compression
* [Burrows Wheeler](data_compression/burrows_wheeler.py)
* [Coordinate Compression](data_compression/coordinate_compression.py)
* [Huffman](data_compression/huffman.py)
* [Lempel Ziv](data_compression/lempel_ziv.py)
* [Lempel Ziv Decompress](data_compression/lempel_ziv_decompress.py)
Expand Down Expand Up @@ -723,6 +725,7 @@
* [Secant Method](maths/numerical_analysis/secant_method.py)
* [Simpson Rule](maths/numerical_analysis/simpson_rule.py)
* [Square Root](maths/numerical_analysis/square_root.py)
* [Weierstrass Method](maths/numerical_analysis/weierstrass_method.py)
* [Odd Sieve](maths/odd_sieve.py)
* [Perfect Cube](maths/perfect_cube.py)
* [Perfect Number](maths/perfect_number.py)
Expand Down Expand Up @@ -956,6 +959,7 @@
* [Sol1](project_euler/problem_009/sol1.py)
* [Sol2](project_euler/problem_009/sol2.py)
* [Sol3](project_euler/problem_009/sol3.py)
* [Sol4](project_euler/problem_009/sol4.py)
* Problem 010
* [Sol1](project_euler/problem_010/sol1.py)
* [Sol2](project_euler/problem_010/sol2.py)
Expand Down Expand Up @@ -1266,6 +1270,7 @@
* [Comb Sort](sorts/comb_sort.py)
* [Counting Sort](sorts/counting_sort.py)
* [Cycle Sort](sorts/cycle_sort.py)
* [Cyclic Sort](sorts/cyclic_sort.py)
* [Double Sort](sorts/double_sort.py)
* [Dutch National Flag Sort](sorts/dutch_national_flag_sort.py)
* [Exchange Sort](sorts/exchange_sort.py)
Expand Down Expand Up @@ -1296,6 +1301,7 @@
* [Shell Sort](sorts/shell_sort.py)
* [Shrink Shell Sort](sorts/shrink_shell_sort.py)
* [Slowsort](sorts/slowsort.py)
* [Stalin Sort](sorts/stalin_sort.py)
* [Stooge Sort](sorts/stooge_sort.py)
* [Strand Sort](sorts/strand_sort.py)
* [Tim Sort](sorts/tim_sort.py)
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<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">
Expand All @@ -19,6 +20,7 @@
<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">
Expand All @@ -30,20 +32,21 @@
<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>
<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
## 🚀 Getting Started

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

## Community Channels
## 🌐 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
## 📜 List of Algorithms

See our [directory](DIRECTORY.md) for easier navigation and a better overview of the project.
12 changes: 11 additions & 1 deletion backtracking/combination_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,18 @@ def combination_sum(candidates: list, target: int) -> list:
>>> combination_sum([-8, 2.3, 0], 1)
Traceback (most recent call last):
...
RecursionError: maximum recursion depth exceeded
ValueError: All elements in candidates must be non-negative
>>> combination_sum([], 1)
Traceback (most recent call last):
...
ValueError: Candidates list should not be empty
"""
if not candidates:
raise ValueError("Candidates list should not be empty")

if any(x < 0 for x in candidates):
raise ValueError("All elements in candidates must be non-negative")

path = [] # type: list[int]
answer = [] # type: list[int]
backtrack(candidates, path, answer, target, 0)
Expand Down
62 changes: 62 additions & 0 deletions backtracking/generate_parentheses_iterative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
def generate_parentheses_iterative(length: int) -> list:
"""
Generate all valid combinations of parentheses (Iterative Approach).

The algorithm works as follows:
1. Initialize an empty list to store the combinations.
2. Initialize a stack to keep track of partial combinations.
3. Start with empty string and push it onstack along with the counts of '(' and ')'.
4. While the stack is not empty:
a. Pop a partial combination and its open and close counts from the stack.
b. If the combination length is equal to 2*length, add it to the result.
c. If open count < length, push new combination with added '(' on stack.
d. If close count < open count, push new combination with added ')' on stack.
5. Return the result containing all valid combinations.

Args:
length: The desired length of the parentheses combinations

Returns:
A list of strings representing valid combinations of parentheses

Time Complexity:
O(2^(2*length))

Space Complexity:
O(2^(2*length))

>>> generate_parentheses_iterative(3)
['()()()', '()(())', '(())()', '(()())', '((()))']
>>> generate_parentheses_iterative(2)
['()()', '(())']
>>> generate_parentheses_iterative(1)
['()']
>>> generate_parentheses_iterative(0)
['']
"""
result = []
stack = []

# Each element in stack is a tuple (current_combination, open_count, close_count)
stack.append(("", 0, 0))

while stack:
current_combination, open_count, close_count = stack.pop()

if len(current_combination) == 2 * length:
result.append(current_combination)

if open_count < length:
stack.append((current_combination + "(", open_count + 1, close_count))

if close_count < open_count:
stack.append((current_combination + ")", open_count, close_count + 1))

return result


if __name__ == "__main__":
import doctest

doctest.testmod()
print(generate_parentheses_iterative(3))
24 changes: 12 additions & 12 deletions blockchain/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# Blockchain

A Blockchain is a type of **distributed ledger** technology (DLT) that consists of growing list of records, called **blocks**, that are securely linked together using **cryptography**.
A Blockchain is a type of **distributed ledger** technology (DLT) that consists of a growing list of records, called **blocks**, that are securely linked together using **cryptography**.

Let's breakdown the terminologies in the above definition. We find below terminologies,
Let's break down the terminologies in the above definition. We find below terminologies,

- Digital Ledger Technology (DLT)
- Blocks
- Cryptography

## Digital Ledger Technology

It is otherwise called as distributed ledger technology. It is simply the opposite of centralized database. Firstly, what is a **ledger**? A ledger is a book or collection of accounts that records account transactions.
Blockchain is also called distributed ledger technology. It is simply the opposite of a centralized database. Firstly, what is a **ledger**? A ledger is a book or collection of accounts that records account transactions.

*Why is Blockchain addressed as digital ledger if it can record more than account transactions? What other transaction details and information can it hold?*
*Why is Blockchain addressed as a digital ledger if it can record more than account transactions? What other transaction details and information can it hold?*

Digital Ledger Technology is just a ledger which is shared among multiple nodes. This way there exist no need for central authority to hold the info. Okay, how is it differentiated from central database and what are their benefits?
Digital Ledger Technology is just a ledger that is shared among multiple nodes. This way there exists no need for a central authority to hold the info. Okay, how is it differentiated from a central database and what are their benefits?

There is an organization which has 4 branches whose data are stored in a centralized database. So even if one branch needs any data from ledger they need an approval from database in charge. And if one hacks the central database he gets to tamper and control all the data.
Suppose that there is an organization that has 4 branches whose data are stored in a centralized database. So even if one branch needs any data from the ledger it needs approval from the database in charge. And if one hacks the central database he gets to tamper and control all the data.

Now lets assume every branch has a copy of the ledger and then once anything is added to the ledger by anyone branch it is gonna automatically reflect in all other ledgers available in other branch. This is done using Peer-to-peer network.
Now let's assume every branch has a copy of the ledger and then once anything is added to the ledger by any branch it is gonna automatically reflect in all other ledgers available in other branches. This is done using a peer-to-peer network.

So this means even if information is tampered in one branch we can find out. If one branch is hacked we can be alerted ,so we can safeguard other branches. Now, assume these branches as computers or nodes and the ledger is a transaction record or digital receipt. If one ledger is hacked in a node we can detect since there will be a mismatch in comparison with other node information. So this is the concept of Digital Ledger Technology.
This means that even if information is tampered with in one branch we can find out. If one branch is hacked we can be alerted, so we can safeguard other branches. Now, assume these branches as computers or nodes and the ledger is a transaction record or digital receipt. If one ledger is hacked in a node we can detect since there will be a mismatch in comparison with other node information. So this is the concept of Digital Ledger Technology.

*Is it required for all nodes to have access to all information in other nodes? Wouldn't this require enormous storage space in each node?*

## Blocks

In short a block is nothing but collections of records with a labelled header. These are connected cryptographically. Once a new block is added to a chain, the previous block is connected, more precisely said as locked and hence, will remain unaltered. We can understand this concept once we get a clear understanding of working mechanism of blockchain.
In short, a block is nothing but a collection of records with a labelled header. These are connected cryptographically. Once a new block is added to a chain, the previous block is connected, more precisely said as locked, and hence will remain unaltered. We can understand this concept once we get a clear understanding of the working mechanism of blockchain.

## Cryptography

It is the practice and study of secure communication techniques in the midst of adversarial behavior. More broadly, cryptography is the creation and analysis of protocols that prevent third parties or the general public from accessing private messages.
Cryptography is the practice and study of secure communication techniques amid adversarial behavior. More broadly, cryptography is the creation and analysis of protocols that prevent third parties or the general public from accessing private messages.

*Which cryptography technology is most widely used in blockchain and why?*

So, in general, blockchain technology is a distributed record holder which records the information about ownership of an asset. To define precisely,
So, in general, blockchain technology is a distributed record holder that records the information about ownership of an asset. To define precisely,
> Blockchain is a distributed, immutable ledger that makes it easier to record transactions and track assets in a corporate network.
An asset could be tangible (such as a house, car, cash, or land) or intangible (such as a business) (intellectual property, patents, copyrights, branding). A blockchain network can track and sell almost anything of value, lowering risk and costs for everyone involved.

So this is all about introduction to blockchain technology. To learn more about the topic refer below links....
So this is all about the introduction to blockchain technology. To learn more about the topic refer below links....
* <https://en.wikipedia.org/wiki/Blockchain>
* <https://en.wikipedia.org/wiki/Chinese_remainder_theorem>
* <https://en.wikipedia.org/wiki/Diophantine_equation>
Expand Down
Loading
Loading