The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Similar documents
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

The University of Nottingham

Nondeterministic Automata vs Deterministic Automata

Formal languages, automata, and theory of computation

NON-DETERMINISTIC FSA

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Closure Properties of Regular Languages

CS 573 Automata Theory and Formal Languages

= state, a = reading and q j

Harvard University Computer Science 121 Midterm October 23, 2012

Parse trees, ambiguity, and Chomsky normal form

First Midterm Examination

Nondeterministic Finite Automata

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Homework 3 Solutions

Minimal DFA. minimal DFA for L starting from any other

Let's start with an example:

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

CS 275 Automata and Formal Language Theory

Worked out examples Finite Automata

CS241 Week 6 Tutorial Solutions

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Regular languages refresher

Context-Free Grammars and Languages

CSCI565 - Compiler Design

Chapter 2 Finite Automata

Lecture 08: Feb. 08, 2019

SWEN 224 Formal Foundations of Programming WITH ANSWERS

Lecture 6 Regular Grammars

First Midterm Examination

Convert the NFA into DFA

2.4 Theoretical Foundations

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

Finite State Automata and Determinisation

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Prefix-Free Regular-Expression Matching

Designing finite automata II

FABER Formal Languages, Automata and Models of Computation

Thoery of Automata CS402

3 Regular expressions

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

1 Nondeterministic Finite Automata

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

System Validation (IN4387) November 2, 2012, 14:00-17:00

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Formal Languages and Automata

Deterministic Finite Automata

CS375: Logic and Theory of Computing

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Regular expressions, Finite Automata, transition graphs are all the same!!

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Lexical Analysis Finite Automate

Nondeterminism and Nodeterministic Automata

Arrow s Impossibility Theorem

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Name Ima Sample ASU ID

Tutorial Automata and formal Languages

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II

Finite Automata-cont d

CMSC 330: Organization of Programming Languages

CS 330 Formal Methods and Models

Review for the Midterm

Lecture 6: Coding theory

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

PYTHAGORAS THEOREM WHAT S IN CHAPTER 1? IN THIS CHAPTER YOU WILL:

Languages and Computation (G52LAC) Lecture notes Spring 2018

CSE 401 Compilers. Today s Agenda

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Revision Sheet. (a) Give a regular expression for each of the following languages:

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Automata and Languages

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Fundamentals of Computer Science

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

Instructions. An 8.5 x 11 Cheat Sheet may also be used as an aid for this test. MUST be original handwriting.

CISC 4090 Theory of Computation

Section 1.3 Triangles

CSC 473 Automata, Grammars & Languages 11/9/10

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Transcription:

The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their desk rd ut must OT write nything else until the strt of the exmintion period is nnouned. Answer ALL THR questions o lultors re permitted in this exmintion. Ditionries re not llowed with one exeption. Those whose first lnguge is not nglish my use stndrd trnsltion ditionry to trnslte etween tht lnguge nd nglish provided tht neither lnguge is the sujet of this exmintion. Sujet-speifi trnsltion diretories re not permitted. o eletroni devies ple of storing nd retrieving text, inluding eletroni ditionries, my e used. ote: ASWRS Turn Over

2 Question 1 The following questions re multiple hoie. There is t lest one orret nswer, ut there my e severl. To get ll the mrks you hve to list ll orret nswers nd none of the inorret ones. 1 mistke results in 3 mrks, 2 mistkes result in 1 mrk, 3 or more mistkes result in zero mrks. Answer: ote tht the nswer tht should e provided is just list of the orret lterntive(s). The dditionl explntions elow re just for your informtion. () Whih of the following sttements re orret? (i) The empty word ǫ is the only word in the empty lnguge. (ii) ǫ Σ, where Σ = {0,1} (iii) ǫ / (iv) The empty word ǫ does not elong to ny non-empty lnguge. (v) ǫ { i j i,j,i+j 42} (where = {0,1,2,...}) Answer: Corret: ii, v Inorret: i The empty lnguge ; i.e., the empty set, does not ontin ny words, not even the empty one. iii By definition, ǫ L for ny lnguge L, inluding the empty lnguge. iv {ǫ} is n exmple of non-empty lnguge tht does ontin the empty word ǫ. (5)

