Regular Languages and Finite Automata

Similar documents
Bound and Free Variables. Theorems and Proofs. More valid formulas involving quantifiers:

Logic: The Big Picture

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

CS 154 Introduction to Automata and Complexity Theory

CISC4090: Theory of Computation

Final exam study sheet for CS3719 Turing machines and decidability.

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

MATH 363: Discrete Mathematics

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

1 More finite deterministic automata

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 3

Approximation Algorithms

What we have done so far

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Computational Models: Class 3

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

CP405 Theory of Computation

CSCE 551 Final Exam, Spring 2004 Answer Key

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Tribhuvan University Institute of Science and Technology Micro Syllabus

Advanced topic: Space complexity

(Refer Slide Time: 0:21)

3130CIT Theory of Computation

CSE 105 THEORY OF COMPUTATION

Finite Automata (contd)

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Finite Automata. Mahesh Viswanathan

Design and Analysis of Algorithms

Homework Assignment 6 Answers

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Time and space classes

NP and NP Completeness

Lecture 4: More on Regexps, Non-Regular Languages

CS 583: Algorithms. NP Completeness Ch 34. Intractability

SAT, NP, NP-Completeness

UNIT-VIII COMPUTABILITY THEORY

Computational Models - Lecture 4

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Announcements. Using a 72-hour extension, due Monday at 11:30AM.

Nondeterministic Finite Automata

(Note that these points are to give a relative sense of the weights on the final exam and have no bearing on extra credit points)

NP-Completeness Part II

V Honors Theory of Computation

Lecture 4: Finite Automata

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Recap from Last Time

Turing machines and linear bounded automata

CpSc 421 Final Exam December 6, 2008

Lecture 3: Finite Automata

Computational complexity

Accept or reject. Stack

Lecture 22: Counting

6.045 Final Exam Solutions

CSE 105 THEORY OF COMPUTATION

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

CSE 105 THEORY OF COMPUTATION

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

Finish K-Complexity, Start Time Complexity

NP-Completeness. Until now we have been designing algorithms for specific problems

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

Overview of Topics. Finite Model Theory. Finite Model Theory. Connections to Database Theory. Qing Wang

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 22: PSPACE

NP, polynomial-time mapping reductions, and NP-completeness

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Part 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages

CS 581: Introduction to the Theory of Computation! Lecture 1!

Introduction to Languages and Computation

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

NP Completeness and Approximation Algorithms

Theory of Computation

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

CSE 105 Theory of Computation

Introduction to Theory of Computing

Deterministic Finite Automata

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Lecture 3: Finite Automata

CS154, Lecture 10: Rice s Theorem, Oracle Machines

1 Functions, relations, and infinite cardinality

Formal Language and Automata Theory (CS21004)

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

Complexity Theory Part I

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

CS154. Non-Regular Languages, Minimizing DFAs

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

CS 154, Lecture 3: DFA NFA, Regular Expressions

1 Functions, relations, and infinite cardinality

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSCI3390-Lecture 14: The class NP

Transcription:

Regular Languages and Finite Automata Theorem: Every regular language is accepted by some finite automaton. Proof: We proceed by induction on the (length of/structure of) the description of the regular language. We need to show that is accepted by a finite automaton Easy: build an automaton where no input ever reaches a final state λ is accepted by a finite automaton Easy: an automaton where the initial state accepts each x I is accepted by a finite automaton Easy: an automaton with two states, where x leads from s 0 to a final state. if A and B are accepted, so is AB Proof: Suppose that M A = (S A, I, f A, s A, F A ) accepts A and M B = (S B, I, f B, s B, F B ) accepts B. Suppose that M A and M B and NFAs, and S A and S B are disjoint (without loss of generality). Idea: We hook M A and M B together. 1

