QuestionQuestion

Write a program that (1) accepts an input set of strings on lower case English letters and create a Non-deterministic Finite State Automaton (NFSA) for accepting only that set, and (2) creates an equivalent Deterministic Finite State Automaton (DFSA) corresponding to the NFSA using the subset construction algorithm.

Sample input:
be bear care

Sample output of phase 1 – NFSA:
(1) number of states: 11
(2) final states: 2, 6, 10
(3) alphabet: a b c d e f g h i j k l m n o p q r s t u v w x y z
(4) transitions:
0 b 1 3
0 c 7
1 e 2
3 e 4
4 a 5
5 r 6
7 a 8
8 r 9
9 e 10

Sample output of phase 2 – The equivalent DFSA:
(1) number of states: 9
state 0: {0}
state 1: {1 3}
state 2: {7}
state 3: {2 4}
state 4: {8}
state 5: {5}
state 6: {9}
state 7: {6}
state 8: {10}
(2) final states: 3, 7, 8
(3) transitions:
state 0: b 1, c 2
state 1: e 3
state 2: a 4
state 3: a 5

state 4: r 6
state 5: r 7
state 6: e 8
state 7: none
state 8: none
(4) test strings:
care Accept
b Reject
be Accept
bea Reject
bears Reject
bear Accept
cars Reject
car Reject
c Reject
beare Reject

Test your program with the following three languages and corresponding test strings.

(1) A language contains {be, bear, care}. Test strings: care, b, be, bea, bears, bear, cars, car, c, beare.

(2) A language contains {program, procedure, proceed}. Test strings: ε, prog, program, procram, procedures, proceed, procee, procedure, procedurr, noprocedure.

(3) A language contains {do, double, throw, throws, int, interface, final, finally}. Test strings: finall, inter, throws, does, do, int, final, throwthrows, interface, int_double.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class Program {
    /**
    * Part1: Buidling NFSA, coverting it to DFSA and displaying its details
    */
    public void part1(){

       String[] inputs = {"be", "bear", "care"};
       String[] testStr = {"care", "b", "be", "bea", "bears", "bear", "cars", "car", "c", "beare"};
       NFSADFSA nfsa = new NFSADFSA();
       for(String str: inputs){
            nfsa.addString(str);
       }

       nfsa.display();
       nfsa.toDFSA();
       System.out.println("Sample output of phase 2 – The equivalent DFSA:");
       nfsa.displayDFAS();
       System.out.println("(4) test strings:");
       for(String str: testStr){
            System.out.printf("%-20s%-10s\n", str, nfsa.test(str));
       }
    }

    /**
    * Part 2: Buidling NFSA, coverting it to DFSA and displaying its details
    */
    public void part2(){
       String[] inputs = {"program", "procedure", "proceed"};
       String[] testStr = {"", "prog", "program",
                "procram", "procedures", "proceed", "procee", "procedure", "procedurr", "noprocedure"};
       NFSADFSA nfsa = new NFSADFSA();
       for(String str: inputs){
            nfsa.addString(str);
       }
       nfsa.display();
       nfsa.toDFSA();
       System.out.println("Sample output of phase 2 – The equivalent DFSA:");
       nfsa.displayDFAS();...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$40.00 $20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats