0

Take the CYK algorithm outlined here: How to prove CYK algorithm has $O(n^3)$ running time

In the top answer, how did that person go from the three summations to $t=(n^3−n)/6$ ? What's the method there?

  • I have updated my answer to show a derivation of $n+1\choose 3$. Let me know if you need greater clarity on any particular aspect of it. – abiessu Sep 24 '13 at 14:06

1 Answers1

1

That specific formula arises from the binomial coefficient $n+1 \choose 3$. There are a number of ways to verify where the formula would come from, but the easiest to "see" is to look down the 4th column of Pascal's Triangle, which is the sum over the third column, which is the sum over the second column, which is the sum over a column of $1$'s.

Going forward, it is clear that the second column is the natural numbers, the third column is the triangular numbers, and the fourth is again where the numbers $n+1\choose 3$ arise. With any "sum of sums" or of a higher degree of sums, it is a good technique to consider how the sums will behave for large $n$. The "order of n" or "big-O notation" gives a reasonable approximation of what will happen in a given algorithm and help to identify the most time consuming portions of code. "Seeing" a formula like this is something that takes time and practice, but the quickest way to see most of this type of formula is to memorize the forms of the first three or four binomial coefficients.

The first three columns of Pascal's Triangle are fairly straightforward:

Column $1$ is all $1$'s.

Column $2$ is the sum over column $1$. Specifically, for each $n$, it is $n$ terms of value $1$.

Column $3$ begins the non-trivial columns. In particular, $\sum_{j=1}^n j$ can be rewritten as a sum of first-last pairs like so:

$$(1+n)+(2+n-1)+(3+n-2)+...$$

There are $n\over 2$ or $n-1\over 2$ such pairs, depending on whether $n$ is even or odd. In the even case, the formula is immediate: ${n(n+1)\over 2}$. In the odd case, there are an odd number of sum terms, so one is left out of the pairing like so: ${(n-1)(n+1)\over 2}+{n+1\over 2}={n(n+1)\over 2}$.

Column $4$ has no "easy" tricks (that I am aware of) like the one for column $3$ which was made famous by Gauss. For this column, let's use a "guess and check" method, taking information that we know from columns $1$ through $3$.

To begin, notice that column $1$ is all constants, which is a polynomial of degree $0$. Looking at column $2$, we have value $n$ at position $n$, which is linear, i.e., a polynomial of degree $1$. For column $3$, we have the triangular numbers, which arise from a polynomial of degree $2$. Further, in Pascal's Triangle, we have the particular summation technique that creates some interesting properties. The one of interest is that for any two successive elements of column $a$, their difference is an element of column $a-1$.

Taking these observations together, let us guess that column $4$ has elements from a degree $3$ polynomial. Let the polynomial be $p(x)=ax^3+bx^2+cx+d$. By the difference property, the following condition should be true:

$$p(n+1)-p(n)={n(n-1)\over 2}$$

Substituting $n+1$ and $n$ in, we get:

$$a(n+1)^3+b(n+1)^2+c(n+1)+d-an^3-bn^2-cn-d=n^2/2-n/2$$

$$\iff a(n+1)^3+b(n+1)^3+c-an^3-bn^2=n^2/2-n/2$$

$$\iff an^3+3an^2+3an+a+bn^2+2bn+b+c-an^3-bn^2=n^2/2-n/2$$

$$\iff 3an^2+3an+a+2bn+b+c=n^2/2-n/2$$

In order for the $n^2$ terms to match, we have $a=1/6$. Then:

$$n^2/2+n/2+1/6+2bn+b+c=n^2/2-n/2$$

$$\iff 1/6+2bn+b+c=-n$$

At this point, it is clear that $b=-1/2$ and $c=1/3$. Then $p(x)=x^3/6-x^2/2+x/3+d$. Since only the first three terms affect our result, let's pretend that $d=0$ for now. If we rewrite $p(x)$ so that all terms have the same denominator, we have $p(x)={x^3-3x^2+2x\over 6}={x(x-1)(x-2)\over 6}={x\choose 3}$. Now it is clear that $d=0$ is a good choice. Notice that when we applied $\sum_{j=1}^n j$, we got $n(n+1)\over 2$ instead of $n(n-1)\over 2$, and the same is true when we apply $\sum_{k=1}^n {n(n+1)\over 2}$, so that the final form of this sum is ${n+1\choose 3}={(n+1)n(n-1)\over 6}={n^3-n\over 6}$.

abiessu
  • 8,303