7.
for$\left ( i=1;i\leqslant n;i++ \right )$
for$\left ( j=n/3;j\leqslant 2n;j=j+n/3 \right )$
$x=x+1;$
Time Complexity will be number of times $x=x+1;$ will execute.
Inner Loop will execute exactly 6 times
$n/3\rightarrow 2n/3\rightarrow n\rightarrow 4n/3\rightarrow 5n/3\rightarrow 2n$ whatever the value of "n" is and is Independent of outer loop
Thus time complexity will number of times outer loop execute $\Rightarrow \Theta \left ( n \right )$
8.
for$\left ( i=1;i\leqslant n;i++ \right )$
for$\left ( j=1;j\leqslant n;j=j+i \right )$
$x=x+1;$
time complexity = number of times "x=x+1" will execute .given below is the table$\Rightarrow$
i |
j |
1 |
n |
2 |
n/2 |
3 |
n/3 |
4 |
n/4 |
$\cdots$ |
$\cdots$ |
n |
n/n |
time complexity $T\left ( n \right )=n+n/2+n/3+n/4+\cdots n/n$
$\Rightarrow T\left ( n \right )=n\left ( 1+1/2+2/3+n/4+\cdots 1/n \right )$
We know $\left ( 1+1/2+2/3+n/4+\cdots 1/n \right )\approx \log n$
$\Rightarrow T\left ( n \right )=\Theta \left ( n*logn \right )$