Help with Array programming in Java

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.
 
T

Tony Morris

If are not competent enough to manage your time or solve your own problems,
you have no chance of surviving in this industry.

For the benefit of myself, my colleagues and this industry in general, I
wish failure upon you.
 
S

Sudsy

Tony said:
If are not competent enough to manage your time or solve your own problems,
you have no chance of surviving in this industry.

For the benefit of myself, my colleagues and this industry in general, I
wish failure upon you.

Touche!
Couldn't agree more. Thanks for voicing an opinion many of us are too
ovine (read: sheepish) to state out loud.
ps. Don't you love it when school is in session and we get all these
lovely homework questions and the disguises?
 
G

Grant Wagner

Sudsy said:
Touche!
Couldn't agree more. Thanks for voicing an opinion many of us are too
ovine (read: sheepish) to state out loud.

While I agree emotionally with the sentiment, it might be a bit misdirected. He
_may_ be a business or economics major who has to take a programming course, and
it simply isn't his forte. That said, if he is having trouble in a subject he has
no interest in, and does not understand terribly well, he should work that much
harder to understand it, or obtain help locally. I'm sure there are any number of
computer "geeks" willing to provide some assistance for a reasonable tutoring fee
(or free beer).
ps. Don't you love it when school is in session and we get all these
lovely homework questions and the disguises?

At least this OP was honest enough to come right out and ask someone to do his
homework for him. Too many try the "I have to solve this problem for a project at
work" and the problem is so obviously artificial that it simply must be homework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How do I make this in C with for loop 3
Help with code 0
Minimum Total Difficulty 0
C Programming functions 2
Help with array 4
Help with my responsive home page 2
Problem with codewars. 5
Dynamic programming 3

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top