In this part, you have been asked to create a simple ADT tree. A company asked...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this part, you have been asked to create a simple ADT tree. A company asked you to create a tree like the following: 120 RD Eng 140 110 CEO 100 HR 77 Relation Hiring 20 22 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 root() public static Worker root() parent(p) left(p) right(p) setLeft(p) setRight size() 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 p) Optional 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 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 1. What is the time complexity of adding new element to a binary tree? 2. What if we used general tree (0 to many children), what would be the time complexity of adding new element? Would the number of children have any effect on it? 3. What is the worst case for adding a new element to a general tree? Is there a relationship with the height of a tree and time complexity? In this part, you have been asked to create a simple ADT tree. A company asked you to create a tree like the following: 120 RD Eng 140 110 CEO 100 HR 77 Relation Hiring 20 22 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 root() public static Worker root() parent(p) left(p) right(p) setLeft(p) setRight size() 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 p) Optional 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 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 1. What is the time complexity of adding new element to a binary tree? 2. What if we used general tree (0 to many children), what would be the time complexity of adding new element? Would the number of children have any effect on it? 3. What is the worst case for adding a new element to a general tree? Is there a relationship with the height of a tree and time complexity?
Expert Answer:
Posted Date:
Students also viewed these databases questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
The engines of most rockets produce a constant thrust (forward force). However, when a rocket is fired, its acceleration increases with time as the engine continues to operate. Is this situation a...
-
Show that For some (x). [From Eq. (3.3), Considering the interpolation polynomial of degree n + 1 on x0, x1, . . . , xn, x, we have f (x) = Pn+1(x) = Pn(x) + f [x0, x1, . . . , xn, x](x x0) (x ...
-
The EU imports coconut from Mexico and from former colonies in the Caribbean. For the coconut imported from Mexico, a tariff of 10% applies, but for coconut imported from the Caribbean states, no...
-
When the hand is holding the 5-lb stone, the humerus H, assumed to be smooth, exerts normal forces F C and F A on the radius C and ulna A, respectively, as shown. If the smallest cross-sectional area...
-
Farley Company identifies the following items for possible inclusion in the taking of a physical inventory. Indicate whether each item should be included or excluded from the inventory taking. (a)...
-
Tamarisco A partir del 1 de enero de 2025, Industries tena una patente registrada en sus libros. Esta patente tena un valor contable de 480.000 dlares y una vida til restante de 8 aos. Durante 2025,...
-
Consider a disc and a hoop of identical masses and moment of inertia about their respective diameters. T'disc The ratio of their radii i.e. O2:1 Thoop is
-
What is the difference between constitutional law and domestic law?
-
What are the 4 sources of constitutional law and their significance? (Canada)
-
How do endocrine disorders, such as diabetes mellitus, hyperthyroidism, and hypopituitarism, arise from dysregulation of hormone synthesis, secretion, or receptor signaling, and what are the...
-
describe the legal concept of constitutionalism as it is in constitutional law ?
-
Explain the sources of each type of law and provide examples of each: constitutional law, statutory law, common law.
-
Using the knowledge@wharton site, review several articles and select one that showcases an authentic, transformational, or servant leader. Take a moment to scroll through the articles to find one...
-
The trade-off theory relies on the threat of financial distress. But why should a public corporation ever have to land in financial distress? According to the theory, the firm should operate at the...
-
Draw a class diagram for resource rental pattern and its installation for library service by using analogy approach.
-
What is Fowlers account pattern? Explain with the help of a diagram.
-
Draw a class diagram for account with entry pattern.
Study smarter with the SolutionInn App