Detecting Infinite Loop See this post for the rabbit and turtle algorithm for detecting infinite loop with O(n) complexity. https://wp.me/p1axj-4