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,230 points
419 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,360 points

Related Questions In Others

0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
209 views
0 votes
0 answers
0 votes
0 answers
0 votes
1 answer
0 votes
2 answers

How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

answered Aug 12, 2020 in Others by Steve
• 200 points
961 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,360 points
1,088 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,360 points
2,276 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

3 days ago in Java by Nicholas
• 6,240 points
9 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,360 points
878 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,360 points
1,356 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP