0% found this document useful (0 votes)
8 views

Experiments

This document outlines the procedure for converting a Non-deterministic Finite Automaton (NFA) to a Deterministic Finite Automaton (DFA). It includes steps for inputting NFA details, computing epsilon-closures, and generating the DFA transition table, along with a C program that implements this process. The program features functions for printing the transition table and calculating closures based on user input for states and transitions.

Uploaded by

Tharanikkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Experiments

This document outlines the procedure for converting a Non-deterministic Finite Automaton (NFA) to a Deterministic Finite Automaton (DFA). It includes steps for inputting NFA details, computing epsilon-closures, and generating the DFA transition table, along with a C program that implements this process. The program features functions for printing the transition table and calculating closures based on user input for states and transitions.

Uploaded by

Tharanikkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Conversion of NFA to DFA

AIM:
To convert the given NFA to DFA.

PROCEDURE:
Here is the step-by-step procedure for converting an NFA to a DFA:
Step 1: Input NFA Details
1. Take input for the number of states (n) in the NFA.
2. Take input for the number of symbols in the alphabet (alpha).
3. Construct the transition table for the NFA:
4. Epsilon-closure of a state q is the set of all states reachable from q using only epsilon
transitions.
5. Compute the epsilon-closure for each state in the NFA.
6. The initial state of the DFA is the epsilon-closure of the NFA’s start state.
7. Use a queue to process each new state
8. A DFA state is a final state if it contains any NFA final state.
9. Store all DFA states and transitions in a structured format.
10. Print the DFA transition table.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define MAX_STATES 100
#define MAX_ALPHABET 10
void printTransitionTable(int table[MAX_STATES][MAX_ALPHABET +
1][MAX_STATES], int n, int alpha) {
printf(" STATE/INPUT |");
char a = 'a';
for (int i = 0; i < alpha; i++) {
printf(" %c |", a++);
}
printf(" ^ \n\n");
for (int i = 0; i < n; i++) {
printf(" %d ", i);
for (int j = 0; j <= alpha; j++) {
printf(" | ");
for (int k = 0; k < MAX_STATES; k++) {
if (table[i][j][k] != -1) {
printf("%d ", table[i][j][k]);
}
}
}
printf("\n");
}
}
void closure(int s, int table[MAX_STATES][MAX_ALPHABET + 1][MAX_STATES], bool
visited[MAX_STATES], int *closureSet, int *count) {
if (!visited[s]) {
visited[s] = true;
closureSet[(*count)++] = s;
for (int i = 0; table[s][MAX_ALPHABET][i] != -1; i++) {
closure(table[s][MAX_ALPHABET][i], table, visited, closureSet, count);
}
}
}
int main() {
int n, alpha;
printf("************************* NFA to DFA *************************\n\n");
printf("Enter total number of states in NFA: ");
scanf("%d", &n);
printf("Enter number of elements in alphabet: ");
scanf("%d", &alpha);
int table[MAX_STATES][MAX_ALPHABET + 1][MAX_STATES];
memset(table, -1, sizeof(table));
for (int i = 0; i < n; i++) {
printf("For state %d:\n", i);
char a = 'a';
int y, yn;
for (int j = 0; j < alpha; j++) {
printf("Enter no. of output states for input %c: ", a++);
scanf("%d", &yn);
printf("Enter output states: ");
for (int k = 0; k < yn; k++) {
scanf("%d", &y);
table[i][j][k] = y;
}
}
printf("Enter no. of output states for input ^: ");
scanf("%d", &yn);
printf("Enter output states: ");
for (int k = 0; k < yn; k++) {
scanf("%d", &y);
table[i][alpha][k] = y;
}
}
printf("\n***** TRANSITION TABLE OF NFA *****\n");
printTransitionTable(table, n, alpha);
return 0;
}

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy