added least common ancestor algorithm