This question:
Are there any efficient ways to populate a balanced tree structure
provides an analytical way of labelling a perfect binary tree of any depth.
In such a tree, is there any way of efficiently figuring out the first common parent of an arbitrary subset of leaf nodes?
For instance, given the following binary tree:
I am looking for a way where if:
Input is: 3,5 Output is: 0
Input is: 3,5,6 Output is: 0
Input is: 3,4 Output is: 1
The only way I can think of is to traverse up to the root (0) from each of the given leaf nodes, and then picking the first common one.
Is there any closed-form analytical way in which the first common parent can be found?

