Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Java code for following question and explain if you can! Part2: General Tree In this part, you have been asked to create a

Please use Java code for following question and explain if you can!

image text in transcribed
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: As you can see you need the following: a a Workerjava class, that only have name and salary attributes, you should have a constructor for this class. a You need a Binary TREE ADT class to hold the tree. a The Tree elements can have no children or many children (0,1,2,3,...) a A binary tree ADT needs the following Name of the Possible' signature of the method method Constmctor Optional root() public static Worker root() Returns the root of the tree {or null ifempty). [Returns object of Worker Type] public static Worker parenthorker p) Return the parent of worker p public static Worker left(Worker p) Return the left child of worker p public static Worker rightiWorker p) Return the right child of worker p public static Worker setLeft(Worker p) Set the left child of worker p public static Worker 5etRight(Worker set the right child of worker p Pl - You need to also write a method to print the tree (nothing fancy! !) 0 You may do it in-order, preorder,... a Last part, create a main 0 create the workers with their name and salary 0 Add them to the tree similar to image, remember to use setLeft and setRight 0 Lastly use your print and print the tree Part 3: Analysis 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? 4. Is there a relationship with the height of a tree and time complexity

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

In 2004 what base ball team ended an 85 year championship drought?

Answered: 1 week ago

Question

On what date was the declaration of independence signed?

Answered: 1 week ago

Question

What achievement is Amelia ear heart best known for?

Answered: 1 week ago

Question

The structure of liberty was a gift from what European country?

Answered: 1 week ago

Question

What was the first US state admitted to the union?

Answered: 1 week ago