दुर्गा बेरागी Durga Beragi, homeEnter the study →

Library › Foundations of computing

Introduction to Automata Theory, Languages, and Computation

John E. Hopcroft and Jeffrey D. Ullman · 1979 · Addison-Wesley

Machines classified by what languages they can recognise.

About the book

John Hopcroft and Jeffrey Ullman published this textbook with Addison-Wesley in 1979. It grew from their earlier Formal Languages and Their Relation to Automata of 1969. The book covers finite automata and regular expressions, context-free grammars and pushdown automata, Turing machines, undecidability, the Chomsky hierarchy and computational complexity, including NP-completeness. It is rigorous, with full proofs and many exercises. Later editions, from 2001, added Rajeev Motwani as an author and were rewritten to be more accessible to undergraduates. The first edition remains the classic version for graduate study and for reference.

Key ideas

  • Machines can be classified by the languages they recognise. Finite automata recognise regular languages; pushdown automata recognise context-free languages; Turing machines recognise recursively enumerable languages.
  • Regular expressions and finite automata describe exactly the same class of languages. The book proves this equivalence by converting each form into the other, which is how practical pattern matchers are built.
  • Context-free grammars describe the syntax of most programming languages. Pushdown automata, which add a stack to a finite machine, recognise exactly the languages such grammars generate.
  • Some problems are undecidable. No Turing machine can decide in general whether another machine halts, and many natural questions about grammars turn out to be undecidable too.
  • Complexity classes such as P and NP measure how much time or space a problem needs. NP-complete problems are widely believed to have no efficient general solution.

Why it is on this shelf

It is the standard reference for the theory behind compilers, parsers and computation. It formalises the ideas in Turing's and Gödel's papers elsewhere in this bay. Working through it gives a precise sense of what each kind of machine can and cannot do.

How to start reading it

Read the chapters on finite automata and regular expressions first. Then read context-free grammars and Turing machines. Do exercises; the theory sinks in only through proofs.

About this book

Introduction to Automata Theory, Languages, and Computation is a textbook by John E. Hopcroft and Jeffrey D. Ullman, published by Addison-Wesley in 1979. It sets out the mathematical theory of what machines can compute, organised around a single idea: that different kinds of abstract machine can be classified by the sets of strings, called languages, that they are able to recognise. For two decades it was the standard text on the subject in universities around the world. Students called it the Cinderella book, after the illustration on its cover.

It grew out of an earlier book by the same authors, Formal Languages and Their Relation to Automata, published in 1969. That book had gathered a field that was then barely fifteen years old into a coherent whole. The 1979 book reorganised and expanded it, adding a substantial treatment of computational complexity, including the theory of NP-completeness, which had been developed only in the early 1970s. Later editions, beginning in 2001, added Rajeev Motwani as a third author and were substantially rewritten for a broader undergraduate audience. The 1979 edition remains the classic version, denser and more complete, and is still used as a reference by researchers.

The question the book answers can be stated simply. Given a kind of machine, with some particular amount and kind of memory, what problems can it solve, and what problems are beyond it? And among problems that can be solved, which can be solved efficiently? The book answers by building a ladder of machines, each more powerful than the last, and proving exactly what each rung can and cannot do.

The intended reader is a student of computer science at the advanced undergraduate or beginning graduate level, with some comfort in mathematical proof. The book is rigorous. It states definitions precisely, proves theorems in full, and includes many exercises, ranging from routine to research-level. It is not a book to read casually. It is a book to work through with a pencil.

Why does such a theory matter? Because it underlies much of practical computing. Every time a program searches text for a pattern, it uses ideas from the first chapters of this book. Every time a compiler reads source code and checks its grammar, it uses ideas from the middle chapters. Every time a programmer is told that a problem has no efficient general solution, or that some property of programs cannot be checked automatically, the reason lies in the later chapters. The theory is abstract, but its consequences are everywhere.

The authors

John Hopcroft

John Edward Hopcroft was born in 1939 in Seattle. He studied electrical engineering, taking his doctorate at Stanford in 1964. He taught at Princeton and then moved to Cornell University, where he spent most of his career. His research covered automata theory, algorithms and data structures, and later robotics and other areas.

In 1986 he shared the Turing Award with Robert Tarjan for fundamental work in the design and analysis of algorithms and data structures. Among their joint results was an efficient algorithm for testing whether a graph can be drawn in the plane without crossing edges. Hopcroft also gave a well-known algorithm for minimising finite automata, which finds the smallest machine equivalent to a given one, and with Richard Karp an efficient algorithm for matching in bipartite graphs. His work is marked by a concern for efficiency: not merely whether a problem can be solved but how fast.

Jeffrey Ullman

Jeffrey David Ullman was born in 1942. He studied engineering mathematics at Columbia and took his doctorate in electrical engineering at Princeton in 1966. He worked at Bell Labs for several years, taught at Princeton, and in 1979 moved to Stanford, where he remained. He has written or co-written many standard textbooks, on algorithms, compilers, database systems and data mining.

With Alfred Aho he wrote the classic texts on compiling, the most famous being Compilers: Principles, Techniques, and Tools, written with Ravi Sethi, which sits in this same bay. Aho and Ullman shared the Turing Award for 2020 for fundamental algorithms and theory underlying programming language implementation, and for synthesising these results in influential books. Aho, Hopcroft and Ullman together wrote The Design and Analysis of Computer Algorithms in 1974, one of the founding textbooks of the algorithms field.

A partnership of textbook writers

