Question

In: Advanced Math

Please explain what we mean by Time Complexity and Space Complexity. Please provide a short survey...

Please explain what we mean by Time Complexity and Space Complexity. Please provide a short survey of Complexity classes.

Solutions

Expert Solution

Solution : i> Time Complexity :  Time complexity is the amount of time taken by an algorithm to run as a function of the length of the input. In other words, time complexity is essentially efficiency, or how long a program function takes to process a given input.

Time complexity is typically expressed in the big - O notation because it will give us an upper limit of the execution time i.e. the execution time in the worst case.

For example, we have the algorithm:

int count = 0;
for (int i = 0; i < N; i++) 
   for (int j = 0; j < i; j++) 
        count++;

Lets see how many times count++ will run.

When i=0, it will run 0 times.
When i=1, it will run 1 times.
When i=2, it will run 2 times and so on.

So total number of times count++ will run is 0+1+2+...+(N−1)=N∗(N−1) / 2.

Hence time complexity will be O(N^2).

ii> Space Complexity : Space complexity is the amount of space or memory taken by an algorithm to run as a function of the length of the input.

For example, we have the algorithm:

int count = 0;
for (int i = 0; i < N; i++) 
    for (int j = 0; j < i; j++) 
        count++;

Here total number of inputs is N .

Hence space complexity will be O(N).


Related Solutions

What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity...
What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity of O(n^2)? Justify.
What does combinatorial complexity mean?
What does combinatorial complexity mean?
No handwriting, please   What is a real-time system? What do we mean by hard and soft...
No handwriting, please   What is a real-time system? What do we mean by hard and soft real-time systems? Discuss, based one real-time operating system and one general purpose operating system, the differences between a real-time operating system and a general-purpose operating system.?
How are time and space linked? Please provide a long answer to the question(s) above, using...
How are time and space linked? Please provide a long answer to the question(s) above, using diagram and formula whenever possible.
please do all parts a.For resizable array based implementation, what is the time complexity in the...
please do all parts a.For resizable array based implementation, what is the time complexity in the worst and base case scenario? Explain. b. For linked implementation of a list, what is the time complexity in the wort and best case scenario? Explain. remove(givenPosition: integer)
Please explain what diplomatic bargaining may mean and provide an example in international relations.
Please explain what diplomatic bargaining may mean and provide an example in international relations.
Section 2: SHORT ANSWER (IN YOUR WORDS) List 5 characteristics of complexity and provide examples for...
Section 2: SHORT ANSWER (IN YOUR WORDS) List 5 characteristics of complexity and provide examples for each:
?magine a transistor with 7 nm size. What we mean by that 'size' please explain that...
?magine a transistor with 7 nm size. What we mean by that 'size' please explain that ?
Please provide an explanation of how to calculate the center of gravity, particularly in space. What...
Please provide an explanation of how to calculate the center of gravity, particularly in space. What the center of gravity is in our solar system and explain your reasoning. List any references used. Be as detailed as possible.
Please explain what diplomatic bargaining may mean and provide an example in international relations demonstrating this...
Please explain what diplomatic bargaining may mean and provide an example in international relations demonstrating this negotiation process by doing some research or finding an article about diplomacy between two or more countries. In addition, please apply Hans Morgenthau’s 9 Rules of Diplomatic Strategy to your analysis.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT