GATE / CS ARCHIVE

SUBJECT COLLECTION

Algorithms · Asymptotic Analysis & Recurrences

63 questions, newest first

GATE CSE has asked 63 questions on Asymptotic Analysis & Recurrences (Algorithms) from 1991 to 2026, in 39 of the 46 papers; the most recent is in GATE CSE 2026 Set 2. In the last five years it carried 1.4 marks per 100-mark paper on average, against 1.9 since 2003. Since 2014 the questions have been 19 MCQ, 3 MSQ and 1 NAT. 7 groups of questions here are solved the same way; “One per method” keeps the newest of each.

Browse topics
Show
1 mark · MCQ
Report issue

Solving nested recurrences

Asymptotic Analysis & Recurrences

Question 17, GATE 2026: For n>1, T1(n)=4T1(n/2)+T2(n), and T2(n)=5T2(n/4)+Θ(log₂n). Both equal 1 for n≤1. Determine T1’s asymptotic order among n², n²log₂n, n^(log₄5), and n^(log₄5)log₂n.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: Theta(n^2)

Givens and goal

For n>1, T1(n)=4T1(n/2)+T2(n), and T2(n)=5T2(n/4)+Θ(log₂n). Both equal 1 for n≤1. Determine T1’s asymptotic order among n², n²log₂n, nlog₄5, and nlog₄5log₂n.

Approach

Solve T2 first, then use its growth rate as the nonrecursive term in the recurrence for T1.

Step-by-step solution

1. In T2, the branching parameters are a=5 and b=4. The critical power is nlog₄5. Set α=log₄5≈1.161.
2. A logarithm is polynomially smaller than n^α: for example log₂n=O(nα/2). The first case of the Master theorem therefore gives T2(n)=Θ(n^α).
3. Substitute into T1: T1(n)=4T1(n/2)+Θ(n^α). Its critical power is nlog₂4=n². Because α<2, the additive term is again polynomially smaller than the critical power.
4. Applying the same Master-theorem case yields T1(n)=Θ(n²), option A. There is no extra logarithmic factor because the additive term is not Θ(n²), which would be the balanced case.
5. A recursion-tree check explains the dominance. At depth j, the T2 work totals Θ(4j(n/2j)^α)=Θ(n^α(4/2^α)j). The ratio exceeds 1, so lower levels dominate. With depth log₂n, the leaf scale is 4log₂n=n². Standard floor/ceiling handling of non-power inputs does not change this asymptotic result.

Original paper, page 14 · Answer key

1 mark · MCQ
Report issue

Ordering four asymptotic functions

Asymptotic Analysis & Recurrences

Question 24, GATE 2026: With logarithms base 2, order n^(1/3), log n, log(n!), and 2^(log n) by increasing asymptotic growth. A log n,n^(1/3),2^(log n),log(n!); B n^(1/3),log n,log(n!),2^(log n); C log n,n^(1/3),log(n!),2^(log n); D 2^(log n),n^(1/3),log n,log(n!).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Givens and goal

With logarithms base 2, order n1/3, log n, log(n!), and 2log n by increasing asymptotic growth. A log n,n1/3,2log n,log(n!); B n1/3,log n,log(n!),2log n; C log n,n1/3,log(n!),2log n; D 2log n,n1/3,log n,log(n!).

Approach

Simplify the exponential and bound the factorial logarithm.

Step-by-step solution

1. Because the bases match, 2log₂n=n exactly. It must therefore be compared as a linear function, not as an arbitrary exponential.
2. Write log(n!)=Σ(k=1 to n)log k. Every summand is at most log n, giving an upper bound n log n. The last at least n/2 summands are at least log(n/2), giving a lower bound (n/2)log(n/2). Thus log(n!)=Θ(n log n).
3. Any fixed positive power of n eventually dominates log n, so log n=o(n1/3). Also n1/3/n=n−2/3→0, and n/(n log n)=1/log n→0.
4. The required increasing order is log n, n1/3, n, Θ(n log n), matching A. This is an eventual growth comparison, not a claim of strict ordering at every small input.

Original paper, page 19 · Answer key

1 mark · MSQ
Report issue

Solving four runtime recurrences

Asymptotic Analysis & Recurrences

Question 25, GATE 2026: All base cases are T(1)=1. Which recurrences give Θ(n)? A T(n)=T(n−1)+1; B T(n)=2T(n/2)+1; C T(n)=2T(n/2)+n; D T(n)=T(n−1)+n. For halving recurrences use powers of two or conventional rounding.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, B

Givens and goal

All base cases are T(1)=1. Which recurrences give Θ(n)? A T(n)=T(n−1)+1; B T(n)=2T(n/2)+1; C T(n)=2T(n/2)+n; D T(n)=T(n−1)+n. For halving recurrences use powers of two or conventional rounding.

Approach

Unroll decrement recurrences and sum levels in divide-and-conquer trees.

Step-by-step solution

1. A makes n−1 unit increments above its base: T(n)=1+(n−1)=n. It is Θ(n).
2. For B, n=2h gives a full binary recursion tree with n leaves. The leaves contribute n; its n−1 internal nodes each contribute 1. Thus T(n)=2n−1=Θ(n).
3. For C, level j has 2j subproblems of size n/2j, so its nonrecursive work is 2j(n/2j)=n. There are log₂n internal levels and n units at the leaves. Therefore T(n)=n log₂n+n=Θ(n log n).
4. D unrolls into 1+2+…+n=n(n+1)/2=Θ(n²). Unlike A, its added work grows with the current input size.
5. Only A and B are linear. Matching recursion shape alone is insufficient: B and C have the same branching but different work per node.

Original paper, page 20 · Answer key

1 mark · MCQ
Report issue

Solving an exponential recurrence by normalization

Asymptotic Analysis & Recurrences

