22.01.2015 Views

Refined Buneman Trees

Refined Buneman Trees

Refined Buneman Trees

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 6.7: An example a node which is a valid insertion node (green), and one<br />

which is not a valid insertion node (red). A node is a valid insertion node if all<br />

subtrees of that node contain only nodes from U (blue nodes) or from V (black<br />

nodes), but not from both.<br />

• w u = |U|∨w v < |V | — in this case, we know that the subtree of w given<br />

by its parent edge only contains elements from V . If we assume that we<br />

found w in a bottom–up traversal, and that w is the first node with the<br />

property w u = |U|, w mustbethenodewearelookingfor.Itcannotbea<br />

node below w, since that node would have a subtree with mixed u’s and<br />

v’s, i.e. the subtree given by its parent edge.<br />

• w u < |U|∨w v = |V | — similar argument as in the case w u = |U|∨w v < |V |.<br />

• w u = |U|∨w v = |V | — in this case, the node we chose at randon to be<br />

the intermediate root, must be the insertion node we are looking for.<br />

Counting can be done in linear time since we only need to visit each node<br />

once, and there are at most 2n − 2 nodes in an unrooted tree with n leaves.<br />

Searching can afterwards be done in time O(n), visiting each node exactly once<br />

and testing each node in constant time until we find the one we are looking for.<br />

6.2.2 Delete<br />

The delete operation is somewhat similar to the insert operation. Again we<br />

start out by counting U’s and V ’s in a bottom-up fashion. The edge e we are<br />

looking for has the property that its destination node is a node w, whereall<br />

subtrees of w contain only elements from U or from V , but not both. In other<br />

words, w isthenodewhereu w = |U| and v w = 0 or vice versa. And, once the<br />

node w is found, the edge e has also been found, since we can keep track of both<br />

48

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!