1. Create a Java program that prompts the user the initial choices for the Binary Search Tree a. User chooses 1: Insert, User chooses 2: Delete, User chooses 3: Show Binary Tree, User chooses 4: Exit Program   2. Insertion in a tree should be such that it obeys the main properties of the binary search tree. The basic algorithm should be: a. If the node to be inserted is greater than the existing root, move down a level through the right pointer of the root. b. If the node to be inserted is lesser than the existing root, move down a level through the left pointer of the root. c. Repeat this process for all nodes till the leaves are reached. d. Insert the node as the left or right pointer for the leaf (based on its value - if it is smaller than the leaf, it should be inserted as the left pointer; if it is larger than the leaf, it should be inserted as the right pointer)   3. Deletion is a bit more complicated than insertion because it varies depending on the node that needs to be deleted from the tree. a. If the node has no children (that is, it is a leaf) - it can simply be deleted from the tree. b. If the node has one child, simply delete the node and move the child up to replace it. c. If the node has two children, it becomes a little tricky. We need to find the node which has the smallest value in the right subtree (among the elements that have a greater value than the node to be deleted) for the node and use that to replace the deleted node. (Note that the smallest value in the right subtree is the node that comes immediately after the node to be deleted, implying that it is the inorder successor for the node to be deleted). If the user chooses to delete an element from the Binary Search Tree: a. Display the elements in the binary tree b. Prompt the user to enter an element to be deleted. c. After entering a number to be deleted, show the updated elements contained in the binary tree. 4. If the user will choose: Show Binary Search Tree your output should look

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1. Create a Java program that prompts the user the initial choices for the Binary Search Tree
a. User chooses

1: Insert, User chooses

2: Delete, User chooses

3: Show Binary
Tree, User chooses

4: Exit Program

 

2. Insertion in a tree should be such that it obeys the main properties of the binary search
tree. The basic algorithm should be:
a. If the node to be inserted is greater than the existing root, move down a level
through the right pointer of the root.
b. If the node to be inserted is lesser than the existing root, move down a level
through the left pointer of the root.
c. Repeat this process for all nodes till the leaves are reached.
d. Insert the node as the left or right pointer for the leaf (based on its value - if it is
smaller than the leaf, it should be inserted as the left pointer; if it is larger than the
leaf, it should be inserted as the right pointer)

 

3. Deletion is a bit more complicated than insertion because it varies depending on the node
that needs to be deleted from the tree.
a. If the node has no children (that is, it is a leaf) - it can simply be deleted from the
tree.
b. If the node has one child, simply delete the node and move the child up to replace
it.
c. If the node has two children, it becomes a little tricky. We need to find the node
which has the smallest value in the right subtree (among the elements that have a
greater value than the node to be deleted) for the node and use that to replace the
deleted node. (Note that the smallest value in the right subtree is the node that
comes immediately after the node to be deleted, implying that it is the inorder
successor for the node to be deleted).

If the user chooses to delete an element from the Binary Search Tree:
a. Display the elements in the binary tree
b. Prompt the user to enter an element to be deleted.
c. After entering a number to be deleted, show the updated elements contained in
the binary tree.

4. If the user will choose: Show Binary Search Tree your output should look like this:
Sample Output:

 

Sample Output:
1. Insert
2. Delete
3. Show Binary Tree
4. Exit Program
Write your input: 1
Write the elements for insertion delimited by spaces(ex: 2 1 4 3 5).
Transcribed Image Text:Sample Output: 1. Insert 2. Delete 3. Show Binary Tree 4. Exit Program Write your input: 1 Write the elements for insertion delimited by spaces(ex: 2 1 4 3 5).
Write your input: 3
Binary Search Tree
8
/ \
59
3 7
Transcribed Image Text:Write your input: 3 Binary Search Tree 8 / \ 59 3 7
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binomial Heap
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education