For example the following one in pseudo-code:
Code: Select all
K=0
for a = 1 to 15
for b = a+1 to 16
for c = b+1 to 17
for d = c+1 to 18
for e = d+1 to 19
for f = e+1 to 20
K=K+1
next
next
....etc.
Or with other words how many times the commands in the inner loop will be executed? I'm not speaking about the number, this is nothing, as one can run the code and find it out, but i'm speaking about the proof/formula that it will have that value.
I have found it to be 38760.
Which "happens" to be equal to (20 , 6). Where (20 , 6) to be the binomial coefficient or the number of combinations of 6 numbers out of 20.
That means (20 , 6) = 20!/(6!·14!)
So how one can prove the above loop will be executed (20,6) times?
►►►►►►►►►►►►►►►►►►►►►►►►
And to generalize it:
If you have a loop of:
Code: Select all
for a1 = 1 to T
for a2 = a1+1 to T+1
for a3 = a2+1 to T+2
..........................
..........................
for an = a(n-1)+1 to T+n-1
next
next
....etc.