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 / 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 |
Post New Answer View All Answers
Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)
write a program that can LOCATE and INSERT elements in array using c++ programming languages.
What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect
Code for Two Classes for Doing Gzip in Memory?
write a program that creates a sequenced array of numbers starting with 1 and alternately add 1 and then 2 to create the text number in the series , as shown below. 1,33,4,6,7,9,............147,148,150 Then , using a binary search , searches the array 100 times using randomly generated targets in the range of 1 to 150
write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n
write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used
Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?
write a program using virtual function to find the transposing of a square matrix?
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++
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
write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.