0% found this document useful (0 votes)
111 views16 pages

Theory of Automata Past Paper Spring 2023

The document is a past paper for a Theory of Automata course from Spring 2023, containing short and long answer questions on topics such as empty strings, null productions in CFG, ambiguity in grammar, and the differences between DFA and NFA. It also includes questions on designing Turing machines, proving languages are not regular or context-free, and understanding finite automata and context-free grammars. The paper emphasizes the importance of automata theory in computer science for language recognition, algorithm design, and system development.

Uploaded by

Shomila Waqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views16 pages

Theory of Automata Past Paper Spring 2023

The document is a past paper for a Theory of Automata course from Spring 2023, containing short and long answer questions on topics such as empty strings, null productions in CFG, ambiguity in grammar, and the differences between DFA and NFA. It also includes questions on designing Turing machines, proving languages are not regular or context-free, and understanding finite automata and context-free grammars. The paper emphasizes the importance of automata theory in computer science for language recognition, algorithm design, and system development.

Uploaded by

Shomila Waqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

THEORY OF AUTOMATA

PAST PAPER
SPRING 2023

S.
Short Answers

IT
ED
Question no. 1:
Differentiate between empty string and empty language. Support the answer with an example.
Answer:

Empty String Empty language


H
Definition: The empty string, denoted by ε, is Definition: An empty language is a language
a string that contains no characters. It is a that contains no strings, not even the empty
valid string in any alphabet but has a length string. It is denoted by the symbol ∅.
of zero.
R

Example: Consider an alphabet Σ = {a, b}. Example: Consider a language L over the
The string "ab", "a", and "b" are examples of alphabet Σ = {a, b} that contains no strings.
/M

strings over this alphabet, but ε is also a That is, L = ∅. This means there are no
string over this alphabet with no characters. strings in L, not even the empty string.

Key Difference:
YT

● Content: The empty string (ε) is a specific string of length zero, whereas the empty
language (∅) is a set that contains no elements at all.
● Belonging: The empty string can be an element of a language, but the empty language
has no elements, including the empty string.
Question no. 2:
What is null production in CFG? How can you identify the null production ?
Answer:

A null production in a Context-Free Grammar (CFG) is a production rule where a non-terminal


can produce the empty string (ε), written as A→ϵA

To Identify Null Productions:

1. Direct Null Production: Look for any production of the form A→ϵA.

S.
2. Indirect Null Production: If a non-terminal can derive ε through a sequence of
productions, it also counts as having a null production.

IT
Questio no. 3:
What is meant by the term “Ambiguity” in grammar? Explain by using some grammar of your
own choice.

ED
Answer:

“Ambiguity in grammar means that a single sentence (or string) can be understood in more than
one way because the grammar allows multiple ways to generate that sentence.”

Example:
H
Consider this grammar:
R
/M

For the sentence "a + a * a", there are two different ways to group the operations:

1. First Way: a+(a∗a)a + (a * a)a+(a∗a)


2. Second Way: (a+a)∗a(a + a) * a(a+a)∗a

Because there are two different ways to interpret the same sentence, the grammar is
YT

ambiguous

Question no. 4:
Differentiate between DFA and NFA. construct a DFA for a language defined over Σ = {0, 1}
accepting strings containing even number of 0’s and odd number of 1’s
Answer:
S.
IT
ED
H
R
/M

Question 5:
What is meant by “Context Free” in the term “Context Free Grammar” ? CFG can generate
regular language & some non regular languages. [ yes / no ] Support your answer ?
Answer:
In the term "Context-Free Grammar" (CFG), "Context-Free" means that the left-hand side of a
YT

production rule (i.e., the non-terminal symbol being replaced) can be replaced by the right-hand
side regardless of the surrounding context.

In other words, the replacement is solely based on the non-terminal symbol itself, without
considering the symbols surrounding it.

YES, both regular and some non-regular languages.


Example:
- Regular: a^n b^n
- Non-regular: a^n b^n c^n
Question 6:
Argument for the following:
->The word that has no letters like “ ^ ”, and the language that has no words are different
-> In “Kleene theorem part 1” there is no need to explain anything.
Answer:

