NDFA Archives - https://www.theoryofcomputation.co/tag/ndfa/ Science of Computer Wed, 15 Aug 2018 13:30:31 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/www.theoryofcomputation.co/wp-content/uploads/2018/08/cropped-favicon-512x512-2.png?fit=32%2C32&ssl=1 NDFA Archives - https://www.theoryofcomputation.co/tag/ndfa/ 32 32 149926143 Equivalence of Automata https://www.theoryofcomputation.co/equivalence-of-automata/ Wed, 15 Aug 2018 13:30:31 +0000 https://www.theoryofcomputation.in/?p=125 Equivalence of Automata Two automata A and B are said to be equivalent if both accept exactly the same set of input strings. Formally, if two automata A and B are equivalent then if there is a path from the start state of A to a final state of A labeled a1a2..ak, there there is...

The post Equivalence of Automata appeared first on .

]]>
Equivalence of NFA and DFAEquivalence of Automata

Two automata A and B are said to be equivalent if both accept exactly the same set of input strings. Formally, if two automata A and B are equivalent then

  • if there is a path from the start state of A to a final state of A labeled a1a2..ak, there there is a path from the start state of B to a final state of B labeled a1a2..ak.
  • if there is a path from the start state of B to a final state of B labeled b1b2..bj, there there is a path from the start state of A to a final state of A labeled b1b2..bj.

[the_ad id=”112″]

Equivalence of Deterministic and Nondeterministic Automata

To show that there is a corresponding DFA for every NDFA, we will show how to remove nondeterminism from an NDFA, and thereby produce a DFA that accepts the same strings as the NDFA.

Equivalence of Finite Automata

The basic technique is referred to as subset construction, because each state in the DFA corresponds to some subset of states of the NDFA.

The idea is this: as we trace the set of possible paths thru an NDFA, we must record all possible states that we could be in as a result of the input seen so far. We create a DFA which encodes the set of states of the NDFA that we could be in within a single state of the DFA.

Subset Construction for NDFA

To create a DFA that accepts the same strings as this NDFA, we create a state to represent all the combinations of states that the NDFA can enter.

From the previous example (of an NDFA to recognize input strings containing the word “main”) of a 5 state NDFA, we can create a corresponding DFA (with up to 2^5 states) whose states correspond to all possible combinations of states in the NDFA:

  {},
  {s0}, {s1}, {s2}, {s3}, {s4},
  {s0, s1}, {s0, s2}, {s0, s3}, {s0, s4},
  {s1, s2}, {s1, s3}, {s1, s4},
  {s2, s3}, {s2, s4},
  {s3, s4},
  {s0, s1, s2}, {s0, s1, s3}, {s0, s1, s4},
  {s0, s2, s3}, {s0, s2, s4},
  {s0, s3, s4},
  {s1, s2, s3}, {s1, s2, s4},
  {s1, s3, s4},
  {s2, s3, s4},
  {s0, s1, s2, s3}, {s0, s1, s2, s4},
  {s0, s1, s3, s4}, {s0, s2, s3, s4},
  {s1, s2, s3, s4},
  {s0, s1, s2, s3, s4}

Note that many of these states won’t be needed in our DFA because there is no way to enter that combination of states in the NDFA. However, in some cases, we might need all of these states in the DFA to capture all possible combinations of states in the NDFA.

Subset Construction for NDFA (cont)

A DFA accepting the same strings as our example NDFA has the following transitions:

  {s0} -m-> {s0,s1}
  {s0} -not m-> {s0}
  
  {s0,s1} -m-> {s0,s1}
  {s0,s1} -a-> {s0,s2}
  {s0,s1} -not m,a-> {s0}
  
  {s0,s2} -m-> {s0,s1}
  {s0,s2} -i-> {s0,s3}
  {s0,s2} -not m,i-> {s0}
  
  {s0,s3} -m-> {s0,s1}
  {s0,s3} -n-> {s0,s4}
  {s0,s3} -not m,n-> {s0}

The start state is {s0} and the final state is {s0,s4}, the only one containing a final state of the NDFA.

Limitations of Finite Automata

The defining characteristic of FA is that they have only a finite number of states. Hence, a finite automata can only “count” (that is, maintain a counter, where different states correspond to different values of the counter) a finite number of input scenarios.

There is no finite automaton that recognizes these strings:

  • The set of binary strings consisting of an equal number of 1’s and 0’s
  • The set of strings over ‘(‘ and ‘)’ that have “balanced” parentheses

The ‘pumping lemma’ can be used to prove that no such FA exists for these examples.

The post Equivalence of Automata appeared first on .

]]>
125
Deterministic Finite Automata (DFA) https://www.theoryofcomputation.co/deterministic-finite-automata-dfa/ Mon, 13 Aug 2018 16:47:35 +0000 https://www.theoryofcomputation.in/?p=116 Definition of Deterministic Finite Automata Deterministic Finite Automata (DFA) consists of 5 tuples {Q, ∑, q, F, δ}. Q : set of all states. ∑ : set of input symbols. ( Symbols which machine takes as input ) q : Initial state. ( Starting state of a machine ) F : set of final state....

