Home > Back-end >  Want to ask you this order the time complexity of how to calculate?
Want to ask you this order the time complexity of how to calculate?

Time:10-12

 int main () {

Int a [10]=,3,4,5,6,13,15,16,18,19 {1};
,6,7,8,10 int [5] b={2};


Int a_len=sizeof (a)/4;
Int b_len=sizeof (b)/4;

Int [a_len + c b_len];

Printf (" array length \ n ");
Printf (" % d % d \ n ", a_len, b_len);

//and sequence
int i=0;
Int l=0;
Int z=0;
For (z=0; Z<2 * b_len; Z++)
{

If (a [I] & gt; B/l)
{
C=b [z] [l];
L++;
} else if (a [I] {
C=[z] a [I];
i++;
}
}

//no part of the merger
For (int x=2 * b_len, p=b_len; x<(a_len + b_len); X++ p++)
{

C=[x] a [p];

}

//and sequence output
Printf (" and sequence output: \ n ");
For (int y=0; Y & lt; (a_len + b_len); Y++)
{
Printf (" % d, c [y]);
}

return 0;
}

CodePudding user response:

Biggest n + m cycle, 3 times for 3 * (n + m), so is O (n) level, because the algorithm focuses on n for several times, the power, is not concerned about the impact of factor, so the time complexity is O (n) or O (n + m)

CodePudding user response:

Complexity depends on the number of times and what is the relationship between the data length

For the subject, through merging, for two already sorted array, merge into one, then the data length is two arrays, and for N
To compute the complex situation, two arrays as long, cross into, this is the most frequently, but also is the most more N - 1

N - 1 is a function of N, the result is O (N)
Even 10000 N + 1000000 times calculation, complexity is O (N)

If this is aN ^ m + bN ^ (m - 1) +... This kind of polynomial, then is O (N ^ m) only exponentiation biggest
If it is 2 ^ N +... This is O (2 ^ N)
In short is take the greatest influence on the result of coefficient to

CodePudding user response:

N here actually and specific array length a dime relationship are not
Is the assumption that N is large, large enough to ignore other data affect the situation down estimate
This is why, amount of calculation is 0.0001 N + 100000000, is O (N) complex reason

Evaluation algorithm is here, the algorithm itself is to be adapted to the array of arbitrary length, this makes sense
  • Related