algorithm for Encounters