posted 19 years ago
Hi,
I'm playing around with binary trees at the minute and having one of those periods where I am wondering whether I have been lobotomised in my sleep. I'm trying to think of algorithms for removing an element from a binary tree. At the minute all I can come up with is this:
Case: node is an internal node.
1. Search for the node ( left subtree < value, right subtree > value)
2. (if !=null) Connect the right subtree of node to node's parent in place of node.
3. Keep a reference, temp, to the left subtree of node.right and reconnect
the left subtree of node as the left subtree of node.right.
4. Add() each of the nodes in temp to node.right.
5. node=null.
Does anyone know of a more efficient general algorithm?
Regards,
Kenny