Create space efficient prefix selection algorithm