Finite state automata
Finite Automata, is the machine or method that's used to recognize those patterns of regular expression .
A Finite Automaton (or FSA) is an abstract machine that reads an input string (like "good") one character at a time and then decides if it "accepts" (matches the pattern) or "rejects" (doesn't match) the string
There are two main types :
Deterministic Finite Automaton (DFA)
A Deterministic Finite Automaton (DFA) is a model of computation used to recognize patterns.
- Key Property (Deterministic): The "deterministic" part means that for any given state and any possible input symbol, there is exactly one defined next state. The machine's path is completely predictable.
Non - Deterministic finite automation (DFS):
same as DFA with Two differences
-
ϵ-Transitions (Your "void state E")
-
An NFA can move from one state to another without reading any input symbol. This is like a "free" move.
-
A DFA must read an input symbol to change states.
-
-
Multiple Next States
-
In an NFA, a single state and a single input symbol (like
'a') can lead to multiple different states at the same time. It's like the path splits. and NFA simultaneously explores all possible paths at once -
In a DFA, a state and an input symbol lead to exactly one state. The path is always predictable.
-
Formal Definition (The 5-Tuple)
A DFA is formally defined as a 5-tuple: \{Q, \Sigma, \delta, q_0, F\}
- Q: A finite set of all states.
- \Sigma (Sigma): A finite set of input symbols, called the alphabet.
- \delta (Delta): The transition function.
- Its signature is: ==\delta: Q \times \Sigma \to 2^Q==
- This means the function takes a current state (from Q) and an input symbol (from \Sigma) and returns the next state (from Q).
- q_0: The initial state (or start state). This is the state the machine begins in before reading any input. (q_0 \in Q)
- F: The set of final states (or accepting states). This can be one state, multiple states, or even no states. (F \subseteq Q)
Simple Example
How it Works (Step-by-Step)
Let's use our last example, tracing the input "ab":
-
Start: You are at
q0. The next input symbol to read is 'a'. -
Read 'a': You read the 'a'. The NFA splits.
-
One path goes to
q1. -
Another path goes to
q3.
-
-
Process ϵ-Move: Before the NFA even looks at the 'b', it checks its new states.
-
The path at
q3does nothing. -
The path at
q1sees the free ϵ-move toq2. It instantly takes this move without reading the 'b'.
-
-
Ready for Next Input: The NFA has now processed the 'a' and is ready to read the 'b'. Its active "clones" are at states {q2,q3}.
-
Read 'b': Now it finally reads the 'b' and proceeds as we discussed before.
graph LR;
%% Define states
q0((q0));
q1((q1));
q2((q2));
q3((q3));
q_final(((q_final)));
%% Define transitions
start(( )) -- Start --> q0;
%% Feature 2: Multiple Transitions
q0 -- a --> q1;
q0 -- a --> q3;
%% Feature 1: Epsilon Transition
q1 -- ε --> q2;
q2 -- b --> q_final;
q3 -- c --> q_final;
Problem
Tags: