17.3. Computer Programs to Solve Computational Problems

Programs that solve computational problems can be written in a variety of forms.


Finite-state machines

Finite state machines are the simplest model of computation. To construct one:

  1. Choose an alphabet A. It should be the alphabet of the problem that the machine is intended to solve.

  2. Choose a finite, nonempty set of states. Any finite nonempty set will do. Often, the set of states has the form {1, 2, 3, …, n} for some n.

  3. Designate one of the states as the start state.

  4. Designate each state as either a yes-state or a no-state.

  5. For each state q and each symbol σ in alphabet A, choose another state r and add a transition from q to r on σ.

    Your choices of transitions define a function δ(q, σ) that takes a state and a symbol and yields state.

To run a finite state machine, start in the start state. Successively get characters from the input string.

At any given point, if you are in state q and see symbol a, move to state δ(q, a).

After reading the last symbol of the input, if you end in a yes-state, the machine answers yes. If you end in a no-state, the machine answers no.


Turing machines

Turing machines are considerably more involved than finite-state machines. But the general idea is simple.

A Turing machine has two alphabets, a tape alphabet and an input alphabet. The tape alphabet must contain at least one symbol, called the blank symbol, that is not in the input alphabet.

A Turing machine has an infinitely long tape that has a left end but is infinitely long to the right.

There is a single tape head that the program can move left or right. The program can also read the symbol at the head or write a symbol at the head.

Initially, the input is written on the tape starting at the left end, followed by infinitely many blank symbols. The input must be written using the input alphabet.

Turing machines serve as a standard model for discussing computation. They are very useful for doing some involved proof.

But in most cases, we can comfortably use more convenient models of computation, due to the Church/Turing Thesis.

The Church/Turing Thesis. The problems computable by Turing machines are exactly the same as the problems computable using the intuitive notion of an algorithm.

General programs

We can write programs in any convenient form, as long as the algorithm is clear, and does not rely on any subjective steps.