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,240 points
506 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,380 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
255 views
0 votes
0 answers
0 votes
0 answers
0 votes
1 answer

How can I use a command button in excel to set the value of multiple cells in one click?

Try this: Private Scan As Integer Private Sub CommandButton1_Click() ...READ MORE

answered Oct 24 in Others by narikkadan
• 37,660 points
63 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24 in Others by narikkadan
• 37,660 points
36 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,380 points
1,175 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,380 points
2,394 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 in Java by Nicholas
• 7,120 points
52 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,380 points
1,027 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,380 points
1,435 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