COT 3100 Spring 2010 Midterm 2

Similar documents
ELEC-270 Solutions to Assignment 5

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

CS525 Winter 2012 \ Class Assignment #2 Preparation

(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

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

Mathematical Induction

Multiple-choice (35 pt.)

Verifying Safety Property of Lustre Programs: Temporal Induction

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

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

CSE 20 DISCRETE MATH WINTER

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

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

Discrete Mathematics Lecture 4. Harper Langston New York University

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

Mathematical Induction

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

Indicate the option which most accurately completes the sentence.

THE PRINCIPLE OF INDUCTION. MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin

Solution : a) C(18, 1)C(325, 1) = 5850 b) C(18, 1) + C(325, 1) = 343

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Lecture Notes on Induction and Recursion

Fall Recursion and induction. Stephen Brookes. Lecture 4

CSC Discrete Math I, Spring Sets

4&5 Binary Operations and Relations. The Integers. (part I)

Solution to Graded Problem Set 4

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

Midterm Exam Review. CS231 Algorithms Handout # 23 Prof. Lyn Turbak November 5, 2001 Wellesley College

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion

Outline. Introduction. 2 Proof of Correctness. 3 Final Notes. Precondition P 1 : Inputs include

HMMT February 2018 February 10, 2018

Recursive Definitions Structural Induction Recursive Algorithms

CmpSci 187: Programming with Data Structures Spring 2015

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

Computer Science 236 Fall Nov. 11, 2010

CS171 Midterm Exam. October 29, Name:

CSC 284/484 Advanced Algorithms - applied homework 0 due: January 29th, 11:59pm EST

CS103 Spring 2018 Mathematical Vocabulary

CSE Discrete Structures

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class.

Solutions to In-Class Problems Week 4, Fri

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

Greedy algorithms is another useful way for solving optimization problems.

Discrete Mathematics Exam File Fall Exam #1

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

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

1 Definition of Reduction

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

Discrete Mathematics Course Review 3

Section 6.3: Further Rules for Counting Sets

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures

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

CSC 1351: Quiz 6: Sort and Search

Test 1, Spring 2013 ( Solutions): Provided by Jeff Collins and Anil Patel. 1. Axioms for a finite AFFINE plane of order n.

STUDENT NUMBER: MATH Final Exam. Lakehead University. April 13, Dr. Adam Van Tuyl

CS 341 Homework 1 Basic Techniques

Matching Theory. Figure 1: Is this graph bipartite?

Today. Finish Euclid. Bijection/CRT/Isomorphism. Review for Midterm.

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,

8/22/12. Outline. Backtracking. The Eight Queens Problem. Backtracking. Part 1. Recursion as a Problem-Solving Technique

Solutions to the Second Midterm Exam

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

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 12

Lecture 6,

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Advanced Induction. Drawing hands by Escher. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

Prelim One Solution. CS211 Fall Name. NetID

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

UNC Charlotte 2010 Comprehensive

ECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm

CS 151 Complexity Theory Spring Final Solutions. L i NL i NC 2i P.

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

1 / 43. Today. Finish Euclid. Bijection/CRT/Isomorphism. Fermat s Little Theorem. Review for Midterm.

Math 485, Graph Theory: Homework #3

CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

MATH20902: Discrete Maths, Solutions to Problem Set 1. These solutions, as well as the corresponding problems, are available at

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions)

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

Overview. A mathema5cal proof technique Proves statements about natural numbers 0,1,2,... (or more generally, induc+vely defined objects) Merge Sort

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Math236 Discrete Maths with Applications

Notes for Recitation 8

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1

Infinity and Uncountability. Countable Countably infinite. Enumeration

Midterm solutions. n f 3 (n) = 3

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Comparing sizes of sets

Lecture 7. SchemeList, finish up; Universal Hashing introduction

CMPSCI 187: Programming With Data Structures. Lecture #15: Thinking Recursively David Mix Barrington 10 October 2012

adjacent angles Two angles in a plane which share a common vertex and a common side, but do not overlap. Angles 1 and 2 are adjacent angles.

2009 HMMT Team Round. Writing proofs. Misha Lavrov. ARML Practice 3/2/2014

Transcription:

