Question bank › A-level Computer Science › Theory of computation

FSMs, regular expressions and BNF

Answer on paper first, then reveal the mark scheme one mark at a time.

1Core4 marks

The finite state machine (FSM) below has start state A and accepting state C. The input alphabet is {0, 1}.

(a) State whether the input 10101 is accepted. Justify your answer. [1]

(b) State whether the input 0110 is accepted. Justify your answer. [1]

(c) Describe the set of strings that this FSM accepts. [1]

(d) Write a regular expression that defines the same language as this FSM. [1]

ABC010110
2Standard4 marks

A regular expression is a(b|c)*d.

(a) The strings below are tested against the whole regular expression. Identify which strings match.

ad   abcd   abbcb   acbbd   abdd   aabd [2]

(b) Write a regular expression for the set of all strings of 0s and 1s that start with 1 and end with 0. [2]

3Standard5 marks

A number format is defined using Backus-Naur Form (BNF):

<digit> ::= 0|1|2|3|4|5|6|7|8|9
<unsigned> ::= <digit> | <digit><unsigned>
<number> ::= <unsigned> | +<unsigned> | -<unsigned>

(a) State which of these are valid <number>s: -07   +-5   5-   42 [2]

(b) Explain how the definition of <unsigned> allows numbers of any length. [1]

(c) Write BNF rules for a <name> that must start with a letter followed by any number of letters or digits. You may assume <letter> and <digit> are already defined. [2]

Stuck on FSMs, regular expressions and BNF?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Hard5 marks

The FSM below has start state A, which is also the only accepting state. The input alphabet is {0, 1}.

(a) State whether each input is accepted: 1001 and 0111. [2]

(b) Write a regular expression for the strings accepted by the FSM. [2]

(c) Explain why an FSM cannot be used to recognise the language of strings with n 0s followed by exactly n 1s for any n. [1]

AB1100

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session