Implementation of k-median algorithm