Implementation of connection scan algorithm