• edited by
20,946 views
39 39 votes

The running time of an algorithm is represented by the following recurrence relation:

$T(n) =  \begin{cases}
  n & n \leq 3 \\
  T(\frac{n}{3})+cn & \text{ otherwise }
 \end{cases}$

Which one of the following represents the time complexity of the algorithm?

  1. $\Theta(n)$

  2. $\Theta(n \log  n)$

  3. $\Theta(n^2)$

  4. $\Theta(n^2 \log  n)$

5 Answers

Best answer
41 41 votes

Comparing with the recurrence form of Master Theorem $T(n) = aT(n/b) + f(n)$

$a=1, b=3,  \log_b a=0$

So $n^{\log_b a} = n^0$

$f(n)=cn$

So, $f(n)=\Omega(n^{\log_b a+\epsilon})$ holds for any $\epsilon < 1$ and this is the third case of Master theorem. But Master theorem also requires (only case 3) that regularity condition be satisfied (this ensures that $f(n)$ is still dominant when the recurrence go deeper) which is $af(n/b) \leq df(n)$ for some $d < 1$ and all sufficiently large $n.$ (Using $d$ here as $c$ is already used in $f(n))$

Here we get, $f(n/3) \leq df(n)$

$\implies cn/3 \leq dcn \implies 1/3 \leq d$

Thus we can use any $1/3 \leq d < 1$ to satisfy the regularity condition and Master theorem case 3 is satisfied. Now, applying case $3$ we get 

$T(n) = \Theta(f(n)) = \Theta(n)$

answer is A.

• edited by
1 1 vote
T(n) = T(n/3) + cn where n <= 3

Using Master's Method,
 

n^log₃1 = n^0 = 1

Since, 1 < cn

Therefore, T(n) = Θ(n)

Correct Answer is Option A.
1 1 vote
Given the recurrence

\[
T(n)=
\begin{cases}
n, & n\leq 3\\
T\left(\frac{n}{3}\right)+cn, & \text{otherwise}
\end{cases}
\]

Expanding the recurrence,

\[
T(n)=T\left(\frac{n}{3}\right)+cn
\]

\[
=T\left(\frac{n}{3^2}\right)+c\frac{n}{3}+cn
\]

\[
=T\left(\frac{n}{3^3}\right)+c\frac{n}{3^2}+c\frac{n}{3}+cn
\]

Continuing,

\[
T(n)=T\left(\frac{n}{3^k}\right)
+cn\left(1+\frac13+\frac1{3^2}+\cdots+\frac1{3^{k-1}}\right)
\]

The recurrence reaches the base case when

\[
\frac{n}{3^k}\leq 3
\]

which gives

\[
k=\Theta(\log n).
\]

The summation

\[
1+\frac13+\frac1{3^2}+\cdots
\]

is a decreasing geometric progression with

\[
a=1,\qquad r=\frac13.
\]

Its sum is bounded by

\[
\frac{1}{1-\frac13}=\frac32,
\]

which is a constant.

Therefore,

\[
T(n)=\Theta(n).
\]

Hence, the correct answer is

\[
\boxed{\text{A. }\Theta(n)}
\]
0 0 votes
Answer is A.

Case III (log power less than 0 ) of Master's Theorem
Answer:
Position:
Show:

Related questions

57 57 votes
4 answers 4 answers
22.8k
22.8k views
go_editor asked Apr 23, 2016
22,757 views
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences $X[m]$ and $Y[n]$ of lengths ...
40 40 votes
3 answers 3 answers
13.9k
13.9k views
Kathleen asked Sep 22, 2014
13,878 views
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences $X[m]$ and $Y[n]$ of lengths ...
74 74 votes
8 answers 8 answers
32.4k
32.4k views
Kathleen asked Sep 22, 2014
32,422 views
In quick-sort, for sorting $n$ elements, the $\left(n/4\right)^{th}$ smallest element is selected as pivot using an $O(n)$ time algorithm. What is the worst case time com...
31 31 votes
5 answers 5 answers
14.5k
14.5k views
Kathleen asked Sep 22, 2014
14,487 views
Consider the following graph:Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskal’s algorithm?$\text{(b, e) (e, f) (a,...