The document discusses the algorithm for constructing an optimal binary search tree. It involves calculating the cost table C and root table R based on the probabilities of keys. The cost C[i,j] is calculated recursively as the minimum of C[i,k-1] + C[k+1,j] + sum of probabilities from i to j. This is done by iterating through all subtrees until the overall minimum cost C[1,n] is found, with the corresponding roots in R. The example calculates the optimal binary search tree for keys A, B, C, D with probabilities 0.1, 0.2, 0.4, 0.3, finding a minimum cost of 1.7.