15.5-1
Construct-optimal-bst (Root)
N←length[root]
Print r[1, n] is the root
PRINT-OBST (1, N)
Print-obst (i, J)
m = R[i, j]
If i = m
Print dm−1 D_{m-1} is the only child of the K_m
Else
Print kr[i,m−1] k_{r[i, M-1]} is the left child of K_m
Print-obst (i, m-1)
If j = m
Print DM d_m is the right child of the K_m
Else
Print Kr[m+1,j] k_{r[m+1, J]} is the right child of K_m
Print-obst (M+1, J)
15.5-2
The right binary search tree is shown below:
The cost of the final calculation is: 3.12.
15.5-3
If you have a Ω\omega table, each calculation of ω[i,j] \omega[i,j] requires only θ (1) \theta (1) time, and no maintenance table requires θ (j−i) \theta (j-i) time, so it is now equivalent to adding a for loop in the second for (not is nested in a third for loop), and the final complexity remains Θ (n3) \theta (n^3).
15.5-4
The 9th and 10 lines are replaced by:
If i = j
R = J
e[i,j]= PI+QI−1+QJ P_i+q_{i-1}+q_j
Else
for r = root[i,j-1] to Root[i+1,j]
When calculating all j−i=k j-i=k E[i,j] (with K-K nodes), each e[i,j] will cost root[i+1, J]–root[i, j-1] + 1 iterations, all j−i=k j-i=k] spend e[i,j] –ROOT[1,K] + n–k. Due to 1≤root[k, 1], root[1, k]≤n, so root[k,1]–root[1,k] + n–k=θ (n). The last K K change range is 0 0 to N