Given a binary search trees for a set of $n=5$ keys with the following probabilities $:$
$\begin{array}{|l|l|l|l|l|l|l|}\hline \text{i} & \text{0} & \text{1} & \text{2} & \text{3} & \text{4} & \text{5} \\\hline p_i & \text{-} & \text{0.15} & \text{0.10} & \text{0.05} & \text{0.10} & \text{0.20} \\\hline q_i & \text{0.05} & \text{0.10} & \text{0.05} & \text{0.05} & \text{0.05} & \text{0.10} \\\hline \end{array}$
The expected optimal cost of the search is
Show the worked solution\[\boxed{e[i,j]=\min_{i\le r\le j}\big(e[i,r-1]+e[r+1,j]\big)+w(i,j)}\]with \(e[i,i-1]=q_{i-1}\) and \(w(i,j)=\sum_{l=i}^{j}p_l+\sum_{l=i-1}^{j}q_l\).
Filling the table for chains of length 1 to 5:\[e[1,1]=0.45,\ e[2,2]=0.40,\ e[3,3]=0.25,\ e[4,4]=0.30,\ e[5,5]=0.50,\]\[e[1,2]=0.90,\ e[2,3]=0.70,\ e[3,4]=0.60,\ e[4,5]=0.90,\]\[e[1,3]=1.25,\ e[2,4]=1.20,\ e[3,5]=1.30,\ e[1,4]=1.75,\ e[2,5]=2.00.\]With \(w(1,5)=1\), root \(k_2\) is best:\[e[1,5]=e[1,1]+e[3,5]+1=0.45+1.30+1=2.75.\]Answer: C
GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com