Questions tagged [cycle]

A cycle is a process or series of items, which repeats several times.

Cycle is processes or events, which repeat several times. Number of repetitions can be known before starting the cycle or cycle can be repeated until some condition is true.

1551 questions
1590
votes
18 answers

Cycles in family tree software

I am the developer of some family tree software (written in C++ and Qt). I had no problems until one of my customers mailed me a bug report. The problem is that the customer has two children with their own daughter, and, as a result, he can't use my…
Partick Höse
  • 11,121
  • 3
  • 15
  • 9
201
votes
23 answers

How does finding a cycle start node in a cycle linked list work?

I understand that Tortoise and Hare's meeting concludes the existence of a loop, but how does moving tortoise to the beginning of linked list while keeping the hare at the meeting place, followed by moving both one step at a time make them meet at…
Passionate programmer
  • 5,748
  • 10
  • 39
  • 43
82
votes
11 answers

Finding all cycles in undirected graphs

I need a working algorithm for finding all simple cycles in an undirected graph. I know the cost can be exponential and the problem is NP-complete, but I am going to use it in a small graph (up to 20-30 vertices) and the cycles are small in…
Violin Yanev
  • 1,507
  • 2
  • 16
  • 23
81
votes
10 answers

Why increase pointer by two while finding loop in linked list, why not 3,4,5?

I had a look at question already which talk about algorithm to find loop in a linked list. I have read Floyd's cycle-finding algorithm solution, mentioned at lot of places that we have to take two pointers. One pointer( slower/tortoise ) is…
GG.
  • 2,835
  • 5
  • 27
  • 34
59
votes
8 answers

How to break outer cycle in Ruby?

In Perl, there is an ability to break an outer cycle like this: AAA: for my $stuff (@otherstuff) { for my $foo (@bar) { last AAA if (somethingbad()); } } (syntax may be wrong), which uses a loop label to break…
Fluffy
  • 27,504
  • 41
  • 151
  • 234
54
votes
5 answers

Detecting cycles in a graph using DFS: 2 different approaches and what's the difference

Note that a graph is represented as an adjacency list. I've heard of 2 approaches to find a cycle in a graph: Keep an array of boolean values to keep track of whether you visited a node before. If you run out of new nodes to go to (without hitting…
Ivan Voroshilin
  • 5,233
  • 3
  • 32
  • 61
52
votes
2 answers

Jackson - serialization of entities with birectional relationships (avoiding cycles)

I have two entities: Parent { Child[] children; } and Child { Parent parent; } I'm aware about @JsonBackReference and @JsonManagedReference. They are good, if I'm serializing instances of Parent. But I also need to transfer instances of…
Eugene Retunsky
  • 13,009
  • 4
  • 52
  • 55
48
votes
2 answers

itertools.cycle().next()?

Well, I was using itertools.cycle().next() method with Python 2.6.6, but now that I updated to 3.2 I noticed that itertools.cycle() object has no method next(). I used it to cycle a string in the spin()method of a Spinner class. So if we cycle the…
Paulo Freitas
  • 13,194
  • 14
  • 74
  • 96
44
votes
7 answers

How to determine if a linked list has a cycle using only two memory locations

Does anyone know of an algorithm to find if a linked list loops on itself using only two variables to traverse the list. Say you have a linked list of objects, it doesn't matter what type of object. I have a pointer to the head of the linked list…
jeffD
  • 1,230
  • 3
  • 13
  • 18
39
votes
4 answers

How to Center Text inside an SVG Path

I need some help, when I use svg to draw a cycle and put some text, how to Center Text inside an SVG Path
j leos
  • 389
  • 1
  • 3
  • 6
34
votes
10 answers

Generating a random DAG

I am solving a problem on directed acyclic graph. But I am having trouble testing my code on some directed acyclic graphs. The test graphs should be large, and (obviously) acyclic. I tried a lot to write code for generating acyclic directed…
Utkarsh Srivastav
  • 3,105
  • 7
  • 34
  • 53
33
votes
3 answers

Tarjan cycle detection help C#

Here is a working C# implementation of tarjan's cycle detection. The algorithm is found here: http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm public class TarjanCycleDetect { private static…
user623879
  • 4,066
  • 9
  • 38
  • 53
29
votes
4 answers

Any chances to imitate times() Ruby method in C#?

Every time I need to do something N times inside an algorithm using C# I write this code for (int i = 0; i < N; i++) { ... } Studying Ruby I have learned about method times() which can be used with the same semantics like this N.times do …
Alexander Prokofyev
  • 33,874
  • 33
  • 95
  • 118
23
votes
7 answers

Cycle through list starting at a certain element

Say I have a list: l = [1, 2, 3, 4] And I want to cycle through it. Normally, it would do something like this, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2... I want to be able to start at a certain point in the cycle, not necessarily an index, but perhaps…
john
  • 3,043
  • 5
  • 27
  • 48
23
votes
7 answers

Modulus (or lack thereof) in Ruby's Liquid templating engine

I'm working on a Jekyll site and am trying to output three column divs nested in a row div. Liquid makes this pretty easy with their cycle filter: {% for p in site.categories.post %} {% cycle 'add rows': '
', nil, nil %} …
Andrew
  • 36,541
  • 13
  • 67
  • 93
1
2 3
99 100