Hopcroft and Ullman, together with Aho, shaped how theoretical computer science was taught for a generation. Their books took results scattered across research papers and gave them a consistent notation, a logical order and full proofs. That work of synthesis is easy to underrate. Before such books existed, a student wanting to learn the field had to read dozens of papers written in different styles and notations. After them, there was a canon. Much of what is now considered standard in the theory of computation is standard partly because these authors chose to present it that way.

The shape of the argument

The book's organising principle is a hierarchy of machines matched to a hierarchy of languages. It climbs the hierarchy from the simplest machines to the most powerful, and then turns to ask not only what can be computed but how efficiently.

Foundations

The book opens with mathematical preliminaries: sets, relations, strings, graphs, and methods of proof, especially proof by induction. It defines a language as any set of strings over a finite alphabet. This definition is simple but powerful. A programming language is a set of strings, the valid programs. A set of numbers can be treated as a language by writing the numbers as strings. Any yes-or-no question can be recast as a language: the set of inputs for which the answer is yes. So asking which languages a machine can recognise is the same as asking which yes-or-no questions it can answer.

The ladder of machines

The bulk of the book climbs a ladder. At the bottom are finite automata, machines with a fixed, finite amount of memory. They recognise the regular languages, which are also exactly the languages described by regular expressions. Next come pushdown automata, which add a stack, an unbounded memory that can only be accessed at the top. They recognise the context-free languages, which are also exactly those generated by context-free grammars. At the top are Turing machines, which have an unbounded tape they can read and write anywhere. They recognise the recursively enumerable languages, and they are believed to capture everything that can be computed at all.

At each rung, the book does the same things. It defines the machine. It defines the matching descriptive formalism, such as regular expressions or grammars. It proves the two are equivalent. It proves closure properties, showing which operations on languages keep you within the class. It proves limits, showing specific languages that the class cannot contain. And it studies decision problems, asking which questions about the machines can be answered by algorithms.

Undecidability and the hierarchy

With Turing machines in hand, the book proves that some problems cannot be solved by any algorithm at all, beginning with the problem of deciding whether a machine accepts a given input. It shows how undecidability spreads by reduction to many natural problems, including questions about grammars. It then gathers the classes of languages into the Chomsky hierarchy, named after the linguist Noam Chomsky, who defined four nested classes of grammars in the 1950s, and adds an intermediate class of machines between pushdown automata and Turing machines.

Complexity

The final part turns from what can be computed to what can be computed efficiently. It defines classes of problems by the time or space a machine needs to solve them, proves that more resources really do allow more problems to be solved, and introduces the classes P and NP and the theory of NP-completeness. This part connects the book's abstract machinery to the practical question of which problems are feasible.

Through all of this, the method is uniform: precise definitions, constructive proofs that show how to convert one formalism into another, and impossibility proofs that show what cannot be done. The book's lasting value lies less in any single theorem than in this disciplined method, which a reader absorbs by working through it.

Idea one: languages as problems

The book's starting point is a reframing. Instead of asking what a machine does, it asks which strings a machine accepts. A machine reads an input string and either accepts or rejects it. The set of strings it accepts is its language. Two machines that accept the same set of strings are equivalent, however differently they work inside.

This reframing turns questions about computation into questions about sets. Is a number prime: consider the language of strings that represent prime numbers. Is a program syntactically valid: consider the language of valid programs. Does a graph have a route visiting every node once: consider the language of strings encoding such graphs. Any decision problem becomes a membership question for some language.

Why this is powerful

The power of the reframing is that it makes very different problems comparable. Once everything is a language, one can ask the same questions of all of them: which machines can recognise it, how much memory they need, how much time. One can compare problems by translating one into another. One can build a single theory that covers text search, compilers and the limits of mathematics.

An analogy: before the metric system, different trades measured length with different units, and comparing them was awkward. A common unit made every length comparable. Treating problems as languages is a common unit for computation. It allows a single scale on which every yes-or-no question can be placed.

What it is often confused with

The word language here does not mean a human language, although the theory was partly inspired by linguistics and does say things about human grammar. A language in this sense is just a set of strings, possibly infinite, with no meaning attached. The strings of the language of balanced parentheses mean nothing; they simply are or are not in the set. Students sometimes look for meaning where the theory deliberately has none. The point is structure, not semantics.

Idea two: finite automata and regular expressions

A finite automaton is the simplest kind of machine the book considers. It has a fixed, finite set of states. It reads its input one symbol at a time, from left to right. Each symbol moves it from its current state to a next state, according to a fixed table. Some states are marked as accepting. When the input is finished, the machine accepts if it is in an accepting state.

That is all. There is no other memory. Everything the machine knows about what it has read so far must be captured by which state it is in. A machine with ten states can distinguish at most ten different situations. This makes finite automata simple, fast and limited.

Everyday examples

Many ordinary devices are finite automata. A turnstile that is either locked or unlocked, changing state when a coin is inserted or someone pushes through, is one. A vending machine that tracks how much money has been inserted, up to the price of an item, is one. A traffic light controller is one. A program that checks whether a string is a valid number, with optional sign, digits, decimal point and more digits, can be written as one. Each has a small, fixed number of situations it can be in.

Nondeterminism

The book introduces a variation: nondeterministic finite automata. Such a machine may have several possible next states for a given symbol, or none, and may change state without reading anything. It accepts if any possible path through its states leads to acceptance. This sounds like a more powerful machine, since it can in effect guess. The book proves that it is not. Every nondeterministic automaton can be converted into a deterministic one that accepts the same language, by building a machine whose states are sets of the original's states. The deterministic machine may be much larger, exponentially so in the worst case, but it exists.

