Home > Net >  Consult a great god! Big O order of magnitude of this method is how much???
Consult a great god! Big O order of magnitude of this method is how much???

Time:10-03

The static void Print_Triangle (int n)
{
For (int I=1, j=1; I & lt;=2 * n - 1; I++)
{
If (n - j & lt; I & amp; & I & lt;=n - 1 + j)
The Console. Write (" * ");
The else
The Console. Write (" ");

If (I==2 * n - 1 & amp; & (I + 1)/2 & gt; J)
{
i=0;
j++;
Console. WriteLine ();
}
}
}

I used up all my possessions points ~

CodePudding user response:

Do you want to ask this time complexity of the program?

CodePudding user response:

O (N)

CodePudding user response:

Yes, feeling is n but also think is n2

CodePudding user response:

I do think, though only a layer of loop, but this cycle is repeated with the ~

CodePudding user response:

Apparently is O (n * n)

CodePudding user response:

Print_Triangle
Print the triangle
Triangle is two-dimensional, do you
So it is O (N ^ 2)

CodePudding user response:

O (n)

CodePudding user response:

The
reference 7 floor OrdinaryCoder response:
O (n)

A careful look at the should be O (n ^ 2)

CodePudding user response:

As with printed triangle, n * (2 * n - 1)

CodePudding user response:

I know, a lot of people at a cycle, and that is O (N)
Note, however, a cycle O (N) is the premise of circulation in the body, loop variables cannot be modified
See
circulating in the body isi=0;
Will pay attention to the

CodePudding user response:

references to the tenth floor caozhy response:
I know, a lot of people at a cycle, and that is O (N)
Note, however, is the premise of a loop) N, circulating in the body, loop variables cannot be modified
See
circulating in the body isi=0;
Will note

At first glance I was cheated carefully checked to see later

CodePudding user response:

N * (n - 1) this, don't you execute the code

CodePudding user response:

11 references OrdinaryCoder response:
Quote: reference to the tenth floor caozhy response:

I know, a lot of people at a cycle, and that is O (N)
Note, however, is the premise of a loop) N, circulating in the body, loop variables cannot be modified
See
circulating in the body isi=0;
Will note

At first glance I was cheated later carefully checked to see

Dizzy dead,,, the pit dad

CodePudding user response:

N * (2 * n - 1) is the

CodePudding user response:

refer to the 13th floor is nu month god reply:
Quote: reference 11 floor OrdinaryCoder response:

The
Quote: reference to the tenth floor caozhy response:

I know, a lot of people at a cycle, and that is O (N)
Note, however, is the premise of a loop) N, circulating in the body, loop variables cannot be modified
See
circulating in the body isi=0;
Will note

At first glance I was cheated later carefully checked to see

Dizzy dead,,, call

webmaster also fan with me the same error

CodePudding user response:

N2 is so???????

CodePudding user response:

A program written by his writing is confused ~

CodePudding user response:

The
reference Forever ~ 16 floor response:
n2 is so???????

N * (2 * n - 1)

CodePudding user response:

Yes, I just keep the highest item, write simple ~
  •  Tags:  
  • C#
  • Related