You'll have someone starting from CEO, CTO, and multiple levels
Your data structure should be able to support the following operations efficiently
addInvididualContributor()
addManager()
deleteManager()
deleteIndividualContributor()
getEmployeeCountUnderAnEmployee()
getLeastCommonAncestorAcrossTwoEmployees()
Your data structure should be able to support the following operations efficiently
addInvididualContributor()
addManager()
deleteManager()
deleteIndividualContributor()
getEmployeeCountUnderAnEmployee()
getLeastCommonAncestorAcrossTwoEmployees()
4 comments:
I believe a B-tree should support the requirement of an efficient data structure. Each node will represent a person at a specific organization level. This tree will be sparse towards the root and will become more dense towards its leaves because in a typical organization, lesser people are at the top of the hierarcy (e.g CEO, MD) and more people are at the bottom of the hierarcy)
The data structure can be roughly like this (in C language):
struct person
{
int EmpID;
char* name;
char* designation;
int numbelow; // no of people directly managed by this person
person* next[];
}
void addperson(int bossID, person* newperson);
void deleteperson(int personID);
void promote(int personID);
Rochak's structure looks good except that it needs a manager field. Else it will be a useless search from top trying to figure out the boss in case of addManager() and deleteManager() calls.
1.along with a tree to store the hirearchy you could have a map with pointers to nodes in tree to make the find operation faster.
Post a Comment