CUET PG 2026 — DSA PYQ
CUET PG | DSA | 2026What is the time complexity represented by the recurrence T(n)=T(n−1)+logn?
Choose the correct answer:
- A.
O(logn)
- B.
O(nlogn)
(Correct Answer) - C.
O(n2)
- D.
O(loglogn)
O(nlogn)
Explanation
To solve the recurrence T(n)=T(n−1)+logn, expand it recursively:
T(n)=T(n−1)+logn
T(n)=T(n−2)+log(n−1)+logn
T(n)=T(n−3)+log(n−2)+log(n−1)+logn
Continuing this process down to the base case T(1)=O(1):
T(n)=log1+log2+log3+⋯+logn
Using the logarithm product rule (loga+logb=log(ab)):
T(n)=log(1⋅2⋅3⋅⋯⋅n)=log(n!)
By Stirling's Approximation, log(n!)=Θ(nlogn).
Therefore, T(n)=O(nlogn).
Correct Answer: (B) O(nlogn)
Explanation
To solve the recurrence T(n)=T(n−1)+logn, expand it recursively:
T(n)=T(n−1)+logn
T(n)=T(n−2)+log(n−1)+logn
T(n)=T(n−3)+log(n−2)+log(n−1)+logn
Continuing this process down to the base case T(1)=O(1):
T(n)=log1+log2+log3+⋯+logn
Using the logarithm product rule (loga+logb=log(ab)):
T(n)=log(1⋅2⋅3⋅⋯⋅n)=log(n!)
By Stirling's Approximation, log(n!)=Θ(nlogn).
Therefore, T(n)=O(nlogn).
Correct Answer: (B) O(nlogn)
