-1

How many DFA's can be constructed given 5 states over the alphabet {0,1}. Given that the initial state is not fixed.

1 Answers1

0

A DFA can have at most one transition for each symbol in the alphabet. So we can enumerate the DFAs by assigning all the valid options for the states.

I will use the following notation, a 5-tuple of 2-tuples with the destination of the transitions for symbols in {0, 1}, for instance.

((None, 4), (4, 3), (1, None), (None, 0), (3, 3))

This gives you an FST that from state 0 it goes to state 4 (symbol 1), from state 4 it can go to state 3 to state (either symbol 0 or 1), and from there back to state 0 (symbol 1). But this is not connected, not using all the 5-states. If you count all the DFAs of this kind the answer is (6^2)^5 = 60466176, because for each symbol can take you to one of 5 states or be missing from a given state (the 6 in the formula), there are two symbols (2 in the formula), and there are 5 states (5 exponent in the formula).

Strictly 5 states

If we want an FST that can be generated with 5 states, and that all the states are reachable then we can generate the above FSTs and filter those thata are connected.

def is_connected(dfa):
    N = len(dfa)
    reached = [False] * N
    nReached = 0
    stack = [0]
    while len(stack):
        s = stack.pop()
        
        if not reached[s]:
            reached[s] = True
            nReached += 1
            if nReached == N:
                return True
            t, u = dfa[s]
            if t is not None:
                stack.append(t)
            if u is not None:
                stack.append(u)
    return False

import itertools
all_dfas = list(itertools.product(
             list(itertools.product([None, 0, 1, 2, 3, 4], 
                   repeat=2)
             ), repeat=5))

num_connected = sum(1 if is_connected(dfa) else 0 for dfa in all_dfas[:])

It gives 15184800.

Isomorphisms

You could try to find the DFAs that are equivalent up to relabeling states, since this does not change the language defined by the DFA, in general we only look to the transitions not the states, but that seems to not be the case since you ask to consider all possible initial states.

Bob
  • 13,867
  • 1
  • 5
  • 27
  • can you explain the part where you found out how many DFA's can be generated please? How did u get 6^2^5? – MR.CODER1111 Feb 10 '21 at 09:35
  • If you read after the formula you have the description, let's use symbols se if it help. s is the set of states ((|s|+1)^|A|)^|s| |s|+1 is the number of destinations for each transition (any state, or absent) |A| is the number of symbols in the alphabet. The exponent |s| is because for each state you can select the destinations independently. – Bob Feb 10 '21 at 12:41
  • We also may need to consider which state is the initial state (a multiplier of `5`) and which states are accepting (a multiplier of `2^5`). – Welbog Feb 10 '21 at 16:31
  • Yes, it makes sense. – Bob Feb 10 '21 at 17:29
  • please check [this](https://stackoverflow.com/tour) – Bob Mar 14 '21 at 10:57