Find Find 13:
Find Min and Find Max Find Min: Find Max:
Insert Insert 13:
Insert Insert 13:
Delete Delete 13:
Delete Delete 13: No child (leaf) Deleted directly
Delete Delete 16:
Delete Delete 16: child Splice out node
Delete Delete 16: tree re-drawn for proper level layout
Delete Delete 5:
Delete Delete 5: children Splice out min node of right sub-tree
Delete Delete 5: Orphaned node’s key needs to replace key in node to be deleted
Delete Delete 5:
The Effect of the Input Sequence on the Shape of BSTs The order in which keys arrive and are inserted impacts the shape of the resulting tree The shape of the tree determines performance All input sequences need to be accommodated in a well behaving BST data structure Deletions also affect tree shape (performance)
Unbalanced BST Insert the numbers 1, 2, 3, 4, 5, 6, 7 into empty BST: 2 2 Input sequence degenerated the tree into a linked list (linear) data structure
Unbalanced BST Insert the numbers 7, 6, 5, 4, 3, 2, 1 into empty BST: 2 Tree is linear again
Unbalanced BST Insert the numbers 4, 3, 5, 2, 6, 1, 7 into empty BST: 2 Tree is still very unbalanced (near-linear)
Unbalanced BST Insert the numbers 1, 3, 2, 5, 4, 7, 6, 8 into empty BST: 4 Tree is still very unbalanced (height is linear)
Balanced BST Insert the numbers 4, 2, 6, 1, 3, 5, 7 into empty BST: Tree is “dense” with a low height