Implementation of k-means clustering algorithm