I'm learning how to find algorithm complexity and I can't figure out what's the complexity of this algorithm. Could someone explain to me how to get the answer?
void algorithm(int a, int b) {
while (a >= b) {
int x = a - b;
for (int i = 0; i <= x; i++) {
std::cout << "complexity of this algorithm?";
}
a = x;
}
}
Please any input is welcome. This is what I have so far:
The complexity is (a^2/b)
As I described in the image, you need to sum up all "x", then you will get the complexity.
summation_part_definition_link
So in the end, if "a" and "b" were for the same order then the result is :
this means complexity is in numeric order. but if "a" was for upper order then the result is :