This result is the first appearance of a theme that runs to the end of the book. Nondeterminism, the ability to guess and check, sometimes adds no power at all, sometimes adds power, and sometimes its effect is unknown. For finite automata it adds no power. For pushdown automata it does. For the efficiency of Turing machines, whether it adds power is the famous open question of P versus NP.

Regular expressions

Regular expressions are a different way of describing languages: algebraic formulas built from single symbols using three operations, namely union, concatenation and repetition. A regular expression might describe all strings of digits that begin with a nonzero digit, or all strings in which every a is followed by a b. The book proves that regular expressions and finite automata describe exactly the same class of languages, the regular languages. It does this constructively, giving methods to convert any expression into an automaton and any automaton into an expression.

This equivalence is the basis of practical pattern matching. Text editors, search tools and programming languages let users write patterns as regular expressions. The software converts the pattern into an automaton, then runs the automaton over the text. The lexical analysers in compilers, which break source code into words such as identifiers, numbers and operators, are built the same way. Ken Thompson, co-creator of Unix, published one of the classic methods for this conversion in 1968, and Unix tools built on it spread the idea of regular expressions to everyday programmers.

Minimisation

Every regular language has a unique smallest deterministic automaton that recognises it. The book shows how to find it, by merging states that cannot be distinguished by any future input. This result, connected to a theorem of Myhill and Nerode, gives a precise characterisation of what a finite automaton must remember: exactly as many distinct situations as there are ways the rest of the input could matter. It is a beautiful example of a theory telling you not just how to build a machine but what the best machine must look like.

A worked picture

A small example, of our own, shows how much a finite automaton can do with very little. Suppose the task is to read a binary number one digit at a time, from the most significant digit, and decide whether it is divisible by three. The number can be any length, so the machine cannot store it. But it does not need to. It only needs the remainder of the number read so far when divided by three, which is zero, one or two. Reading a new digit doubles the number and adds the digit, so the new remainder can be computed from the old remainder and the digit alone. Three states suffice: one for each remainder. The machine accepts if it ends in the state for remainder zero.

The example shows the right way to think about these machines. The question is never how to store the input. It is what minimal summary of the input so far is enough to decide the rest. For divisibility by three the summary is a remainder. For checking a valid number format it is which part of the format one is in. For the equal-counts language there is no finite summary at all, which is why no finite automaton can do it. This way of thinking, finding the smallest sufficient summary, is useful well beyond automata, for instance in designing streaming algorithms that process data too large to store.

Idea three: the limits of finite memory

Finite automata cannot recognise every language. The simplest example is the language of strings consisting of some number of a's followed by the same number of b's. To recognise it, a machine must remember how many a's it has seen, and that number can be arbitrarily large. A machine with a fixed number of states cannot keep count beyond its size. So no finite automaton can recognise this language.

The pumping lemma

The book makes this argument precise with a tool called the pumping lemma for regular languages. The idea is this. If a finite automaton with some number of states reads a string longer than that number, it must visit some state twice, by the pigeonhole principle. The part of the string read between the two visits forms a loop. That loop can be repeated any number of times, or removed, and the machine will still end in the same state. So for any regular language, every sufficiently long string in it contains a section that can be pumped, repeated or deleted, without leaving the language.

To show a language is not regular, one shows that it violates this property: for some long string in it, every way of pumping produces a string outside the language. For the equal-counts language, pumping a section of a's changes the number of a's without changing the b's, breaking the balance.

Why it matters

This is the first impossibility result in the book, and it teaches a pattern of reasoning used throughout: to show a machine cannot do something, find a property every such machine's language must have, and show the target language lacks it. In practice it explains why regular expressions cannot match balanced parentheses or nested structures, a limit programmers sometimes discover the hard way when trying to parse structured text, such as HTML, with patterns alone.

The pumping lemma is often misused by students, who try to use it to prove a language is regular. It cannot do that. It gives a property all regular languages have, but some non-regular languages have it too. It is a tool for proving non-regularity only. The Myhill-Nerode characterisation, by contrast, gives a condition that is both necessary and sufficient.

Idea four: grammars and pushdown automata

The next rung of the ladder adds structure. A context-free grammar is a set of rules for building strings by replacing symbols. For example, a rule might say that an expression can be an expression plus a term, or just a term, and another that a term can be a number or a parenthesised expression. Starting from a single start symbol and applying rules repeatedly, one generates strings. The language of the grammar is the set of strings of ordinary symbols it can generate.

Context-free grammars can describe nesting, which finite automata cannot. Balanced parentheses, arithmetic expressions with brackets, and the block structure of programming languages are all context-free. This is why grammars of this kind became the standard way to define the syntax of programming languages, beginning with the notation John Backus and Peter Naur used for ALGOL 60 around 1960.

Parse trees and ambiguity

When a grammar generates a string, the sequence of rule applications can be drawn as a tree, called a parse tree, whose leaves spell out the string. The tree shows the string's structure: which parts group with which. A grammar is ambiguous if some string has two different parse trees. Ambiguity matters in practice. If an arithmetic grammar allows two ways to group a minus b minus c, the two groupings give different answers. The book discusses how ambiguity arises and shows that some context-free languages are inherently ambiguous, meaning every grammar for them is ambiguous. It also shows that whether a given grammar is ambiguous is undecidable.

Normal forms

