algorithm 1 for removing redundant datapoints