A workshop has 12 available seats. Its booking flowchart receives group sizes in this order: 4, 10, 3, 5, 0. Each Read next group size consumes only the next value. Zero is a sentinel, rather than a booking request. A rejected group is skipped, and accepted counts groups rather than people. The symbol ←\leftarrow← assigns a value to a variable.
Trace the flowchart and give four exact integers: the remaining seats displayed, the accepted groups displayed, the number of input values read, and the number of times the remaining is zero decision is evaluated.
Unlock full course notes by signing up
Trace table for a loop with a branch
Trace the following pseudocode by hand. MOD gives the remainder after division, so x MOD 2 = 0 is true when x is even.
For each pass through the loop, complete the table. In the branch column, type odd if the ELSE branch runs or even if the THEN branch runs, based on x at the start of that pass. In the last column, give x after the pass as a whole number.
Combining a fee boundary with a later discount
A parcel service uses the flowchart below to calculate a fee in Canadian dollars. Each parcel is processed in a separate run. The arrow symbol ←\leftarrow← means that the variable receives the value on its right. Complete the output column using exact whole-dollar amounts, without currency symbols.
Output of nested FOR loops
In the pseudocode below, FOR k ← a TO b runs its body once for each whole number k from a to b, including both a and b.
Trace the pseudocode and state the value that is output, as a whole number.