Sangmin Jeon 4f29d209c8
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/)
2023-07-16 20:11:13 +09:00
2023-05-26 09:34:17 +02:00
2023-06-22 14:31:48 +02:00
2023-05-26 09:34:17 +02:00
2023-05-26 09:34:17 +02:00
2023-04-01 22:05:01 +02:00
2023-06-07 23:47:27 +02:00
2023-03-01 17:23:33 +01:00
2023-05-26 09:34:17 +02:00
2023-05-14 22:03:13 +01:00
2023-05-26 09:34:17 +02:00
2023-05-26 09:34:17 +02:00
2022-07-23 07:56:59 +05:30
2022-03-16 23:40:48 +08:00

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.

Languages
Python 99.9%
Shell 0.1%