Complexity T(n)

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;
}
}


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More C++ Code Interview Questions

Here's the programm code: int magic(int a, int b) { return b == 0 ? a : magic(b, a % b); } int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", magic(a, b)); return 0; } on input stream we have integers 4, 45 What's the output integer? How many times will be initiated "magic" function?

1 Answers  


What will be the output- for(i=1;i<=3;i++) { printf("%d",i); continue; i++; }

5 Answers   Impetus,


write a program that calculate the volume of cylinder after user enters radius and height and show the algorithm used

1 Answers   Jomo Kenyatta University,


Write A C++ Program To Input A Number Between 20 To 99 And Display Its Numbername?

3 Answers   TCS,


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

0 Answers   HCL,






write a c program, using for loop, that accepts and odds two numbers. The output must be the sum and the addens. This should be repeated 5 times while the first number is decremented by one and the second number is incremented by 1.

2 Answers   IBM, Infosys,


PROBLEM #8 The cashier at the counter of a Super Store, Mr. Khazaanchi has the following bundles of rupee cash notes with him: Rs. 1, 2, 5, 10, 50, 100, 500, 1000 A customer comes at his counter with various items that he has shopped. Mr. Khazaanchi totals the item prices and tells the customer his total amount payable. The customer gives Mr. Khazanchi some amount of cash. Find the total number of rupee notes of each denomination (i.e. 1, 2, 5, 10, 50, 100, 500, 1000) Mr. Khazaanchi will have to give to the withdrawer ensuring that the total number of rupee notes are minimum.

1 Answers   AR, ARJ,


Write a program using one dimensional array that accept five values from the keyboard. Then it should also accept a number to search. This number is to be searched if it among the five input values. If it is found, display the message “Search number is found!” otherwise, display “Search is lost”. Example: Enter 5 numbers: 10 15 20 7 8 Enter number to search: 7 Search number is found!

2 Answers   College School Exams Tests,


1.program to add any two objects using operator overloading 2.program to add any two objects using constructors 3.program to add any two objects using binary operator 4.program to add any two objects using unary operator

2 Answers   IBM,


How to swap two ASCII numbers?

0 Answers  


develop a program to calculate and print body mass index for 200 employees

0 Answers   Jomo Kenyatta University,


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

0 Answers   Qatar University,


Categories