title: how to merge tree nodes into one node
body: <p>Hopefully, my question is not duplicated.
  I would like to know if there exists such algorithm which merges some nodes in a tree to a new tree so the node in the new tree consists of some nodes in the old tree?</p>
  
  <p>In order to explain my idea, I drew a graph to explain the question.</p>
  
  <p>Input:  A original tree.</p>
  
  <p>Output: A new tree. There are  following conditions with which the new tree must be satisfied: </p>
  
  <ol>
  <li>The number of nodes in the new tree should be a fixed number <em>k</em>.</li>
  <li>Each node in the new tree must consists of nodes in the original tree.  For example, the node A in the second graph contains node 1,3, and 4 of the first graph. Node D in the secod graph contains nodes 9,12, and 13 in the first graph.</li>
  <li>if one node of the original tree is contained in a node of the new tree, it cannot appear in another node of the new tree.</li>
  <li>The nodes in the new tree are not necessarily have to be a subtree of the original tree. For example, node C in the second graph contains 6,7,and 10 of the first graph, It is not a subtree of the original graph. Because both node 6 and node 7 in the original graph connect to the nodes in the dotted area of A in the original tree, So they could be grouped in the node C of the second graph.</li>
  </ol>
  
  <p>Currently, I just want the original tree can be converted to a new tree that has a <em>K</em> number of nodes and meets above conditions. For a given tree, there are many solutions. For example, graph 3 and graph 4 illustrate another solution for the original tree. It also has 4 nodes.</p>
  
  <p><a href="https://i.stack.imgur.com/KfNfJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KfNfJ.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/bcc6e.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bcc6e.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/hrnOE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hrnOE.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/1IVz9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1IVz9.jpg" alt="enter image description here"></a></p>