The book shows that any context-free grammar can be transformed into simpler standard shapes, called normal forms, without changing its language. One of these, Chomsky normal form, restricts every rule to produce either two symbols or a single terminal symbol. Such forms simplify proofs and algorithms. For example, a classical algorithm based on dynamic programming can decide whether a string belongs to the language of a grammar in Chomsky normal form in time proportional to the cube of the string's length.

Pushdown automata

The machine that matches context-free grammars is the pushdown automaton. It is a finite automaton with a stack: an unbounded memory where it can push symbols on top and pop them off, but can only look at the top. A stack is exactly what is needed for nesting. On reading an opening bracket, push; on reading a closing bracket, pop and check it matches. The book proves that nondeterministic pushdown automata recognise exactly the context-free languages, again by constructive conversions in both directions.

Here nondeterminism matters. Deterministic pushdown automata, which never need to guess, recognise a strictly smaller class: the deterministic context-free languages. For example, the language of even-length palindromes needs a machine that guesses where the middle is. Fortunately, most programming languages can be given deterministic grammars, which is why they can be parsed efficiently by a single left-to-right pass. The theory of such grammars, including the LR parsing method due to Donald Knuth, underlies the parser generators used to build compilers.

Idea five: what a stack cannot do

Pushdown automata are more powerful than finite automata, but they too have limits. A stack can match one thing against another, such as opening brackets against closing ones. It cannot match three things against each other. The language of strings with some number of a's, then the same number of b's, then the same number of c's, is not context-free. A stack can count the a's and check them against the b's, but by then the count is used up and nothing is left to check the c's.

The book proves such results with a pumping lemma for context-free languages. The argument is similar in spirit to the one for regular languages but works on parse trees instead of state sequences. In a tall enough parse tree, some grammar symbol must repeat along a path from the root to a leaf. The portion of the tree between the two occurrences can be repeated or removed, which pumps two sections of the string at once. Languages that cannot survive such two-section pumping are not context-free. A strengthened version, due to William Ogden, gives more control over where pumping happens and settles harder cases.

Closure and its failures

Context-free languages are closed under union, concatenation and repetition: combining context-free languages in these ways gives context-free languages. But they are not closed under intersection or complement. The intersection of two context-free languages can fail to be context-free; the three-way counting language above is the intersection of two context-free ones, one matching a's with b's and the other b's with c's. This contrasts with regular languages, which are closed under every Boolean operation.

These closure facts are not mere curiosities. They decide what tools can be combined. If one wants to check that a program satisfies a grammar and also some other syntactic constraint, closure properties tell you whether a single context-free parser can do both, or whether separate checks are needed. Many real compilers parse with a context-free grammar and then check additional rules, such as that every variable is declared before use, in a separate pass, precisely because those rules are not context-free.

Decision problems for grammars

Some questions about context-free grammars can be answered by algorithm: whether a grammar generates any strings at all, whether it generates infinitely many, and whether a given string is generated. Others cannot. Whether two grammars generate the same language, whether a grammar generates every possible string, and whether a grammar is ambiguous are all undecidable. The dividing line between these is one of the book's more surprising lessons: questions that look equally simple can lie on opposite sides of a sharp boundary.

Idea six: Turing machines

At the top of the ladder is the Turing machine, introduced by Alan Turing in 1936 as a model of a person carrying out a calculation with pencil and paper. It has a finite set of states, like a finite automaton, and an unbounded tape divided into cells. It has a head that reads one cell, writes a symbol there, and moves one cell left or right, according to a fixed table of rules based on its current state and the symbol read. It may halt in an accepting or rejecting state, or it may run forever.

The difference from a pushdown automaton seems small: the tape can be read and written anywhere, rather than only at the top of a stack. But the effect is enormous. With unrestricted access to unbounded memory, a Turing machine can simulate any procedure that can be described step by step. It can add, multiply, sort, search and simulate other machines, including other Turing machines.

Robustness

The book shows that many variations on the Turing machine have the same power. Machines with several tapes, with tapes infinite in both directions, with several heads, or with nondeterministic choices all recognise exactly the same languages as the basic model, though they may be faster. Even quite different models, such as machines with two counters, or simple programming languages, turn out equivalent. This robustness is strong evidence that Turing machines capture something real and natural, not an accident of one definition.

The Church-Turing thesis

This leads to the Church-Turing thesis: the claim that anything that can be computed by an effective procedure, a finite set of precise instructions that a person could follow mechanically, can be computed by a Turing machine. Alonzo Church reached an equivalent conclusion at about the same time as Turing using a different formalism, the lambda calculus, and the two were shown to be equivalent. The thesis cannot be proved, since effective procedure is an informal idea, but no counterexample has ever been found, and every proposed model of computation built from discrete steps has turned out to be no more powerful.

The thesis is what gives the rest of the book its force. When it proves that no Turing machine can solve a problem, the conclusion is not merely about one model of machine. It is that no algorithm of any kind, in any programming language, on any computer, can solve it.

The universal machine

Turing also showed that there is a universal Turing machine: a single machine that, given a description of any other machine and an input, simulates that machine on that input. This is the theoretical form of the stored-program computer, in which programs are data loaded into memory and run by a fixed processor. Every general-purpose computer is, in principle, a universal machine with a finite tape. The book constructs the idea carefully, because it is the key to the impossibility results that follow.

Machines as data

