Deterministic Finite Automata (DFA) vs Nondeterministic Finite Automata (NFA)

Pasted image 20261105195635.png
Pasted image 20261105195648.png

So basically the issue here is that in the first example there is too many transitions, and so you do not end up knowing which one of them you should take, and then in the second one there is no transition for b when you have a zero so you end up not having anywhere to go. I thought that this would basically mean that this is not a valid automaton but it seems that I do guess you can make these kinds of ones as well.

Deterministic Finite Automaton, DFA:

  • Are the simplest form of finite automata
  • They are well-behaved in terms of reading all input
    1. This means that for EACH state in DFA, there is exactly ONE transition for each letter of the alphabet
    2. It also means that there is a unique starting state, so you know where you need to being

Therefore, if either of those two rules are broken, then the automaton is Non-Deterministic


Nondeterministic Finite Automaton, NFA

  • Very similar to that of the DFA
  • The differences are those two rules though, there may be many choices at one particular point
  • There may also be no paths spelling the input
  • An input is accepted if at least one sequence of choices leads to an accepting state

So in essence these are sort of like shortcut DFA, where you can have a bunch of different bullshit that if you do it one specific way it leads to an accepting state. Because of this they can be much more complex than a DFA

Example:

Pasted image 20261105200444.png

If you specifically choose for the first one to loop, and then accept the second one to go forward, and then you have the zero move forward, and then you have the one loop, you end up at the accepting state of C.

However if you do something like let both of the first ones loop on A, and then move on the zero to B, and then loop the last 1 onto be, then you end up with a non accepting state


DFA Example

Pasted image 20261105200546.png

So basically the language defined for the deterministic finite automaton starts with an initial state of course, and this initial state leads to one of two branching states for each of the letters of the alphabet, if the initial choice is b, then we can outright reject the entire string by looping that node, and if the starting choice is A, we then have another branching of two states, where we eventually want to end in B or go back to A, very simple, each state has a transition, and we have a valid start point:

Pasted image 20261105200957.png

Right, very simple, you have what was described above, q1 is the dummy state that is outright rejecting and loops for all values in the alphabet, and then up top is the actual real logic where you loop until you find a b and if you find an a then you just go back until you find another b

Pasted image 20261105201951.png

Quick little example of a DFA that works for strings in a language of A, B where we have strings with even values of A and an Odd Number of Bs


Computation by NFA

Pasted image 20261105203017.png

The issue here of course if what if you end up at the state of B and then you have nowhere to go because you run into another zero? You kind of end up stalling there forever without anywhere to go with the above string example. So this input is actually rejected. This is kind of nice if you think about it because it means you do not need to handle the extra cases

Pasted image 20261105203356.png

The above automaton is good because when you look at what it does, it basically checks to see if the first two values within of the string are a zero, and it rejects all strings that have the first two values as zeros. You could theoretically showcase this with a DFA by having another zero branch over into a dummy state, but then that means a whole extra node of complexity, this is something you can reduce with this NFA

More Complex Example:

Pasted image 20261105203540.png

This one is a little bit weirder, you basically have the choice of looping over on the start point for as long as you like, with the values of zero holding really the most power here. I think the most interesting things to look at is really what gets rejected, because a string that starts with something like 01 will automatically get rejected, but an input that has a sequence of 00 anywhere within it will get accepted, unless of course it has a 01 in it first, very weird, I do not really see the purpose of this one. I do understand it can make modeling the same thing as a DFA more simple though.

Making an NFA example

Pasted image 20261105204013.png

So basically this is the same concept, the is now however that you can basically choose to skip out certain options, so instead of drawing the b section from the starting point, you can actually just say fuck that, and have it loop I think, so you can have a more simple automaton.

Pasted image 20261105204300.png

While designing the NFA ONLY THINK ABOUT THE STRINGS THAT ARE ACCEPTED, so you do not have to do things like handle any of the edge cases, so you can only expect to see an A, and do not need to consider a B, and then after that you can see however many A’s or B’s as you want, given you EXPECT it to end in a B.

The reason why we can do this is because we have a nondeterministic way of checking. That means that whenever you do have multiple options for deciding which way to go, the path that you actually go ahead and choose is the path that favors you better. This means that you can check all of the options you have, and choose the one that leads to the accepting state, and this is why a string like abb is accepted

Week 8 Exercises

Now it’s time to put into practice the concepts that you have learnt so far in Week 8. Attempt the following exercises. If you get stuck, you can refer to the hints and tips on the next page.

Please note that these exercises are optional, further practice – but we strongly recommend that you engage with them in order to test your knowledge and see where you might need to do additional study.

  1. Over {a,b}, design a DFA to accept all strings starting with ‘b’ and having an odd number of ‘a’s.
  2. Over {0,1}, design a DFA to accept all strings ending with 01.
  3. Over {a,b}, design an NFA to accept all strings in which their second letter is ‘a’ and their last letter is ‘b’.
  4. Design an NFA that accepts binary numbers greater than 0, whose decimal equivalents are divisible by 6. For instance, the NFA should accept inputs like ‘1100’ (decimal equivalent: 12) and ‘110 (decimal equivalent: 6), but it rejects inputs like ‘1101’ (decimal equivalent: 13) and ‘1001’ (decimal equivalent: 9).

