Faster Algorithms for the Constrained k-means Problem

The classical center based clustering problems such as $k$-means/median/center assume that the optimal clusters satisfy the locality property that the points in the same cluster are close to each other. A number of clustering problems arise in machine learning where the optimal clusters do not follow such a locality property. Consider a variant of the $k$-means problem that may be regarded as a general version of such problems. Here, the optimal clusters $O_1, ..., O_k$ are an arbitrary partition of the dataset and the goal is to output $k$-centers $c_1, ..., c_k$ such that the objective function $\sum_{i=1}^{k} \sum_{x \in O_{i}} ||x - c_{i}||^2$ is minimized. It is not difficult to argue that any algorithm (without knowing the optimal clusters) that outputs a single set of $k$ centers, will not behave well as far as optimizing the above objective function is concerned. However, this does not rule out the existence of algorithms that output a list of such $k$ centers such that at least one of these $k$ centers behaves well. Given an error parameter $\varepsilon>0$, let $\ell$ denote the size of the smallest list of $k$-centers such that at least one of the $k$-centers gives a $(1+\varepsilon)$ approximation w.r.t. the objective function above. In this paper, we show an upper bound on $\ell$ by giving a randomized algorithm that outputs a list of $2^{\tilde{O}(k/\varepsilon)}$ $k$-centers. We also give a closely matching lower bound of $2^{\tilde{\Omega}(k/\sqrt{\varepsilon})}$. Moreover, our algorithm runs in time $O \left(n d \cdot 2^{\tilde{O}(k/\varepsilon)} \right)$. This is a significant improvement over the previous result of Ding and Xu who gave an algorithm with running time $O \left(n d \cdot (\log{n})^{k} \cdot 2^{poly(k/\varepsilon)} \right)$ and output a list of size $O \left((\log{n})^k \cdot 2^{poly(k/\varepsilon)} \right)$.


Introduction
Clustering problems intend to classify high dimensional data based on the proximity of points to each other. There is an inherent assumption that the clusters satisfy locality property -points close to each other (in a geometric sense) should belong to the same category. Often, we model such problems by the notion of a center based clustering problem. We would like to identify a set of centers, one for each cluster, and then the clustering is obtained by assigning each point to the nearest center. For example, the k-means problem is defined in the following manner: given a dataset X = {x 1 , . . . , x n } ⊂ R d and an integer k, output a set of k centers {c 1 , . . . , c k } ⊂ R d such that the objective function x∈X min c∈{c 1 ,...,c k } ||x − c|| 2 is minimized. The k-median and the k-center problems are defined in a similar manner by defining a suitable objective function.
However, often such clustering problems entail several side constraints. Such constraints limit the set of feasible clusterings. For example, the r-gather k-means clustering problem is defined in the same manner as the k-means problem, but has the additional constraint that each cluster must have at least r points in it. In such settings, it is no longer true that the clustering is obtained from the set of centers by the Voronoi partition. Ding and Xu [DX15] began a systematic study of such problems, and this is the starting point of our work as well. They defined the so-called constrained k-means problem. An instance of such a problem is specified by a set of points X, a parameter k, and a set C, where each element of C is a partitioning of X into k disjoint subsets (or clusters). Since the set C may be exponentially large, we will assume that it is specified in a succinct manner by an efficient algorithm which decides membership in this set. A solution needs to output an element O = {O 1 , . . . , O k } of C, and a set of k centers, c 1 , . . . , c k , one for each cluster in O. The goal is to minimize k i=1 x∈O i ||x − c i || 2 . It is easy to check that the center c i must be the mean of the corresponding cluster O i . Note that the k-means problem is a special case of this problem where the set C contains all possible ways of partitioning X into k subsets. The constrained k-median problem can be defined similarly. We will make the natural assumption (which is made by Ding and Xu as well) that it suffices to find a set of k centers. In other words, there is an (efficient) algorithm A C , which given a set of k centers c 1 , . . . , c k , outputs the clustering {O 1 , . . . , O k } ∈ C such that k i=1 x∈O i ||c i − x|| 2 is minimized. Such an algorithm is called a partition algorithm by Ding and Xu [DX15] 2 . For the case of the k-means problem, this algorithm will just give the Voronoi partition with respect to c 1 , . . . , c k , whereas in the case of the r-gather k-means clustering problem, the algorithm A C will be given by a suitable min-cost flow computation (see section 4.1 in [DX15]).
Ding and Xu [DX15] considered several natural problems arising in diverse areas, e.g. machine learning, which can be stated in this framework. These included the so-called r-gather k-means, r-capacity k-means and l-diversity k-means problems. Their approach for solving such problems was to output a list of candidate sets of centers (of size k) such that at least one of these were close to the optimal centers. We formalize this approach and show that if k is a constant, then one can obtain a PTAS for the constrained k-means (and the constrained k-median) problems whose running time is linear plus a constant number of calls to A C .
We define the list k-means problem. Given a set of points X and parameters k and ε, we want to output a list L of sets of k points (or centers). The list L should have the following property: for any partitioning O = {O 1 , . . . , O k } of X into k clusters, there exists a set c 1 , . . . , c k in the list L such that (up-to reordering of these centers) where m i = x∈O i x |O i | denotes the mean of O i . Note that the latter quantity is the k-means cost of the clustering O, and so we require c 1 , . . . , c k to be such that the cost of assigning to these centers is close to the optimal k-means cost of this clustering. We shall use opt k (O) to denote the optimal k-means cost of O.
Although such an oblivious approach to clustering may appear too optimistic, we show that it is possible to obtain such a list L of size 2Õ (k/ε) in O nd · 2Õ (k/ε) time. This improves the result of Ding and Xu [DX15], where they gave an algorithm which outputs a list of size O (log n) k · 2 poly(k/ε) . Observe that we address a question which is both algorithmic and existential : how small can the size of L be, and how efficiently can we find it ? We also give almost matching lower bounds on the size of such a list L. Our algorithm for finding L relies on the D 2 -sampling idea -iteratively find the centers by picking the next one to be far from the current set of centers. Although these ideas have been used for the k-means problems (see e.g. [JKS14]), they rely heavily on the fact that given a set of centers, the corresponding clustering is obtained by the corresponding Voronoi partition. Our approach relies in showing that there is small sized list L which works well for all possible clusterings.
It is not hard to show that a result for the list k-means problem implies a corresponding result for the constrained k-means problem with the number of calls to A C being equal to the size of the list L. Therefore, we obtain as corollary of our main result efficient algorithms for the constrained k-means (and the constrained k-median) problems.

