Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Binary Search Trees with Lazy Deletion

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 Java program should prompt user with options to do one of the above routines.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define marketing.

Answered: 1 week ago

Question

What are the traditional marketing concepts? Explain.

Answered: 1 week ago

Question

Define Conventional Marketing.

Answered: 1 week ago

Question

Define Synchro Marketing.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago