Professional Documents
Culture Documents
10.1 Introduction
This method finds the common ancestor between two nodes (u,v).
10.2 Approach
• Input: Two nodes u,v of a tree.
• Solution:
10-1
– Find LCA(g,j):
Here we label each node in the euler tour in terms of (index,level) form.
10-2
Now the l(g) is 12 and l(j) is 15. Therefore, r(g) = 12 and r(j) = 15. Here r(g) < l(j)
10-3
Hence the LCA(g,j) is C.
10-4
• Range Minima Problem:
• Compute prefix and suffix minima for every prefix and suffix to combine the range.
10-5