Computing the nearest common ancestor