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 regularly write solutions to programming problems that you may or may not find in technical job interviews.
I also love to explain those solutions and answer questions.
If you would like to get the latest problem + solution, subscribe to the newsletter
or subscribe via RSS.
You can also follow me on