Question 9286 – Database-Management-System
May 13, 2024Question 8471 – Algorithms
May 13, 2024Question 8933 – Algorithms
Which is the complexity of the following code?
sum=0;
for(i=1; i<=n; i*=2)
for(j=1; j<=n; j++)
sum++;
Which of the following is not a valid string?
Correct Answer: C
Question 392 Explanation:
sum=0; → O(1) Time
for(i=1; i<=n; i*=2) → O(logn) time
for(j=1; j<=n; j++) → O(n) Time
sum++; → O(1) time
Total time complexity: O(nlogn) but in question they given not a valid string.
So, O(n2) > O(nlogn logn) > O(nlogn) > O(n).
This program can’t run less than O(nlogn) time.
for(i=1; i<=n; i*=2) → O(logn) time
for(j=1; j<=n; j++) → O(n) Time
sum++; → O(1) time
Total time complexity: O(nlogn) but in question they given not a valid string.
So, O(n2) > O(nlogn logn) > O(nlogn) > O(n).
This program can’t run less than O(nlogn) time.
O(n2)
O(nlogn)
O(n)
O(nlogn logn)
Subscribe
Login
0 Comments