Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ class dfa for deterministic finite automata. The states are numbered 0,1,... and state 0 is always the start state. All states have

Write a C++ class dfa for deterministic finite automata. The states are numbered 0,1,... and state 0 is always the start state. All states have two transitions for characters 0 and 1. The following member functions must be supported:

  • typedef std::size_t State;
  • typedef std::unordered_set StateSet;
  • constructor dfa(std::size_t n = 1, const StateSet &F = StateSet()): returns a new dfa with n1 states and accepting state set F. All transitions go to state 0.
  • std::size_t size() const: returns the number of states of this dfa;
  • StateSet F() const: returns the accepting state set.
  • State delta(State s, char x) const: returns (s,x)
  • void add_transition(State source, char symbol, State dest): changes transition in state source on input symbol to state dest;
  • State eval(const string & w) const: returns the final state of this dfa after reading input string w starting in state 0;
  • bool accept(const string & w) const: returns true iff this dfa accepts input string w starting in state 0.

Also overload the input and output operators to allow reading and writing dfas. Use the following format for reading/writing dfas:

 n k // number of states and number of accepting states a1 ... ak // accepting states s_1 0 d1 // transitions for each state s_1 1 d2 ... s_n 0 d_{2n+1} s_n 1 d_{2n+2}

We use M to refer to the above description of a dfa M.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Why is executive onboarding for external hires so difficult?

Answered: 1 week ago

Question

1. What is perception?

Answered: 1 week ago