### Transcription of Theory of Computation

1 Introduction to **Theory** of ComputationAnil Maheshwari Michiel SmidSchool of Computer ScienceCarleton 17, 2019iiContentsContentsPrefacevi1 Purpose and motivation .. **complexity** **Theory** .. Computability **Theory** .. Automata **Theory** .. This course .. Mathematical preliminaries .. Proof techniques .. Direct proofs .. Constructive proofs .. Nonconstructive proofs .. Proofs by contradiction .. The pigeon hole principle .. Proofs by induction .. More examples of proofs .. 15 Exercises .. 182 Finite Automata and Regular An example: Controling a toll gate .. Deterministic finite automata .. A first example of a finite automaton .. A second example of a finite automaton .. A third example of a finite automaton .. Regular operations .. Nondeterministic finite automata.

2 A first example .. A second example .. A third example .. Definition of nondeterministic finite automaton .. Equivalence of DFAs and NFAs .. An example .. Closure under the regular operations .. Regular expressions .. Equivalence of regular expressions and regular languages .. Every regular expression describes a regular language . Converting a DFA to a regular expression .. The pumping lemma and nonregular languages .. Applications of the pumping lemma .. Higman s Theorem .. Dickson s Theorem .. Proof of Higman s Theorem .. 77 Exercises .. 803 Context-Free Context-free grammars .. Examples of context-free grammars .. Properly nested parentheses .. A context-free grammar for a nonregular language .. A context-free grammar for the complement of a non-regular language.

3 A context-free grammar that verifies addition .. Regular languages are context-free .. An example .. Chomsky normal form .. An example .. Pushdown automata .. Examples of pushdown automata .. Properly nested parentheses .. Strings of the form 0n1n.. Strings withbin the middle .. Equivalence of pushdown automata and context-free grammars The pumping lemma for context-free languages .. Proof of the pumping lemma .. Applications of the pumping lemma .. 128 ContentsvExercises .. 1324 Turing Machines and the Church-Turing Definition of a Turing machine .. Examples of Turing machines .. Accepting palindromes using one tape .. Accepting palindromes using two tapes .. Acceptinganbncnusing one tape .. Acceptinganbncnusing tape alphabet{a, b, c, }.. Acceptingambncmnusing one tape .. Multi-tape Turing machines.

4 The Church-Turing Thesis .. 151 Exercises .. 1525 Decidable and Undecidable Decidability .. The languageADFA.. The languageANFA.. The languageACFG.. The languageATM.. The Halting Problem .. Countable sets .. The Halting Problem revisited .. Rice s Theorem .. Proof of Rice s Theorem .. Enumerability .. Hilbert s problem .. The languageATM.. Where does the term enumerable come from? .. Most languages are not enumerable .. The set of enumerable languages is countable .. The set of all languages is not countable .. There are languages that are not enumerable .. The relationship between decidable and enumerable languages A languageAsuch that bothAandAare not enumerable .. not enumerable .. not enumerable .. 188 Exercises .. 189viContents6 **complexity** The running time of algorithms.

5 The **complexity** classP.. Some examples .. The **complexity** classNP.. contained inNP.. DecidingNP-languages in exponential time .. Summary .. Non-deterministic algorithms .. languages .. Two examples of reductions .. Definition of NP-completeness .. AnNP-complete domino game .. Examples ofNP-complete languages .. 231 Exercises .. 2357 Summary239 PrefaceThis is a free textbook for an undergraduate course on the **Theory** of Com-putation, which we have been teaching at Carleton University since the 2011/2012 academic year, this course was offered as a second-yearcourse (COMP 2805) and was compulsory for all Computer Science with the 2012/2013 academic year, the course has been downgradedto a third-year optional course (COMP 3803).We have been developing this book since we started teaching this , we cover most of the material from Chapters 2 5 during a 12-weekterm with three hours of classes per material from Chapter 6, on **complexity** **Theory** , is taught in thethird-year course COMP 3804 (Design and Analysis of Algorithms).

