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

Chapter 18: LCA method 1 #8

Open
rosshjb opened this issue Nov 29, 2023 · 0 comments
Open

Chapter 18: LCA method 1 #8

rosshjb opened this issue Nov 29, 2023 · 0 comments

Comments

@rosshjb
Copy link

rosshjb commented Nov 29, 2023

First of all, thank you for your work.

https://github.com/pulkit1joshi/handbook_codes/blob/main/Chapter%2018%3A%20Tree%20Queries/treequeries_lca_method1.1.cpp

The code for LCA Method 1 appears to have a time complexity of $O(N)$ rather than $O(logN)$ — for example, if the tree is skewed.

(The book says that method 1 has a time complexity of $O(logN)$.)

Using dynamic programming, it seems like it should be possible to move up two or more steps when reaching the minimum common ancestor vertex.

Thanks.

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

No branches or pull requests

1 participant