- Empty word (^): A word with zero length, still a member of the language (e.g., ε ∈ L).
- Empty language ({ }): A language with no words, no elements (e.g., L = ∅).

Distinction:

S.
- The empty word is an element of a language.
- The empty language has no elements.

IT
Argument 2: Kleene's Theorem Part 1
No explanation needed because:

ED
Kleene's Theorem Part 1 states:

- Every Regular Expression (RE) can be converted to a Finite Automaton (FA).


- Every FA can be converted to an RE.
H
This theorem establishes the equivalence between REs and FAs, making explanations
unnecessary since:

- If you have an RE, you can convert it to an FA.


R

- If you have an FA, you can convert it to an RE.


/M

No further justification is required.

LONG ANSWERS
YT

Question 1:
Design a turing machine to recognize strings of matched parenthesis. The actions that should
be carried out are:
● Search for a right parenthesis.
● Search for a matching left parenthesis.
● If a right parenthesis is found then delete it and return to the matching left
parenthesis(the one found in step 2) and delete it as well.
● If there is no left parenthesis or there are too many right parenthesis, the Turing machine
stops in a non accepting state.
E.g; () ( ( () ) )
interpret/test, the given three strings below to generate TM.
(i)- ( () ) ( ()() )
(ii)- ( ( ( ()() ) () ) )
(iii)- ( () ( ()() )

Answer:

S.
IT
ED
H
R
/M
YT

Question 2:
For a string X ∈{ a , b }*, let X^R, denote the string X reversed. Consider the language
L = { WW^R | W ∈ { a , b }* }.
a) Prove that L is not regular by using the pumping lemma for regular languages.
Answer:
Step 1:
We suppose that the language is regular and we can make its FA.

Step 2:
We will consider that FA has 8 states. N = 8

Step 3:
Take string of length greater than the states
Let’s consider the string abababababa

S.
string = ababaababa

Which is a valid string because

IT
W = ababa
W^R = ababa
String = ababaababa = W.W^R ∈

ED
Step 4:
Dividing word into 3 parts. Such that x+y<N & y=>1
X=3 ; y =4 ; z=3
x= aba ; y = baab ; z = aba
H
Step 5:
Pumping Y i.e = XYYZ
W = ababaabbaababa
R

Step 6: Check if the Pumped String is in L


/M

For the new string to be in LLL, it must be of the form WW^R, which means the second half of
the string must be the reverse of the first half.

The pumped string is ababaabbaababa, and we can clearly see that:

● The first half of this string is ababaab


YT

● The second half is baababa, which is the reverse of ababaab.

Thus, the pumped string does belong to the language L, because it is of the form WW^R.

Question 3:
Suppose a language contains words that start and end in opposite double letters, and in the
middle of these letters words must contain odd numbers of a’s or b’s.
E.g; aaaaabb, bbaaa
Write Regular Expression & draw an FA for given language
Answer
REGULAR EXPRESSION
If starts with double a’s and end with double b’s
(aa(bb*+aa*)*bb)
If starts with double b’s and end with double a’s
(bb(aa*+bb*)*aa)

FINITE AUTOMATA (FA)

S.
IT
ED
H
SPRING 2022
R

Q.1. Answer the following questions precisely with logic. Extra writing practice not required. (6x5=30)
/M

Question 1:
From practical point of view, why it is necessary to study Theory of Automata
Answer:
Studying the Theory of Automata is essential because it provides foundational concepts for
YT

designing and understanding computational systems

Studying the Theory of Automata is crucial because it helps:

1. Language Recognition: Essential for programming languages and compilers.


2. Algorithm Design: Aids in creating efficient string processing algorithms.
3. System Design: Informs the development of complex systems and protocols.
4. Complexity Insights: Enhances understanding of computational limits.

It’s foundational for many areas in computer science.


Question 2:
Suppose there is some specific language with identifier naming rules as:
The identifier name can consist of alphabets (upper & lowercase), digits (0-9) & underscore ( _ ).
The first character can be either Underscore ( _ ) or an alphabet (upper or lowercase). You are
directed to draw finite state automata for the case to accept legal identifiers.
Answer:

