Skip to content
Official PYQ · 1995

GATE CS 1995 Q1.9 — Regular Expressions and Finite Automata

Explain with AI

In some programming language, an identifier is permitted to be a letter followed by any number of letters or digits. If LL and DD denote the sets of letters and digits respectively, which of the following expressions defines an identifier?

Choose one option
View worked solution

Answer: C

According to the problem definition, an identifier must satisfy the following rules:

  1. It must start with a letter (LL).
  2. The starting letter must be followed by any number of letters or digits.

Let's translate these rules into a regular expression:

  • The set of letters is denoted by LL.
  • The set of digits is denoted by DD.
  • "Letters or digits" represents the union of the two sets, which is written as (L+D)(L + D).
  • "Any number of" means zero or more occurrences, which is represented by the Kleene star (∗*). Thus, "any number of letters or digits" is (L+D)∗(L + D)^*.

Combining these two parts, we get the regular expression for an identifier:

L(L+D)∗L(L + D)^*

Let's evaluate the given options:

  • Option A: (L+D)+(L + D)^+ – This allows an identifier to start with a digit, which is invalid.
  • Option B: (L.D)∗(L.D)^* – This only allows alternating sequences of letters and digits, and also allows the empty string, which is invalid.
  • Option C: L(L+D)∗L(L + D)^* – This correctly matches a letter followed by any sequence of letters and/or digits.
  • Option D: L(L.D)∗L(L.D)^* – This restricts the characters following the first letter to only alternating letter-digit pairs.

Therefore, the correct option is C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular Expressions and Finite Automata questions