Question
JAVA DATA STRUCTURES BST 1)A Binary Search Tree (BST) is a data structure that is used to store data in a sorted manner. It is
JAVA DATA STRUCTURES
BST
1)A Binary Search Tree (BST) is a data structure that is used to store data in a sorted manner. It is a type of self-balancing tree structure, with the root node being the first node and the left and right subtrees being the children. A BST can be used to store any type of data, including strings. In this example, we are creating a BST to store common names of animals and their corresponding genus scientific names. The BST will take two strings as parameters: a common name and a genus name. It will then output data related to the given parameters. For example, if the user inputs "dog" as the common name, the output should be "Canis" as its genus name. If no matching name is found in the BST, then the user input will be output as is. To implement this BST, we will need to create a method to insert the common name and corresponding genus name into the tree. This method should take two strings as parameters, the common name and genus name, and use the common name to order the tree. A name should go to the left if it is alphabetically before the current node's name, and to the right if it is after this node's name. Duplicate names should be ignored. We will also need a method to translate the common name to its genus name. This method should take a string (common name) and search for it recursively. If the name is not found, it should return null. If the common name is found, it should return its genus name. To illustrate the expected output, let's use the following mock data: commonName: GenusName: dog canis cat felis horse equus lion panthera cat felis If the user inputs "dog" as the common name, the output should be "Canis". If the user inputs "cat" as the common name, the output should be "Felis". If the user inputs "hippo" as the common name, the output should be "hippo" plus a relevant message if no match is found. In summary, a Binary Search Tree can be used to store common names of animals and their corresponding genus scientific names.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started