I am trying to solve a question about NFA. The instructions are as following: Alphabet {a, b, c}. • L1 is all strings that their last character is the same as their fifth-last character. For instance, the string aaacbacbca should be accepted, because the fifth-last character and the last character are both a. The string ccaab should be rejected because the fifth-last character is c and the last character is b. Here is with what I came up, but I am really beginner in this topic and I am not sure whether is correct or not:
The automata you have at the moment accepts only the strings that end with acbca
. Here are steps to arrive to the solution:
a
b
, c
You were almost right, but the automata you drew was only to accept strings ending in acbca
. This one will accept the strings you want
a,b,c a a,b,c a,b,c a,b,c a a,b,c
,--->[q0]--->[q1]--->[q2]--->[q3]--->[q4]--->{q5}----+>[q16]-----.
| /| b a,b,c a,b,c a,b,c b a,b,c| ^ a,b,c |
`---´ +----->[q6]--->[q7]--->[q8]--->[q9]--->{q10}---+ `-------´
| c a,b,c a,b,c a,b,c c a,b,c|
`----->[q11]-->[q12]-->[q13]-->[q14]-->{q15}---´
States like {q5}
are accepting states, while states like [q0]
are not accepting. The meaning of q16
is to make sure that strings that have two equal letters distant 4 characters but not ending there, sink to a non accepting state. Same might be for letters b,c
in state [q4]
, for letters a,c
in state [q9]
, and for letters a,b
in state [q14]
, but for clarity of the drawing, I have omitted them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.