levo

Algorithms

Trace tables and correcting algorithms

  • 3 things to know
  • J277/02
Start revising · £5/month

Overview

Trace tables and why they are used, the output of short algorithms in Exam Reference Language, and finding and fixing errors in given code.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a trace table?

Key term

Explain why trace tables are used.

Key term

What is output by the algorithm n = 1, do, n = n * 3, until n > 20, print(n)?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a trace table?

    Model answer

    A trace table records how the values of variables change as an algorithm runs. Each row shows the values after a step, and outputs have their own column.

  2. 2

    Explain why trace tables are used.

    Model answer

    A trace table shows exactly what an algorithm does with a given set of data. A trace can reveal a logic error or the purpose of an unfamiliar algorithm.

  3. 3

    What is output by the algorithm total = 0, for i = 1 to 6, if i MOD 2 == 1 then total = total + i endif, next i, print(total)?

    Model answer

    The algorithm prints 9. The nested if statement adds only the odd values of i, so total becomes 1, then 4, then 9.

  4. 4

    What is output by the algorithm x = 50, count = 0, while x > 5, x = x DIV 2, count = count + 1, endwhile, print(count)?

    Model answer

    The algorithm prints 4. The variable x falls to 25, 12, 6 and then 3, and count rises by 1 each time. The loop stops because 3 is not greater than 5.

  5. 5

    What is output by the algorithm n = 1, do, n = n * 3, until n > 20, print(n)?

    Model answer

    The algorithm prints 27. The variable n becomes 3, then 9, then 27, and the loop stops once n is greater than 20.

  6. 6

    Which values appear in the total column of a trace table for total = 0, for i = 1 to 3, total = total + i * i, next i?

    Model answer

    The total column shows 0, then 1, 5 and 14. Each pass adds the square of i, so the final value of total is 14.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Systems Architecture
Memory and Storage
Computer Networks, Connections and Protocols
Network Security

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A bit is the unit of data.
smallestlargestmain

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Integer means a whole number with no fractional part.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Algorithms, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.