Asymptotic Notation: JavaScript

Learn about the asymptotic notation of JavaScript data structures and functions.

Analyzing Runtimes

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

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 function by counting the number of iterations the while loop will perform based on the size of the input (n).