Question
Algorithms question in Java : Do not use built-in functions or classes of JAVA. This question is designed similarly to a job interview. First,
Algorithms question in Java: Do not use built-in functions or classes of JAVA.
This question is designed similarly to a job interview. First, we will introduce a problem. You then
need to apply critical thinking, design a solution, evaluate the solution (Big-O), then improve it if needed.
Lastly, you will implement your solution.
detailed comments will be much appreciated, thanks!
# In the instructions, there is a mistake. The methods setLeft, and setRight have 2 input arguments each (of Worker type). In the instructions, it is stated that they have one input argument p. For example, for the setLeft method, 2 input arguments of the Worker type are required, one as the root and one as the left child.
# The signature of the methods described in the tables of instructions includes the word "static". Implementing the methods as static is not required, and only the name of the method needs to be the exact same.
# For the SetLeft method, 2 input arguments of the Worker type are required. Just be careful that the root here does not refer to the root of the tree and rather the root of the sub-tree you are adding the child to.
# The idea is that you should have a general tree with many children but for simplicity of it, we are using only binary tree. setRight, setLeft methods Do not need to return anything. For size, it should return the number of nodes in the tree --- n
Part2: General Tree In this part, you have been asked to create a simple ADT tree. A company asked you to create a tree like the following: RD Eng 140 110 CEO 100 HR Relation Hiring 20 As you can see you need the following: a Worker.java class, that only have name and salary attributes, you should have a constructor for this class. . You need a Binary TREE ADT class to hold the tree. . The Tree elements can have no children or many children (0,1,2,3,...) A binary tree ADT needs the following Name of the method Possible signature of the method Explanation Constructor Optional root() public static Worker root() public static Worker parent(Worker p) public static Worker left (Worker p) public static Worker right(Worker p) public static Worker setLeft(Worker p) public static Worker setRight(Worker Returns the root of the tree (or null if empty). [Returns object of Worker Type] Return the parent of worker p Return the left child of worker p Return the right child of worker p Set the left child of worker p set the right child of worker p parent(p) left(p) right(p) setLeft(p) setRight p) size() Return the size Example You need to also write a method to print the tree (nothing fancy!!) You may do it in-order, preorder,... Last part, create a main create the workers with their name and salary Add them to the tree similar to image, remember to use setLeft and setRight Lastly use your print and print the tree
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