Go to file
Sangmin Jeon a03b739d23
Fix radix_tree.py insertion fail in ["*X", "*XX"] cases (#8870)
* Fix insertion fail in ["*X", "*XX"] cases

Consider a word, and a copy of that word, but with the last letter repeating twice. (e.g., ["ABC", "ABCC"])
When adding the second word's last letter, it only compares the previous word's prefix—the last letter of the word already in the Radix Tree: 'C'—and the letter to be added—the last letter of the word we're currently adding: 'C'. So it wrongly passes the "Case 1" check, marks the current node as a leaf node when it already was, then returns when there's still one more letter to add.
The issue arises because `prefix` includes the letter of the node itself. (e.g., `nodes: {'C' : RadixNode()}, is_leaf: True, prefix: 'C'`) It can be easily fixed by simply adding the `is_leaf` check, asking if there are more letters to be added.

- Test Case: `"A AA AAA AAAA"`
  - Fixed correct output:
  ```
  Words: ['A', 'AA', 'AAA', 'AAAA']
  Tree:
  - A   (leaf)
  -- A   (leaf)
  --- A   (leaf)
  ---- A   (leaf)
  ```
  - Current incorrect output:
  ```
  Words: ['A', 'AA', 'AAA', 'AAAA']
  Tree:
  - A   (leaf)
  -- AA   (leaf)
  --- A   (leaf)
  ```

*N.B.* This passed test cases for [Croatian Open Competition in Informatics 2012/2013 Contest #3 Task 5 HERKABE](https://hsin.hr/coci/archive/2012_2013/)

* Add a doctest for previous fix

* improve doctest readability
2023-07-24 11:29:05 +02:00
.github Fix failing pytest quantum/bb84.py (#8838) 2023-06-26 08:54:50 +05:30
.vscode Create a Simultaneous Equation Solver Algorithm (#8773) 2023-06-02 07:14:25 +02:00
arithmetic_analysis Fix failing tests from ruff/newton_raphson (ignore S307 "possibly insecure function") (#8862) 2023-07-11 11:51:21 +02:00
audio_filters Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
backtracking Add power sum problem (#8832) 2023-06-26 09:39:18 +02:00
bit_manipulation Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
blockchain pre-commit: Upgrade psf/black for stable style 2023 (#8110) 2023-02-01 18:44:54 +05:30
boolean_algebra Update and_gate.py (#8690) 2023-05-10 21:38:52 +12:00
cellular_automata [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
ciphers Improve readability of ciphers/mixed_keyword_cypher.py (#8626) 2023-06-09 11:06:37 +02:00
compression pre-commit: Upgrade psf/black for stable style 2023 (#8110) 2023-02-01 18:44:54 +05:30
computer_vision Revert "Add LeNet Implementation in PyTorch (#7070)" (#8621) 2023-04-08 06:22:26 +05:30
conversions Energy conversions (#8801) 2023-06-22 14:31:48 +02:00
data_structures Fix radix_tree.py insertion fail in ["*X", "*XX"] cases (#8870) 2023-07-24 11:29:05 +02:00
digital_image_processing Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
divide_and_conquer [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
dynamic_programming Consolidate duplicate implementations of max subarray (#8849) 2023-07-11 11:44:12 +02:00
electronics Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
file_transfer Update receive_file.py (#8541) 2023-03-31 16:08:13 +02:00
financial Added apr_interest function to financial (#6025) 2023-06-19 13:46:29 +02:00
fractals pre-commit: Upgrade psf/black for stable style 2023 (#8110) 2023-02-01 18:44:54 +05:30
fuzzy_logic Misc fixes across multiple algorithms (#6912) 2022-10-16 10:55:38 +05:30
genetic_algorithm Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
geodesy pre-commit: Upgrade psf/black for stable style 2023 (#8110) 2023-02-01 18:44:54 +05:30
graphics Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
graphs [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
greedy_methods Added minimum waiting time problem solution using greedy algorithm (#8701) 2023-05-01 12:23:03 +02:00
hashes Revamp md5.py (#8065) 2023-04-01 22:05:01 +02:00
knapsack pre-commit: Upgrade psf/black for stable style 2023 (#8110) 2023-02-01 18:44:54 +05:30
linear_algebra Added rank of matrix in linear algebra (#8687) 2023-05-31 17:03:02 +02:00
linear_programming Simplex algorithm (#8825) 2023-06-18 18:00:02 +02:00
machine_learning Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
maths [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
matrix Create count negative numbers in matrix algorithm (#8813) 2023-06-10 14:21:49 +02:00
networking_flow clean of unnecessary checks, imports, calls (#7993) 2022-11-21 00:00:27 +13:00
neural_network Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
other Small docstring time complexity fix in number_container _system (#8875) 2023-07-22 12:34:19 +02:00
physics Speed of sound (#8803) 2023-06-07 23:47:27 +02:00
project_euler [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
quantum [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
scheduling Make some ruff fixes (#8154) 2023-03-01 17:23:33 +01:00
scripts Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
searches Correct ruff failures (#8732) 2023-05-14 22:03:13 +01:00
sorts Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
strings [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
web_programming [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
.gitattributes Create .gitattributes for Cross OS compatibility (#3410) 2020-10-17 07:25:25 +02:00
.gitignore chore: update .gitignore (#6263) 2022-07-23 07:56:59 +05:30
.gitpod.yml Change gitpod configuration for python3. (#1827) 2020-04-07 12:20:08 +02:00
.pre-commit-config.yaml [Upgrade Ruff] Fix all errors raised from ruff (#8879) 2023-07-22 12:05:10 +02:00
CONTRIBUTING.md Add note in CONTRIBUTING.md about not asking to be assigned to issues (#8871) 2023-07-22 12:11:04 +02:00
DIRECTORY.md Consolidate duplicate implementations of max subarray (#8849) 2023-07-11 11:44:12 +02:00
LICENSE.md LICENSE: Year change (#5920) 2022-03-16 23:40:48 +08:00
pyproject.toml Dijkstra algorithm with binary grid (#8802) 2023-06-22 13:49:09 +02:00
README.md Fix broken links to Gitter Community (Fixes: #8197) (#8546) 2023-03-26 18:20:47 +02:00
requirements.txt Revert "Add LeNet Implementation in PyTorch (#7070)" (#8621) 2023-04-08 06:22:26 +05:30

The Algorithms - Python

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.

Getting Started

Read through our Contribution Guidelines before you contribute.

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!

List of Algorithms

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