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