A theater booking system uses a 2D grid to track seat statuses. The algorithm shown in Figure 1 searches the grid to locate the coordinates of a seat marked as "Selected".
Figure 1
targetRow = -1
targetCol = -1
for row from 0 to 3
for col from 0 to 3
if getSeat(row, col) == "Selected" then
targetRow = row
targetCol = col
endif
endfor
endfor
Figure 2
| Column 0 | Column 1 | Column 2 | Column 3 | |
|---|---|---|---|---|
| Row 0 | Available | Available | Booked | Available |
| Row 1 | Booked | Selected | Available | Booked |
| Row 2 | Available | Available | Available | Available |
| Row 3 | Booked | Available | Booked | Available |
Explain the purpose of the second (inner) iteration structure in the algorithm in Figure 1.
208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.