Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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

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

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

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

 Is This Answer Correct ? 2 Yes 7 No

More C++ Code Interview Questions

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

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.

hello friends, given an expression we have to remove the unwanted brackets in that expression. Eg : (a+b) ---> a+b (a+b)*(c)-----> (a+b)*c. Please mail me if you know the logic. My mail id is : saravana6m@gmail.com. Thank you in advance :-)

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.

Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

write a program that can locate elements in array.

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

i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

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

Write an algorithm that receives a string and reverses it.

1. Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.

Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and calculate its complexity T(n).

Categories