Binary Search Tree Using Dynamic Programming