Incorrect Cycle Path Construction in detectUndirectedCycle
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript
- Ambito
- backend
Direzione di ricerca
Start at the detectUndirectedCycle function and inspect how cycle is constructed and how allowTraversal controls DFS. Verify the returned cycle is an ordered vertex array whose first and last vertices match, and assess whether traversal can stop immediately after detection. Run the relevant cycle-detection tests and confirm existing behavior remains covered.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
In the function detectUndirectedCycle, the cycle path is being constructed as an object with vertex keys as properties and their parent vertices as values. This makes the returned cycle not a standard path array, but rather a mapping, which may not be intuitive or useful for consumers expecting an ordered path of vertices forming the cycle. A more conventional approach would be to return an ordered array of vertices representing the cycle, starting and ending at the same vertex.
Additionally, if a cycle is detected, the function continues to traverse the graph until DFS completes, although traversal is blocked by allowTraversal once a cycle is set. However, early exit after detecting a cycle could improve efficiency.
Suggested Fix:
- Change
cycleto be an array that accumulates the ordered path of the cycle. - Optionally, add a mechanism to exit the traversal immediately after the cycle is found.
- Lingua principale
- JavaScript
- Stelle
- 197k
- Fork
- 31k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri 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 trekhleb/javascript-algorithms
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
trekhleb/javascript-algorithms#2102 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
trekhleb/javascript-algorithms#2085 · 6 commenti · 1 reazione ·
-
LinkedList methods. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
trekhleb/javascript-algorithms#2065 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
trekhleb/javascript-algorithms#2056 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
trekhleb/javascript-algorithms#2048 · 2 commenti · 2 reazioni ·
Tutte le issue di trekhleb/javascript-algorithms
Issue simili
-
code-quality refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100