Let NFS M AB = (S A S B, I, f AB, s A, F B + ), where F B + F = B F A if λ B; F B otherwise t f AB (s, i) if either s S A and t f A (s), or s S B and t f B (s), or s F A and t f B (s B ). Idea: given input xy AB, the machine guesses when to switch from running M A to running M B. M AB accepts AB. if A and B are accepted, so is A B. M A B = (S A S B {s 0 }, I, f A B, s 0, F A B ), where s 0 is a new state, not in S A S B f A (s) if s S A f A B (s) = f B (s) if s S B f A (s A ) f B (s B ) if s = s 0 F F A B = A F B {s 0 } if λ A B F A F B otherwise. M A B accepts A B. 2

if A is accepted, so is A. M A = (S A {s 0 }, I, f A, s 0, F A {s 0 }), where s 0 is a new state, not in S A ; f A (s) if s S A F A ; f A (s) = f A (s) f A (s A ) if s F A ; f A (s A ) if s = s 0 M A accepts A. 3

A Non-Regular Language Not every language is regular (which means that not every language can be accepted by a finite automaton). Theorem: L = {0 n 1 n : n = 0, 1, 2,...} is not regular. Proof: Suppose, by way of contradiction, that L is regular. Then there is a DFA M = (S, {0, 1}, f, s 0, F ) that accepts L. Suppose that M has N states. Let s 0,..., s 2N be the set of states that M goes through on input 0 N 1 N Thus f(s i, 0) = s i+1 for i = 0,..., N. Since M has N states, by the pigeonhole principle (remember that?), at least two of s 0,..., s N must be the same. Suppose it s s i and s j, where i < j, and j i = t. Claim: M accepts 0 N 0 t 1 N, and 0 N 0 2t 1 N, O N 0 3t 1 N. Proof: Starting in s 0, O i brings the machine to s i ; another 0 t bring the machine back to s i (since s j = s i+t = s i ); another 0 t bring machine back to s i again. After going around the loop for a while, the can continue to s N and accept. 4

The Pumping Lemma The techniques of the previous proof generalize. If M is a DFA and x is a string accepted by M such that x S S is the number of states; x is the length of x then there are strings u, v, w such that x = uvw, uv S, v 1, uv i w is accepted by M, for i = 0, 1, 2,.... The proof is the same as on the previous slide. x was 0 n 1 n, u = 0 i, v = 0 t, w = 0 N t i 1 N. We can use the Pumping Lemma to show that many langauges are not regular {1 n2 : n = 0, 1, 2,...}: homework {0 2n 1 n : n = 0, 1, 2,...}: homework {1 n : n is prime}... 5

More Powerful Machines Finite automata are very simple machines. They have no memory Roughly speaking, they can t count beyond the number of states they have. Pushdown automata have states and a stack which provides unlimited memory. They can recognize all languages generated by contextfree grammars (CFGs) CFGs are typically used to characterize the syntax of programming languages They can recognize the language {0 n 1 n : n = 0, 1, 2,...}, but not the language L = {0 n 1 n 2 n : n = 0, 1, 2,...} Linear bounded automata can recognize L. More generally, they can recognize context-sensitive grammars (CSGs) CSGs are (almost) good enough to characterize the grammar of real langugaes (like English) 6

Most general of all: Turing machine (TM) Given a computable language, there is a TM that accepts it. This is essentially how we define computability. If you re interested in these issues, take CS 3810! 7

Coverage of Final everything covered by the first prelim emphasis on more recent material Chapter 4: Fundamental Counting Methods Permutations and combinations Combinatorial identities Pascal s triangle Binomial Theorem (but not multinomial theorem) Balls and urns Inclusion-exclusion Pigeonhole principle Chapter 6: Probability: 6.1 6.5 (but not inverse binomial distribution) basic definitions: probability space, events conditional probability, independence, Bayes Thm. random variables uniform and binomial distribution expected value and variance 8

Chapter 7: Logic: 7.1 7.4, 7.6, 7.7; *not* 7.5 translating from English to propositional (or firstorder) logic truth tables and axiomatic proofs algorithm verification first-order logic Chapter 3: Graphs and Trees basic terminology: digraph, dag, degree, multigraph, path, connected component, clique Eulerian and Hamiltonian paths algorithm for telling if graph has Eulerian path BFS and DFS bipartite graphs graph coloring and chromatic number graph isomorphism Finite State Automata describing finite state automata regular langauges and finite state automata nondeterministic vs. deterministic automata pumping lemma (understand what it s saying) 9

