This document describes the optimal binary search tree algorithm. It finds the structure of the optimal binary search tree (OBST) that results in the smallest possible search time for a given sequence of key accesses. It builds a BST from a set of keys with access probabilities. It calculates the costs of different subtree configurations in a bottom-up dynamic programming approach to find the overall minimum cost tree. As an example, it calculates the optimal BST for 4 keys with frequencies 3, 4, 8, 9, which has a cost of 43 and root node 2.