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

By: Prof. Dr. Fazal Rehman | Last updated: February 11, 2025

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)*

 

 

 

Regular expression for odd length strings
Regular expression for odd length strings

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

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(*).

Deterministic Finite Automata for the language of all even length strings but starts with a

Deterministic Finite Automata for the language of all even length strings but starts with a

 


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 of String starts with a ends with b and having odd length

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*

Regular expression for every odd position is 1 defined over {0,1}

1(01)*

Regular expression for every odd position is 0 defined over {a,b}

0(10)*

Regular expression for every odd position is a defined over {a,b}

a(ba)*

Regular expression for every odd position is b defined over {a,b}

b(ab)*

More Examples of Regular Expression 

  1. Regular Expression for no 0 or many triples of 0โ€™s and many 1 in the strings.
  2. RegExp for strings of one or many 11 or no 11.
  3. A regular expression for ending with abb
  4. A regular expression for all strings having 010 or 101.
  5. Regular expression for Even Length Strings defined over {a,b}
  6. Regular Expression for strings having at least one double 0 or double 1.
  7. Regular Expression of starting with 0 and having multiple even 1โ€™s or no 1.
  8. Regular Expression for an odd number of 0โ€™s or an odd number of 1โ€™s in the strings.
  9. Regular Expression for having strings of multiple double 1โ€™s or null.
  10. Regular Expression (RE) for starting with 0 and ending with 1.
  11. RE for ending with b and having zero or multiple sets of aa and bb.
  12. A regular expression of the second last symbol is 1.
  13. RE for starting with 1 having zero or multiple even 1โ€™s.
  14. Regular Expression for multiple aโ€™s and multiple bโ€™s.
  15. RE for exactly single 1 many 0โ€™s |exactly single a many b.
  16. A regular expression for strings starting with aa and ending with ba.
  17. A regular expression for the language of all consecutive even length aโ€™s.
  18. A regular expression for the language of all odd-length strings
  19. A regular expression for the language of all even length strings but ends with aa.
  20. A regular expression for the language of an odd number of 1s.
  21. A regular expression for the language of even length strings starting with a and ending with b in theory of automata.
  22. A regular expression for the language of all even length strings but starts with a.
  23. A Regular Expression for the Language of all strings with an even number of 0โ€™s or even number of 1โ€™s.
  24. A regular expression for the language of all those strings end with abb.
  25. A regular expression for string having must 010 or 101.
  26. Regular expression of  strings begin with 110
    Regular expression of  strings begin and end with 110
    Regular expression of strings containing exactly three consecutive 1โ€™s.
  27. A Regular Expression of all strings divisible by 4.
  28. A Regular Expression Strings that does not contain substring 110.

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.

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials