Question 2

AQA Computer Science Specimen Paper 1 (7517/1)A level7 marks

On the specification

2.1
3.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 A finite state machine (FSM) can be used to define a language: a string is allowed in a language if it is accepted by the FSM that represents the rules of the language. Figure 1 shows the state transition diagram for an FSM. Figure 1 1 1, 0 S2 S4 1 0 S1 1 0 S3 0 An FSM can be represented as a state transition diagram or as a state transition table. Table 1 is an incomplete state transition table for Figure 1. Complete Table 1 and copy the table into the Electronic Answer Document. 2.1 Table 1 Original state Input New state S3 S3 [1 mark] Any language that can be defined using an FSM can also be defined using a regular expression. The FSM in Figure 1 defines the language that allows all strings containing at least, either two consecutive 1s or two consecutive 0s. The strings 0110, 00 and 01011 are all accepted by the FSM and so are valid strings in the language. The strings 1010 and 01 are not accepted by the FSM and so are not valid strings in the language. 2.2 Write a regular expression that is equivalent to the FSM shown in Figure 1. [3 marks] Backus-Naur Form (BNF) can be used to define the rules of a language. Figure 2 shows an attempt to write a set of BNF production rules to define a language of full names. Figure 2 Note: underscores (_) have been used to denote spaces. Note: rule numbers have been included but are not part of the BNF rules. Rule 1 <fullname> ::= <title>_<name>_<endtitle> | <name> | <title>_<name> | <name>_<endtitle> 2 <title> ::= MRS | MS | MISS | MR | DR | SIR 3 <endtitle> ::= ESQUIRE | OBE | CBE 4 <name> ::= <word> | <name>_<word> 5 <word> ::= <char><word> 6 <char> ::= A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z BNF can be used to define languages that are not possible to define using regular expressions. The language defined in Figure 2 could not have been defined using regular expressions. 2.3 Complete Table 2 below by writing either a ‘Y’ for Yes or ‘N’ for No in each row. Table 2 Rule number Could be defined using a regular expression (given in Figure 2) 1 2 3 4 5 6 Copy your answer in Table 2 into the Electronic Answer Document. [1 mark] There is an error in rule 5 in Figure 2 which means that no names are defined by the language. 2.4 Explain what is wrong with the production rule and rewrite the production rule so that the language does define some names – the names ‘BEN D JONES’, ‘JO GOLOMBEK’ and ‘ALULIM’ should all be defined. [2 marks]