Delete a node with two children
transcript
A bank app closes an account. Its number must leave the tree. Its node has two children. Two children cannot share one link. So who takes its place?
The successor is the next larger code. Go to the right child, then left as far as you can. Copy its code into the node.
Delete eight, the top of the street tree. The successor is ten. Ten moves to the top. The old node of ten has a right child, fourteen. It takes over.
Now forget to remove the old node. The code ten is now in two places. The tree now holds a duplicate. A search would find two.
Print the tree in preorder before the delete. Keep the list. Print it again after the delete. Look for a code that appears twice, or one that went missing.
Copy the successor's code up. Remove its old node. Full breakdown in the lecture.