I lack 9 reputation points, so sadly I can't comment the great answer by w_s. ;)
Just for completeness, the concept described is known in graph theory as "Tarjan's Algorithm" for finding strongly connected components.
Wikipedia has a nice animation that helps following the steps.Tarjan's Algorithm http://zippy.gfycat.com/ActualSinfulConch.gif
For study, here is another (more formal) Python implementation, it's the one I have used for finding loops in functions in IDAscope but it's easily adapted for finding recursive functions.