Lab: Order of Growth Experiments

In this lab, you will time several algorithms to determine their growth rates.

Instructions

You should complete this lab individually. Of course, please visit office hours or TA hours if you are having difficulty.

Background

In class, we discussed common runtime growth rates:

By plotting input size and runtime, you can experimentally determine an algorithm’s growth rate. For example, this data shows a quadratic growth rate:

A graph of time vs size, showing a quadratic growth rate.

It can be difficult to visually differentiate between quadratic, cubic, and exponential functions. To determine the degree of a polynomial runtime, measure the runtime for input size n and n/2, which we call tn and tn/2. Then, substitute those times into this equation: degree =ln(tn÷tn/2)ln(2) Use the largest input sizes you can measure, to ensure the highest order term overpowers the lower order terms. If the degree is not close to an integer, then the runtime is probably not polynomial.

Measure Algorithm Runtimes

This website includes JavaScript code for several different algorithms. The input size is configured using the text field. You should run each algorithm multiple times, with increasing input sizes. I recommend doubling the input size until the runtime exceeds one minute.

Use this spreadsheet to record and plot algorithm runtimes. I recommend creating a separate sheet for each algorithm.










Submit

Submit your answers on Gradescope. You can resubmit multiple times.

Learning Goals