GATE / CS ARCHIVE

GATE CSE 2023 / QUESTION 54

GATE CSE 2023 Q54

Algorithms · Asymptotic Analysis & Recurrences · Full GATE CSE 2023 paper

GATE 2023, Q54 2 marks · MSQ
Report issue

Asymptotic Analysis & Recurrences

Question 54, GATE 2023: Function 1 repeats while n>1: increment x exactly n times, then set n=floor(n/2). Function 2 increments x exactly 100n times. Let their increment counts be f1(n),f2(n) for the original n. Select true claims: A f1∈Θ(f2); B f1∈o(f2); C f1∈ω(f2); D f1∈O(n).
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, D

For integer n at least 2, the first function executes at least n increments and fewer than n+n/2+n/4+...=2n increments. Therefore f1(n)=Theta(n). The second executes exactly 100n increments, also Theta(n). Their ratio stays bounded above and below by positive constants, so A and D hold, while neither little-o nor little-omega holds. The floor in the halving assignment does not change these bounds.

Teaching detail. Do not multiply the outer-loop count Θ(log n) by the original inner-loop length n: the inner length shrinks each time. For n a power of two, the exact count is n+n/2+...+2=2n−2. For arbitrary n, flooring can only reduce the geometric upper bound and the first pass alone supplies the n lower bound for n≥2. Compared with f2=100n, the ratio lies between 1/100 and 2/100. Being a smaller constant fraction is not little-o; little-o needs the ratio to vanish.

Original paper, page 57 · Answer key