Final Exam 2, CS154. April 25, 2010

Similar documents
Final Exam 1, CS154. April 21, 2010

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

Name: CS 341 Practice Final Exam. 1 a 20 b 20 c 20 d 20 e 20 f 20 g Total 207

Theory of Computations Spring 2016 Practice Final Exam Solutions

CS164: Midterm I. Fall 2003

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

To illustrate what is intended the following are three write ups by students. Diagonalization

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

1 Parsing (25 pts, 5 each)

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

1. [5 points each] True or False. If the question is currently open, write O or Open.

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

CS 44 Exam #2 February 14, 2001

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Multiple Choice Questions

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

Theory Bridge Exam Example Questions Version of June 6, 2008

Turing Machine Languages

CpSc 421 Final Solutions

Theory of Computation, Homework 3 Sample Solution

CSC-461 Exam #2 April 16, 2014

Theory of Programming Languages COMP360

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Recursively Enumerable Languages, Turing Machines, and Decidability

CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY

CT32 COMPUTER NETWORKS DEC 2015

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

Homework 1 Due Tuesday, January 30, 2018 at 8pm

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Computer Sciences Department

Section 1.7 Sequences, Summations Cardinality of Infinite Sets

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

CS402 - Theory of Automata Glossary By

CS525 Winter 2012 \ Class Assignment #2 Preparation

Section 2.4 Sequences and Summations

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Midterm Exam. CSCI 3136: Principles of Programming Languages. February 20, Group 2

1. Lexical Analysis Phase

Structure of Programming Languages Lecture 3

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

Problems, Languages, Machines, Computability, Complexity

CS 275 Automata and Formal Language Theory. First Problem of URMs. (a) Definition of the Turing Machine. III.3 (a) Definition of the Turing Machine

Midterm I (Solutions) CS164, Spring 2002

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

UNIT I PART A PART B

MAT 090 Brian Killough s Instructor Notes Strayer University

Chapter 3. Set Theory. 3.1 What is a Set?

Theory and Compiling COMP360

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1

Reflection in the Chomsky Hierarchy

CS3102 Theory of Computation Problem Set 2, Spring 2011 Department of Computer Science, University of Virginia

CISC 4090 Theory of Computation

Midterm Exam 2 Solutions, C programming

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Sets. {1, 2, 3, Calvin}.

UNIVERSITY of OSLO. Faculty of Mathematics and Natural Sciences. INF 4130/9135: Algorithms: Design and efficiency Date of exam: 8th December 2016

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Quiz 1: Solutions J/18.400J: Automata, Computability and Complexity. Nati Srebro, Susan Hohenberger

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

Turing Machines, continued

MITOCW watch?v=4dj1oguwtem

Notes on Turing s Theorem and Computability

COS 126 General Computer Science Spring Written Exam 2

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Lecture 5: The Halting Problem. Michael Beeson

CSCI 340: Computational Models. Turing Machines. Department of Computer Science

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Theory of Computations Spring 2016 Practice Final

Compiler Construction

CSE 120. Computer Science Principles

chapter 14 Monoids and Automata 14.1 Monoids GOALS Example

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets.

Assignment No.4 solution. Pumping Lemma Version I and II. Where m = n! (n-factorial) and n = 1, 2, 3

t!1; R 0! 1; R q HALT

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Actually talking about Turing machines this time

ˆ The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

CMSC Theory of Algorithms Second Midterm

announcements CSE 311: Foundations of Computing review: regular expressions review: languages---sets of strings

Lexical Analysis. Lecture 2-4

Variants of Turing Machines

Draw a diagram of an empty circular queue and describe it to the reader.

SWEN 224 Formal Foundations of Programming

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

YOUR NAME PLEASE: *** SOLUTIONS ***

Decidable Problems. We examine the problems for which there is an algorithm.

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

From Theorem 8.5, page 223, we have that the intersection of a context-free language with a regular language is context-free. Therefore, the language

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Compilers and computer architecture From strings to ASTs (2): context free grammars

Compiler Construction LECTURE # 3

Computer Science 236 Fall Nov. 11, 2010

CS 3410 Ch 7 Recursion

Transcription:

