26

I was going through the k-means Wikipedia page. Based on the algorithm, I think the complexity is O(n*k*i) (n = total elements, k = number of cluster iteration)

So can someone explain me this statement from Wikipedia and how is this NP hard?

If k and d (the dimension) are fixed, the problem can be exactly solved in time O(ndk+1 log n), where n is the number of entities to be clustered.

nbro
  • 15,395
  • 32
  • 113
  • 196
parallel
  • 303
  • 1
  • 3
  • 9

2 Answers2

42

It depends on what you call k-means.

The problem of finding the global optimum of the k-means objective function

enter image description here

is NP-hard, where Si is the cluster i (and there are k clusters), xj is the d-dimensional point in cluster Si and μi is the centroid (average of the points) of cluster Si.

However, running a fixed number t of iterations of the standard algorithm takes only O(t*k*n*d), for n (d-dimensional) points, where kis the number of centroids (or clusters). This what practical implementations do (often with random restarts between the iterations).

The standard algorithm only approximates a local optimum of the above function, and so do all the k-means algorithms that I've seen.

nbro
  • 15,395
  • 32
  • 113
  • 196
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1

The problem is NP-Hard because there is another well known NP hard problem that can be reduced to (planar) k-means problem. Have a look at the paper The Planar k-means Problem is NP-hard (by Mahajan et al.) for more info.

nbro
  • 15,395
  • 32
  • 113
  • 196
Trect
  • 2,759
  • 2
  • 30
  • 35