COT 3100 Spring 2010 Midterm 2

Size: px
Start display at page:

Download "COT 3100 Spring 2010 Midterm 2"

Transcription

1 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 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 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 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

4 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 = 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 Number of integers divisible by 9 + Number of integers divisible by 36 + Thus, the answer is = 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

5 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) (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 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 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

6 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 (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

ELEC-270 Solutions to Assignment 5

ELEC-270 Solutions to Assignment 5 ELEC-270 Solutions to Assignment 5 1. How many positive integers less than 1000 (a) are divisible by 7? (b) are divisible by 7 but not by 11? (c) are divisible by both 7 and 11? (d) are divisible by 7

More information

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall CSE 20 https://goo.gl/forms/1o 1KOd17RMoURxjn2 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Today's learning goals Explain the steps in a proof by mathematical and/or structural

More information

CS525 Winter 2012 \ Class Assignment #2 Preparation

CS525 Winter 2012 \ Class Assignment #2 Preparation 1 CS525 Winter 2012 \ Class Assignment #2 Preparation Ariel Stolerman 2.26) Let be a CFG in Chomsky Normal Form. Following is a proof that for any ( ) of length exactly steps are required for any derivation

More information

(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

(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 CS 70 Discrete Mathematics for CS Fall 2000 Wagner MT1 Sol Solutions to Midterm 1 1. (16 pts.) Theorems and proofs (a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are

More information

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

To illustrate what is intended the following are three write ups by students. Diagonalization General guidelines: You may work with other people, as long as you write up your solution in your own words and understand everything you turn in. Make sure to justify your answers they should be clear

More information

Mathematical Induction

Mathematical Induction Mathematical Induction Victor Adamchik Fall of 2005 Lecture 3 (out of three) Plan 1. Recursive Definitions 2. Recursively Defined Sets 3. Program Correctness Recursive Definitions Sometimes it is easier

More information

Multiple-choice (35 pt.)

Multiple-choice (35 pt.) CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need

More information

Verifying Safety Property of Lustre Programs: Temporal Induction

Verifying Safety Property of Lustre Programs: Temporal Induction 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 Verifying Safety Property of Lustre Programs: Temporal Induction Copyright 2008 Cesare Tinelli. These notes are copyrighted

More information

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

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory Proof Techniques Alphabets, Strings, and Languages Foundations of Computer Science Theory Proof By Case Enumeration Sometimes the most straightforward way to prove that a property holds for all elements

More information

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

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 CS 3512, Spring 2011 Instructor: Doug Dunham Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 Prerequisites: Calc I, CS2511 Rough course outline:

More information

CSE 20 DISCRETE MATH WINTER

CSE 20 DISCRETE MATH WINTER CSE 20 DISCRETE MATH WINTER 2016 http://cseweb.ucsd.edu/classes/wi16/cse20-ab/ Today's learning goals Explain the steps in a proof by (strong) mathematical induction Use (strong) mathematical induction

More information

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

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD Recap. Growth rates: Arrange the following functions in ascending order of growth rate: n 2 log n n log n 2 log n n/ log n n n Introduction Algorithm: A step-by-step way of solving a problem. Design of

More information

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

1. Chapter 1, # 1: Prove that for all sets A, B, C, the formula Homework 1 MTH 4590 Spring 2018 1. Chapter 1, # 1: Prove that for all sets,, C, the formula ( C) = ( ) ( C) is true. Proof : It suffices to show that ( C) ( ) ( C) and ( ) ( C) ( C). ssume that x ( C),

More information

Discrete Mathematics Lecture 4. Harper Langston New York University

Discrete Mathematics Lecture 4. Harper Langston New York University Discrete Mathematics Lecture 4 Harper Langston New York University Sequences Sequence is a set of (usually infinite number of) ordered elements: a 1, a 2,, a n, Each individual element a k is called a

More information

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

Write an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression Chapter 5 Dynamic Programming Exercise 5.1 Write an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression x 1 /x /x 3 /... x n 1 /x n, where

More information

Mathematical Induction

Mathematical Induction COMP 182 Algorithmic Thinking Mathematical Induction Luay Nakhleh Computer Science Rice University Chapter 5, Section 1-4 Reading Material [P (1) ^8k(P (k)! P (k + 1))]!8nP (n) Why Is It Valid? The well-ordering

More information

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

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont. Announcements CS43: Discrete Structures Strong Induction and Recursively Defined Structures Işıl Dillig Homework 4 is due today Homework 5 is out today Covers induction (last lecture, this lecture, and

More information

Indicate the option which most accurately completes the sentence.

Indicate the option which most accurately completes the sentence. Discrete Structures, CSCI 246, Fall 2015 Final, Dec. 10 Indicate the option which most accurately completes the sentence. 1. Say that Discrete(x) means that x is a discrete structures exam and Well(x)

More information

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

THE PRINCIPLE OF INDUCTION. MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin THE PRINCIPLE OF INDUCTION MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin The Principle of Induction: Let a be an integer, and let P(n) be a statement

More information

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

Solution : a) C(18, 1)C(325, 1) = 5850 b) C(18, 1) + C(325, 1) = 343 DISCRETE MATHEMATICS HOMEWORK 5 SOL Undergraduate Course College of Computer Science Zhejiang University Fall-Winter 2014 HOMEWORK 5 P344 1. There are 18 mathematics majors and 325 computer science majors

More information

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

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Please check your tutorial (TUT) section from the list below: TUT 101: F 11:30, MC 4042 TUT 102: M 10:30, MC 4042 TUT 103: M 11:30, MC 4058 TUT 104: F 10:30,

More information

Lecture Notes on Induction and Recursion

Lecture Notes on Induction and Recursion Lecture Notes on Induction and Recursion 15-317: Constructive Logic Frank Pfenning Lecture 7 September 19, 2017 1 Introduction At this point in the course we have developed a good formal understanding

More information

Fall Recursion and induction. Stephen Brookes. Lecture 4

Fall Recursion and induction. Stephen Brookes. Lecture 4 15-150 Fall 2018 Stephen Brookes Lecture 4 Recursion and induction Last time Specification format for a function F type assumption guarantee (REQUIRES) (ENSURES) For all (properly typed) x satisfying the

More information

CSC Discrete Math I, Spring Sets

CSC Discrete Math I, Spring Sets CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its

More information

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

4&5 Binary Operations and Relations. The Integers. (part I) c Oksana Shatalov, Spring 2016 1 4&5 Binary Operations and Relations. The Integers. (part I) 4.1: Binary Operations DEFINITION 1. A binary operation on a nonempty set A is a function from A A to A. Addition,

More information

Solution to Graded Problem Set 4

Solution to Graded Problem Set 4 Graph Theory Applications EPFL, Spring 2014 Solution to Graded Problem Set 4 Date: 13.03.2014 Due by 18:00 20.03.2014 Problem 1. Let V be the set of vertices, x be the number of leaves in the tree and

More information

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

Ma/CS 6b Class 26: Art Galleries and Politicians Ma/CS 6b Class 26: Art Galleries and Politicians By Adam Sheffer The Art Gallery Problem Problem. We wish to place security cameras at a gallery, such that they cover it completely. Every camera can cover

More information

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

Midterm Exam Review. CS231 Algorithms Handout # 23 Prof. Lyn Turbak November 5, 2001 Wellesley College CS231 Algorithms Handout # 23 Prof. Lyn Turbak November 5, 2001 Wellesley College Midterm Exam Review This handout contains some problems that cover material covered on the midterm exam. Reviewing these

More information

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

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion Consider the following recursive function: int what ( int x, int y) if (x > y) return what (x-y, y); else if (y > x) return what (x, y-x);

More information

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

Outline. Introduction. 2 Proof of Correctness. 3 Final Notes. Precondition P 1 : Inputs include Outline Computer Science 331 Correctness of Algorithms Mike Jacobson Department of Computer Science University of Calgary Lectures #2-4 1 What is a? Applications 2 Recursive Algorithms 3 Final Notes Additional

More information

HMMT February 2018 February 10, 2018

HMMT February 2018 February 10, 2018 HMMT February 2018 February 10, 2018 Combinatorics 1. Consider a 2 3 grid where each entry is one of 0, 1, and 2. For how many such grids is the sum of the numbers in every row and in every column a multiple

More information

Recursive Definitions Structural Induction Recursive Algorithms

Recursive Definitions Structural Induction Recursive Algorithms Chapter 4 1 4.3-4.4 Recursive Definitions Structural Induction Recursive Algorithms 2 Section 4.1 3 Principle of Mathematical Induction Principle of Mathematical Induction: To prove that P(n) is true for

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #9 John Ridgway February 26, 2015 1 Recursive Definitions, Algorithms, and Programs Recursion in General In mathematics and computer science

More information

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

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]: CSE 101 Homework 1 Background (Order and Recurrence Relations), correctness proofs, time analysis, and speeding up algorithms with restructuring, preprocessing and data structures. Due Thursday, April

More information

Computer Science 236 Fall Nov. 11, 2010

Computer Science 236 Fall Nov. 11, 2010 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

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

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

CSC 284/484 Advanced Algorithms - applied homework 0 due: January 29th, 11:59pm EST CSC 84/484 Advanced Algorithms - applied homework 0 due: January 9th, 11:59pm EST Grading: 84: 1 problem solved = A 484: problems solved = A, 1 problem solved = B This homework has different rules than

More information

CS103 Spring 2018 Mathematical Vocabulary

CS103 Spring 2018 Mathematical Vocabulary CS103 Spring 2018 Mathematical Vocabulary You keep using that word. I do not think it means what you think it means. - Inigo Montoya, from The Princess Bride Consider the humble while loop in most programming

More information

CSE Discrete Structures

CSE Discrete Structures CSE 2315 - Discrete Structures Homework 3- Solution - Fall 2010 Due Date: Oct. 28 2010, 3:30 pm Sets 1. Rewrite the following sets as a list of elements. (8 points) a) {x ( y)(y N x = y 3 x < 30)} {0,

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

More information

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE 332, Spring 2010, Midterm Examination 30 April 2010 CSE 332, Spring 2010, Midterm Examination 30 April 2010 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note. You may use a calculator for basic arithmetic only.

More information

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

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class. CIS 160 - Spring 2018 (instructor Val Tannen) Lecture 19 Thursday, March 29 GRAPH THEORY Graph isomorphism Definition 19.1 Two graphs G 1 = (V 1, E 1 ) and G 2 = (V 2, E 2 ) are isomorphic, write G 1 G

More information

Solutions to In-Class Problems Week 4, Fri

Solutions to In-Class Problems Week 4, Fri Massachusetts Institute of Technology 6.042J/18.062J, Fall 02: Mathematics for Computer Science Professor Albert Meyer and Dr. Radhika Nagpal Solutions to In-Class Problems Week 4, Fri Definition: The

More information

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

1. [5 points each] True or False. If the question is currently open, write O or Open. University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

More information

Greedy algorithms is another useful way for solving optimization problems.

Greedy algorithms is another useful way for solving optimization problems. Greedy Algorithms Greedy algorithms is another useful way for solving optimization problems. Optimization Problems For the given input, we are seeking solutions that must satisfy certain conditions. These

More information

Discrete Mathematics Exam File Fall Exam #1

Discrete Mathematics Exam File Fall Exam #1 Discrete Mathematics Exam File Fall 2015 Exam #1 1.) Which of the following quantified predicate statements are true? Justify your answers. a.) n Z, k Z, n + k = 0 b.) n Z, k Z, n + k = 0 2.) Prove that

More information

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms Chapter Summary Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms Section 5.1 Sec.on Summary Mathematical Induction Examples of Proof by Mathematical Induction Mistaken

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC 165 H1 Term Test 2 / L5101 Fall 2011 Duration: Aids Allowed: 60 minutes none Student Number: Family Name(s): Given Name(s): Do not turn this page until you have received the signal to start. In the

More information

1 Definition of Reduction

1 Definition of Reduction 1 Definition of Reduction Problem A is reducible, or more technically Turing reducible, to problem B, denoted A B if there a main program M to solve problem A that lacks only a procedure to solve problem

More information

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

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points MC 0 GRAPH THEORY 0// Solutions to HW # 0 points + XC points ) [CH] p.,..7. This problem introduces an important class of graphs called the hypercubes or k-cubes, Q, Q, Q, etc. I suggest that before you

More information

Discrete Mathematics Course Review 3

Discrete Mathematics Course Review 3 21-228 Discrete Mathematics Course Review 3 This document contains a list of the important definitions and theorems that have been covered thus far in the course. It is not a complete listing of what has

More information

Section 6.3: Further Rules for Counting Sets

Section 6.3: Further Rules for Counting Sets Section 6.3: Further Rules for Counting Sets Often when we are considering the probability of an event, that event is itself a union of other events. For example, suppose there is a horse race with three

More information

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

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures Lamé s Theorem Gabriel Lamé (1795-1870) Recursively Defined Sets and Structures Lamé s Theorem: Let a and b be positive integers with a b Then the number of divisions used by the Euclidian algorithm to

More information

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

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014 CMPSCI 250: Introduction to Computation Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014 Things, Sets, and Strings The Mathematical Method Administrative Stuff The Objects of Mathematics

More information

CSC 1351: Quiz 6: Sort and Search

CSC 1351: Quiz 6: Sort and Search CSC 1351: Quiz 6: Sort and Search Name: 0.1 You want to implement combat within a role playing game on a computer. Specifically, the game rules for damage inflicted by a hit are: In order to figure out

More information

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

Test 1, Spring 2013 ( Solutions): Provided by Jeff Collins and Anil Patel. 1. Axioms for a finite AFFINE plane of order n. Math 532, 736I: Modern Geometry Test 1, Spring 2013 ( Solutions): Provided by Jeff Collins and Anil Patel Part 1: 1. Axioms for a finite AFFINE plane of order n. AA1: There exist at least 4 points, no

More information

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

STUDENT NUMBER: MATH Final Exam. Lakehead University. April 13, Dr. Adam Van Tuyl Page 1 of 13 NAME: STUDENT NUMBER: MATH 1281 - Final Exam Lakehead University April 13, 2011 Dr. Adam Van Tuyl Instructions: Answer all questions in the space provided. If you need more room, answer on

More information

CS 341 Homework 1 Basic Techniques

CS 341 Homework 1 Basic Techniques CS 341 Homework 1 Basic Techniques 1. What are these sets? Write them using braces, commas, numerals, (for infinite sets), and only. (a) ({1, 3, 5} {3, 1}) {3, 5, 7} (b) {{3}, {3, 5}, {{5, 7}, {7, 9}}}

More information

Matching Theory. Figure 1: Is this graph bipartite?

Matching Theory. Figure 1: Is this graph bipartite? Matching Theory 1 Introduction A matching M of a graph is a subset of E such that no two edges in M share a vertex; edges which have this property are called independent edges. A matching M is said to

More information

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

Today. Finish Euclid. Bijection/CRT/Isomorphism. Review for Midterm. Today Finish Euclid. Bijection/CRT/Isomorphism. Review for Midterm. Finding an inverse? We showed how to efficiently tell if there is an inverse. Extend euclid to find inverse. Euclid s GCD algorithm.

More information

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,

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, Exercises Exercises 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, a) f(n + 1) = f(n) + 2. b) f(n + 1) = 3f(n). c) f(n + 1) = 2f(n). d) f(n + 1) = f(n)2

