Download presentation
Presentation is loading. Please wait.
Published byBuck Barker Modified over 8 years ago
2
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata. Equivalence between DFA and NFA. 2
4
*notes:- In a set we do not distinguish repetitions of the elements. Thus the set{red, blue, red} is the same as set{red, blue}. Similarly, the order of the elements is immaterial; for example, {3, 1, 9}, {9, 3,1}, and {1, 3, 9} are the same set. 4 To summarize: Two sets are equal (that is, the same) if and only if they have the same elements.
5
*The elements of a set need not be related in any way for example, {3, red, {d, blue}} is a set with three elements, one of which is itself a set. 5 So far we have specified sets by simply listing all their elements, separated by commas and included in braces. HW:- F={ yes, no }. write in other ways
6
For examplethe set N of natural numbers is infinite; we may suggest its elements by writing N = {0, 1, 2,... }, using the three dots and your intuition in place of an infinitely long list. For example :- the set N of natural numbers is infinite; we may suggest its elements by writing N = {0, 1, 2,... }, using the three dots and your intuition in place of an infinitely long list. *Some sets cannot be written in this way,because *Some sets cannot be written in this way, because they are infinite *Another way to specify a set is by referring to other sets and to properties that elements may or may not have. For example I= {l, 3, 9} and G = {3,9} G may be described as the set of elements of I that are greater than 2. the set of odd natural numbers is Set with even number S= {2, 4, 6, …} S = {i :i>0 and even 6
7
7
8
If we have two sets A,B then the there is some operations that performed on them as follow 8 For example 1. {1,3,9} {3,5,7} = {1,3,5,7} 1. {1,3,9} {3,5,7} = {1,3,5,7} {1,3,9} {3,5,7} ={3} {1,3,9} {3,5,7} ={3} 2. {1,3,9} {a,b,c,d} = Ø 2. {1,3,9} {a,b,c,d} = Ø 3. {1,3,9} {a,b,c,d}=? 3. {1,3,9} {a,b,c,d}=?
9
9 It is possible to form intersections and unions of more than two sets.If S is any collection of sets, we write S for the set whose elements are the elements of all the sets in S. And S for the set whose elements are the elements of each sets in S. For example, if S = {{a, b}, {b, c},{c, d, b}} It is possible to form intersections and unions of more than two sets. If S is any collection of sets, we write S for the set whose elements are the elements of all the sets in S. And S for the set whose elements are the elements of each sets in S. For example, if S = {{a, b}, {b, c},{c, d, b}} S = {a, b, c,d } S = {b} A - B = {x: x A and x B}. For example, { I, 3, 9} - {3, 5, 7} = {I, 9}.
10
HW:- what are these sets? (a) ({1,3,5} {3,1}) {3,5,7} (b) { {3}, {3, 5}, { {5, 7}, {7, 9}}} (c) ({1,2,5} - {5, 7,9}) ({5, 7,9} - {l,2,5}) (d) 2 {7,8,9} - 2 {7,9} (e) 2 Ø HW:- what are these sets? (a) ({1,3,5} {3,1}) {3,5,7} (b) { {3}, {3, 5}, { {5, 7}, {7, 9}}} (c) ({1,2,5} - {5, 7,9}) ({5, 7,9} - {l,2,5}) (d) 2 {7,8,9} - 2 {7,9} (e) 2 Ø 10
11
Alphabet:- An alphabet is a finite and not empty set of symbols.We use Σ(sigma) to denote this alphabet. Alphabet:- An alphabet is a finite and not empty set of symbols. We use Σ(sigma) to denote this alphabet. English alphabet ∑ = { A, B, …, Z, a, b, …, z,0,…,9 } For example: Binary alphabet ∑ = { 0,1} For example: 0, 1, 11, 00, and 01101 are strings over {0, 1 }. Cat, CAT, watermelon and compute are strings over the English alphabet. Lower case letters ∑= {a, b, c,... z} 11
12
For example: 1. |automata|= 8 2. |computation| = 11 3. |ε |= 0 4. |101|=3 5. |ab |=3 6. |01 0 1 00 | = ? 12
13
13
14
Example: 01. 001 = 01001 01. 001 = 01001 beach. boy = beachboy beach. boy = beachboy if n = 0, w0 = ε if n > 0, w1 = w w2 = w1. w1 w2 = w1. w1 w3 = w2. w1 w3 = w2. w1... wn = wn-1. w1 wn = wn-1. w1 Example: (do) 2 = dodo 14
15
- ε is a substring of every string. - for every string x, x is a substring of x itself. - ε is a substring of every string. - for every string x, x is a substring of x itself. Example: ε, compu and computation are substrings of computation. The string ”spelled backwards” Example: 1. (reverse) R = esrever 2. (automata) R = atamotua 15
16
Σ*: denotes the set of all sequences of strings that are composed of zero or more symbols of Σ The symbol * is called the Kleene star. Σ*: denotes the set of all sequences of strings that are composed of zero or more symbols of Σ.The symbol * is called the Kleene star. ∑* = ∑ 0 U ∑ 1 U ∑ 2 U … 1. = {0, 1}. 1. = {0, 1}. * = { , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… } * = { , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… } Σ + : denotes the set of all sequences of strings composed of one or more symbols of Σ. ∑ + = ∑1 U ∑2 U ∑3 U … ∑ + = ∑1 U ∑2 U ∑3 U … 1. + = {0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… } 2. + = { a,b,aa,ab,ba,bb,aaa,aab,…} Σ + = Σ* − {ε} 16 2. = {a,b} * = { , a,b,aa,ab,ba,bb,aaa,aab,…} * = { , a,b,aa,ab,ba,bb,aaa,aab,…}
17
17 A language is a set of strings over an alphabet Σ. 1.Let L be the language of all strings consisting of n 0’s followed by n 1’s: L = { ,01,0011,000111,…} 2.Let L be the language of all strings with equal number of 0’s and 1’s: L = { ,01,10,0011,1100,0101,1010,1001,…} 3. Let L be the language of all strings contain two consecutive 0’s L = { ,001,100,0011,1100,0000100,…} L = { ,001,100,0011,1100,0000100,…} 4. L = {(10) n : n ≥0} L = { ,10,1010,101010,101010,…} L = { ,10,1010,101010,101010,…} 5. L = {a 2n + 1 : n >= 0} L = {a, aaa, aaaaa,...} L = {a, aaa, aaaaa,...}
18
18
19
Union: Let L 1 and L 2 be languages over an alphabet Σ. The union of L 1 and L 2, denoted by L 1 L 2, is {x | x is in L 1 or L 2 }. Examples: 1. L 1 ={ 0, 11, 01, 011 },L 2 ={ 1, 01, 110 } L1 L 2 = { 0, 11, 01, 011, 1, 110, 111 } L1 L 2 = { 0, 11, 01, 011, 1, 110, 111 } 2. {x {0,1}*|x begins with 0} {x {0,1}*|x ends with 0} = {x {0,1}*| x begins or ends with 0} = {x {0,1}*| x begins or ends with 0} 19
20
Intersection: Let L 1 and L 2 be languages over an alphabet Σ.The intersection of L 1 and L 2, denoted by L 1 L 2, is { x | x is in L 1 and L 2 }. Examples 1. L 1 ={ 0, 11, 01, 011 },L 2 ={ 1, 01, 110 } L1 L 2 ={01} L1 L 2 ={01} 2. { x {0,1}*| x begins with 0} { x {0,1}*| x ends with 0} = { x {0,1}*| x begins and ends with 0} 20
21
Let L 1 and L 2 be languages over an alphabet Σ. The concatenation of L 1 and L 2, denoted by L 1 L 2, is {w 1 w 2 | w 1 is in L 1 and w 2 is in L 2 }. is {w 1 w 2 | w 1 is in L 1 and w 2 is in L 2 }.Examples: 1. L1 = {00, 01}. 1. L1 = {00, 01}. L2 = {a, aa, aaa }. Then, L2 = {a, aa, aaa }. Then, L1.L2 = {00a, 01a, 00aa, 01aa, 00aaa, 01aaa}. L1.L2 = {00a, 01a, 00aa, 01aa, 00aaa, 01aaa}. 2. L1 = { a, ab } L2 = { b, ba } = L2 = { b, ba } = L1.L2 = { ab, aba, abb, abba }. L1.L2 = { ab, aba, abb, abba }. 21
22
Expansion: The concatenation of a language L with itself n times is denoted L n In particular, if n = 0, L 0 = {ε}. if n = 0, L 0 = {ε}. if n > 0, L 1 = L if n > 0, L 1 = L L 2 = L 1. L 1 L 2 = L 1. L 1 L 3 = L 2. L 1 L 3 = L 2. L 1... L n = L n-1. L 1 L n = L n-1. L 1 Example: If L = {01, 001}, then L 0 = {ε}. L 0 = {ε}. L 1 ={01, 001}. L 1 ={01, 001}. L 2 = {0101, 001001, 01001, 00101}. L 2 = {0101, 001001, 01001, 00101}. L 3 = {010101, 01001001, 0101001, 0100101, L 3 = {010101, 01001001, 0101001, 0100101, 0010101, 001001001, 00101001, 00100101}. 0010101, 001001001, 00101001, 00100101}. 22 Hw:- Let L = { 1, 00} compute L 3
23
23
24
Closure: Let L be a language over an alphabet Σ.The closure of L, denoted by L +, is { x | for an integer n 1, x = x 1 x 2 …x n and x 1, x 2, …, x n are in L} Or it all strings derivable by one or more concatenations of strings in L. Example : Let L = { a, ab }. Then we have, L* = {ε} {a, ab} {aa, aab, aba, abab} … L+ = {a, ab} {aa, aab, aba, abab} … 24
26
26 Software for designing and checking the behavior of digital circuits. Lexical analyzer of a typical compiler. Software for scanning large bodies of text (e.g., web pages) for pattern finding Software for verifying systems of all types that have a finite number of states (e.g., stock market transaction, communication/network protocol)
27
27 machine that automatically recognizes if a particular string belongs to the language or not, by checking the grammar or rules of the string. Example 1:-represents a finite state machine that recognize (accept) string {ab}. Start state Final state Transition Intermediate state Example 2:- Modeling recognition of the string {then}
29
29 Deterministic Finite Automata (DFA) The machine can exist in only one state at any given time q0q0 start q1q1 0 0,1 Non-deterministic Finite Automata (NFA) The machine can exist in multiple states at the same time q0q0 start q1q1 0 1 0 {q 0 } 1 0 {q 1 } 1 {q 2 } 0 0 1 Find the DFA and NFA for the following diagrams One Two
30
30 A deterministic finite automaton (DFA) isA deterministic finite automaton (DFA) is a 5-tuple (Q, , , q0, F) where a 5-tuple (Q, , , q0, F) where – Q is a finite set of states – is an alphabet – : Q × → Q is a transition function – q 0 Q is the initial state – F Q is a set of accepting states (or final states). q0q0q0q0 q1q1q1q1 q2q2q2q2 1000,11 alphabet = {0, 1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state= q0 accepting states F = {q0, q1} alphabet = {0, 1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state= q0 accepting states F = {q0, q1} states input symbols 0 1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q0q0q0q0 q1q1q1q1 q2q2q2q2 q2q2q2q2 q2q2q2q2 q1q1q1q1 transition function : Example 1:
31
31 q0q0q0q0 q1q1q1q1 q2q2q2q2 1 000,11 HW:- find the 5-tuple parts for the following diagram alphabet = {a, b} states Q = {0, 1, 2} states Q = {0, 1, 2} initial state= 0 accepting states F = {1} alphabet = {a, b} states Q = {0, 1, 2} states Q = {0, 1, 2} initial state= 0 accepting states F = {1} Example 2: states input symbols a b 0 1 2 1 2 2 2 2 2 transition function :
32
32 Input: a word or string w in ∑*Input: a word or string w in ∑* Question: Is w acceptable by the DFA?Question: Is w acceptable by the DFA? Steps:Steps: –Start at the “start state” q 0 –For every input symbol in the sequence w do Compute the next state from the current state by given the current input symbol in w and the transition functionCompute the next state from the current state by given the current input symbol in w and the transition function –If after all symbols in w are consumed, the current state is one of the final states (F) then accept w; –Otherwise, reject w. What does a DFA do on reading an input string?
33
33 So String is accepted by a FA if and only if the FA starting at the initial state and ends in an accepting state after reading the string. M=(Q, , , q 0, F) alphabet = {0,1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state = q0 accepting states F = {q1} transition function : M=(Q, , , q 0, F) alphabet = {0,1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state = q0 accepting states F = {q1} transition function : For Example: states input symbols 0 1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q0q0q0q0 q1q1q1q1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q2q2q2q2 we see that the automation will accept the strings 01,101,0111 and 11001, but reject the strings 00,100 or 1100 Note: extended transition function Note: extended transition function * Q × → Q the second argument of * is a string rather than a single symbol. for example: q0,a)=q1 q0,a)=q1And (q1,b)=q2 Then q0,ab)=q2 for example: q0,a)=q1 q0,a)=q1And (q1,b)=q2 Then q0,ab)=q2
34
34 Languages and DFA language accepted by a DFA M=(Q, , , q 0, F) is the set of all strings on accepted by M, and the languages called regular languages. In formal notation. While, Nonaccepted means that the DFA stops in a nonfinal state. In formal notation Example 1: Answer :
35
35 Example 2: find a diagram of DFA for language L = {a 2n + 1 | n >= 0} L = {a 2n + 1 | n >= 0} Answer : L = {a, aaa, aaaaa,...} Example 3: L(M) = {w in {a,b}* | w contains even no. of a's} Answer : * = {a,b}* = {b,aa, bb,aab,baba,babba…}
36
36 HW in class:-Build a DFA for the following language: L = { w in {a,b}* | w has odd number of b's}. HW :-DFA of A = {w | w contains at least one 1 and an even number of 0s follow the last 1}
37
37
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.