Let A[1..n] be an array storing a bit (1 or 0) at each location, and let f(m) be 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
- A\(\Omega (n^{2})\)
- B\(\Omega (n \log n)\) and \(O (n^{2})\)
- C\(\Theta(n)\)
- D\(o(n)\)