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

Answer Posted / hero

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

Is This Answer Correct ?    2 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

2002


write a program that reads a series of strings and prints only those strings begging with letter "b"

2666


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

2042


write a program to perform generic sort in arrays?

2615


Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?

7328






write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

4298


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

1811


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2434


create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

2211


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

7023


Code for Two Classes for Doing Gzip in Memory?

2805


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

2392


Write a simple encryption program using string function which apply the substitution method.

5529


how to write a program that opens a file and display in reverse order?

2561


Code for Easily Using Hash Table?

2383