This program checks if a given deterministic finite automaton (DFA) has a synchronizing word, and if so, it outputs the shortest such word. A synchronizing word is a sequence of input symbols that, when applied to any state of the DFA, leads to a specific state. If the DFA is not synchronizing, the program outputs the string "automaton isn't synchronizing"
. The program uses the fact that shortest synchronizing word of a DFA is determined by the shortest path in that DFA's power automaton.
The input file must describe a valid DFA and follow this format:
- First Line: An integer
n
representing the number of states in the DFA. - Second Line: A string of
k
symbols representing the alphabet, with all symbols listed consecutively without spaces. - Third Line: A description of the transition function in the following format:
[list0, list1, ... listn-1]
, where eachlisti
is ak
-element list of tuples(c, m)
.c
is aChar
representing a symbol from the alphabet, andm
is an integer representing the target state (0 ton-1
).- This means that the transition function sends state
i
to statem
using symbolc
(i.e.,transitionFunction(i, c) = m
).
3 ab [[('a', 1), ('b',1)], [('a', 1), ('b', 2)], [('a', 0), ('b', 1)]]
- The DFA has 3 states (
0
,1
,2
). - The alphabet consists of two symbols:
a
andb
. - The transition function is defined as:
- From state
0
:a
leads to1
,b
leads to1
- From state
1
:a
leads to1
,b
leads to2
- From state
2
:a
leads to0
,b
leads to1
- From state
- If the DFA has a synchronizing word, the program prints the shortest synchronizing word.
- If the DFA does not have a synchronizing word, the program prints
"automaton isn't synchronizing"
.
- The
main
function and file handling assume that states are numbered from0
ton-1
. However, the functions implemented to find the shortest synchronizing word only require that the type representing states is comparable.