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
11
votes
3 answers

How can I find the number of Hamiltonian cycles in a complete undirected graph?

Can someone explain how to find the number of Hamiltonian cycles in a complete undirected graph? Wikipedia says that the formula is (n-1)!/2, but when I calculated using this formula, K3 has only one cycle and K4 has 5. Was my calculation incorrect?
avd
  • 13,993
  • 32
  • 78
  • 99
10
votes
4 answers

Check if two arrays are cyclic permutations

Given two arrays, how do you check if one is a cyclic permutation of the other? For example, given a = [1, 2, 3, 1, 5], b = [3, 1, 5, 1, 2], and c = [2, 1, 3, 1, 5] we have that a and b are cyclic permutations but c is not a cyclic permutation of…
dsg
  • 12,924
  • 21
  • 67
  • 111
10
votes
3 answers

Cycle a Rust iterator a given number of times

How do I cycle through an iterator a finite number of times? I would expect the output of something like this to be 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 and then stop: vec![1, 2, 3].iter().cycle(4) // ^ but .cycle() doesn't…
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
10
votes
1 answer

What are the relative cycle times for the 6 basic arithmetic operations?

When I try to optimize my code, for a very long time I've just been using a rule of thumb that addition and subtraction are worth 1, multiplication and division are worth 3, squaring is worth 3 (I rarely use the more general pow function so I have…
DrZ214
  • 486
  • 5
  • 19
10
votes
6 answers

How to find the length of a linked list that is having cycles in it?

This was one of the interview questions asked. How to find the length of a linked list that is having cycle in it. I know how to calculate whether a linked list has a cycle or not using Hare and Tortoise technique. I even know how to calculate the…
bragboy
  • 34,892
  • 30
  • 114
  • 171
10
votes
1 answer

Possible causes of cyclic FPS drops?

I was writing a new code base in opengl and have encountered a weird bug very early on. It is a distinct fluctuation in framerate that is repetitive and predictable. I know that it is definitely proportional to objects rendered. It is also…
Nathan Wride
  • 965
  • 1
  • 7
  • 28
9
votes
2 answers

Detecting a repeating cycle in a sequence of numbers (python)

I was wondering what would be a a fairly 'common' or normal way of doing this. Wasn't really looking for the shortest possible answer like a 2-liner or anything. I've just quickly put this piece of code together but I can't not feel like there's way…
SuperLemon
  • 751
  • 1
  • 7
  • 23
9
votes
1 answer

Is there a data structure for DAGs that supports efficient edits?

I'm looking for a data structure that will store any DAG, but can efficiently (i.e., sub-linearly in the number of edges/vertices) detect if adding an edge would create a cycle (and thus prevent you from breaking the acyclic invariant). Does anyone…
copumpkin
  • 2,836
  • 18
  • 25
9
votes
1 answer

r igraph find all cycles

I have directed igraph and want to fetch all the cycles. girth function works but only returns the smallest cycle. Is there a way in R to fetch all the cycles in a graph of length greater then 3 (no vertex pointing to itself and loops)
Ankit
  • 6,388
  • 8
  • 54
  • 79
9
votes
3 answers

Is there a way to cycle through indexes

list1 = [1,2,3,4] If I have list1 as shown above, the index of the last value is 3, but is there a way that if I say list1[4], it would become list1[0]?
Aditya
  • 144
  • 2
  • 13
8
votes
4 answers

jQuery Cycle plugin z-index float problem

When I try to place an element on top of my jQuery Cycle element, it doesn't work. The element is always behind the jQuery cycle element. I use float: right; to position the element, and set its z-index to 100000, to no avail. Firebug sees the…
Antony Carthy
  • 5,549
  • 9
  • 34
  • 38
8
votes
2 answers

Simple implementation for detecting cycles in a directed graph in C#

I wonder if you could help me with a simple implementation for detecting cycles in a directed graph in C#. I've read about the algorithms but I'd like to find something already implemented, very simple and short. I don't care about the performance…
Homam
  • 23,263
  • 32
  • 111
  • 187
8
votes
2 answers

Zip cyclically over multiple lists in Python

Say I have these three lists: aList = [1,2,3,4,5,6] bList = ['a','b','c','d'] cList = [1,2] and I want to iterate over them using zip. By using cycle with zip as following: from itertools import cycle for a,b,c in zip(aList, cycle(bList),…
Abhijay Ghildyal
  • 4,044
  • 6
  • 33
  • 54
8
votes
3 answers

Count number of cycles in directed graph using DFS

I want to count total number of directed cycles available in a directed graph (Only count is required). You can assume graph is given as adjacency matrix. I know DFS but could not make a working algorithm for this problem. Please provide some…
8
votes
4 answers

help in the Donalds B. Johnson's algorithm, i cannot understand the pseudo code (PART II)

i cannot understand a certain part of the paper published by Donald Johnson about finding cycles (Circuits) in a graph. More specific i cannot understand what is the matrix Ak which is mentioned in the following line of the pseudo code…
C.LS
  • 1,319
  • 2
  • 17
  • 35