Question 9286 – Database-Management-System
May 13, 2024
Question 8471 – Algorithms
May 13, 2024
Question 9286 – Database-Management-System
May 13, 2024
Question 8471 – Algorithms
May 13, 2024

Question 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.
A
O(n2)
B
O(nlogn)
C
O(n)
D
O(nlogn logn)
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!