Related work
The classical k-means problem is one of the most well-studied clustering problems. There is a long sequence of work on obtaining fast PTAS for the k-means and the k-median problems (see e.g., [Mat00, BHPI02, dlVKKR03, HPM04, KSS10, ABS10, Che06, JKS14, FMS07] and references therein). Some of these works implicitly maintain a list of centers of size k such that the condition (1) is satisfied for all clusterings O which correspond to a Voronoi partition (with respect to a set of k centers) of the input set of points, and one picks the best possible set of centers from this list (see e.g., [KSS10, ABS10, JKS14]). The list has at most 2 poly(k/ε) elements, and from this, one can recover a (1 + ε)-approximation algorithm for the k-means problem with running time O nd · 2 poly(k/ε) .
The more general case of the constrained k-means problem was studied by Ding and Xu [DX15] who also gave an algorithm that outputs a list of size O (log n) k · 2 poly(k/ε) . Our work improves upon this result. Moreover, we consider the formulation of the list k-means problem as an important contribution, and feel that similar formulations in other classification settings would be useful.

Preliminaries
We formally define the problems considered in this paper. The centroid or mean of a finite set of points X ⊂ R d is denoted by Γ (X) = x∈X x |X| . Let ∆(X) denote the 1-means cost of these set of points, i.e., x∈X ||x − Γ (X)|| 2 .
An input instance I for the list k-means (or the list k-median) problem consists of a set of points X, a positive integer k and a positive parameter ε. A partition of X into disjoint subsets O 1 , . . . , O k will be called a clustering of X. Given a clustering O ⋆ = {O ⋆ 1 , . . . , O ⋆ k } of X and a set of k centers C = {c 1 , . . . , c k }, define cost C (O ⋆ ) as the minimum, over all permutations π of C, For a set of points X and a set of points C (of size at most k), define Φ C (X) as x∈X min c∈C ||x− c|| 2 , i.e., we consider the Voronoi partition of X induced by C, and consider the k-means cost of X with respect to this partition. When considering the list k-median problem, we will use the same notation, except that we will consider the Euclidean norm instead of the square of the Euclidean norm. When C is a singleton set {c}, we shall abuse notation by using Φ c (X) instead of Φ {c} (X).
As mentioned in the introduction, the constrained k-means problem is specified by a set of points X, a positive integer k, and a set C of feasible clusterings of X. Further, we are given an algorithm A C , which given a set of k centers C, outputs the clustering O in C which minimizes cost C (O). The goal is to find a clustering O ∈ C and a set C of size k which minimizes cost C (O). Note that the centers in C should just be the mean of each cluster in O. On the other hand, if we know C, then we can find the best clustering in C by calling A C . We use the same notation for the constrained k-median problem.
We now mention a few results which will be used in our analysis. The following fact is well known.
We next define the notion of D 2 -sampling.
Definition 1 (D 2 -sampling). Given a set of points X ⊂ R d and another set of points C ⊂ R d , . The following result of Inaba et al. [IKI94] shows that a constant size random sample is a good enough approximation of a set of points X as far as the 1-means objective is concerned.
Lemma 1 ( [IKI94]). Let S be a set of points obtained by independently sampling M points with replacement uniformly at random from a point set X ⊂ R d . Then for any δ > 0, We will also use the following simple fact that may be interpreted as approximate version of the triangle inequality for squared Euclidean distance.

