Hi, I want to maintain a hierarchical organization of employees in a company. Each employee has an ID and a level which refers to where the person stands in the hierarchy. And I want my tree-based data structure to facilitate the following operations.
add(a,b) → this function adds a new node with id a to the node with id b
del(a,b) → removes a from the tree and adds all of its children to b
lca(a,b) → returns lowest common ancestor of node a and b
Now the question is, what is the best data structure to use so as to handle multiple queries in logN time?
NOTE: The tree is not binary.