This preview shows page 1. Sign up to view the full content.
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
This note was uploaded on 01/13/2012 for the course CMSC 351 taught by Professor Staff during the Fall '11 term at University of Louisville.
 Fall '11
 Staff

Click to edit the document details