Center of a graph

后端 未结 3 1133
天涯浪人
天涯浪人 2021-01-06 14:02

Given an unoriented tree with weightless edges with N vertices and N-1 edges and a number K find K nodes so that every node from a tree is within S distance of at least one

相关标签:
3条回答
  • 2021-01-06 14:38

    For me it looks like a clustering problem. Try it with the k-Means (wikipedia) algorithm where k equals to your K. Since you have a tree and all vertices are connected, you can use as distance measurement the distance/number of edges between your vertices. When the algorithm converts you get the K nodes which should be found. Then you can determine S by iterating through all k clusters. There you calculate the maximum distance for every node in the cluster to the center node. And the overall max should be S.

    Update: But actually I see that the k-means algorithm does not produce a global optimum, so this algorithm wouldn't also produce the best result ...

    0 讨论(0)
  • 2021-01-06 14:41

    This problem is called p-center, and you can find several papers online about it such as this. It is indeed NP for general graphs, but polynomial on trees, both weighted and unweighted.

    0 讨论(0)
  • 2021-01-06 14:46

    You say N nodes and N-1 vertices so your graph is a tree. You are actually looking for a connected K-subset of nodes minimizing the longest edge.

    A polynomial algorithm may be: Sort all your edges increasing distance. Then loop on edges:

    • if none of the 2 nodes are in a group, create a new group.
    • else if one node is in 1 existing goup, add the other to the group
    • else both nodes are in 2 different groups, then fuse the groups

    When a group reach K, break the loop and you have your connected K-subset.

    Nevertheless, you have to note that your group can contain more than K nodes. You can imagine the problem of having 4 nodes, closed two by two. There would be no exact 3-subset solution of your problem.

    0 讨论(0)
提交回复
热议问题