DESKTOP

Algorithms for Compiler Design: EXAMPLES OF FINITE AUTOMATA CONSTRUCTION

7/24/2010 7:58:40 PM
2.7 EXAMPLES OF FINITE AUTOMATA CONSTRUCTION
EXAMPLE 1
Start example

Construct a finite automata accepting the set of all strings of zeros and ones, with at most one pair of consecutive zeros and at most one pair of consecutive ones.

End example

A transition diagram of the finite automata accepting the set of all strings of zeros and ones, with at most one pair of consecutive zeros and at most one pair of consecutive ones is shown in Figure 1.

Click To expand
Figure 1: Transition diagram for Example 1 finite automata.
EXAMPLE 2
Start example

Construct a finite automata that will accept strings of zeros and ones that contain even numbers of zeros and odd numbers of ones.

End example

A transition diagram of the finite automata that accepts the set of all strings of zeros and ones that contains even numbers of zeros and odd numbers of ones is shown in Figure 2.

Click To expand
Figure 2: Finite automata containing even number of zeros and odd number of ones.
EXAMPLE 3
Start example

Construct a finite automata that will accept a string of zeros and ones that contains an odd number of zeros and an even number of ones.

End example

A transition diagram of finite automata accepting the set of all strings of zeros and ones that contains an odd number of zeros and an even number of ones is shown in Figure 3.

Click To expand
Figure 3: Finite automata containing odd number of zeros and even number of ones.
EXAMPLE 4
Start example

Construct the finite automata for accepting strings of zeros and ones that contain equal numbers of zeros and ones, and no prefix of the string should contain two more zeros than ones or two more ones than zeros.

End example

A transition diagram of the finite automata that will accept the set of all strings of zeros and ones, contain equal numbers of zeros and ones, and contain no string prefixes of two more zeros than ones or two more ones than zeros is shown in Figure 4.

Click To expand
Figure 4: Example 4 finite automata considers the set prefix.
EXAMPLE 5
Start example

Construct a finite automata for accepting all possible strings of zeros and ones that do not contain 101 as a substring.

End example

Figure 5 shows a transition diagram of the finite automata that accepts the strings containing 101 as a substring.

Click To expand
Figure 5: Finite automata accepts strings containing the substring 101.

A DFA equivalent to this NFA will be:

0

1

{A}

{A}

{A, B}

{A, B}

{A, C}

{A, B}

{A, C}

{A}

{A, B, D}

{A, B, D}*

{A, C, D}

{A, B, D}

{A, C, D}*

{A, D}

{A, B, D}

{A, C, D}*

{A, D}

{A, B, D}

Let us identify the states of this DFA using the names given below:

{A}

q0

{A, B}

q1

{A, C}

q2

{A, B, D}

q3

{A, C, D}

q4

{A, D}

q5

The transition diagram of this automata is shown in Figure 6.

Click To expand
Figure 6: DFA using the names A-D and q05.

The complement of the automata in Figure 6 is shown in Figure 7.

Click To expand
Figure 7: Complement to Figure 6 automata.

After minimization, we get the DFA shown in Figure 8, because states q3, q4, and q5 are nondistinguishable states. Hence, they get combined, and this combination becomes a dead state and, can be eliminated.

Click To expand
Figure 8: DFA after minimization.
EXAMPLE 6
Start example

Construct a finite automata that will accept those strings of decimal digits that are divisible by three (see Figure 9).

Click To expand
Figure 9: Finite automata that accepts string decimals that are divisible by three.

End example

EXAMPLE 7
Start example

Construct a finite automata that accepts all possible strings of zeros and ones that do not contain 011 as a substring.

End example

Figure 10 shows a transition diagram of the automata that accepts the strings containing 101 as a substring.

Click To expand
Figure 10: Finite automata accepts strings containing 101.

A DFA equivalent to this NFA will be:

0

1

{A}

{A, B}

{A}

{A, B}

{A, B}

{A, C}

{A, C}

{A, B}

{A, D}

{A, D}*

{A, B, D}

{A, D}

{A, B, D}*

{A, B, D}

{A, C, D}

{A, C, D}*

{A, B, D}

{A, D}

Let us identify the states of this DFA using the names given below:

{A}

q0

{A, B}

q1

{A, C}

q2

{A, D}

q3

{A, B, D}

q4

{A, C, D}

q5

The transition diagram of this automata is shown in Figure 11.

Click To expand
Figure 11: Finite automata identified by the name states A-D and q05.

The complement of automata shown in Figure 11 is illustrated in Figure 12.

