Computer Science 236 Fall Nov. 11, 2010

Similar documents
CS525 Winter 2012 \ Class Assignment #2 Preparation

Non-context-Free Languages. CS215, Lecture 5 c

AXIOMS FOR THE INTEGERS

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

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

Discrete Structures. Fall Homework3

Dynamic Programming Algorithms

Dynamic Programming Algorithms

1. Chapter 1, # 1: Prove that for all sets A, B, C, the formula

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

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

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

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

CSE 20 DISCRETE MATH WINTER

We will give examples for each of the following commonly used algorithm design techniques:

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Notes for Recitation 8

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.

CIT3130: Theory of Computation. Regular languages

Write an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression

Framework for Design of Dynamic Programming Algorithms

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

Ambiguous Grammars and Compactification

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Solutions to Homework 10

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science

1 Matchings in Graphs

Lecture 22 Tuesday, April 10

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

Ma/CS 6b Class 26: Art Galleries and Politicians

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

HW Graph Theory SOLUTIONS (hbovik) - Q

Lecture 6: Sequential Sorting

II (Sorting and) Order Statistics

SET DEFINITION 1 elements members

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Recursively Enumerable Languages, Turing Machines, and Decidability

Figure 4.1: The evolution of a rooted tree.

Indicate the option which most accurately completes the sentence.

Section 1.4 Proving Conjectures: Deductive Reasoning

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Lecture 2 Finite Automata

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

Fall Recursion and induction. Stephen Brookes. Lecture 4

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

8.2 Paths and Cycles

Worst-case running time for RANDOMIZED-SELECT

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

Math 454 Final Exam, Fall 2005

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

31.6 Powers of an element

Do you remember any iterative sorting methods? Can we produce a good sorting method by. We try to divide and conquer: break into subproblems

A Reduction of Conway s Thrackle Conjecture

Greedy Algorithms 1. For large values of d, brute force search is not feasible because there are 2 d

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

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

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

CS521 \ Notes for the Final Exam

1 Algorithm and Proof for Minimum Vertex Coloring

Module 11. Directed Graphs. Contents

Math Circle Beginners Group October 18, 2015 Solutions

Mathematical Induction

CSE 21 Spring 2016 Homework 5. Instructions

