Regular expression for the language of all odd length strings in theory of automata

Write the Regular expression for the language of all odd-length strings defined over ∑ = {a, b}?

Specifying odd length with regular expression

inValid Strings:

These all strings are not part of the language, so should be rejected by our regular expression.

Examples of invalid strings = {aa, bb, ab, ba, aaaa, abba, abbb,……………..} and all other strings that does not contain odd length strings.

Valid Strings:

These all strings are the part of the language so should be accepted by regular expression.

Examples of valid strings = {a, b,  aaa, aba, aabba, aabbb,………}and all other strings that contain odd length strings.

R.E = (a+b) (aa+bb+ab+ba)*

 Part 1 Part 2 (a+b) (aa+bb+ab+ba)*

Part 1:

Restricting the machine to read only one odd alphabet so the machine can read only a or b.

Part 2:

Restricting the machine to read many times even length alphabet like a machine can read aa or bb or ab or ba and machine can read it many times by repeating the loop(*).

DFA for all odd-length strings

Write the Regular expression for the language of all even length strings but starts with a defined over ∑ = {a, b}?

Accepted Strings:

These all strings are the part of the language so should be accepted by regular expression.

Example strings = {aa, ab,  aaab, aaab, aabb, abba, ababab………}and all other strings that are started with a and have even length.

Rejected Strings:

These all strings are not part of the language so should be rejected by regular expression.

Example strings = {a, b,  bb, ba, bab, bab, bba, babb,……………..} and all other strings that do not contain odd length strings.

R.E = (ab + aa) (aa+bb+ab+ba)*

 Part 1 Part 2 (ab + aa) (aa+bb+ab+ba)*

Part 1:

Bounding the machine to read the only even alphabet and starting with a.

Part 2:

Bounding the machine to read many times even length alphabet like a machine can read aa or bb or ab or ba and machine can read it many times by repeating the loop(*).

Write the Regular expression for the language of all even length strings but ends with aa defined over ∑ = {a, b}?

Accepted Strings:

These all strings are part of the language so should be accepted by regular expression.

Example strings = {aa, baaa,  bbaa, babaaa, …….}and all other strings that end with aa and have even length.

Rejected Strings:

These all strings are not part of the language so should be rejected by regular expression.

Example strings = {a, b, ab, ba, bb,  abb, aba, bab, aab, bbab, abbb,……………..} and all other strings that do not contain even length strings and not end with aa.

R.E = (aa+bb+ab+ba)aa

 Part 1 Part 2 (aa+bb+ab+ba)* aa

Part 1:

Bounding the machine to read many times even length alphabet like the machine can read aa or bb or ab or ba and machine can read it many times by repeating the loop(*).

Part 2:

Bounding the machine to read-only aa at the end.

List of 100+ Important Regular Expression

Regular Expression for Strings starts with a and ends with b and having an odd length string defined over {0,1}.

a( (a+b)((a+b)(a+b))* )b

valid strings={aab, abb,aaaab, aaabb, aabbb, abbbb, abaab,….}

Regular expression odd number of 1’s defined over {0,1}.

R.E = 0*(10*10*)*10*

Regular expression odd number of 0’s defined over {0,1}.

R.E = 1*(01*01*)*01*

Regular expression odd number of b’s defined over {a,b}.

R.E = a*(ba*ba*)*ba*

Regular expression odd number of a’s defined over {a,b}.

R.E = b*(ab*ab*)*ab*

1(01)*

0(10)*

a(ba)*

b(ab)*

Tutorial: Regular Expression

A detailed tutorial of the regular expression is here in the link of regular expression tutorial. This page contains the practice questions of regular expressions with solutions.

Tutorial covering the topics

• Give a regular expression.
• Describe the strings of the regular expression.
• write a regular expression.
• create all strings from regular expression.
• Generate all strings from regular expression.
• Extract all strings from regular expression.
• Find all strings from regular expression.
• Examples of regular expression.