• edited by
2,445 views
37 37 votes

Consider mutually recursive definitions of $T(a, b)$ and $S(c, d)$ :
$$
\begin{array}{rlr}
T(x, c) & =\Theta(x) & \text { for } c \leq 2 \\
T(x, y) & =\Theta(x)+S(x, y / 2), &\\
S(c, y) & =\Theta(y) & \text { for } c \leq 2, \text { and }\\
S(x, y) & =\Theta(y)+T(x / 2, y) &
\end{array}
$$
Select the correct asymptotic complexity of an algorithm with run-time $T(n, n)$.

  1. $\Theta(\log n)$.
  2. $\Theta(n)$.
  3. $\Theta(n \log n)$.
  4. $\Theta\left(n \log ^{2} n\right)$.

4 Answers

41 41 votes
The correct answer here is $\Theta(n)$. To see why, we want to first eliminate the mutually recursive recurrence relations. To do so, we will replace all references to the function $S(x, y)$ with the definition of $S(x, y)$. This yields the following recurrence relation for $T(x, y)$ :
$$
T(x, y)=\Theta(x)+\Theta(y / 2)+T(x / 2, y / 2)
$$
We can rewrite this to eliminate the constants and get the recurrence
$$
T(x, y)=\Theta(x+y)+T(x / 2, y / 2)
$$
We rewrite the recurrence relation to avoid $\Theta$ notation as follows:
$$
T(x, y)=c(x+y)+T(x / 2, y / 2) .
$$
We may then begin to replace $T(x / 2, y / 2)$ with the recursive formula containing it:
$$
T(x, y)=c(x+y)+c\left(\frac{x+y}{2}\right)+c\left(\frac{x+y}{4}\right)+c\left(\frac{x+y}{8}\right)+\ldots
$$
This geometric sequence is bounded from above by $2 c(x+y)$, and is obviously bounded from below by $c(x+y)$. Therefore, $T(x, y)$ is $\Theta(x+y)$, and so $T(n, n)$ is $\Theta(n)$
2 2 votes
\[
\begin{aligned}
T(x,c) &= \Theta(x), && c\leq 2,\\
T(x,y) &= \Theta(x)+S(x,y/2),\\
S(c,y) &= \Theta(y), && c\leq 2,\\
S(x,y) &= \Theta(y)+T(x/2,y).
\end{aligned}
\]
$\text{We need to find \(T(n,n)\).}$
\[
T(x,y)=\Theta(x)+S(x,y/2)
\]
$\text{Using the definition of \(S\),}$
\[
S(x,y/2)=\Theta(y/2)+T(x/2,y/2)
\]
$\text{Therefore,}$
\[
T(x,y)
=
\Theta(x)+\Theta(y/2)+T(x/2,y/2)
\]
$\text{Again expanding \(T\),}$
\[
T(x/2,y/2)
=
\Theta(x/2)+S(x/2,y/4)
\]
$\text{Hence,}$
\[
T(x,y)
=
\Theta(x)+\Theta(y/2)
+\Theta(x/2)+S(x/2,y/4)
\]
$\text{Now,}$
\[
S(x/2,y/4)
=
\Theta(y/4)+T(x/4,y/4)
\]
$\text{Thus,}$
\[
T(x,y)
=
\Theta(x)+\Theta(y/2)
+\Theta(x/2)+\Theta(y/4)
+T(x/4,y/4)
\]
$\text{Continuing,}$
\[
T(x,y)
=
\Theta\left(
x+\frac{x}{2}+\frac{x}{4}+\cdots
\right)
+
\Theta\left(
\frac{y}{2}+\frac{y}{4}+\frac{y}{8}+\cdots
\right)
\]
$\text{Both are geometric series:}$
\[
x+\frac{x}{2}+\frac{x}{4}+\cdots=\Theta(x)
\]
$\text{and}$
\[
\frac{y}{2}+\frac{y}{4}+\frac{y}{8}+\cdots=\Theta(y)
\]
$\text{Therefore,}$
\[
T(x,y)=\Theta(x)+\Theta(y)
\]
\[
T(x,y)=\Theta(x+y)
\]
$\text{Putting \(x=n\) and \(y=n\),}$
\[
T(n,n)=\Theta(n+n)
\]
\[
\boxed{T(n,n)=\Theta(n)}
\]
$\text{Therefore, the correct option is}$
\[
\boxed{\text{B. }\Theta(n)}
\]
Answer:
Position:
Show:

Related questions

16 16 votes
3 3 answers
2.1k
2.1k views
GO Classes asked Jun 19, 2022
2,137 views
Let $T(n)$ be$$T(n)=T(\sqrt{n})+\log \log n$$What will be asymptotic bound on $T(n)?$$\Theta(\log n)$$\Theta((\log \log n)^2)$$\Theta(\log \log \log n)$$\Theta(\log \log ...
10 10 votes
3 3 answers
1.2k
1.2k views
GO Classes asked Jun 19, 2022
1,234 views
Let $T(n)$ be$$T(n)=2 T(\sqrt{n})+\log n$$What will be asymptotic bound on $T(n) ?$$\Theta(\log n)$$\Theta(\log \log n)$$\Theta(\log n \log \log n)$$\Theta(n \log n)$
15 15 votes
2 2 answers
2.1k
2.1k views
GO Classes asked Jun 19, 2022
2,149 views
Let $T(n)$ be$$T(n)=n^{2}+T(n / 2)+T(n / 4)$$What will be asymptotic bound on $T(n)?$ $\Theta\left(n^ 2\right)$$\Theta\left(n^ 3\right)$$\Theta\left(n^ 4\right)$$\Theta\l...
20 20 votes
6 6 answers
1.9k
1.9k views
GO Classes asked Jun 19, 2022
1,923 views
Let $$T(n)=\sqrt{n} \cdot T(\sqrt{n})+n$$What will be asymptotic bound on $T(n) ?$$\Theta(\sqrt{n} \log n)$$\Theta(\log \log n)$$\Theta(n \log \log n)$$\Theta(\sqrt{n} \l...