Some Bureuacracy The final is on Friday, May 15, 2-4:30 PM, in Olin 155 If you have a conflict and haven t told me, let me know now Also tell me the courses and professors involved (with emails) Also tell the other professors Office hours go on as usual during study week, but check the course web site soon. There may be small changes to accommodate the TA s exams There will be two review sessions: May 12 (7 PM) and May 13 (4:45) 10

Ten Powerful Ideas Counting: Count without counting (combinatorics) Induction: Recognize it in all its guises. Exemplification: Find a sense in which you can try out a problem or solution on small examples. Abstraction: Abstract away the inessential features of a problem. One possible way: represent it as a graph Modularity: Decompose a complex problem into simpler subproblems. Representation: Understand the relationships between different possible representations of the same information or idea. Graphs vs. matrices vs. relations Refinement: The best solutions come from a process of repeatedly refining and inventing alternative solutions. Toolbox: Build up your vocabulary of abstract structures. 11

Optimization: Understand which improvements are worth it. Probabilistic methods: Flipping a coin can be surprisingly helpful! 12

Connections: Random Graphs Suppose we have a random graph with n vertices. How likely is it to be connected? What is a random graph? If it has n vertices, there are C(n, 2) possible edges, and 2 C(n,2) possible graphs. What fraction of them is connected? One way of thinking about this. Build a graph using a random process, that puts each edge in with probability 1/2. Given three vertices a, b, and c, what s the probability that there is an edge between a and b and between b and c? 1/4 What is the probability that there is no path of length 2 between a and c? (3/4) n 2 What is the probability that there is a path of length 2 between a and c? 1 (3/4) n 2 What is the probability that there is a path of length 2 between a and every other vertex? > (1 (3/4) n 2 ) n 1 13

Now use the binomial theorem to compute (1 (3/4) n 2 ) n 1 (1 (3/4) n 2 ) n 1 = 1 (n 1)(3/4) n 2 + C(n 1, 2)(3/4) 2(n 2) + For sufficiently large n, this will be (just about) 1. Bottom line: If n is large, then it is almost certain that a random graph will be connected. Theorem: [Fagin, 1976] If P is any property expressible in first-order logic, it is either true in almost all graphs, or false in almost all graphs. This is called a 0-1 law. 14

Connection: First-order Logic Suppose you wanted to query a database. How do you do it? Modern database query language date back to SQL (structured query language), and are all based on first-order logic. The idea goes back to Ted Codd, who invented the notion of relational databases. Suppose you re a travel agent and want to query the airline database about whether there are flights from Ithaca to Santa Fe. How are cities and flights between them represented? How do we form this query? You re actually asking whether there is a path from Ithaca to Santa Fe in the graph. This fact cannot be expressed in first-order logic! 15

(A Little Bit on) NP (No details here; just a rough sketch of the ideas. Take CS 3810/4820 if you want more.) NP = nondeterministic polynomial time a language (set of strings) L is in NP if, for each x L, you can guess a witness y showing that x L and quickly (in polynomial time) verify that it s correct. Examples: Does a graph have a Hamiltonian path? guess a Hamiltonian path Is a formula satisfiable? guess a satisfying assignment Is there a schedule that satisfies certain constraints?... Formally, L is in NP if there exists a language L such that 1. x L iff there exists a y such that (x, y) L, and 2. checking if (x, y) L can be done in polynomial time 16

NP-completeness A problem is NP-hard if every NP problem can be reduced to it. A problem is NP-complete if it is in NP and NP-hard Intuitively, if it is one of the hardest problems in NP. There are lots of problems known to be NP-complete If any NP complete problem is doable in polynomial time, then they all are. Hamiltonian path satisfiability scheduling... If you can prove P = NP, you ll get a Turing award. 17