Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C12 - Lab Question With Answer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Que-1: Draw a deterministic and non-deterministic finite automate which accept

00 and 11 at the end of a string containing 0, 1 in it, e.g., 01010100 but not
000111010.
Explanation – Design a DFA and NFA of a same string if input value reaches the
final state then it is acceptable otherwise it is not acceptable.
NFA of the given string is as follows:

DFA of the given string is as follows:


Here, q0 shows the initial state, q1 and q2 are the transition states,
and q3 and q4 are the final states.
Note – NFA and DFA both have same power that means if NFA can recognized
an language L then DFA can also be defined to do so and if DFA can recognized
an language L then NFA can also be defined to do so.
Que-2: Draw a deterministic and non-deterministic finite automata which accept
a string containing “the” anywhere in a string of {a-z}, e.g., “there” but not
“those”.
Explanation – Design a DFA and NFA of a same string if input value reaches the
final state then it is acceptable otherwise it is not acceptable. It is applicable for
all the DFA and NFA. Since, NFA is quit easier then DFA, so first make its NFA
and then go through the DFA.
NFA of the given string is as follows:

DFA of the given string is as follows:

Here, q0 shows the initial state, q1 and q2 are the transition states, and q3 is the
final state.
Que-3: Draw a deterministic and non-deterministic finite automata which accept
a string containing “ing” at the end of a string in a string of {a-z}, e.g.,
“anything” but not “anywhere”.
Explanation – Design a DFA and NFA of a same string if input value reaches the
final state then it is acceptable otherwise it is not acceptable. It is applicable for
all the DFA and NFA.
NFA of the given string is as follows:

DFA of the given string is as follows:

Here, q0 shows the initial state, q1 and q2 are the transition states, and q3 is the
final state.
Q4. What is ALGOL ?
Answer:ALGOL (ALGOrithmic Language) is one of several high level languages designed specifically
for programming scientific computations. It started out in the late 1950’s, first formalized in a report
titled ALGOL 58, and then progressed through reports ALGOL 60, and ALGOL 68. It was designed by
an international committee to be a universal language. Their original conference, which took place in
Zurich, was one of the first formal attempts to address the issue of software portability. ALGOL’s
machine independence permitted the designers to be more creative, but it made implementation
much more difficult. Although ALGOL never reached the level of commercial popularity of FORTRAN
and COBOL, it is considered the most important language of its era in terms of its influence on later
language development. ALGOL’s lexical and syntactic structures became so popular that virtually all
languages designed since have been referred to as “ALGOL – like”; that is they have been
hierarchical in structure with nesting of both environments and control structures.
Q5. What is the difference between Palindrome and Reverse function?
Answer:It is to be denoted that the words of PALINDROME are called palindromes.
Reverse =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

Q6..Define Kleene Star?


Answer:Given Σ, then the Kleene Star Closure of the alphabet Σ, denoted by Σ*, is the collection of all
strings defined over Σ, including Λ
It is to be noted that Kleene Star Closure can be defined over any set of strings.

Examples

If Σ = {x}

Then Σ* = {Λ, x, xx, xxx, xxxx, ….}

If Σ = {0,1}

Then Σ* = {Λ, 0, 1, 00, 01, 10, 11, ….}

If Σ = {aaB, c}

Then Σ* = {Λ, aaB, c, aaBaaB, aaBc, caaB, cc, ….}

Note:

Languages generated by Kleene Star Closure of set of strings, are infinite languages. (By infinite
language, it is supposed that the language contains infinite many words, each of finite length)
Q7. What is the difference between FA , TG , GTG. ?
In every FA, we mark transitions with single letter of the given alphabet but in TG transitions can be
marked with letters or strings (combination of letters).

In every FA, every state shows transition for all letters of given alphabet but in any TG it is not
necessary to show all transition for all letters of given alphabet. In TG, we may or may not show all
letter transitions according to requirement. We can also show transitions on reading any strings in
TGs but it is not possible in FA’s. In GTG Directed edges connecting some pair of states are labeled
with regular expressions . It may be noted that in GTG, the labels of transition edges are
corresponding regular expressions. In TG we write strings and in GTG we are bound to write RE.
Every FA is also a TG but not every TG is FA.

Q8. Q No.6 How one can create RE of a particular language?

First thing about RE and FA is that there is no hard and fast formula or method to generate these.
One can generate them by its mental approach. And this mental approach can be acquired through
only PRACTICE.

Here are some useful tips to write RE’s,

Let our language consist of the words of length three exactly over alphabet Σ= {a,b}

then it consists of the words

L = {aaa, aab, aba,abb,baa,bab,bba,bbb}.

Its RE can be simply written as

RE = aaa + aab + aba + abb + baa + bab + bba + bbb

which simply means that our language consists of only these words.
So we can make RE for a finite language by writing its all words with + operator between them.

We should also keep the null string in our mind. If our language generates null string than our RE
should also generate it)

For example language having all the words of even length has null string in it as well so we can write
its RE as follows

RE = ((a+b)(a+b))*

This RE also generates null string.

If a language generates all strings starting with a. then strings will be of type

a , aa, ab, aab, aaa, aba, abb,….

Here RE should start with ‘a’ and then all strings including null. So this will be (a + b)* and complete
RE is a (a+ b)*.

Similarly languages of strings ending in b will have RE (a + b)*b.

Q9. Q No.11 What is the method to understanding FA’s and NFA’s


Firstly we know that an FA is used to describe a language. Now a language consists of strings. FA will
describe the specific language only if it accepts all the strings of that particular language and all the
strings generated by the FA are in the language. So confirmation is of two ways.

Now, how to traverse the FA. It is very easy. Every FA has one initial state (state with -sign). From
every state of FA there is one transition for every letter of the alphabet. Read the string letter by letter
and move according to transitions from state to state. If the string ends in the final state (state with a +
sign), that particular string will be accepted otherwise rejected.

So, every string ending in final state will be accepted by FA and will be a word of the language.

For NFA, there may be no path or more than one path for a letter from a specific state. As similar to
FA just start traversing from the initial state and if the string ends in the final state, it will be accepted.

Remember, as there may be more than one path for a letter from a state. So any path can be used.
Goal is to reach the final state. Remaining theory is same to the FA.

Practice is the key to success. Just try simple FA’s and NFA’s in the start.

Q10. What is the concept of Pumping Lemma I and II and what is the difference between
pumping Lemma 1 and pumping Lemma 2 ?

In fact PLI & PLII are same (A way to recognize Non Regular language). The only difference is that
the conditions in pumping lemma II are more stricter than Pumping Lemma I some language that are
difficult to proof Non Regular by Pumping Lemma I are proved Non Regular by pumping Lemma II
easily.

Further mare in pumping lemma I we have to generate all words to of a language but in Pumping
Lemma II we have to generate a single word to prove a language non regular.

Explanation:

Some languages like PALINDROME that are proved to be regular by first version

due to some of their symmetrical words when we pump these words they remain to be

the parts of the language like

bbabb

By pumping lemma 1
Let y = a

Now repeating y three times results in

bbaaabb

That is also a valid word of PALINDROME so by pumping lemma I PALINDROME can not be proved
non regular, so there was the need of pumping lemma version version 2.

Now consider for the word

bbabb

if we take N=2

Then by pumping y (let we take it b ) two times results in

bbbbabb

That word is not in PALINDROME.

But if we take N=3 and y = a

Then by pumping y two times results in

bbaaabb

That word is in PALINDROME. So be careful in taking total no of states of the FA

and also the repeating factor (y) to prove an infinite language non regular you

need to prove only one word that is not part of the language.

You might also like