Our results
We now state our results for the list k-means and the list k-median problems.
Theorem 1. Given a set of n points X ⊂ R d , parameters k and ε, there is a randomized algorithm which outputs a list L of 2Õ (k/ε) sets of centers of size k such that for any clustering O ⋆ = {O ⋆ 1 , ..., O ⋆ k } of X, the following event happens with probability at least 1/2 : there is a set C ∈ L such that Moreover, the running time of our algorithm is O nd · 2Õ (k/ε) . The same statement holds for the list k-median problem as well, except that the size of the list L becomes 2Õ (k/ε O(1) ) and the running time of our algorithm becomes O nd · 2Õ (k/ε O(1) ) .
As a corollary of this result we get PTAS for the constrained k-means problem (and similarly for the constrained k-median problem).
Corollary 1. There is a randomized algorithm which given an instance of the constrained k-means problem and parameter ε > 0, outputs a solution of cost at most (1 + ε)-times the optimal cost with probability at least 1/2. Further, the time taken by this algorithm is where T denotes the time taken by A C on this instance.
Proof. We use the algorithm in Theorem 1 to get a list L for this data-set. For each set C ∈ L, we invoke A C with C as the set of centers -let O(C) denote the clustering produced by A C . We output the clustering for which cost C (O(C)) is minimum. Let O ⋆ be the optimal clustering, i.e., the clustering in C for which opt k (O ⋆ ) is minimum. We know that with probability at least 1/2, there is set C ∈ L for which cost C (O ⋆ ) ≤ (1 + ε)opt k (O ⋆ ). Now, the solution produced by our algorithm has cost at most cost C (O(C)), which by definition of A C , is at most cost C (O ⋆ ).

⊓ ⊔
We also give a nearly matching lower bound on the size of L. The following result along with Yao's Lemma shows that one cannot reduce the size of L to less than 2Ω k √ ε .
Theorem 2. Given a parameter k and a small enough positive constant ε, there exists a set X of points in R d and a set C of clusterings of X such that any list L of centers of size k with the following property must have size at least 2Ω Our techniques also extend to settings involving many other "approximate" metric spaces (see the discussion in Section 6). Another important observation is that in the lower bound result above, the clusterings in C correspond to Voronoi partitions of X. This throws light on the previous works [KSS10, ABS10, FMS07, JKS14, JKY15] as to why the running time of all the algorithms was proportional to 2 poly(k/ε) : they were implicitly maintaining a list which satisfied (1) for all Voronoi partitions of X, and therefore, our lower bound result applies to their algorithms as well.

