What is the time complexity T(n) of the following portions of code? For simplicity, you may
assume that n is a power of 2. That is, n = 2k for some positive integer k.
a) …
for (i = 1; i <= n; i++)
{
j = n; cout << i << “ ” j << “ ” << endl;
}
b) …
for (i = 0; i <= n; i += 2)
{
j = n; cout << i << “ ” j << “ ” << endl;
}
c) …
for (i = n; i >= 1; i = i/2)
{
j = n; cout << i << “ ” j << “ ” << endl;
}
d)
for (i = 1; i <= n; i++)
{ j = n;
while (j >= 0)
{ cout << i << “ ” j << “ ” << endl;
j = j - 2;
}
}

pls i need the solution tomorrow i have exam and i dont know how to solve this kind of question i need proof

if it is in O(n) or o(logn)....etc:'(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.