Nearest neighbour based phasing algorithm