More information

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

8/22/12. Outline. Backtracking. The Eight Queens Problem. Backtracking. Part 1. Recursion as a Problem-Solving Technique Part 1. Recursion as a Problem-Solving Technique CS 200 Algorithms and Data Structures CS 200 Algorithms and Data Structures [Fall 2011] 2 Outline Backtracking Formal grammars Relationship between recursion

More information

Solutions to the Second Midterm Exam

Solutions to the Second Midterm Exam CS/Math 240: Intro to Discrete Math 3/27/2011 Instructor: Dieter van Melkebeek Solutions to the Second Midterm Exam Problem 1 This question deals with the following implementation of binary search. Function

More information

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

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 The entire examination is 925 points. The real final will be much shorter. Name: No books, notes, scratch paper, or calculators. Use pen

More information

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

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of

More information

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

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 Contents STRAND B: Number Theory Unit 7 Number System and Bases Student Text Contents Section 7. Number System 7.2 Binary Numbers 7.3 Adding and Subtracting Binary Numbers 7.4 Multiplying Binary Numbers

More information

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

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

More information

Lecture 6,

Lecture 6, Lecture 6, 4.16.2009 Today: Review: Basic Set Operation: Recall the basic set operator,!. From this operator come other set quantifiers and operations:!,!,!,! \ Set difference (sometimes denoted, a minus

More information

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

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

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

Advanced Induction. Drawing hands by Escher. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1 Advanced Induction Drawing hands by Escher Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1 Logistics Midterm is done grading but entering into Moodle/tallying/analysis will

More information

Prelim One Solution. CS211 Fall Name. NetID

Prelim One Solution. CS211 Fall Name. NetID Name NetID Prelim One Solution CS211 Fall 2005 Closed book; closed notes; no calculators. Write your name and netid above. Write your name clearly on each page of this exam. For partial credit, you must

More information

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

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: 1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: Input: A CNF formula ϕ with n variables x 1, x 2,..., x n. Output: True if there is an

More information

UNC Charlotte 2010 Comprehensive

UNC Charlotte 2010 Comprehensive 00 Comprehensive March 8, 00. A cubic equation x 4x x + a = 0 has three roots, x, x, x. If x = x + x, what is a? (A) 4 (B) 8 (C) 0 (D) (E) 6. For which value of a is the polynomial P (x) = x 000 +ax+9

More information

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

ECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm ECE G205 Fundamentals of Computer Engineering Fall 2003 Exercises in Preparation to the Midterm The following problems can be solved by either providing the pseudo-codes of the required algorithms or the

More information

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

CS 151 Complexity Theory Spring Final Solutions. L i NL i NC 2i P. CS 151 Complexity Theory Spring 2017 Posted: June 9 Final Solutions Chris Umans 1. (a) The procedure that traverses a fan-in 2 depth O(log i n) circuit and outputs a formula runs in L i this can be done

More information

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE Professor Kindred Math 104, Graph Theory Homework 2 Solutions February 7, 2013 Introduction to Graph Theory, West Section 1.2: 26, 38, 42 Section 1.3: 14, 18 Section 2.1: 26, 29, 30 DO NOT RE-DISTRIBUTE

More information

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

1 / 43. Today. Finish Euclid. Bijection/CRT/Isomorphism. Fermat s Little Theorem. Review for Midterm. 1 / 43 Today Finish Euclid. Bijection/CRT/Isomorphism. Fermat s Little Theorem. Review for Midterm. 2 / 43 Finding an inverse? We showed how to efficiently tell if there is an inverse. Extend euclid to

More information

Math 485, Graph Theory: Homework #3

Math 485, Graph Theory: Homework #3 Math 485, Graph Theory: Homework #3 Stephen G Simpson Due Monday, October 26, 2009 The assignment consists of Exercises 2129, 2135, 2137, 2218, 238, 2310, 2313, 2314, 2315 in the West textbook, plus the

More information

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

CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel We will now discuss computer programs, a concrete manifestation of what we ve been calling

More information

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

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009 CS70 Discrete Mathematics and Probability Theory, Spring 2009 Midterm 2 Solutions Note: These solutions are not necessarily model answers. Rather, they are designed to be tutorial in nature, and sometimes

More information

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

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved Recursion Chapter 7 Contents What Is Recursion? Tracing a Recursive Method Recursive Methods That Return a Value Recursively Processing an Array Recursively Processing a Linked Chain The Time Efficiency

More information

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

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, 2013 Midterm 1 Solutions 1 True/False 1. The Mayan base 20 system produces representations of size that is asymptotically

More information

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

MATH20902: Discrete Maths, Solutions to Problem Set 1. These solutions, as well as the corresponding problems, are available at MATH20902: Discrete Maths, Solutions to Problem Set 1 These solutions, as well as the corresponding problems, are available at https://bit.ly/mancmathsdiscrete.. (1). The upper panel in the figure below

More information

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

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions) CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions) Consider the following recursive function: int what ( int x, int y) if (x > y) return what (x-y, y); else if (y > x) return