Click To expand
Figure 12: Complement to Figure 11 automata.

After minimization, we get the DFA shown in Figure 13, because the states q3, q4, and q5 are nondistinguishable states. Hence, they get combined, and this combination becomes a dead state that can be eliminated.

Click To expand
Figure 13: Minimization of nondistinguishable states of Figure 12.
EXAMPLE 8
Start example

Construct a finite automata that will accept those strings of a binary number that are divisible by three.

The transition diagram of this automata is shown in Figure 14.

Click To expand
Figure 14: Automata that accepts binary strings that are divisible by three.

End example


Other  
  •  Algorithms for Compiler Design: REGULAR SETS AND REGULAR EXPRESSIONS
  •  Algorithms for Compiler Design: OBTAINING THE REGULAR EXPRESSION FROM THE FINITE AUTOMATA
  •  Algorithms for Compiler Design: LEXICAL ANALYZER DESIGN
  •  Algorithms for Compiler Design: PROPERTIES OF REGULAR SETS
  •   Algorithms for Compiler Design: EQUIVALENCE OF TWO AUTOMATAS
  •  Algorithms for Compiler Design: CONTEXT-FREE GRAMMAR
  •  Algorithms for Compiler Design: REGULAR GRAMMAR
  •  Algorithms for Compiler Design: RIGHT LINEAR AND LEFT LINEAR GRAMMAR
  •  Algorithms for Compiler Design: Top-down parsing
  •  Algorithms for Compiler Design: Implementation
  •  Algorithms for Compiler Design: THE PREDICTIVE TOP-DOWN PARSER
  •  Algorithms for Compiler Design: A HANDLE OF A RIGHT SENTENTIAL FORM
  •  Algorithms for Compiler Design: IMPLEMENTATION in Bottom-up Parsing
  •  Algorithms for Compiler Design: THE LR PARSER
  •  Algorithms for Compiler Design: DATA STRUCTURES FOR REPRESENTING PARSING TABLES
  •  Algorithms for Compiler Design: WHY LR PARSING IS ATTRACTIVE
  •  Algorithms for Compiler Design: EXAMPLES for Bottom-up Parsing
  •  Combinations and Permutations with F#
  •  Production Diagnostics Improvements in CLR 4
  •  Using the Dynamic Keyword in C# 4.0
  •  
    Video
    Top 10
    Mobile Application Security : The Apple iPhone - Push Notifications, Copy/Paste, and Other IPC
    Exploring the T-SQL Enhancements in SQL Server 2005 : The WAITFOR Command
    Parallel Programming with Microsoft .Net : Parallel Aggregation - Variations
    Optimizing an Exchange Server 2010 Environment : Analyzing Capacity and Performance
    Programming .NET Security : Hashing Algorithms Explained
    Sharepoint 2007: Specify Your Colleagues
    Algorithms for Compiler Design: THE NFA WITH ∈-MOVES
    Choosing The Right Parts For Your Build (Part 1) - Picking the perfect processor
    Choosing The Right Parts For Your Build (Part 5) - Choosing your case & Picking the right storage
    SQL Server 2008 : Leveraging the Microsoft Sync Framework
    Most View
    Legal Trouble with Social Networks (Part 1)
    The choices of mobile computing for SOHO users (part 2)
    Infrastructure Security: The Application Level
    Sharepoint 2007: Create a New List Item
    SQL Azure Data Access
    Getting Started with MySQL Enterprise & MySQL Enterprise Components
    iPhone Application Development : Using Advanced Interface Objects and Views - User Input and Output
    How to Protect Your Mobile Devices
    Joomla! Blogging and RSS Feeds : Commenting anyone?
    The Second BlackBerry Developers Conference Asia (Part 2)
    Windows Azure : Understanding the Blob Service
    Windows Server 2008 : Understanding the Identity Management for UNIX Components
    Migrating from Legacy SharePoint to SharePoint Server 2010 : Using Visual Upgrade
    Designing and Implementing Mobility in Exchange Server 2010 : Securing Access to ActiveSync Using Internet Security and Acceleration (ISA) Server 2006
    SQL Server 2008 : Explaining Advanced Query Techniques - Creating CTEs
    Configuring Server Roles in Windows 2008 : New Roles in 2008
    Mass Effect Infiltrator
    iPhone 3D Programming : Anti-Aliasing Tricks with Offscreen FBOs (part 1) - A Super Simple Sample App for Supersampling
    Changes in Windows Vista Affecting SDI
    Search for a File or Directory