“Automata theory part 2.pdf” could not be found.

Book Reading

“Sipser pp47 58 Accessible.pdf” could not be found.

Book Work

So, up till this point, in the reading at least, when the machine has been in a given state, it would read the next symbol, and we would know exactly what the next state will be. It is determined for each of the given possible values, and it therefore called the deterministic computation.

In a non-deterministic computation several choices might exist for the next state at any point, meaning you can take many different paths from the same point given the same input. Nondeterminism is a generalization of determinism. So every single determinisitc finite automaton is automatically also a nondeterministic finite automaton

DFA vs NFA

Pasted image 20261107150851.png

The above example is a NFA, or Nondeterministic Finite Automaton, and the difference between this and a Determinisitic Finite Automaton of a DFA, is the fact that we can already see that not every single state/node has a transition for each member of the alphabet, and there is also sometimes multiple different transitions for the same input in a given state, meaning your going through the automaton can branch out with the same input.

Notice also the use of the symbol ε in one of the transitions there, this is also something that you would not find in a NFA, it means that whenever you land on that node, you can actually move past it even without consuming input if you wanted to, or with input consumption if possible, so you can move ahead without changing anything.

The way that an NFA actually computes is by going through the machine like normal, but then whenever you reach a branch that would lead to difference choices, so for example a one that can loop and then a one that can go to another state, then the possibilities split off and then run in parallel, doing so for every possible split in transit. This goes on for all the possible ways for the string to run through the automaton, and if at least one is accepted then the string is considered as accepted.

So you can really think of it as multiple processes/threads running concurrently, trying out all possible options and “forking” off into several different children, and if at least one is accepted then the whole input is. So you can think of it kind of as a tree like structure:

Pasted image 20261107153924.png

So you have an option that splits based on the options that you can make, and then based on the symbol you get a branch from where you can end up going basically, and with this you keep going until either you get a way of accepting, or you end up with a state that rejects you.

So, for the above example of an NFA, we basically have an automaton that accepts strings that have either a 101 or 11 as a substring inside of them.


A NFA can be very useful in a lot of different ways, we can convert an NFA into an equivalent DFA for one if need be, but most of the time an NFA is used is because it can be a LOT smaller than it’s DFA counterpart, and understanding the function of what it is trying to accomplish may be much easier as well.

Pasted image 20261107160057.png

So if you want to have something that would check if there is a 1 3 places from the end of the string, you can basically look until the NFA can “guess” it is three places from the end, and then you can check to see if the 1 exists in the place 3 places from the end

Pasted image 20261107160218.png

This is basically the same DFA that does the same thing as the previous NFA, it needs to have a branching state for each of the possible choices, but also needs to be able to go back to the original failing point if the criteria not met, as you can see this looks a lot more complicated than the DFA, and is therefore why something like the NFA might be used in order to better convey the intent behind the machine.


Convenience of ε arrows

So assume that you have a unary alphabet {0}, and then the following automaton:

Pasted image 20261107160509.png

So the above NFA allows us to actually accept all strings of 0^k where k is a multiple of either 2 or three, so things like 00, 000, 000000, are all accepted, but something like 00000 or 0 would not be. This is because the use of the ε allows us to actually branch out into the two possibilities that we want to explore without actually consuming any state, letting us check equally for both the multiple of 2, and the multiple of 3.

Formal Definition for NFA

Pasted image 20261107161039.png

They are basically the exact same, with the only difference being that number 3 rule, the delta function that describes transitions. Basically, unlike in a deterministic finite automaton, the transition function takes a state and an input symbol, or empty string, and produces a set of possible next states. So basically this:

Pasted image 20261107161242.png

So you basically end up with the powerset of all the possible outcomes that can come from a given move, so think of it just like that tree thing that is a few images up basically. So for the previous example the formal definition ends up being the following:

Pasted image 20261107162014.png

As you can see it is defined out pretty similarly to that of a regular DFA, but the only difference being that the delta function now describes sets of states instead of a single state, even with a null set whenever the item ends up being rejected.

Pasted image 20261107162918.png

So basically you define a computation for an NFA as hey, I have this given alphabet, and this string that exists inside of the alphabet which can be summed up as a collection of characters from this alphabet. Then, a sequence of states that exist in the set of all states defined for the machine, with the three conditions of there must be a start state, there is a transitional possibility, and there is a way for us to reach the final accepting state.


Equivalence between DFA and NFA

Now even though a NFA has a lot more power than something like a DFA, they actually still cover the same range of languages, which is a bit surprising but makes sense if you think about it since every single non-deterministic finite automaton has an equivalent deterministic finite automaton. An NFA just tends to cut corners and take off things like dummy nodes with less transitions or avoid unwanted states using looping here is the given proof from the book:

Pasted image 20261107165609.png
Pasted image 20261107165633.png