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

Similar documents
CS103 Handout 14 Winter February 8, 2013 Problem Set 5

CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5

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

CS103 Handout 16 Winter February 15, 2013 Problem Set 6

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

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

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

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

Theory Bridge Exam Example Questions Version of June 6, 2008

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed)

CS103 Spring 2018 Mathematical Vocabulary

CS103 Handout 39 Winter 2018 February 23, 2018 Problem Set 7

Problem One: A Quick Algebra Review

Turing Machines Part Two

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

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

Skill 1: Multiplying Polynomials

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Theory of Computations Spring 2016 Practice Final Exam Solutions

Context-Free Grammars

Chapter Seven: Regular Expressions

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Midterm I - Solution CS164, Spring 2014

CS164: Midterm I. Fall 2003

CS 181 EXAM #1 NAME. You have 90 minutes to complete this exam. You may state without proof any fact taught in class or assigned as homework.

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

CSE 105 THEORY OF COMPUTATION

Hardware versus software

CS2 Practical 2 CS2Ah

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

Announcements. Written Assignment 2 due today at 5:00PM. Programming Project 2 due Friday at 11:59PM. Please contact us with questions!

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

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Final Exam May 8, 2018

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Final Exam 1, CS154. April 21, 2010

MITOCW watch?v=kz7jjltq9r4

CS 125 Section #10 Midterm 2 Review 11/5/14

CSE 105 THEORY OF COMPUTATION

14.1 Encoding for different models of computation

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Theory of Computations Spring 2016 Practice Final

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

CS143 Midterm Fall 2008

Finite Automata Part Three

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

CS314: FORMAL LANGUAGES AND AUTOMATA THEORY L. NADA ALZABEN. Lecture 1: Introduction

Final Exam 2, CS154. April 25, 2010

6 NFA and Regular Expressions

Context-Free Grammars

Extra Practice Problems 2

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Linked Lists. What is a Linked List?

Recursively Enumerable Languages, Turing Machines, and Decidability

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Languages and Automata

(Refer Slide Time: 0:19)

Theory of Computation

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

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

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

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08008 INFORMATICS 2A: PROCESSING FORMAL AND NATURAL LANGUAGES

CSC-461 Exam #2 April 16, 2014

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

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

CS 373: Combinatorial Algorithms, Spring 1999

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Midterm I (Solutions) CS164, Spring 2002

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

CS40-S13: Functional Completeness

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

Programming Lecture 3

Multiple Choice Questions

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

CSE Qualifying Exam, Spring February 2, 2008

MITOCW watch?v=hverxup4cfg

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

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

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

III. Supplementary Materials

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Lexical Error Recovery

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

Material from Recitation 1

Algorithms, Probability, and Computing Midterm Exam HS17

Theory of Programming Languages COMP360

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

Mathematical Logic Part One

