Reputation: 5039
If I have a binary search tree like this then what will be lowest common ancestor of nodes 6 and 1?
Upvotes: 3
Views: 2103
Reputation: 160942
According to the Wikipedia definition of the Lowest common ancestor I correct myself:
The lowest common ancestor (LCA) is a concept in graph theory and computer science. Let T be a rooted tree with n nodes. The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).
So yes going by this definition the correct answer would be 6
. If this is an interview question would be good to clarify in advance with the interviewer.
Upvotes: 4