Nearest neighbour algorithm