Presentation is loading. Please wait.

Presentation is loading. Please wait.

WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.

Similar presentations


Presentation on theme: "WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University."— Presentation transcript:

1 WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University

2 2  High-level sketch Regular expressions NFA DFA Lexical Specification Table-driven Implementation of DFA

3 3  Deterministic Finite Automata (DFA)  One transition per input per state  No  -moves  Nondeterministic Finite Automata (NFA)  Can have multiple transitions for one input in a given state  Can have  -moves  Finite automata have finite memory  Need only to encode the current state

4 4  A DFA can take only one path through the state graph  Completely determined by input  NFAs can choose  Whether to make  -moves  Which of multiple transitions for a single input to take

5  There is a fixed number of states but we can be in multiple states at one time. NFA = “a 5-tuple “  (Q, Σ, , q 0, F) QA finite set of states ΣA finite input alphabet q 0 The initial/starting state, q 0 is in Q FA set of final/accepting states, which is a subset of Q δA transition function, which is a total function from Q x Σ to 2 Q, this function:  Takes a state and input symbol as arguments.  Returns a set of states instead a single state as in DFA. δ: (Q x Σ) – > 2 Q -2 Q is the power set of Q, the set of all subsets of Q δ(q,s) is a function from Q x S to 2 Q (but not to Q) Dr. Hussien M. Sharaf 5

6  There is a fixed number of states and the DFA can only be in one state at a time. DFA = “a 5-tuple “  (Q, Σ, , q 0, F) Q: { q 0, q 1, q 2, … } is set of states. Σ: {a, b, …} set of alphabet. (delta): A transition function, which is a total function from Q x Σ to Q, this function:  Takes a state and input symbol as arguments.  Returns a single state. : Q x Σ → Q q 0 Q is the start state. FQ is the set of final/accepting states. Dr. Hussien M. Sharaf 6

7 A finite automaton is deterministic if  It has no edges/transitions labeled with epsilon/lamda.  For each state and for each symbol in the alphabet, there is exactly one edge labeled with that symbol.

8 8  For each kind of rexp, define an NFA  Notation: NFA for rexp A A For   For input a a

9 9  For BC B C  For B|c C B    

10 10  For D* D   

11 11  Choose the NFA that accepts the following regular expression: 1* + 0

12 12  Consider the regular expression (1 | 0)*1  The NFA is …  1 C E 0 DF   B   G    A H 1 IJ

13 13 Alphabet =  NFA travels all possible paths, and so it remains in many states at once. As long as at least one of the paths results in an accepting state, the NFA accepts the input. Dr. Hussien M. Sharaf

14 14 Two choices Alphabet = Dr. Hussien M. Sharaf

15 15 No transition Two choices No transition Alphabet = Dr. Hussien M. Sharaf

16 16 An NFA accepts a string: if there is a computation of the NFA that accepts the string i.e., all the input string is processed and the automaton is in an accepting state Dr. Hussien M. Sharaf

17 17 Acceptance Example 1 Dr. Hussien M. Sharaf

18 18 Dr. Hussien M. Sharaf

19 19 Dr. Hussien M. Sharaf “reject” “accept”

20 20 is accepted by the NFA: “accept” “reject” because this computation accepts this computation is ignored Dr. Hussien M. Sharaf

21 21 An NFA rejects a string: if there is no computation of the NFA that accepts the string. All the input is consumed and the automaton is in a non final state The input cannot be consumed OR For each computation:

22 22 is rejected by the NFA: “reject” All possible computations lead to rejection Dr. Hussien M. Sharaf

23 23 is rejected by the NFA: “reject” All possible computations lead to rejection Dr. Hussien M. Sharaf

24 24 Dr. Hussien M. Sharaf

25 25 Dr. Hussien M. Sharaf Acceptance Example 2

26 26 Dr. Hussien M. Sharaf

27 27 input tape head does not move Dr. Hussien M. Sharaf

28 28 “accept” String is accepted all input is consumed Dr. Hussien M. Sharaf

29 29 Rejection Example 3 Dr. Hussien M. Sharaf

30 30 Dr. Hussien M. Sharaf

31 31 (read head doesn’t move) Dr. Hussien M. Sharaf

32 32 “reject” String is rejected Input cannot be consumed Automaton halts Dr. Hussien M. Sharaf

33 33 Language accepted: Dr. Hussien M. Sharaf

34 34 Example 4 Dr. Hussien M. Sharaf

35 35 Dr. Hussien M. Sharaf

36 36 Dr. Hussien M. Sharaf

37 37 “accept” Dr. Hussien M. Sharaf

38 38 Another String Dr. Hussien M. Sharaf

39 39 Dr. Hussien M. Sharaf

40 40 Dr. Hussien M. Sharaf

41 41 Dr. Hussien M. Sharaf

42 42 Dr. Hussien M. Sharaf

43 43 Dr. Hussien M. Sharaf

44 44 “accept” Dr. Hussien M. Sharaf

45 45 Language accepted Dr. Hussien M. Sharaf

46 46 Dr. Hussien M. Sharaf

47 47 Language accepted (redundant state) Dr. Hussien M. Sharaf

48  All words with even count of letters. ((a+b)(a+b))* 1±2 a, b Dr. Hussien M. Sharaf 48

49  All words that start with “a” a(a+b)* 1- 2 b a 3 + a,b 1- 2 b a 3 + a,b Does not accept all inputs Dr. Hussien M. Sharaf 49

50  All words that start with “a” a(a+b)* 4+ 1- 2 b a 3 + a,b Special accept state for string “a”, might give better performance in hardware implementation Dr. Hussien M. Sharaf 50

51  All words that start with triple letter (aaa+bbb)(a+b)* 1- 2 a 3 a,b 4 b 5 b 6+ b a a Dr. Hussien M. Sharaf 51

52 {aa, ba, baba, aaaa, ab, bb, bababa, aaba, …} All words with even count of letters having “a” in an even position from the start, where the first letter is letter number one.  (a+b)a((a+b)a)* - a,b Dr. Hussien M. Sharaf 52


Download ppt "WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University."

Similar presentations


Ads by Google