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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 14RQ
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT