GATE CSE 2017 Session 2 Q48: Time complexity of nested loop with step i
- Algorithms
- 2 marks
- MCQ
- −2/3 if wrong
Syllabus topic: Asymptotic worst-case time and space complexity
Question
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
Try it: multiple choice: exactly one correct option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation
Answer: C (official GATE 2017 final answer key)
Concept used: The inner loop runs about times, so the total work is a harmonic sum .
First step: Count the inner-loop iterations for a fixed , then add over from 1 to .
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Asymptotic worst-case time and space complexity
Every PYQ on this topic →Share this question
Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Algorithms PYQs
- 2026 Session 1 · Q17Solve nested recurrences T1 = 4T1(n/2) + T2, T2 = 5T2(n/4) + log n
- 2026 Session 1 · Q41Shortest paths with at most k edges: two statements
- 2026 Session 1 · Q47Condition forcing a vertex into every minimum vertex cover
- 2026 Session 1 · Q49Cycle and cut properties of MSTs with distinct weights
- 2026 Session 1 · Q50Impossible DFS discovery/finish orderings for a DAG edge
- 2026 Session 1 · Q55Properties of 2-colorable (bipartite) graphs