handbook_codes icon indicating copy to clipboard operation
handbook_codes copied to clipboard

Chapter 18: LCA method 1

Open rosshjb opened this issue 8 months ago • 0 comments

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.

rosshjb avatar Nov 29 '23 05:11 rosshjb