Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 26

An algorithm in pseudocode is designed to display and sum the daily shipment counts (5 working days per hub) for 4 different regional hubs.

1  hubs ← ['Alpha', 'Beta', 'Gamma', 'Delta']
2  shipments ← [105, 112, 98, 115, 120, 88, 92, 85, 90, 99, 134, 142, 128, 130, 135, 76, 80, 82, 79, 85]
3  totalShipments ← 0
4  FOR i ← 0 TO 3
5      hubName ← hubs[i]
6      OUTPUT 'Hub: ', hubName
7      FOR j ← 0 TO 4
8          val ← shipments[i * 4 + j]
9          OUTPUT 'Day: ', j + 1, ' - ', val
10         totalShipments ← totalShipments + val
11     ENDFOR
12 ENDFOR

How could the logic error in this algorithm be corrected so that the correct shipment data for each day and hub is accessed?

A

Change line number 4 to: FOR i←0 TO 4\text{FOR } i \leftarrow 0 \text{ TO } 4FOR i←0 TO 4

B

Change line number 7 to: FOR j←0 TO 3\text{FOR } j \leftarrow 0 \text{ TO } 3FOR j←0 TO 3

C

Change line number 8 to: val←shipments[i∗5+j]\text{val} \leftarrow \text{shipments}[i * 5 + j]val←shipments[i∗5+j]

D

Change line number 8 to: val←shipments[j∗4+i]\text{val} \leftarrow \text{shipments}[j * 4 + i]val←shipments[j∗4+i]

Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

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.

Question bank