Implement K-means clustering with Map-Reduce
You can run a loop over $j\in\{1..k\}$:


Create a map that maps each point $x_i$ to itself if $x_i$ is nearest to the mean $m_j$, and to the zero vector otherwise:
$$x_i \rightarrow \begin{cases}(x_i, 1)  &amp; d(x_i, m_j) \le d(x_i, m_l),\ l\neq j \\ (0,0) &amp; \text{otherwise} \end{cases}$$
In the reduce stage, you would find the sums and counts:
$$(x_{i1}, c_1), (x_{i2}, c_2)\rightarrow(x_{i1}+x_{i2}, c_1+c_2)$$ 
You then divide the resulting sum by the total count.


Thus, for each iteration in the k-means algorithm you will need $k$ maps and $k$ reduces.