Debugging pseudocode by stepping through it with a trace table 

Here are three pseudocode trace table exercises with their solutions.

NOTES:

  1. You must have a column in the solution for the line number.
  2. The loops must be clearly visible ie the lines numbers get repeated as the loop executes.
  3. Look out immediately for a nested loop. A loop within a loop is tricky – most people get it wrong if they don’t note its presence BEFORE they start on the solution. Once complete ask yourself again – did I take into account the inner loop correctly? A typical nested loop solutions looks something like this (outer loop, inner, inner, inner, outer loop, inner, inner, inner, outer loop, inner, inner, inner). The outer loop executes 3 time but the inner loop 9 time  . . .  in this example)
  4. The columns for your trace table are negotiable and up to personal preference. Therefore marking a half correct trace table in a fair manner is very difficult. For this reason most exams these days give you the column names at the top of the grid. If you dont like the given columns make your own columns, determine the solution and then transfer your solution back into the original-given grid.
  5. These three question feature MOD. MOD is the remainder after integer division.
    Examples:
    0 MOD 7 is 0, 2 MOD 3 is 2, 7 MOD 2 is 1,
    5 MOD 0 is division by zero and therefore a run time error.

Click here for question A and B

Click here for the solution of A and B

Click here for question C

Click here for the solution to C