BUILT-IN WOLFRAM LANGUAGE SYMBOL

# FindCycle

FindCycle[g]

finds a cycle in the graph g.

FindCycle[g,k]

finds a cycle of length at most k in the graph g.

FindCycle[g,{k}]

finds a cycle of length exactly k.

FindCycle[g,{k_{min},k_{max}}]

finds a cycle of length between k_{min} and k_{max}.

FindCycle[g,kspec,s]

finds at most s cycles.

FindCycle[{g,v},…]

finds cycles that include the vertex v.

FindCycle[{vw,…},…]

uses rules vw to specify the graph g.

## DetailsDetails

- A cycle is also known as a circuit or loop.
- A cycle is a path with no repetitions of vertices or edges other than the starting and ending vertices.
- FindCycle gives a list of cycles. Each cycle is given as a list of edges.
- FindCycle will return an empty list if there is no cycle.
- FindCycle[g,kspec,All] finds all the cycles.
- For weighted graphs, FindCycle[g,k] gives all cycles with total weights less than k.
- FindCycle works with undirected graphs, directed graphs, and multigraphs.

## Background & ContextBackground & Context

- FindCycle attempts to find one or more distinct cycles in a graph. Cycles are returned as a list of edge lists or as {} if none exist. A cycle of a graph (more properly called a circuit when the cycle is identified using an explicit path with particular endpoints) is a consecutive sequence of distinct edges such that the first and last edges coincide at their endpoints. Cycle enumeration can be used for planning a cyclic route in many situations (subway, road trip, etc.), computing voltage or current in electronic circuits, or discovering infinite loops in computer programs.
- In general, FindCycle[g,kspec,s] attempts to find s cycles of length kspec. The count specification s may be omitted (in which case it is taken to be 1), may be a positive integer, or can be All. The length specification kspec may be a positive integer k (in which case it stands for cycles of length k or less), Infinity, a positive integer inside a list {k} (in which case it stands for cycles of length exactly k), or a list of two positive integers {k
_{min},k_{max}} (in which case it stands for cycles of lengths k_{min}through k_{max}). - FindCycle[g,Infinity] attempts to find a cycle of maximum length, with the length of such a cycle being known as the graph circumference. A graph for which FindCycle[g,{3}] returns {} is known as a triangle-free graph, and one for which FindCycle[g,{4}] returns {} is known as square-free. A cycle of length n, where n is the number of vertices in a graph, is known as a Hamiltonian cycle, and a graph possessing such a cycle is said to be Hamiltonian.
- A graph that does not contain any cycle is called an acyclic graph and can be tested for using AcyclicGraphQ.
- FindCycle returns simple cycles, while FindHamiltonianCycle, FindEulerianCycle, and FindFundamentalCycles return specific types of cycles. FindPath may be used to find a path (a set of edges for which the endpoints do not coincide) between two specific vertices, returned as a set of consecutive vertices along the path.

Introduced in 2014

(10.0)

| Updated in 2015 (10.3)

- Services
- Technical Services
- Corporate Consulting

- Company
- Announcements
- Events
- About Wolfram
- Careers
- Contact

- Connect
- Wolfram Community
- Wolfram Blog
- Newsletter

© 2017 Wolfram. All rights reserved.