Saturday 25 August 2012

CS402 Spring 2012 Assignmet_2


Theory of Automata (CS402)
Assignment # 2
Solution

  Total marks = 20
                                                                                       Deadline Date = Expired

Please carefully read the following instructions before attempting the assignment.

Rules for Marking
It should be clear that your assignment would not get any credit if:

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • The assignment is copied.

Note that strict action would be taken if the submitted assignment is copied from any other student. Both students will be punished severely.

1)      You should concern recommended books to clarify your concepts as handouts are not sufficient.
2)      You are supposed to submit your assignment in .doc format. Any other formats like scan images, PDF, Zip, rar, bmp etc will not be accepted.
3)      You are advised to upload your assignment at least two days before Due date.


Important Note: 

Assignment comprises of 20 Marks. Note that no assignment will be accepted after due date via email in any case (whether it is the case of load shedding or emergency electric failure or internet malfunctioning etc.). Hence, refrain from uploading assignment in the last hour of the deadline, and try to upload Solutions at least 02 days before the deadline to avoid inconvenience later on.

For any query please contact: CS402@vu.edu.pk

Question No. 1 [5+5]

Construct deterministic Finite State Automata for each of the following over Σ = {x, y}:

a. Language of all those strings in which second last symbol is ‘y’.
Solution:






















b. Language of all those strings whose length is odd and number of y’s is even.
Solution:
                                                           





















Question No. 2 [5+5]

a. Convert the given transition graph (TG) into generalized transition graph (GTG) and derive its regular expression.                
Solution:

First of all single initial and single final states are required as given below:

After eliminating state 3 the TG will look like:

Now eliminate state 4
Eliminate state 5
Now eliminate state 6

After eliminating states 1 and 2 the GTG will look like:

b. Find out the union of the given two FAs:













Solution:



   New states after reading
Old States



a
b



z1 - = (x1, y1)
(x2, y2) = z2
(x2, y2) = z2
z2= (x2, y2)
(x2, y3) = z3
(x3, y2) = z4
z3+ = (x2, y3)
(x2, y3) = z3
(x3, y3) = z5
z4+ =(x3, y2)
(x3, y3) = z5
(x3, y2) = z4
z5+ = (x3, y3)
(x3, y3) = z5
(x3, y3) = z5


The resultant FA of the union of above two FAs is given below:







CS402 Spring 2012 Assignmet_1


Theory of Automata (CS402)
Assignment # 1(Solution)
  Total marks = 20
                                                                                       Deadline Date = Expired

Please carefully read the following instructions before attempting the assignment.

Rules for Marking
It should be clear that your assignment would not get any credit if:

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • The assignment is copied. Note that strict action would be taken if the submitted assignment is copied from any other student. Both students will be punished severely.

1)      You should concern recommended books to clarify your concepts as handouts are not sufficient.
2)      You are supposed to submit your assignment in .doc format. Any other formats like scan images, PDF, Zip, rar, bmp, docx etc will not be accepted.
3)      You are advised to upload your assignment at least two days before Due date.
4)      This assignment file comprises of Two (3) pages.


Important Note: 

Assignment comprises of 20 Marks. Note that no assignment will be accepted after due date via email in any case (whether it is the case of load shedding or emergency electric failure or internet malfunctioning etc.). Hence, refrain from uploading assignment in the last hour of the deadline, and try to upload Solutions at least 02 days before the deadline to avoid inconvenience later on.

For any query please contact: CS402@vu.edu.pk



Q 1.

a. Define the language of strings of length 3 over Σ = {#, %, @}.                 Marks 4
Ans.
            L = {###, ##%, ##@, #%#, #@#, #%%, #@%, #@@, #%@, %##, %#%, %#@, %%#, %@#, %@%, %%%, %%@, %@@, @###, @#%, @#@, @%#, @%%, @%@, @@#, @@%, @@@ }       



b. Generate the reverse of language generated in part a.                             Marks 4
Ans.
            Rev (L) = {###, %##, @##, #%#, #@#, %%#, %@#, @@#, @%#, ##%, %#%, @#%, #%%, #@%, %@%, %%%, @%%, @@%,##@, %#@, @#@, #%@, %%@, @%@, #@@, %@@, @@@}



c. Identify if there is any palindrome.                                                                          Marks 2
Ans.
            Palindromes= {###, #%#, #@#, %#%, %@%, %%%, @#@, @%@, @@@}
                                   



                                                                                                                              
Q 2.

Consider the language of strings defined over Σ = {x, z, xy, yz, zx} with the following strings:
i.  xyzxyz
ii. xxyzxy

a. Tokenize the above strings in all possible ways along with finding their lengths.                                                                                                                                          Marks 6

Ans.
i.  xyzxyz

The give string can be tokenized in the following four ways:

Tokenization                 Length

(x)(yz)(x)(yz)                4         
(xy)(zx)(yz)                   3
(x)(yz)(xy)(z)                4
(xy)(z)(x)(yz)                4





ii. xxyzxy

The string can be tokenized in the following two ways:
Tokenization                 Length

(x)(x)(yz)(xy)                  4
(x)(xy)(z)(xy)                 4



b. Explain whether the above alphabet is valid or not along with justification?
Marks 4
Ans.

The given alphabet Σ = {x, xy, yz, zx} is an invalid alphabet because “x” is the prefix of “xy” and “z” is the prefix of “zx” where x and z are already letters of the given alphabet set.  From the definition of invalid alphabet we know that an alphabet set is invalid if there is a letter which is the letter of the alphabet set and is the prefix of another letter.