05-MoreBinaryTrees

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

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

View Full Document Right Arrow Icon
Binary Search Trees (continued)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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.
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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.
Background image of page 10
Image of page 11
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 Right Arrow Icon
Ask a homework question - tutors are online