wrote:
> standard 2d array filling with increasing numbers for rows and columns:
>
> for(int i=0;i<n;i++)
> for(int j=0;j<n;j++)
> a[i][j] = i + j;
>
> problem is it's O(n^2). I'm looking for a method to decrease the time,
> any suggestions? I'm googling for dynamic programming solutions, but
> not coming up with much.
Initialize it statically, and then it will be filled at load-time
rather than run-time. At file/namespace scope, do this:
int a[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
Of course this limits your flexibility.
Cheers! --M