How to find the time complexity of a program

0 votes

Hi Team,

I am new to DSA. I want to find the time complexity of the below program. How can I get that?

int a = 0, b = 0;
for (i = 0; i < N; i++) {
    a = a + rand();
}
for (j = 0; j < M; j++) {
    b = b + rand();
}
Oct 15, 2020 in Others by akhtar
• 38,260 points
1,261 views

1 answer to this question.

0 votes

Hi@akhtar,

The first loop is O(N) and the second loop is O(M). Since we don’t know which is bigger, we say this is O(N + M). This can also be written as O(max(N, M)). You can also find how much this program will consume using the time command in Linux.

answered Oct 15, 2020 by MD
• 95,460 points

Related Questions In Others

0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
728 views
0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
2,889 views
0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
661 views
0 votes
0 answers

How to find the username of the instance launched in amazon-ec2?

I m having trouble connecting to the ...READ MORE

Apr 4, 2022 in Others by Kichu
• 19,040 points
1,519 views
0 votes
0 answers

How to find the username of the instance launched in amazon-ec2?

I m having trouble connecting to the ...READ MORE

Apr 5, 2022 in Others by Kichu
• 19,040 points
545 views
0 votes
1 answer

ModuleNotFoundError: No module named 'line_profiler'.

Hi@akhtar, You need to install the module in ...READ MORE

answered Nov 5, 2020 in Python by MD
• 95,460 points
2,248 views
0 votes
1 answer

ERROR: Could not build wheels for line-profiler which use PEP 517 and cannot be installed directly.

Hi@akhtar, If you are trying to install with pip ...READ MORE

answered Nov 5, 2020 in Python by MD
• 95,460 points
3,589 views
0 votes
0 answers

How do I check if an array includes a value in JavaScript?

What is the shortest and most efficient ...READ MORE

Sep 28, 2022 in Java by Nicholas
• 7,760 points
607 views
0 votes
1 answer

How to retrieve the value of a text field in Flutter App?

Hi@akhtar, In your TextField, you can call one ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,460 points
1,801 views
0 votes
1 answer

How to change the background color of AppBar in Flutter?

Hi@akhtar, You can add backgroundColor keyword in your ...READ MORE

answered Aug 12, 2020 in Others by MD
• 95,460 points
2,094 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP