Question: In recursively defined structures, like trees, all the coding ( and complexity ) is found in the recursive structure itself. So , for this assignment,
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.
public class Node
Nodeint key, string value Constructor.
Node left
Node right
int key The key to find the value.
string value The value that the node contains.
string toTreeString label, int indent Returns a string of the trees structure. Please see below.
String toSortedList Returns a string sorted by the key. Please see below.
void addint key, string value Adds the key to the correct position in the BST If the key
already exists, do nothing.
string findint key Finds a node with the key and returns its value. If the
node is not found, you can return an empty string.
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.
public class BinarySearchTree
BinarySearchTree Constructor.
Node root Private
string about Returns text about you the author of this class.
string toTree Returns a string of the trees structure.
It will start recursion from the root node with indent and a label of
"Root".
String toSortedList Returns a string sorted by the key. Please see below.
It will start recursion from the root node.
void addint key, String value Adds the key to the correct position in the BST If the key already
exists, do nothing.
string findint key Finds a node with the key and returns the value. If the node is not
found, you can return an empty string.
Binary Search Trees are extremely sensitive to the order that data is fed into them. In fact, once node is added, it's position in
the tree will never change. In the example below, I've added the same entries, but I have switched the position of the first two.
File: halloween calories txt
Tootsie Pop
M&Ms Fun size
Starburst Fun Size
Kit Kat Snack Size
Laffy Taffy
Snickers Fun Size
Nerds Mini Box
Hershey's Milk Chocolate Fun Size
Almond Joy Snack Size
END
Observe that, this minor change of order, has had a profound impact on the structure of the tree. The first key added will
always become the root. And it will remain the root.
: Tootsie Pop
L: Starburst Fun Size
L: Laffy Taffy
R: Nerds Mini Box
R: M&Ms fun size
L: Kit Kat Snack Size
R: Snickers Fun Size
L: Hershey's Milk Chocolate Fun Size
R: Almond Joy Snack Size
Can I ask for your help? In java Programming will it be alright to code that will result in halloween text file. Please include comments and picture of the result thank you.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
