**Regular Expression **can be anything, from a terminal symbol, ∅, to union of two regular expressions (R_{1} + R_{2}), their concatenation (R_{1}R_{2}) or its closure R_{1}* as well.

**Examples of Regular Expression :**

- Regular expression of set of all strings of 0’s and 1’s starting with two zeros :
00(0+1)*

- Regular expression of set of all strings of 0’s and 1’s having even number of 0’s followed by odd numbers of 1’s :
(00)*1(11)*

- Regular expression of set of all strings of 0’s and 1’s containing at least one 0 and at least two 1’s :
00*11(0+1)* + 0111*(0+1)*

Strings that will be acceptable by regular expression with alternate 0’s and 1’s –

- ∈ (no input, 0 and 1)
- 010101….. (string that starts with 0 followed by 1 and so on).
- 101010….. (string that starts with 1 followed by 0 and so on).

Now, a regular expression for set of all strings consisting of alternate 0’s and 1’s would be **(01)***, where it can accept ∈, 01, 0101, 010101…..etc but this restricts the string as it can always begin with 0 only.

Again, the expression **(10)*** will accept ∈, 10, 1010, 101010….etc but this too restricts string as it can always begin with 1 only.

So, we introduce** 1(01)*** and **0(10)*** to meet gap in respective cases.

While 1(01)* breaks the restriction of string starting with 0, 0(10)* breaks same for string starting with 1.

So, the final expression is –

(01)* + (10)* + 0(10)* + 1(01)*

**Figure –**Finite Automata of Regular Expression for alternate 0’s and 1’s

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- DFA in LEX code which accepts even number of zeros and even number of ones
- DFA of a string with at least two 0’s and at least two 1’s
- DFA machines accepting odd number of 0’s or/and even number of 1’s
- DFA for strings not containing consecutive two a's and starting with 'a'
- Construct a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}
- Program to build a DFA to accept strings that start and end with same character
- Difference between DFA and NFA
- DFA for exactly one of a and at least one of b
- Program to build a DFA that accepts strings starting and ending with different character
- Design a DFA that accepts a string containing 3 a's and 3 b's
- Build a DFA to accept a binary string containing "01" i times and "1" 2j times
- Conversion from NFA to DFA
- Minimization of DFA
- DFA for accepting the language L = { a
^{n}b^{m}| n+m=even } - Program to Implement NFA with epsilon move to DFA Conversion
- DFA for Strings not ending with "THE"
- Union process in DFA
- Concatenation process in DFA
- Complementation process in DFA
- DFA of a string in which 2nd symbol from RHS is 'a'

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.