Question 20, GATE 2025: T(0)=1 and T(n)=2T(n−1)+n·2^n for n>0. Which asymptotic order is correct? A Θ(n²2^n); B Θ(n2^n); C Θ((log n)²2^n); D Θ(4^n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Divide out the homogeneous growth factor 2n so that the remaining recurrence becomes a simple cumulative sum.
Define U(n)=T(n)/2n. Dividing the recurrence by 2n gives U(n)=T(n−1)/2n−1+n=U(n−1)+n, with U(0)=1. Repeated substitution yields U(n)=1+1+2+⋯+n=1+n(n+1)/2.
Therefore T(n)=2n[1+n(n+1)/2]. The bracket is a quadratic polynomial with positive leading coefficient, so it is Θ(n²). Multiplication by 2n gives Θ(n²2n), option A.
B overlooks the accumulation of n successive normalized contributions. C grows too slowly by replacing that quadratic sum with logarithms, and D is exponentially larger than the exact solution. A master theorem for T(n/b) is not the natural tool because this recurrence decreases n by one, rather than dividing it.

Original paper, page 20 · Answer key

2 marks · MCQ
Report issue

Normalize a square-root recurrence and flag its base case

Asymptotic Analysis & Recurrences

Question 42, GATE 2024: The printed recurrence gives T(n)=√n·T(√n)+n for n≥1 and T(1)=1. Which asymptotic answer is intended? A Θ(n log log n); B Θ(n log n); C Θ(n² log n); D Θ(n² log log n). The recursive branch overlaps the base case, so the literal definition needs qualification.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: First disclose the definition's defect, then solve the intended version with a constant-size stopping threshold.
1. Literally, the n≥1 branch applies at n=1 and says T(1)=T(1)+1, contradicting T(1)=1. Merely changing ≥ to > is still insufficient over exact real arguments: repeated square roots of n>1 approach 1 but never reach it in finitely many steps. A constant threshold greater than 1, or a specified integer-rounding convention with a valid base, is needed.
2. For the intended recurrence, divide by n and set F(n)=T(n)/n. Then √n·T(√n)/n=T(√n)/√n=F(√n), so F(n)=F(√n)+1.
3. After k expansions, F(n)=F(n1/2^k)+k. Reaching a fixed threshold c>1 requires log n/2k≤log c, so k=Θ(log log n).
4. A bounded base value gives F(n)=Θ(log log n), hence T(n)=Θ(n log log n).
Official intended answer: A. This derivation is conditional on the corrected stopping model; it does not solve the inconsistent recurrence exactly as printed. Existing discrepancy CS-2024-S1-Q42-BASE-CASE is preserved.

Original paper, page 27 · Answer key

1 mark · MCQ
Report issue

A recurrence whose larger-root coefficient vanishes

Asymptotic Analysis & Recurrences

Question 15, GATE 2024: T(0)=1, T(1)=2, and T(n)=5T(n−1)−6T(n−2) for n≥2. Choose its tight asymptotic class. A Θ(2^n); B Θ(n2^n); C Θ(3^n); D Θ(n3^n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Solve the characteristic equation and then enforce both initial conditions.

1. Derivation. The characteristic polynomial r²−5r+6=(r−2)(r−3) gives T(n)=a 2ⁿ+b3ⁿ. T(0)=1 gives a+b=1, while T(1)=2 gives 2a+3b=2. Subtracting twice the first equation yields b=0, so a=1 and T(n)=2ⁿ exactly. Therefore A; the larger characteristic root does not contribute for these initial values.

2. Explanation and checks. A direct induction independently verifies the result: assuming T(n−1)=2n−1 and T(n−2)=2n−2, the recurrence becomes (10−6)2n−2=2n. Both base cases agree. The characteristic roots are distinct, so no factor n is introduced by repeated roots. More importantly, choosing the largest root without solving for its coefficient would give the wrong growth class here because that coefficient is zero.

Original paper, page 12 · Answer key

1 mark · MSQ
Report issue

Asymptotic Analysis & Recurrences

Question 29, GATE 2023: For f(n)=n and g(n)=n², select true claims: A f∈O(g); B f∈Ω(g); C f∈o(g); D f∈Θ(g).
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C

f(n)/g(n)=n/n²=1/n tends to 0. Hence f=o(g), which also implies f=O(g). A positive constant lower bound proportional to n² cannot hold for all large n, so f is neither Ω(g) nor Θ(g). Answer A, C.

Teaching detail. The asymptotic definitions distinguish an upper bound from a tight bound. For n≥1, n≤n², so O(g) holds with constant 1. Little-o requires that for every ε>0, n≤εn² for all sufficiently large n; choosing n≥1/ε establishes it. An Ω(n²) lower bound would require 1/n≥c for some fixed c>0 eventually, which is impossible. Since Θ requires both O and Ω, it fails as well. A vanishing ratio is stronger evidence than a few sample comparisons.

Original paper, page 27 · Answer key

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

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 11, GATE 2022: For positive functions f(n), identify the universally valid statement under its specified restriction: A f(n²)=Θ(f(n)²) if f is polynomial; B f(n²)=o(f(n)²); C f(n²)=O(f(n)²) if f is exponential; D f(n²)=Ω(f(n)²).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

For a positive polynomial of degree d with leading coefficient c>0, f(n²)~c n2d and f(n)²~c² n2d, so they are Θ-equivalent, A. B fails with f(n)=n. C fails with f(n)=2n, since 2n²/22n diverges. D fails with f(n)=log n, since 2log n/(log n)² tends to zero.

The ratio f(n²)/f(n)² tends to 1/c for a degree-d polynomial, a positive finite constant, which is exactly enough for a Θ comparison. In B the ratio for n is 1 rather than tending to zero. In C the ratio is 2n²−2n, unbounded. In D use log(n+1) if positivity is required even at n=1; the ratio still tends to zero.

Original paper, page 11 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 3, GATE 2021: Let f1=10^n, f2=n^(log n), and f3=n^(√n). Arrange by increasing asymptotic growth. A f3,f2,f1; B f2,f1,f3; C f1,f2,f3; D f2,f3,f1.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Taking logarithms gives log f2=Θ((log n)²), log f3=√n log n, and log f1=n log10. Since (log n)²=o(√n log n) and √n log n=o(n), the increasing order is f2, f3, f1, D.

Logarithms are strictly increasing on positive values, so their comparison preserves the order. Ratios of logarithms settle both gaps: (log n)²/(√n log n)=(log n)/√n→0 and (√n log n)/n=(log n)/√n→0. Consequently f2/f3 and f3/f1 tend to zero. The phrase 'n raised to log n' is not n log n; misreading the exponent would change the classification.

Original paper, page 13 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 30, GATE 2021: The printed recurrence is T(n)=T(n/2)+T(2n/5)+7n for n>0, and T(0)=1. Under the intended integer-rounded or terminating-cutoff interpretation, select its tight order. A Θ(n^(5/2)); B Θ(n log n); C Θ(n); D Θ((log n)^(5/2)). The printed recurrence itself omits a rounding/cutoff convention.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Our answer: C under terminating integer-size recurrence convention

The two recursive subproblem sizes sum to 0.9n. Thus the nonrecursive work over successive levels is bounded by 7n[1+0.9+0.9²+…]=70n. A terminating rounded-size recursion tree has O(n) leaves, so constant leaf costs do not alter the upper bound. The root alone costs 7n, giving Ω(n), hence Θ(n), C. Literal qualification: exact real-valued subproblem sizes never reach 0 from positive n, and the only printed base case is n=0. Integer rounding or a positive-size cutoff is therefore implicit; without such a convention the displayed recursion is not a terminating algorithm.

An induction makes the linear upper bound concrete: for floor-rounded subproblems and n≥1, assume T(k)≤Ck+D for smaller k. Then T(n)≤.9Cn+2D+7n, so any C sufficiently above 70 absorbs the constant excess for large n; enlarge constants for finitely many small cases. Alternatively a positive cutoff and geometric level sum yield the same result. Applying the equal-subproblem Master theorem directly would be invalid because the two recursive sizes differ.

Original paper, page 26 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 39, GATE 2021: T(n)=aT(n/b)+f(n), a>1,b>1. Let d=log_b a. A f=n log₂n implies T=Θ(n log₂n); B f=n/log₂n implies T=Θ(log₂n); C f=O(n^(d−ε)), ε>0 implies T=Θ(n^d); D f=Θ(n^d) implies T=Θ(n^d). Choose correct statement under usual running-time recurrence conventions.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

For the standard running-time recurrence with positive constant base cost, nonnegative work, and terminating integer-size conventions, write d=logb a. If f(n)=O(nd−ε) for ε>0, work per level increases geometrically toward the leaves and total cost is Θ(nd), Master Theorem case1, C. Equal-order work in D adds a logarithmic factor. A lacks a condition on a, b, and B is already smaller than its own n/log n root work.

At recursion depth j, there are aj nodes of size n/bj, and height logb n. Leaves number alogb n=nd. For polynomially smaller f, the sum is bounded by a geometric series of that order. At equal order every level instead costs Θ(nd), so D misses Θ(log n) levels. Taking a=b and f=n log n also refutes A, giving Θ(n log²n).

Original paper, page 77 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 2, GATE 2020: For parameters a,b, both printed as ω(1), T(n)=T(n^(1/a))+1 and T(b)=1. Choose the printed asymptotic expression. Options: A Θ(log_a(log_b n)); B Θ(log_(ab) n); C Θ(log_b(log_a n)); D Θ(log_2(log_2 n)). No cutoff for inputs below b is specified; retain this qualification.
Question 2, GATE 2020: For parameters a,b, both printed as ω(1), T(n)=T(n^(1/a))+1 and T(b)=1. Choose the printed asymptotic expression. Options: A Θ(log_a(log_b n)); B Θ(log_(ab) n); C Θ(log_b(log_a n)); D Θ(log_2(log_2 n)). No cutoff for inputs below b is specified; retain this qualification.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: A under the intended recurrence-depth convention

Worked explanation

Unroll without changing the logarithm bases: T(n)=T(n1/a²)+2=…=T(n1/a^j)+j. Exact termination at b requires n1/a^j=b, or (ln n)/aj=ln b. Thus aj=ln n/ln b=logb n. Taking log base a yields the expression in A, with total value j+1. This derivation assumes a,b are held fixed during a recursion chain, even if their initial values depend on the original input size. It does not justify swapping a and b as in C. The rigorous cutoff-based estimate is Θ(1+max(0,loga(logb n))) in the regime n>1,a>1,b>1, with ceiling for integral depth.

Derivation and answer

After j recursive calls the argument is n1/a^j. Equating it to b gives aj=logb n, hence j=loga(logb n) and T(n)=j+1 on exact-depth inputs. With a base cutoff at n≤b, the corresponding depth is max(0, ceil(loga(logb n))) for fixed call parameters a, b>1. This gives intended A when the depth is bounded below away from 0, in particular when it grows. Qualification: the source says a, b are ω(1), not fixed constants, and gives only T(b)=1. Arbitrary inputs need a cutoff/rounding convention, and the additive 1 cannot always be dropped when parameters vary. For example a=n, b=log n gives depth 1 under the cutoff, but loga(logb n) tends to 0. Thus the printed unconditional Theta claim requires a parameter regime/termination convention.

Original paper, page 4 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 4, GATE 2017: Arrange 10, √n, n, log₂n, 100/n in increasing asymptotic complexity. A log₂n,100/n,10,√n,n; B 100/n,10,log₂n,√n,n; C 10,100/n,√n,log₂n,n; D 100/n,log₂n,10,√n,n.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Compare eventual growth rather than the values at a particular small n. The reciprocal 100/n tends to zero while 10 stays constant.

2. log₂n is unbounded, but log₂n/√n→0. Also √n/n=1/√n→0. These limiting ratios put logarithm below square root below linear growth.

3. Consequently 100/n < 10 < log₂n < √n < n in asymptotic growth, option B. Constants such as 100 do not reverse eventual ordering.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 3, GATE 2017: Match P:Towers of Hanoi with n disks; Q:binary search of n sorted numbers; R:worst-case heapsort of n numbers; S:addition of two n×n matrices. Complexities i:Θ(n²), ii:Θ(n log n), iii:Θ(2^n), iv:Θ(log n). Options (P,Q,R,S): A:(iii,iv,i,ii), B:(iv,iii,i,ii), C:(iii,iv,ii,i), D:(iv,iii,ii,i).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Hanoi moves n-1 disks away, moves the largest disk once, then moves n-1 disks back: T(n)=2T(n-1)+1=2n-1, so P→iii.

2. Binary search halves the candidate interval each time; after k comparisons about n/2k candidates remain. Reaching one requires Θ(log n) comparisons, so Q→iv.

3. Heapsort builds a heap in O(n) and performs n extractions costing O(log n) each in the worst case, giving Θ(n log n): R→ii. Matrix addition performs one addition at each of n² positions, giving S→i. Select C.

Original paper, page 2 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 30, GATE 2017: T(n)=2T(√n)+1 for n>2, and T(n)=2 for 0<n≤2. What is its asymptotic order? A:Θ(log log n). B:Θ(log n). C:Θ(√n). D:Θ(n).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. The argument shrinks by square root, so transform to its logarithm. Put m=log₂n and S(m)=T(2m). Since √(2m)=2m/2, the recurrence becomes S(m)=2S(m/2)+1 with a constant base for m≤1.

2. This is a binary recursion tree with Θ(m) leaves and Θ(m) total nodes. Equivalently, the Master theorem has a=2,b=2 and f(m)=1, giving S(m)=Θ(m).

3. Substituting back gives T(n)=Θ(log n), option B. The recursion depth is only Θ(log log n), but each level branches into twice as many subproblems. Counting depth alone misses the total work.

Original paper, page 11 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 38, GATE 2017: For positive n, C code executes: for(i=1;i<=n;i++){ for(j=1;j<n;j+=i){ printf(" %d %d",i,j); } }. Find its Θ time complexity, treating each iteration/output as unit cost. A:Θ(n√n). B:Θ(n²). C:Θ(n log n). D:Θ(n² log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Fix i. The inner-loop j values are 1,1+i,1+2i,… below n, so there are ceil((n-1)/i) iterations. The step size is i, not 1; different outer-loop iterations therefore have different costs.

2. Sum over i=1,…,n. Ignoring rounding gives (n-1)Σ1/i=(n-1)Hn. Rounding adds at most n operations, and Hn=Θ(log n), so the total is Θ(n log n).

3. The outer-loop overhead is only Θ(n) and does not change the result, giving C. This is the conventional unit-cost model used by the question. Counting the individual decimal digits written by printf, or fixed-width integer overflow at extreme n, would be a different analysis from the intended asymptotic loop count.

Original paper, page 14 · Answer key

2 marks · NAT
Report issue

Asymptotic Analysis & Recurrences

Question 39, GATE 2016: A recursive flowchart starts with A(n/2), then branches. Left: call A(n/2), return. Right: call A(n/2) twice, then branch to return or call A(n/2) and branch again to return or one final A(n/2) then return. All other work is O(1); assume a constant-size base case and attainable recursive worst branches. Find the least α for worst-case O(n^α), to two decimals.
Tap to enlarge
Answer & solution

Official answer: 2.2 : 2.4

Our answer: log₂5 ≈2.32

Assuming the displayed worst branch can recur and a constant-size base case, T(n)=5T(n/2)+O(1), yielding Theta(nlog₂5). The least exponent islog₂5≈2.32; the official accepted interval 2.2 : 2.4 is preserved.

Only calls on a single executed control-flow path are added. The two alternative exits must not both be counted. At recursion level j, the worst-case tree has 5j calls of size n/2j; after log₂n levels it has 5log₂n=nlog₂5 leaves. This yields the exponent without mistaking five sequential calls for five levels of recursion.

Original paper, page 36 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 64, GATE 2015: C function: int fun1(int n){int i,j,k,p,q=0;for(i=1;i<n;++i){p=0;for(j=n;j>1;j=j/2)++p;for(k=1;k<p;k=k*2)++q;}return q;}. Which most closely approximates its return value? A n³; B n(log n)²; C n log n; D n log(log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The first inner loop computes p≈log₂n but never increments q. The second loop increments q for k=1,2,4,… below p, about log₂p times. Multiplying by n−1 outer iterations gives Θ(n log log n). This asks for the returned number, not running time: computing p itself costs Θ(log n) each iteration, so the code's runtime is Θ(n log n). Mathematical asymptotics assume integers do not overflow.

Solution: The outer loop runs n−1 times. Repeated integer halving of j from n until≤1 gives p=floor(log₂n). Doubling k from 1 while k<p increments q ceil(log₂p) times when p≥1. Thus for sufficiently large n the return value is(n−1)*ceil(log₂ floor(log₂n))=Θ(n log log n), D. This is the mathematical count under no-overflow arithmetic; q can overflow a fixed-width int for sufficiently large inputs.

Original paper, page 24 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 20, GATE 2015: Let X=Σ(i³), i=0,...,n. Which asymptotic descriptions of X are valid? I: Θ(n⁴); II: Θ(n⁵); III: O(n⁵); IV: Ω(n³). Options: (A) only I; (B) only II; (C) I or III or IV, but not II; (D) II or III or IV, but not I.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. The exact polynomial is n⁴/4+n³/2+n²/4. Its leading term supplies a two-sided Θ(n⁴) bound; a looser upper bound n⁵ and looser lower bound n³ remain valid, whereas a two-sided n⁵ bound does not.

2. Sum(i³, i=0..n)=[n(n+1)/2]²=Θ(n⁴). It is consequently O(n⁵) and Ω(n³), but not Θ(n⁵). Thus I, III, IV, C; equality to an asymptotic class is conventional membership notation.

Original paper, page 60 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 64, GATE 2015: Let f(n)=n and g(n)=n^(1+sin n), for positive integers n, with sine measured in radians. Which asymptotic statements hold? I: f(n)=O(g(n)); II: f(n)=Ω(g(n)). Options: (A) I only; (B) II only; (C) both; (D) neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

1. The ratio g(n)/f(n)=nsin n.

2. Since1/(2π) is irrational, integer n modulo 2π is dense, and every tail is dense. There are therefore arbitrarily large n with sin n≥1/2 and arbitrarily large n with sin n≤−1/2. Along the former subsequence g/f≥sqrt(n) is unbounded, ruling out f=Ω(g); along the latter f/g≥sqrt(n) is unbounded, ruling out f=O(g). Thus neither statement holds, D, with sine in radians.

Original paper, page 78 · Answer key

2 marks · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 42, GATE 2014: Pseudocode sets D=2, then loops i=1..n, j=i..n, k=j+1..n, performing D=D*3 once per innermost iteration. How many multiplications occur? A: Half the product of three consecutive integers. B: One-third the product of three consecutive integers. C: One-sixth the product of three consecutive integers. D: None of these.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Method and setup. Count valid index triples rather than estimating every loop as n iterations. For a fixed j, index i can take j values and k can take n−j values. Multiplying those independent choices and summing over j gives an exact count; the assignment D=2 performs no multiplication.

2. Work through the result and its assumptions. For each middle index j there are j choices of i and n−j choices of k. The number of multiplications is sum(j=1..n)j(n−j)=n·n(n+1)/2−n(n+1)(2n+1)/6=(n−1)n(n+1)/6, one-sixth the product of three consecutive integers, C.

Original paper, page 18 · Answer key

1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 13, GATE 2014: Solve asymptotically T(n)=2T(n/2)+log n with T(1)=1. A Θ(n); B Θ(n log n); C Θ(n²); D Θ(log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Set up the reasoning. Apply the Master theorem with a=2 and b=2: nlogb a=n. The extra work log n grows polynomially more slowly than n, for example log n=O(n1/2).

2. Derive the result. For T(n)=2T(n/2)+log n, the leaf contribution is n. At level i, extra cost is 2i(log₂n−i); its total over levels is O(n). Equivalently log n is polynomially smaller than n in the Master theorem. Therefore T(n)=Θ(n), A.

3. Check the interpretation. There are n constant-cost leaves, which already force an Ω(n) lower bound. The logarithmic work is not multiplied by n at every level; subproblem sizes shrink, and summing the level costs gives O(n).

Original paper, page 32 · Answer key

2 marks · MCQ
Report issue

Amortized cost of MultiDequeue

Asymptotic Analysis & Recurrences

Question 44, GATE 2013: Besides constant-time Enqueue/Dequeue, MultiDequeue sets m=k and repeatedly dequeues while the queue is nonempty and m>0, decrementing m. Starting with an empty queue, find worst-case total time for n top-level operations: AΘ(n), BΘ(n+k), CΘ(nk), DΘ(n²).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Let E be the number of Enqueue operations among the n top-level operations. Starting from an empty queue, at most E elements can be removed in total, whether by individual Dequeue calls or inside MultiDequeue. Therefore all successful inner-loop iterations together cost O(E)⊆O(n), not O(nk). Each top-level call and each terminating loop check contribute O(1), adding O(n). Conversely, n calls incur Ω(n) total overhead, and n Enqueue calls witness that bound. The worst-case total is Θ(n), option A, assuming constant-time primitive queue operations and constant-time arithmetic on the counter.

Charge every actual deletion to the earlier insertion that supplied that element. Since an element cannot be deleted twice without being inserted again, the total number of successful dequeues is no larger than the number of Enqueue operations, at most n. MultiDequeue also performs one final failing guard check, but there are at most n top-level calls to pay for those checks. This accounting bounds the complete sequence by a constant times n regardless of k. Multiplying the worst cost of one call by n would ignore the initially empty queue and double-count available elements.

Original paper, page 10 · Answer key

1 mark · MCQ
Report issue

Towers of Hanoi recurrence

Asymptotic Analysis & Recurrences

Question 16, GATE 2012: The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with
        n discs is
        (A) T(n) = 2T(n − 2) + 2                         (B) T(n) = 2T(n − 1) + n
        (C) T(n) = 2T(n/2) + 1                           (D) T(n) = 2T(n − 1) + 1
Tap to enlarge
Your answer
Answer & solution

Official answer: D

To move n discs, first move the top n−1 discs to the spare peg, move the largest disc once, then move those n−1 discs onto it. These two subproblems cannot be avoided in an optimal solution. Thus T(n)=2T(n−1)+1 with T(0)=0, yielding 2n−1 moves. Hence D.

Check: The largest disc cannot move until all n−1 smaller discs are off it, and afterward those smaller discs must be transferred onto it. With T(1)=1, the recurrence yields T(2)=3 and T(3)=7, consistent with 2n−1.

Original paper, page 4 · Answer key

1 mark · MCQ
Report issue

Average time compared with worst-case time

Asymptotic Analysis & Recurrences

Question 18, GATE 2012: Let W(n) and A(n) denote respectively, the worst case and average case running time of an
        algorithm executed on an input of size n. Which of the following is ALWAYS TRUE?
        (A) A(n) = Ω(W(n))                              (B) A(n) = Θ (W(n))
        (C) A(n) = O (W(n))                              (D) A(n) = o (W(n))
Tap to enlarge
Your answer
Answer & solution

Official answer: C

At a fixed input size, each running time is at most the maximum W(n). Taking an expectation over any input distribution preserves the inequality A(n)≤W(n). Hence A(n)=O(W(n)), C. Equality in order can occur, ruling out an always-strict little-o claim; no matching lower bound is guaranteed.

Check: Average time depends on a distribution; worst-case time does not. If every input takes n steps then A=W=n, disproving an unconditional o bound. If a rare expensive input exists, the average can be much smaller, disproving an unconditional Θ bound.

Original paper, page 4 · Answer key

2 marks · MCQ
Report issue

Ordering polynomial quasipolynomial exponential growth

Asymptotic Analysis & Recurrences

Question 37, GATE 2011: Order these functions by increasing asymptotic growth: f1(n)=2^n; f2(n)=n^(3/2); f3(n)=n log2 n; f4(n)=n^(log2 n).

(A) f3,f2,f4,f1
(B) f3,f2,f1,f4
(C) f2,f3,f1,f4
(D) f2,f3,f4,f1
Tap to enlarge
Your answer
Answer & solution

Official answer: A

n log n grows slower than n3/2. The function nlog2 n=2^((log2 n)²) eventually exceeds every fixed power of n, but is smaller than 2n since(log2 n)²=o(n). Hence f3<f2<f4<f1 asymptotically, A.

Pairwise ratios justify the ordering beyond a few sample values. f3/f2=(log2 n)/√n tends to zero. Taking logarithms, log2(f4/f2)=(log2 n)²-(3/2)log2 n tends to infinity. Finally log2(f4/f1)=(log2 n)²-n tends to minus infinity. Thus the quasipolynomial sits above every fixed-degree polynomial but below the exponential. Finite small-n ties or reversals do not affect an asymptotic comparison.

Original paper, page 10 · Answer key

1 mark · MCQ
Report issue

Comparing quadratic and log-linear costs

Asymptotic Analysis & Recurrences

Question 12, GATE 2010: A database contains 10^k records. To process n records, package A takes 0.0001n² time units and B takes 10n log₁₀n time units. What is the smallest offered value of k for which B is preferred to A?
Options: (A) 12; (B) 10; (C) 6; (D) 5.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Put n=10k. Package B is faster when 10·10k·k < 0.0001·102k, equivalently 10k−5>k. At k=5 this is 1>5, false; at k=6 it is 10>6, true. For positive integer k≤5, 10k−5≤1≤k, so 6 is the smallest positive integer exponent, C. The meaningful growing-database interpretation excludes the degenerate n=1 case k=0.

The inequality compares actual running-time formulas, not only asymptotic orders. At k=5, A=106 and B=5×106 time units, so A wins. At k=6, A=108 and B=6×107, so B wins. This illustrates why the smaller-growth algorithm need not be faster at small inputs when its constant factor is much larger.

Original paper, page 3

2 marks · MCQ
Report issue

Geometric-sum recurrence

Asymptotic Analysis & Recurrences

Question 35, GATE 2009: T(n)=n for n≤3, otherwise T(n)=T(n/3)+cn with fixed c>0. Which growth rate? A Θ(n); B Θ(n log n); C Θ(n²); D Θ(n² log n).
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Expanding T(n)=T(n/3)+cn gives cn+cn/3+cn/9+... plus a constant-size base case. For fixed positive c this is bounded above by(3c/2)n+O(1) and below by cn. Hence Θ(n), A, with routine integer rounding not changing the asymptotic result.

The recursion tree has only one child, whose size shrinks by 3. Work by level is cn, cn/3, cn/9, … . The geometric sum is below cn/(1−1/3)=1.5cn, while the root alone contributes cn. These upper and lower linear bounds establish Θ(n). The depth is logarithmic, but multiplying n by that depth overcounts because work per level decreases rather than remaining n.

Original paper, page 8

2 marks · MCQ
Report issue

Factorial versus exponential and quasipolynomial

Asymptotic Analysis & Recurrences

Question 39, GATE 2008: Let f(n)=2^n, g(n)=n!, h(n)=n^(log n). Which asymptotic statement is true?

(A) f=O(g); g=O(h)
(B) f=Ω(g); g=O(h)
(C) g=O(f); h=O(f)
(D) h=O(f); g=Ω(f)
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Compare logarithms, which preserve growth order for positive functions. log h=(log n)² up to base constants; log f=Θ(n). Since (log n)²=o(n), h grows slower than f.
2. Stirling gives log(n!)=n log n−n+O(log n), which grows faster than n. Thus f grows slower than g.
3. Therefore h=O(f) and g=Ω(f), D.

Original paper, page 7

2 marks · MCQ
Report issue

Recursive versus iterative recurrence runtime

Asymptotic Analysis & Recurrences

Question 74, GATE 2008: Consider these C functions, assuming valid array bounds and the intended unit-cost arithmetic model:
int f1(int n) {
 if(n==0 || n==1) return n;
 else return 2*f1(n-1)+3*f1(n-2);
}
int f2(int n) {
 int i; int X[N],Y[N],Z[N];
 X[0]=Y[0]=Z[0]=0;
 X[1]=1; Y[1]=2; Z[1]=3;
 for(i=2;i<=n;i++) {
  X[i]=Y[i-1]+Z[i-2];
  Y[i]=2*X[i]; Z[i]=3*X[i];
 }
 return X[n];
}
What are the running times of f1(n) and f2(n), respectively?

(A) Θ(n),Θ(n)
(B) Θ(2^n),Θ(n)
(C) Θ(n),Θ(2^n)
(D) Θ(2^n),Θ(2^n)
Question 74, GATE 2008: Consider these C functions, assuming valid array bounds and the intended unit-cost arithmetic model:
int f1(int n) {
 if(n==0 || n==1) return n;
 else return 2*f1(n-1)+3*f1(n-2);
}
int f2(int n) {
 int i; int X[N],Y[N],Z[N];
 X[0]=Y[0]=Z[0]=0;
 X[1]=1; Y[1]=2; Z[1]=3;
 for(i=2;i<=n;i++) {
  X[i]=Y[i-1]+Z[i-2];
  Y[i]=2*X[i]; Z[i]=3*X[i];
 }
 return X[n];
}
What are the running times of f1(n) and f2(n), respectively?

(A) Θ(n),Θ(n)
(B) Θ(2^n),Θ(n)
(C) Θ(n),Θ(2^n)
(D) Θ(2^n),Θ(2^n)
Tap to enlarge
Your answer
Answer & solution

Answer: No exact option; B is the apparent intended choice (no official key was published)

1. The recursive function makes one call on n−1 and one on n−2; coefficients 2 and 3 multiply the returned values and do not multiply the number of calls. Thus T(n)=T(n−1)+T(n−2)+Θ(1), giving Θ(φn), where φ=(1+√5)/2.
2. The iterative f2 executes n−1 constant-time iterations, Θ(n). None of the printed options gives Θ(φn),Θ(n).
3. Option B prints Θ(2n),Θ(n), which supplies an exponential upper bound but falsely labels it tight Θ. This analysis assumes unit-cost bounded-size arithmetic and n within valid array bounds; unbounded n in actual C would also encounter overflow.

Original paper, page 16

2 marks · MCQ
Report issue

Worst-case recursion depth of Euclid algorithm

Asymptotic Analysis & Recurrences

Question 44, GATE 2007: For the following source C-style function with n≥m, how many recursive calls are made?
int gcd(n,m) {
    if(n % m == 0) return m;
    n = n % m;
    return gcd(m,n);
}
The source does not explicitly say worst case or m>0; state those assumptions in interpreting the options.
Options:
(A) Θ(log₂ n)
(B) Ω(n)
(C) Θ(log₂ log₂ n)
(D) Θ(√n)
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Approach. This is Euclid’s algorithm. An upper bound comes from a constant-factor size reduction within two calls; a tight worst-case lower bound comes from consecutive Fibonacci arguments.

2. Derivation and interpretation. For positive integers n≥m>0, Euclid replaces (n,m) by (m,n mod m). Within two recursive steps the larger argument decreases by at least a factor of two, so there are O(log n) recursive calls. Consecutive Fibonacci inputs attain a matching lower bound: their quotients are one for most steps, and Fk grows exponentially in k, giving Θ(log n) calls in the worst case (A). The statement does not say worst case: when m divides n, there are zero recursive calls. Therefore Θ(log n) is not a pointwise bound for every input satisfying n≥m. Positive m is also necessary to avoid remainder by zero.

Original paper, page 10

2 marks · MCQ
Report issue

Recursion repeatedly taking the square root

Asymptotic Analysis & Recurrences

Question 45, GATE 2007: What is the time complexity of this recursive function, with unit-cost arithmetic and square root?
int DoSomething(int n) {
    if(n<=2) return 1;
    else return DoSomething(floor(sqrt(n))) + n;
}
Options:
(A) Θ(n²)
(B) Θ(n log₂ n)
(C) Θ(log₂ n)
(D) Θ(log₂ log₂ n)
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Approach. The function makes one recursive call, not n calls. Each square root halves the logarithm of the argument, so analyze the recursion in terms of log n.

2. Derivation and interpretation. Assuming unit-cost integer arithmetic and square root as intended, T(n)=T(floor(sqrt(n)))+Θ(1). After k reductions the argument is approximately n1/2^k, and reaches a constant when 2k=Θ(log n). Thus k=Θ(log log n), giving D. Adding n to the returned value is one arithmetic operation, not n operations; floors change only constant-level stopping details.

Original paper, page 10

2 marks · MCQ
Report issue

Bounds on the trial-division primality loop

Asymptotic Analysis & Recurrences

Question 51, GATE 2007: For the following printed C fragment, T(n) counts for-loop executions on input n. Which asymptotic bounds are intended?
int IsPrime(n) {
    int i,n;
    for(i=2;i<=sqrt(n);i++)
        if(n%i==0) { printf("Not Prime\n"); return 0; }
    return 1;
}
The source redeclares n; interpret the intended divisor-testing algorithm separately from literal C validity.
Options:
(A) O(√n) and Ω(√n)
(B) O(√n) and Ω(1)
(C) O(n) and Ω(√n)
(D) None of these
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. A uniform lower bound must apply to easy inputs too. Even numbers terminate at i=2, whereas prime numbers make the loop test all candidate divisors through floor(√n).

2. Derivation and interpretation. Under the intended interpretation that n is the positive input integer, at most floor(sqrt(n))−1 candidate divisors are tested, so T(n)=O(sqrt(n)). For even n≥4, the first divisor i=2 causes immediate return, so T(n)=1 on an unbounded input family and no uniform Ω(sqrt(n)) lower bound is valid. For all sufficiently large n at least one iteration occurs, establishing Ω(1); B is therefore the intended answer. Prime n attain Θ(sqrt(n)). Source caveat: the printed function uses old-style IsPrime(n) and then declares int i,n inside its body, redeclaring its parameter n in the same scope. This is not valid C as printed; the algorithmic answer requires repairing the parameter declaration/removing the duplicate local n.

Original paper, page 12

1 mark · MCQ
Report issue

Horner's rule evaluation

Asymptotic Analysis & Recurrences

Question 1, GATE 2006: For nonzero coefficients a₀,…,a₃, consider p(x)=a₀+a₁x+a₂x²+a₃x³. What is the minimum multiplication count for evaluating p at x? This is the GFG cubic reading; GateForum prints a₃x² instead, and neither source explicitly says generic coefficients.
Options:
(A) 3
(B) 4
(C) 6
(D) 9
Tap to enlarge
Your answer
Answer & solution

Answer: A for generic cubic coefficients (no official key was published)

1. The the paper displays a cubic: p=a0+x(a1+x(a2+a3x)). Horner evaluation uses three multiplications and three additions, giving A under the conventional generic-coefficient evaluation model.

2. Nonzero coefficients alone also do not rule out special simplifications, for example (x+1)3 uses two multiplications after forming x+1.

3. Thus three is the standard generic cubic cost, not a universal lower bound for every coefficient choice. Original official wording and key remain unavailable.

4. Teaching check: Evaluate the nested form from the inside: t=a₃x+a₂, then t=tx+a₁, then p=tx+a₀. Each stage contributes one multiplication. The answer depends on treating the cubic as a generic polynomial; it is not a theorem about every particular nonzero coefficient tuple.

Original paper, page 1

2 marks · MCQ
Report issue

Square-root divide-and-conquer recurrence

Asymptotic Analysis & Recurrences

Question 51, GATE 2006: For integers n>1, T(n)=2T(⌊√n⌋)+1 and T(1)=1. What is the asymptotic growth?
Options:
(A) Θ(log log n)
(B) Θ(log n)
(C) Θ(√n)
(D) Θ(n)
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. After h repeated floor-square-root steps, the subproblem size is floor(n1/2^h). For n≥2 it first reaches 1 when n<22^h, so h=floor(log₂(log₂ n))+1.

2. The recurrence tree is a full binary tree of height h. Every node contributes one, including the T(1)=1 leaves, so T(n)=2h+1−1. Because log₂ n<2h≤2 log₂ n, this is Θ(log n), option B.

3. Teaching check: The depth is Θ(log log n), but exponentiating that Θ statement alone would not justify Θ(log n). The sharper h=log₂(log₂ n)+O(1) bound controls the number of leaves within constant factors. Floor rounding is included explicitly and ensures termination at the stated base case.

Original paper, page 7

2 marks · MCQ
Report issue

False bound for a divide-and-conquer recurrence

Asymptotic Analysis & Recurrences

Question 37, GATE 2005: T(n)=2T(n/2)+n, with T(0)=T(1)=1. Which claim is false? A O(n²); B Θ(n log n); C Ω(n²); D O(n log n).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

For n=2k, dividing by n gives T(n)/n=T(n/2)/(n/2)+1, so T(n)=n(1+log2 n). Standard rounding of subproblem sizes preserves Θ(n log n). Therefore O(n²), Θ(n log n), and O(n log n) hold, but Ω(n²) does not, C, since(n log n)/n²→0.

For powers of two, each recursion level contributes n and there are log₂n nontrivial levels plus linear total base cost. Thus T(n)=n(1+log₂n), giving Θ(n log n). This is bounded above by n² but not below by a positive constant times n², since log n/n tends to zero. Hence the false bound is C. A loose upper bound can still be true even when it is not tight.

Original paper, page 5

2 marks · MCQ
Report issue

Space used by repeated recursive calls

Asymptotic Analysis & Recurrences

Question 81a, GATE 2005: double foo(int n){int i;double sum;if(n==0)return 1.0;sum=0.0;for(i=0;i<n;i++)sum+=foo(i);return sum;} Printed 81(a): maximum auxiliary space of foo(n)? A O(1); B O(n); C O(n!); D O(n^n). Seek intended tight order, not merely any loose upper bound.
Question 81a, GATE 2005: double foo(int n){int i;double sum;if(n==0)return 1.0;sum=0.0;for(i=0;i<n;i++)sum+=foo(i);return sum;} Printed 81(a): maximum auxiliary space of foo(n)? A O(1); B O(n); C O(n!); D O(n^n). Seek intended tight order, not merely any loose upper bound.
Question 81a, GATE 2005: double foo(int n){int i;double sum;if(n==0)return 1.0;sum=0.0;for(i=0;i<n;i++)sum+=foo(i);return sum;} Printed 81(a): maximum auxiliary space of foo(n)? A O(1); B O(n); C O(n!); D O(n^n). Seek intended tight order, not merely any loose upper bound.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Every activation stores only a constant number of locals, but calls are nested. A path foo(n)→foo(n−1)→…→foo(0) reaches n+1 simultaneous activations. The loop calls execute sequentially, so the exponentially many calls are not all live at once. Maximum stack space is Θ(n), option B.

Count simultaneously live activations, not total recursive calls. During its last recursive branch, foo(n) may be suspended while foo(n−1), foo(n−2),…, foo(0) are active, giving linear depth. Each frame contains only a constant number of scalar locals. Separate loop iterations return before the next call, so their storage is reused. This distinguishes linear stack space from exponential running time. Larger Big-O choices are also loose bounds; the intended answer describes the tight growth.

Original paper, page 11

2 marks · MCQ
Report issue

Matrix layout and asymptotic multiplication cost

Asymptotic Analysis & Recurrences

Question 39, GATE 2004: Matrices M1,M2 are stored in arrays A,B respectively. Each may use row-major or column-major contiguous storage. How does this affect the time complexity of a fixed algorithm computing M1×M2?
Options:
(A) Best when A is row-major and B column-major
(B) Best when both are row-major
(C) Best when both are column-major
(D) Independent of storage scheme
Question 39, GATE 2004: Matrices M1,M2 are stored in arrays A,B respectively. Each may use row-major or column-major contiguous storage. How does this affect the time complexity of a fixed algorithm computing M1×M2?
Options:
(A) Best when A is row-major and B column-major
(B) Best when both are row-major
(C) Best when both are column-major
(D) Independent of storage scheme
Tap to enlarge
Your answer
Answer & solution

Answer: D under a unit-cost RAM model (no official key was published)

1. Changing row-major to column-major storage changes the address formula, not the number of arithmetic operations or constant-time element accesses. Thus asymptotic running time for a fixed multiplication algorithm is independent of the layout, D.

2. For the usual i,j,k loop order, A-row-major/B-column-major can improve locality and elapsed time, but that is a cache-performance distinction rather than an asymptotic RAM-operation count.

3. Teaching check: For an r×c row-major array, address(i,j) uses ic+j; column-major uses jr+i. Both formulas take constant time under a unit-cost RAM model. Cache misses may differ dramatically, but that does not by itself alter a fixed algorithm’s asymptotic arithmetic/access count.

Original paper, page 5

2 marks · MCQ
Report issue

Amortized cost of processing runs of ones

Asymptotic Analysis & Recurrences

Question 82, GATE 2004: A[1..n] stores bits. Function f(m) takes Θ(m) time for positive m, with constant bookkeeping for m=0. What is the complexity of:
counter=0;
for(i=1;i<=n;i++) {
  if(A[i]==1) counter++;
  else { f(counter); counter=0; }
}
Option D is little-o in the clearer GateForum reproduction.
Options:
(A) Ω(n²)
(B) Ω(n log n) and O(n²)
(C) Θ(n)
(D) o(n)
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The counter measures the current consecutive run of ones. A zero invokes f on that run length and then resets the counter.

2. The lengths passed to all calls sum to at most n, because no position containing one belongs to two completed runs. Thus all calls together take O(n), including O(1) bookkeeping for zero-length runs, while the loop itself always performs n iterations and costs Ω(n).

3. Total complexity is Θ(n), C. A final run without a trailing zero does not increase this bound.

4. Teaching check: Charge each unit of f’s linear work to one of the ones in its completed run. No one belongs to two runs, so total charged work is linear. The always-executed loop supplies the matching linear lower bound; little-o(n) cannot describe it.

Original paper, page 11

2 marks · MCQ
Report issue

Cost of duplicated recursive calls

Asymptotic Analysis & Recurrences

Question 83, GATE 2004: For positive integer n, find the time complexity of:
int recursive(int n) {
  if(n==1) return 1;
  else return recursive(n-1)+recursive(n-1);
}
Use the ordinary execution model without memoization; the source prose says “a>0” although the code parameter is n.
Options:
(A) O(n)
(B) O(n log n)
(C) O(n²)
(D) O(2^n)
Question 83, GATE 2004: For positive integer n, find the time complexity of:
int recursive(int n) {
  if(n==1) return 1;
  else return recursive(n-1)+recursive(n-1);
}
Use the ordinary execution model without memoization; the source prose says “a>0” although the code parameter is n.
Options:
(A) O(n)
(B) O(n log n)
(C) O(n²)
(D) O(2^n)
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. For positive integer n, each nonbase invocation makes two independent calls at n−1. With the usual unit-cost model and no memoization, T(n)=2T(n−1)+Θ(1), T(1)=Θ(1).

2. The recursion tree has 2n−1 leaves and 2n−1 total calls, yielding Θ(2n), and hence D. The identical arguments do not make the two evaluations a single call in this abstract execution model; integer overflow and compiler transformations are outside the model.

3. Teaching check: At recursion depth k there are 2k calls, until depth n−1. Adding the geometric series gives 2n−1 calls. The depth is only n, but depth alone is not total work when the recursion branches.

Original paper, page 12

2 marks · MCQ
Report issue

Solve a linear nonhomogeneous recurrence

Asymptotic Analysis & Recurrences

Question 84, GATE 2004: Solve T(1)=1 and T(n)=2T(n−1)+n for n≥2. The sign is plus in the rendered sources, despite faulty text extraction.
Options:
(A) 2^(n+1)−n−2
(B) 2^n−n
(C) 2^(n+1)−2n−2
(D) 2^n+n
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. The rendered recurrence is T(1)=1 and T(n)=2T(n−1)+n. A particular solution is −n−2, so T(n)=C·2n−n−2.

2. Using T(1)=1 gives 2C−3=1 and C=2. Therefore T(n)=2n+1−n−2, A.

3. Direct substitution gives 2[2n−(n−1)−2]+n=2n+1−n−2.

4. Teaching check: An alternative transformation is U(n)=T(n)+n+2. Then U(n)=2U(n−1), U(1)=4, so U(n)=2n+1. Subtract n+2 to recover T(n); this directly verifies the affine particular solution.

Original paper, page 12

2 marks · MCQ
Report issue

Total smaller-subtree cost in a balanced tree

Asymptotic Analysis & Recurrences

Question 85, GATE 2004: A program visits every node x of a balanced binary search tree with n leaves, computing g(x). The cost at x is min(number of leaves in x’s left subtree,number in x’s right subtree). What is worst-case total time?
Options:
(A) Θ(n)
(B) Θ(n log n)
(C) Θ(n²)
(D) Θ(n² log n)
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. In a perfect balanced tree with n leaves, the root costs n/2, the two children together cost n/2, and every internal level similarly costs n/2. There are log2 n internal levels, so this supplies a Θ(n log n) worst-case lower bound.

2. For any balanced tree, at each depth the subtrees are disjoint and the sum of their leaf counts is at most n; summing min(left leaves,right leaves) at that depth is at most n/2. Height O(log n) gives O(n log n), with traversal overhead O(n).

3. Thus worst-case Θ(n log n), B, assuming the usual balanced binary-tree model.

4. Teaching check: For n=8 in a perfect tree, the root cost is 4, the next level totals 4 and the next totals 4, giving 12 before traversal bookkeeping. Each internal level contributes n/2, and there are log2 n such levels. Counting only the root misses the repeated per-level work.

Original paper, page 12

1 mark · MCQ
Report issue

Polynomial shifts and exponential bounds

Asymptotic Analysis & Recurrences

Question 20, GATE 2003: Which asymptotic claims are correct? I. (n+k)^m=Θ(n^m) for fixed constants k,m; II. 2^(n+1)=O(2^n); III. 2^(2n)=O(2^n) in GFG; GateForum instead shows 2^(2n+1)=O(2^n). Both claims have the same false truth value. A. I and II; B. I and III; C. II and III; D. I, II and III.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Test big-O claims by ratios. A bounded positive ratio suffices for O; a ratio bounded away from zero as well establishes Θ. Doubling the exponent is not multiplying the result by a constant: 22n=(2n)². This is the specific error behind claim III.

2. For fixed k,m, ((n+k)m)/(nm)=(1+k/n)m tends to 1, so I holds.2n+1=2·2n, so II holds. But 22 n/2n=2n is unbounded, so III fails. Thus I and II only, A.

Original paper, page 3

2 marks · MCQ
Report issue

Summing integer square-root increments

Asymptotic Analysis & Recurrences

Question 35, GATE 2003: Given T(1)=1, find T(m²) for integer m≥1. GFG prints T(n+1)=T(n)+floor(sqrt(n−1)), n≥1; GateForum instead prints floor(sqrt(n+1)). Preserve both versions. Options: A. (m/6)(21m−39)+4; B. (m/6)(4m²−3m+5); C. (m/2)(3m^(2.5)−11m+20)−5; D. (m/6)(5m³−34m²+137m−104)+5/6.
Question 35, GATE 2003: Given T(1)=1, find T(m²) for integer m≥1. GFG prints T(n+1)=T(n)+floor(sqrt(n−1)), n≥1; GateForum instead prints floor(sqrt(n+1)). Preserve both versions. Options: A. (m/6)(21m−39)+4; B. (m/6)(4m²−3m+5); C. (m/2)(3m^(2.5)−11m+20)−5; D. (m/6)(5m³−34m²+137m−104)+5/6.
Tap to enlarge
Your answer
Answer & solution

Answer: As printed (n−1) the value differs from the options; B holds for the n+1 recurrence (no official key was published)

1. In the block k²≤j<(k+1)² the value is k and the block length is 2k+1. Use sum k=(m−1)m/2 and sum k²=(m−1)m(2m−1)/6 to simplify. The shifted range omits the final terms m and m−1 and adds the initial 1, explaining the difference −2m+2.

2. For the latter, T(m²)=sum_(j=1)m²floor(sqrt(j)). Group j from k² through(k+1)²−1: for k<m there are 2 k+1 copies of k, followed by the final m. Hence sum_(k=1)m−1k(2 k+1)+m=m(4 m²−3 m+5)/6, option B. Literal the paper instead gives 1+sum_(j=0)m²−2floor(sqrt(j))=m(4 m²−3 m+5)/6−2 m+2, including m=1. These are not silently equated; original wording/key are needed to resolve the source discrepancy.

Original paper, page 4

2 marks · MCQ
Report issue

Bit complexity of integer cube root

Asymptotic Analysis & Recurrences

Question 66, GATE 2003: The integer cube root of a natural number n is the largest natural m with m³≤n. The input n is represented in binary. Which describes its computation complexity?
A. O(n), but not O(n^0.5)
B. O(n^0.5), but not O((log n)^k) for any constant k>0
C. O((log n)^k) for some constant k>0, but not O((log log n)^m) for any constant m>0
D. O((log log n)^k) for some constant k>0.5, but not O((log log n)^0.5)
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The input length is b=floor(log2 n)+1; complexity in n and in the bit length b must not be confused.
2. Binary search the integer interval [0,n], retaining the largest tested m with m³≤n. Halving the interval takes O(log n)=O(b) iterations.
3. Using schoolbook arithmetic, a multiplication of O(b)-bit numbers costs O(b²); two multiplications form m³. Hence this explicit algorithm costs O(b³), polynomial in log n.
4. The output cube root has about b/3 bits, so even writing it costs Ω(b), which dominates every fixed power of log b. Thus a polynomial in log log n cannot suffice in the bit model, and C follows.

Solution: Let b be the number of input bits, so b=Theta(log n). Binary search for the largest m with m³≤n needs O(b) comparisons. Schoolbook multiplication computes a b-bit cube in O(b²) bit operations, giving an explicit O(b³) algorithm. The answer itself has Theta(b) bits for growing n, so writing it already requires Omega(b) bit operations. Thus the problem is polynomial in log n, but not polynomial in log log n, option C. This is a bit-complexity statement, not a unit-cost model for arbitrarily large integers.

Original paper, page 9

1 mark · MCQ
Report issue

Recurrence on powers of two

Asymptotic Analysis & Recurrences

Question 1.3, GATE 2002: Solve T(2^k) = 3T(2^(k−1)) + 1, with T(1) = 1.
(A) 2^k; (B) (3^(k+1)−1)/2; (C) 3^(log₂ k); (D) 2^(log₃ k).
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Remove the powers of two from the argument.

Step 2: Writing out S(1)=4, S(2)=13, S(3)=40 reveals the repeated multiply-by-three pattern. In general the homogeneous contribution is 3kS(0), while the added ones contribute 1+3+…+3k−1. Evaluating that geometric sum gives the stated formula; at k=0 it correctly returns1.

Conclusion: Put S(k)=T(2k). Then S(k)=3S(k−1)+1 with S(0)=1. Iteration gives 3k+sum_(j=0)k−13j=(3k+1−1)/2, B.

Original paper, page 1

2 marks · MCQ
Report issue

Repeated square-root recursion

Asymptotic Analysis & Recurrences

Question 2.11, GATE 2002: For procedure A(n), if n≤2 return 1; otherwise return A(⌈√n⌉). Which listed bound best describes its running time?
(A) O(n); (B) O(log n); (C) O(log log n); (D) O(1).
Question 2.11, GATE 2002: For procedure A(n), if n≤2 return 1; otherwise return A(⌈√n⌉). Which listed bound best describes its running time?
(A) O(n); (B) O(log n); (C) O(log log n); (D) O(1).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: Take logarithms of the argument shrinkage.

Step 2: Let m=log₂n. Taking a square root approximately halves m, so the recursion needs about log₂m halvings to make m constant. Therefore the number of constant-work calls is Θ(log log n). This count concerns runtime, not the returned value, which is always 1. Arbitrary-precision root computation would require a different per-call cost model.

Conclusion: Ignoring integer rounding initially, after k calls the argument is n1/2^k. It becomes bounded once 2k is of order log n, so the recursion depth is Θ(log log n). Ceiling rounding changes only constants, and the small integer arguments reach the base case. With constant-time root/rounding operations per call, C is the tight listed growth bound, even though looser O(n) and O(log n) bounds are also true.

Original paper, page 4

1 mark · MCQ
Report issue

Comparing polynomial and polylogarithmic factors

Asymptotic Analysis & Recurrences

Question 1.16, GATE 2001: Compare f(n)=n² lg n and g(n)=n(lg n)^10. Which asymptotic relationship holds: only f=O(g), only g=O(f), neither, or both?
Question 1.16, GATE 2001: Compare f(n)=n² lg n and g(n)=n(lg n)^10. Which asymptotic relationship holds: only f=O(g), only g=O(f), neither, or both?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Divide f(n)=n² lg n by g(n)=n(lg n)10. The ratio is n/(lg n)9.

Step 2: Put t=lg n, so the ratio becomes 2t/t9, which tends to infinity because an exponential dominates every fixed power of t.

Therefore g=O(f), while f is not O(g), giving B. The logarithmic factor with exponent 10 cannot compensate asymptotically for the additional factor n in f.

Original paper, page 2

2 marks · MCQ
Report issue

Asymptotic comparison using logarithmic identities

Asymptotic Analysis & Recurrences

Question 2.17, GATE 2000: Let f(n)=3n^(√n),g(n)=2^(√n log2 n),h(n)=n!. Which is true: h=O(f),h=O(g),g is not O(f),or f=O(g)?
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: Use 2log2 n=n to simplify g(n)=n√n. Hence f(n)=3g(n), so f and g are Θ-equivalent. This proves D and refutes the claim that g is not O(f).

Step 2: Factorial grows faster: n!≥(n/2)n/2, whose logarithm is(n/2)log(n/2), while log g=√n log n. Their ratio of logarithmic scales tends to infinity.

Thus h is neither O(f) nor O(g), leaving D.

Original paper, page 5

1 mark · MCQ
Report issue

Multiplications for a power of two

Asymptotic Analysis & Recurrences

Question 1.16, GATE 1999: For n a power of two, how many multiplications are minimally needed to compute a^n? Options log2 n, sqrt(n), n−1,n.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Write n=2k. Repeated squaring computes a²,a⁴,…,a2^k, using exactly k multiplications. To prove minimality in the ordinary multiplication-only straight-line model, observe that one multiplication can at most double the largest exponent already available. Starting with exponent 1, after t multiplications every computed exponent is at most 2t. Reaching n therefore requires t≥log2 n=k. Construction and lower bound coincide, giving A; n=1 needs zero multiplications.

Original paper, page 2

2 marks · MSQ
Report issue

Matching recurrence growth

Asymptotic Analysis & Recurrences

Question 2.21, GATE 1999: M:T(n)=T(n−1)+n; N:T(n)=T(n/2)+n; O:T(n)=T(n/2)+n log n; P:T(n)=T(n−1)+log n. Match to U O(n),V O(n log n),W O(n²),X O(log² n).
Tap to enlarge
Select all that apply
Answer & solution

Answer: B: M-W,N-U,O-V,P-V (no official key was published)

For M, summing 1+2+…+n gives Θ(n²). For N, the work is n+n/2+n/4+…=Θ(n). For O, the first term already gives n log n and the geometric weighted tail is O(n log n), hence Θ(n log n). For P, summing log k for k=2…n gives log(n!)=Θ(n log n): the upper bound is n log n and the last n/2 terms each exceed log(n/2). Thus M-W,N-U,O-V,P-V, option B. The listed big-O labels are interpreted as tight intended growth classes; loose upper bounds would not define a unique matching.

Original paper, page 5

3 marks · Descriptive
Report issue

Harmonic recurrence and its cost model

Asymptotic Analysis & Recurrences

Question 11(a), GATE 1999: Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation. GFG retains the O symbols lost in GateForum.

what(n):
    if n = 1: call A
    else:
        what(n-1)
        call B(n)

Assume n is a positive integer.
Question 11(a), GATE 1999: Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation. GFG retains the O symbols lost in GateForum.

what(n):
    if n = 1: call A
    else:
        what(n-1)
        call B(n)

Assume n is a positive integer.
Question 11(a), GATE 1999: Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation. GFG retains the O symbols lost in GateForum.

what(n):
    if n = 1: call A
    else:
        what(n-1)
        call B(n)

Assume n is a positive integer.
Tap to enlarge
Shared context

Given the algorithm below, with procedure A taking O(1) time and B(n) taking O(1/n) time, derive its time complexity in O-notation.

what(n):
if n = 1: call A
else:
what(n-1)
call B(n)

Assume n is a positive integer.

Answer & solution

Answer: Procedure-cost-only model: O(log n). With ordinary constant recursion/control overhead: Θ(n). (no official key was published)

In the idealized accounting suggested by the question, count only costs of A and B. Let their costs be a and b(k), with a=O(1) and b(k)=O(1/k). The recurrence is T(1)=a and T(n)=T(n−1)+b(n). Expanding gives T(n)=a+Σ(k=2..n)b(k)≤C₀+C₁Σ(k=2..n)1/k for suitable constants, absorbing finitely many small inputs into C₀.

The harmonic sum is bounded above by 1+ln n, by comparison with the integral of 1/x. Thus T(n)=O(log n). If the supplied procedure costs are actually Θ(1) and Θ(1/n), the lower integral bound gives Θ(log n), but upper bounds alone do not prove this tight classification.

Cost-model qualification: a real RAM implementation must perform a test, decrement, recursive call and return at each of n recursion levels. These contribute Θ(1) per level, giving T_RAM(n)=T_RAM(n−1)+Θ(1)+O(1/n)=Θ(n), with Θ(n) stack depth. Moreover a nonzero discrete instruction cost cannot asymptotically decrease as 1/n. Therefore O(log n) is the intended abstract procedure-cost result, not an unconditional full implementation running-time claim.

Original paper, page 7

2 marks · MCQ
Report issue

Recurrence dominated by leaf work

Asymptotic Analysis & Recurrences

Question 4.6, GATE 1997: T(1)=1 and T(n)=2T(floor (n/2))+sqrt (n) for n≥2. Choose O(sqrt n), O(n), O(log n), none.
Tap to enlarge
Your answer
Answer & solution

Answer: B: Θ(n) (no official key was published)

At recursion depth j there are roughly 2j subproblems of size n/2j. Their combined nonrecursive work is sqrt (n)·2j/2, increasing geometrically toward the leaves. Summing through depth about log 2 n gives O(n), and there are Θ(n) leaves each contributing constant work, providing Ω(n). Hence T(n)=Θ(n), so B. Equivalently the Master theorem has nlog 2 2=n and toll n1/2, which is polynomially smaller; rounding does not change the asymptotic order.

Original paper, page 4

1 mark · Descriptive
Report issue

Count recursive function activations

Asymptotic Analysis & Recurrences

Question 15(c), GATE 1997: For positive integers n,m, consider the directly recursive, nonmemoized function
function F(n,m:integer):integer;
begin
  if (n<=0) or (m<=0) then F:=1
  else F:=F(n-1,m)+F(n,m-1)
end.
Use C(s,t)=C(s−1,t)+C(s−1,t−1).
How many calls to F occur when evaluating F(n,m), including the original call?
Question 15(c), GATE 1997: For positive integers n,m, consider the directly recursive, nonmemoized function
function F(n,m:integer):integer;
begin
  if (n<=0) or (m<=0) then F:=1
  else F:=F(n-1,m)+F(n,m-1)
end.
Use C(s,t)=C(s−1,t)+C(s−1,t−1).
How many calls to F occur when evaluating F(n,m), including the original call?
Tap to enlarge
Answer & solution

Answer: 2C(n+m,n)−1. (no official key was published)

The execution forms a full binary recursion tree. Each nonbase call executes exactly two child calls, and each base call has no children. Every base call returns 1, while every internal call returns the sum of its two children's values. The root's return value is consequently the number L of leaf activations. From the recurrence solution, L=F(n,m)=C(n+m,n).

In a full binary tree with I internal nodes and L leaves, the number of edges is 2I because every internal node has two children. It is also I+L−1 because a tree has one fewer edge than nodes. Equating gives I=L−1, so the total number of call activations is I+L=2L−1. Therefore the requested count, including the root call, is

2C(n+m,n)−1.

For n=m=1, the root calls F(0,1) and F(1,0), giving three activations; the formula gives 2·2−1=3. For n=1,m=2 it gives five. If only calls initiated recursively were requested, one would subtract the original root and obtain 2C(n+m,n)−2, but that is not the wording here.

This counts the actual nonmemoized execution tree, including repeated argument pairs as separate calls. Counting only distinct states, or assuming a dynamic-programming implementation, would answer a different complexity question.

Original paper, page 8

1 mark · MCQ
Report issue

Comparing slowly growing functions

Asymptotic Analysis & Recurrences

Question 1.11, GATE 1996: Which asymptotic claim is false: (A) 100n log n=O(n log n/100); (B) sqrt(log n)=O(log log n); (C) for fixed 0<x<y, n^x=O(n^y); (D) 2^n is not O(n^k) for fixed k?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Put t=log n. Then sqrt(log n)/(log log n)=sqrt(t)/log t tends to infinity, so no constant bounds the numerator by a multiple of the denominator eventually. Hence B is false. Multiplying n log n by fixed nonzero constants does not change its big-O class. For fixed x<y, nx/ny=nx−y tends to zero. Finally 2n eventually dominates every fixed-degree polynomial nk: the logarithm of their ratio is n log 2−k log n, which tends to infinity. Thus D is true, not the false statement sought.

Original paper, page 2

2 marks · MCQ
Report issue

A divide-and-conquer recurrence

Asymptotic Analysis & Recurrences

Question 2.12, GATE 1996: Solve T(1)=2, T(n)=3T(n/4)+n asymptotically for powers of four.
Question 2.12, GATE 1996: Solve T(1)=2, T(n)=3T(n/4)+n asymptotically for powers of four.
Tap to enlarge
Your answer
Answer & solution

Answer: A: Θ(n) (no official key was published)

At recursion depth j there are 3j subproblems of size n/4j, so the total nonrecursive work is n(3/4)j. Summing these decreasing geometric terms gives O(n), while the root alone costs n and proves Ω(n). More exactly, with k=log₄ n, the leaves contribute 2·3k and internal levels contribute 4n(1−(3/4)k). The total is 4n−2nlog₄3. Therefore the recurrence is linear, not n log n, because each successive level contributes less work than the preceding one.

Original paper, page 5

Descriptive
Report issue

Evaluate a binomial recurrence

Asymptotic Analysis & Recurrences

Question 4(a), GATE 1995: GET(A,B)=1 if B=0; otherwise GET(A,B)=0 if A<B; otherwise GET(A−1,B)+GET(A−1,B−1). Find GET(3,2).
Tap to enlarge
Answer & solution

Answer: 3 (no official key was published)

Step through it (23 steps)

The base case with B=0 represents the single way to choose no elements. The A<B case represents the impossibility of choosing more elements than are available. The recursive case separates choices according to whether the last element is excluded or included; it is Pascal’s binomial recurrence.

Expand the requested call rather than assuming a closed form: GET(3,2)=GET(2,2)+GET(2,1). The first term is GET(1,2)+GET(1,1)=0+[GET(0,1)+GET(0,0)]=0+0+1=1. The second is GET(1,1)+GET(1,0)=1+1=2. Hence the result is 3, agreeing with the binomial coefficient C(3,2). The ordering of the tests matters at (0,0): B=0 is tested first and returns 1.

Original paper, page 6

Report issue

Piecewise functions and multiple big-O answers

Asymptotic Analysis & Recurrences

Question 1.23, GATE 1994: Eventually g1(n)=n² and g2(n)=n³; below fixed cutoffs the formulas differ. Assess A g1=O(g2), B g1=O(n³), C g2=O(g1) in GateForum but g2=O(g2) in GFG, D g2=O(n).
Tap to enlarge
Your answer
Answer & solution

Answer: A, B, C (no official key was published)

Big-O ignores any fixed finite prefix, so only the eventual n² and n³ behavior matters. Since n²≤n³ for n≥1, both A and B are true. C instead compares g2 with itself and is trivially true. Thus the paper supports a unique single-choice answer.

Original paper, page 3

2 marks · MSQ
Report issue

Summing big-O terms in a multiple-select item

Asymptotic Analysis & Recurrences

Question 8.7, GATE 1993: Classify Σ(k=1…n)O(n) among O(n),O(n²),O(n³),O(3n²),O(1.5n²).
Tap to enlarge
Select all that apply
Answer & solution

Answer: B,C,D,E under a uniform O(n) bound (no official key was published)

If each summand has magnitude at most Cn with the same constant C, the sum has magnitude at most Cn². Thus it belongs to O(n²),and constant factors 3 or 1.5 do not change that class. O(n³) is also a valid looser upper bound,so C must be selected in a literal multiple-select reading. O(n) is not guaranteed because n terms each equal to n sum to n². The notation needs a uniform bound over k: if hidden constants depend unboundedly on k, such as terms kn, the sum can instead be Θ(n³). Big-O is an upper-bound class,not an assertion of tightness.

Original paper, page 9

Descriptive
Report issue

Recurrence from nested loops

Asymptotic Analysis & Recurrences

Question 7(a), GATE 1992: The printed function initializes F1←1, tests n=1 and assigns F←3 in that case; otherwise it repeats i=1..n, setting C←0, incrementing C once for each j=1..F(n−1), then setting F1←F1*C. A final F←F1 appears after the loop, with ambiguous if/else grouping. n is positive. Derive a recurrence for the returned value F(n).
Question 7(a), GATE 1992: The printed function initializes F1←1, tests n=1 and assigns F←3 in that case; otherwise it repeats i=1..n, setting C←0, incrementing C once for each j=1..F(n−1), then setting F1←F1*C. A final F←F1 appears after the loop, with ambiguous if/else grouping. n is positive. Derive a recurrence for the returned value F(n).
Tap to enlarge
Answer & solution

Answer: Intended base-case-preserving reading: F(1)=3, F(n)=F(n−1)^n for n>1. Literal unconditional final assignment instead gives F(n)=1 for all n. (no official key was published)

First distinguish the function’s returned numerical value from its running time. In one outer iteration the inner loop increments C exactly F(n−1) times, so C=F(n−1). Starting from F1=1, the outer loop multiplies by that same value n times. Hence for n>1 the returned value is F(n)=∏[i=1..n] F(n−1)=[F(n−1)]n. The base is F(1)=3 if the base-case assignment is returned without being overwritten.

A block-explicit rendition of this intended reading is:

function F(n):
  if n=1 then return 3;
  F1:=1;
  for i:=1 to n do begin
    C:=0;
    for j:=1 to F(n−1) do C:=C+1;
    F1:=F1*C
  end;
  return F1.

This explains why neither n·F(n−1) (a sum) nor a runtime recurrence answers the value question. For instance F(2)=3²=9 and F(3)=9³=729.

The paper places a final F=F1 after the if/else loop without clearly enclosing it in the else branch. Under a literal Pascal-like reading with that assignment executed unconditionally, n=1 first sets F=3 but then overwrites it with the initial F1=1. The recurrence becomes F(1)=1, F(n)=F(n−1)n and all values are 1. The intended nontrivial recurrence therefore requires treating the final assignment as part of the else computation or returning immediately from the n=1 case.

Original paper, page 6

Descriptive
Report issue

Closed form of multiplicative recurrence

Asymptotic Analysis & Recurrences

Question 7(b), GATE 1992: The printed function initializes F1←1, tests n=1 and assigns F←3 in that case; otherwise it repeats i=1..n, setting C←0, incrementing C once for each j=1..F(n−1), then setting F1←F1*C. A final F←F1 appears after the loop, with ambiguous if/else grouping. n is positive. Solve the recurrence for a closed form.
Question 7(b), GATE 1992: The printed function initializes F1←1, tests n=1 and assigns F←3 in that case; otherwise it repeats i=1..n, setting C←0, incrementing C once for each j=1..F(n−1), then setting F1←F1*C. A final F←F1 appears after the loop, with ambiguous if/else grouping. n is positive. Solve the recurrence for a closed form.
Tap to enlarge
Answer & solution

Answer: Under intended base F(1)=3, F(n)=3^(n!). Under unconditional final-assignment reading, F(n)=1. (no official key was published)

Using the base-case-preserving reading, F(1)=3 and F(n)=[F(n−1)]n for n≥2. All values are positive, so define an=log₃F(n). Exponentiation becomes multiplication: a1=1 and an=n an−1. Repeated substitution gives an=n(n−1)…2·1=n!, hence F(n)=3n!.

An induction verifies the expression without logarithms. At n=1, 31!=3 equals the base value. If F(n−1)=3^((n−1)!), then F(n)=(3^((n−1)!))n=3^(n·(n−1)!)=3n!. This completes the proof for every positive integer n. Checks at n=2 and n=3 give 9 and 729; n=4 yields 324=282429536481. Confusing 3n! with (3n)! or with 3n would lose the repeated multiplication of exponents.

This formula describes the function’s value under unbounded-integer arithmetic, not the execution time or the size of a machine integer. The return value grows much faster than an ordinary exponential, and practical fixed-width implementations overflow quickly.

The source ambiguity remains material here. If the final F=F1 executes even after n=1 assigns F=3, the true base is 1. Induction on the same recurrence then gives F(n)=1 for all positive n. Thus 3n! is an explicitly conditional intended solution; 1 is the literal unconditional-assignment solution. No verified official key resolves that control-flow formatting.

Original paper, page 6

2 marks · Other
Report issue

Recursive Fibonacci call count

Asymptotic Analysis & Recurrences

Question 1(x), GATE 1991: fib(0)=fib(1)=1; for n≥2, fib(n)=fib(n−1)+fib(n−2), using ordinary recursive calls. Count all calls evaluating fib(7), including the initial call.
Question 1(x), GATE 1991: fib(0)=fib(1)=1; for n≥2, fib(n)=fib(n−1)+fib(n−2), using ordinary recursive calls. Count all calls evaluating fib(7), including the initial call.
Tap to enlarge
Answer & solution

Answer: 41 (no official key was published)

Step through it (23 steps)

Let C(n) count function invocations. Each base case requires one call, so C(0)=C(1)=1. A nonbase invocation counts itself plus both recursive subtrees: C(n)=1+C(n−1)+C(n−2). Successive values for n=2, …, 7 are 3, 5, 9, 15, 25, 41. This count includes repeated evaluation of identical arguments, as the supplied recursion does not memoize them. It is different from the numeric return value fib(7)=21; counting only leaves or only additions would also answer a different question.

Original paper, page 1