S.
IT
Question 3:
ED
Discuss the concept of restrictions in DFA and relaxation in NFA with supportive examples.
H
Answer
R
/M
YT

Summary

● DFA enforces strict rules, making it deterministic and easier to implement but less
flexible due to its single transition requirement for each input symbol.
● NFA, on the other hand, relaxes these rules, allowing for multiple transitions and epsilon
moves, which provides greater flexibility in recognizing languages, though it can be more
complex to implement.

DFA Rule One letter cannot move to more than one state, There is only one output so the next
state is already determined. NFA RULE One letter can move to more than one state, Next state
is not determined. Dead State is not required in NFA. Can move to another state without an
input. i.e = It allows null / epsilon transition

S.
Question 4:
Do comparison of the computational models in terms of language recognition, rules, memory
management and Implementation.

IT
Answer

ED
H
R
/M

Question 5:
YT

What is the exact meaning of finite in finite automata? Design finite automata which accept odd
numbers of 1's and even number of O's. Verify your answer by applying at least 5 strings on your
designed automata.
Answer:

Meaning of "Finite" in Finite Automata

The term "finite" in finite automata refers to the fact that the automaton has a limited (finite)
number of states. This means that the automaton can only be in one state at a time and can
transition between these predefined states based on the input symbols. Unlike Turing machines,
which have an infinite tape and can have an infinite number of states, finite automata operate
within a fixed set of states.

FA

Tested Strings

100 1110000 1111100 1111111000000 1110000

S.
IT
ED
H
R

Question 6:
What is CNF? Support with an example.
/M

Answer:
Chomsky Normal Form (CNF) is a way to express context-free grammars where each
production rule is either:
1) Non-Terminal variables represents exactly two Non-Terminal Variables (AA-ZZ)
2) Non-Terminal variables represents exactly one Non-Terminal Variables (a-z , 0-9)
YT

Example:

Consider the grammar:

1. S→AB exactly two Non-Terminal Variables (AA-ZZ)


2. A→a exactly one Non-Terminal Variables (a-z , 0-9)
3. B→1 exactly one Non-Terminal Variables (a-z , 0-9)

This is in CNF because it follows the rules.


Q.2. Answer the following questions. (3x10=30)

Question 1:
Using the Turing Machine mechanism, process the given input as per instructions given in the
table, and draw the state diagram as well.
Input String: 0123456

S.
0 1 2 3 4 5 6 #
States Σ

Qo ( Q2 , 6 , R ) ( Q2 , 5 , R ) ( Q3 , 4 , R ) ( Q2 , 3 , R ) ( Q1 , 2 , R ) ( Q2 , 1 , R ) ( Q3 , 0 , R ) ( Q3 , 0 , L )

IT
Q1 ( Q1 , 4 , R ) ( Q1 , 5 , R ) ( Q3 , 6 , R ) ( Q2 , 4 , R ) ( Q1 , 1 , R ) ( Q2 , 1 , R ) ( Q3 , 0 , R ) ( Q3 , 0 , L )

ED
Q2 (P,6,R) ( Q1 , 5 , R ) ( Q3 , 4 , R ) ( Q2 , 3 , R ) ( Q2 , 2 , R ) ( Q2 , 1 , R ) ( Q3 , 0 , R ) ( Q3 , 0 , L )

Q3 ( Q1 , 4 , R ) ( Q3 , 5 , R ) ( Q3 , 6 , R ) ( Q2 , 4 , R ) ( Q1 , 1 , R ) ( Q2 , 1 , R ) ( Q3 , 0 , R ) ( Q3 , 0 , L )

Answer:
Because Answer Is Long
H
https://docs.google.com/document/d/1W-7r2Hyr89OUZu8qeAvLVApV1SSeDEeGz_zeI1zFqR0/e
dit?usp=sharing
R

Question 2:
/M

Prove that the language { | I & J > 0 }is not context-free by using the pumping lemma
for context-free languages.
Answer:

Step 1: Suppose language is CONTEXT FREE


YT