3 () Consider the following finite utomton A over Σ = {,,}:,,,,,,,, 0 1 2 3 4 Whih of the following sttements out A re orret? (i) The utomton A is Deterministi Finite Automton (DFA). (ii) ǫ L(A) (iii) L(A) (iv) L(A) (v) The lnguge epted y the utomton A is ll words over Σ tht ontins the letters,,, in tht order. (5) Answer: Corret: iv, v Inorret: i The utomton is n FA sine more thn one trnsition sometimes re possile for some sttes nd lphet symols. ii ǫ / L(A) sine no strt stte is epting. iii / L(A) sine it is not possile to reh ny epting stte on this word. () Consider the following regulr expression: () () Whih of the following regulr expressions denote the sme lnguge s the ove regulr expression? (i) (++) (ii) (+) (++) (iii) (ǫ+) ( +) (iv) +() +() (v) ( ) ( ) (5) Answer: Corret: iii Inorret: i, ii, iv, v Turn Over

4 (d) Consider the following Context-Free Grmmr (CFG) G: S XX Y X X Y Y Y ǫ where S, X, Y re nonterminl symols, S is the strt symol, nd,, re terminl symols. Whih of the following sttements out the lnguge L(G) generted y G re orret? (i) ǫ L(G) (ii) L(G) (iii) L(G) (iv) L(G) = L 1 L 1 L 2 where L 1 = { i j i i,j, i > 0} nd L 2 = { i i } (where = {0,1,2,...}) (v) The following CFG G is equivlent to G ove; i.e., L(G ) = L(G): S XX X X Y Y Y ǫ Answer: Corret: i, ii, iv Inorret: (5) iii Sine the word ontins s nd s, the derivtion must egin S XX. The only possiility to derive the word from XX is to split it into two prts fter the lst, nd derive the first prt from the first X nd the lst prt from the seond X. But while n e derived from the first X, nnot e derived from the seond. v ot equivlent euse ǫ n now e derived from X, mening tht word like L(G ). However, / L(G).

5 (e) Whih of the following sttements out the Hlting Prolem re orret? (i) The Hlting Prolem is undeidle. (ii) The Hlting Prolem is semi-deidle. (iii) The Hlting Prolem is the prolem tht Turing Mhines n get stuk. (iv) There is no Turing Mhine tht deides the Hlting Prolem. (v) A Turing mhine tht never hlts hs got the Hlting Prolem. Answer: Corret: i, ii, iv (The semi-deidle lnguges re proper suset of the undeidle ones.) Inorret: iii, v (5) Turn Over

6 Question 2 () Given the following ondeterministi Finite Automton (FA) over the lphet Σ = {,, }, onstrut Deterministi Finite Automton (DFA) D() tht epts the sme lnguge s y pplying the suset onstrution:,, 0 1 2 3 4 To sve work, onsider only the rehle prt of D(). Clerly show your lultions in stte-trnsition tle. Then drw the trnsition digrm for the resulting DFA D(). Do not forget to indite the initil stte nd the finl sttes oth in the trnsition tle nd the finl trnsition digrm. (12) Answer: δ D() {0} = A {0,1} = B {0,2} = C {0} = A {0,1} = B {0,1} = B {0,2,3} = D {0} = A {0,2} = C {0,1,3} = {0,2} = C {0} = A {0,2,3} = D {0,1,3} = {0,2} = C {0,4} = F {0,1,3} = {0,1} = B {0,2,3} = D {0,4} = F {0,4} = F {0,1} = B {0,2} = C {0,3} = G {0,3} = G {0,1} = B {0,2} = C {0,4} = F We n now drw the trnsition digrm for D(): A B C D F G