The universal machine depends on a simple but far-reaching idea: a machine can be written down as a string. Its states, symbols and rules can all be listed in some agreed format, and the list is just a string over a finite alphabet. Once machines are strings, they can be inputs to other machines. A machine can read another machine's description, analyse it, simulate it, or transform it into a different machine.

This is the idea behind every compiler, interpreter and operating system. A compiler is a program that reads programs and writes programs. An interpreter is a program that reads a program and runs it. An operating system loads programs as data and then hands them control. All of this rests on the observation, made precise in this part of the book, that there is no fundamental distinction between a program and the data it works on.

It is also the idea that makes undecidability possible. A machine that can read machine descriptions can be fed its own description. That self-application, harmless in most cases, becomes the lever for the impossibility proofs that follow. The same feature that makes computers universal makes certain questions about them unanswerable. One does not come without the other.

Idea seven: undecidability

The most important result in the book is that some well-defined problems cannot be solved by any algorithm. The first such problem is closely related to Turing's halting problem: given a description of a Turing machine and an input, decide whether the machine accepts that input.

The diagonal argument

The proof uses a diagonal argument, the same family of ideas that Georg Cantor used to show that the real numbers cannot be listed and that Gödel used in his incompleteness theorem. In outline: suppose a machine existed that could decide, for any machine and input, whether the machine accepts the input. Use it to build a new machine that takes a machine description, asks whether that machine accepts its own description, and then does the opposite. Now feed this new machine its own description. Whatever it does contradicts what the decider said it would do. So the decider cannot exist.

An analogy helps some readers. Imagine a list of every possible rule for choosing yes or no for each person in a numbered list of people. Build a new rule that, for person number n, chooses the opposite of what rule number n chooses for that person. This new rule differs from every rule on the list somewhere, so it is not on the list. The diagonal argument for machines works the same way, with machines in place of rules and inputs in place of people.

Reductions

Once one problem is known to be undecidable, others follow by reduction. To show a new problem is undecidable, show that an algorithm for it could be used to build an algorithm for a problem already known to be undecidable. Since the latter is impossible, so is the former. The book uses this technique repeatedly. It shows that it is undecidable whether a machine accepts any input at all, whether two machines accept the same language, and many more.

A sweeping result of this kind is Rice's theorem, which says that every nontrivial property of the language a Turing machine recognises is undecidable. Nontrivial means that some machines have the property and some do not. So whether a machine's language is empty, finite, regular, or contains a particular string: none of these can be decided by algorithm in general. For programmers, this explains why no tool can perfectly check arbitrary programs for properties such as whether they ever reach a certain line or ever produce a certain output. Practical analysis tools work by approximating, accepting either false alarms or missed cases.

Undecidability beyond machines

The book shows that undecidability is not confined to questions about machines. Emil Post's correspondence problem is a simple puzzle about matching sequences of tiles whose top and bottom strings must spell the same word. It looks like a combinatorial game, yet it is undecidable. Through it, the book shows that natural questions about context-free grammars, such as whether two grammars share a common string, are undecidable too. Undecidability appears wherever a problem is rich enough to encode the behaviour of an arbitrary machine.

Recursive and recursively enumerable

The book distinguishes two classes. A language is recursive, or decidable, if some Turing machine always halts and correctly says yes or no. A language is recursively enumerable if some Turing machine halts and says yes for every string in it, but may run forever on strings not in it. The acceptance problem is recursively enumerable but not recursive: one can confirm a yes answer by simulating the machine, but no procedure can always confirm a no. And its complement is not even recursively enumerable. This asymmetry, between being able to verify membership and being able to verify non-membership, is one of the deep facts of the theory.

Idea eight: the Chomsky hierarchy

In the 1950s the linguist Noam Chomsky classified grammars into four types according to the forms their rules may take. The most general, unrestricted grammars, allow any rule that rewrites one string into another. Context-sensitive grammars require that rules never shrink the string. Context-free grammars require that each rule rewrites a single symbol, regardless of its neighbours. Regular grammars further restrict rules to a very simple form.

The book shows that these four classes of grammar correspond exactly to four classes of machine. Regular grammars match finite automata. Context-free grammars match pushdown automata. Unrestricted grammars match Turing machines. And context-sensitive grammars match linear bounded automata, which are Turing machines whose tape is limited to the length of the input. Each class strictly contains the one below it.

Why the correspondence is remarkable

The match between grammars and machines is not obvious. Grammars generate strings by rewriting from a start symbol; machines recognise strings by reading them. That two such different approaches, one descriptive and one procedural, line up exactly at four different levels is a sign of deep structure. It means that each class of languages is natural: it can be reached from two independent directions.

For linguists, the hierarchy raised the question of where human languages fall. Chomsky argued that they are not regular and that context-free grammars are inadequate in some respects, leading to more powerful theories of grammar. The question of exactly how much power human syntax needs remains debated. For computer scientists, the hierarchy gives a map of the trade-off between expressive power and tractability. The lower the class, the easier the questions about it. Regular languages admit efficient algorithms for nearly everything. Context-free languages admit efficient parsing but not equivalence checking. At the top, almost nothing interesting is decidable.

Between the rungs

The 1979 book also explores territory between and around the main classes: deterministic context-free languages, important for parsing; closure properties of families of languages in general; and other language classes studied in the research of the time. These sections are where the book is most specialised. A first-time reader can treat them as optional, but they show how the clean four-level picture is surrounded by a richer landscape.

Idea nine: measuring difficulty

