Is a language that accepts n(n-1)(n-2)/6+n(n-1)/2+1 many numbers of {0,1}^n for every n is a regular language?
I have a question to draw the dfa of those language, but I'm not even sure whether it is a regular one.
This sounds like homework, and I'm guessing the question is: draw a DFA that accepts exactly n(n-1)(n-2)/6+n(n-1)/2+1 words of length n (over the alphabet {0,1}). Lets construct the automaton as an intersection of two DFAs.
The first automaton accepts words of length n. This is very easy - there is a chain of n+1 states. The first state is the initial state, only the last state is accepting, and every state has a transition labeled 0,1 to the next state in the chain. The accepting state has no outgoing transitions.
The second automaton accepts words in which there is one, two, or three 1s. Also, very easy - we need 4 states: q_0, q_1, q_2, q_sink. The state q_0 is the initial state, the states q_0,q_1,q_2 are accepting, and they have a self loop with 0. There are transitions q_0 --1--> q_1 --1--> q_2 --1--> q_sink. Finally, q_sink is rejecting and it has a self loop with 0,1.
In order to construct the intersection of the automata we need the product of the two automata. This is a general construction which also isn't very hard.
Related
I want to create a DFA for language {1,0} which accepts only words build from sequences of odd 1 and 0.
I've found many examples for DFA with even/odd numbers of 0 and 1 in a string but not in each sequence of that string. I cannot grasp how to create said graph. Should it be build with 4 states or maybe 3?
Just thought about something, is this one correct or am I mistaken here?
Ok, so this one was wrong, but maybe this one?
With this one, however, I fell like you always have to start with either one 1 or one 0 and won't get more in the first sequence so it's not relly perfect...
Kind regards,
Give a deterministic finite automaton accepting those words over the alphabet {0, 1}, where each series of zeros and each series of 1s is of odd length.
Is not 100% unambiguous. I personally understand, that the empty word, and a word consisting solely of 0s or solely of 1s is also part of the language (if it is of odd length). Then something like the following should do the trick.
State 1 is the starting state. The "upper" branch (ie states 2, 3) is for accepting any odd number of 0, the "lower" branch (ie states 4,5) accepts any odd number of 1. You can "enter" the respective branch only by reading a single instance of the respective symbol, either starting from the empty word, or after reading an odd number of the respective other symbol.
For instance the word 1000111110001. After reading a single 1 you are in state 4. By reading a single 0, you switch to the "upper branch" and now can read any even (in this case 2) number of 0, which will always bring you back to the accepting state 2. Reading a 1 in state 3 is not possible (because the word would be invalid). Reading a single 1 in state 2 brings you back to state 4. And from here similar to the above, you can read any even number (in this case 4) of 1 which will always bring you back to the accepting state 4. And so on and so forth. If the symbol changes (or the word ends) after an even number of equal symbols, you are either in state 3 or 5, which are both not accepting, thus the word won't be accepted.
Let L be any regular language and a ∈ Σ. How to show that the language L'={uav | uv ∈ L} is regular too?
Wikipedia says a way to proove it is to lead it back to a regular language but I don't understand how to do that in this case. Hope somebody can help.
There are lots of ways to show this. I think an argument whereby we construct a DFA is particularly easy to visualize.
Imagine a DFA for your language L. Let's call it M. Imagine it sprawled out in diagram form on a table. Now, imagine making a copy of M and spreading it out next to M on the table. Call it M'.
Now - from M, add a new transition from state q of M to the corresponding state q' of M'. The transition is on the symbol a.
Now, consider the aggregate machine whose start state is the start state of M and whose accepting states are the accepting states of M'. This machine starts out accepting strings in L, then accepts an a somewhere in the middle, and then continues accepting strings in L from where it left off. This is the language we were going for and we have defined a perfectly reasonable NFA for it. Since any language accepted by an NFA is regular, our language is regular.
I have seen in several sources (e.g. 1, 2 - page 160), that the complexity of running through an NFA is O(m²n). However I haven't understood why it is so.
My intuition is that the complexity should be O(m^n) (where m is the length of the string, and n is the number of states), because for each letter in the input string, there are n possible states that the NFA can move to them.
Can anyone explain this to me?
Thanks.
Let's think about how we'd do one step of simulating the NFA. We begin in some set of active states Qinit. For each state we're in, we look at all the outgoing transitions labeled with the current symbol, then gather them into a set Qmid. Next, we follow all possible ε-transitions from those states and keep repeating this process until there are no more ε-transitions to follow (that is, we find the ε-closure), giving us our new set of state Qnext. We then repeat this process once per character in the input.
So how much time does this take? Well, there are m characters in the input string, so the runtime is m times whatever work we do on one individual character. Each state can have at most n transitions leaving it on each character, so the time to iterate over all the characters in Qinit to find the set Qmid is O(n2): there are O(n) states in Qinit and we only need to scan O(n) transitions per state. From there, we have to keep following ε-transitions until we run out of transitions to follow. We can do that by doing a BFS or DFS starting simultaneously from each state in Qmin and only following ε-transitions. The NFA can have at most O(n2) ε-transitions total (one between each pair of states), so the BFS or DFS will run in time O(n2). Overall we're doing O(n2) work per character, so the total work done is O(mn2).
For example I have several states I will name A, B and C.
A allows 1,0 and loops. When it enters state B, is it possible that everything will be empty again before going to C? If yes, how?
In general finite automata is like decision making type.It can tell whether the given string is recognized by the automata or not.The major draw back of finite automata is that it can't recognize the previously given input.so to enhance it we are going for push down automata(pda).In pda we have stack to store the input symbols.There also we can push or pop only one element at a time.If you want to pop all elements when it enters state B then use a loop to pop all elements of the stack until stack becomes empty
Which is the best or easiest method for determining equivalence between two automata?
I.e., if given two finite automata A and B, how can I determine whether both recognize the same language?
They are both deterministic or both nondeterministic.
A different, simpler approach is to complement and intersect the automata. An automaton A is equivalent to B iff L(A) is contained in L(B) and vice versa which is iff the intersection between the complement of L(B) and L(A) is empty and vice versa.
Here is the algorithm for checking if L(A) is contained in L(B):
Complementation: First, determinize B using the subset construction. Then, make every accepting state rejecting and every rejecting state accepting. You get an automaton that recognizes the complement of L(B).
Intersection: Construct an automaton that recognizes the language that is the intersection of the complement of L(B) and L(A). I.e., construct an automaton for the intersection of the automaton from step 1 and A. To intersect two automata U and V you construct an automaton with the states U x V. The automaton moves from state (u,v) to (u',v') with letter a iff there are transitions u --a--> u' in U and v --a--> v' in V. The accepting states are states (u,v) where u is accepting in U and v is accepting in V.
After constructing the automaton in step 2, all that is needed is to check emptiness. I.e., is there a word that the automaton accepts. That's the easiest part -- find a path in the automaton from the initial state to an accepting state using the BFS algorithm.
If L(A) is contained in L(B) we need to run the same algorithm to check if L(B) is contained in L(A).
Two nondeterministic finite automota (NFA's) are equivalent if they accept the same language.
To determine whether they accept the same language, we look at the fact that every NFA has a minimal DFA, where no two states are identical. A minimal DFA is also unique. Thus, given two NFA's, if you find that their corresponding minimal DFA's are equivalent, then the two NFA's must also be equivalent.
For an in-depth study on this topic, I highly recommend that you read An Introduction to Formal Language and Automata.
I am just rephrasing answer by #Guy.
To compare languages accepted by both we have to figure out if L(A) is equal to L(B) or not.
Thus, you have to find out if L(A)-L(B) and L(B)-L(A) is null set or not. (Reason1)
Part1:
To find this out, we construct NFA X from NFA A and NFA B, .
If X is empty set then L(A) = L(B) else L(A) != L(B). (Reason2)
Part2:
Now, we have to find out an efficient way of proving or disproving X is empty set. When will be X empty as DFA or NFA? Answer: X will be empty when there is no path leading from starting state to any of the final state of X. We can use BFS or DFS for this.
Reason1: If both are null set then L(A) = L(B).
Reason2: We can prove that set of regular languages is closed under intersection and union. Thus we will able to create NFA X efficiently.
and for sets: