1
votes

In these slides (13) the deletion of a point in a kd-tree is described: It states that the left subtree can be swapped to be the right subtree, if the deleted node has only a left subtree. Then the minimum can be found and recursively be deleted (just as with a right subtree).

This is because kd-trees with equal keys for the current dimensions should be on the right.

My question: Why does the equal key point have to be the right children of the parent point? Also, what happens if my kd-tree algorithm returns a tree with an equal key point on the left?

For example: Assume the dataset (7,2), (7,4), (9,6) The resulting kd-tree would be (sorted with respect to one axis):

     (7,2)
    /     \ 
  (7,4)   (9,6)

Another source that states the same theory is this one (paragraph above Example 15.4.3)

Note that we can replace the node to be deleted with the least-valued node from the right subtree only if the right subtree exists. If it does not, then a suitable replacement must be found in the left subtree. Unfortunately, it is not satisfactory to replace N's record with the record having the greatest value for the discriminator in the left subtree, because this new value might be duplicated. If so, then we would have equal values for the discriminator in N's left subtree, which violates the ordering rules for the kd tree. Fortunately, there is a simple solution to the problem. We first move the left subtree of node N to become the right subtree (i.e., we simply swap the values of N's left and right child pointers). At this point, we proceed with the normal deletion process, replacing the record of N to be deleted with the record containing the least value of the discriminator from what is now N's right subtree.

Both refer to nodes that only have a left subtree but why would this be any different? Thanks!

1

1 Answers

1
votes

There is no hard and fast rule to have equal keys on right only. You can update that to left as well.

But doing this, you would also need update your algorithms of search and delete operations.

Have a look at these links:

https://www.geeksforgeeks.org/k-dimensional-tree/

https://www.geeksforgeeks.org/k-dimensional-tree-set-3-delete/