deterministic selection algorithm