An optimal pointer machine algorithm for finding nearest common ancestors