Dynamic Programming21 sections · 916 units
Open in Course

Optimal BST - Problem Statement

Classic application

Given nn keys with access frequencies f1,,fnf_1, \ldots, f_n, build a BST to reduce expected search cost. If key ii is at depth did_i, cost is fi(di+1)\sum f_i \cdot (d_i + 1). Deeper keys cost more.

This is the problem Knuth designed his improvement for. The interval DP structure comes from the recursive BST definition. Read the problem statement carefully, noting the constraints. Try to identify the recursive structure before looking at the solution.