Question 5 (10 points)
the definition of LCA on Wikipedia: "The lowest common ancestor is defined
between two nodes p and q as the lowest node in T that has both p and q as
descendants (where we allow a node to be a descendant of itself)."
3
5
1
6
2
0
8
7
4
The LCA of 5, 1 is 3
The LCA of 4, 6 is 5
The LCA of 7, 8 is 3
What is the complexity of an algorithm to calculate the LCA
Node LCA(Node p, Node q)
in a BST with n nodes and height h?
h
n
n^2
h^2