We can further define this sum recursively and use memoization for improved efficiency ( 3)For non-terminal nodes, we first focus on straight non-terminals with parent node d = str, l, c, c + 1, r , and left and right child nodes l, lc, lc+1, c and d r = s r , c+1, rc, rc+ 1, r .
first, we note that the loss for the subtree rooted at d can be expressed as the subtree's total loss can be factored into the loss of its left subtree, the loss of its right subtree, and the additional loss contributed by comparisons between the words spanning both subtrees.