Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: lowest common ancestor algorithms for trees #453

Closed
AlexandruValeanu opened this issue Dec 13, 2017 · 6 comments · Fixed by #597
Closed

Feature Request: lowest common ancestor algorithms for trees #453

AlexandruValeanu opened this issue Dec 13, 2017 · 6 comments · Fixed by #597

Comments

@AlexandruValeanu
Copy link
Collaborator

AlexandruValeanu commented Dec 13, 2017

I have noticed that Tarjan's algorithm is implemented but that is not very efficient if you run the queries one by one. There are some nice algorithms for solving the lca problem for trees that provide O(log n) or even O(1) per query.

I was thinking about implementing some and I was curious if this is something that would be interesting to have.

@d-michail
Copy link
Member

Definitely! We are also missing some cleanup and unification work (interface design, etc) regarding LCA algorithms.

@AlexandruValeanu
Copy link
Collaborator Author

AlexandruValeanu commented Dec 13, 2017

Great! I'll start working on that.

Yes, I've seen that there is no LcaAlgorithm interface but adding one is not hard.
The problem is that all LCA algorithms should be in some package (in my opinion). But this would mean that Naive and Tarjan have to move which is a major problem. Do you have any suggestions on how to structure all LCA-related stuff?

@rahul6789sharma
Copy link

HI
Recently i have started using this great library in my project. LCA algorithm is good to have. and even it is better can we have some algorithm to find all the leaf nodes of given vertex.
i am not sure if it is already available

@d-michail
Copy link
Member

@AlexandruValeanu We are slowly moving stuff into their respective packages. If you contribute more LCA algorithms, it would definitely make sense to have a separate lca package.

Note that we use a strict 2 releases deprecation policy. We first deprecate a class in one release, and then remove it in the next. If you want to move a class, you deprecate the class and add a new class at the other location. After the next release, we will remove the deprecated class.

@LightnessOfBeing
Copy link

Hi @d-michail. I'm interested to resolve that issue. I wanted to ask: what methods except findLca(V a, V b) and findAllLcas(V a, V b) should be presented in the LCA interface?

About additional LCA algorithms: I want to implement Binary Lifting algorithm with O(nlogn) on preprocessing and O(logn) on query. Are you interested in it? Or it would be better to implement Farach-Bender first (because it's faster <O(n), O(1))?

@AlexandruValeanu
Copy link
Collaborator Author

AlexandruValeanu commented Feb 13, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants