COL 106: Assignment 2

Due Date : February 17, 2019

Storing hierarchical structure of a company

We want to maintain the list of employees in a company. We will be concerned with two quantities associated with each employee in the company -- name of the employee (you can assume no two employees in the company have the same name), and the level of the employee. The level denotes where the person stands in the hierarchy. Level 1 denotes the highest post in the company (say the CEO), level 2 comes below level 1 and so on. There is only 1 person at level 1, but there can be several employees at level i > 1. Each level i employee works under a level i-1 employee, which is his/her immediate boss. Given an employee A, we can form a sequence of employees A',A'', A''', ... where A works under A', A' works under A'', and so on. We say that each employee in A',A'', A''',... is a boss of A. We would like to implement a suitable tree data-structure so that we can implement the following operations : Write a program which implements such a data-structure. Credit will be given to choice of proper data-structures and efficiency. For example, in the second operation above, one should not just search the entire tree to look for the name of the employee S'. Your program should also catch errors, for example if in the first operation above, there is no employee with name S', then it should say it is an error. Use the notions of exceptions in JAVA to implement error checking.

Input format: first we specify the initial set of employees as follows:
Num_Employees
EmployeeName1     BossName1
EmployeeName1     BossName1
....

After this the file will contain a sequence of operations specified as follows (call the above operations 0,1,2,3 in the order they are described above):
Num_Commands
Query_type1 Employee1 Employee2 (where Query_Type1 is 0,1,2,3. Note that if Query_type is 3, then no other arguments are needed).