Questions tagged [cycle-detection]
42 questions
2
votes
2 answers
Adjacency Linked List Cycle Detection - Java
I have some problem checking if my adjacency list has a cycle or not.
I want to make a function that checks if my adjacency list has existing at least one cycle.
Based on my program. First, I have to input the Root Node, followed by a number of…

aldrich19
- 39
- 1
- 5
1
vote
1 answer
Cycle Detection in Undirected Graph
I have this undirected and weighted graph in the above link and I just cannot detect how many cycles are there. I have tried BFS, DFS and Set disjoint method but all of them just goes wrong somewhere while calculating. I can do the code. The…

Mashrur Kabir Riyan
- 19
- 2
1
vote
1 answer
Counting the number of cycles in an Undirected Graph
Question
Write a JAVA program to count the number of cycles in an Undirected graph.
My approach:
I tried solving this using Depth First Search.
I found a program online that counts the cycles of length n in an undirected and connected graph.
The…

KSP
- 94
- 1
- 11
1
vote
1 answer
Finding the cycle in a directed graph
I was solving a problem to determine whether a graph contains a cycle. I solved it using the coloring method (in the visited array I will mark, 0 if it has never visited, 1 if it is visited, and 2 if the tour of vertex is done)
for this I wrote the…

anand singh
- 103
- 7
1
vote
0 answers
How to print all cycles in a linked list with extra pointers?
Given a data structure that resembles a linked list with a pointer pointing to next node and another pointer pointing to any random node, I have to print all the unique cycles that the structure has. Here is an example of this data…

shivam agarwal
- 27
- 3
1
vote
0 answers
How to detect a cycle in a directed graph using the union-find algorithm
Can I apply the union-find algorithm for the detecting a cycle in a directed graph other than Depth First Search (DFS)?
I know that we can apply the union-find algorithm for the detecting cycle in a undirected graph.

Vinay Kumar
- 386
- 2
- 8
1
vote
0 answers
Cycle detection by array reference
I have been searching for tree cycle detection and came by this PHP code:
/**
* Takes an adjacency list: an array of parent/child relationships
* array(array(1,2));
*/
function check_for_cycles($relationships) {
$roots = array();
foreach…

Ralf
- 41
- 5
1
vote
1 answer
How to deal with parallel edges between two vertices in cycle detection using BFS in an undirected graph?
I am new to Programming and learning Algorithms and was studying BFS when I read that BFS could be used for cycle detection. I tried to implement the same on an undirected graph G with Adjacency List Representation.
What I did is as follows:
• Do a…

ATK
- 358
- 3
- 17
1
vote
0 answers
Brent-Pollard factorization: What are the correct tortoise & hare indices in Brent's cycle finding algorithm?
Some time ago, I ported this Python implementation of the Pollard-Brent algorithm to Clojure. It works, and works fast, too; that's not the problem. And when given identical non-random seed values and stepping functions, it reproduces the hare and…

tabidots
- 11
- 3
1
vote
1 answer
Cycle Detection in a Graph using NetworkX Python
My CSV file has ~2.6 million records of transaction among different people. I am trying to make a graph from this file as: person having unique IDs as nodes and edges representing transaction between two people and want to fetch all possible cycles…

Shubham Singh
- 91
- 2
- 12
1
vote
2 answers
Algorithm to order tasks with dependencies
In a private open source project I encounter the following problem:
There are a variety of tasks to perform. Some of these tasks will have annotations that
they must be performed after one or more specific other tasks
they must be performed before…

Regis May
- 3,070
- 2
- 30
- 51
1
vote
2 answers
Why does Floyd's cycle finding algorithm fail for certain pointer increment speeds?
Consider the following linked list:
1->2->3->4->5->6->7->8->9->4->...->9->4.....
The above list has a loop as follows:
[4->5->6->7->8->9->4]
Drawing the linked list on a whiteboard, I tried manually solving it for different pointer steps, to see…

Divij Sehgal
- 647
- 2
- 11
- 26
1
vote
1 answer
How to experimentally simulate and compare various graph cycle detection algorithms?
I studied about various algorithms for cycle detection algorithm in directed graphs like incremental way search, strongly connected components, BFS, two way search, etc. Now I want to simulate it and compare the performance. I am calling cycle…
user4090410
0
votes
1 answer
Finding cycles in an undirected graph in [node, node] format returns wrong result
I'm trying to find cycles in an undirected, unweighted graph. In [node, node] format. Here is the code I wrote:
def find_cycles(graph):
cycles = []
def dfs(node, visited, path):
visited.add(node)
path.append(node)
…

Mani
- 3
- 2
0
votes
1 answer
Finding cyclic product relations with TypeORM/SQL/NestJS
Currently I have a Product class like so:
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: number;
@ManyToMany(() => Product, (product) => product.id, {
onDelete: 'RESTRICT',
onUpdate: 'CASCADE',
})
@JoinTable({…

CXY
- 33
- 8