Running Time and Complexity

Asymptotic Analysis: A very limited overview.

This is a means of discussing the general efficiency of an algorithm. When discussing the time complexity of an algorithm, we use the positive integer to represent the size of the data set it processes. To evaluate the actual algorithm, we must ignore machine-dependent constants (i.e., think about the number of instructions being executed, not about how fast a certain machine can execute them) and look at its growth rate as approaches (i.e., how does it grow as a function of time — especially as gets large?).

Here are the big terms you need to know:


  1. is Theta of if and only if there exists some positive constants , , and such that whenever . In short, is bounded both above and below by because after some point , and have the same growth rate.

  2. is ("oh" or "big oh") of if and only if there exists some positive constants and such that whenever . In short, is bounded above by because after some point , will always grow at a larger asymptotic growth rate than .

  3. is Omega ("big omega") of if and only if there exists some positive constants and such that whenever . In short, is bounded below by because after some point , will always grow at a larger asymptotic growth rate than .

The term time, or "constant time", is used to refer to fundamental operations that take a constant amount of time to execute (e.g., reading a single value, performing a comparison between two values, checking a condition, etc.).

At a very basic level, you need to think about how many instructions your algorithm must execute in the best and worst case scenarios when processing pieces of data. Then determine the function(s) that your algorithm is bounded above and below by, disregarding any leading constants (e.g., , , etc.) or lower-order terms (e.g., is a lower-order term than ); basically, you don't hang on to anything that doesn't directly impact the growth rate of and you only want to retain the term that has the greatest impact on growth rate (e.g., if , then is .

Resource: Algorithms Sequential & Parallel: A Unified Approach.

Example

for(int i = 0; i < n; i++) {

    for(int j = 0; j < n/2; j++) {
        // Θ(1) operation  
        // Θ(1) operation 
        // Θ(1) operation 
    }
}

In the nested loop above, there are three constant time operations that will be performed times as a result of the nested loops. Because , our code is .

 
Go to Top
  1. Challenge Walkthrough
    Let's walk through this sample challenge and explore the features of the code editor.1 of 6
  2. Review the problem statement
    Each challenge has a problem statement that includes sample inputs and outputs. Some challenges include additional information to help you out.2 of 6
  3. Choose a language
    Select the language you wish to use to solve this challenge.3 of 6
  4. Enter your code
    Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
  5. Test your code
    You can compile your code and test it for errors and accuracy before submitting.5 of 6
  6. Submit to see results
    When you're ready, submit your solution! Remember, you can go back and refine your code anytime.6 of 6
  1. Check your score