G
G G
O(log n) < O(n) < O(nLog n) < O(n^2) < O(n^3) < O(2^n) in running time.
2 2
my question has to do with actually determining that Big-O type.
Questions:
n represents the number of data items?
given a loop:
for (int i =0; i<1000: i++)
{
int a = a + i;
}
this would be a O(n), because as the number of items increases the time
to run increase linearly?
what about:
for ( int i=0: i<1000: i++)
{
int a = a + i;
int t = t + i;
}
are we only concerned of the number of item or will the two assignment
statement change the analysis in some way?
what about:
for (int i =0; i <1000; i++)
{
for ( int t =1; i < 1000; i++)
{
int a = a+i+t;
}
}
is this O(n^2)? why? how do you come up with that?
what are example of something being O(n/2), or O(log n )?
2
and how do you know that they are that?
2 2
my question has to do with actually determining that Big-O type.
Questions:
n represents the number of data items?
given a loop:
for (int i =0; i<1000: i++)
{
int a = a + i;
}
this would be a O(n), because as the number of items increases the time
to run increase linearly?
what about:
for ( int i=0: i<1000: i++)
{
int a = a + i;
int t = t + i;
}
are we only concerned of the number of item or will the two assignment
statement change the analysis in some way?
what about:
for (int i =0; i <1000; i++)
{
for ( int t =1; i < 1000; i++)
{
int a = a+i+t;
}
}
is this O(n^2)? why? how do you come up with that?
what are example of something being O(n/2), or O(log n )?
2
and how do you know that they are that?