Skip to content
S3U
Login Create Account

Science / Programming basics / Grade 12 / scc70

Programming Basics: Count the Work

Compare operation counts under a clearly stated cost model.

All worksheets
5 questions0m 0s

Learn first

Hours, minutes, and clock hands

An hour has 60 minutes. On a usual clock, the short hand shows the hour and the long hand shows minutes. Each numbered minute-hand step is five minutes; small tick marks are single minutes.

How to work it out Read the hour already started. Count minutes from 12 to the minute hand. The hour hand moves gradually toward the next hour. Keep a.m., p.m., and day labels when given.

A separate example In a separate clock, a minute hand at 8 means 40 minutes past. The short hand will be between the current hour and the next hour, not necessarily exactly on a number.

Powers and exponents

An exponent tells how many equal factors are multiplied. A square uses two factors; a cube uses three. An exponent does not mean multiply the base by the exponent.

How to work it out For powers with the same base, multiplication adds exponents. Apply parentheses and exponents before ordinary multiplication and addition.

A separate example In a separate example, 3⁴ = 3 × 3 × 3 × 3. Also 3² × 3⁴ = 3⁶ because there are six factors of 3.

Programs follow precise instructions

A program is a set of instructions. A variable stores a value. A condition chooses between paths. A loop repeats steps. Output is the result produced.

How to work it out Trace one instruction at a time. Keep a record of values and check exactly when a condition or repeated step is evaluated.

A separate example In a separate trace, start with n = 2, add 3, then double n. The two instructions happen in order: 5 is an intermediate value before the final result.

Learn the skill

Count only SHOW executions. A single REPEAT n TIMES loop containing one SHOW performs n shows. Two nested loops, each REPEAT n TIMES, with one SHOW in the inner body perform n squared shows. n is a nonnegative integer; this is not a wall-clock prediction.

Worked example

For n = 4, the single loop performs 4 shows and the nested loops perform 16. Doubling n doubles the first count but quadruples the second count.

For input size four, a single loop executes SHOW four times and two nested loops execute SHOW sixteen times. Doubling the input to eight gives eight and sixty-four shows respectively.
For input size four, a single loop executes SHOW four times and two nested loops execute SHOW sixteen times. Doubling the input to eight gives eight and sixty-four shows respectively.
Question 1 For n = 5, how many shows does the single loop perform?
Question 2 For n = 5, how many shows do the two nested loops perform?
Question 3 For n = 0, how many shows do the nested loops perform?
Question 4 When n doubles, the nested-loop SHOW count changes by what factor?
Question 5 Does this count alone tell exact elapsed seconds?