简体   繁体   中英

how do I reduce this spanning tree problem to np-completeness?

I have the following algorithmic problem:

If I have a graph G=(V,E), does G have a spanning tree with exactly k leaves? Leaves being a vertex with only one neighbor in the spanning tree. Also, i'm not looking for a minimum spanning tree, just a spanning tree.

TO sum up, a solution algortihm would take as inputs a graph G and a number k, and return either true or false, depending on whether G has a spanning tree of k leaves

Example: For this graph:

在此处输入图像描述

if k is 6, then my algorithm would output "True" because:

在此处输入图像描述

Now I am pretty sure that this problem is np-complete, so I need to perform a reduction from a know np-complete problem.

I just have no idea which problem, and how the reduction should look like, can you help out?

The Hamiltonian path problem is a special case of your problem - a spanning tree with exactly k = 2 leaves is a Hamiltonian path. Testing for the existence of one is NP-complete.

Not a real answer to your question, but you might want to try to simplify the graph before you go on board on those 1.x^N algorithms

Simplifying things (untested code ahead)

if (nodes.size() < K)
  return false;

Remove all nodes with only one edge as they are forced to be leaves.

while (nodes && nodes.front().edges.size() == 1) {
  nodes.erase(nodes.begin()); // updates one other node which could have 1 edge then.
  K--;
}

if (K < 0 || nodes.size() < K)
  return false;

Remove all nodes which have 2 edges and where removing one would disconnect the graph, connect the two nodes it connected to directly. It is not a bridge if there is any path from edge1 to edge2. O(N^2)

node = nodes.begin();
while (node->edges.size() == 2) {
  if (DisconnectingBrigde(node)) {
    edges = node->edges;
    node = nodes.erase(node); // returns next node
    nodes.addEgde(edges.front(), edges.back()); // connect the two parts
  } else
    node++; // next node
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM