Question discussion

Consider the pseudocode of the function given below.what will the time complexity of the function abc() be?

359452Medium DSSSB TGT Computer Science 0 replies 0 views
0
Consider the pseudocode of the function given below.
what will the time complexity of the function abc() be?
abc(int n)
{
    int i, j, k = 0;
    for (i = n/2; i <= n; i++)
        for (j = 2; j <= n; j = j * 2)
        k = k + n/2;
    return k;
}
  • AOption A
  • BOption B
  • COption C
  • DOption D
Correct answer: C

Explanation

The outer loop runs about n/2 times and the inner loop about log n times, so the total work is Θ(n log n).

Discussion 0

Nobody has replied yet. Start the discussion!