The Wayback Machine - https://web.archive.org/web/20241114063242/https://www.geeksforgeeks.org/introduction-of-finite-automata/
Open In App

Introduction of Finite Automata

Last Updated : 12 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Finite automata are abstract machines used to recognize patterns in input sequences, forming the basis for understanding regular languages in computer science. They consist of states, transitions, and input symbols, processing each symbol step-by-step. If the machine ends in an accepting state after processing the input, it is accepted; otherwise, it is rejected. Finite automata come in deterministic (DFA) and non-deterministic (NFA), both of which can recognize the same set of regular languages. They are widely used in text processing, compilers, and network protocols.

Fintie Automata

Figure: Features of Finite Automata

Features of Finite Automata

  • Input: Set of symbols or characters provided to the machine.
  • Output: Accept or reject based on the input pattern.
  • States of Automata: The conditions or configurations of the machine.
  • State Relation: The transitions between states.
  • Output Relation: Based on the final state, the output decision is made.

Formal Definition of Finite Automata

A finite automaton can be defined as a tuple:

{ Q, ÎĢ, q, F, Îī }, where:

  • Q: Finite set of states
  • ÎĢ: Set of input symbols
  • q: Initial state
  • F: Set of final states
  • Îī: Transition function

Types of Finite Automata

There are two types of finite automata:

  • Deterministic Fintie Automata (DFA)
  • Non-Deterministic Finite Automata (NFA)

1. Deterministic Finite Automata (DFA)

A DFA is represented as {Q, ÎĢ, q, F, Îī}. In DFA, for each input symbol, the machine transitions to one and only one state. DFA does not allow any null transitions, meaning every state must have a transition defined for every input symbol.

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.

Example:

Construct a DFA that accepts all strings ending with ‘a’.

Given:

ÎĢ = {a, b},

Q = {q0, q1},

F = {q1}

State Transition Diagram

Fig 1. State Transition Diagram for DFA with ÎĢ = {a, b} 

State\Symbol a b
q0 q1 q0
q1 q1 q0

In this example, if the string ends in ‘a’, the machine reaches state q1, which is an accepting state.

2) Non-Deterministic Finite Automata (NFA)

NFA is similar to DFA but includes the following features:

  • It can transition to multiple states for the same input.
  • It allows null (Ïĩ) moves, where the machine can change states without consuming any input.

Example:

Construct an NFA that accepts strings ending in ‘a’.

Given:

ÎĢ = {a, b},

Q = {q0, q1},

F = {q1}

Fig 2. State Transition Diagram for NFA with ÎĢ = {a, b}

State Transition Table for above Automaton,

State\Symbol a b
q0 {q0,q1} q0
q1 φ φ

In an NFA, if any transition leads to an accepting state, the string is accepted.

Comparison of DFA and NFA

Although NFAs appear more flexible, they do not have more computational power than DFAs. Every NFA can be converted to an equivalent DFA, although the resulting DFA may have more states.

  • DFA: Single transition for each input symbol, no null moves.
  • NFA: Multiple transitions and null moves allowed.
  • Power: Both DFA and NFA recognize the same set of regular languages.

Conclusion

Finite automata, whether deterministic or non-deterministic, are powerful tools in pattern recognition and regular language processing. They form the backbone of many computational processes, especially in text analysis and compiler design. While DFAs are simpler and more commonly used, NFAs offer a more flexible yet equivalent way to define regular languages. Understanding the nuances of both helps in optimizing various algorithms in computer science.

Frequently Asked Questions on Finite Automata – FAQs

1. What is the main difference between DFA and NFA?

The main difference is that DFA allows only one transition for each input symbol, while NFA can have multiple transitions for the same input and even transition without consuming input (Ïĩ move).

2. Can every NFA be converted to a DFA?

Yes, every NFA can be converted to an equivalent DFA, although the resulting DFA may have exponentially more states.

3. Why is DFA used in lexical analysis?

DFA is used in lexical analysis because it provides a more structured and efficient way to process input symbols, making it ideal for scanning and recognizing patterns in source code.

4. What are the applications of finite automata?

Finite automata are widely used in text searching, regular expression matching, compiler design (lexical analysis), and network protocol design.


Previous Article
Next Article