Step 2:
By the pumping lemma for context-free languages, there exists a pumping length p=12 such
that any string can be divided into five parts s=uvwxyz, satisfying the conditions of the pumping
lemma.

Step 3:

Take a string of length greater than the pumping length p=12

Let’s consider the string s = a^{3} b^{3} c^{9}


S = aaa bbb ccccccccc

This is a valid string because:

● i=3 , j=3 = ,
● The number of c's is cij= 3*3 = 9
● So the string is a^{3} b^{3} c^{9} ∈ L.

Step 4:

S.
Dividing the string into five parts, s=uvwxy, such that | vwx <= p = 12 | & vx > 0

U = 1 , v= 2 , w = 3 , x = 4 , y = 5

IT
U=a

V = aa

W = bbb

X = cccc

Y = ccccc
ED
H
.

Step 5: pumping v and y


R

S = a aa bbb cccc ccccc


/M

S = a aa bbb bbb cccc ccccc ccccc

Now = a^3 , b^6 , c^15 & 3 + 6 != 15

However, the string does not satisfy the condition that the number of ccc's should be 3×6=18
YT

Instead, it has 15 c's, which is incorrect.

So the given language is not a context free language


Question 3:
What is PDA? What are its components? Explain each component in detail. Further draw 1
(a+b)*aa(a+b)* in a new format (with components like START, REJECT, ACCEPT, READ).
Answer:

S.
IT
Components:

ED
The term components generally refers to the individual parts or elements of a PDA or the
attributes of the states and transitions. In the context of PDAs, it can refer to:
H
● The states themselves (each state may represent a different condition or configuration of
the automaton).
● The input symbols that the PDA can read.
R

● The stack operations (push and pop) that the PDA can perform.
● The transition rules that define how the PDA moves from one state to another based on
input and stack symbols.
/M

Definition of PDA

A PDA is formally defined as a 7-tuple:


YT

PDA=(Q,Σ,Γ,δ,Qo,Zo,F)

Where each component is defined as follows:

1. Q: Set of States

● Definition: Q is a finite set of states in which the PDA can be. Each state represents a
unique configuration of the PDA.
● Purpose: States are used to track the current condition of the automaton. The PDA
transitions from one state to another based on the input it reads and the operations it
performs on the stack.
● Example: Q={q0,q1,q2} could represent states indicating different stages in processing
an input string.

2. Σ \ Sigma: Input Alphabet

● Definition: Σ\Sigma is a finite set of symbols that the PDA can read as input. These are
the characters that the automaton processes.
● Purpose: The input alphabet is the source of data that the PDA operates on. It
determines the strings that can be processed by the PDA.
● Example: For a PDA that recognizes balanced parentheses, Σ\SigmaΣ might be { ( , )}

S.

3. Γ \ Gamma: Stack Alphabet

IT
● Definition: Γ \ Gamma is a finite set of symbols that can be pushed to or popped from
the stack. The stack alphabet can include the same symbols as the input alphabet or

ED
different ones.
● Purpose: The stack provides additional memory for the PDA, allowing it to keep track of
additional information during processing (e.g., counting occurrences, matching symbols).
● Example: In a PDA for parsing nested structures, Γ \ Gamma might include symbols like
{ ( , ) , Z } where Z could be a marker for the bottom of the stack.
H
4. δ \ delta: Transition Function

● Definition: δ \ delta is the transition function, which defines the rules for moving from
one state to another. It is typically defined as:
R
/M

● Parameters:
○ Current State: A state from Q.
○ Input Symbol: A symbol from Σ \ Sigma or ϵ \ epsilon (representing no input).
○ Top of Stack: A symbol from Γ \ Gamma that is currently on top of the stack.
YT

● Returns: A set of pairs containing the next state from Q and the new stack content
(which can be a sequence of stack symbols).
● Purpose: The transition function dictates how the PDA processes input and manipulates
the stack based on its current state and the input symbol it reads.


YT
/M
R
H
ED
IT
S.
PDA For (a+b)*aa(a+b)* in a new format (with components like
START, REJECT, ACCEPT, READ

S.
IT
Or can also be made as
ED
H
R
/M
YT

You might also like