write a regular expression expression for the set of strings over alphabet {a,b,c) containing at least one a and at least one b [closed] - theory

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
write a regular expression expression for the set of strings over alphabet {a,b,c) containing at least one a and at least one b
How can I answer this question?

E*(aE*b)|(bE*a)E*
E is sigma, so any character in the alphabet

I don't have enough points to comment on joeya17's answer, but I don't see how that Regex would accept the string "abc" or "cba".
I came up with this Regex initially:
( a+b+c* U a+c*b+ U b+a+c* U b+c*a+ U c*+a+b+ U c*b+a+ )+
which I think should work, but seeing joeya17's answer, I think you could do it like this as well:
E = any letter in Sigma
(E*a+E*b+|a+E*b+E*|b+E*a+E*|E*b+E*a+)+

For the regular expression there are various possibilities:-
Now,
exactly one a and one b (where a comes before b) - c* a c* b c*
exactly one a and one b (where b comes before a) - c* b c* a c*
We take this idea to the answer for more than one a and b:-
a comes before b
(c* a a* c* b b* c*) ;
b comes before a
(c* b b* c* a a* c*)
or there are intermmediate occurances of a and b :-
Let RE R=(a+b+c)*
this is all possible occurences of a,b,c in all orders ;
Hence when a comes before b;
(R* a R* b R*);
when b comes before a;
(R* b R* a B*)
we take the union to get the final answer ( R* a R* b R* + R* b R* a R*) where R = (a + b + c)*

Related

How can we transform written number to number in C? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
For example the input is three hundred and twenty six and the output is 326.
I have already tried to write all word of specific numbers like one,two,hundred,... in an array and the same for the integers . So they will have the same index like
word[0] is "one" and integer[0] is 1
But after that nothing works .
I really recommend starting with constructing a grammar. Here is an idea on how it can be done:
T :== t | td | d | x
H :== dh | dh&T
d - digit
x - ten, eleven or twelve
t - twenty - ninety
h - hundred
& - and
T - 1-99
H - 1-999
Note that this may be slightly incorrect because English is not my native language. But it shows how to construct a grammar.
So 326 could then be constructed by H -> dh&T -> dh&td
An expanded grammar to include thousands could look like this:
A :== Ha | HaH
a - thousand
312108 could be constructed with A -> HaH -> dh&Tadh&T -> dh&xadh&d

Find the regular expressions of the following?Language of odd length and cannot contain length multiple of 3 over 𝚺={𝒂,𝒃} [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Language of odd length and cannot contain length multiple of 3 over
𝚺={𝒂,𝒃}
OK to have an odd length that's not a multiple of 3, we can have a "head" part that generates strings of length 6n, and then a "tail" part that generates strings of length 1 and 5 (but not 7). Any odd number that's not a multiple of 3 can be written as 6n + 1 or 6n + 5 for n >= 0. So, let's get crackin.
r = ((a + b)^6)*((a + b) + (a + b)^5)
I have used a shorthand notation here which you can omit; basically, s ^ n stands for the regular expression s repeated n times. As long as n is a definite number this can be written out, just makes the regular expression a little longer.

Computation theory - DFA [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
i want to design a DFA of an alphabet {x,y,z} which accepts words with a number of 'z' multiples of 3 (eg "xzyyxzzyy")
Does anybody knows how? or which is the language that accepts it?
You will need three states to keep track of the number of z's seen, modulo three; the states will cycle through each other on input z, and the one for #z(w) = 0 (mod 3) will be the only accepting state.
To allow any arbitrary x's and y's, each state can loop to itself on these inputs.
You might use q0, q1 and q2 for the states, making q0 the initial state and only accepting state. Then, you have three transitions f(qi, z) = wh where j = i + 1 (mod 3), three transitions f(q, x) = q and three transitions f(q, y) = q for a total of nine transitions.

Show that the language is decidable

How do I show this language
{<C,A,B> | C,A,B are DFAs, L(C) contains the shuffle of L(A) and L(B)}
is decidable ?
I believe if I can construct automatas for A and B, then I can get an automata that contains the shuffle of them.
I am also thinking about using emptiness testing but I have not made any progress yet.
Given DFAs A and B, construct a DFA D such that L(D) is equal to the shuffle of L(A) and L(B).
Then, construct two DFAs using the Cartesian Product Machine construction for the languages L(M1) = L(C) \ L(D) and L(M2) = L(D) \ L(C).
Determine which, if either of L(M1) and/or L(M2) is empty.
if L(M1) is empty and L(M2) is empty, L(C) is the shuffle of L(A) and L(B)
if L(M1) is empty, L(C) is a subset of the shuffle of L(A) and L(B)
if L(M2) is empty, L(C) is a superset of the shuffle of L(A) and L(B)
To do #1: create a new DFA whose states are triples (x, y, z) where:
x is a state from A
y is a state from B
z is either 1 or 2
The initial state of the DFA will be (qi_A, qi_B, 1). The input alphabet will be the union of the input alphabets of A and B. The transitions will be such that:
f((x,y,1), a) = (x',y,2) where f(x,a) = x' in machine A
f((x,y,2), b) = (x,y',1) where f(y,b) = y' in machine B
The accepting states shall be the states with are accepting in either A or B (or just B if you prefer).
To do #2: create a new DFA whose states are pairs (x, y) where:
x is a state from D
y is a state from C
The initial state of he DFA will be (qi_D, qi_C). The input alphabet will be the union of input alphabets of A and C. The transitions will be such that:
f((x,y),c) = (x',y') where f(x,c) = x' in D and f(y,c) = y' in C.
The accepting states will be:
states that are accepting in D but not C, for L(D) \ L(C)
states that are accepting in C but not D, for L(C) \ L(D)
To do #3:
You can minimize the DFAs using the well-known DFA minimization algorithm. Iff you end up with a DFA that has a single non-accepting state, the language is empty.
You can try all input strings up to the pumping length for the resulting DFA (strings that don't cause the DFA to enter any state more than once). If none of these are accepted by the DFA, then the DFA accepts no strings and the language is empty.

Find number of k-permutation with ordering but no repetition [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Im truggling to find a closed form for the number of k-permutations of a set S of cardinality n.
The combinations should regard ordering, but no repitions.
Example:
|S| = n = 3
S = {a,b,c}
k = 2
{a,b}
{b,a}
{b,c}
{c,b}
{a,c}
{c,a}
Anyone could help me out how to compute the number of viable permutations (and not the permutations itself)?
What I've tried:
I've read through different material and found out, that including repitititions it is
O(n) = n^k
My initial though was, that I need to eliminiate the permutations like
{a,a}
{b,b}
{c,c}
But I struggle finding a closed form for the number of perceivable repititions.
You are looking for the number of k-permutations of a set S of cardinality n.
The formulae is well known : n!/(n-k)!
Pseudo-proof :
for the 1st element, you are able to choose among the n elements of S ;
for the 2nd, only among : n-1, because you don't want doublons ;
...
for the ith, only among : n-(i-1) ;
...
for the kth, only among : n-(k-1) ;
So, finally :
n * (n-1) * ... * (n-i) * ... * (n-k+1)
= n! / (n-k)!

Resources