Similar Reads

Difference Between Pushdown Automata and Finite Automata
Two important computational models in automata theory that are used to identify various language kinds are Pushdown Automata (PDA) and Finite Automata (FA). Both automata process strings as input and switch between states according to pre-established rules. Still, their memory capacities account for the majority of the variance. Pushdown Automata h
5 min read
Generating regular expression from Finite Automata
Prerequisite - Introduction of FA, Regular expressions, grammar and language, Designing FA from Regular Expression There are two methods to convert FA to the regular expression: 1. State Elimination Method:Step 1 - If the start state is an accepting state or has transitions in, add a new non-accepting start state and add an ₮-transition between the
3 min read
Theory of Computation | Regular languages and finite automata | Question 2
What is the complement of the language accepted by the NFA shown below? (A) A (B) B (C) C (D) D Answer: (B) Explanation: Quiz of this QuestionPlease comment below if you find anything wrong in the above post
1 min read
Practice problems on finite automata
Que-1: Draw a deterministic and non-deterministic finite automate which accept 00 and 11 at the end of a string containing 0, 1 in it, e.g., 01010100 but not 000111010. Explanation - Design a DFA and NFA of a same string if input value reaches the final state then it is acceptable otherwise it is not acceptable. NFA of the given string is as follow
2 min read
Practice problems on finite automata | Set 2
Que-1: Draw a deterministic and non-deterministic finite automate which either starts with 01 or end with 01 of a string containing 0, 1 in it, e.g., 01010100 but not 000111010. Explanation - Draw a DFA and NFA of same language whose strings only reach to the final state containing either 01 at start or at the end. If anything else is come then com
3 min read
Designing Finite Automata from Regular Expression (Set 6)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 5) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = a(a+b)* The language of the given RE is, {aaa, aba, baa, bba} Strings
3 min read
Finite Automata with Output (Set 6)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output, i.e., Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {0, 1} as input and produce 'A' as output if the input contains '101' as the sub
2 min read
Finite Automata with Output (Set 5)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {0, 1} as input and produce 'A' as output if the input contains '1' as the substri
2 min read
Designing Deterministic Finite Automata (Set 5)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which every 'a' is followed by a 'bb'. Explanation: The desired language will be like: L1 = {ε, abb, abbabb, bbbbabb, abbabbabbabbabbbb,
3 min read
Designing Deterministic Finite Automata (Set 9)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting a set of strings over {a, b} in which {abwa / wε{a, b}*}. Here 'w' is the substring containing alphabets over any number of 'a' and 'b' ranging from zero to infinity.
4 min read
Designing Deterministic Finite Automata (Set 6)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which anbm, where n and m is greater than or equal to 1. Explanation: The desired language will be like: L1 = {ab, aab, abb, aabb, aaabbb, aaabbb
3 min read
Finite Automata with Output (Set 3)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take set of all string over {a, b} as input and count number of substring 'a'. That is here we have, Ε
2 min read
Finite Automata with Output (Set 11)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines. Problem: Construction of the machines that take the binary number {0, 1} as input and produce 1's complement of that number as output. Here the assumptio
4 min read
Designing Finite Automata from Regular Expression (Set 2)
Prerequisite: Finite automata, Regular expressions, grammar and language. Designing finite automata from Regular expression In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Φ (Phi). The language of the given RE is L1 = {} i.e, empty string. Its finite automata will be
3 min read
Designing Finite Automata from Regular Expression (Set 3)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 2) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression. Regular Expression 1: 'ab*' ('a' followed by any number of 'b'). The language of the given RE is, L1 = {a, ab, abb
3 min read
Designing Finite Automata from Regular Expression (Set 4)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 3) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = (a+b)(a+b) The language of the given RE is, {aa, ab, ba, bb} Length o
3 min read
Designing Finite Automata from Regular Expression (Set 5)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 4) In the below article, we shall see some Designing of Non-deterministic Finite Automata form the given Regular Expression- As NFA can be changed to corresponding DFA. Regular Expression 1: Regular language, L1 = ((a+b)(
3 min read
Designing Finite Automata from Regular Expression (Set 7)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 6) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = b*aa(a+b)*+b*ab*aa(a+b*) The language of the given RE is- {aaa, baa,
3 min read
Designing Finite Automata from Regular Expression (Set 8)
Prerequisite: Finite automata, Regular expressions, grammar and language, Designing finite automata from Regular expression (Set 7) In the below article, we shall see some Designing of Finite Automata form the given Regular Expression- Regular Expression 1: Regular language, L1 = {an | n≥ 1} The language of the given RE is- {a, aa, aaa, ........
2 min read
Compound Finite Automata (FA)
Prerequisite - Finite Automata (FA) Compound FA is the resultant DFA formed after performing operation (∪, ∩, -) on given DFAs D1 and D2. D1 = (Q1, ∑, δ, q1, F1) and D2 = (Q2, ∑, δ, q2, F2) Where, Q1 and Q2: Set of finite states of DFA D1 and D2 respectively. ∑: Input alphabet contain finite number of input symbols.
2 min read
Equivalence Of F.S.A (Finite State Automata)
An Automaton is a machine that has a finite number of states. Any Two Automaton is said to be equivalent if both accept exactly the same set of input strings. Two Automaton are equivalent if they satisfy the following conditions : 1. The initial and final states of both the automatons must be same.2. Every pair of states chosen is from a different
3 min read
Designing finite automata for various operations like 1's complement, 2's complement
Transducers in Finite Automata(FA) means FA with Output.There are two types of Machines for FA with Output. 1. Mealy Machine : It is FA in which output is associated with each transition. (that means output depends on state and input).2. Moore Machine : It is FA in which output is associated with each state. (that means output depends on state only
4 min read
Design finite automata from regular expressions
Prerequisite - Finite automata, Regular expressions, grammar, and language. In this article, we will see some popular regular expressions and how we can convert them to finite automata (NFA and DFA). Let's discuss it one by one. Overview :Let a and b are input symbols and r is the regular expression. Now we have to design NFA as well as DFA for eac
3 min read
Conversion of Regular Expression to Finite Automata
As the regular expressions can be constructed from Finite Automata using the State Elimination Method, the reverse method, state decomposition method can be used to construct Finite Automata from the given regular expressions. Note: This method will construct NFA (with or without Îĩ-transitions, depending on the expression) for the given regular exp
3 min read
Designing Finite Automata from Regular Expression (Set 1)
In this article, we will see some popular regular expressions and how we can convert them to finite automata. Even number of a's : The regular expression for even number of a's is (b|ab*ab*)*. We can construct a finite automata as shown in Figure 1. The above automata will accept all strings which have even number of a’s. For zero a’s, it will be i
3 min read
Designing Deterministic Finite Automata (Set 7)
Prerequisite: Designing finite automata In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which a n b m c l , where n, m and l is greater than or equal to 0. Explanation: The desired language will be like: L1 = {Îĩ, a, aa, aaa, b, bb, b
6 min read
Designing Deterministic Finite Automata (Set 2)
Prerequisite - Designing finite automata, previous article: Designing Deterministic Finite Automata (Set 1) In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a DFA for the set of string over {a, b} such that length of the string |w| is divisible by 2 i.e, |w| mod 2 = 0. Explanation - The
7 min read
Designing Non-Deterministic Finite Automata (Set 4)
Prerequisite: Finite Automata Introduction In this article, we will see some designing of Non-Deterministic Finite Automata (NFA). Problem-1: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language contain 'a' as the substring. Explanation: The desired language will be like: L1 = {ab, abba, abaa, ..
4 min read
Designing Deterministic Finite Automata (Set 4)
Prerequisite: Designing finite automata , Designing Deterministic Finite Automata (Set 3) In this article, we will see some designing of Deterministic Finite Automata (DFA). Problem-1: Construction of a minimal DFA accepting set of strings over {a, b} in which every 'a' is followed by a 'b'. Explanation: The desired language will be like: L1 = {Îĩ,
6 min read
Designing Non-Deterministic Finite Automata (Set 1)
Prerequisite: Finite Automata Introduction In this article, we will see some designing of Non-Deterministic Finite Automata (NFA). Problem-1: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language starts with 'a'. Explanation: The desired language will be like: L1 = {ab, abba, abaa, ...........} He
6 min read
Article Tags :
three90RightbarBannerImg