Optimize Node.has_loop to use constant auxiliary space instead of O(N) space
I maintainer di solito rispondono entro 1 giorno
@mohitjoshi-hey ci sta già lavorando.
Dal 14/10/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 15/100
Direzione di ricerca
The has_loop property in data_structures/linked_list/has_loop.py currently builds a set of visited nodes via the iterator. Linked PR #15577 is already open against this issue, so check that PR before starting, since the work is under way. The change would replace the set with Floyd's tortoise-and-hare pointers, and done means the listed cases pass: acyclic, self-loop, back-edge, tail loop, and duplicate data values.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature description
Optimize has_loop to use constant auxiliary space
Description
The has_loop property in data_structures/linked_list/has_loop.py currently detects loops by traversing the linked list and storing every visited node in a set:
@property
def has_loop(self) -> bool:
try:
list(self)
return False
except ContainsLoopError:
return True
The iterator uses:
visited = set()
and adds each visited node to that set. As a result, detecting whether a linked list contains a loop requires O(n) additional memory.
Proposed change
Update only the has_loop property in:
data_structures/linked_list/has_loop.py
Use Floyd’s tortoise-and-hare cycle-detection algorithm:
- A slow pointer moves one node at a time.
- A fast pointer moves two nodes at a time.
- If the pointers meet, the linked list contains a loop.
- If the fast pointer reaches the end of the list, no loop exists.
Expected complexity
Time complexity: O(n)
Auxiliary space: O(1)
Required behavior
The updated has_loop property should correctly detect:
- an acyclic linked list;
- a self-loop;
- a loop back to an earlier node;
- a loop involving the final node;
- lists containing duplicate data values in different nodes.
Loop detection must compare node references rather than node data values.
Reference
- Lingua principale
- Python
- Stelle
- 225k
- Fork
- 51.2k
- Merge medio
- 1g 8h
- PR unite (30g)
- 40
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TheAlgorithms/Python
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crashForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
TheAlgorithms/Python#15636 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Forse già presa @mohammedanasnakhuda l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
TheAlgorithms/Python#15634 ·
I maintainer di solito rispondono entro 1 giorno
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed itForse già presa @raaj-2222 l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
TheAlgorithms/Python#15633 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileForse già presa @SakshiYeole l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
TheAlgorithms/Python#15637 ·
I maintainer di solito rispondono entro 1 giorno
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)Forse già presa @SwetaKumari7 l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
TheAlgorithms/Python#15635 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TheAlgorithms/Python
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
btclib-org/btclib-node#2083 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Gathin23/cleanyourtv#2089 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
jxxghp/MoviePilot#7212 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
cli dx rust
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
NekomyaDev/nudge#278 ·
I maintainer di solito rispondono entro 1 giorno