Binary Trees
Binary Trees
Two kinds:
depth-first traversal
breadth-first traversal
Traversals
There are three different types of depth-first
traversals, :
is not in a tree;
is a leaf;
has only one child;
has two children.
If toDelete is not in the tree, there is nothing to delete. If toDelete node has
only one child the procedure of deletion is identical to deleting a node from a
linked list - we just bypass that node being deleted
Deletion of an internal node with two children is less straightforward. If we
delete such a node, we split a tree into two subtrees and therefore, some
children of the internal node won't be accessible after deletion. In the picture
below we delete 8:
Deletion
• Deletion strategy is the following: replace
the node being deleted with the largest
node in the left subtree and then delete
that largest node. By symmetry, the node
being deleted can be swapped with the
smallest node is the right subtree.
• For in depth information, you may watch this video from
Youtube.com:
• https://www.youtube.com/watch?v=9oTV7fDEaCY