The goal is to find the binary tree with the cheapest cost, where the cost is the sum from 1 to n of (1+li )*pi, plus the sum from 0 to n of mi*qi , where li is the level of the item Pi and mi the level of the external node corresponding to Qi.
Let Cj,k be the cost of the cheapest binary search tree for
the subproblem consisting of the data items (Pi)i=j+1k and data
intervals (Qi)i=jk, so that the cost of the optimal tree for the original instance is C0,n. If r ranges over the set of possible roots of the binary search tree for the subproblem, then
Based on this recurrence (and appropriate initial conditions), find the cost of the optimal binary search tree for the instance where n=5, (pi ) = (30 10 5 10 10), and (qi) = (5 10 5 5 5 5). Also sketch the optimal tree.