The count of cycles (simple and not simple) of length n or less for Kn is given by the following function C(n).
The count consists of the count of cycles for each length 2 <= l <= n given by C(n, l).
The count for a given length l consists of the count of cycles (simple and not simple) from each vertex 1 <= i <= n given by C(i, n, l).
The following OCaml program counts the number of cycles for complete graphs K2 to K20.
To run the program in Linux or OSX, install the OCaml interpreter, save the program in a file, and grant execution permission to the file.
In OSX with Homebrew, when you save the program in file count-cycles.ml you install and run the program as follows.
Want to read more?
I love to explain and answer questions on programming problems, the kind you find in coding interviews.
I publish a new programming problem and its solution every Sunday.
Did I mention that I love to answer questions?