Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

22
Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory 1

Transcript of Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Page 1: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

TopicsAutomata TheoryGrammars and LanguagesComplexities

Formal Languages and Automata Theory 1

Page 2: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Why Automata Theory?To study abstract computing devices which are closely related to today’s computers. A simple example of finite state machine:

Formal Languages and Automata Theory 2

off onstart

1

1

There are many different kinds of machines.

Page 3: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Another Example

Formal Languages and Automata Theory 3

start

0

1on

0

0

1

offoff

1

When will this be on?Try 100, 1001, 1000, 111, 00, …

Page 4: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Grammar and LanguagesGrammars and languages are closely related to automata theory and are the basis of many important software components like:Compilers and interpretersText editors and processorsSearch enginesSystem verification components

Formal Languages and Automata Theory 4

Page 5: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

ComplexitiesStudy the limits of computations. What kinds of problems can be solved with a computer? What kinds of problems can be solved efficiently?

Formal Languages and Automata Theory 5

Page 6: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

PreliminariesAlphabetsStringsLanguagesProblems

Formal Languages and Automata Theory 6

Page 7: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

AlphabetsAn alphabet is a finite set of symbols.

Usually, use to represent an alphabet.

Examples:

= {0,1}, the set of binary digits.

= {a, b, … , z}, the set of all lower-case letters.

= {(, )}, the set of open and close parentheses.

Formal Languages and Automata Theory 7

Page 8: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Strings A string is a finite sequence of symbols from

an alphabet.

Examples:

0011 and 11 are strings from = {0,1}

abc and bbb are strings from = {a, b, … , z}

(()(())) and )(() are strings from = {(, )}

Formal Languages and Automata Theory 8

Page 9: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

StringsEmpty string:

Length of string: |0010| = 4, |aa| = 2, ||=0

Prefix of string: aaabc, aaabc, aaabc

Proper prefix of string: aaabc, aaabc

Suffix of string: aaabc, aaabc, aaabc

Proper suffix of string: aaabc, aaabc

Substring of string: aaabc, aaabc, aaabc

Formal Languages and Automata Theory 9

Page 10: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

StringsConcatenation: =abd, =ce, =abdce

Exponentiation: =abd, 3=abdabdabd, 0=

Reversal: =abd, R = dba

k = set of all k-length strings formed by symbols in

e.g., ={a,b}, 2={ab, ba, aa, bb}, 0={}

What is 1? Is 1 different from ? How?

Formal Languages and Automata Theory 10

Page 11: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

StringsKleene Closure * = 012… = k0 k

e.g., ={a, b}, * = {, a, b, ab, aa, ba, bb,

aaa, aab, abb, … } is the set of all strings

formed by a’s and b’s.

+ = 123… = k>0 k

i.e., * without the empty string.

Formal Languages and Automata Theory 11

Page 12: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

LanguagesA language is a set of strings over an alphabet.

Examples:

={(, )}, L1={(), )(, (())} is a language over .

={a, b, c, … , z}, the set L of all legal English

words is a language over .

The set {} is a language over any alphabet.

What is the difference between and {}?

Formal Languages and Automata Theory 12

Page 13: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

LanguagesOther Examples:

={0, 1}, L={0n1n | n1} is a language over

consisting of the strings {01, 0011, 000111, … }

={0, 1}, L = {0i1j | ji0} is a language over

consisting of the strings with some 0’s (possibly

none) followed by at least as many 1’s.

Formal Languages and Automata Theory 13

Page 14: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

ProblemsIn automata theory, a problem is to decide

whether a given string is a member of some particular language.

This formulation is general enough to capture the difficulty levels of all problems.

Formal Languages and Automata Theory 14

Page 15: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Finite Automata ( or Finite State Machines)

This is the simplest kind of machine.We will study 3 types of Finite Automata:

Deterministic Finite Automata (DFA)Non-deterministic Finite Automata (NFA)Finite Automata with -transitions (-NFA)

Formal Languages and Automata Theory 15

Page 16: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Deterministic Finite Automata (DFA) We have seen a simple example before:

Formal Languages and Automata Theory 16

off onstart

1

1

There are some states and transitions (edges)between the states. The edge labels tell whenwe can move from one state to another.

Page 17: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Definition of DFA A DFA is a 5-tuple (Q, , , q0, F) where

Q is a finite set of states is a finite input alphabet is the transition function mapping Q to

Q q0 in Q is the initial state (only one)

F Q is a set of final states (zero or more)

Formal Languages and Automata Theory 17

Page 18: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Definition of DFA For example:

Formal Languages and Automata Theory 18

off onstart

1

1

Q is the set of states: {on, off} is the set of input symbols: {1} is the transitions: off 1 on; on 1 offq0 is the initial state: offF is the set of final states (double circle): {on}

Page 19: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Definition of DFA Another Example:

Formal Languages and Automata Theory 19

start

0

1q2

0

0

1

q1q0

1

What are Q, , , q0 and F in this DFA?

Page 20: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Transition Table For the previous example, the DFA is

(Q,,,q0,F) where Q = {q0,q1,q2}, = {0,1}, F = {q2} and is such that

Formal Languages and Automata Theory 20

StatesInputs

0 1q0

q1

*q2

q1 q0

q2

q0q1

q0

Note that there is one transition only for each inputsymbol from each state.

Page 21: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

Language of a DFA Given a DFA M, the language accepted (or

recognized) by M is the set of all strings that, starting from the initial state, will reach one of the final states after the whole string is read.

For example, the language accepted by the previous example is the string that ends with 00

Formal Languages and Automata Theory 21

Page 22: Topics Automata Theory Grammars and Languages Complexities Formal Languages and Automata Theory1.

DFA Example Consider the DFA M=(Q,,,q0,F)

where Q = {q0,q1,q2,q3}, = {0,1}, F = {q0} and is:

Formal Languages and Automata Theory 22

StatesInputs

0 1q0

q1

q2

q3

q2

q2q1

q1

q3

q3q0

q0

q0

q2 q3

q1

1

1

1

1

0 000

Start

We can use a transition table or a transition diagram to specifythe transitions. What input can take you to the final state in M?

OR