Year 10 · Computer Science · Spring 2
Algorithm design and problem solving · Lesson 4 of 5
Searching and sorting; validation and verification
Practical7.4 Standard methods of solution7.5 Validation and verification7.6 Test data
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
You will learn to
- Write and trace a linear search and a bubble sort in pseudocode.
- Explain the difference between validation and verification.
- Describe range, length, type, presence, format and check digit checks, and write a validation loop.
- Choose normal, abnormal, extreme and boundary test data for a range check.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Success criteria
You have got it when you can say:
- I can trace one full pass of a bubble sort on five numbers.
- I can name the check that stops an age of 150, and write it in pseudocode.
- I can explain why a double entry check is verification, not validation.
- I can give test data of each type for a range check of 1 to 100.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
Bubble sort stops when…
A Half the list is sortedB The first swap happensC A whole pass makes no swaps
C. A whole pass makes no swaps
- Last unit
A MAC address is…
A Given out by the router each timeB The name of a websiteC The fixed hardware address of a network card
C. The fixed hardware address of a network card
- Earlier this year
A 10 × 10 image at 8 bits per pixel takes…
A 8,000 bitsB 80 bytesC 800 bits = 100 bytes
C. 800 bits = 100 bytes
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Key words (1 of 4)
- Program development life cycle
- The four stages of making a program: analysis, design, coding and testing.
- Pseudocode
- A structured, code-like way of writing an algorithm that is not tied to one language.
- Totalling
- Adding values into a running total, for example Total ← Total + Value.
- Counting
- Adding 1 to a counter each time something happens.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Key words (2 of 4)
- Linear search
- Checking each item in a list in turn until the target is found or the list ends.
- Bubble sort
- Sorting by comparing neighbouring items and swapping them if they are in the wrong order, pass after pass.
- Validation
- An automatic check that input data is reasonable and follows set rules.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Key words (3 of 4)
- Verification
- A check that data has been copied or typed in exactly as the original.
- Check digit
- An extra digit calculated from the other digits, used to catch typing errors.
- Normal data
- Test data that should be accepted.
- Abnormal data
- Test data that should be rejected.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Key words (4 of 4)
- Extreme data
- The largest and smallest values that should be accepted.
- Boundary data
- The largest and smallest accepted values and the nearest rejected values next to them.
- Trace table
- A table used in a dry run to record the value of each variable as an algorithm runs.
7.4 Standard methods of solution · The explanation · step 1 of 13 · part 1 of 5
Totalling and counting
Totalling means adding values into a running total: `Total ← Total + Value`.
Counting means adding 1 each time something happens: `Count ← Count + 1`.
Both variables must start at 0 before the loop.
7.4 Standard methods of solution · The explanation · step 1 of 13 · part 2 of 5
Totalling and counting (continued)
7.4 Standard methods of solution · The explanation · step 1 of 13 · part 3 of 5
Totalling and counting (continued)
DECLARE Marks : ARRAY[1:6] OF INTEGER
DECLARE Index : INTEGER
DECLARE Total : INTEGER
DECLARE PassCount : INTEGER
// Marks already holds 34, 48, 21, 40, 15, 45
Total ← 0
PassCount ← 0
FOR Index ← 1 TO 6
Total ← Total + Marks[Index]
IF Marks[Index] >= 25
THEN
PassCount ← PassCount + 1
ENDIF
NEXT Index
OUTPUT "Total: ", Total
OUTPUT "Number of passes: ", PassCount7.4 Standard methods of solution · The explanation · step 1 of 13 · part 4 of 5
Totalling and counting (continued)
marks = [34, 48, 21, 40, 15, 45]
total = 0
pass_count = 0
for index in range(6):
total = total + marks[index]
if marks[index] >= 25:
pass_count = pass_count + 1
print("Total:", total)
print("Number of passes:", pass_count)7.4 Standard methods of solution · The explanation · step 1 of 13 · part 5 of 5
Totalling and counting (continued)
Setting Total to 0 inside the loop is a classic error. The total is wiped each time round, so only the last value is kept.
7.4 Standard methods of solution · The explanation · step 2 of 13 · part 1 of 6
Finding the maximum and minimum
To find the maximum (largest), keep a variable `Highest`. Compare each value with it. If the value is bigger, it becomes the new `Highest`.
The minimum (smallest) works the same way with `Lowest` and `<`.
Start `Highest` at the smallest possible value and `Lowest` at the largest possible value. Another safe way is to start both at the first item.
7.4 Standard methods of solution · The explanation · step 2 of 13 · part 2 of 6
Finding the maximum and minimum (continued)
7.4 Standard methods of solution · The explanation · step 2 of 13 · part 3 of 6
Finding the maximum and minimum (continued)
DECLARE Marks : ARRAY[1:6] OF INTEGER DECLARE Index : INTEGER DECLARE Highest : INTEGER DECLARE Lowest : INTEGER // Marks already holds 34, 48, 21, 40, 15, 45 (each out of 50) Highest ← 0 Lowest ← 50
7.4 Standard methods of solution · The explanation · step 2 of 13 · part 4 of 6
Finding the maximum and minimum (continued)
FOR Index ← 1 TO 6
IF Marks[Index] > Highest
THEN
Highest ← Marks[Index]
ENDIF
IF Marks[Index] < Lowest
THEN
Lowest ← Marks[Index]
ENDIF
NEXT IndexOUTPUT "Highest: ", Highest OUTPUT "Lowest: ", Lowest
7.4 Standard methods of solution · The explanation · step 2 of 13 · part 5 of 6
Finding the maximum and minimum (continued)
marks = [34, 48, 21, 40, 15, 45]
highest = 0
lowest = 50
for index in range(6):
if marks[index] > highest:
highest = marks[index]
if marks[index] < lowest:
lowest = marks[index]
print("Highest:", highest)
print("Lowest:", lowest)7.4 Standard methods of solution · The explanation · step 2 of 13 · part 6 of 6
Finding the maximum and minimum (continued)
If Lowest starts at 0, no mark is ever smaller, so the answer is wrong. Start Lowest at the top of the range (50 here) or at the first value.
The explanation · 11 more steps
More on the lesson page
The lesson page has the rest of the explanation, step by step:
- Finding the average
- Linear search
- Bubble sort
- How many comparisons? (extra)
- Validation and verification are different
- Range, length, type and presence checks
- Format and check digit checks
- Writing a validation loop
- Verification: visual check and double entry
- The four types of test data
- Worked example: a test plan
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Try it: Bubble sort, one comparison at a time
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Try it: Binary search, step by step
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Try it: Test the score checker (0 to 50)
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Quick quiz · 1 of 3
Abnormal test data is…
- A Data at the edge of the range
- B Data that should be rejected
- C Typical data
B. Data that should be rejected
Normal works, abnormal is rejected, extreme sits on the edge, boundary is either side of it.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Quick quiz · 2 of 3
A range check on age 0 to 120 would reject…
- A 150
- B 0
- C 120
A. 150
0 and 120 are the edges and are allowed. 150 is outside.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Quick quiz · 3 of 3
Typing an email address twice to check it is…
- A A trace table
- B Verification
- C Validation
B. Verification
Validation checks the data is sensible; verification checks it was entered as intended.
Year 10 · Computer Science · Algorithm design and problem solving · Lesson 4 of 5
Exit ticket
Answer on paper before you go. Then check.
In a trace table you write a new row…
A Only at the endB Only for OUTPUTC Each time a value changes
C. Each time a value changes One column per variable, one row per change.
A diamond in a flowchart means…
A Input or outputB A processC A decision
C. A decision Rectangle: process. Parallelogram: input or output. Diamond: a question with yes and no.