Hi, Interviewer want to test the knowledge of design pattern of the candidate . we can use any DS to store Employee info like ArrayList ,Tree(Level by Level Trave.. is good option),or hash . This problem is related to Composite and Iterator pattern.
Thanks Yash On Aug 5, 10:09 am, Chonku <cho...@gmail.com> wrote: > We can store the employees as a list. Since each employee is managed by 1 > boss, we can store the pointer to boss in the child. > To calculate getCostToCompany(char* bossName), we can scan the list and look > for those records where bossName matches those employees who have boss with > <bossName>. This would bw O(n). To add a record, first we find the boss > pointer and then insert the record at the end of the list using the boss > pointer. > > > > On Thu, Aug 5, 2010 at 5:13 AM, Anand <anandut2...@gmail.com> wrote: > > As per the problem it seems to be that there is one root node (CEO) and > > all employees are child node. B'cos iin the question it is mentioned that > > each employee is led by only 1 person except for the CEO (who has no boss). > > > Correct me if I am wrong. > > > On Wed, Aug 4, 2010 at 4:32 PM, Gene <gene.ress...@gmail.com> wrote: > > >> This is a nice question for them because the idea is simple, but they > >> have given you a data structure that is not good for the problem. If > >> each employee records had a list of people the employee leads, it > >> would be trivially easy. But it doesn't. So in the interview you can > >> show how smart you are by discussing the pros and cons of defining a > >> parallel data structure (since you're apparently not allowed to change > >> this one) to contain child pointers. Or computing all the costs in a > >> single pass through the whole list of employees and updating these > >> appropriately as employees are added, deleted, get raises, etc. > > >> On Jul 27, 7:57 am, aparichith <vineelyalamar...@gmail.com> wrote: > >> > A company has many employees & each employee is led by only 1 person > >> > except for the CEO (who has no boss). The cost to the company of an > >> > employee is the sum of his salary plus the cost to the company of all > >> > the people led by him. Given is the following structure : > > >> > Employee > > >> > Data members: > > >> > Name > > >> > Salary > > >> > isBoss > > >> > nameOfBoss > > >> > Methods: > > >> > getSalary > > >> > getName > > >> > a) Define the class/structure > > >> > b) Write a function getCostToCompany() to calculate the cost to > >> > the company of an employee whose name is passed as a parameter to the > >> > function getCostToCompany() > > >> > public float getCostToCompany(String name) > > >> > Note: Don’t write any input functions such as main() & assume that the > >> > data structures have already been defined > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Algorithm Geeks" group. > >> To post to this group, send email to algoge...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/algogeeks?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algoge...@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.