Check your understanding of the previous reading: what makes a good program, ways to measure how long a program takes, and the constant, linear and quadratic relationships.

Question 1

What three criteria are commonly used to evaluate a program?

Select every answer that applies, then check.

  • Correct. Readability is the second question a Computer Scientist asks: programs live for a long time and need to be read, debugged and updated.
  • Not one of the three. More loops don't make a program better; loops are often what makes it slow.
  • Correct. How long the program takes to run is the last question, and the topic of this reading.
  • Not one of the three. The reading asks whether a program is correct, readable and fast, not whether it is clever.
  • Correct. This is the first question: an incorrect program doesn't solve the problem it sets out to solve.
  • Not one of the three. The reading calls the number of lines an incorrect way to measure even the length of a program.

Question 2

Match each description to its most accurate label.

#DescriptionLabel
1 Measuring the actual time taken by the program.
2 Estimating the time each statement of a program will take via a simplified model of execution.
3 The number of statements in the program.

Question 3

Put these mathematical relationships in order from slowest to fastest growth relative to each other.

Drag the items into order, or use the arrow buttons, then check.

  1. Constant
  2. Linear
  3. Quadratic

A constant relationship doesn't grow with the size of the input at all; a linear one takes a constant amount of extra time for every extra element; a quadratic one takes a linear amount of extra time for every extra element, so it grows fastest.

Question 4

Mark each of the following as either constant, linear, or quadratic based on the size of the input. You can assume that we are talking about the worst possible input for each possible given size input.
Adding together three numbers.
Adding up a list of numbers.
Doubling every element of a list.
Checking to see if a list contains a negative number.
Getting the first and last elements of a list and adding them together.
Getting the first element of each row of a 2-dimensional list.
Check to see if a certain number is in a 2-dimensional list.