Algorithm for finding recurrent and transient states.