L = for every prefix s' of s, $mid n_0(s')-n_1(s') mid leq 2 $ is regular?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Given language:
L = sâÂÂ(0+1)* is regular?
My Try:
Somewhere it explained as:
here we need just 6 states to recognize L.
#0 - #1 = 0
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = -1
#0 - #1 = -2
If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible because of the words "for every prefix s' of s" in L and that is what makes this language regular.
Can you explain please, how we count number of $0's$ and $1's$ in strings of the language?
AFAIK : I think, we need for two variables for that, I got confusion. would you include NFA/DFA for language ?
discrete-mathematics formal-languages automata regular-language regular-expressions
add a comment |Â
up vote
1
down vote
favorite
Given language:
L = sâÂÂ(0+1)* is regular?
My Try:
Somewhere it explained as:
here we need just 6 states to recognize L.
#0 - #1 = 0
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = -1
#0 - #1 = -2
If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible because of the words "for every prefix s' of s" in L and that is what makes this language regular.
Can you explain please, how we count number of $0's$ and $1's$ in strings of the language?
AFAIK : I think, we need for two variables for that, I got confusion. would you include NFA/DFA for language ?
discrete-mathematics formal-languages automata regular-language regular-expressions
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Given language:
L = sâÂÂ(0+1)* is regular?
My Try:
Somewhere it explained as:
here we need just 6 states to recognize L.
#0 - #1 = 0
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = -1
#0 - #1 = -2
If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible because of the words "for every prefix s' of s" in L and that is what makes this language regular.
Can you explain please, how we count number of $0's$ and $1's$ in strings of the language?
AFAIK : I think, we need for two variables for that, I got confusion. would you include NFA/DFA for language ?
discrete-mathematics formal-languages automata regular-language regular-expressions
Given language:
L = sâÂÂ(0+1)* is regular?
My Try:
Somewhere it explained as:
here we need just 6 states to recognize L.
#0 - #1 = 0
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = -1
#0 - #1 = -2
If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible because of the words "for every prefix s' of s" in L and that is what makes this language regular.
Can you explain please, how we count number of $0's$ and $1's$ in strings of the language?
AFAIK : I think, we need for two variables for that, I got confusion. would you include NFA/DFA for language ?
discrete-mathematics formal-languages automata regular-language regular-expressions
discrete-mathematics formal-languages automata regular-language regular-expressions
edited Sep 4 at 11:12
asked Nov 22 '15 at 11:16
Mithlesh Upadhyay
2,83182556
2,83182556
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
We donâÂÂt actually count the $0$s and $1$s: we just keep track of the difference. The difference $n_0(s')-n_1(s')$ increases by $1$ every time we read a $0$ and decreases by $1$ every time we read a $1$. If the difference is always in the set $-2,-1,0,1,2$, we want to accept the string, and if it ever goes outside that set, we want to reject the string, so we need only six states: one for each value of the difference that is in that set, and one for being outside the set.
Let $q_0$ be the initial state. WeâÂÂll design the DFA so that itâÂÂs in state $q_0$ whenever it has read the same number of $0$s and $1$s. There will also be the following states:
- $q_1$; the machine will be in this state when the number of $0$s read is one more than the number of $1$s;
- $q_2$; the machine will be in this state when the number of $0$s read is two more than the number of $1$s;
- $q_-1$; the machine will be in this state when the number of $0$s read is one less than the number of $1$s;
- $q_-2$; the machine will be in this state when the number of $0$s read is two less than the number of $1$s; and
- $q_infty$; the machine will be in this state when the numbers of $0$s and $1$s read so far differ by more than $2$.
The meanings assigned to the states tell you what most of the transitions must be. For instance, in state $q_0$ reading a $0$ must put the machine in state $q_1$, while reading a $1$ must put it in state $q_-1$. State $q_infty$ is a garbage (or trap) state that collects the words that are not to be accepted. The full set of transitions is:
$$beginarrayll
q_0overset0longrightarrow q_1&q_0overset1longrightarrow q_-1\
q_1overset0longrightarrow q_2&q_1overset1longrightarrow q_0\
q_2overset0longrightarrow q_infty&q_2overset1longrightarrow q_1\
q_-1overset0longrightarrow q_0&q_-1overset1longrightarrow q_-2\
q_-2overset0longrightarrow q_-1&q_-2overset1longrightarrow q_infty\
q_inftyoverset0,1longrightarrow q_infty
endarray$$
States $q_0,q_1,q_2,q_-1$, and $q_-2$ are all acceptor states; $q_infty$ is not.
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
We donâÂÂt actually count the $0$s and $1$s: we just keep track of the difference. The difference $n_0(s')-n_1(s')$ increases by $1$ every time we read a $0$ and decreases by $1$ every time we read a $1$. If the difference is always in the set $-2,-1,0,1,2$, we want to accept the string, and if it ever goes outside that set, we want to reject the string, so we need only six states: one for each value of the difference that is in that set, and one for being outside the set.
Let $q_0$ be the initial state. WeâÂÂll design the DFA so that itâÂÂs in state $q_0$ whenever it has read the same number of $0$s and $1$s. There will also be the following states:
- $q_1$; the machine will be in this state when the number of $0$s read is one more than the number of $1$s;
- $q_2$; the machine will be in this state when the number of $0$s read is two more than the number of $1$s;
- $q_-1$; the machine will be in this state when the number of $0$s read is one less than the number of $1$s;
- $q_-2$; the machine will be in this state when the number of $0$s read is two less than the number of $1$s; and
- $q_infty$; the machine will be in this state when the numbers of $0$s and $1$s read so far differ by more than $2$.
The meanings assigned to the states tell you what most of the transitions must be. For instance, in state $q_0$ reading a $0$ must put the machine in state $q_1$, while reading a $1$ must put it in state $q_-1$. State $q_infty$ is a garbage (or trap) state that collects the words that are not to be accepted. The full set of transitions is:
$$beginarrayll
q_0overset0longrightarrow q_1&q_0overset1longrightarrow q_-1\
q_1overset0longrightarrow q_2&q_1overset1longrightarrow q_0\
q_2overset0longrightarrow q_infty&q_2overset1longrightarrow q_1\
q_-1overset0longrightarrow q_0&q_-1overset1longrightarrow q_-2\
q_-2overset0longrightarrow q_-1&q_-2overset1longrightarrow q_infty\
q_inftyoverset0,1longrightarrow q_infty
endarray$$
States $q_0,q_1,q_2,q_-1$, and $q_-2$ are all acceptor states; $q_infty$ is not.
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
add a comment |Â
up vote
1
down vote
accepted
We donâÂÂt actually count the $0$s and $1$s: we just keep track of the difference. The difference $n_0(s')-n_1(s')$ increases by $1$ every time we read a $0$ and decreases by $1$ every time we read a $1$. If the difference is always in the set $-2,-1,0,1,2$, we want to accept the string, and if it ever goes outside that set, we want to reject the string, so we need only six states: one for each value of the difference that is in that set, and one for being outside the set.
Let $q_0$ be the initial state. WeâÂÂll design the DFA so that itâÂÂs in state $q_0$ whenever it has read the same number of $0$s and $1$s. There will also be the following states:
- $q_1$; the machine will be in this state when the number of $0$s read is one more than the number of $1$s;
- $q_2$; the machine will be in this state when the number of $0$s read is two more than the number of $1$s;
- $q_-1$; the machine will be in this state when the number of $0$s read is one less than the number of $1$s;
- $q_-2$; the machine will be in this state when the number of $0$s read is two less than the number of $1$s; and
- $q_infty$; the machine will be in this state when the numbers of $0$s and $1$s read so far differ by more than $2$.
The meanings assigned to the states tell you what most of the transitions must be. For instance, in state $q_0$ reading a $0$ must put the machine in state $q_1$, while reading a $1$ must put it in state $q_-1$. State $q_infty$ is a garbage (or trap) state that collects the words that are not to be accepted. The full set of transitions is:
$$beginarrayll
q_0overset0longrightarrow q_1&q_0overset1longrightarrow q_-1\
q_1overset0longrightarrow q_2&q_1overset1longrightarrow q_0\
q_2overset0longrightarrow q_infty&q_2overset1longrightarrow q_1\
q_-1overset0longrightarrow q_0&q_-1overset1longrightarrow q_-2\
q_-2overset0longrightarrow q_-1&q_-2overset1longrightarrow q_infty\
q_inftyoverset0,1longrightarrow q_infty
endarray$$
States $q_0,q_1,q_2,q_-1$, and $q_-2$ are all acceptor states; $q_infty$ is not.
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
We donâÂÂt actually count the $0$s and $1$s: we just keep track of the difference. The difference $n_0(s')-n_1(s')$ increases by $1$ every time we read a $0$ and decreases by $1$ every time we read a $1$. If the difference is always in the set $-2,-1,0,1,2$, we want to accept the string, and if it ever goes outside that set, we want to reject the string, so we need only six states: one for each value of the difference that is in that set, and one for being outside the set.
Let $q_0$ be the initial state. WeâÂÂll design the DFA so that itâÂÂs in state $q_0$ whenever it has read the same number of $0$s and $1$s. There will also be the following states:
- $q_1$; the machine will be in this state when the number of $0$s read is one more than the number of $1$s;
- $q_2$; the machine will be in this state when the number of $0$s read is two more than the number of $1$s;
- $q_-1$; the machine will be in this state when the number of $0$s read is one less than the number of $1$s;
- $q_-2$; the machine will be in this state when the number of $0$s read is two less than the number of $1$s; and
- $q_infty$; the machine will be in this state when the numbers of $0$s and $1$s read so far differ by more than $2$.
The meanings assigned to the states tell you what most of the transitions must be. For instance, in state $q_0$ reading a $0$ must put the machine in state $q_1$, while reading a $1$ must put it in state $q_-1$. State $q_infty$ is a garbage (or trap) state that collects the words that are not to be accepted. The full set of transitions is:
$$beginarrayll
q_0overset0longrightarrow q_1&q_0overset1longrightarrow q_-1\
q_1overset0longrightarrow q_2&q_1overset1longrightarrow q_0\
q_2overset0longrightarrow q_infty&q_2overset1longrightarrow q_1\
q_-1overset0longrightarrow q_0&q_-1overset1longrightarrow q_-2\
q_-2overset0longrightarrow q_-1&q_-2overset1longrightarrow q_infty\
q_inftyoverset0,1longrightarrow q_infty
endarray$$
States $q_0,q_1,q_2,q_-1$, and $q_-2$ are all acceptor states; $q_infty$ is not.
We donâÂÂt actually count the $0$s and $1$s: we just keep track of the difference. The difference $n_0(s')-n_1(s')$ increases by $1$ every time we read a $0$ and decreases by $1$ every time we read a $1$. If the difference is always in the set $-2,-1,0,1,2$, we want to accept the string, and if it ever goes outside that set, we want to reject the string, so we need only six states: one for each value of the difference that is in that set, and one for being outside the set.
Let $q_0$ be the initial state. WeâÂÂll design the DFA so that itâÂÂs in state $q_0$ whenever it has read the same number of $0$s and $1$s. There will also be the following states:
- $q_1$; the machine will be in this state when the number of $0$s read is one more than the number of $1$s;
- $q_2$; the machine will be in this state when the number of $0$s read is two more than the number of $1$s;
- $q_-1$; the machine will be in this state when the number of $0$s read is one less than the number of $1$s;
- $q_-2$; the machine will be in this state when the number of $0$s read is two less than the number of $1$s; and
- $q_infty$; the machine will be in this state when the numbers of $0$s and $1$s read so far differ by more than $2$.
The meanings assigned to the states tell you what most of the transitions must be. For instance, in state $q_0$ reading a $0$ must put the machine in state $q_1$, while reading a $1$ must put it in state $q_-1$. State $q_infty$ is a garbage (or trap) state that collects the words that are not to be accepted. The full set of transitions is:
$$beginarrayll
q_0overset0longrightarrow q_1&q_0overset1longrightarrow q_-1\
q_1overset0longrightarrow q_2&q_1overset1longrightarrow q_0\
q_2overset0longrightarrow q_infty&q_2overset1longrightarrow q_1\
q_-1overset0longrightarrow q_0&q_-1overset1longrightarrow q_-2\
q_-2overset0longrightarrow q_-1&q_-2overset1longrightarrow q_infty\
q_inftyoverset0,1longrightarrow q_infty
endarray$$
States $q_0,q_1,q_2,q_-1$, and $q_-2$ are all acceptor states; $q_infty$ is not.
answered Nov 22 '15 at 23:48
Brian M. Scott
449k39497885
449k39497885
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
add a comment |Â
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
Thanks for nice explanation.
â Mithlesh Upadhyay
Nov 23 '15 at 13:24
1
1
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
@Mithlesh: You're welcome.
â Brian M. Scott
Nov 23 '15 at 16:18
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1540903%2fl-s%25e2%2588%258801-for-every-prefix-s-of-s-mid-n-0s-n-1s-mid-leq-2%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password