More information

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

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

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

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016 Complexity, Induction, and Recurrence Relations CSE 373 Help Session 4/7/2016 Big-O Definition Definition: g(n) is in O( f(n) ) if there exist positive constants c and n0 such that g(n) c f(n) for all

More information

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

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302 ECE 250 Algorithms and Data Structures MIDTERM EXAMINATION Douglas Wilhelm Harder dwharder@uwaterloo.ca EIT 4018 x37023 2013-10-23T09:30:00P1H20M Rooms: RCH-103 and RCH-302 Instructions: Read and initial

More information

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

Overview. A mathema5cal proof technique Proves statements about natural numbers 0,1,2,... (or more generally, induc+vely defined objects) Merge Sort Goals for Today Induc+on Lecture 22 Spring 2011 Be able to state the principle of induc+on Iden+fy its rela+onship to recursion State how it is different from recursion Be able to understand induc+ve proofs

More information

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

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60 CPS 102: Discrete Mathematics Instructor: Bruce Maggs Quiz 3 Date: Wednesday November 30, 2011 NAME: Prob # Score Max Score 1 10 2 10 3 10 4 10 5 10 6 10 Total 60 1 Problem 1 [10 points] Find a minimum-cost

More information

Math236 Discrete Maths with Applications

Math236 Discrete Maths with Applications Math236 Discrete Maths with Applications P. Ittmann UKZN, Pietermaritzburg Semester 1, 2012 Ittmann (UKZN PMB) Math236 2012 1 / 19 Degree Sequences Let G be a graph with vertex set V (G) = {v 1, v 2, v

More information

Notes for Recitation 8

Notes for Recitation 8 6.04/8.06J Mathematics for Computer Science October 5, 00 Tom Leighton and Marten van Dijk Notes for Recitation 8 Build-up error Recall a graph is connected iff there is a path between every pair of its

More information

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

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1 CS 70 Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1 PRINT Your Name:, (last) SIGN Your Name: (first) PRINT Your Student ID: CIRCLE your exam room: 1 Pimentel 141 Mccone

More information

Infinity and Uncountability. Countable Countably infinite. Enumeration

Infinity and Uncountability. Countable Countably infinite. Enumeration Infinity and Uncountability. Countable Countably infinite. Enumeration How big is the set of reals or the set of integers? Infinite! Is one bigger or smaller? Same size? Same number? Make a function f

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

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

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Comparing sizes of sets

Comparing sizes of sets Comparing sizes of sets Sets A and B are the same size if there is a bijection from A to B. (That was a definition!) For finite sets A, B, it is not difficult to verify that there is a bijection from A

More information

Lecture 7. SchemeList, finish up; Universal Hashing introduction

Lecture 7. SchemeList, finish up; Universal Hashing introduction Lecture 7. SchemeList, finish up; Universal Hashing introduction CS 16 February 24, 2010 1 / 15 foldleft #!/usr/bin/python def foldleft(func, slist, init): foldleft: ( * -> ) * ( SchemeList)

More information

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

CMPSCI 187: Programming With Data Structures. Lecture #15: Thinking Recursively David Mix Barrington 10 October 2012 CMPSCI 187: Programming With Data Structures Lecture #15: Thinking Recursively David Mix Barrington 10 October 2012 Thinking Recursively Recursive Definitions, Algorithms, and Programs Computing Factorials

More information

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.

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. Angle 1 Angle 2 Angles 1 and 2 are adjacent angles. Two angles in a plane which share a common vertex and a common side, but do not overlap. adjacent angles 2 5 8 11 This arithmetic sequence has a constant

More information

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

2009 HMMT Team Round. Writing proofs. Misha Lavrov. ARML Practice 3/2/2014 Writing proofs Misha Lavrov ARML Practice 3/2/2014 Warm-up / Review 1 (From my research) If x n = 2 1 x n 1 for n 2, solve for x n in terms of x 1. (For a more concrete problem, set x 1 = 2.) 2 (From this

More information