Skip to Content
Article

Asymptotic Notation: Java

Learn about asymptotic notation in Java.

Analyzing Runtimes

Now that you’ve started learning how to use asymptotic notation to measure the runtime of a function, let’s practice with Java!

When analyzing the runtime of a function, it’s necessary to check the number of iterations the loop will perform based on the size of the input.

The divideByTwo() function below takes in a positive integer of size n, and returns the number of times n must be divided by 2 until it reaches 1. We can analyze the runtime of this method by counting the number of iterations the while loop will perform based on the size of the input (n).

Ready to Learn More?

Find the course that's right for you! Explore our catalog or get a recommendation.