(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Math Introduction to Advanced Mathematics

COUNTING THE NUMBER OF WINNING BINARY STRINGS IN THE 1-DIMENSIONAL SAME GAME. Department of Mathematics Oberlin College Oberlin OH 44074

Recursive Definitions Structural Induction Recursive Algorithms

1. Find f(1), f(2), f(3), and f(4) if f(n) is defined recursively by f(0) = 1 and for n = 0, 1, 2,

9.5 Equivalence Relations

14 More Graphs: Euler Tours and Hamilton Cycles

Total Points: 60. Duration: 1hr

CSE 20 DISCRETE MATH. Winter

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

15.4 Longest common subsequence

Notebook Assignments

Line Graphs and Circulants

Theory Bridge Exam Example Questions Version of June 6, 2008

Selection (deterministic & randomized): finding the median in linear time

Math 170- Graph Theory Notes

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

THEORY OF COMPUTATION

Solutions to In Class Problems Week 5, Wed.

Algorithms Exam TIN093/DIT600

4 Fractional Dimension of Posets from Trees

1 Digraphs. Definition 1

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Theory of Computation, Homework 3 Sample Solution

Treewidth and graph minors

2. CONNECTIVITY Connectivity

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

Notes for Comp 454 Week 2

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

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

Transcription:

Computer Science 26 Fall Nov 11, 2010 St George Campus University of Toronto Assignment Due Date: 2nd December, 2010 1 (10 marks) Assume that you are given a file of arbitrary length that contains student records for CSC26 Each line of the file has the following format: LastName,FirstName,Average There are no spaces and commas are the separators on each line Assume that the only characters in the file are upper case letters, numerals (0-9) and commas and that the file is sorted by decreasing average You need to find some information out about the students in the class The easiest way to do this is to write a regular expression that matches the information you need (much like grep in Unix) If possible, construct a regular expression to extract the information If no such regular expression exists, prove why not [Note: you may use the notation to represent any alphabetic symbol and to represent any numeric symbol] (a) (2 marks) All those people whose last name begins with or If you were more specific about the number of digits, ie, ensuring that the name is non-empty or that the average is 2 or digits that is fine as well (b) (2 marks) All those people who are passing the course!" (c) (2 marks) All those people who are failing the course ' ()* + $&%%" (d) (4 marks) Determine whether there are more people passing the course than failing the course [Hint: notice that the entries are sorted by from largest to smallest average] We can first use two variables to represent the regular expressions that denote all those people passing the course and all those failing the course, respectively (we know what these expressions are from (b) and (c)) Let F represent failing and P represent passing Then what we :9<;> want is an expression to represent all those files that satisfy, where,-0/214576 8 Can this be done? No We can prove this using the Pumping Lemma Proof by contradiction Assume that there exists some regular expression that denotes,, then there must also exist some FSA to accept, Assume that such an FSA has?

; % * 9 states Now consider some file that has people passing, where? and people failing This file will be accepted by the DFA since it satisfies the requirements of more people passing than failing We split into three pieces as required by the pumping lemma: - We don t know the exact decomposition of, but by the lemma? and is nonempty By the pumping lemma, files of the form must also be in, Now take -%, the string must also be in, and since is non-empty this implies that the DFA accepts a string with either an equal number of people passing or fewer people passing than failing contradicting the definition of, Therefore,, is not regular 2 (16 marks) For each of the following, give a regular expression that denotes the set of strings as well as a DFA that accepts it (a) -0/ /2% OR (b) -0/ /2% (c) -0/2%2 6 (d) '& -0/ / DFAs )(&)* neither 00 nor 11 appear as substrings of &%" &%" ( &%" % % % % both 00 and 11 appear as substrings of (%" % % %" ;%$ % and is odd % %" % % % %" % %""! starts and ends with the same letter ( %"

(12 marks) Consider a set S of strings over the alphabet <- /2% (a) Construct a DFA that accepts iff the decimal value of is divisible by 5 For example, your DFA should accept 0, 101, 1010 and 1111 but it should not accept 10, 1001, 1011 etc

(b) Use induction to prove that your DFA is correct We will do this by structural induction (induction on the length of the string would be fine, too) Let be: iff is empty iff % iff 8 - iff ) iff * & iff + We must prove for all strings in /2% Base case: - Then ends at and is not accepted as required Inductive step: Assume that holds, ie, that: & Let -, where /2% separately Case 1: -% Then: - iff is empty iff % iff iff ) iff * & iff + We will consider each case for -% and -0, %" iff is empty, ie, % %" iff %, ie, % %" iff, ie, ) - & %" iff ), ie, + & %" iff *, ie, & %" iff +, ie, * These hold because adding a low % bit multiplies the value of by 2 By inspection of the DFA, we can see that: and thus the claim holds Case 2: - Then: % - %" - %" - %" - %" - && %" - &

iff is empty, ie, iff %, ie, iff, ie, * - & iff ), ie, % & iff *, ie, ) & iff +, ie, + These hold because adding a low bit multiplies the value of by 2 and adds 1 By inspection of the DFA, we can see that: and thus the claim holds & - - - - - && - 4 (6 marks) Show that if is a regular language then is as well, ie, that the class of regular languages is closed under reversal There are two possible ways to do this One way is by induction, as follows Let M represent the FSA for and the FSA for if it exists Let S(n) be There exists an " that accepts the language - / 8 > WTS: S(n) is true Define - / 8 ' > Base Case: n0 Since -, > iff > accept or reject depending on whether IH: Assume for arbitrary that & and the single state machine can either? is true for all?, %? Inductive Step: WTS S(n) Notice that if - then -, therefore, - where and Since and, we can apply the inductive hypothesis, and each of these languages has a FSA that accepts them and therefore by the closure of concatenation, there exists a FSA to accept Alternatively, we can show how to construct an NFSA for Since is a regular language, there exists some DFA, that accepts it Now consider the following method to construct a NFSA to accept We keep the same however first we reverse the direction of all the transitions So -0/ - We then turn in into the final accepting state 5 - / of

