public static int binaryLCA ( int x , int y ) { if ( x == y ) { return x ; } int xor = x ^ y ; int idx = getMaxExp ( xor ) ; if ( idx == - 1 ) { throw new UnsupportedOperationException ( ) ; } return replaceBy1and0sFrom ( x , idx ) ; }
Get the lowest common ancestor of x and y in a complete binary tree