Math 2602 Finite and Linear Math Fall 14. Homework 8: Core solutions

Similar documents
Exam 2 Solutions. x 1 x. x 4 The generating function for the problem is the fourth power of this, (1 x). 4

Some Review Problems for Exam 2: Solutions

Math 2142 Homework 5 Part 1 Solutions

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

A SUMMARY OF RECURSION SOLVING TECHNIQUES

Math Homework # 4

WORKSHEET ON NUMBERS, MATH 215 FALL. We start our study of numbers with the integers: N = {1, 2, 3,...}

Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2:

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

MATH 103 Pre-Calculus Mathematics Test #3 Fall 2008 Dr. McCloskey Sample Solutions

, p 1 < p 2 < < p l primes.

Computational Complexity - Pseudocode and Recursions

An analogy from Calculus: limits

Math 1302 Notes 2. How many solutions? What type of solution in the real number system? What kind of equation is it?

Math Circle: Recursion and Induction

3.1 Asymptotic notation

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

What is proof? Lesson 1

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Lecture 4: Constructing the Integers, Rationals and Reals

Lecture 10: Powers of Matrices, Difference Equations

Math 475, Problem Set #8: Answers

MULTIPLYING TRINOMIALS

MATH 22 FUNCTIONS: ORDER OF GROWTH. Lecture O: 10/21/2003. The old order changeth, yielding place to new. Tennyson, Idylls of the King

Grade 11/12 Math Circles Rational Points on an Elliptic Curves Dr. Carmen Bruni November 11, Lest We Forget

Homework #2 solutions Due: June 15, 2012

Chapter 1 Review of Equations and Inequalities

Section 5.2 Solving Recurrence Relations

Part V. Chapter 19. Congruence of integers

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Math 138: Introduction to solving systems of equations with matrices. The Concept of Balance for Systems of Equations

MATH 115, SUMMER 2012 LECTURE 4 THURSDAY, JUNE 21ST

8 Primes and Modular Arithmetic

1. Prove that the number cannot be represented as a 2 +3b 2 for any integers a and b. (Hint: Consider the remainder mod 3).

2. Limits at Infinity

Sequences and infinite series

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

Algebra Exam. Solutions and Grading Guide

MATH 2112/CSCI 2112, Discrete Structures I Winter 2007 Toby Kenney Homework Sheet 5 Hints & Model Solutions

Math 109 HW 9 Solutions

Fall Lecture 5

Homework 1 Submission

Quadratic Equations Part I

Basic elements of number theory

Basic elements of number theory

Algebra Year 10. Language

Notes for Recitation 14

1.1 Inductive Reasoning filled in.notebook August 20, 2015

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5. This homework is due October 6, 2014, at 12:00 noon.

Definition For a set F, a polynomial over F with variable x is of the form

Algorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse

Congruences. September 16, 2006

Math 3361-Modern Algebra Lecture 08 9/26/ Cardinality

Modular Arithmetic Instructor: Marizza Bailey Name:

MATH 361: NUMBER THEORY FOURTH LECTURE

Theorems About Roots of Polynomial Equations. Theorem Rational Root Theorem

What Fun! It's Practice with Scientific Notation!

Fall 2017 Test II review problems

Math 308 Midterm Answers and Comments July 18, Part A. Short answer questions

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Section 7.2 Solving Linear Recurrence Relations

Math 016 Lessons Wimayra LUY

2005 Palm Harbor February Invitational Algebra II Answer Key

WORKSHEET MATH 215, FALL 15, WHYTE. We begin our course with the natural numbers:

Practical Algebra. A Step-by-step Approach. Brought to you by Softmath, producers of Algebrator Software

[Disclaimer: This is not a complete list of everything you need to know, just some of the topics that gave people difficulty.]

with the size of the input in the limit, as the size of the misused.

Problem Solving in Math (Math 43900) Fall 2013

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Data Structures and Algorithms. Asymptotic notation

CMSC Discrete Mathematics FINAL EXAM Tuesday, December 5, 2017, 10:30-12:30

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Note 7

