The shape of the lesson
By the end of the lesson, learners can
- Declaring an array: The declaration gives the identifier, the range of indexes and the data type of every element.
- Arrays and loops: In the lab, choose Maximum and minimum.
- Using the index: The index can be any expression that gives an integer, so a program can search an array, or move values between neighbouring elements, such as Names[Count + 1].
- Declare: DECLARE Name : ARRAY[1:n] OF type.
- Access: Name[Index], where Index can be a variable or expression.
- Loop: FOR Index ← 1 TO n to input, total or search every element.
- Max and min: start with the first element, then compare the rest.
One picture every idea returns to
An array is a data structure that holds a fixed number of elements of the same data type under one identifier. Each element is reached by its index, written in square brackets: Scores[3]. Declare it with its lower and upper bounds: DECLARE Scores : ARRAY[1:5] OF INTEGER. The first index can be 0 or 1 (exam pseudocode generally uses 1). Because the index can be a variable, a FOR loop can visit every element in turn.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, One name, many values.. Storing 30 test marks in 30 separate variables would be painful. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Declaring an array | The declaration gives the identifier, the range of indexes and the data type of every element. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Arrays and loops | In the lab, choose Maximum and minimum. Project tab 2 of the lab (Arrays with standard methods) and let a student drive it while the class predicts. Model the worked example Finding the largest on the board, one line at a time. | Pairs |
| 21 to 30 min | Teach and check: Using the index | The index can be any expression that gives an integer, so a program can search an array, or move values between neighbouring elements, such as Names[Count + 1]. Model the worked example Linear search on the board, one line at a time. Your turn: Count is 2. Which element does Names[Count + 1] refer to? | Think-Pair-Share |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 19 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Using the index, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Think-Pair-Share
Pose the question, give thirty seconds of silent thinking, then a minute to compare with a partner before a few pairs share with the class. The silent minute is the part that cannot be cut.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| Using an index outside the bounds, such as Scores[6] or Scores[0] for ARRAY[1:5], is an error: that element does not exist. | Return to Declaring an array: ask a pair to state the correct version and show it on the lab before moving on. |
| Start Highest at the first element, not at 0: if every value were negative, a starting value of 0 would be wrongly output as the largest. | Return to Arrays and loops: ask a pair to state the correct version and show it on the lab before moving on. |
One-dimensional arrays: worksheet
6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.
Describe what is meant by a one-dimensional array.
Write pseudocode to declare an array Heights to store 20 real values and use a loop to input all 20 values.
The array Prices[1:50] holds 50 prices. Write pseudocode to find and output the lowest price.
State the values stored in Data and the output.
FOR Index ← 1 TO 4
Data[Index] ← Index * Index - 1
NEXT Index
OUTPUT Data[2] + Data[4]The array Marks[1:30] holds 30 marks. Write pseudocode to count and output how many marks are 50 or more.
Explain why storing 30 names in an array is better than using 30 separate variables.
Answer key and marking notes
- A data structure with a fixed number of elements under a single identifier.
- All the elements are of the same data type.
- Each element is accessed using an index (its position).
DECLARE Heights : ARRAY[1:20] OF REALFOR Index ← 1 TO 20...NEXT IndexINPUT Heights[Index]inside the loop
Lowest ← Prices[1]FOR Index ← 2 TO 50IF Prices[Index] < Lowest THEN Lowest ← Prices[Index]- After the loop:
OUTPUT Lowest
- Data[1] = 0, Data[2] = 3.
- Data[3] = 8, Data[4] = 15.
- Output: 3 + 15 = 18
Count ← 0before the loopFOR Index ← 1 TO 30IF Marks[Index] >= 50 THEN Count ← Count + 1- After the loop:
OUTPUT Count
- Only one identifier is needed, so the code is shorter and easier to read.
- A loop with the index as the loop variable can process every name with the same statements.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
An array is declared with DECLARE Temps : ARRAY[1:7] OF REAL. Which statement is correct?
- AIt holds 7 elements, and every element is REAL
- BIt holds 8 elements, and every element is REAL
- CIt holds 7 elements, and each element can be any data type
- DIt holds a single REAL value that is 7 digits long
Scores is ARRAY[1:5] OF INTEGER and holds 12, 7, 15, 9, 11 in that order. What is output by OUTPUT Scores[2] + Scores[4]?
- A16
- B26
- C6
- D22
Scores is declared as ARRAY[1:5] OF INTEGER. Which statement causes an error when it runs?
- A
Scores[0] ← 4 - B
Scores[5] ← 0 - C
Scores[1] ← Scores[5] - D
Scores[3] ← Scores[3] + 1
Scores holds 4, 9, 2, 9, 6 and the input is 9. What is output?
INPUT Target
Found ← FALSE
Index ← 1
WHILE Found = FALSE AND Index <= 5 DO
IF Scores[Index] = Target
THEN
Found ← TRUE
ELSE
Index ← Index + 1
ENDIF
ENDWHILE
IF Found = TRUE
THEN
OUTPUT "Found at position ", Index
ELSE
OUTPUT "Not found"
ENDIF- AFound at position 2
- BFound at position 4
- CFound at position 9
- DNot found
Temps is ARRAY[1:4] OF INTEGER and holds -3, -8, -1, -5. What is output?
Highest ← 0
FOR Index ← 1 TO 4
IF Temps[Index] > Highest
THEN
Highest ← Temps[Index]
ENDIF
NEXT Index
OUTPUT Highest- A0
- B-1
- C-8
- D-3
Data is ARRAY[1:5] OF INTEGER and holds 3, 8, 1, 6, 4. The code is meant to move every value one place to the right. What does Data hold afterwards?
FOR Index ← 2 TO 5
Data[Index] ← Data[Index - 1]
NEXT Index- A3, 3, 3, 3, 3
- B3, 3, 8, 1, 6
- C8, 1, 6, 4, 4
- D3, 8, 1, 6, 4
Quiz key
The bounds 1 to 7 give 7 elements, Temps[1] to Temps[7], and every element of an array has the same data type, here REAL. 8 would be the count for bounds 0 to 7. An array cannot mix data types. The bounds set the number of elements, not the size of one value.
Scores[2] is 7 and Scores[4] is 9, so 7 + 9 = 16. 26 counts from 0 (15 + 11). 6 adds the indexes instead of the values. 22 uses the elements at positions 2 and 3 (7 + 15).
Index 0 is below the lower bound of 1, so Scores[0] does not exist. Scores[5] is the last element and is valid. Copying Scores[5] into Scores[1] uses two valid indexes. Adding 1 to Scores[3] reads and writes a valid element.
Scores[1] is 4, so Index becomes 2; Scores[2] is 9, so Found becomes TRUE and the loop stops with Index = 2. Position 4 holds the second 9, which is never reached. 9 is the value, not its position. Not found would need no element to equal 9.
Every element is negative, so no Temps[Index] > 0 is ever TRUE and Highest keeps its starting value: 0 is output, although 0 is not in the array. Starting with Highest ← Temps[1] would give the correct largest, -1. -8 is the smallest value. -3 is the first element.
Pass 1 copies Data[1] (3) into Data[2]; pass 2 copies the new Data[2] (3) into Data[3], and so on, so every element ends up 3. 3, 3, 8, 1, 6 is the intended result, which needs the loop to run backwards from 5 down to 2. 8, 1, 6, 4, 4 is a shift to the left. 3, 8, 1, 6, 4 assumes nothing changes.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.