How to Check if a vertex in a tree is an ancestor of some other vertex

Can Anyone Explain about how to check this in Graph using BFS?

Say 'u' and 'v' are the two vertices in consideration.

If LCA(u,v)=u, ā€˜uā€™ is the ancestor of ā€˜vā€™ .
If LCA(u,v)=v,ā€˜vā€™ is the ancestor of ā€˜uā€™.

LCA(i,j) can be found out in O(logN) for a tree with ā€˜Nā€™ nodes.

1 Like

Thanks Man :sweat_smile: