Asymptotic Notation: Java
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.
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 (