This question was asked recently in Google coding interview:
Design a tree-like data structure with two functionalities:
Optimize DS for IsAncestor calls. Note that on calls of SetRoot, the connections direction may change.
I was asked to think of better time complexity than O(N), where N is no of nodes. Any ideas?