COT 3100 Spring 2010 Midterm 2 For the first two questions #1 and #2, do ONLY ONE of them. If you do both, only question #1 will be graded. 1. (20 pts) Give iterative and recursive algorithms for finding the n th term of the sequence {a n defined by a 0 = 2, a 1 = 2 and a n+1 = a n (a n-1 ) 2. Which algorithm is more efficient and why? : + Input: n, a 0 = 2, a 1 = 2, a n+1 = a n (a n-1 ) 2 ; + Output: The n th term of the sequence {a n. Iterative algorithm: for (int i = 2; i <=n; i++) { result = a 1 * a 0 * a 0 ; a 0 = a 1 ; a 1 = result; return result; Recursive algorithm: int a(int k) { if (k <= 1 ) return 2; else return a(k-1)*a(k-2)*a(k-2); return result = a(n); Which algorithm is more efficient and why? Iterative algorithm performs (n-2) iterations and in each iteration, updates values of 3 variables, thus its time complexity is O(n). The recursive algorithm, in order to find a(n), loops into itself 3 times to find a(n-1) and two a(n-2). To find a(n-1), it again loops into itself 3 times to find a(n-2) and two a(n-2), so on and so forth. Thus, its creates a complete 3-leaf tree with height n. Thus, the total time complexity is O(3 n ). Therefore, the iterative algorithm is more efficient. 1

