Chapter 3: Q18E (page 109)
You are given a tree T=(V,E) (in adjacency list format), along with a designated root node . Recall that u is said to be an ancestor of v in the rooted tree if the path from r to v in T passes through u.
You wish to reprocess the tree so that queries of the form “is u an ancestor v?” can be answered in constant time. The pre-processing itself should take linear time. How can this be done?
Short Answer
To reprocess the tree to fit the query “is u an ancestor v ”, by performing the Depth first search with pre and post numbering the tree T=(V,E).