Added imperative k-selection algorithm