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

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

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

The University of Nottingham

Formal languages, automata, and theory of computation

Convert the NFA into DFA

Homework 3 Solutions

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

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

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

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

SWEN 224 Formal Foundations of Programming WITH ANSWERS

Designing finite automata II

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

Harvard University Computer Science 121 Midterm October 23, 2012

First Midterm Examination

Minimal DFA. minimal DFA for L starting from any other

First Midterm Examination

Closure Properties of Regular Languages

Nondeterminism and Nodeterministic Automata

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

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

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

1 Nondeterministic Finite Automata

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.

Worked out examples Finite Automata

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

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

Formal Languages and Automata

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

Context-Free Grammars and Languages

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

Finite Automata-cont d

Deterministic Finite Automata

3 Regular expressions

Parse trees, ambiguity, and Chomsky normal form

FABER Formal Languages, Automata and Models of Computation

Name Ima Sample ASU ID

CS 330 Formal Methods and Models

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.

Lecture 08: Feb. 08, 2019

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

CS 275 Automata and Formal Language Theory

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

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.

Coalgebra, Lecture 15: Equations for Deterministic Automata

Thoery of Automata CS402

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

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

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

Tutorial Automata and formal Languages

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

CMSC 330: Organization of Programming Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

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

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

CS375: Logic and Theory of Computing

Lecture 6 Regular Grammars

Model Reduction of Finite State Machines by Contraction

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

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

378 Relations Solutions for Chapter 16. Section 16.1 Exercises. 3. Let A = {0,1,2,3,4,5}. Write out the relation R that expresses on A.

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

CSC 311 Theory of Computation

State Minimization for DFAs

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Lexical Analysis Finite Automate

Let's start with an example:

Some Theory of Computation Exercises Week 1

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Review for the Midterm

CISC 4090 Theory of Computation

DFA minimisation using the Myhill-Nerode theorem

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Non-deterministic Finite Automata

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

Fundamentals of Computer Science

Lexical Analysis Part III

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

Chapter 2 Finite Automata

Special Numbers, Factors and Multiples

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Lecture 2 : Propositions DRAFT

Finite-State Automata: Recap

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

CHAPTER 1 Regular Languages. Contents

CS 275 Automata and Formal Language Theory

Bases for Vector Spaces

CS 314 Principles of Programming Languages

Theory of Computation Regular Languages

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Non-deterministic Finite Automata

A negative answer to a question of Wilke on varieties of!-languages

Transcription:

The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook nd sign their desk crd ut must NOT write nything else until the strt of the exmintion period is nnounced. nswer LL THREE questions No clcultors re permitted in this exmintion. Dictionries re not llowed with one exception. Those whose first lnguge is not English my use stndrd trnsltion dictionry to trnslte etween tht lnguge nd English provided tht neither lnguge is the suject of this exmintion. Suject-specific trnsltion directories re not permitted. No electronic devices cple of storing nd retrieving text, including electronic dictionries, my e used. Note: NSWERS Turn Over

2 Question 1 The following questions re multiple choice. There is t lest one correct nswer, ut there my e severl. To get ll the mrks you hve to list ll correct nswers nd none of the incorrect ones. 1 mistke results in 3 mrks, 2 mistkes result in 1 mrk, 3 or more mistkes result in zero mrks. nswer: Note tht the nswer tht should e provided is just list of the correct lterntive(s). ny further explntions elow re just for clrifiction. () Consider the following finite utomton over Σ = {,}: 0 1 2 3 4 Which of the following sttements out re correct?, (i) The utomton is Deterministic Finite utomton (DF). (ii) ǫ L() (iii) L() (iv) ll words ccepted y contin one more thn or one more thn. (v) The utomton ccepts ll words over Σ tht contin one more thn or one more thn. (5) nswer: Correct: i, iii, iv Incorrect: ii The initil stte is not ccepting. v E.g. / L().

