Skip to content

Lowest Common Ancestor for DAG #231

Open
@jyoti246

Description

@jyoti246

Description of the problem

Using a naive approach we can find LCA between two nodes in a non cyclic graph in O(n) time. But when there are O(n) queries i.e we need to get LCA of O(n) different pairs of nodes, the time complexity becomes O(n^2).
But by doing some pre processing we can reduce the complexity to O(nlogn).
There are mainly two approaches:
Binary lifting
using Segment tree and Eulars tour

Both of these can be implemented in pydatastructs/graphs/algorithms.py as classes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions