What is the time complexity T(n) of the following program?

a)
int n, d, i, j;
cin >> n;
for (d=1; d<=n; d++)
for (i=1; i<=d; i++)
for (j=1; j<=n; j += n/10)
cout << d << " " << i << " " << j << endl;


b)
void main()
{ int n, s, t;
cin >> n;
for (s = 1; s <= n/4; s++)
{t = s;
while (t >= 1)
{ cout << s << " " << t << endl;
t--;
}
}
}


c)
void main()
{ int n, r, s, t;
cin >> n;
for (r = 2; r <= n; r = r * 2)
for (s = 1; s <= n/4; s++)
{
t = s;
while (t >= 1)
{
cout << s << " " << t << endl;
t--;
}
}
}

Answers were Sorted based on User's Feedback



What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; ..

Answer / arunthathi

1.t(n)=10*n*n*(n+1)/2
2.t(n)={n/4*(n/4)*[(n/4)+1]}/2

Is This Answer Correct ?    17 Yes 6 No

What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; ..

Answer / rajesh kumar pal

a- (n*n)*log(n).
b- log(n)*log(n).
c-log(n)*log(n)*log(n).

Is This Answer Correct ?    5 Yes 9 No

What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; ..

Answer / hero

a. T(n)= n*(2n+1)/2*n/10

Is This Answer Correct ?    2 Yes 7 No

Post New Answer

More C++ Code Interview Questions

write a program to perform generic sort in arrays?

0 Answers  


How reader and writer problem was implemented and come up with effective solution for reader and writer problem in case we have n readers and 1 writer.

6 Answers   Microsoft, NetApp,


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

0 Answers   Facebook, Webyog, Wipro,


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

0 Answers  


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

0 Answers  






Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

0 Answers  


Code for Method of Handling Factorials of Any Size?

0 Answers  


Wrie a function which returns the most frequent number in a list of integers. Handle the case of more than one number which meets this criterion. public static int[] GetFrequency(int[] list)

3 Answers   Nagarro,


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

0 Answers  


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

0 Answers   Nagarro,


Code for Easily Using Hash Table?

0 Answers  


write a function – oriented program that calculates the sum of the squares from 1 to n. thus, if the input is 3, the output is 14

3 Answers  


Categories