6 In theearly years of COMP 2805, we gave a two-lecture overview of ComplexityTheory at the end of the term. Even though this overview has disappearedfrom the course, we decided to keep Chapter 6. This chapter has not beenrevised/modified for a long course as we teach it today has been influenced by the following twotextbooks: Introduction to the **Theory** of **Computation** (second edition), by MichaelSipser, Thomson Course Technnology, Boston, 2006. Einf uhrung in die Theoretische Informatik, by Klaus Wagner, Springer-Verlag, Berlin, reading this text, we recommend that you also take a look atthese excellent textbooks, as well as one or more of the following ones: Elements of the **Theory** of **Computation** (second edition), by HarryLewis and Christos Papadimitriou, Prentice-Hall, Introduction to Languages and the **Theory** of **Computation** (thirdedi-tion), by John Martin, McGraw-Hill, 2003.

7 Introduction to Automata **Theory** , Languages, and **Computation** (thirdedition), by John Hopcroft, Rajeev Motwani, Jeffrey Ullman, AddisonWesley, let us know if you find errors, typos, simpler proofs, comments,omissions, or if you think that some parts of the book need improvement .Chapter Purpose and motivationThis course is on theTheory of **Computation** , which tries to answer thefollowing questions: What are the mathematical properties of computer hardware andsoft-ware? What is acomputationand what is analgorithm? Can we give rigorousmathematical definitions of these notions? What are thelimitationsof computers? Can everything be com-puted? (As we will see, the answer to this question is no .)Purpose of the **Theory** of **Computation** :Develop formal math-ematical models of **Computation** that reflect real-world field of research was started by mathematicians and logicians in the1930 s, when they were trying to understand the meaning of a **Computation** .

8 A central question asked was whether all mathematical problems can besolved in a systematic way. The research that started in those days led tocomputers as we know them , the **Theory** of **Computation** can be divided into the follow-ing three areas: **complexity** **Theory** , Computability **Theory** , and 1. **complexity** theoryThe main question asked in this area is What makes some problems com-putationallyhardand other problemseasy? Informally, a problem is called easy , if it is efficiently solvable. Exam-ples of easy problems are (i) sorting a sequence of, say, 1,000,000 numbers,(ii) searching for a name in a telephone directory, and (iii) computing thefastest way to drive from Ottawa to Miami. On the other hand, a problem iscalled hard , if it cannot be solved efficiently, or if we don t know whetherit can be solved efficiently. Examples of hard problems are (i) time tablescheduling for all courses at Carleton, (ii) factoring a 300-digit integer intoits prime factors, and (iii) computing a layout for chips in Question in **complexity** **Theory** :Classify problems ac-cording to their degree of difficulty.

9 Give a rigorous proof thatproblems that seem to be hard are really hard . Computability theoryIn the 1930 s, G odel, Turing, and Church discovered that some ofthe fun-damental mathematical problems cannot be solved by a computer . (Thismay sound strange, because computers were invented only in the 1940 s).An example of such a problem is Is an arbitrary mathematical statementtrue or false? To attack such a problem, we need formal definitions of thenotions of computer, algorithm, and theoretical models that were proposed in order to understand solvableand unsolvable problems led to the development of real Question in Computability **Theory** :Classify problemsas being solvable or Purpose and Automata theoryAutomata **Theory** deals with definitions and properties of different types of **Computation** models . Examples of such models are: Finite Automata.

10 These are used in text processing, compilers, andhardware design. Context-Free Grammars. These are used to define programming lan-guages and in Artificial Intelligence. Turing Machines. These form a simple abstract model of a real computer, such as your PC at Question in Automata **Theory** :Do these models havethe same power, or can one model solve more problems than theother? This courseIn this course, we will study the last two areas in reverse order: Wewill startwith Automata **Theory** , followed by Computability **Theory** . The first area, **complexity** **Theory** , will be covered in COMP , before we start, we will review some mathematical proof tech-niques. As you may guess, this is a fairly theoretical course, with lots ofdefinitions, theorems, and proofs. You may guess this course is fun stuff formath lovers, but boring and irrelevant for others. You guessed itwrong, andhere are the reasons:1.