Toc Project
Toc Project
Toc Project
Submitted By
Vivek Kumar (2100430100059)
Shrawan Kumar (2100430100050)
Nikhil Kumar (2100430100033)
Abhinav Sharma(2200430109001)
1
ACKNOWLEDGEMENT
We are indebted to our respected Head of the Department Dr. Yashpal Singh for
guiding us. The team is also grateful to our project guide Prof. Shashank Gupta, for their
invaluable guidance for this project. We also thank our respected faculty members,
Dr. R.N. Verma, Dr. Sanjay Kumar Gupta of the Computer Science and Engineering
department for their indomitable contribution and guidance without which this project
would have been impossible to complete.
Our sincerest thanks to all the teachers, seniors and colleagues whose help and
guidance brought this project to successful completion.
Submitted by:
2
ABSTRACTION
This project based upon the subject of “Theory of Automata and Formal Languages”. In
this project, We make the program of convert NFA to DFA. The code written in C++
3
LIST OF FIGURES
S.NO. TABLE
1. Introduction
2. Source Code
3. Reference
4
Introduction
6
5. Accept states: Any DFA state that contains at least one NFA accept state
will also be an accept state in the DFA.
6. Repeat: Repeat steps 4 and 5 until no new states can be added to the DFA.
7. Minimization (optional): After converting the NFA to a DFA, you may
apply a state minimization algorithm to eliminate any redundant states and
optimize the DFA.
The result is an equivalent DFA that recognizes the same language as the original
NFA. The conversion process can be implemented algorithmically, and various
programming languages can be used to perform the conversion. Note that in some
cases, the DFA may have more states than the original NFA due to the subset
construction process.
7
CODE:
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
while (!stateQueue.empty()) {
int currentState = stateQueue.front();
stateQueue.pop();
return closure;
}
return nextStateSet;
}
dfaStates.push_back(epsilonClosure(nfaStartState, nfaTransitions));
stateIndices[dfaStates[0]] = 0;
dfaStartState = dfaStates[0];
stateQueue.push(dfaStates[0]);
while (!stateQueue.empty()) {
StateSet currentStateSet = stateQueue.front();
stateQueue.pop();
if (!epsilonClosureSet.empty()) {
if (stateIndices.find(epsilonClosureSet) == stateIndices.end()) {
int newStateIndex = dfaStates.size();
dfaStates.push_back(epsilonClosureSet);
stateIndices[epsilonClosureSet] = newStateIndex;
stateQueue.push(epsilonClosureSet);
}
9
dfaTransitions[{currentStateSet, symbol}] = epsilonClosureSet;
}
}
}
int main() {
// Example NFA
vector<StateSet> nfaStates = {{0}, {1}, {2}, {3}};
TransitionMap nfaTransitions = {
{{0, '0'}, {0}},
{{0, '1'}, {0}},
{{0, 'e'}, {1}},
{{1, '0'}, {1}},
{{1, '1'}, {1}},
{{1, 'e'}, {2}},
{{2, '0'}, {2}},
{{2, '1'}, {2}},
{{2, 'e'}, {3}},
{{3, '0'}, {3}},
{{3, '1'}, {3}}
};
StateSet nfaStartState = {0};
set<int> nfaAcceptStates = {3};
set<char> alphabet = {'0', '1'};
return 0;
}
12
Reference:
https://www.geeksforgeeks.org/
https://www.tutorialspoint.com/index.htm
13