7 () Wht lnguge does the following Turing Mhine (TM) M ept? where M = (Q, Σ, Γ, δ,q 0, B, F) Q = {q 0,q 1,q 2,q 3,q 4 } Σ = {,,} Γ = {,,,x,b} F = {q 4 } δ(q 0,) = {(q 1,x,R)} δ(q 1,) = {(q 1,x,R)} δ(q 1,) = {(q 2,x,R)} δ(q 1,) = {(q 3,x,R)} δ(q 2,) = {(q 2,x,R)} δ(q 2,) = {(q 3,x,R)} δ(q 3,) = {(q 3,x,R)} δ(q 3,B) = {(q 4,B,R)} δ(q, x) = stop elsewhere Give preise, mthemtil hrteristion of the epted lnguge long with rief explntion of why the mhine epts this lnguge. (8) Answer: L(M) = { i j k i,j,k,i 1,k 1}. Alterntively, we n oserve tht the lnguge tully is regulr nd given y e.g. the regulr expression. The mhine only ever move right nd either stys in stte or moves to higher numered stte. The mhine strts in stte q 0, where only is epted, using the mhine to move to stte q 1. In q 1 the mhine n loop on, epting further ritrry numer of s, or it n ept or moving to q 2 or q 3, respetively. Both q 2 nd q 3 re looping sttes, llowing n ritrry numer of s nd s respetively to e epted. A single is required to move form q 2 to q 3, ut note tht q 3 lso n e rehed diretly from q 1 on single, mening tht the numer of s in n epted word n e 0. The words epted re thus those onsisting of 1 or more s, followed y 0 or more s, followed y 1 or more s. Turn Over

8 () In the ontext of Turing Mhines, explin wht it mens for lnguge to e: reursive, reursively-enumerle, deidle, undeidle. (5) Answer: A reursive lnguge is lnguge tht is epted y Turing Mhine tht lwys hlts. This is the sme s sying tht the lnguge is deidle (or tht the prolem represented y the lnguge is deidle). A reursively enumerle lnguge is lnguge tht is epted y Turing Mhine (ut not y ny Turing mhine tht neessrily hlts). A lnguge tht is not reursive is undeidle. The undeidle lnguges thus inludes the reursively enumerle (or semi-deidle) lnguges nd those lnguges whih re not even reursively-enumerle.

9 Question 3 () The following is ontext-free grmmr (CFG) for simple rithmeti expressions. For simpliity, we only onsider the numers 0, 1, nd 2: + () 0 1 2 nd re nonterminls, is the strt symol, +,,, (, ), 0, 1, 2 re terminls. Show tht this grmmr is miguous. (5) Answer: To demonstrte miguity, demonstrte tht there is t lest one derivle word for whih there re two different leftmost or rightmost derivtions, or two different prse tress. For exmple, here re two different leftmost derivtions of the word 0+1+2: + + + + + 0+ + 0+ + 0+1+ 0+1+ 0+1+2 nd + + 0+ 0+ + 0+ + 0+1+ 0+1+ 0+1+2 Alterntively, here re the two prse trees orresponding to the derivtions ove: + + + nd + 2 0 0 1 1 2 Turn Over

10 () Construt n equivlent ut unmiguous version of the ontext-free grmmr for rithmeti expressions given in () ove y mking it reflet the following onventions regrding opertor preedene nd ssoitivity: Opertors Preedene Assoitivity highest right medium left + lowest left It should further e possile to use prentheses for grouping in the usul wy. (8) Answer: Strtify the grmmr so tht produtions for opertors refer to either produtions t the sme level or produtions t the next level up, nd use left-reursive produtions for left-ssoitive opertors nd right-reursive produtions for right-ssoitive opertors. + 1 1 1 1 2 2 2 3 2 3 3 () 0 1 2

11 () The following Context-free grmmr(cfg) is immeditely left-reursive: S S X X XX YXd Y Y Ye Yf g S, X, nd Y re nonterminls,,,, d, e, f, nd g re terminls, nd S is the strt symol. Trnsform this grmmr into n equivlent right-reursive CFG. Stte the generl trnsformtion rule you re using nd show the min trnsformtion steps. (12) Answer: First identify the immeditely left-reursive non-terminls. Then group the produtions for eh suh non-terminl into two groups: one where eh RHS strts with the non-terminl in question, nd one where they don t: A Aα 1... Aα m A β 1... β n Then reple those produtions with new produtions for A nd produtions for A, where A is new nme, s follows: A β 1 A... β n A A α 1 A... α m A ǫ There re two immeditely left-reursive non-terminls in the given grmmr: X nd Y. The grmmr is essentilly lredy grouped s required. Applying the ove trnsformtion rule to oth the X nd Y produtions yields: S S X X YXdX YX X XX ǫ Y gy Y ey fy ǫ nd