Question: Given a rooted tree (T, o) with n vertices and a set of k pairs of vertices {(u1, v1), (u2, v2), . . . ,

Given a rooted tree (T, o) with n vertices and a set of k pairs of vertices {(u1, v1), (u2, v2), . . . , (uk, vk)}, design an algorithm to find the lowest common ancestor of ui and vi for all i = 1, . . . , k. Analyse the running time of your algorithm. Faster and correct algorithms worth more points.

You should try to find an algorithm to solve the problem for an undirected rooted tree but if you solve the directed version you will get partial credit.

Hint: Consider the labels prev() and post(). Consider the set S of all vertices DFS discovered but havent finish exploring (i.e. those vertices with a prev() but no post()). Note that the set S changes as we run DFS. Now, for any pair with prev(ui)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!