Transcription:

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1 We strongly recommend that you work through this exam under realistic conditions rather than just flipping through the problems and seeing what they look like. Setting aside three hours in a quiet space with your notes and making a good honest effort to solve all the problems is one of the single best things you can do to prepare for this exam. It will give you practice working under time pressure and give you an honest sense of where you stand and what you need to get some more practice with. This practice final exam is a (slightly modified) version of the final exam we gave out the last time we taught CS103 (Fall 2016). The exam policies are the same for the midterms closed-book, closed-computer, limited note (one double-sided sheet of 8.5 11 paper decorated however you'd like). You have three hours to complete this exam. There are 50 total points. Question Points Graders (1) Set Theory and Logic / 8 (2) Graphs and Natural Numbers / 6 (3) Binary Relations and Induction / 10 (4) Regular and Context-Free Languages / 13 (5) R and RE Languages / 10 (6) P and NP Languages / 3 / 50

2 / 14 Problem One: Set Theory and Logic (8 Points) An independence system over a set A is a nonempty set I (A) with the following property: S I. (S) I. This question explores some properties of independence systems. i. (3 Points) Prove that if I is an independence system over a set A, then Ø I.

3 / 14 As a refresher from part (i) of this problem, an independence system over a set A is a nonempty set I (A) with the following property: S I. (S) I. ii. (5 Points) Let I₁ and I₂ be independence systems over the same set A. Prove that I₁ I₂ is also an independence system over A. For simplicity, you can use the fact that I₁ I₂ (A) without proof. However, since we haven't talked much about properties of set intersection in this course, if you want to use any other facts about set intersection, you'll need to prove them first.

4 / 14 Problem Two: Graphs and Natural Numbers (6 Points) On Problem Set Four, you explored bipartite graphs. As a refresher, a graph G = (V, E) is bipartite if there are sets V₁ and V₂ where all three of the following are true: V₁ and V₂ have no nodes in common (that is, V₁ V₂ = Ø). Every node v V belongs to at least one V₁ and V₂. Every edge in E has one endpoint in V₁ and the other endpoint in V₂. Now, consider the graph G N defined as follows: the nodes in G N are the natural numbers, and there's an edge between a pair of nodes u and v if and only if u + v is odd. This graph contains infinitely many nodes, which is unusual but nothing to worry about. Prove that G N is bipartite.

5 / 14 Problem Three: Induction and Binary Relations (10 Points) Given a binary relation R over a set A and a natural number n 1, we can define a new binary relation over A called the nth power of R, denoted R n. This relation is defined inductively as follows: xr 1 y if xry xr n+1 y if z A. (xrz zr n y). (Note that R n is only defined for n 1, and remember that if here means is defined as. ) i. (7 Points) Let R be an arbitrary binary relation over a set A. Your task is to prove the following statement: For any natural numbers m, n 1, and for any a, b, c A, if ar n b and br m c, then ar n+m c. To do so, we'd like you to use induction. Specifically, use induction to prove that the statement P(n) defined below is true for all natural numbers n 1: P(n) is the statement for any natural number m 1, and for any a, b, c A, if ar n b and br m c, then ar n+m c.

(Extra space for your answer to Problem Three, part (i), if you need it.) 6 / 14

7 / 14 The transitive closure of a binary relation R over a set A, denoted R +, is a binary relation over A defined as follows: xr + y if n N. (n 1 xr n y). ii. (3 Points) Let R be an arbitrary binary relation over a set A. Using your result from part (i) of this problem, prove that R + is transitive. (You can use the result from part (i) even if you weren't able to prove it.)

8 / 14 Problem Four: Regular and Context-Free Languages Consider the following language: (13 Points) L₁ = { w {a, b, c}* the last character of w appears nowhere else in w, and w 1 }. This is a variant on one of the languages you built an NFA for in Problem Set Six. Here are some sample strings in L₁: a b c aaaaac aabbaabbc ccbbccbba bac cbba Since this language is regular, it's possible to build a regular expression for it. i. (2 Points) Write a regular expression for L₁. (Hint: You probably don't have time to work through the state elimination algorithm on this exam. Try designing the regular expression from scratch.)

9 / 14 In many programming languages (C, C++, Python, Java, JavaScript, etc.), a string literal is a piece of text enclosed in double quotes, such as "Hi everybody!" or "Good luck on the exam!". Sometimes, you'll want to define a string that contains a double-quote character. In these languages, to do that, you escape the double-quote by preceding it with a backslash, like this: "Quoth the raven \"Nevermore.\"" This lets the compiler distinguish between the double-quotes inside a string and the double-quotes delimiting a string. As a consequence of this rule, any time you want to write a backslash character, you need to escape it as well by preceding it with a second backslash. For example, you might have a string like this: "The notation \"A \\ B\" denotes the difference of the sets A and B." Let Σ = {z, ", \} and consider this language L₂: Here are some sample strings in L2: "" "z" "\"" "\\" Here are some sample strings not in L2: "z (this string isn't closed) L₂ = { w Σ* w is a legal string literal }. "zz\"zz\\zz\"z" "\\\"" "\"zz\"" "\"\"" """ (the quote in the middle needs to be escaped) "\" (this string is unterminated that final double quote is escaped) \"zz" (the string doesn't begin with a double quote) "\z" (you cannot escape the letter z with a slash) "\\\z" (you cannot escape the letter z with a slash) This language happens to be regular, which is useful because many compilers use some form of finite automaton to find strings in source code. ii. (3 Points) Design an NFA for L₂.

10 / 14 According to old-school Twitter rules, all tweets need to be 140 characters or less. Let Σ be the alphabet of characters that can legally appear in a tweet and consider the following language: L₃ = { w Σ* w 140 }. This is the language of all legal tweets. The good news is that this language is regular. The bad news is that building a DFA for it would be a frustrating endeavor. iii. (4 Points) Prove that any DFA for L₃ must have at least 142 states. To do so, use the result you proved on Problem Set Seven that says that if you can find a set of 142 strings that are pairwise distinguishable relative to L₃, then any DFA for L₃ must have at least 142 states.

11 / 14 Let Σ = {a, b} and consider the following language: L₄ = { w Σ* w 4 0, and the first quarter of the characters in w contains at least one b }. For example, baaa L₄, bbbb L₄, abbbbbba L₄, bbbaaabbbaaa L₄, ababbbbbbbbb L₄, but abbb L₄, ε L₄, b L₄, aabbbbaa L₄, and aaabbbbbbbbb L₄. (For simplicity, I've underlined the first quarter of the characters in each string). iv. (4 Points) Write a CFG for L₄.

12 / 14 Problem Five: R and RE Languages (10 Points) Stanford's email system often tags messages with attachments as possible viruses by changing the subject to say something like [POSSIBLE VIRUS: ###]. You might wonder why the email system says something is a possible virus rather than just intercepting emails that really do contain viruses and blocking them from getting to their recipients. This question explores why. Let's imagine that there's some method that, if called, will do something nefarious to your computer. Imagine it's this method: private void dosomethingnefarious() Your job is to prove that it's impossible to write a method private boolean candosomethingnefarious(string program) that takes as input the source code of a program, then returns true if the program under some circumstance can call the dosomethingnefarious method and returns false otherwise. (This partially explains why you get the possible virus warning over email there's no general way to test whether a program can do nefarious things!) i. (4 Points) In the interests of time, we don't want you to write out a full formal proof of this result. Instead, do the following: In the space below, write a self-referential program P that uses the candosomethingnefarious method such that P does something nefarious if and only if it doesn't do something nefarious. You can assume you have access to a method mysource() that returns the source code of your program. Briefly explain why P does something nefarious if and only if it doesn't do something nefarious, addressing each direction of the implication.

13 / 14 iii. (6 Points) Below is a Venn diagram showing the overlap of different classes of languages we've studied so far. We have also provided you a list of numbered languages. For each of those languages, draw where in the Venn diagram that language belongs. As an example, we've indicated where Language 1 and Language 2 should go. No proofs or justifications are necessary, and there is no penalty for an incorrect guess. 1. Σ* 2. L D 3. { 1 m +1 n =1 m+n m, n N and m and n are even } 4. { 1 m +1 n =1 m+n m, n N and m 10 137 } 5. { 1 m +1 n =1 m+n m, n N and m + n 10 137 } 6. { M, w M is a TM, w is a string, and M accepts w within w 137 steps } 7. { M M is a TM and M halts on infinitely many inputs } 8. { M, w M is a TM, w is a string, M accepts at least one substring of w }

14 / 14 Problem Six: P and NP Languages (3 Points) We briefly covered the P and NP languages in our last week of class. Here's a quick series of true/false questions about them. Each correct answer is worth one point, and there is no penalty for an incorrect guess. You do not need to justify your answers. i. NP stands for not polynomial time and is the class of decision problems that cannot be solved in polynomial time. True False ii. All NP-hard problems are in NP. True False iii. If the halting problem is decidable, then P NP. True False We have one final question for you: do you think P = NP? Let us know in the space below. There are no right or wrong answers to this question we're honestly curious to hear your opinion! I think P = NP I think P NP