Knowing that a problem can be solved is not enough. A problem that can be solved only in a time longer than the age of the universe is, for practical purposes, unsolved. The last part of the book turns from computability to complexity: how much time or memory a machine needs to solve a problem, as a function of the size of its input.

Time and space

The book measures time as the number of steps a Turing machine takes, and space as the number of tape cells it uses. It then defines classes of languages by bounds on these quantities: all languages decidable in time bounded by some function, or in space bounded by some function. The exact model matters little for the broad picture. A multi-tape machine can be simulated by a single-tape one with at most a squaring of the time, and real computers can be simulated by Turing machines with polynomial overhead. So classes defined by polynomial bounds are robust across reasonable models.

Hierarchy theorems

An early question is whether more resources really allow more problems to be solved. The hierarchy theorems, proved by Juris Hartmanis and Richard Stearns in the mid-1960s for time and by others for space, show that they do: given substantially more time, or more space, there are languages a machine can decide that it could not decide with less. The proofs again use diagonalisation, building a machine that differs from every machine with the smaller resource bound.

Nondeterminism and space

The book also presents Savitch's theorem, which shows that a nondeterministic machine using a certain amount of space can be simulated by a deterministic machine using only the square of that space. So for space, nondeterminism helps at most polynomially, and the nondeterministic and deterministic versions of polynomial space are the same class. For time, no such result is known. This contrast is central to the next idea.

Why polynomial time

The book, following Alan Cobham and Jack Edmonds in the 1960s, treats polynomial time as the working definition of efficient. A problem solvable in time bounded by some fixed power of the input size is considered tractable; one that requires exponential time is not. This is a rough rule. A polynomial with a huge exponent is not practical, and an exponential algorithm can be fine for small inputs. But the rule works well in practice, because natural problems that are polynomial usually have small exponents, and because the class is closed under combining algorithms. It gives the field a clear line to study.

Idea ten: P, NP and NP-completeness

The class P contains the problems a deterministic machine can solve in polynomial time. The class NP contains the problems a nondeterministic machine can solve in polynomial time. Equivalently, NP contains the problems whose yes answers can be checked quickly given a suitable hint, called a certificate. Deciding whether a large number is composite is in NP, because a factor serves as a certificate that can be checked by division. Deciding whether a map can be coloured with three colours so that no neighbours share a colour is in NP, because a colouring can be checked quickly.

Every problem in P is in NP. Whether the converse holds, whether every problem whose solutions can be checked quickly can also be solved quickly, is the P versus NP question. It was posed precisely in the early 1970s and remains unsolved. It is widely regarded as the most important open problem in theoretical computer science.

Completeness

Stephen Cook in 1971, and independently Leonid Levin in the Soviet Union, showed that one specific problem is as hard as any problem in NP. That problem is satisfiability: given a formula of Boolean logic, is there an assignment of true and false to its variables that makes it true. Cook showed that any problem in NP can be translated, in polynomial time, into a satisfiability question. So if satisfiability could be solved in polynomial time, every problem in NP could. Such a problem is called NP-complete.

In 1972 Richard Karp showed that twenty-one well-known combinatorial problems are also NP-complete, by reductions from satisfiability and from each other. These included problems about graphs, scheduling, packing and covering. The 1979 book presents this theory with full proofs, and it was among the first textbooks to do so. Garey and Johnson's Computers and Intractability, published the same year and also in this bay, catalogued hundreds of NP-complete problems and became the standard reference for practitioners.

Why it matters

NP-completeness gives practical guidance. If a programmer faces a problem and can show it is NP-complete, they know that a fast exact algorithm for all cases would resolve one of the great open questions of mathematics. It is wiser to look for approximations, heuristics, special cases or exponential algorithms that work on realistic inputs. Countless scheduling, routing, layout and planning problems in industry fall into this class, and recognising them saves effort spent searching for an algorithm that almost certainly does not exist.

What it is often confused with

NP does not mean not polynomial. It stands for nondeterministic polynomial time. NP-complete problems are not known to be unsolvable; they are solved every day, sometimes for very large instances, by clever algorithms. What is unknown is whether they can be solved efficiently in the worst case. And NP-completeness is a statement about worst cases: many instances of an NP-complete problem are easy. Finally, the class NP is not the hardest class. The book also discusses problems complete for polynomial space, such as determining the winner in certain generalised games, which are believed to be harder still, and problems proven to require exponential time.

Idea eleven: proofs that are also programs

A feature of the book that is easy to miss is how many of its proofs are constructions. When it proves that every nondeterministic finite automaton has an equivalent deterministic one, it does not merely argue that one must exist. It gives a procedure that builds it. When it proves that every regular expression has an equivalent automaton, it gives a procedure for producing the automaton. The same holds for converting grammars into normal forms, grammars into pushdown automata, and back.

Each of these procedures is an algorithm, and many of them are used in real software. The construction that turns a regular expression into a nondeterministic automaton, and the subset construction that makes it deterministic, are at the core of lexical analyser generators. The procedure for minimising automata is used to make them compact. Grammar transformations are used by parser generators. A student who works through these proofs is, without quite noticing, learning how to build tools.

Why this matters

This pattern says something about the field. In much of mathematics, an existence proof is satisfying in itself. In computer science, the question is nearly always also how to find the thing whose existence is proved, and how quickly. The book's constructive proofs serve both purposes at once. They also make the theory testable: one can implement a construction, run it on examples, and see that it works. A reader who does this for even one or two constructions will understand them far better than by reading alone.

