Question 9

AQA Computer Science June 2019 Paper 1GCSE6 marks

On the specification

3.1 Fundamentals of algorithms3.2 Programming
Question text

9 A black and white image can be represented as a two-dimensional array where: box • 0 represents a white pixel • 1 represents a black pixel. Two images are exact inverses of each other if: • every white pixel in the first image is black in the second image • every black pixel in the first image is white in the second image. For example, B is the inverse of A but C is not the inverse of A: A B C A developer has started to create an algorithm that compares two 3x3 black and white images, image1 and image2, to see if they are exact inverses of each other. Complete the algorithm in pseudo-code, ensuring that, when the algorithm ends, the value of the variable inverse is true if the two images are inverses of each other or false if they are not inverses of each other. The algorithm should work for any 3x3 black and white images stored in image1 and image2. • Note that indexing starts at zero. image1 ← [ [0, 0, 0], [0, 1, 1], [1, 1, 0] ] image2 ← [ [1, 1, 1], [1, 1, 0], [0, 0, 1] ] inverse ← true i ← 0 WHILE i ≤ 2 j ← 0 WHILE j ≤ 2 [6 marks]