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

output for printf("printf");

0 Answers  


using repetition structure. Write a c program that will accept five numbers. The program should count and output the total count of even numbers and total count of add numbers.

2 Answers  


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.. ""EXAMPLE"" enter how many numbers to be inputted: 5 12 14 11 09 30 what number to search: 11 11 IS FOUND IN LOCATION 3 PLZZZ.. ELP ME...

3 Answers  


Complexity T(n) Write a linear-time algorithm that sorts n distinct integers, each of which is between 1 and 500. Hint: Use a 500-element array. (Linear-time means your algorithm runs in time c*n + b, where c and b are any constants that do not depend on n. For example, your algorithm can run in time n, or time 2n + 1, or time 5n + 10, or time 100n + 6, but not time c*n*n = c*n?.)

1 Answers   Qatar University,


Given 1 to n distinct random number of which n+1th element was duplicated. How do find the duplicate element and explain the time complexity of the algorithm.

0 Answers   Microsoft, NetApp,






write a proram using exceptional handling create a error & display the message "THERE IS AN ERROR?... PLEASE RECTIFY"?

1 Answers  


Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.

1 Answers   IMO, NetApp,


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

0 Answers   Facebook, Webyog, Wipro,


Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

2 Answers   TCS,


Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

0 Answers  


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

0 Answers   Qatar University,


A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE OUTPUT: E

1 Answers  


Categories