The contrast with the impossibility proofs is instructive. Those cannot be constructive in the same way; they show that no procedure exists. Yet they too have a constructive core. A reduction is a procedure that transforms instances of one problem into another. The diagonal argument builds a specific machine that defeats any claimed decider. Even the proofs of what cannot be done are built from things that can.

The tradition around it

What came before

The theory in this book was assembled over about forty years. Its logical foundations lie in the 1930s, in the work of Gödel, Church, Turing, Post and Kleene on computability, collected in The Undecidable, edited by Martin Davis, which sits in this bay. Finite automata emerged in the 1940s and 1950s from the study of neural networks by Warren McCulloch and Walter Pitts and from the design of switching circuits. Stephen Kleene proved the equivalence of finite automata and regular expressions in 1956. Michael Rabin and Dana Scott introduced nondeterministic automata in 1959. Chomsky's work on grammars came in the late 1950s, and the link between context-free grammars and pushdown automata was established in the early 1960s. Complexity theory followed in the 1960s and early 1970s.

Marvin Minsky's Computation: Finite and Infinite Machines, published in 1967 and also in this bay, was an earlier and more discursive treatment of much of the same ground. Hopcroft and Ullman's own 1969 book was the first to gather formal language theory into a textbook. The 1979 book consolidated all of this and added complexity theory, producing the canonical presentation.

What came after

The 2001 and later editions, with Rajeev Motwani, made the material gentler, added more examples and motivation, and cut some of the more specialised topics. Michael Sipser's Introduction to the Theory of Computation, first published in 1997 and also in this bay, became the most widely used alternative, praised for its clarity and for presenting proof ideas before proofs. Many courses now use Sipser. Readers who find Hopcroft and Ullman's 1979 edition too dense often start there and return to Hopcroft and Ullman for depth and for topics Sipser omits.

Research has moved well beyond the book in complexity theory, with work on randomised computation, interactive proofs, approximation, and quantum computation. Nielsen and Chuang's Quantum Computation and Quantum Information, in this bay, extends the question of what can be computed efficiently to machines governed by quantum mechanics.

Its neighbours on this shelf

The book stands between several neighbours. Aho, Sethi and Ullman's Compilers: Principles, Techniques, and Tools applies its theory of regular expressions and context-free grammars directly to building compilers; reading the two together shows theory turning into engineering. Kernighan and Ritchie's The C Programming Language is the kind of language whose syntax this theory describes and whose compilers it makes possible. Hofstadter's Gödel, Escher, Bach presents the ideas of formal systems, the halting problem and diagonalisation informally and with great charm; this book is where those ideas are made precise. Hodges's Alan Turing: The Enigma tells the life of the man whose machine is the book's central object. Cormen, Leiserson and Rivest's Introduction to Algorithms deals with the efficient algorithms whose limits this book's complexity chapters define.

Questions and criticisms

Difficulty and style

The most common complaint about the 1979 edition is that it is hard. Proofs are given in full detail, often with heavy notation, and little space is spent on motivation or intuition. Students without strong mathematical preparation can find it forbidding. This is a real cost, and it is why the later editions and Sipser's book became popular. But the density is also why the 1979 edition remains valued: it is complete and precise, and it treats topics in depth that gentler books skip.

Scope

Some topics in the 1979 book reflect the research interests of its time and have since faded from the core curriculum, such as certain specialised families of languages and some detailed closure results. Conversely, topics that have grown in importance since, such as randomised and approximation algorithms, interactive proofs and quantum computation, are naturally absent. A modern reader should treat the book as the foundation and look elsewhere for the newer superstructure.

Is the model right

A deeper question concerns the Turing machine itself. It is an idealisation: unbounded memory, no errors, discrete steps, no interaction with an environment during computation. Real computers have finite memory, run concurrently, interact continuously with users and networks, and fail. Some researchers argue that interactive and concurrent computation needs different models. Others reply that the classical theory still sets the outer limits, and that finer models refine rather than replace it. Both views have merit. The classical results about undecidability and intractability have held up completely; they are mathematical theorems. The question is how directly they describe practical systems.

What has held up

Nearly everything. The definitions, the main theorems, the method of reduction and the hierarchy of machines are as valid today as in 1979 and are still taught in essentially the same form. P versus NP is still open. The book's emphasis on rigorous proof, and its insistence on showing constructively how to convert between formalisms, remain models of how to teach theory.

Why it is on this shelf

This bay is about the foundations of computing, and this book is about the foundation of the foundation: what computation is, and how its kinds and limits can be classified exactly. It turns ideas that other books on the shelf present informally into precise theorems. We keep it because there is a difference between having heard that some problems are undecidable and having proved it, and this book gives the proof.

For a reader who moves among Vedanta, Jyotish, science, economics and technology, it offers a particular kind of clarity. Vedantic and other philosophical traditions have long reflected on the limits of what can be known by reasoning from within a system. This book gives one exact, modern instance of such a limit, without mysticism: there are questions any mechanical procedure must fail to answer. Jyotish calculation and economic modelling are, at bottom, computations, and some problems in economics, such as finding optimal allocations or equilibria in certain settings, are known to be computationally hard. Knowing the theory of complexity helps one see when a model asks for more computation than the world could perform.

There is a further reason. The book's central method, classifying systems by what they can and cannot express, is useful as a habit of thought. Faced with any formal tool, whether a spreadsheet, a query language, a set of accounting rules or a scheme of astrological calculation, one can ask what class of questions it can answer, what memory it effectively has, and what lies beyond it. Readers who have worked through this book tend to ask that question naturally, and it often saves them from expecting a tool to do something it structurally cannot. That habit, more than any single theorem, is what we hope a reader carries away from this part of the shelf.

