r/AskComputerScience • • Mar 12 '25

Need help with a DFA

I have to form a DFA with the following condition:
A = {a,b,c}
Form a DFA that acceps the language:

  • The set A* −{bab}

I don't know if I am plain stupid or this is challenging but I've been stuck on this problem for quite some time

2 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/xenomachina Mar 12 '25

The DFA is structured like a tree of height 3,

This is a good, general approach for building DFAs that have to handle a finite set of strings differently.

Essentially, you:

  1. Build a trie containing your special cases.
  2. Turn each node of the trie into a state, with the root being the start state, and each connection being a transition. Set which states are accepting as appropriate.
  3. If the default case is to accept (rather than reject), add an additional "accept and loop" state, with "else" transitions from all other states.
  4. Optionally optimize afterwards.