heuristic algorithm for grouping entities into clusters