Our Techniques
Our techniques are based on the idea of D 2 -sampling that was used by Jaiswal et al.
[JKS14] to give a (1 + ε)-approximation algorithm for the k-means problem. Our ideas also have similarities to the ideas of Ding and Xu [DX15]. We discuss these similarities towards the end of this subsection.
One of the crucial ingredients that is used in most of the (1 + ε)-approximation algorithms for k-means is Lemma 1. This result essentially states that given a set of points P , if we are able to uniformly sample O(1/ε) points from it, then the mean of these sampled points will be a good substitute for the mean of P . Consider an optimal clustering O ⋆ 1 , . . . , O ⋆ k for a set of points X. If we could uniformly sample from each of the clusters O ⋆ i , then by the argument above, we will be done. The first problem one encounters is that one can only sample from the input set of points, and so, if we sample sufficiently many points from X, we need to somehow distinguish the points which belong to O ⋆ i in this sample. This can be dealt with using the following argument: suppose we manage to get a small sample S of points (say of size O(poly(k/ε))) that contain at least Ω(1/ε) points uniformly distributed in O ⋆ i , then we can try all possible subsets of S of size O(1/ε) and ensure that at least one of the subsets is a uniform sample of appropriate size from O ⋆ i . Another issue is -how do we ensure that the sample S has sufficient representation from O ⋆ i ? Uniform sampling from the input X will not work since |O ⋆ i | might be really small compared to the size of |X|. This is where D 2 -sampling plays a crucial role and we discuss this next.
Given a set of points X ⊆ R d and candidate centers c 1 , ..., c i ∈ R d , D 2 -sampling with respect to the centers c 1 , ..., c i samples a point x ∈ X with probability proportional to min c∈{c 1 ,...,c i } ||x − c|| 2 . Note that this process "boosts" the probability of a cluster O ⋆ j that has many points far from the set {c 1 , . . . , c i }. Therefore, even if a cluster O ⋆ j has a small size, we will have a good chance of sampling points from it (if it is far from the current set of centers). However, this nonuniform sampling technique gives rise to another issue. The points being sampled are no longer uniform samples from the optimal clusters. Depending on the current set of centers, different points in a cluster O ⋆ j have different probability of getting sampled. This issue is not that grave for the k-means problem where the optimal clusters are Voronoi regions since we can argue that the probabilities are not very different. However, for the constrained k-means problem where the optimal clusters are allowed to be arbitrary partition of the input points, this problem becomes more serious. This can be illustrated using the following example. Suppose we have managed to pick centers c 1 , . . . , c i that are good (in terms of cluster cost) for the optimal clusters O ⋆ 1 , . . . , O ⋆ i . At this point let O ⋆ j denote the cluster other than O ⋆ 1 , . . . , O ⋆ i , such that a point sampled using D 2 sampling w.r.t. c 1 , . . . , c i is most likely to be from O ⋆ j . Suppose we sample a set S of O(k/ε) points using D 2 -sampling. Are we guaranteed (w.h.p.) to have a subset in S that is a uniform sample from O ⋆ j ? The answer is no (actually quite far from it). This is because the optimal clusters may form an arbitrary partition of the data-set and it is possible that most of the points in O ⋆ j might be very close to the centers c 1 , . . . , c i . In this case the probability of sampling such points will be close to 0. The way we deal with this scenario is that we consider a multi-set S ′ that is the union of the set of samples S and O(1/ε) copies of each of c 1 , . . . , c i . We then argue that all the points in O ⋆ j that is far from c 1 , . . . , c i will have a good chance of being represented in S (and hence in S ′ ). On the other hand, even though the points that are close to one of c 1 , . . . , c i will not be represented in S (and hence S ′ ), the center (among c 1 , . . . , c i ) that is close to these points have good representation in S ′ and these centers may be regarded as "proxy" for the points in O ⋆ j . Ding and Xu [DX15], instead of using the idea of D 2 -sampling, rely on the ideas of Kumar et al.
[KSS10] which involves uniform sampling of points and then pruning the data-set by removing the points that are close to centers that are currently being considered. In their work, they also encounter the problem that points from some optimal cluster might be close to the current set good centers (and hence will be removed before uniform sampling). Ding and Xu [DX15] deal with this issue using what they call a "simplex lemma". Consider the same scenario as in the previous paragraph. At a very high level, they consider grids inside several simplices defined by the current centers c 1 , . . . , c i and the sampled points. Using the simplex lemma, they argue that one of the points inside these grids will be a good center for the cluster O ⋆ j . We now give an overview of the paper. In Section 2, we give the algorithm for generating the list of sets of centers for an instance of the list k-means problem. The algorithm is analyzed in Section 3. In Section 4, we give the lower bound result on the size of the list L. In Section 5, we discuss how our algorithm can be extended to the list k-median problem. We conclude with a brief discussion on extensions to other metrics in Section 6.

The Algorithm
Consider an instance of the list k-means problem. Let X denote the set of points, and ε be a positive parameter. The algorithm List-k-means is described in Figure 2.1. It maintains a set C of centers, which is initially empty. Each recursive call to the function Sample-centers increases the size of C by one. In Step 2 of this function, the algorithm tries out various candidates which can be added to C (to increase its size by 1). First, it builds a multi-set S as follows: it independently samples (with replacement) O(k/ε 3 ) points using D 2 -sampling from X w.r.t. the set C. Further, it adds O(1/ε) copies of each of the centers in C to the set S. Having constructed S, we consider all subsets of size O(1/ε) of S -for each such subset we try adding the mean of this set to C. Thus, each invocation of Sample-centers makes multiple recursive calls to itself ( |S| M to be precise). It will be useful to think of the execution of this algorithm as a tree T of depth k. Each node in the tree can be labeled with a set C -it corresponds to the invocation of Sample-centers with this set as C (and i being the depth of this node). The children of a node denote the recursive function calls by the corresponding invocation of Sample-centers. Finally, the leaves denote the set of candidate centers produced by the algorithm.

