Calculate the big-O for each of the given functions and explain how they fall into different categories,
Fantastic news! We've Found the answer you've been seeking!
Question:
Calculate the big-O for each of the given functions and explain how they fall into different categories, which one would be better to use for large numbers? explain why.
static int countFactors(int a, int b) {
int count = 0;
while (a >= b) {
count++;
a -= b;
}
return count;
}
static int countFactors(int a, int b) {
int count = 0;
int c = 1;
while (c * b <= a) {
c = c * 2;
}
while (c > 1) {
c = c / 2;
if (a >= ( c * b) {
count = count + c;
a = a - c * b;
}
}
return count;
}
Related Book For
Financial Accounting and Reporting
ISBN: 978-0273744443
14th Edition
Authors: Barry Elliott, Jamie Elliott
Posted Date: