I need help in analyzing loop structures. I am a student and need to know this for a class.
In my first example here:
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
I need to figure out how to analyze that this loop runs n^2 times. (This was an example given in a later class is the only reason I know that much). The instructor wants for us to set up a table as such:
i _____ j _____ # of reps
1 _____ n _____ n
2 _____ n _____ n
3 _____ n _____ n
Another example is this:
for (int i=1;i<=n;i++)
for (int j=1;j<=i;j++)
According to the instructor the table should look like
i _____ j _____ # of reps
1 _____ 1->1 _____ 1
2 _____ 1->2 _____ 2
3 _____ 1->3 _____ 3
and from that table I am supposed to be able to infer that (n(n-1))/2.
Can anyone give me an answer that sounds like it is in plain English or give me some terms to search in Google. I have tried very hard to find this subject using multiple search engines and am comming up empty. Thanks for any help.