Optimize Node.has_loop to use constant auxiliary space instead of O(N) space
Los mantenedores suelen responder en 1 día
@mohitjoshi-hey ya está trabajando en esto.
Desde el 14/10/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 15/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 225k
- Forks
- 51.2k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 40
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de 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 crashPosiblemente ocupada @Nate-br la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
TheAlgorithms/Python#15636 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Posiblemente ocupada @mohammedanasnakhuda la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
TheAlgorithms/Python#15634 ·
Los mantenedores suelen responder en 1 día
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed itPosiblemente ocupada @raaj-2222 la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
TheAlgorithms/Python#15633 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the filePosiblemente ocupada @SakshiYeole la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
TheAlgorithms/Python#15637 ·
Los mantenedores suelen responder en 1 día
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)Posiblemente ocupada @SwetaKumari7 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
TheAlgorithms/Python#15635 ·
Los mantenedores suelen responder en 1 día
Todos los issues de TheAlgorithms/Python
Issues similares
-
follow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
-
query rewriting: prompt says "Language for `query` field: None" when language detection failsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
modelscope/modelscope#1833 ·
Los mantenedores suelen responder en 1 día
-
ocr_data_to_elements() raises AttributeError when a layout element is a ListPosiblemente ocupada @Eapp1e la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Unstructured-IO/unstructured#4616 ·
Los mantenedores suelen responder en 1 día