LCA and Kth node on a path

link to the problem. We can compute LCA through many ways, but how we can compute the Kth node on the path from node a to b in the most efficient way(time), O(n) time algorithm is straight forward please share a logarithmic time algorithm for the second query, that is, Kth node on the path from node a to b.

You can compute the K th node from u to v using the {O(NlogN),O(logN)} approach of finding LCA . Like this

1 Like