CS402 Solved Subjective Final Term by JUNAID
CS402 Solved Subjective Final Term by JUNAID
FAQ's about
Lectures 36 to 40
Automata Theory
FAQ's about Lectures 36 to 40
Q No 1.What is the Difference between Nullable
and Null production? How to make eliminate
Nullable and for Null Productions from the CFG
?
The production of
the form
nonterminal ® L
is said to be null production.
Example:
Consider the following CFG
S ® aA|bB|L, A ® aa|L, B ® aS
Here S ® L and A ® L are null productions.
A production is called nullable production there is a
derivation that starts at Non Terminal and leads to L
i.e.
S ---- > aA | bB | aa
A ----- > C | bb
C ----- > L
Here A nullable Non Terminal due to Nullable production A > C as
C leads to null.
Example:
AL-JUNAID INSTITUTE GROUP
Consider the
following CFG S
® XY, X ® Zb, Y
® bW
Z ® AB, W ® Z,
A ® aA|bA|L B
®Ba|Bb|L.
Here A ® L and B ® L are null productions, while Z ®
AB, W ® Z are nullable productions.
Method:
Delete all the Null productions and add new productions e.g.
Consider the following productions of a certain
CFG X ® aNbNa, N ® L, delete the production N
® L and using the production
X ® aNbNa, add the following
new productions X ® aNba, X ®
abNa and X ® aba
Thus the new CFG will contain the following
productions X ® Nba|abNa|aba|aNbNa
Note: It is to be noted that X ® aNbNa will still be included in the
new CFG.
Method:
Consider the
following CFG S
® XY, X ® Zb, Y
® bW
Z ® AB, W ® Z, A
® aA|bA|L B
®Ba|Bb|L.
AL-JUNAID INSTITUTE GROUP
Here A ® L and B ® L are null productions, while Z ®
AB, W ® Z are nullable productions. The new CFG
after, applying the method, will be
S ® XY
X®
Zb|b Y
®
bW|b
Z®
AB|A|B
W®Z
A®
aA|a|bA|b
B
®Ba|a|Bb
|b
Note: While adding new productions all Nullable
productions should be handled with care. All
Nullable productions will be used to add new
productions, but only the Null production will be
deleted
Q No 2. Is it possible to make CFG for infix and
postfix expression's using derivation tree ?
Derivation tree is only used to derive words of
language that is described by a CFG. Yes, we can
create CFG for languages infix expressions, postfix
expressions.
AL-JUNAID INSTITUTE GROUP
Q No 3 what is the uses of push down automata in computing
?
PDA is just an enhancement in FAs. i.e Memory is
attached with machine that recognizes some language.
FA is basic structure for most advanced electronic
machines such as computer etc.
Q No 4 What is difference between PUSH DOWN
STACK and PUSH DOWN STORE ?
No difference at all. Both terms are used to describe memory
structure attached with FAs to store some characters in it.
Q No 5 How we can distinguish between "CFG" and "CNF" in
the questions
?
Chomsky Normal Form (CNF)
If a CFG has only productions of the form
string of two nonterminalsnonterminal ---------
or
one terminalNonterminal -----------
Then the CFG is said to be in Chomsky Normal Form (CNF).
Thus if the given CFG is in the form specified
above it will be called in CNF. Q No 6.What is
meant by the terms stack consistence and input
tape consistence ?
Term Stack consistent means we can pop any
character from the top of the stack only. PDA should
not be able to pop any character other than that is
present on the top of the stack.
Term Tape consistent means we can read only the
first letter on the tape not any other letter of the
tape after the first one.
AL-JUNAID INSTITUTE GROUP
Q No 7 What is the concept of unit production ?
The productions of the form
one Nonterminalone Nonterminal --------
Are called unit
productions. For
example
A (Unit Produciton)S --------
a | bA--------
A. we can directly writeHere there is no
need of Unit Production S S a | b
Q No 8 Why Context Free Grammars are
called "Context Free? Context Free Grammars
are called context free because the words of the
languages of Context Free Grammars have
words like
“aaabbb”(PALINDROME). In these words the value
of letters (a , b) is the same on whatever position
they appear. On the other hand in context sensitive
grammars their value depend on the position they
appear in the word a simple example may be as
follows
Suppose we have a decimal number 141 in our
language . When compiler reads it, it would be in
the form of string. The compiler would calculate its
decimal equivalent so that we can perform
mathematical functions on it. In calculating its
decimal value , weight of first “1” is different than
the second “1” it means it is context sensitive
(depends on in which position the “1” has
appeared).
i.e.
AL-JUNAID INSTITUTE GROUP
1*102 + 4*101 + 1* 100 = 14
(value of one is 100) (value of one is just one)
That is not the case with the words of Context Free
Languages. (The value of “a” is always same in
whatever position “a” appears).
Q No 9. What is Unit Production?
The production in which one non-terminal leads to only one non-
terminal.
Q No 10.What is Left most Derivation in CFG?
It is a method of generation of strings from a CFG
starting from left most letter of the string.
Q No 1.Give a example of converting a CFG to CNF?
Consider the CFG
given below S}
ABC
A} aa
| b B}
c
C}d
Its CNF
will be
S} DC
D } AB
A}
EE | b
E}a
B}c
C}d
AL-JUNAID INSTITUTE GROUP
Q No 2.In the lecture 41 's example, we have
converted PDA to conversion form and a word
'aaaabb' is derived from this conversion form
PDA. What are the derivation steps.
The PDA converted to conversion form has some
specific features that are important to understand first.
These features are
The states named START, READ, HERE and
ACCEPT are called joints of the machine.
With the help of the conversion form we have been
able to achieve that POP state has only one path out
of it and the path taking (multiple paths) decisions
take place only on the READ state.
The word 'aaaabb' is generated as
follows from the PDA START-
POP4-PUSH $
This step pops $ and then pushes it to ensure that
stack contains $ at the beginning.
READ1-POP6-PUSH $-PUSH a
As first time after reading "a" there is $ at the top
of stack so we will follow path segment READ1-
POP6-PUSH $-PUSH a
READ1-POP5-PUSH a-PUSH a
Now a is on the top of the stack so we will follow
READ1-POP5-PUSH a-PUSH a
READ1-POP5-PUSH a-PUSH a
Again following same
segment for a READ1-
POP5-PUSH a-PUSH
AL-JUNAID INSTITUTE GROUP
a
Again following same segment for a
READ1-POP1- HERE-POP2
As we read b on
input tape.
READ2-POP1-
HERE-POP2
As we read b on
input tape.
READ2-POP3-
ACCEPT.
As we read ∆ from the input tape
Q No 3.How to differentiate between "wanted" and
"unwanted branch" ? When we derive a word in
Top down parsing beginning with the starting Non
Terminal the branches of the tree that do not lead to
our required word are left aside these branches are
called unwanted branches.
For example
for CFG S
---- >AA
A - >a | b
If we want to generate the word "aa" we will leave
the branch generated by the production A >b.
Q No 4.What is the difference between
intersection and union of a language?
Intersection of two languages will consist of all those
words which are in both languages while union of two
languages will consist of all those words which are
present in at least one language.
Symbol for intersection is 、 and for union is U.
AL-JUNAID INSTITUTE GROUP
Q No 5.What is the difference between Context
free languages and regular languages?
Regular languages can be represented by FA’s because
we do not need any memory to recognize (accept or
reject them on FA) them but there is another class of
languages that can not be represented by FA’s
because these languages require that we have some
memory (with the help of memory we can store letters
of the string we are checking so that we can compare
them with next coming letters in the string).
For example language anbn requires that we must
store a’s and then compare their count with next
coming b’s so that we can check whether a’s are equal
to b’s or not.
Due to this reason we use Context Free Grammars to
represent them because we can5t write RE’s for them.
So Context Free Languages represent a broader
category this category also include regular
languages as subcategory. It means that context
free languages include regular languages as well
as some other languages.
Q No 6.What is the difference between Moore and Mealey
machines?
In Mealy Machine we read input string letters and
generate output while moving along the paths from
one state to another while in Moore machine we
generate output on reaching the state so the output
pattern of Moore machine contains one extra letter
because we generated output for state q0 where we
read nothing.
AL-JUNAID INSTITUTE GROUP
Q No 7.What does the following terms mean
STACK Consistent
Y-able Paths
Working string
Semi Word means
Stack consistence means that in the PDA converted in
the conversion form, when we follow a path
segment (which is formed by combining start, read
or here state with next read, here or accept state on
the path) along the PDA its pop state should have
the path for the same letter that is present on the top
of the stack at that stage. If this doesn’t happen
our PDA will crash because in conversion form of
the PDA the pop state has only one letter path, so if
we could not be able to find that letter on the top of
the stack our PDA will crash (if will not find path
where to go from that state)
Working string means the string present on the input tape.
Y-able Paths means that when we follow a certain
sequence of rows from the row table to generate a
path for a word form start state to accept state. The
path (sequence of rows) should be stack as well as
joint consistent it means that rows should end at the
same read or here state (join consistency ) and the
rows should be able to pop the letter from the top that
is indicated in the pop state of the row.
Semi word is the string of terminals it may be null
string ending with a Non terminals on the right.
AL-JUNAID INSTITUTE GROUP
For example some
semi words are aaS
aab
bA
B
Is Automata Theory is a Programming Subject or theoretical?
Automata theory is the study of abstract computing
devices, or "machines". This topic goes back to the
days before digital computers and describes what is
possible to compute using an abstract machine.
These ideas directly apply to creating compilers,
programming languages, and designing applications.
They also provide a formal framework to analyze
new types of computing devices, e.g. biocomputers or
quantum computers
What are practical Examples of the
implications of Automata Theory and the
formal Languages?
Grammars and languages are closely related
to automata theory and are the basis of many
important software components like:
Compilers and interpreters
Text searching
System verification
Finite Automata
AL-JUNAID INSTITUTE GROUP
RegularLanguages
Linear-bounded Automata
Push-Down Automata
Turing Machines
Arrays of Automata
Question:
Difference between Palindrome and Reverse function?
Answer:
The language consisting of ┄ and the strings s
defined over ┋ such that Rev(s)=s.
It is to be denoted that the words of
PALINDROME are called palindromes. Reverse
(w) = w
Example: ┋={a,b},
PALINDROME={┄ , a, b, aa, bb, aaa, aba, bab, bbb,
...}
If a is a word in some language L, then reverse (a)
is the same string of letters spelled backwards,
called the reverse of a.
e.g
reverse (xxx)
= xxx reverse
(623) =
326
reverse (140) = 041
Question: Define Strings?
Answer: Concatenation of finite letters from the alphabet is called a
string.
e.g If ┋= {a,b} then a language L can be defined as
L = {a, abab, aaabb, ababababababababab,. }
it's mean all words with a's more or equal to b's
AL-JUNAID INSTITUTE GROUP
Question: Define empty or null strings?
Answer: Concatenation of finite letters from the alphabet is called a
string.
Sometimes a string with no symbol at all is used,
denoted by (Small Greek letter Lambda) ┣ or
(Capital Greek letter Lambda) ┄, is called an empty
string or null string.
Question:
Strings that ending in "a " and strings containing
Answer:
exactly one "a".
Its means all string ending in a
e.g ┋= {a, b}
{a, aa, ba, aba,
baa,…….} Exactly a,
defined over ┋= {a, b}
{ab, ba, abb, bba,… }
Rows correspond to
states Columns
correspond to inputs
Entries correspond to
next states
The start state is marked with
an arrow The accepting
states are marked with a
star
AL-JUNAID INSTITUTE GROUP
Questi What does it means by the transition?
on: Transition means which letter, after being read, is
Answ transfer from which place to which place. It is
necessary to show transition of every letter from each
er:
and every state.
Question:
What is the difference between pumping Lemma
Answer: 1 and pumping Lemma 2?
Infact PLI & PLII are same (A way to recognize Non
Regular language). The only difference is in PLII we
take care about the substring x & y that length (x) +
length (y) less than or equal no. of state of machine.
This is because through PLI palindrome (that is Non
Regular) is proved to be regular and through PLII this
problem is fixed.
AL-JUNAID INSTITUTE GROUP
Question: What is pumping lemma? And what is history?
Answer:
A theorem to check validity (Regularity) of an
infinite language should not be used with finite
languages. Whenever an infinite is regular then
there must be a loop (circuit) because without a loop
means infinite no. of states that is not possible
practically. (Machine can have finite states only)
Question:
Why we use null string in FA?
Answer:
If null string is part of our language then we have to
handle it in FA, its not compulsion.
e.g.
aab =
valid baa
= valid
aba =
invalid
abab =
invalid
Question:
Can we accept the strings going from final to initial?
Answer:
It is to be noted that if any state start from the final
state it does not accept any string. Even it does not
accept the null string, because there is no path
starting from initial state and ending in final state.