We also keep it as a model of rigour. It shows what it means to define terms exactly and prove every claim. That discipline is useful far outside computer science.

How to read it

Before you start

Make sure you are comfortable with proof by induction and proof by contradiction, and with basic set notation. The opening chapter on preliminaries reviews these; do not skip it if they are rusty. Consider reading Sipser's Introduction to the Theory of Computation alongside, or first, for intuition, and using this book for depth.

A plan

  • Spend two to three weeks on finite automata and regular expressions. Draw automata by hand. Convert a few regular expressions to automata and back. Minimise a small automaton yourself.
  • Do the pumping lemma exercises until you can prove a language non-regular without looking at the template.
  • Spend two to three weeks on context-free grammars and pushdown automata. Write grammars for arithmetic expressions and for balanced brackets. Convert a grammar to Chomsky normal form by hand once.
  • On a first pass, skim the chapters on deterministic context-free languages and on closure properties of families of languages, and the final survey of other language classes.
  • Give Turing machines and undecidability the most time of all, perhaps a month. Write out the diagonal argument in your own words. Do several reductions yourself.
  • Read the Chomsky hierarchy chapter as a review that ties the earlier material together.
  • Read the complexity chapters slowly, alongside Garey and Johnson's Computers and Intractability for many more examples of NP-completeness.

Pace and method

Do exercises. This theory cannot be absorbed by reading alone. Aim for a handful of exercises per section, choosing a mix of easy and harder ones. When a proof is long, first read it for its idea, then reconstruct it on paper without looking, then compare. Expect a full first reading to take a semester. If you lose your way in a long chapter, return to the definitions at its start; most confusion in this subject comes from a definition only half absorbed.

What to read next from this shelf

Read Compilers: Principles, Techniques, and Tools to see the first half of the theory applied. Read Computers and Intractability for the practice of NP-completeness. Read The Undecidable for the original papers of Gödel, Turing and Post. Read Gödel, Escher, Bach for a broader and more playful view of the same ideas. Read Quantum Computation and Quantum Information to see how quantum machines change the complexity picture.

Questions to carry

  • Why does treating problems as languages make such different problems comparable?
  • What exactly must a finite automaton remember about its input, and why is the smallest automaton unique?
  • Why does nondeterminism add no power to finite automata but add power to pushdown automata?
  • What feature of a language makes it require a stack, and what makes it require more than a stack?
  • Why do so many different models of computation turn out equivalent to the Turing machine?
  • How does the diagonal argument for the halting problem resemble Cantor's and Gödel's arguments?
  • Why can membership in some languages be confirmed but non-membership never be confirmed?
  • What does Rice's theorem imply for automatic tools that check programs?
  • Why is polynomial time a reasonable definition of efficient, and where does it break down?
  • What would change in practice if P turned out to equal NP?
  • Why are context-free languages closed under union but not intersection?
  • How does the gap between grammars that generate and machines that recognise close at each level of the Chomsky hierarchy?
  • Which questions about your own field are, at bottom, decision problems, and how hard might they be?

Words to know

  • Alphabet: a finite set of symbols from which strings are formed.
  • String: a finite sequence of symbols from an alphabet.
  • Language: any set of strings over an alphabet.
  • Finite automaton: a machine with a fixed finite set of states that reads input once from left to right.
  • Nondeterminism: allowing a machine several possible moves and accepting if any path leads to acceptance.
  • Regular expression: a formula built from symbols using union, concatenation and repetition.
  • Regular language: a language recognised by a finite automaton, equivalently described by a regular expression.
  • Pumping lemma: a property every long string in a regular or context-free language must have, used to prove languages lie outside those classes.
  • Context-free grammar: a set of rules that rewrite single symbols, used to generate a language.
  • Parse tree: a tree showing how a grammar generates a string.
  • Ambiguity: the property of a grammar that some string has more than one parse tree.
  • Pushdown automaton: a finite automaton with a stack.
  • Turing machine: a finite-state machine with an unbounded tape it can read and write anywhere.
  • Universal Turing machine: a Turing machine that can simulate any other given its description.
  • Church-Turing thesis: the claim that every effective procedure can be carried out by a Turing machine.
  • Decidable or recursive language: one for which some Turing machine always halts with the correct yes or no answer.
  • Recursively enumerable language: one for which some Turing machine halts and accepts exactly the strings in it.
  • Reduction: transforming one problem into another to transfer hardness or undecidability.
  • Linear bounded automaton: a Turing machine restricted to the tape space occupied by its input.
  • Chomsky hierarchy: the four nested classes of grammars and languages: regular, context-free, context-sensitive and recursively enumerable.
  • P: the class of problems solvable by a deterministic machine in polynomial time.
  • NP: the class of problems whose yes answers can be checked in polynomial time given a certificate.
  • NP-complete: a problem in NP to which every problem in NP can be reduced in polynomial time.

A note on this edition

This is a study edition written for this shelf in our own words. It describes and discusses Introduction to Automata Theory, Languages, and Computation by John E. Hopcroft and Jeffrey D. Ullman but does not reproduce it. The book itself is in copyright. It is worth getting from a library or bookshop, in the 1979 edition for depth or a later edition for a gentler path. Its value lies in its proofs and exercises, which must be worked through in the original.

Terms from this book with their own page: Church-Turing thesis, Turing machine

More from “Foundations of computing”

The whole section →