Question 2
AQA Computer Science June 2017 Paper 1A level7 marks
On the specification
- 2.1
- 4.4 Theory of computation
- 2.2
- 4.4 Theory of computation
- 2.3
- 4.4 Theory of computation
- 2.4
- 4.4 Theory of computation
Question text
2 Postcodes are used to aid the sorting of mail and help to ensure that mail being sent arrives at the correct destination as quickly as possible. The format of a UK postcode (ignoring any spaces) is shown in Figure 2. Figure 2 • 1 or 2 letters • followed by: o 1 numeric digit or o 2 numeric digits or o 1 numeric digit then 1 letter • followed by 1 numeric digit • followed by 2 letters When a post box is emptied in the town of Ipswich the mail in the post box is taken to a central sorting office. Each item is looked at and placed in one of three vans depending upon the postcode written on the envelope. Postcodes that begin with IP1, IP2, IP3 or IP4 followed by one numeric digit and two letters, eg IP2 8QY, are for mail being sent to an address in the town of Ipswich and go in Van A. Other postcodes that begin with IP, eg IP5 3QW, are for areas not in the town but near to Ipswich and go in Van B. Postcodes that start with anything other than IP, eg CO3 5FN, are not for the Ipswich area and go in Van C. IP postcodes do not use the full range of formats available for UK postcodes. A finite state machine (FSM) could be used to sort mail using postcodes. Figure 3 shows a state transition diagram for an FSM used at the Ipswich sorting office. In Figure 3, if a transition is not defined from a state for a particular input symbol then the FSM will stop processing the input and it will be rejected. 2.1 If the FSM in Figure 3 reaches state S12 what does it mean? [1 mark] 2.2 If the FSM in Figure 3 finishes at state S11 what does it mean? [1 mark] 2.3 Assuming that the FSM in Figure 3 can be used to recognise any valid IP postcode, state one format used for UK postcodes that IP postcodes do not use. [1 mark] Figure 3 Figure 2 is repeated below. Figure 2 • 1 or 2 letters • followed by: o 1 numeric digit or o 2 numeric digits or o 1 numeric digit then 1 letter • followed by 1 numeric digit • followed by 2 letters 2.4 The language recognised by an FSM can also be represented by a regular expression. When writing regular expressions \d is used to represent any numeric digit and \a is used to represent any alphabetic character. For example, the regular expression \d \d \a \d describes the language of all strings that contain two numeric digits followed by one letter and then one numeric digit. Write a regular expression that represents a valid UK postcode as described in Figure 2. In your answer you should only use the | metacharacter once. [4 marks]