More information on the algorithm to do so: https://en.wikipedia.org/wiki/Cycle_detection