Welcome Guest, Not a member yet? Register   Sign In
What is the most efficient way to fix the time complexity of an algorithm?
#1

I have looked through Google and resource for a clear and straightforward explanation of how to calculate time complexity, but I have yet to find one.

What information do I already have?

The following code is:
Code:
char h = 'y'; // This will be executed 1 time
int abc = 0; // This will be executed 1 time


The following loop is like the one below:
Code:
for (int i = 0; i < N; i++) {
    Console.Write('Hello, World!!');
}
This will be executed only once.
  • int i=0; This will be executed only once.
The time is actually calculated to i=0 and not the declaration.
  • i < N; This will be executed N+1 times
  • i++ This will be executed N times
The number of operations needed to complete this loop is {1+(N+1)+N}= 2N+2.

I am familiar with the basics of time complexity calculations but have seen complexity measured in terms of O(N), O(n^2), O(log n), O(n!), and other forms.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB