Runtime Complexity

Projected Time

About 3 hours

Prerequisites

Motivation

While computers are lightning fast, some code can run faster than other code. When computer programs get larger and larger, a slow runtime can be noticeable to the user. Luckily, code can be written in efficient ways. Understanding runtime complexity is important for multiple reasons:

Which companies use runtime complexity? Pinterest reported that search engine traffic and sign-ups increased by 15% when the perceived load times decreased by 40%. While there are many factors that contribute to the waiting time of large websites, any company will want their programmers to be considering runtimes when writing their code.

Google also has written extensively on the importance of runtime, and why more efficient websites lead to increased web traffic.

Objectives

Participants will be able to:

Materials

Supplemental Resources

Lesson

Things to know:

Runtimes to know:

There are several common runtimes that you should understand:

Runtime details:

Things we’ll cover later

These things are not covered in this lesson, but they are related and important to know.

Independent Practice

Techtonica staff will assign pairs.

Runtime Complexity Exercise 1: Reading code and analyzing runtime

Read the functions in runtime1-analyzing.js. For each function, figure out:

Runtime Complexity Exercise 2: Comparing code

Compare multiple pieces of code that do the same thing, and figure out the runtime of each one. Which solution would be fastest for large input sizes? runtime2-comparisions.js

Runtime Complexity Exercise 3: Solving problems and writing code

How would you solve these problems runtime3-solving.md? Can you think of an O(n^2), O(n log n), O(n) solution?

Group Practice

Discuss with the group and an instructor:

Challenge

Check for Understanding

-Make a cheat sheet about runtime complexity. For O(1), O(log(n)), O(n), and O(nlogn) and O(n^2), give an example of 1-3 algorithms/operations that have this runtime.