Unformatted text preview: 2 You are given a tree T , having n vertices (rooted at vertex r for convenience). You are also given k pairs ( x i , y i ) , 1 ≤ i ≤ k . The task is to output for each pair ( x i , y i ) whether x i is an ancestor of y i in tree T (that is, output yes if x i is an ancestor of y i , and no if it is not). Note that x i is an ancestor of y i can be reframed as y i is in the subtree rooted at x i for convenience. Your algorithm should take O ( n + k ) time. Hint : Think about the graph traversal methods you learned in class. 1...
View Full Document
- Fall '11
- Graph Theory, Yi, Graph traversal methods, Catalin-Stefan Tiseanu, challenge homework problems