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 in Others by akhtar
• 33,370 points
23 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 by MD
• 79,190 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
76 views
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 in Others by Steve
• 200 points
211 views
0 votes
1 answer

How to apply zoom animation for each element of a list in angular?

Hey @Sid, do check if this link ...READ MORE

answered Jul 30, 2019 in Others by Vardhan
• 13,180 points
180 views
0 votes
1 answer

Where is the documentation to refer for coinbase api integration of Etherium coin currency in php?

Hey there! Please refer to the following ...READ MORE

answered Jan 25, 2019 in Others by Omkar
• 69,030 points
124 views
0 votes
1 answer

How to do Installation of Ruby on Rails on Linux (Ubuntu)?

Hi Pratibha, installing ROR on ubuntu is ...READ MORE

answered Mar 1, 2019 in Others by Anvi
• 14,110 points
356 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 in Python by MD
• 79,190 points
48 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 in Python by MD
• 79,190 points
133 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 in Others by MD
• 79,190 points
141 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 in Others by MD
• 79,190 points
479 views