CSC300: 2D Triangle [4/19] |
01 |
for (long i = 1; i <= N; i = i+1) { for (long j = 1; j <= i; j = j+1) { result = result+1; } } |
Output
01 02 02 03 03 03 04 04 04 04 05 05 05 05 05 06 06 06 06 06 06 07 07 07 07 07 07 07 08 08 08 08 08 08 08 08 09 09 09 09 09 09 09 09 09 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 Elapsed count f( 512): 131,328: 3.992 [ 0.002 : 2.000] Elapsed count f( 1,024): 524,800: 3.996 [ 0.003 : 1.500] Elapsed count f( 2,048): 2,098,176: 3.998 [ 0.002 : 0.667] Elapsed count f( 4,096): 8,390,656: 3.999 [ 0.005 : 2.500] Elapsed count f( 8,192): 33,558,528: 4.000 [ 0.016 : 3.200] Elapsed count f( 16,384): 134,225,920: 4.000 [ 0.065 : 4.063] Elapsed count f( 32,768): 536,887,296: 4.000 [ 0.246 : 3.785] Elapsed count f( 65,536): 2,147,516,416: 4.000 [ 1.001 : 4.069] Elapsed count f( 131,072): 8,590,000,128: 4.000 [ 4.006 : 4.002] Elapsed count f( 262,144): 34,359,869,440: 4.000 [ 15.628 : 3.901] Elapsed count f( 524,288): 137,439,215,616: 4.000 [ 62.422 : 3.994] Elapsed count f( 1,048,576) aborted execution after a minute or so Elapsed count f( 2,097,152) aborted execution after a minute or so Elapsed count f( 4,194,304) aborted execution after a minute or so Elapsed count f( 8,388,608) aborted execution after a minute or so Elapsed count f( 16,777,216) aborted execution after a minute or so Elapsed count f( 33,554,432) aborted execution after a minute or so Elapsed count f( 67,108,864) aborted execution after a minute or so Elapsed count f( 134,217,728) aborted execution after a minute or so Elapsed count f( 268,435,456) aborted execution after a minute or so Elapsed count f( 536,870,912) aborted execution after a minute or so Elapsed count f(1,073,741,824) aborted execution after a minute or so Elapsed count f(2,147,483,648) aborted execution after a minute or so
This is quadratic: ~ 1/2 * N^2
More accurately: (1/2 * N^2) - N/2