algorithm - Find multiple LCAs in unrooted tree -


i trying implement lca unrooted tree. have given tree (a connected undirected graph without cycles) , sequence of queries lca root , 2 vertices. every particular query can have different root, cannot use algorithms preprocess tree arbitrary root @ beginning.

so far i've tried find paths both of vertices root dfs , check diverge, slow (o(nq), q number of queries).

any suggestions how preprocess tree in order have sublinear complexity of query?

let lca(u, v, w) lca of v , w respect root u. compute lca(u, v, w), can compute, fixed r,

lca(r, u, v) lca(r, u, w) lca(r, v, w) 

and take "odd man out", i.e., if 2 equal , third different, take third, else they're equal, take node.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -