Question bank › A-level Computer Science › Paper 1 – Programming, data structures & algorithms

Theory of computation (FSMs, regular expressions, BNF, Turing machines, Big-O)

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]

4Standard4 marks

(a) State the time complexity of the following algorithm in terms of n. [1]

FOR i ← 1 TO n
  FOR j ← 1 TO n
    OUTPUT i * j
  ENDFOR
ENDFOR

(b) State the time complexity of a binary search on a sorted list of n items. [1]

(c) An algorithm with time complexity O(n²) takes 4 ms for n = 1000. Estimate the time it takes for n = 3000. Show your working. [2]

5Hard6 marks

A Turing machine has the transition table below. Symbols are 0, 1 and _ (blank). The tape is blank on both sides of the input. The head starts on the leftmost symbol of the input in state q0. H is the halting state. Each rule is (new state, symbol written, direction).

StateRead 0Read 1Read _
q0(q0, 0, R)(q0, 1, R)(q1, _, L)
q1(H, 1, R)(q1, 0, L)(H, 1, R)

(a) The tape initially holds 1011. Give the tape contents when the machine halts. [1]

(b) State what the machine does to the binary number on the tape. [1]

(c) State the number of transitions the machine makes on the input 1011, including the one that enters H. Show your working. [2]

(d) Explain why a Turing machine is a useful model of computation. [2]

6Standard4 marks

(a) State what is meant by the halting problem. [1]

(b) State the significance of the halting problem for computer scientists. [1]

(c) Distinguish between a problem that is intractable and a problem that is unsolvable. [2]

7Hard5 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

Still losing marks on this topic?

Book a free introductory session and we'll find exactly which step is costing you.

Book a free intro