Dynamic Programming21 sections · 916 units
Open in Course

Optimal BST - Why QI Holds

The proof

For Optimal BST, cost(i,j)=l=ijflcost(i,j) = \sum_{l=i}^{j} f_l (sum of frequencies). I'll verify QI: cost(a,c)+cost(b,d)cost(a,d)+cost(b,c)cost(a,c) + cost(b,d) \leq cost(a,d) + cost(b,c). Left side: l=acfl+l=bdfl\sum_{l=a}^{c} f_l + \sum_{l=b}^{d} f_l.

The middle part [b,c][b,c] is counted twice. Right side: l=adfl+l=bcfl\sum_{l=a}^{d} f_l + \sum_{l=b}^{c} f_l. The full span [a,d][a,d] plus the middle [b,c][b,c] again. Breaking into pieces: left = ab1+2bc+c+1d\sum_{a}^{b-1} + 2\sum_{b}^{c} + \sum_{c+1}^{d}. Right = same expression. They're equal! Since left = right, we have left \leq right. QI holds.