inal Exam 2, CS154 April 25, 2010 Exam rules. he exam is open book and open notes you can use any printed or handwritten material. However, no electronic devices are allowed. Anything with an on-off switch must be turned off. here is one exception: you can use a music player as long as nobody else can hear it and you just put it on shuffle and do not use its controls during the exam. About the problems. hese problems are similar to your homework problems. he same conventions about alphabets, etc. that were used on the homework will apply here. Scoring. en problems, 10 points each, total 100 points. 1. Give a regular expression matching exactly those strings accepted by the following NA: Answer: a b aa aa ba. here are also other correct answers, of course. 1

2. Convert the following NA to an equivalent DA: Answer: 2

3. Which of the following languages are regular? Circle the letter of each regular language (more than one is regular). In each example, valid just means, has the right form for, e.g. a valid U.S. phone number has a certain form involving digits, parentheses, and dashes, regardless of whether it actually connects to a working telephone; a valid credit card number satisfies certain relations between the digits but does not have to belong to an individual with good credit. (a) the set of syntactically correct (compilable) Java programs. No, because this involves checking matching parentheses (as well as other constructions that require something to match) (b) the set of valid IP addresses. Yes, these follow a simple pattern with a fixed number of characters. (c) the set of valid credit card numbers. Yes, for two reasons. irst, the set of valid credit card numbers is finite and any finite set is regular. hat answer, of course, is of no practical value. More usefully, credit card numbers have a fixed number of digits, so we can remember the digits so far seen in a state of the machine, and perform any computation we want with those digits. (d) the set of palindromes (strings equal to their reverse) No, we used the pumping lemma to show this set is not regular. (e) the set of valid social security numbers. Yes, same reasons as (c). 4. Convert the following grammar to an equivalent PDA: S asbb SS ɛ Answer produced by the textbook algorithm: he starting state is 0, the only accepting state is 1, and the rules are as follows. 0, ɛ, ɛ 1, S 1, a, a 1, ɛ 1, b, b 1, ɛ 1, ɛ, S 1, asbb 1, ɛ, S 1, SS 1, ɛ, S 1, ɛ 3

5. A recipe has two parts: a list of ingredients and a list of instructions. Each line of the ingredient list (i.e. each part of the ingredient list between two newlines, or between the start and the first newline) has the form number, followed by unit, followed by name, followed optionally by information in parentheses, as illustrated by this ingredient list: 2 C milk 1 C egg whites (beaten) 1 lb butter (melted) 1/2 C sugar In this problem you are asked to give a grammar that describes the format of a recipe ingredient list. (We will ignore the instruction list part of a recipe for now.) he alphabet should be the ASCII alphabet. he grammar should not try to generate English words, but allow any sequence of letters as an ingredient, i.e. if we replace butter by szyefj in the above example, it is OK if that recipe list is generated. he grammar just has to enforce the rules mentioned above. Note that the recipe list is really just one string (that happens to contain some newline characters). he empty ingredient list is not OK. he possible units, however, are not arbitrary strings you cannot replace 1 C by 1 Z. You cannot even write 1 stick butter instead of 1/4 lb butter. (his would be necessary if you want to write a program to scale up a recipe to any number of servings.) S L Newline S ɛ L Number Unit String Optional Optional (String) ɛ Number Digit Number raction ɛ raction Digit/Digit Unit C bsp tsp t oz lb g qt gal l String Letter More More Letter More ɛ Letter a b c... z A... Z 4

6. Please use the pumping lemma to prove that the set L of αα such that α is any string of a s and b s is not regular. or example, abaaba is in L but abbaab is not. Answer: Assume, for proof by contradiction, that L is regular. Let N be as in the pumping lemma. Choose w = a N b N a N b N. hen w is in L. According to the pumping lemma we have w = xyz with xy N and y 1 and xy j z L for j = 0, 1, 2,.... Since xy N and the first N characters of w are a, we must have y = a k, and k > 0 since y 1. hen xy 2 z = a N+k b N a N b N, which must belong to L by the pumping lemma, but which does not belong to L since it is not of the form αα, since its first half matches a b but the second half starts with b, then has some a s, and then more b s. hat completes the proof. 5