Algorithms CMSC The Method of Reverse Inequalities: Evaluation of Recurrent Inequalities

Big-oh stuff. You should know this definition by heart and be able to give it,

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Homework 10 M 373K by Mark Lindberg (mal4549)

Algorithms CMSC Homework set #1 due January 14, 2015

Warm-Up. Simplify the following terms:

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

CSCE 222 Discrete Structures for Computing. Review for the Final. Hyunyoung Lee

Menu. Lecture 2: Orders of Growth. Predicting Running Time. Order Notation. Predicting Program Properties

CHAPTER 3. Congruences. Congruence: definitions and properties

Algebra Review. Finding Zeros (Roots) of Quadratics, Cubics, and Quartics. Kasten, Algebra 2. Algebra Review

MTH 346: The Chinese Remainder Theorem

Contribution of Problems

Partial Fractions. June 27, In this section, we will learn to integrate another class of functions: the rational functions.

Quiz 07a. Integers Modulo 12

SCHOOL OF MATHEMATICS MATHEMATICS FOR PART I ENGINEERING. Self-paced Course

CHMC: Finite Fields 9/23/17

CSC2100B Data Structures Analysis

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

Chapter 2. Polynomial and Rational Functions. 2.5 Zeros of Polynomial Functions

Some Review Problems for Exam 1: Solutions

Sums and products: What we still don t know about addition and multiplication

One-to-one functions and onto functions

CSE 20 DISCRETE MATH. Winter

Transcription:

Math 2602 Finite and Linear Math Fall 14 Homework 8: Core solutions Review exercises for Chapter 5 page 183 problems 25, 26a-26b, 29. Section 8.1 on page 252 problems 8, 9, 10, 13. Section 8.2 on page 264 problems 1, 2, 4, 5, 7a-7b, 9. 25. Find a formula for a n, given a 0 = a 1 = 1 and a n = 3a n 1 2a n 2 +5 for n 2. Solution: The difference between this recurrence relation and the previous ones (from the last homework) is the extra term +5. First, let s guess a particular solution, p n that satisfies the inhomogeneous recurrence relation a n = ra n 1 + sa n 2 + f(n) above (with r = 3, s = 2, and f(n) = 5), ignoring initial conditions. We guess that p n = c for some constant c, since f(n) is constant. We plug in our guess p n into the inhomogeneous recurrence and solve for c. We have p n = 3p n 1 2p n 2 + 5 c = 3c 2c + 5 c c = 5 0 = 5 Oops! Looks like our guess was not a good one. Let s try a different guess. Let s try p n = a+bn since, at least, f(n) = 5 is linear (it s even constant, but that obviously didn t work). With this choice of p n we plug into the inhomogeneous recurrence and try to solve for the constants a and b. We have p n = 3p n 1 2p n 2 + 5 a + bn = 3(a + b(n 1)) 2(a + b(n 2)) + 5 a + bn = 3a 2a + 3bn 2bn 3b + 4b + 5 0 = b + 5 So b = 5 and a is undetermined (so just set a = 0, if we pick a different value it will work itself out when we find c 1, c 2 later). Thus, a particular solution to the inhomogeneous recurrence, ignoring initial conditions, is p n = 5n. Now, by Theorem 5.3.2 on page 172 we have that the solution to the recurrence is the sum p n +q n where p n is as above and q n is a general solution to the homogeneous recurrence relation a n = 3a n 1 2a n 2, ignoring initial conditions (meaning we haven t solved for c 1, c 2 yet). We solve a n = 3a n 1 2a n 2 in the usual way. The characteristic polynomial is x 2 3x + 2 = (x 2)(x 1), which has roots x = 1, 2. So the general solution to the homogeneous recurrence is a n = c 1 + c 2 2 n. Finally, we have that the general solution to the inhomogeneous recurrence we started with is a n = p n + q n = 5n + c 1 + c 2 2 n. We solve for c 1, c 2 in the usual way, by taking into account

