Your algorithm runs in Omega (N k log k), where N is the
size of the set, and you are interested in the k smallest
elements. Which is pretty lousy. With k for instance N / 100,
your algorithm is worse than doing a bubble sort of the entire
set, and getting the k smallest from the sorted set.
Abigail