7. Please write a uring machine (program) that erases the last half of its input. If the input has an odd number of characters, it erases the middle character as well as those following. or example, if started with aaaabbbb, it terminates with aaaa on the tape, and if started with aaaabaaaa it terminates with aaaa on the tape. Please comment your code so it won t take me all day to figure it out. Assume the input alphabet is {a, b}. Answer: 0,a->c,1,R 0,b->d,1,R 1,a->a,1,R 1,b->b,1,R 1,_->_,2,L 2,a->3,_,L 2,b->3,_,L 2,c->3,_,L 2,d->3,_,L 3,a->3,a,L 3,b->3,b,L 3,c->0,c,R 3,d->0,d,R 0,_->4,_,L 4,c->4,a,L 4,d->4,b,L // replace a by c // and b by d // and move right // back up when you hit blank // erase the last character // even if it was the middle character // and move left // without modifying the tape // until you hit c or d // and loop // done erasing, // move left replacing c by a // and d by b Halt when you get to the left end of the tap, when you will read the triangle marker. (No instruction is necessary for that.) You could hit the triangle in state 3 if there was only one character of input, but that s OK. 6

8. rue or false: (a) It s impossible to write a Java program that takes Java programs e as inputs, and produces the same output as program e would produce. (Here the output of a Java program is what, if anything, it prints to the console.) (b) It s impossible to write a Java program that takes uring machines e as inputs, and prints out 1 if uring machine e halts (with no input) and 0 if it does not. (c) It s impossible to write a Java program that takes Java programs e as inputs, and prints out 1 if program e would eventually print something to the console, and 0 if not. (d) It s impossible to write a uring machine that would take Java programs e as inputs, and produce the same output as program e would produce. (e) It s impossible to write a Java program that takes as input a Java program e and a number k, and outputs 1 if the e outputs k (before printing anything else, although it may go on outputting other characters after printing the digits of k), and 0 otherwise. 9. Please classify the following sets as either recursive or r.e. (recursively enumerable), as in the homework. You do not have to justify or explain your answers. (a) he set of palindromes (strings equal to their reverses, such as racecar). Recursive we can write a program to test whether a string is a palindrome. (b) he set of strings accepted by a particular finite automaton. Recursive just feed the input to the machine and see if it is in an accepting state when the input is gone. here is no question of waiting for it to finish, it takes exactly as many steps as the input has characters. (c) he set of strings accepted by a particular uring machine (assume here that I have listed a machine with several thousand instructions that I do not expect you to read and analyze). r.e.; without analyzing the particular machine, for all we know it is a universal machine, which would recognize an r.e. but not recursive set. (d) he set of n such that, somewhere in the decimal expansion of π, there occurs a string of n consecutive 7 s. r.e., because if there is a string of n sevens, we will find it eventually, but if there is not, we don t know when to stop looking, in the present state of mathematical knowledge. 7

(e) he set of Java programs that produce at least five characters of output to the console. r.e., because if five characters are eventually produced, we can accept that input string; but we can t say recursive, because we have no program to tell us whether five characters will be eventually produced, and indeed no such program exists, because we can reduce the halting problem to this set: let (e) be the program that prints 1234 and then runs e at input e; if it halts it prints 5. hen e belongs to the halting set if and only if (e) prints at least five characters of output. Hence the set in this problem is not recursive. 10. Consider the Subset Product Problem. he input is a finite set A of positive integers and a positive integer K. he problem is to determine A has a subset B such that the product of the elements of B is equal to K. or example, if A = {1, 3, 5, 7, 11, 17}, and K = 165, we could take B = {3, 5, 11}, but if K = 8 then there is no subset B of this particular A meeting the requirement. Note, numbers are represented in ordinary decimal notation for purposes of this problem. Is this problem in P, or is it in N P, or is it in Co-N P? Briefly explain your answer. Answer: it is in N P, because a non-deterministic uring machine can first generate a subset B of its input A, and then check (in polynomial time) whether B satisfies the required condition. We cannot say that this problem is in P, because there is no (apparent) algorithm to generate the required set B (and generating all of the subsets would take exponential time). In fact this problem is known to be N P -complete, so it is in Pif and only if all N P problems are in P. 8