Let $A[1,\ldots,n]$ be an array storing a bit ($1$ or $0$) at each location, and $f(m)$ is a function whose time complexity is $\Theta(m)$. Consider the following program fragment written in a C like language:
counter = 0;
for (i=1; i<=n; i++)
{
if (a[i] == 1) counter++;
else {f (counter); counter = 0;}
}
The complexity of this program fragment is
-
$\Omega(n^2)$
-
$\Omega (n\log n) \text{ and } O(n^2)$
-
$\Theta(n)$
-
$o(n)$