Answered step by step
Verified Expert Solution
Question
1 Approved Answer
NO PLAGIARISM PLEASE ALL NEE TO BE YOUR OWN WRITTEN CODE You may use any programming language you are comfortable with. I strongly recommend not
NO PLAGIARISM PLEASE ALL NEE TO BE YOUR OWN WRITTEN CODE You may use any programming language you are comfortable with. I strongly recommend not using C C Java, C#
Visual Basic are all good choices Part : BinarySearchTree Class
Interface
For this project, you are also to create a wrapper BinarySearchTree Class. In reality, this class doesn't do that much. The
class simply starts recursion of the root itself.
Naturally, there is some logic needed to handle an null root, but that is just a few basic ifstatements.
Pseudocodeprivate Node root if root is null else end if and so on
end classPart : Input File Format
A number of test files will be provided to you for testing your code. The format is designed to be easy to read in multiple
programming languages. You need to use the classes, built in your programming language, to read the source files.
File Format
The first line of the data contains the total digits in the key. You might want to save this value I can be used to separate the
key from the value using the substring function found in most programming languagesKey Value
Key n Value nThe following is one of the most basic test files on the website.
File: california.txt
Sacramento State
Apple Founded
Transcontinental Railroad
Tesla Founded
Gold Rush Begins
California Flag officially adopted
California joins the US
Intel Founded
Overview
For this assignment, you are to create a very basic Binary Search Tree BST It will read data from a file which are a slightly modified version from Project # Once loaded, your BST can print the tree as both a sorted list and an ASCIIart tree.
You don't have to balance the tree. In fact, don't even try it yet. Though, to be honest, a redblack tree as long as you do the leftchild rotate trick when adding isn't all that hard.
Part : Node Class
Interface
In recursively defined structures, like trees, all the coding and complexity is found in the recursive structure itself. So for this assignment, all the logic will be found in the Node Class.
The Tree Class, which is defined in the handout below, merely starts recursion on the root.
tableNode int key, string valueConstructor.Nodeleft,Noderight,intkey,The key to find the value.stringvalue,The value that the node contains.stringtoStringString label, int indentReturns a string of the tree's structure. Please see below.tablevoidaddint key, string valuetableAdds the key to the correct position in the BST If the keyalready exists, do nothing. Pseudocode
Your Node class should be as follows:public int keypublic Node left. All your methods go here
end classAdding to the Tree
To add a key, you will write a recursive method that will either recurse to the left or right depending on the key. Whenever it
can no longer recurse left or right, a new node is simply added.if key this node's key then create a new left child for this node. left.addkey valueend if if right is null else end ifend method Creating the ASCII Tree
The method will recursively generate a string for the structure of the tree. One node will be displayed per line. In the examples
below, Im using spaces followed by label that identifies each as either L for left and R for right. You can use spaces,
dashes, etc... You can use any size of indentation you like etc...
Notice that the current node "this" is concatenated before the left and right recursive calls. This is an example of an preorder
depthfirst traversal.Declare String resultresult label : if left isn't nullend if result right.toStringR indent return result
End FunctionThe following could be produced by this algorithm. Your version is can look a bit different if you wish, but you must indent your
lines and somehow indicate which is the left and right branch. Notice that this is the point of the label field.L: Transcontinental Railroad L: Bear Flag Revolt R: California Flag officially adopted L: Intel Founded
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