2. (20 pts) Give iterative and recursive algorithms for determining whether a string is a palindrome or not. (Note: A string is a palindrome if it can be read the same way in either direction, e.g., ABBA, madam, level ). + Input: A string w of length n; + Output: YES if w is a palindrome, NO otherwise. Iterative algorithm w is a palindrome iff (w[i] == w[n+1-i]) for any i th index from 1 to n. Therefore, we test this property on every i th position and stop when the index i hits the middle of the string w. int middle = n/2; for(int i = 1; i<=middle; i++) { if ( w[i]!= w[n+1-i] ) return NO; return YES; Recursive algorithm A string w of length k is a palindrome iff (w[1] == w[k]) and the substring w[2...k-1] is also a palindrome. This observation suggests the following recursive algorithm boolean ispal(w, k) { if (k==0 k==1) return YES; return (w[1] == w[k]) && ispal(w[2...k-1], k-2); 2

3. (10 pts) Prove by induction that (x - y) divides x n - y n for any integer n 1. + Let P(n) be the statement: (x - y) divides x n - y n. + Basis step: n = 1. It is clear that (x - y) divides x 1 - y 1 (= x - y). + Inductive step: - Assume P(n) is true. We will prove that P(n+1) is also true, i.e., (x-y) divides x n+1 - y n+1. - Now: x n+1 - y n+1 = x n+1 - xy n + xy n - y n+1 = x(x n - y n ) + y n (x - y) - Since P(n) is true, we have (x - y) divides x n - y n, which implies (x-y) divides x(x n - y n ). In addition, (x - y) also divides y n (x - y). Therefore, (x - y) divides x(x n - y n ) + y n (x - y), which means P(n+1) is also true. 4. (20 pts) Let S be the subset of the set of ordered pairs of integers defined recursively by: Basis step: (0,0) S. Recursive step: If (a,b) S then (a+4, b+5) S and (a-2, b-7) S. a. Prove by strong induction on the number of applications of recursive steps that a b is even for any (a,b) S. Let n be the number of applications of recursive steps. We will show that for any (a,b) S, a is even which implies a b is even for any (a,b) S Basis step n = 0. It is clear that 0 is even. Thus the basis step is true. Inductive step + Assume that for all 0 < n N, a is even for any (a,b) S. We will show that a' is also an even number for any (a',b') generated in step (N+1). + Consider the two following cases. Case #1: a' is derived by (a+4) for some number a in step N and based on the assumption, we have a is even. Thus a' = a + 4 is also even. Case #2: a' is derived by (a-2) for some number a in step N and based on the assumption, we have a is even. Thus a' = a - 2 is also even. The inductive step is complete. a. Prove by structural induction that 9 a+ b for any (a,b) S Basis step It is clear that 9 0 + 0. The basis step is true. Inductive step + We will prove that, in Recursive Step, any (a', b') obtained from (a,b) S satisfies: 9 (a' + b'). Since (a', b') is derived from (a,b), it must be obtained by either (a+4,b+5) or (a-2,b-7). Thus, (a' + b') equals either (a+b+9) or (a+b-9) (*). + Now, because (a,b) is previously in S, we have 9 (a + b) which implies 9 divides both (a+b+9) and (a+b-9). This fact also implies that 9 (a' + b') due to (*). 3

5. (10 pts) Give the recursive definition of the sequence {a n, n = 1,2,3, if a. a n = 4n - 9 a 1 = -5; a n+1 = 4(n+1) - 9 = 4n - 9 + 4 = a n + 4; b. a n = n 2 2n a 1 = -1; a n+1 = (n+1) 2-2(n+1) = n 2 + 2n + 1-2n - 2 = n 2-2n + 2n - 1 = a n + 2n - 1 For questions #6 and #7, please justify your answers. Answers with only numbers will result in no point. 6. (10 pts) How many positive integers from 1000 to 9999 inclusive are divisible by 9 but not by 4? "A number divisible by 9 but not by 4" means a number divisible by 9 but not 36(=4*9). Therefore, we just need to find the number of integers divisible by 9 and subtract the number of those divisible by 36. + Number of integers divisible by 9 + Number of integers divisible by 36 + Thus, the answer is 1000-250 = 750. 7. a. (10 pts) A coin is flipped 20 times where each flip comes up either heads or tails. How many possible outcomes contain at most 5 tails? + Number of outcomes contain 0 tails: C(20,0) + Number of outcomes contain 1 tails: C(20,1) + Number of outcomes contain 2 tails: C(20,2) + Number of outcomes contain 3 tails: C(20,3) + Number of outcomes contain 4 tails: C(20,4) + Number of outcomes contain 5 tails: C(20,5) Total possible outcomes = C(20,0) + C(20,1) + C(20,2) + C(20,3) + C(20,4) + C(20,5) 4

b. (10 pts) What is the least number of people needed to form a group in which we can surely conclude that there are at least 3 people having the same birthday? Assume that there are 365 days in a year. Based on Pigeonhole Principle, the least number of people we need to choose is one more than the number of days in (3-1) years. Answer = 365*(3-1) + 1 8. (10 pts) Find the error in this "proof" of the clearly false claim: "Every set of lines in the plane, no two of which are parallel, meet in a common point". "Proof": Let P(n) be the statement that "Every set of n lines in the plane, no two of which are parallel, meet in a common point". We will try to prove that P(n) is true for n 2. 1. Basis step: P(2) is true due to the definition of parallel lines. 2. Inductive step: Assume that P(k) is true, i.e., every set of k lines in the plane, no two of which are parallel, meet in a common point. We will try to prove that P(k+1) is also true. 3. Consider the set S of (k+1) distinct lines in the plane, no two of which are parallel. Since P(k) is true, the first k lines of S must meet in a point p 1, and the last k lines of S must meet in a point p 2. 4. If p 1 is different from p 2, then all lines containing both of them must be exactly the same since two distinct points determine a line. This implies the second line, the third line,..., and the k th lines of S are the same, contradicting to the fact that they are all distinct. 5. Therefore, p 1 and p 2 must be the same point, i.e., (k+1) distinct lines in the plane, no two of which are parallel, meet in a common point, which means P(k+1) is true. The problem is at step #4. We cannot show that P(2) implies P(3). When k = 2, the first two lines must meet in a common point p1 and the last two lines must meet in a common point p2. But in this case, p 1 and p 2 do not have to be the same, because only the second line is common to both sets of lines. 5

Bonus questions: 1. (5pts) Show that is Θ( ) for any positive integer k > 1. Choose c 1 = and c 2 =, we have = Thus, = Θ( ) c 1 c 2. 2. (5 pts) Prove that if five points are selected from the interior of a 1 1 square, then there are two points whose distance is less than. We first divide the square into 4 smaller squares (by connecting the corresponding middle points) and then select 5 points from the interior of the "big" square. By Pigeonhole Principle, there must be a "small" square containing at least 2 points. In addition, the maximum distance in this "small" square cannot exceed the length of the diagonal, which is. Thus, any two points inside this "small" square has distance less than. 6