Knowee
Questions
Features
Study Tools

What is the time complexity of this function / algorithm?void f(int n){ int i; for (i = 0; i < n; i += 98) { printf("[%d]\n", i); }}

Question

What is the time complexity of this function / algorithm?void f(int n){ int i; for (i = 0; i < n; i += 98) { printf("[%d]\n", i); }}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The time complexity of this function is O(n). This is because there is a single loop that runs n times. However, since the increment in each iteration is 98, the actual number of iterations is n/98. But in Big O notation, we ignore constants. So, the time complexity remains O(n).

Similar Questions

What is the time complexity of this function / algorithm?void f(int n){ printf("n = %d\n", n);}

What is the time complexity of this function / algorithm?void f(int n){ int i; for (i = 0; i < n; i++) { printf("[%d]\n", i); }}O(n)O(1)O(log(n))O(nlog(n))O(2^n)O(n!)O(n^2)

What is the time complexity of this function / algorithm?void f(unsigned int n){ int i; for (i = 1; i < n; i = i * 2) { printf("[%d]\n", i); }}

What is the time complexity of the following code :int i, j, k = 0;for (i = n/2; i <= n; i++) { for (j = 2; j <= n; j = j * 2) { k = k + n/2; }}

What will be the time complexity of the following code?int fun(int n){ int count = 0; for (int i = n; i > 0; i /= 2){ for (int j = 0; j < i; j++){ count += 1;| } }return count;

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.