Module II
Module II
Regular Expressions
Regular languages are denoted by regular expressions.
1
Regular Expression
Regular languages are denoted by Regular Expressions.
3. Pattern Matching:
Regular expressions are used for pattern matching within strings. In the context of formal
languages, this involves checking if a given string belongs to a particular regular
language defined by a regular expression.
4. Lexical analysis:
Regular expressions are commonly used in the design of lexical analyzers (lexers) for
compilers. Lexers are responsible for breaking down the source code into tokens, and
regular expressions are used to describe the patterns of valid tokens in the programming
languages.
They provide a concise and powerful notation for describing patterns and sets of strings
within the context of formal language theory.
3
Pumping Lemma:
Two Pumping Lemmas have been defined for the following:
This basically indicates that even after a string v is "pumped," or added a number of times, the
resulting string stays in L.
It is an evidence of language irregularity. Therefore, a language definitely fulfills pumping
lemma if it is regular. L is undoubtedly not regular if it contains a minimum of one pumping
string that is not in L.
It's possible that the contrary isn't always true. That is, the language is not regular even if
Pumping Lemma holds.
4
Applications of Pumping Lemma:
1. Proving Non-Regularity:
One of the primary applications of the Pumping Lemma is to prove that a given language
is not regular. If a language cannot satisfy the conditions of the Pumping Lemma, then it
cannot be regular
3. Compiler Design:
In the context of compiler design, the Pumping Lemma can be applied to analyze the
regularity of the language defined by the lexical structure of a programming language. It
helps ensure that the lexical analyzer can efficiently recognize valid tokens.
The Pumping Lemma is a powerful tool in formal language theory, and its applications
extend to various areas, including language design, compiler construction, and the
theoretical analysis of computational complexity.
i. If a path exists from the initial state of an A to its final state, designated a1a2..ak,
then a path exists from the initial state of a B to its final state, also designated
a1a2..ak.
ii. Should a path exist from the initial state of B to the ultimate state of B, designated
5
as b1b2..bj, then a path exists from the initial state of A to the ultimate state of A,
also designated as b1b2..bj.
Minimization of DFA
Conversion of a DFA to equivalent DFA with the fewest possible states is known as DFA
minimization. Partitioning algorithms are used in DFA minimization, also known as
Optimization of DFA.
Minimization of DFA
Assume a DFA D < Q, Σ, q0, δ, F > that is capable of identifying the language L.
Then, for language L, the reduced DFA D < Q', Σ, q0, δ', F' > can be built as follows:
Step 1: Q (the collection of states) will be split into two sets. All final states will be
included in one set, and non-final states will be included in the other. P0 is the name
of this partition.
Step 2: Set up k = 1.
Step 3: Partition the various Pk-1 sets to find Pk. We will take every feasible pair of
states in each set of Pk-1. We shall divide the sets into distinct sets in Pk if two states
inside a set can be distinguished from one another.
Step 5: A set's states combine to form a single state. In Pk, the sets will equal the
states in reduced DFA.
6
How may the distinguishability between two states in partition Pk be determined?
If δ (qi, a) and δ (qj, a) are in separate sets in partition Pk-1 for each given input
symbol a, then two states (qi, qj) can be distinguished in partition Pk.
Ex:
. Examine the DFA that is depicted as
Step 1. P0 contains 2 states. The last DFA states, q1, q2, and q4, will be in one set, and
the remaining states will be in another.
Step 2. Now determine whether or not sets of partition P0 can be partitioned in order to
compute P1:
7
In the same way, q0 and q3 combine to form q3. Figure 2 displays the minimized DFA that
corresponds to the DFA of Figure 1 as:
8
Ex:
Examine the provided DFA. Which statement below is not true?
1. L(A)'s complement is independent of context.
2. L (A) = L ((11 * 0 + 0) (0 + 1)* 0* 1*)
3. A is the minimal DFA for the language that A has approved.
4. A takes any string longer than { 0, 1 } by at least two lengths.
9
Solution:
It will take all strings with a minimum length of two, according to statement 4. However, it
takes 0 (which has length 1). Thus, 4 is untrue.
According to Statement 3, the DFA is negligible. We will verify with the previously
mentioned algorithm.
P0 equals P1, hence P1 is ultimate DFA. Q0 , Q1 are combinable. Then there will be 2
states for minimal DFA. As a result, statement 3 is likewise not true.
Thus, (D) is the correct choice.