levo

Algorithms

Trace tables and correcting algorithms

  • 3 things to know
  • J277/02

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A bit is the unit of data.
smallestlargestmain

Blank Blitz makes facts automatic

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

AThe sum 0 + 0 is 0, and 0 + 1 is 1.
BThe sum 1 + 1 is 0 carry 1.
CThe sum 1 + 1 + 1 is 1 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Integer means a whole number with no fractional part.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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