3 () Consider the following set W of words: W = {ǫ,, c, } Which of the following regulr expressions denote lnguge tht contins ll words in W? (ut not necessrily only the words in W: the lnguge denoted y the regulr expression is llowed to contin more words.) (i) (ǫ++c)(ǫ+) (ii) (ǫ++c)( +) (iii) (ǫ++c) (iv) (+c) (v) () +c nswer: Correct: i, iii, iv Incorrect: (5) ii ǫ / L( +) nd therefore ǫ / L((ǫ++c)( +)). v c / L(() ) nd c / L(c ), nd therefore c / L(() +c ). (c) Consider the following Context-Free Grmmr (CFG) G: S XY X X ǫ Y Yc ǫ where S, X, Y re nonterminl symols, S is the strt symol, nd,, c re terminl symols. Which of the following sttements out the lnguge L(G) generted y G re correct? (i) ǫ L(G) (ii) c L(G) (iii) c L(G) (iv) ccc L(G) (v) L(G) = { n 2n c n n N} (where N = {0,1,2,...}) nswer: Correct: i, ii, iv; Incorrect: iii, v ({ n 2n c n n N} L(G)) (5) Turn Over

4 (d) Which of the following properties of prolem P imply tht P is undecidle? (i) P is reducile to the Hlting Prolem. (ii) The Hlting Prolem is reducile to P. (iii) P is recursively enumerle ut not recursive. (iv) The complement of P is recursively enumerle. (v) There is no Turing Mchine tht solves P. nswer: Correct: ii, iii, v Incorrect: i, iv When prolem Q is reducile to nother prolem P, this mens tht ny instnce of Q cn e trnsformed into n instnce of P with the sme solution. If we hd n lgorithm to solve P, we could then lso solve Q. Therefore, if we lredy know tht P is undecidle, this reduction shows tht there cnnot e n lgorithm to solve P. We cn conclude tht P is lso undecidle. This is why (iii) is correct. However if we know tht P is undecidle, the fct tht instnces of Q re reducile to instnces of P is not informtive: there my still e n lgorithm to solve Q, independently of the fct tht we don t hve one for P. Tht s why (ii) does not imply tht P is undecidle. nswer (iv) is incorrect ecuse it merely sys tht there is n lgorithm tht enumertes the instnces of P tht hve negtive solution. This still leves open the possiility tht there is nother lgorithm tht enumertes the instnces of P with positive solution. In tht cse, y comining the two lgorithms, we could decide P. (e) Which of the following sttements out the λ-clculus re true? (i) Every λ-term hs norml form. (ii) Every λ-term hs fixed point. (iii) Every computle function cn e represented y λ-term. (iv) The normliztion property of λ-terms is decidle prolem. (v) The set of functions representle y λ-terms is the sme s those computle y Turing Mchines. (5) nswer: Correct: ii,iii,v Incorrect: i,iv (5)

5 nswer (i) is incorrect ecuse there re λ-terms whose reduction sequences go on forever (independently of wht reduction strtegy we use). One exmple is (λx.xx)(λx.xx). nswer (iv) is incorrect ecuse normliztion of λ-terms is equivlent to the Hlting Prolem (it is in fct the formultion of the Hlting Prolem in the λ-clculous). Therefore it is undecidle. Turn Over

6 Question 2 () Given the following Nondeterministic Finite utomton (NF) N over the lphet Σ = {,, c}, construct Deterministic Finite utomton (DF) D(N) equivlent to N y pplying the suset construction:,,c,,c,,c 0 1 2 3 Show your clcultions in stte-trnsition tle. Consider only the rechle prt of D(N). Then drw the trnsition digrm for the resulting DF D(N). Indicte the initil stte nd the finl sttes oth in the trnsition tle nd the finl trnsition digrm. (12) nswer: δ D() c {0} = {0,1} = {0} = {0} = {0,1} = {0,1} = {0,1,2} = C {0,1} = {0,1,2} = C {0,1,3} = D {0,1,2,3} = E {0,1,3} = D {0,1,3} = D {0,1} = {0,1,2} = C {0,1} = {0,1,2,3} = E {0,1,3} = D {0,1,2,3} = E {0,1,3} = D The sttes hve een nmed (,,..., E) to fcilitte drwing the trnsition digrm. We cn now drw the trnsition digrm for D(N):,c,c,c,c C D E,c

