Right, because of this cell responds to the initial subexpression from one to n.

Now everything is ready to write down an algorithm.

In the algorithm we will maintain two tables, m and capital M.

The first one for storing the minimum values for all subexpressions, and

the second one for storing the maximum values for all subexpressions.

We start by initializing these tables as follows.

So when subexpression contains just one digit,

which means that when j = i, then there is nothing,

actually to minimize or maximize because there are no operations.

So there is no order on operations.

So, because of that we just initialize

the main diagonals of this table with the most current point in digits.

This is with the following loop.

So m(i,i) and M(i,i) = di.

Then we go through all possible subproblems in order of increasing size.

And this is done as follows.

We gradually increase the parameter s from 1 to n- 1.

This is done in the following loop.

When s is fixed, i goes from 1 to n- s.

And j is computed as i + s.

This is done to go through all possible payers (i,j)

such that j- i = s.

Right when i and j are fixed we call the procedure min and

max to compute the minimum and maximum value of the subexpression (i,j).

All right.

So finally we return the value of capital M of 1,n as the result for

our initial problem because this subexpression,

1 n corresponds to our initial problem.

Containing all digits from 1 to n.