GATE CS 2017, set 2 · Question 38 · Algorithms · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider the following C function.
int fun(int n) { int i, j; for(i = 1; i <= n; i++) { for(j = 1; j < n; j += i) { printf(" %d %d",i,j); } } }
Time complexity of fun in terms of Θ notation is

  1. (A) Θ(n√n)
  2. (B) Θ(n²)
  3. (C) Θ(n log n)
  4. (D) Θ(n²log n)
Answer

Answer (C)

Answer from the official GATE CS 2017 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes