Question: Binary Search Trees with Lazy Deletion in Java Implement binary search tree class with lazy deletion that has TreeNode as nested class in Java. Design

Binary Search Trees with Lazy Deletion in Java

Implement binary search tree class with lazy deletion that has TreeNode as nested class in Java.

Design the class, TreeNode to have following class variables:

int key; // All Keys are in the range 1 to 99

TreeNode leftChild;

TreeNode rightChild;

boolean deleted;

Your program method must have routines to do the following operations.

1. insert

//Should insert a new element to a leaf node. If new element is aduplicatethen do nothing. If the new element is previously deleted one, then do not add other copy just mark the previous deleted as valid now

2. delete

//Should not remove the element from the tree. It should just mark the element as deleted.

Lazy deletion, meaning you will not be deleting the node but only mark it for deletion. It is ok to display the deleted node put an * before it to indicate it is deleted.

3. findMin

//Should return the minimum element, butif it is marked deleted return appropriate minimum

4. findMax

//Should return the maximumelement, butif it is marked deleted return appropriate maximum

5. contains

//Should return true if a particular element is in the tree and is not marked as deleted

6. In order tree Traversal

//Should print the in order traversal of the tree. Indicating with * symbol for elements that are marked deleted

7. Height ( returns the height of the tree)

//Return the height of the tree, count all the elements even the ones that are marked as deleted

8. No Of nodes ( returns number of nodes + number of deleted nodes)

//Return and print size of the tree, count all the elements even the ones that are marked as deleted. And also return the number of deleted elements.

The program should prompt user with options to do one of the above routines.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!