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
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 |
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 |
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 :-)
1 Answers GrapeCity, Microsoft,
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.
4 Answers ADP, Amazon, HCL, IBM, Infosys, Satyam, TCS, Vimukti Technologies,
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.
0 Answers Nagarro, Wollega University,
write a program that can locate elements in array.
develop a program to calculate and print body mass index for 200 employees
0 Answers Jomo Kenyatta University,
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.
0 Answers Facebook, Webyog, Wipro,
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).
1 Answers Infosys, Qatar University,