Re: question on big-O-notation
- To: mathgroup at smc.vnet.net
- Subject: [mg41591] Re: question on big-O-notation
- From: Bill Rowe <listuser at earthlink.net>
- Date: Wed, 28 May 2003 04:57:24 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 5/27/03 at 1:47 AM, atang at netband.com.hk (Alan Tang) wrote:
> Is it correct?
> for (i=0; i<1000000; i++)
> { for (j=10; j<n; j++)
> { a[j]=a[j]+i;
> }}
>big-O-notation equation (1000001) + 10000000 * [(1+n-10) * (n-10)]
No, the code above is not correct syntax. To be correct *syntax* it should read:
For[i = 1, i < 10000000, i++,
For[j = 10, j < n, j++, a[[j]] = a[[j]] + 1]]
Indices for arrays in Mathematica start with 1 not 0
a[j] would be a function with arguement j not the jth element of array a
The "{" is used to delimit Lists not grouping as you've done here
";" is used to terminate a statement "," is used to separate arguements
Note, what I've show above is correct syntax. It may not be (and probably isn't) a correct solution to the problem you are trying to solve.