Core of an algorithm for n-best similarity matching