7 () Consider the following Context-Free Grmmr (CFG): S Sp m c lsr S,, nd re nonterminls,,, c, l, m, p, nd r re terminls, nd S is the strt symol. Drw the derivtion tree ccording to this grmmr for the word mlppcrm. (5) nswer: Derivtion tree for mlppcrm: S m m l S r S p S p c Turn Over

8 (c) Construct n unmiguous Context-Free Grmmr (CFG) for regulr expressions over the lphet Σ = {,,c} (with the syntx defined in the lecture notes). To ensure your grmmr is unmiguous, it should reflect the precedence nd ssocitivity for the regulr expression constructs s specified y the following tle: Opertors Precedence ssocitivity highest n/ conctention medium left + lowest left For exmple, ((ǫ+)) + is vlid regulr expression, wheres oth (ecuse the prentheses re not lnced) nd ( + (ecuse + is inry opertor) re not. (8) nswer: The following is one possile grmmr. It hs een strtified to cpture the desired precedence levels, nd left recursion is used to imprt left ssocitivity on the relevnt constructs ccording to the specifiction: E E + E 1 E 1 E 1 E 1 E 2 E 2 E 2 E 2 E 3 E 3 (E) E P E P c ǫ Here, E, E 1, E 2, nd E P re nonterminls with E eing the strt symol, nd +,, (, ),,, c, ǫ, re terminls. (Note in prticulr tht E P ǫ is not n epsilon production in this cse!)

9 Question 3 () Write the λ-terms tht represent the following vlues: The oolen vlues true nd flse; The exclusive or function xor, such tht xortruetrue flse, xortrueflse true, xorflsetrue true, xorflseflse flse; For every couple of terms nd, term, representing the pir, such tht The Church Numerl 3., true,, flse ; nswer: true = λx.λy.x flse = λx.λy.y xor = λu.λv.u(vflsetrue)v where (vflsetrue) is the encoding of (notv), = λx.x 3 = λf.λx.f (f (f x)) (8) () Consider the following λ-terms: xor-pir is function on pirs of oolens, xor-fun function from Church Numerls to pirs of oolens: xor-pir = λp. pflse,xor(ptrue)(pflse) xor-fun = λn.n xor-pir true, true Wht vlues do the following terms reduce to? xor-pir true,true? xor-pir true,flse? xor-pir flse,true? xor-pir flse,flse? Show the steps of reduction in the computtion of (xor-fun3). [You cn use the previous reductions nd those from prt () s single steps.] Give n informl definition of wht xor-fun does: for which numers n does (xor-funn) true,true? (10) nswer: xor-pir true,true true,flse xor-pir true,flse flse,true xor-pir flse,true true,true xor-pir flse,flse flse,flse Turn Over

10 xor-fun3 3xor-pir true,true xor-pir(xor-pir(xor-pir true,true )) xor-pir(xor-pir true,flse ) xor-pir flse,true true,true (xor-funn) reduces to true,true if n is divisile y 3, to true,flse if the reminder of division of n y 3 is 1, nd to flse,true if the reminder is 2. (c) In the context of complexity theory, explin wht it mens for decision prolem to elong to the clsses: P, NP, NP-complete. (7) nswer: prolem elongs to the clss P if there is Turing Mchine tht lwys termintes in polynomil time nd decides ech instnce of the prolem. It elongs to NP if either of the following equivlent conditions hold: (i) There is non-deterministic Turing Mchine tht runs in polynomil time nd decides every instnce of the prolem. (ii) There is deterministic Turing Mchine tht runs in polynomil time nd checks solutions to instnces of the prolem: when we give it s input n instnce of the prolem nd cndidte solution, it termintes in n ccepting sttes if nd only if the solution is correct. prolem is NP-complete if it elongs to NP nd every NP prolem cn e reduced in polynomil time to it. End