throwaway_1234's blog

By throwaway_1234, history, 8 years ago, In English

I thought of this problem and I was wondering if there is any polynomial time solution?

Given a weighted tree of N nodes, pick K nodes such that sum of distances from each node to the nearest picked node is minimized.

For K = 1, the answer is the centroid of the tree. What about K > 1 ?

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I think you can binary search for the distance possible, and then use a greedy algorithm, where you take nodes as high as you can in the tree.

»
8 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Your problem (on general graphs) is called as "K-median". A quick search reveals that the problem on trees can be solved in O(KN2) time [1].

[1] Tamir, A. An O(pn2) algorithm for the p-median and related problems on tree graphs.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Thanks!

    The O(pn2) algorithms also solves for a much more general version of the problem (with weighted vertices and custom distance functions) so that's cool!