05-MoreBinaryTrees

# 05-MoreBinaryTrees - Binary Search Trees(continued Deletion from a BST Inserting into a BST is relatively simple when compared to deletion The

This preview shows pages 1–11. Sign up to view the full content.

Binary Search Trees (continued)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Deletion from a BST Inserting into a BST is relatively simple when ompared to deletion The reason is that insertions compared to deletion. The reason is that insertions always occur at the leaves. Deletion of leaf nodes also easy -- e interior (non- af) nodes are is also easy the interior (non leaf) nodes are what present difficulties. Hard to delete asy to delete Easy to delete
Deleting a Root Node The general problem is to determine what value hould replace the deleted value in the root of a should replace the deleted value in the root of a non-empty subtree (i.e., a non-leaf node). left 4 right ft 2 ft 6 left right left right left 1 right left 3 right left 5 right left 7 right

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
BST Conditions on the Replacement Value If the number 4 is deleted, it must be replaced ith a value that is greater than everything in the with a value that is greater than everything in the left subtree and not greater than anything in the right subtree. left 4 right ft 2 ft 6 left right left right left 1 right left 3 right left 5 right left 7 right
The Inorder Predecessor The inorder predecessor of a value is the largest alue that is less than it The inorder predecessor value that is less than it. The inorder predecessor in the below example is a suitable replacement. left 4 right ft 2 ft 6 left right left right The inorder predecessor f 4 left 1 right left 3 right left 5 right left 7 right of 4.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Inorder Predecessor The inorder predecessor of a value is the largest alue that is less than it The inorder predecessor value that is less than it. The inorder predecessor in the below example is a suitable replacement. left 3 right ft 2 ft 6 left right left right left 1 right left 5 right left 7 right
The Inorder Successor The inorder successor of a value is the smallest alue that is not less than it The inorder successor value that is not less than it. The inorder successor is a suitable replacement. left 4 right ft 2 ft 6 left right left right The inorder successor f 4 left 1 right left 3 right left 5 right left 7 right of 4.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Inorder Successor The inorder successor of a value is the smallest alue that is not less than it The inorder successor value that is not less than it. The inorder successor is a suitable replacement. left 5 right ft 2 ft 6 left right left right left 1 right left 3 right left 7 right
Datasets with Duplicates Suppose the dataset can have duplicates. If the BST ondition requires that keys in the left subtree are condition requires that keys in the left subtree are less than the key in the root, do we need to use the inorder predecessor, successor, or does it matter? left 4 right ft 2 ft 6 left right left right left 1 right left 3 right left 5 right left 7 right

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Datasets with Duplicates If the less-than inequality is used as the BST condi- on then the inorder successor must be used tion, then the inorder successor must be used.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/06/2010 for the course CS 2050 taught by Professor Uhlmann during the Fall '09 term at Missouri (Mizzou).

### Page1 / 75

05-MoreBinaryTrees - Binary Search Trees(continued Deletion from a BST Inserting into a BST is relatively simple when compared to deletion The

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online