Analysis
In this section we prove Theorem 1 for the list k-means problem. Let L denote the set of candidate solutions produced by List-k-means, where a solution corresponds to a set of centers C of size k. These solutions are output at the leaves of the execution tree T . Fix a clustering Recall that a node v at depth i in the execution tree T corresponds to a set C of size i -call -Repeat 2 k times: -Make a call to Sample-centers(X, k, ε, 0, {}).
Algorithm 2.1. Algorithm for list k-means this set C v . Our proof will argue inductively that for each i, there will be a node v at depth i such that the centers chosen so far in C v are good with respect to a subset of i clusters in O ⋆ 1 , . . . , O ⋆ k . We will argue that the following invariant P (i) is maintained during the recursive calls to Samplecenters: where c 1 , . . . , c i−1 are the centers in the set C v i corresponding to v i . Recall that ∆(O ⋆ j l ) refers to the optimal 1-means cost of O ⋆ j l .
The proof of the main theorem follows easily from this invariant property -indeed, the statement P (k) holds with probability at least 1/2 k . Since the algorithm List-k-means invokes Samplecenters 2 k times, the probability of the statement in P (k) being true in at least one of these invocations is at least a constant. We now prove the invariant by induction on i. The base case for i = 1 follows trivially: the vertex v 1 is the root of the tree T and C v 1 is empty. Now assume that P (i) holds for some i ≥ 1. We will prove that P (i + 1) also holds. We first condition on the event in P (i) (which happens with probability at least 1 2 i−1 ). Let v i and O ⋆ j 1 , . . . , O ⋆ j i−1 be as guaranteed by the invariant P (i). Let C v i = {c 1 , . . . , c i−1 } (as in the statement P (i)). For sake of ease of notation, we assume without loss of generality that the index j i is i, and we shall use C i to denote C v i . Thus, the center c l corresponds to the cluster is proportional to the probability that a point sampled from X using D 2 -sampling w.r.t. C i comes from the set O ⋆ i ′ -letī ∈ {i, . . . , k} be the index i ′ for which Φ C i (O ⋆ i ′ ) is maximum. We will argue that the invocation of Sample-centers corresponding to v i will try out a point c i (in Step 2(d)(i)) such that the following property will hold with probability at least 1/2: . For doing this, we break the analysis into the following two parts. These two parts are discussed in the next two subsections that follow.
Case I < ε 13k : This captures the scenario where the probability of sampling from any of the uncovered clusters is very small. Note that for the classical k-means problem, this is not an issue because in this case we can argue that the current set of centers C already provides a good approximation for the entire set of data points and we are done. However, for us this is an issuefor example, assuming i > 2, it is possible that some of the points in O ⋆ i are close to c 1 , whereas the remaining points of this cluster are close to c 2 . Still we need to output a center for O ⋆ i . In this case we argue that it will be sufficient to output a suitable convex combination of c 1 and c 2 .
Case II ≥ ε 13k : In this case, we argue that with good probability we will sample sufficient points from O ⋆ i during Step 2(a) of Sample-centers. Further, we will show that a suitable combination of such points along with centers in C i will be a good center for O ⋆ i .
Case I : In this case we argue that a convex combination of the centers in C i provides a good approximation to ∆(O ⋆ i ). Intuitively, this is because the points in O ⋆ i are close to the points in the set C i . This convex combination is essentially "simulated" by taking O(1/ε) copies of each of the centers c 1 , ..., c i−1 in the multi-set S and then trying all possible subsets of size O(1/ε). The formal analysis follows. First, we note that The induction hypothesis and the fact that i respectively. We first show that m ⋆ and m ′ are close, and so, assigning all the points of O ⋆ i to m ′ will have cost close to ∆(O ⋆ i ). Secondly, we show that if we have a good approximation m ′′ to m ′ , then assigning all the points of O ⋆ i to m ′′ will also incur small cost (comparable to ∆(O ⋆ i )). We now carry out these steps in detail. Observe that where the second last inequality follows from Cauchy-Schwartz 3 . ⊓ ⊔

