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
22
votes
2 answers

What is the dynamic programming algorithm for finding a Hamiltonian cycle in a graph?

What is dynamic programming algorithm for finding a Hamiltonian cycle in an undirected graph? I have seen somewhere that there exists an algorithm with O(n.2^n) time complexity.
avd
  • 13,993
  • 32
  • 78
  • 99
21
votes
10 answers

Efficient algorithm to determine if an alleged binary tree contains a cycle?

One of my favorite interview questions is In O(n) time and O(1) space, determine whether a linked list contains a cycle. This can be done using Floyd's cycle-finding algorithm. My question is whether it's possible to get such good time and space…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
19
votes
2 answers

Would the ability to detect cyclic lists in Haskell break any properties of the language?

In Haskell, some lists are cyclic: ones = 1 : ones Others are not: nums = [1..] And then there are things like this: more_ones = f 1 where f x = x : f x This denotes the same value as ones, and certainly that value is a repeating sequence. But…
Jason Orendorff
  • 42,793
  • 6
  • 62
  • 96
19
votes
3 answers

Perl - while (<>) file handling

A simple program with while( <> ) handles files given as arguments (./program 1.file 2.file 3.file) and standard input of Unix systems. I think it concatenates them together in one file and work is line by line. The problem is, how do I know that…
Mantas Marcinkus
  • 603
  • 2
  • 6
  • 11
16
votes
1 answer

Counting Angular's $digest Cycles

tl;dr: I want to have angular trigger css animations on page load. Is there a way to count angular's digest cycles within say, a controller or directive? long version: I have some angular animations which I want to run when the page loads, using…
mmm
  • 2,272
  • 3
  • 25
  • 41
15
votes
5 answers

How to check if an edge is in some cycle?

I have a hw problem that asks for an algorithm that detects if there is any cycle in any undirected graph that contains any given edge 'E'. The algorithm should run in O(N) linear time. The problem I have is that I don't know where to start. I have…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
15
votes
4 answers

Cycle detection in linked list with the Hare and Tortoise approach

I understand that in order to detect a cycle in a linked list I can use the Hare and Tortoise approach, which holds 2 pointers (slow and fast ones). However, after reading in wiki and other resources, I do not understand why is it guaranteed that…
Meir
  • 1,691
  • 2
  • 14
  • 15
14
votes
2 answers

Detecting cycles in neo4j property graph using cypher

What is the best way to detect for cycles in a graph of a considerable size using cypher. I have a graph which has about 250000 nodes and about 270000 relationship and I would like to detect cycles in sub graph of about 10k nodes and involving 100k…
Amit
  • 435
  • 3
  • 13
13
votes
5 answers

"While" and "repeat" loops in Twig

Are there any nice ways to use while and repeat loops in Twig? It is such a simple task, but without macros I can't find anything nice and simple. At least do an infinite cycle and then break it in a condition? EDIT: I mean something like do { …
Aistis
  • 3,695
  • 2
  • 34
  • 34
13
votes
6 answers

Spinning progress bar in every listview item

I've been scratching my head over this for a long time now and searched for an answer without any luck! It seems to be trivial, but as far as I know, it isn't. I use a listview in my Android application where every item (view) displays a spinning…
maglar
  • 151
  • 2
  • 8
12
votes
4 answers

Why Oracle connect by with nocycle follows root cycle

Does anyone know why Oracle continues to follow a path beyond a cyclical loop when the cycle occurs at the top node (root node connected right back to root node)? More importantly, how to prevent it? I have Oracle 11g Release 2 (11.2) and I have…
Larry May
  • 121
  • 1
  • 1
  • 4
12
votes
11 answers

Finding cycle of 3 nodes ( or triangles) in a graph

I am working with complex networks. I want to find group of nodes which forms a cycle of 3 nodes (or triangles) in a given graph. As my graph contains about million edges, using a simple iterative solution (multiple "for" loop) is not very…
zapa
  • 121
  • 1
  • 1
  • 3
11
votes
2 answers

jQuery Cycle plugin- How to return the index number of the currently displayed slide?

I'm currently using Malsup's Cycle plugin . I am just wondering is it possible to have cycle plugin return the index number of the currently displayed slide?? I want to change the content of the page when a specific slide is active. Don't know how…
Newcomer
  • 135
  • 1
  • 6
11
votes
1 answer

How long does the stream of Random().Next() take until it repeats?

Consider the .NET Random stream: var r = new Random(); while (true) { r.Next(); } How long does it take to repeat?
aharon
  • 7,393
  • 10
  • 38
  • 49
11
votes
1 answer

Why does Python's itertools.cycle need to create a copy of the iterable?

The documentation for Python's itertools.cycle() gives a pseudo-code implementation as: def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... saved = [] for element in iterable: yield element …
stantonk
  • 1,922
  • 1
  • 18
  • 24