Skip to main content
ICT
Lesson AB30 - Binary Search Trees
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT AB30.2 page 14 of 15

Binary Search Tree (continued)

Assignment:

  1. Add the following methods to your Binary Search Tree class from the previous Lab Assignment AB30.1.

    1. public Object find(Comparable target)
    2. private Object findHelper(TreeNode root, Comparable target)
    3. public void delete(Comparable target)
    4. private TreeNode deleteHelper(TreeNode node, Comparable target)

  2. However, you are required to code the two-child case for deletion as a mirror image of the solution described in Section B.7 of the lesson. Change the deleteTargetNode method to deal with the two-child case as follows:

    1. Position marker to access the node with the smallest value in the right subtree. This is the leftmost node in the right subtree.

    2. Copy the contents of the left child of marker and set it as the current value.

    3. Delete the smallest value from the left subtree. Reattach the left subtree to maintain an ordered tree.

  3. Test your code and solve the following sequence of run output steps:

    1. Load the file from disk (file20.txt).
    2. Print the tree.
    3. Print the number of nodes in the tree.
    4. Search for Id values specified by your teacher. Print out the Id and Inv response in column form.
    5. Delete the Id values specified by your teacher.
    6. Print the tree again.
    7. Print the number of nodes in the tree.

Instructions:

  1. Turn in your source code for the entire program and the run output described above.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.