The post Deterministic Finite Automata (DFA) appeared first on .

]]>
Definition of Deterministic Finite Automata
Deterministic Finite Automata (DFA) consists of 5 tuples {Q, ∑, q, F, δ}. 
Q : set of all states.
∑ : set of input symbols. ( Symbols which machine takes as input )
q : Initial state. ( Starting state of a machine )
F : set of final state.
δ : Transition Function, defined as δ : Q X ∑ --> Q.

IDeterministic Finite Automata (DFA)n a DFA, for a particular input character, machine goes to one state only. A transition function is define on every state for every input symbol. Also in DFA null (or ε) move is not allowe, i.e., DFA can not change state without any input character.

For example, below DFA with ∑ = {0, 1} accepts all strings ending with 0.

One important thing to note is, there can be many possible DFAs for a pattern. A DFA with minimum number of states is generally preferred.

 

Some Important Points:

  1. Every DFA is NFA but not vice versa.
  2. Both NFA and DFA have same power and each NFA can be translated into a DFA.
  3. There can be multiple final states in both DFA and NFA.
  4. NFA is more of a theoretical concept.
  5. DFA is used in Lexical Analysis in Compiler.

Limitations of Finite Automata

The defining characteristic of FA is that they have only a finite number of states. Hence, a finite automata can only “count” (that is, maintain a counter, where different states correspond to different values of the counter) a finite number of input scenarios.

There is no finite automaton that recognizes these strings:

  • The set of binary strings consisting of an equal number of 1’s and 0’s
  • The set of strings over ‘(‘ and ‘)’ that have “balanced” parentheses

The ‘pumping lemma’ can be used to prove that no such FA exists for these examples.

Read: What is Non Deterministic Finite Automata?

The post Deterministic Finite Automata (DFA) appeared first on .

]]>
116
Non Deterministic Finite Automata https://www.theoryofcomputation.co/non-deterministic-finite-automata/ Sun, 12 Aug 2018 17:16:03 +0000 https://www.theoryofcomputation.in/?p=105 Non Deterministic Finite Automata (NDFA) If, for each pair of states and possible input chars, there is a unique next state (as specificed by the transitions), then the FA is deterministic (DFA). Otherwise, the FA is non deterministic finite automata (NDFA). What does it mean for an FA to have more than one transition from...

The post Non Deterministic Finite Automata appeared first on .

]]>
Non Deterministic Finite Automata (NDFA)

If, for each pair of states and possible input chars, there is a unique next state (as specificed by the transitions), then the FA is deterministic (DFA). Otherwise, the FA is non deterministic finite automata (NDFA).

What does it mean for an FA to have more than one transition from a given state on the same input symbol? How do we translate such an FA into a program? How can we “goto” more than one place at a time?

Conceptually, a nondeterministic FA can follow many paths simultaneously. If any series of valid transitions reaches an accepting state, they we say the FA accepts the input. It’s as if we allow the FA to “guess” which of several transitions to take from a given state, and the FA always guesses right.

We won’t attempt to translate an NDFA into a program, so we don’t have to answer the question “how can we goto more than one place at a time”. Instead, we can prove that every NDFA has a corresponding DFA, and there is a straightforward process for translating an NDFA into a DFA. So, when given an NDFA, we can translate it into a DFA, and then write a program based on the DFA.

Definition of Non Deterministic Finite Automata

NFA is similar to DFA except following additional features:

1. Null (or ε) move is allowed i.e., it can move forward without reading symbols.
2. Ability to transit to any number of states for a particular input.
However, these above features don’t add any power to NFA. If we compare both in terms of power, both are equivalent.

Due to above additional features, NFA has a different transition function, rest is same as DFA.

δ: Transition Function
δ:  Q X (∑ U ϵ ) --> 2 ^ Q.

As you can see in transition function for any input including null (or &epsilon), NFA can go to any state number of states.

Non Deterministic Finite Automata

Example of an NDFA

An NDFA to accept strings containing the word “main”:

-> s0 -m-> s1 -a- > s2 -i-> s3 -n-> (s4)
-> s0 -any character-> s0

This is an NDFA because, when in state s0 and seeing an “m”, we can choose to remain in s0 or go to s1. (In effect, we guess whether this “m” is the start of “main” or not.)

If we simulate this NDFA with input “mmainm” we see the NDFA can end up in s0 or s1 after seeing the first “m”. These two states correspond to two different guesses about the input: (1) the “m” represents the start of “main” or (2) the “m” doesn’t represent the start of “main”.

  -> s0 -m-> s0
        -m-> s1

On seeing the next input character (“m”), one of these guesses is proven wrong, as is there is no transition from s1 for an “m”. That path halts and rejects the input. The other path continues, making a transition from s0 to either s0 or s1, in effect guessing that the second “m” in the input either is or is not the start of the word “main”.

  -> s0 -m-> s0 -m-> s0
                -m-> s1
        -m-> s1

Continuing the simulation, we discover that at the end of the input, the machine can be in state s0 (still looking for the start of “main”), s1 (having seen an “m” and looking for “ain”), or s4 (having seen “main” in the input). Since at least one of these states is an accepting state (s4), the machine accepts the input.

  s0 -m-> s0 -m-> s0 -a-> s0 -i-> s0 -n-> s0 -m-> s0 
  				           -m-> s1
             -m-> s1 -a-> s2 -i-> s3 -n-> s4
     -m-> s1

The post Non Deterministic Finite Automata appeared first on .

]]>
105