A
Ashwin Kumar
I have the following problem for my class assignment due tomorrow and
I am kind of stuck and unable to think of a viable solution to this
problem. Any help will be appreciated (like pseudo code)
Thanks
Ash
An array is being used to represent an organizational hierarchy. This
is
done by using the array subscript to map to the employee-id and the
value in
each element to represent the employee-id of the supervisor of the
employee.
For example the first element in the array maps to the supervisor of
employee-id 1, the second element maps to the supervisor of employee
id
2.
The corresponding value for the top person in the organization is set
to -1.
For example the following array ?
7
5
7
10
-1
7
5
2
2
5
translates to the following hierarchical structure -
· employee 5 is the top boss
· employees 2, 7, and 10 report to employee 5
· employees 8 and 9 report to employee 2
· employees 1, 3 and 6 report to employee 7
· employee 4 reports to employee 10
The following diagram represents the organization structure
5
+ --- 2
| + --- 8
| + --- 9
|
+ --- 7
| + --- 1
| + --- 3
| + --- 6
|
+ --- 10
+ --- 4
5 is at level 1 in the organization.
2, 7 and 10 are at level 2
1, 3, 4, 6, 8, 9 are at level 3
Given an array of size N (the employee-ids being 1 to N), write a
program to
find the number of people in level L, where the top person in the
organization is at level 1.
I am kind of stuck and unable to think of a viable solution to this
problem. Any help will be appreciated (like pseudo code)
Thanks
Ash
An array is being used to represent an organizational hierarchy. This
is
done by using the array subscript to map to the employee-id and the
value in
each element to represent the employee-id of the supervisor of the
employee.
For example the first element in the array maps to the supervisor of
employee-id 1, the second element maps to the supervisor of employee
id
2.
The corresponding value for the top person in the organization is set
to -1.
For example the following array ?
7
5
7
10
-1
7
5
2
2
5
translates to the following hierarchical structure -
· employee 5 is the top boss
· employees 2, 7, and 10 report to employee 5
· employees 8 and 9 report to employee 2
· employees 1, 3 and 6 report to employee 7
· employee 4 reports to employee 10
The following diagram represents the organization structure
5
+ --- 2
| + --- 8
| + --- 9
|
+ --- 7
| + --- 1
| + --- 3
| + --- 6
|
+ --- 10
+ --- 4
5 is at level 1 in the organization.
2, 7 and 10 are at level 2
1, 3, 4, 6, 8, 9 are at level 3
Given an array of size N (the employee-ids being 1 to N), write a
program to
find the number of people in level L, where the top person in the
organization is at level 1.