2 the initial values a 0 = 1, a 1 = 1. We have a 0 = 1 = c 1 + c 2 = 1 a 1 = 1 = 5 + c 1 + 2c 2 = 1. Solving the system of two linear equations in the two variables c 1, c 2 we immediately obtain c 2 = 5 and c 1 = 4. Thus, the solution is a n = 5n 4 + 5 2 n, n 0. Just because it s the first time we ve tried this, lets check. The first few terms of the sequence, starting at n = 0 of course, are 1, 1, 6, 21, 56,..., and this satisfies a 0 = a 1 = 1 and a 2 = 3(1) 2(1) + 5 = 6 and a 3 = 3(6) 2(1) + 5 = 21 and a 4 = 3(21) 2(6) + 5 = 56. We did it! (or at least, we checked the first few values) (to make extra sure we could also check that the solution we found works by plugging it into the recurrence, but I m sick of this problem, um, I mean, ahem checking that way is left to the reader ) 29. Let a and b be any positive integers and define the recurrence a 1 = a, a 2 = b, and a n = a n 1 + a n 2 for n 3. Assume that the sequence a 2 a 1, a 3 a 2, a 4 a 3,... has a limit k. What is the value of k? Solution: What to try? The recurrence relation given has characteristic polynomial x 2 x 1, which has roots x = 1± 2 using the quadratic formula. So, the general solution is a n = c 1 ( 1 + 2) n + c 2 ( 1 2) n. For now, we are not overly concerned with the particular values of c 1, c 2. Note that, since 1 + 2 < 1 that, in the limit, a n c 2 ( 1 2 n ). Therefore, a n+1 /a n c 2( 1 2) n+1 c 2 ( 1 = 1 2. In other words, the limit of a 2) n n+1 /a n is 1 2 as n tends to infinity. (Cool!) (Notice, we never cared at all about what the values of a, b, c 1, c 2 were) 8. Describe an algorithm that, upon input of n real numbers, a 1, a 2,..., a n, outputs their average. Solution: Input: a 1, a 2,..., a n. step 1: Initialize S = 0.

3 replace S with S + a i. step 3: replace S with S/n. 9. Describe an algorithm that outputs the maximum of the numbers a 1,..., a n. Solution: Input: a 1, a 2,..., a n. step 1: Initialize S = a 1. IF a i a i+1, replace S with a i+1. 10. Describe an algorithm that determines how many of the numbers a 1,..., a n are equal to x. Solution: Input: a 1, a 2,..., a n, and x. step 1: Initialize S = 0. IF a i = x, replace S with S + 1. 11. Describe an algorithm that gives all solutions x in the range 0 x < n to the congruence ax b(mod n) for given values of a, b, n, which should all be integer inputs. If there are no solutions, the algorithm should output the words no solution. Solution: It may be best to give some examples before trying to tackle this problem. questions to get us started. First, some

4 What are the solutions to x 3 (mod 7)? Recall, x 3 (mod 7) means that the integer x has a remainder of 3 after dividing by 7. There is only one x value that is in the range 0 x < 7, namely x = 3. What are the solutions to 2x 3 (mod 7)? The statement 2x 3 (mod 7) means 2x has a remainder of 3 after dividing by 7. Lets just check the x-values in the range x = 0,..., 6 that make that true. x = 0 0 3 (mod 7) false x = 1 2 3 (mod 7) false x = 2 4 3 (mod 7) false x = 3 6 3 (mod 7) false x = 4 8 3 (mod 7) false x = 5 10 3 (mod 7) false x = 6 12 3 (mod 7) false Ok, so in this case, our algorithm should output no solution. Let s try another case. Set a = 2, b = 4 and n = 7. We are going to look for solutions to the equivalence ax b (mod 7), 2x 4 (mod 7). Again, we look in the range x = 0,..., 6 (since n = 7). x = 0 0 3 (mod 7) false x = 1 2 4 (mod 7) false x = 2 4 4 (mod 7) true x = 3 6 4 (mod 7) false x = 4 8 4 (mod 7) false x = 5 10 4 (mod 7) false x = 6 12 4 (mod 7) false Alright, so in this case, the output of our algorithm should be x = 4. Let s do another case. Let s try to make a lot of output this time. Set a = 7, b = 0 and n = 7.

