add first common ancester algorithm