Answer: A;B
To find which recurrence relations correspond to a time complexity of Θ(n), we analyze each option individually:
-
T(n)=T(n−1)+1,T(1)=1
Unrolling the recurrence:
T(n)=T(n−1)+1=T(n−2)+1+1=⋯=T(1)+(n−1)⋅1
Substituting T(1)=1:
T(n)=1+n−1=n=Θ(n)
Thus, Option A is correct.
-
T(n)=2T(2n)+1,T(1)=1
Using the Master Theorem of the form T(n)=aT(n/b)+f(n):
- Here, a=2, b=2, and f(n)=1.
- We compare f(n)=1 with nlogba=nlog22=n1=n.
- Since f(n)=O(n1−ϵ) for ϵ=1, we fall into Case 1 of the Master Theorem.
Therefore:
T(n)=Θ(nlogba)=Θ(n)
Thus, Option B is correct.
-
T(n)=2T(2n)+n,T(1)=1
Using the Master Theorem:
- Here, a=2, b=2, and f(n)=n.
- We compare f(n)=n with nlogba=n.
- Since f(n)=Θ(nlogba), we fall into Case 2 of the Master Theorem.
Therefore:
T(n)=Θ(nlogn)
Thus, Option C is incorrect.
-
T(n)=T(n−1)+n,T(1)=1
Unrolling the recurrence:
T(n)=T(n−1)+n=T(n−2)+(n−1)+n=⋯=T(1)+2+3+⋯+n
Summing the arithmetic progression:
T(n)=2n(n+1)=Θ(n2)
Thus, Option D is incorrect.