1

Noob here with simple question. I'm building a DFA for a homework problem. I have to make a DFA where the binary representation of a number is divisble by N.

As a sample input of 5, I'm not sure if I need to use 101 or 00000101? Because that changes the state diagram based on which base I use.

mdo123
  • 43
  • That is really a question for your teacher. And an important one. – copper.hat Sep 26 '19 at 17:45
  • It is not clear what you are trying to do with the DFA. Do you mean to recognise a number that is divisible by $N$? Presumable the repeating sequence $2^n \mod N$ is relevant here. – copper.hat Sep 26 '19 at 17:52
  • yes for some language {0,1}* w is the binary representation of a number that is divisible by N (n in this case is 5). I assume since it says binary it's base 2 and thus 101, but I have emailed my professor. Thanks. – mdo123 Sep 26 '19 at 17:54
  • If you assume binary you don't need to know the length of the input. – copper.hat Sep 26 '19 at 17:54
  • yes sorry stupid question I suppose it can be deleted. I just completed my DFA and both 101 and 00000101 are accepted. – mdo123 Sep 26 '19 at 18:00
  • It is not stupid. – copper.hat Sep 26 '19 at 18:01
  • DFA = Discrete Finite Automata ? You should always recall the definition of acronyms. – Jean Marie Sep 26 '19 at 18:24

2 Answers2

0

Here are some suggestions, this is not an answer, but too long for a comment:

Suppose the input is in binary, LSB first. Presumably $N$ is a known, fixed number.

Compute $2^n \text{ mod } N$, this will generate a repeating sequence of length $\le N$, say $a_0,a_1,...,a_p$.

The idea is that we want to compute the number modulo $N$, so we need to know what our current result is and so our state needs to track the current value modulo $N$. It is essentially a counter.

As each bit comes in, it doubles the amount we need to 'advance'. However, since $p$ (from the above sequence) is finite, we can track this easily with another part of the state.

This suggests that a reasonable state is $(i,j)$ where $i \in \{0,...,N-1\}$ is the current number, and $j$ is the index of the $a_j$ above (so $j \in \{0,...,p\}$).

The initial state will be $(0,0)$, and in general, if the current state is $(i,j)$ and the input is $u \in \{0,1\}$, the next state will be $((i+a_j \cdot u ) \text{ mod } N, (j+1) \text{ mod (p+1)} ) $.

The current state will be accepting if it is of the form $(0,*)$.

copper.hat
  • 172,524
0

I am not sure to understand your problem in the case $N = 5$. If I am not wrong, the automaton below accepts exactly the binary representations of a number divisible by $5$, including those leading with an arbitrary number of zeros, like $101, 0101, 00101, 000101$, etc.

$\hskip 100pt$

J.-E. Pin
  • 40,163