5 Then, x = 0 0 0 (mod 7) true x = 1 7 0 (mod 7) true x = 2 14 0 (mod 7) true x = 3 21 0 (mod 7) true x = 4 28 0 (mod 7) true x = 5 35 0 (mod 7) true x = 6 42 0 (mod 7) true In this case, the output should be x = 0, 1, 2, 3, 4, 5, 6, 7. Ok, last example. Set a = 4, b = 0, and n = 8. Now lets find the solutions x in the range x = 0,..., 7 (since n = 8 now the range is bigger, 0 x < n, then it was when n was equal to 7). x = 0 0 0 (mod 7) true x = 1 4 0 (mod 7) false x = 2 8 0 (mod 7) true x = 3 12 0 (mod 7) false x = 4 16 0 (mod 7) true x = 5 20 0 (mod 7) false x = 6 24 0 (mod 7) true In this case, the output should be x = 0, 2, 4, 6. Ok, we are ready to try to describe the algorithm. Recall, ax b (mod n) if and only if ax b 0 (mod n). In other words, x satisfies the equivalence ax b (mod n) exactly when ax b is divisible by n. Now, in order to ensure that our algorithm is a finite process, we can t check all the possible multiples of 7 to see if ax b is one of them, so we will have to write a sub-routine to deal with checking if ax b is divisible by 7. There is some issue when ax b is negative. But for now, we will avoid discussing it. Sub-routine DIV (x, a, b, n): Input: x, a, b, n with ax b 0. step 1: Initialize S = 0. step 2: For k = 0.. ax b n,

6 IF ax b = kn, replace S with 1. The algorithm DIV (x, a, b, n) outputs 1 if ax b is divisible by n and outputs 0 otherwise. This is because if the output of the algorithm is 1, then for some k in the range 0 k ax b n the equality ax b = kn holds. If we knew that ax b were non-negative for all x in the range 0 x < n, the algorithm we would want is Input: a, b, n. step 1: Initialize S = {}. step 2: For x = 0..n 1, IF DIV (x, a, b, n) = 1, replace S with S {x}. We can adjust the algorithm to accommodate for the restriction ax b by replacing b with its remainder modulo n. That is, ax b is divisible by 7 if and only if ax (b + 7k) is divisible by 7 for all integers k (very easy to prove directly). To that end, define the subroutine Sub-routine REM(b, n): Input: b, n. step 1: Initialize r = 0. step 2: For x = 0..n 1, IF DIV (x, 1, b, n) = 1, replace r with x. Output: r where 0 r < n and r b (mod n). Finally, the desired algorithm is Input: a, b, n. step 1: Initialize S = {}. step 2: IF ax b 0 For x = 0..n 1, IF DIV (x, a, b, n) = 1, replace S with S {x}. IF ax b 0 Replace b with REM(b, n), For x = 0..n 1,

7 IF DIV (x, a, b, n) = 1, replace S with S {x}. 1. Consider the distance algorithm used to calculate (x1 y 1 ) 2 + (x 2 y 2 ) 2 + + (x n y n ) 2 using 3n operations: n subtractions, n squarings, n 1 additions, and 1 square root. Assume that addition and subtraction require the same amount of time, that addition is twice as fast as multiplication, and that multiplication is ten times as fast as the square root operation. Find the complexity function. Solution: Considering the time it takes to perform the subtraction operation as a unit, the complexities of the + and operation are both 1. The complexity of 2 is 2, and the complexity of is 10. The complexity of the algorithm is thus n+2n+n 1+10 = 4n + 9 = O(n). (by the way, the original algorithm was also O(n), so really no time is lost with the extra assumptions) 2. Show that the number of operations required to multiply an n-digit number by a single-digit number does not exceed 3n 2. Count + and as equivalent operations. Solution: Consider the following algorithm for multiplying an n-digit number by a single-digit number. Input: (a n a n 1... a 1 ) 10, x. step 1: Initialize m 1 = r 1 = = m n = r n = m n+1 = r n+1 = 0. replace m i with the ones digit of x a i + r i, IF x a i 10 replace r i+1 with 1, step 3: Replace m n+1 with r n+1. Output: (m n+1 m n m n 1... m 1 ) 10. There are a total of 2n multiplications and n additions in this algorithm. Thus, the complexity is bounded by 3n. But we need to get rid of two operations to meet the book s requirement of a complexity bounded by 3n 2. It isn t hard to see how to change the algorithm above to get the desired result.