$ Then, we construct a new initial state for and define final accepting state in we add an transition from ) - /25, ie, for each 5 (6 marks) A palindrome is a word that can be read forwards and backwards For example, bob, anna, kayak, radar Let be the alphabet of lower case English letters Consider the set 1 of palindromes from Let be the language consisting of the set of strings in 1 Determine whether is regular and prove your claim either by giving a description of how to build a DFA to accept or by constructing a contradiction is not regular Suppose that it were Then, by the pumping lemma, there is an such that for any string,, of length at least, -, where, - and for all $ %, Let - ( ( Clearly,, and $ So there exists such a, and and, and so consists entirely of ( s Because -, any 9 ; 9 % yields a $- ( 6 ( for which 6 (15 marks), and so is not in, which is a contradiction (a) (5 marks) Let 8 Prove that (That is, prove and prove ) We will first prove that So assume that So let * and be positive numbers such that * for all integers $ $0 So * for all integers $ So We will now prove that So assume that So let * and be positive numbers such that * for all integers $ So * for all integers $ So (b) (5 marks) Prove or disprove the following Conjecture Conjecture: For every 8, if, then (We define to be that function that maps to ) We will prove the conjecture Say that Let * and be positive numbers such that * for all integers $$ It is not hard to show, in fact, that * for all $, where * -! " / *2 Note that -! " /, so it suffices to show that * and * $ for all $ But this is true because $ *, and % * $ for all (c) (5 marks) Define 8 by - % % 2 $&% and - &% % Prove that by exhibiting particular constants * and, and proving that * for all $ Let - % % 2 $&% and - &%% We will show that for every $ )% % So let $ ) % % be an integer We have $ )% %, $)&'

* 1 1 $ $ so &% %, so )%% $) So it suffices to show that thus that $ % % % Since $$, we have and &% $&% $) &%% $)% %, so, and 7 (10 marks) Consider the following recurrence for a function that takes on nonnegative values and is defined on integers $ : if + * if :9 + Prove that is Note that it doesn t help to use the general theorem about divide-and-conquer recurrences You should present a particular constant * and prove that for all $ * Motivation: This recurrence actually comes up in the following situation Say we wish to find the median of distinct elements, using as few comparisons as possible More generally, say we wish to find the -th smallest of elements We could sort the numbers but this takes about comparisons Instead we do the following which, by the theorem proven in this question, uses comparisons: Divide the elements up into groups of 5 (don t worry now about what to do if isn t divisible by 5); find the median of each group of 5, using a linear in number of comparisons in total This gives us about median points Recursively find the median of these median points using about comparisons; call this element Using a linear in number of comparisons, compare every element to ; let be the set of elements!", and let $ be the set of elements %" Because of the way was chosen, each of & and ' must have at most *) ( elements If +!-,,, then recursively find the -th smallest element of, otherwise recursively find the /",, -th smallest element of ; this takes at most *) ( comparisons Let *-$* % (Note that we chose * by going through the proof and seeing what value of * would work) Let 1 be: * We will use complete induction to prove that 1 holds for every integer $ Let be an integer such that 1? holds for every integer?,? We will show $$ CASE 1: + For each such, - Since *, it is easy to check that * for each such i $$ CASE 1 2: 1 &%" * &%"" * 0 So we have - and 1 " hold, so '* We have ' * -! &% * *" - 1 &%"" " &%" %" So %" * %" * 1 &%" and 2 *! &%" * % * -* % * So 1 holds