MELJUN CORTES Automata Lecture Intro to Finite Automata 1

Embed Size (px)

Citation preview

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    1/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 1 of 14

    TOPIC TITLE: Introduction to Finite Automata

    Specific Objectives:

     At the end of the topic session, the students are expected to:

    Cognit ive:  

    1. Explain the theory of automata and its role in the study ofcomputers.

    2. Give the formal definition of a deterministic finite automaton.3. Determine the different strings a given DFA will accept.4. Design the DFA given the kinds of strings it should accept.5. Define the language of an automaton.6. Determine if a language is regular or not

    Affective:

    1. Listen to others with respect.2. Participate in class discussions actively.

    MATERIALS/EQUIPMENT:

    o  topic slideso  OHP

    TOPIC PREPARATION:

    o  Have the students review whatever related topics werediscussed during the previous semesters.

    o  Prepare the slides to be presented in class.o  It is imperative for the instructor to incorporate various kinds of

    teaching strategies while discussing the suggested topics. o  Prepare additional examples on the topic to be presented. 

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    2/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 2 of 14

     Automata TheoryPage 1 of 25

    Introduction to Finite Automata

    Automata Theory

    Autom ata theory  is the study of abstract machines, particularly the problems theycan solve, or the kind of computations or operations they can perform.

    Abstract machines  are theoretical representations of real-world machines (suchas a computer) but without the unnecessary details associated with a particularinstance of that machine. Details such as the type of processor and memory used,how input data are obtained and the output is produced, and many others are notincluded in the representation. In other words, abstract machines are simplified orbare representations of real machines.

    By removing these details, it is easier to mathematically analyze the operation andproperties of the machines being studied without having to build the actual,physical machine.

     Automata TheoryPage 2 of 25

    Here is a simple example to illustrate the concept of using abstract machines.

     Assume that the machine to be analyzed is a simple light bulb connected to apower source via a single toggle switch.

    If the lever of the toggle switch is pushed or flipped, the light bulb turns on. If thelever is pushed again, it turns off.

    The operation of the light bulb “machine” can be described by the following graph:

    Light

    Bulb is

    On 

    push lever of

    switch

    Light

    Bulb is

    Off 

    push lever of

    switch  

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    3/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 3 of 14

     Automata TheoryPage 3 of 25

    Each node in the graph represents the “state” of the light bulb.  A light bulb canonly be in one of two states, it’s either off  or on. Nothing in between.

    The edges of the graph show when the machine would move between the twostates. The labels of the edges indicate the event or condition that has to occur for

    the current status to move from the state it is currently in to a new state. Theseevents may be thought of as inputs to the system. For the light bulb machine, theonly event that can occur is the pushing of the lever of the switch.

     Assume initially that the bulb is turned off (it is currently in the off  state). If the leverof the toggle switch is pushed, the light bulb will turn on. So the machine “moves” from the off  state to the on state as indicated in the graph

    The current state of the bulb is now the on state. If the lever is pushed again, thelight bulb is turned off so the machine moves from the on state to the off  state.

     Automata TheoryPage 4 of 25

    This is now an abstract model of the light bulb machine. There are no detailsassociated with this machine such as the type of light bulb or the power sourceused.

    With this model, the operation of the light bulb can now be analyzed without havingthe actual physical machine present.

    For example:

    What happens if the lever of the switched is pushed 6 times insuccession?

    It can be seen from the graph that if the system’s current state is the off  state, pushing the lever or the switch 6 times would result in the followingstate transitions: off  → on → off  → on → off  → on → off . If, on the otherhand, the current state is the on state, the state transitions would be: on → off  → on → off  → on → off  → on.

    So if the lever of the switch is pushed 6 times in succession, the light bulbwill end up in whatever its current state is.

    This abstract model of the light bulb machine is called an automaton , and thegraph that represents it is called its state diagram .

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    4/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 4 of 14

     Automata TheoryPage 5 of 25

     Automata theory therefore uses abstract or mathematical models to representmachines and computers.

     Although the example given is a very simple one, it does exhibit the usefulness ofmathematical models.

    Like the light bulb machine, a computer can also be in a certain state. Thesestates depend upon several factors such as the current contents of its mainmemory, processor registers, etc.

    When input data arrives or an event occurs which happens when someone clicksthe mouse or types a character on the keyboard, the contents of the main memoryand the processor registers may change. The computer system subsequentlymoves from its current state to another state.

     Automata TheoryPage 6 of 25

    The following are just some of the things that can be done once models have beenestablished:

    1. Determine the capabilities and limitations of each machine.

    2. Determine which machine is more powerful. That is, make objectivecomparisons.

    3. Determine what each machine can compute.

     Automata Theory

    Page 7 of 25 An automaton is not only used to represent machines (hardware) but they can alsobe used to represent non-machines such as software (such as operating systemsand compilers).

    The different types of automata that will be encountered in this course are

    1. Finite Automata (both deterministic and nondeterministic)

    2. Push-down Automata

    3. Turing Machines.

    [Automata Theory, Pages 1 –7 of 25] 

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    5/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 5 of 14

    Deterministic Finite AutomataPage 8 of 25

    Finite Automata

    Deterministic Finite Automata

     A fini te automaton  is a machine that has a limited (finite) number of states.

    Because of this limitation, these are normally used to model computers with alimited amount of memory or programs that process only a small amount of data.

    In the light bulb example, there are only two states that the system has toremember, the on and off  states. If it were a computer, the memory required forthat machine is only 1 bit (because it only has two states). The bit could be 0 torepresent the off  state while 1 could represent the on state.

    To facilitate the discussions on automata in this course, the machine to beconsidered will be a hypothetical machine whose only task is to determine whetheran input string or a series of input symbols is acceptable or not based on somepredefined rule.

    Deterministic Finite AutomataPage 9 of 25

    Given the following state diagram of a finite automaton M 1.

    q 1 

    0

    qq 2

    q 3 

    1

    0, 1

    0

    1

    0

    1

    q 0 

     

    Take note of the following facts about M 1:

    1. It has four states labeled q0, q1, q2, and q3.

    2. It has an init ial state  which is q0. There can only be one initial or startstate, and it is indicated by an arrow that does not originate from anystate. The initial state is the current state of the system before the start ofany processing or computation.

    3. It has one f inal  or accept state  which is q2. There could be one or morefinal states and they are designated by circles with double loops.

    4. It has edges connecting the states. These edges represent t ransi t ions .These are labeled by symbols. A symbol represents the input needed tocause the transition from one state to the other.

    In the given state diagram, the edge connecting q0  to q1  is labeled 0. Thismeans that if the system is at state q0, an input symbol of 0 will cause thesystem to move from state q0 to state q1. State q3 had an edge leading to itselflabeled 0, 1. If the system is at state q3, and if an input equal to either 0 or 1arrives, the system will remain at state q3. Since the input is either 0 or 1 only,if the system goes into state q3, it will no longer be able to leave the state.

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    6/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 6 of 14

    Deterministic Finite AutomataPage 10 of 25

    Consider the following process flow for M 1 when there is an input string of 00101:

    1. The machine is currently at the initial state, q0.

    2. The system receives a 0 as its input. So the system moves from q0 to q1.

    3. At q1, the system receives another 0 as its second input. So the systemstays at state q1.

    4. Still at q1, the system then receives a 1 as its third input. So the systemmoves from state q1 to q2.

    Deterministic Finite AutomataPage 11 of 25

    5. Now at q2, the system receives a 0 as its fourth input. So the systemmoves from state q2 to q1.

    6. Back at q1, the system receives a 1 as its fifth and last input. So thesystem moves from state q1 to q2.

    Since the system is now at state q2 and it is a final state, then it is said that thesystem accepts the input string 00101.

    Repeat the simulation again for various input strings such as 000000, 01, 1010111,101, 0101011, 0111110, and 0111111. Notice that M 1 will only accept the strings

    01, 0101011, and 0111111 since these are the strings where the computationended in the accept state.

    The strings accepted by a finite automaton may be described by a single,generalized statement.

    In this case, the generalization will be of the form “M 1 accepts any string that startswith a 0, followed by any number of 0s and 1s, as long as the last input is a 1.” 

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    7/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 7 of 14

    Deterministic Finite AutomataPage 12 of 25

    Formal Definition of a Deterministic Finite Automaton (DFA)

     A formal definition of a deterministic finite automaton or DFA is obtained by simplyenumerating its components.

     A deterministic finite automaton (DFA) is composed of

    1. A finite set of states  designated as Q.

    2. A finite set of symbols  (alphabet) used as inputs designated as  .

    3. A t ransi t ion funct ion  designated as  .

    4. A star t state  designated as q0.

    5. A set of f inal states  or accept states  designated as F .

    Deterministic Finite AutomataPage 13 of 25

    The transition function is a table that specifies when state transitions (movementfrom one state to another) are carried out.

    For the DFA M 1, its transition function    can be shown in the following form:

    This transition table is actually the state diagram in tabular form.

    From the transition table, it is easy to see that:

    If the current state is q0 and the input is 0, the DFA goes to q1. If theinput is 1, it goes to q3.

    If the current state is q1 and the input is 0, the DFA stays at q1. If theinput is 1, it goes to q2.

    If the current state is q2 and the input is 0, the DFA goes to q1. If theinput is 1, it stays at q2.

    If the current state is q3 and the input is 0, the DFA stays at q3. If theinput, it stays at q3.

     A mathematical way of stating state transitions is by using the equation of the form

      (q0, 0) = q1 

    This equation indicates that if the current state is q0  and theinput is 0, the DFA goes to q1. That is, the arguments of thefunction are the current state and the input.

    It is important to point out that for each input symbol, the DFA can move to onlyone state given its current state. This is what is meant by the term “deterministic.” 

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    8/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 8 of 14

    Deterministic Finite AutomatonPage 14 of 25

    Using the formal definition of a DFA, M 1 can now be described as a 5-tuple (thecomponents):

    M 1 = {Q,  ,  , q0, F }

    where:

    1. Q = {q0, q1, q2, q3}

    2.   = {0, 1}

    3.   is defined by the transition table

    4. Start State = q0.5. F  = {q2}

    Deterministic Finite AutomataPage 15 of 25

    For each of the following DFA examples, have the students formally describe theDFA by listing down the components of each (set of states, set of symbols, thetransition table, the start state, and the final state or states). Then let themexperiment with various strings to determine the strings that will be accepted andrejected by the DFA. Finally, have them come up with a generalized statement onthe strings accepted by the DFA.

    It is not advised that the instructor let the students to work on all the examples andthen later present to them all the solutions.

    Instead, it is highly recommended that the students work on them one at a time.Meaning, have them work on one example for 5 to 10 minutes. Then present tothem the solution for that example. After that, have them work on the secondexample for another 5 to 10 minutes and then present to them the solution. In thisway, the students learn from their mistakes before proceeding to solve the nextexercise.

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    9/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 9 of 14

    Deterministic Finite AutomataPage 16 of 25

    Deterministic Finite AutomataPage 17 of 26

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    10/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 10 of 14

    Deterministic Finite AutomataPage 18 of 25

    For DFA M 2:

    q 1

    0, 1

    q 0

    0, 1  

    1. Q = {q0, q1}

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q0}

    M 2  accepts all strings whose length is even. Take note that since thestart state is also the final state, the system is already in the accept stateeven though there is no input yet. Therefore, it will accept the emptystring ε .

    Deterministic Finite AutomataPage 19 of 25

    For DFA M 3:

    q 1

    1

    q 0

    1

    00

     

    1. Q = {q0, q1}

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q0}

    M 3 accepts all strings (including the empty string ε) that contain an evennumber of 1’s. 

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    11/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 11 of 14

    Deterministic Finite AutomataPage 20 of 25

    For DFA M 4:

    0 0q 2q 1q 0

    1 1 0, 1

     

    1. Q = {q0, q1, q2}

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q1}

    M 4 accepts all strings that only has exactly one 0.

    Deterministic Finite AutomataPage 21 of 25

    For DFA M 5:

    0, 1q 1

    0, 1

    0, 1

    q 2q 0

     

    1. Q = {q0, q1, q2}

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q0}

    M 5  accepts all strings whose length is divisible by 3. It will also acceptthe empty string ε  since the start state is also a final state. Plus the factthat the length of the empty string is 0 which is also divisible by 3.

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    12/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 12 of 14

    Deterministic Finite AutomataPage 22 of 25

    For DFA M 6:

    1

    0

    01

    q 0

    q 1

    q 3

    q 2

    q 4

    0

    1

    0

    0 1

    1

     

    1. Q = {q0, q1, q2, q3, q4)

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q1, q3}

    M 6 accepts all strings that start and end with the same symbol.

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    13/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 13 of 14

    Deterministic Finite AutomataPage 23 of 25

    For DFA M 7:

    1

    0

    1

    0, 1

    q 0 q 1 q 2

    0

     

    1. Q = {q0, q1, q2}

    2.   = {0, 1}

    3.  : 

    4. Start State = q0.

    5. F  = {q1}

    M 7 accepts all strings that have at least one 1 and the last 1 is alwaysfollowed by an even number (including 0) of consecutive 0s.

    Deterministic Finite Automata

    Page 24 of 25

     A DFA accepts a specified set of strings. And, as discussed previously, a set of

    strings is called a language.

    Therefore, the set of strings that an automaton accepts is called the language ofthe automaton .

    For example, the language of DFA M 2 is the set of all strings over the alphabet   ={0, 1} whose length is even.

    If L is the language recognized by a DFA M , then it is designated as L(M ).

    The language of M 2 can then be mathematically described as:

    L(M 2) = {w   the length of w  is even}

    This is read as “the language of M 2  is the set of all strings w  such that the length of w is even.”  

  • 8/21/2019 MELJUN CORTES Automata Lecture Intro to Finite Automata 1

    14/14

     

    Theory of Computation (With Automata Theory)

    Introduction to Finite Automata *Property o f STIPage 14 of 14

    Deterministic Finite AutomataPage 25 of 25

     A language that is recognized by a DFA is called a regular language .

    For example, the language composed of all strings over the alphabet   = {0, 1} thatstarts and ends with the same symbol is a regular language because there is aDFA (specifically, M 6) that recognizes it.

    Therefore, L(M 6) is a regular language.

    [Deterministic Finite Automata, Pages 8 –

    25 of 25]