c++ - Non-Big O complexity -
I am very confused by calculating the algorithm complexity For an assignment, we are given the following tasks and to find its complexity Is called.
int selectkth (int a [], int k, int n) {int i, j, mini, tmp; For (i = 0; i L [A] [mini]) MINI = J; Tmp = a [ii]; A [i] = one [small]; A [mini] = tmp; } Back [k-1]; } The assignment asks itself to find the complexity of the function used to find the smallest integer of k-th in an unauthorized array of integers. "
In addition to this we were asked to write our G function along with our F function.
For the function, I will add all assignments and operations to the function. Do I include variables or n in this F function?
As the best estimate, I would say that F (N) = 6 N + 4 (N ^ 2), because there are 6 operations in the first loop, omitted in the nested loop 4 operations were performed.
And to understand, will the big o complexity of this ceremony be O (N ^ 2)? I say that because there is a nested for loop, and this means the worst case of going through every item at all times.
I should be sorry if I am not clear. I am quite confused with how it works.
Here is a simple analysis:
External loop k < / Code> is doing it with iterations. Inter-looping is n-1 iterations but it does that k bar. So we have o (k * (n-1)) = o (kn-k) since k might be equal to n n = n (n ^ 2-n) = o (n ^ 2) n (n ^ 2) / Code>. For more help with Big O Notation Notation check out:
Comments
Post a Comment