8 Input: (a n a n 1... a 1 ) 10, x. step 1: Initialize m 1 = r 1 = = m n = r n = m n+1 = r n+1 = 0. step 2: Replace m 1 with the ones digit of x a 1. step 3: For i = 2..n, Replace m i with the ones digit of x a i + r i, IF x a i 10 replace r i+1 with 1, step 4: Replace m n+1 with r n+1. Output: (m n+1 m n m n 1... m 1 ) 10. In Step 2 there is one operation. In each iteration of Step 3 there are three operations, and there are n 1 iterations, for a total of 3(n 1) operations in Step 3. Thus, the total number of operations is 1 + 3(n 1) = 1 + 3n 3 = 3n 2. By the way... If we do not allow the operation, then we replace x a i +r i with a i + a i + + a }{{} i +r i. With x times this replacement, the algorithm now uses x + 1 of the + operations in the i-th iteration of Step 2. Thus, the complexity is bounded by n i=1 (x + 1) = n(x + 1) = O(n). Unfortunately, this is not good enough for the problem; we are supposed to show the complexity is bounded by f(n) = 3n 2 and n(x + 1) is bigger if x 3, which is possible. If we instead replace x a i + r i with x } + x + {{ + x } + r i, then the complexity of the i-th a i times iteration of Step 2 is bounded by a i + 1, and the complexity of the algorithm is n i=1 (a i + 1) max{a 1,..., a n } n + n = O(n). But, again, this complexity is not good enough unless the maximum of the digits in the n-digit number is 2. Even though neither are good enough, they are both good enough from an asymptotic standpoint (they all are O(n)). Question: What is the best complexity you can get if you only allow the operation +? What is the best complexity you can get if the cost of is some constant times the cost of +? 3. Let x be a real number and n a positive integer. Consider the following two algorithms for calculating x 2n. Algorithm A: Input: x, n. step 1: Initialize a = 1.

9 step 2: For i = 1..2 n, replace a with xa. Output: a. Algorithm B: Input: x, n. step 1: Initialize a = x. replace a with a 2. Output: a. Find complexity functions for both algorithms and explain why B is more efficient. Assume that is the basic operation. Solution: The complexity of A is 2 n while the complexity of B is only n. Since, n 2 n, the complexity of B is much (much MUCH ) better. 7a. Show f(n) = 5n is O(g) where g(n) = n 3. Solution: We need to find c > 0 and n 0 Z such that n n 0 f(n) cg(n). Setting c = 1 and n 0 = 5 works, since if n 5 then 5n n 2 n 3. 7b. Show f(n) = 17n 4 + 8n 3 + 5n 2 + 6n + 1 is O(g) where g = n 4 Solution: Set c = 85 and n 0 = 0. Then, if n 0 we have 17n 4 + 8n 3 + 5n 2 + 6n + 1 17n 4 + 17n 4 + 17n 4 + 17n 4 + 17n 4 = 85n 4. 9. If f, g, h : N R, f = O(h) and g = O(h), show that f + g = O(h). Solution: By definition, since f = O(h) there exists c 1 > 0 and n 0 Z such that if n n 0 then f(n) c 1 h(n). Similarly, there exists c 2 > 0 and m 0 Z such that if n m 0 then g(n) c 2 h(n). Set c = c 1 + c 2 and N 0 = max{m 0, n 0 }. Then, if n N 0 then f(n) c 1 h(n) and g(n) c 2 h(n), so f(n) + g(n) (c 1 + c 2 )h(n), as desired.