Now we show that ∆(O ⋆ i ) and ∆(O
Proof. The lemma follows by the following inequalities:

⊓ ⊔
Finally, we argue that a good center for O ′ i will also serve as a good center for O ⋆ i .
This completes the proof of the lemma.

⊓ ⊔
The above lemma tells us that it will be sufficient to obtain a (1 + ε/8)-approximation to the 1-means problem for the dataset O ′ i . Now, Lemma 1 tells us that there is a subset (again as a multi-set) O ′′ of size 16 ε of O ′ i such that the mean m ′′ of these points satisfies the conditions of Lemma 5. Now, observe that O ′′ will be a subset of the set S constructed in Step 2 of the algorithm Sample-center -indeed, in Step 2(c), we add more than 16 ε copies of each point in C i to S. Now, in Step 2(d), we will try out all subsets of size 16 ε of S and for each such subset, we will try adding its mean to C i . In particular, there will be a recursive call of this function, where we will have C i+1 = C i ∪ {m ′′ } as the set of centers. Lemma 5 now implies that C i+1 will satisfy the invariant P (i + 1). Thus, we are done in this case.

Case II
In this case, we would like to prove that we add a good approximation to the mean of O ⋆ i to the set C i . Again, consider the invocation of Sample-centers corresponding to C i . We want the multi-set S to contain a good representation from points in the set O ⋆ i . Secondly, in order to apply Lemma 1, we will need this representation to be a uniform sample from , the probability that a point sampled using D 2 sampling w.r.t. C i is from O ⋆ i is not too small. So, the multi-set S will have non-negligible representation from the set O ⋆ i . However the points from O ⋆ i in S may not be a uniform sample from O ⋆ i . Indeed, suppose there is a good fraction of points of O ⋆ i which are close to C i , and remaining points of O ⋆ i are quite far from C i . Then, D 2 -sampling w.r.t. to C i will not give us a uniform sample from O ⋆ i . To alleviate this problem, we take sufficiently many copies of points in C i and add them to the multi-set S. In some sense, these copies act as proxy for points in O ⋆ i that are too close to C i . Finally, we argue that one of the subsets of S "simulates" a uniform sample from O ⋆ i and the mean of this subset provides a good approximation for the mean of O ⋆ i . The formal analysis follows. We divide the points in O ⋆ i into two parts -points which are close to a center in C i , and the remaining points. More formally, let the radius R be given by i except that points close to centers in C i have been "collapsed" to these centers by taking appropriate number of copies. Clearly, |O At a high level, we will argue that any center that provides a good 1-means approximation for O ′ i also provides a good approximation for O ⋆ i . We will then focus on analyzing whether the invocation of Sample-centers tries out a good center for O ′ i . We give some more notation. Let m ⋆ and m ′ denote the mean of O ⋆ i and O ′ i respectively. Let n ⋆ and n denote the size of the sets O ⋆ i and O n i respectively. First, we show that ∆(O ⋆ i ) is large with respect to R.
Proof. Let c be the center in C i which is closest to m ⋆ . We divide the proof into two cases: Therefore, (ii) ||m ⋆ − c|| < 5 ε · R: In this case, we have This completes the proof of the lemma. ⊓ ⊔ Proof. Since the only difference between O ⋆ i and O ′ i are the points in O n i , we get where the first inequality follows from the Cauchy-Schwartz inequality.
The lemma follows from the following sequence of inequalities: . This completes the proof of the lemma.

We now argue that any center that is good for O
Proof. The lemma follows from the following inequalities: This completes the proof of the lemma. ⊓ ⊔ Given the above lemma, all we need to argue is that our algorithm indeed considers a center m ′′ such that Φ m ′′ (O . Therefore, the fact that we are in case II implies that . This completes the proof of the lemma. ⊓ ⊔ Let X 1 , . . . X l be l points sampled independently using D 2 -sampling w.r.t. C i . We construct a new set of random variables Y 1 , . . . , Y l . Each variable Y u will depend on X u only, and will take values either in O ′ i or will be ⊥. These variables are defined as follows: if X u / ∈ O f i , we set Y u to ⊥. Otherwise, we assign Y u to one of the following random variables with equal probability: (i) X u or (ii) a random element of the multi-set c(O n i ). The following observation follows from Lemma 10.

Corollary 2. For a fixed index u, and an element
Proof. If x ∈ O f i , then we know from Lemma 10 that X u is x with probability at least γ . Conditioned on this event, Y u will be equal to X u with probability 1/2. Now suppose x ∈ c(O n i ). Lemma 10 implies that X u is an element of O f i with probability at least ε 15k . Conditioned on this event, Y u will be equal to x with probability at least 1 2 · 1 |c(O n i )| . Therefore, the probability that X u is equal to x is at least ε 15k · 1 Corollary 2 shows that we can obtain samples from O ′ i which are nearly uniform (up to a constant factor). To convert this to a set of uniform samples, we use the idea of [JKS14]. For an element x ∈ O ′ i , let γ x be such that γx |O ′ i | denotes the probability that the random variable Y u is equal to x (note that this is independent of u). Corollary 2 implies that γ x ≥ γ ′ . We define a new set of independent random variables Z 1 , . . . , Z l . The random variable Z u will depend on Y u only. If i , then Z u takes the value x with probability γ ′ γx , and ⊥ with the remaining probability. Note that Z u is either ⊥ or one of the elements of O ′ i . Further, conditioned on the latter event, it is a uniform sample from O ′ i . We can now prove the key lemma.
Lemma 11. Let l be 128 γ ′ ·ε , and m ′′ denote the mean of the non-null samples from Z 1 , . . . , Z l . Then, with probability at least 1/2, Proof. Note that a random variable Z u is equal to a specific element of O ′ i with probability equal to . Therefore, it takes ⊥ value with probability 1 − γ ′ . Now consider a different set of iid random variables Z ′ u , 1 ≤ u ≤ l as follows: each Z u tosses a coin with probability of Heads being γ ′ . If we get Heads, it gets value ⊥, otherwise it is equal to a random element of O ′ i . It is easy to check that the joint distribution of the random variables Z ′ u is identical to that of the random variables Z u . Thus, it suffices to prove the statement of the lemma for the random variables Z ′ u . Now we condition on the coin tosses of the random variables Z ′ u . Let n ′ be the number of the number of random variables which are not ⊥. (n ′ is a deterministic quantity because we have conditioned on the coin tosses). Let m ′′ be the mean of such non-⊥ variables among Z ′ 1 , . . . , Z ′ l . If m ′′ happens to be larger than 64/ε, Lemma 1 implies that with probability at least 3/4, Finally, observe that the expected number of non-⊥ random variables is γ ′ ·l ≥ 128/ε. Therefore, with probability at least 3/4, the number of non-⊥ elements will be at least 64/ε.
denote the multi-set obtained by taking l copies of each of the centers in C i . Now observe that all the non-⊥ elements among Y 1 , . . . , Y l are elements of {X 1 , . . . , X l } ∪ C (l) i , and so the same must hold for Z 1 , . . . , Z l . This implies that in Step 2(d) of the algorithm Samplecenters, we would have tried adding the point m ′′ as described in Lemma 11. Therefore, the induction hypothesis continues to hold with probability at least 1/2. This concludes the proof of Theorem 1.

Lower Bound
In this section, we prove the lower bound result Theorem 2. Consider parameters k and ε (assume ε is a small enough constant). We first define the set of points X. Let m denote ⌈ 1 √ ε ⌉. The points will belong to R d , where d = km. The set X will have d points, namely, e 1 , . . . , e d , where e i denotes the vector which has all coordinates 0, except for the i th coordinate, which is 1. Now, we define the set C of clusterings of X. The set C will consist of those clusterings O = {O 1 , . . . , O k } for which each of the clusters has exactly m points. Observe that Now fix a set C of k centers, c 1 , . . . , c k . We will now upper bound the number of clusterings O ∈ C for which Let O = {O 1 , . . . , O k } be as above. Note that Recall that cost C (O) is obtained by assigning each cluster in O to a unique center in C, and then by computing the sum of square of distances of points in X to the corresponding centers. Wlog we rearrange the clusters in O such that the points in O j are assigned to c j . For a vector v, we shall use (v) j to denote the j th coordinate of v. For every center c r we define a corresponding vector v r as follows: Proof. Fix a cluster O r . Let m r denote the mean of O r . Note that (m r ) j is 1/m if e j ∈ O r , 0 otherwise. We now simplify the expression cost C (O) as follows: .

⊓ ⊔
Now define a corresponding assignment function f : X → {1, . . . , k} as follows: . . , O ′ k } be another clustering in C which satisfies condition (6). Define vectors v ′ r and the assignment function f ′ in a similar manner. The following lemma shows that f and f ′ cannot differ in too many coordinates.
Lemma 13. Let D denote the set of indices j for which f (e j ) = f ′ (e j ). Then |D| ≤ d/2.
Proof. Assume for the sake of contradiction that |D| > d/2. For cluster O r , let D r denote the set of indices j such that e j ∈ O r △O ′ r . Observe that (v r ) j and (v ′ r ) j differ (in absolute value) by 1/m. Therefore, Summing over r = 1, . . . , k, we get where the last inequality follows from Cauchy-Schwarz, and the observation that r |D r | = 2|D| > d. Using Lemma 12, we see that assuming m is a large enough constant. But this contradicts Lemma 12.

⊓ ⊔
The above lemma shows that the number of clusterings in C satisfying condition (6) is small.
Proof. Fix a clustering O = {O 1 , . . . , O r } satisfying condition (6), and let f be the corresponding assignment function. How many assignment functions (corresponding to a clustering in C) can differ from f in at most d/2 coordinates ? There are at most km km/2 ways of choosing the coordinates in which the two functions differ. Consider a fixed choice of such coordinates, and say there are d r coordinates corresponding to points in O r . Let d ′ denote r d r (and so, d ′ ≤ d/2). Now, we need to partition these coordinates into sets of size d 1 , . . . , d k (note that f ′ corresponds to a clustering where all clusters are of equal size). The number of possibilities here is d ′ ! d 1 !...d k ! , which is at most Recall that we want L to contain enough elements such that for at least half of the clusterings in C, condition (6) is satisfied with respect to some set of centers in L. Therefore, Corollary 3 and (5) imply that This concludes the proof of Theorem 2.

Extension to the list k-median problem
The setting for the list k-median problem is same as that for the list k-means problem, except for the fact that distances are measured using the Euclidean norm (instead of the square of the Euclidean norm). As before, for a set C of k centers, and a clustering O = {O 1 , . . . , O k } of a set of points X, define cost C (O) as the minimum, over all permutations π of C, of k i=1 x∈O i ||x − c π(i) ||. Define opt k (O), Φ C (X) analogously. For a set of points X, let ∆(X) denote the optimal 1-median cost of X, i.e., min c∈R d x∈X ||x − c||. We no longer have an analogue of Fact 1 -for a set of points X, if c ⋆ denotes the optimal center with respect to the 1-median objective, and c is a point such that Φ c (X) ≤ (1 + ε) · Φ c ⋆ (X), it is possible that ||c − c ⋆ || is large. This also implies that there is no analogue of the Lemma 1. However, instead of the approximate triangle inequality (Fact 2), we get triangle inequality in the Euclidean metric.
We shall use a result of Kumar et al. [KSS10], which gives an alternative to Lemma 1, although it outputs several candidate centers instead of just the mean of a random sample.
Lemma 14 (Theorem 5.4 [KSS10]). Given a random sample (with replacement) R of size 1 ε 4 from a set of points X ∈ R d , there is a procedure construct(R), which outputs a set core(R) of size 2 (1/ε) O(1) such that the following event happens with probability at least 1/2 : there is at least one point c ∈ core(R) such that Φ c (X) ≤ (1 + ε) · ∆(X). The time taken by the procedure construct(R) Now we explain the changes needed in the algorithm and the analysis. Given a set of points X and another set of points C, D-sampling from X w.r.t. C samples a point x ∈ X with probability proportional to Φ C (x), i.e., min c∈C ||c − x||.

The algorithm
The algorithm is the same as that in Figure 2.1, except for some minor changes in the procedure Sample-Centers, and changes in the values of the various parameters. The parameters α and β in the procedure List-k-median are large enough constants. We briefly describe the changes in the procedure Sample-Centers. In Step 2(a), we sample the multi-set S using D-sampling w.r.t C. We replace Step 2(d) by the following: for all subsets T ⊂ S ′ of size M , and for all elements c ∈ core(T ) (i) C ← C ∪ {c}, (ii) Sample-centers(X, k, ε, i + 1, C). Recall that core(T ) is the set guaranteed by Lemma 14. In other words, unlike for the k-means setting, where we could just work with the mean of T , we now need to try out all the elements in core(T ). Figure 5.1, gives a detailed description of the algorithm.

Analysis
The analysis proceeds along the same lines as in Section 3, and we would again like to prove the induction hypothesis P (i). We use the same notation as in Section 3, and define Cases I and II analogously. Consider Case I first. Proof of Lemma 2 remains unchanged. The set O Proof of Lemma 5 also changes as follows: let m ′′ be as in the statement of this lemma. Then, Rest of the arguments remain unchanged (we use Lemma 14 instead of Lemma 1). Now we consider Case II. We redefine the parameter R as We have the following version of Lemma 8: where n denotes |O ⋆ i |. Finally, let m ′′ be as in the statement of Lemma 9. Then, Rest of the arguments go through without any changes.

Conclusion
We formulated the list k-means problem and gave nearly tight upper and lower bounds on the size of the list of candidate centers. We also obtained an algorithm for the constrained k-means problem getting a significant improvement over the previous results of Ding and Xu [DX15]. Furthermore, we show how our techniques generalize for the corresponding k-median problems. We would also like to point out that our techniques generalize for settings that involve non-Euclidean distance measures. After going through the analysis of our algorithm, it is not difficult to show that the only properties that are used in the analysis are: (i) Symmetry of the distance measure (used implicitly) (ii) (Approximate) Triangle Inequality: Fact 2 (iii) Centroid property: Fact 1 (iv) Sampling property: Lemma 1 The analysis holds even for some approximate versions of the above properties. For instance, for the k-median problem we were able to use Lemma 14 instead of Lemma 1 (i.e., the sampling property). Also, we were able to work without the centroid property since for the k-median problem the distances follow the exact triangle inequality instead of the approximate version (i.e., Fact 2). We note that there are a number of clustering problems in machine learning that are modeled as k-median problem over distance measures that follow the above properties in some approximate sense. Mahalanobis distance and µ-similar Bregman divergence are two examples of such distance measures. Our results can be very easily extended for the k-median problem over such distance measures 4 .