Finding the optimal topologies for different N and k using distance matrices