Algorithms: Background

Similar documents
Binomial Coefficient Identities/Complements

MATH 402 : 2017 page 1 of 6

Definition: Let S and T be sets. A binary relation on SxT is any subset of SxT. A binary relation on S is any subset of SxS.

Introduction to Decision Sciences Lecture 10

Compare the growth rate of functions

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Notation Index. gcd(a, b) (greatest common divisor) NT-16

Pigeonhole Principle and Ramsey Theory

Counting Methods. CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

What you learned in Math 28. Rosa C. Orellana

Chapter 1 : The language of mathematics.

Fibonacci numbers. Chapter The Fibonacci sequence. The Fibonacci numbers F n are defined recursively by

{ 0! = 1 n! = n(n 1)!, n 1. n! =

MATH 215 Final. M4. For all a, b in Z, a b = b a.

Notes for Math 290 using Introduction to Mathematical Proofs by Charles E. Roberts, Jr.

Introduction to Number Theory

Introduction to Decision Sciences Lecture 11

Advanced Counting Techniques

Advanced Counting Techniques. Chapter 8

Review 3. Andreas Klappenecker

1 The distributive law

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

Putnam Pigeonhole Principle October 25, 2005

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

Final Exam Review. 2. Let A = {, { }}. What is the cardinality of A? Is

Solutions to Practice Final

PRIME NUMBERS YANKI LEKILI

Discrete Structures for Computer Science: Counting, Recursion, and Probability

8. Given a rational number r, prove that there exist coprime integers p and q, with q 0, so that r = p q. . For all n N, f n = an b n 2

1 Basic Combinatorics

CSE 1400 Applied Discrete Mathematics Proofs

The Pigeonhole Principle

Notes on Continued Fractions for Math 4400

Fall 2017 Test II review problems

MATH FINAL EXAM REVIEW HINTS

MATH 363: Discrete Mathematics

Mathematics 228(Q1), Assignment 2 Solutions

0.Axioms for the Integers 1

Week 2: Sequences and Series

COMP Intro to Logic for Computer Scientists. Lecture 15

Propositional Logic, Predicates, and Equivalence

Section 11.1 Sequences

Simplification by Truth Table and without Truth Table

Counting. Math 301. November 24, Dr. Nahid Sultana

Test Codes : MIA (Objective Type) and MIB (Short Answer Type) 2007

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

Recurrence Relations

CIS Spring 2018 (instructor Val Tannen)

Recursive Definitions

3 Finite continued fractions

Simplification by Truth Table and without Truth Table

Lecture Notes 1 Basic Concepts of Mathematics MATH 352

CHAPTER 8: EXPLORING R

MATH 310 Course Objectives

Theoretical Cryptography, Lecture 10

International Competition in Mathematics for Universtiy Students in Plovdiv, Bulgaria 1994

Mathematical Reasoning & Proofs

Week 15-16: Combinatorial Design

The Real Number System

What can you prove by induction?

1. The positive zero of y = x 2 + 2x 3/5 is, to the nearest tenth, equal to

MATH 117 LECTURE NOTES

Numbers and their divisors

Notes for Finite Mathematics (WUSTL, Math 220, Summer 2017)

Mathematical Fundamentals

Applications. More Counting Problems. Complexity of Algorithms

MAT115A-21 COMPLETE LECTURE NOTES

Groups. 3.1 Definition of a Group. Introduction. Definition 3.1 Group

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

1. Given the public RSA encryption key (e, n) = (5, 35), find the corresponding decryption key (d, n).

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

1 Sequences and Summation

CMSC Discrete Mathematics SOLUTIONS TO FIRST MIDTERM EXAM October 18, 2005 posted Nov 2, 2005

Induction and Recursion

Mathathon Round 1 (2 points each)

Hence, the sequence of triangular numbers is given by., the. n th square number, is the sum of the first. S n

Logic. Facts (with proofs) CHAPTER 1. Definitions

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Chapter 5.1: Induction

Fundamentals of Pure Mathematics - Problem Sheet

MATH 145 LECTURE NOTES. Zhongwei Zhao. My Lecture Notes for MATH Fall

1. (16 points) Circle T if the corresponding statement is True or F if it is False.

CMSC Discrete Mathematics SOLUTIONS TO SECOND MIDTERM EXAM November, 2005

Contribution of Problems

Discrete Mathematics. Kishore Kothapalli

Series of Error Terms for Rational Approximations of Irrational Numbers

CHAPTER 4: EXPLORING Z

Teaching with a Smile

MATH 201 Solutions: TEST 3-A (in class)

Proofs. Chapter 2 P P Q Q

0 Sets and Induction. Sets

Mathematical Background

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

5. Sequences & Recursion

IVA S STUDY GUIDE FOR THE DISCRETE FINAL EXAM - SELECTED SOLUTIONS. 1. Combinatorics

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n.

Solutions to Practice Final 3

ELEMENTARY LINEAR ALGEBRA

Math 109 September 1, 2016

Transcription:

Algorithms: Background Amotz Bar-Noy CUNY Amotz Bar-Noy (CUNY) Algorithms: Background 1 / 66

What is a Proof? Definition I: The cogency of evidence that compels acceptance by the mind of a truth or a fact. Definition II: The process or an instance of establishing the validity of a statement especially by derivation from other statements in accordance with principles of reasoning. Definition III: A sequence of statements, each of which is either validly derived from those preceding it or is an axiom or assumption, and the final member of which, the conclusion, is the statement of which the truth is thereby established. Definition IV: a chain of reasoning using rules of inference, ultimately based on a set of axioms, that lead to a conclusion. Amotz Bar-Noy (CUNY) Algorithms: Background 2 / 66

The Pythagorean Theorem c b a Theorem: c 2 = a 2 + b 2 for a right triangle with short sides of length a and b and long side of length c. Amotz Bar-Noy (CUNY) Algorithms: Background 3 / 66

Proof I b a a c c b b c c a a b (a + b) 2 = c 2 + 4 ab 2 a2 + b 2 = c 2 Amotz Bar-Noy (CUNY) Algorithms: Background 4 / 66

Proof II c c b a b a a b a b c c c 2 = 4 ab 2 + (b a)2 c 2 = b 2 + a 2 Amotz Bar-Noy (CUNY) Algorithms: Background 5 / 66

Proof III a c c b a b a + b c2 (a + b) = 2 2 + 2ab 2 a2 + b 2 = c 2 Amotz Bar-Noy (CUNY) Algorithms: Background 6 / 66

More Proofs 118 proofs: http://www.cut-the-knot.org/pythagoras/ 6 proofs without words: https://www.youtube.com/watch?v=cokhrdbncua An experimental proof: https://www.youtube.com/watch?v=cakmudeb06o More about the Theorem and its proofs: https://en.wikipedia.org/wiki/pythagorean_theorem Amotz Bar-Noy (CUNY) Algorithms: Background 7 / 66

Prime Numbers Theorem: There are infinitely many prime numbers. Proof: Let p 1 < p 2 < < p n be a set of n primes. Let Q = p 1 p 2 p n + 1. If Q is a prime, then a new prime is found. Otherwise, Q is a product of two or more primes. The Fundamental Theorem of Arithmetic. None of these primes can be p 1,..., p n. Therefore, a new prime is found. This process can continue infinitely often to find infinitely many primes. Amotz Bar-Noy (CUNY) Algorithms: Background 8 / 66

A Proof by Contradiction Theorem: The number 2 is an irrational number. Proof: Assume towards contradiction that p q = 2 for two positive integers p and q that have no common divisor. Squaring the equation implies p 2 = 2q 2. Therefore, p must be even. Let p = 2r for a positive integer r. It follows that 2q 2 = (2r) 2 = 4r 2 q 2 = 2r 2. Therefore, q must be even. A contradiction since both p and q are even. Amotz Bar-Noy (CUNY) Algorithms: Background 9 / 66

The Numbers An integer number: One of the (counting) numbers..., 3, 2, 1, 0, 1, 2, 3,.... Z (Z +, Z ) The set of all (positive, negative) integers. A rational number: A number that can be expressed as a fraction p/q where p (the numerator) and q (the denominator) are integers and q 0. Q (Q +, Q ) The set of all (positive, negative) rationals. A real number: A number of the form n.b 1 b 2 b 3... where n is an integer and b i {0, 1} for all i = 1, 2,.... R (R +, R ) The set of all (positive, negative) reals. Amotz Bar-Noy (CUNY) Algorithms: Background 10 / 66

Equality Between Sets Definition: Two finite or infinite sets S and T have the same cardinality (S T ) if and only if there is a one-to-one mapping f : S T from S to T. Mapping: For all s S there exists t T such that f (s) = t. From S: s 1 s 2 f (s 1 ) f (s 2 ). To T : For all t T there exists s S such that f (s) = t. Remark: For finite sets S = T is equivalent to S T. Amotz Bar-Noy (CUNY) Algorithms: Background 11 / 66

Examples Z Z + although it seems like Z is twice as large as Z +. Q Z although there are infinite number of rational numbers between any two consecutive integers. R Q although there are infinite number of rational numbers between any two real numbers. Since Q R (every rational number is also a real number), it follows that Q R from a cardinality point of view. Amotz Bar-Noy (CUNY) Algorithms: Background 12 / 66

Z Z + The mapping f : Z Z + : f (n) = 2n for a positive integer n. f ( n) = 2n + 1 for a positive integer n. f (0) = 1.... -3-2 -1 0 1 2 3... 7 5 3 1 2 4 6 Amotz Bar-Noy (CUNY) Algorithms: Background 13 / 66

Z + Q + The mapping: From Z + to Q + by following the arrows and skipping the already assigned fractions. 1/1 2/1 3/1 4/1 5/1... 1/2 2/2 3/2 4/2 5/2... 1/3 2/3 3/3 4/3 5/3... 1/4 2/4 3/4 4/4 5/4... 1/5.. 2/5... 3/5.. 4/5... 5/5...... Amotz Bar-Noy (CUNY) Algorithms: Background 14 / 66

Z + R + Assume that a mapping f : Z + R + exists. f (1) = n 1.b1b 1 1b 2 1 3... bi 1... f (2) = n 2.b2b 1 2b 2 2 3... bi 2... f (3) = n 3.b3b 1 3b 2 3 3... bi 3.... f (i) = n i.bi 1 bi 2 bi 3... bi i... Let x = n 1. b 1 1 b 2 2 b 3 3... b i i... where b j j = 1 b j j. x f (i) for any i = 1, 2,.... Therefore f is not a valid mapping: a contradiction. Amotz Bar-Noy (CUNY) Algorithms: Background 15 / 66

A False Proof a = b + c (a b)a = (a b)(b + c) a 2 ab = ab + ac b 2 bc a 2 ab ac = ab b 2 bc a(a b c) = b(a b c) a = b Amotz Bar-Noy (CUNY) Algorithms: Background 16 / 66

Another False Proof i = i 1 = 1 1 1 = 1 = 1 1 1 1 1 1 1 = 1 1 1 = 1 Amotz Bar-Noy (CUNY) Algorithms: Background 17 / 66

Induction Let P n be a statement for all the positive integer (n = 1, 2, 3,...). If the following 2 properties hold: Property I: P 1 is true. Property II: P k+1 is true if P k is true for each positive integer k. Then P n is true for all n. Amotz Bar-Noy (CUNY) Algorithms: Background 18 / 66

Why Induction Works? Let S be the set of all numbers n for which P n is false. Let k be the minimum number in S. k > 1 since by Property I of the induction definition, P 1 is true. By the minimality of k, P k 1 is true and P k is false. A contradiction to Property II of the induction definition. Amotz Bar-Noy (CUNY) Algorithms: Background 19 / 66

A Summation Problem Prove that for an integer n 1: Define: 1 + 2 + 3 + + n = n(n+1) 2. L(n) = 1 + 2 + 3 + + n. R(n) = n(n+1) 2. Prove that L(n) = R(n) for n 1. Amotz Bar-Noy (CUNY) Algorithms: Background 20 / 66

Verifying the Claim Check correctness for small values of n: n L(n) R(n) 1 2 1 1 = 1 2 = 1 2 3 2 1 + 2 = 3 2 = 3 3 4 3 1 + 2 + 3 = 6 2 = 6... 10 11 10 1 + 2 + 3 + + 10 = 55 2 = 55 Amotz Bar-Noy (CUNY) Algorithms: Background 21 / 66

A Direct Proof Idea: Compute the value of 2L(n). Example: 2(1 + 2 + 3) = (1 + 2 + 3) + (3 + 2 + 1) = (1 + 3) + (2 + 2) + (3 + 1) = 3 4 = 12 = 2 3 4 2 Amotz Bar-Noy (CUNY) Algorithms: Background 22 / 66

A Direct Proof 2 L(n) = (1 + + n) + (n + + 1) = (1 + n) + (2 + (n 1)) + + (n + 1) = (n + 1) + (n + 1) + + (n + 1) = n(n + 1) This implies that: L(n) = n(n+1) 2 = R(n). Amotz Bar-Noy (CUNY) Algorithms: Background 23 / 66

A Proof by Induction Prove correctness for n + 1 assuming correctness for n: L(n + 1) = 1 + 2 + + n + (n + 1) = L(n) + (n + 1) = R(n) + (n + 1) n(n + 1) = + (n + 1) 2 (n + 1)(n + 2) = 2 = R(n + 1) Amotz Bar-Noy (CUNY) Algorithms: Background 24 / 66

The Pigeonhole Principle Simple form: If k + 1 objects are placed into k boxes then there exists at least one box containing 2 or more objects. Dual form: If k objects are placed into k + 1 boxes then there exists at least one empty box. Generalized form: If K objects are placed into k boxes then there exists at least one box containing K /k or more objects. Amotz Bar-Noy (CUNY) Algorithms: Background 25 / 66

Hand Shaking Problem: In a group of n people handshaking takes place. No-one shakes their own hand and no pair of people shake hands more than once. Show that there must be two people who have shaken the same number of hands. Amotz Bar-Noy (CUNY) Algorithms: Background 26 / 66

Hand Shaking Problem: In a group of n people handshaking takes place. No-one shakes their own hand and no pair of people shake hands more than once. Show that there must be two people who have shaken the same number of hands. Proof: For 1 i n, person P i shakes 0 h i n 1 hands. There cannot be 2 people P i and P j such that h i = 0 and h j = n 1. There are only n 1 possible values for h 1, h 2,..., h n. By the pigeonhole principle at least 2 people have shaken the same number of hands. Amotz Bar-Noy (CUNY) Algorithms: Background 26 / 66

Friends and Enemies Problem: In a group of 6 people, each pair of individuals consists of 2 friends or 2 enemies. Show that there are either 3 mutual friends or 3 mutual enemies in the group. Amotz Bar-Noy (CUNY) Algorithms: Background 27 / 66

Friends and Enemies Problem: In a group of 6 people, each pair of individuals consists of 2 friends or 2 enemies. Show that there are either 3 mutual friends or 3 mutual enemies in the group. Proof: Let A be one of the 6 people. By the generalized pigeonhole principle either A has 3 friends or A has 3 enemies. Assume A has 3 friends B, C, D. If any 2 of B, C, D are friends then these 2 and A are 3 mutual friends. Otherwise B, C, D are 3 mutual enemies. Similar arguments hold if B, C, D are the enemies of A. Amotz Bar-Noy (CUNY) Algorithms: Background 27 / 66

Discussing Topics Problem: 17 people discuss 3 topics where each pair discuss only 1 topic. Prove that there are at least 3 people who discuss among themselves the same topic. Amotz Bar-Noy (CUNY) Algorithms: Background 28 / 66

Discussing Topics Problem: 17 people discuss 3 topics where each pair discuss only 1 topic. Prove that there are at least 3 people who discuss among themselves the same topic. Proof: Let A be one of the 17 people. By the generalized pigeonhole principle there exists a topic T discussed by A with at least 6 people. If among these 6 people there are B and C who discuss T, then A, B, C discuss T among themselves. Otherwise, these 6 people discuss only the other 2 topics. By the previous problem, there are 3 people who discuss among themselves the same topic. Amotz Bar-Noy (CUNY) Algorithms: Background 28 / 66

Ramsey s Numbers Friends and Enemies: R(3, 3) http://www.cut-the-knot.org/curriculum/combinatorics/threeorthree.shtml Discussing Topics: R(3, 3, 3) http://www.cut-the-knot.org/arithmetic/combinatorics/ramsey333.shtml Amotz Bar-Noy (CUNY) Algorithms: Background 29 / 66

Induction vs. Pigeonhole Principle Induction:... then for all... Pigeonhole Principle:... then there exists... Amotz Bar-Noy (CUNY) Algorithms: Background 30 / 66

The Subsequence Theorem Theorem: Let x 1,..., x n 2 +1 be any sequence of distinct numbers. Then there exists either an increasing or a decreasing (n + 1)-subsequence Amotz Bar-Noy (CUNY) Algorithms: Background 31 / 66

The Subsequence Theorem Theorem: Let x 1,..., x n 2 +1 be any sequence of distinct numbers. Then there exists either an increasing or a decreasing (n + 1)-subsequence Without loss of generality the numbers are 1, 2,..., n 2 + 1. Trivial for n = 1: the only possible sequences of length n 2 + 1 = 1 2 + 1 = 2 are the increasing sequence (1, 2) and the decreasing sequence (2, 1) of length n + 1 = 2. Amotz Bar-Noy (CUNY) Algorithms: Background 31 / 66

Sequences of Length n 2 The sequence (7, 8, 9, 4, 5, 6, 1, 2, 3) is an example why the theorem is not correct for n 2 numbers for n = 3. The sequence (4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13) is an example why the theorem is not correct for n 2 numbers for n = 4. Amotz Bar-Noy (CUNY) Algorithms: Background 32 / 66

Sequences of Length n 2 The sequence (7, 8, 9, 4, 5, 6, 1, 2, 3) is an example why the theorem is not correct for n 2 numbers for n = 3. The sequence (4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13) is an example why the theorem is not correct for n 2 numbers for n = 4. The following two sequences are examples why the theorem is not correct for n 2 numbers for any n 1: ([n 2 n + 1, n 2 n + 2,..., n 2 ], [n 2 2n + 1, n 2 2n + 2,..., n 2 n],..., [1, 2,..., n]) ([n, n 1,..., 1], [2n, 2n 1,..., n + 1],..., [n 2, n 2 1,..., n 2 n + 1]) Amotz Bar-Noy (CUNY) Algorithms: Background 32 / 66

n = 2: Sequences of Length 5 Check all the 120 permutations of 1, 2, 3, 4, 5 and show either an increasing or a decreasing 3-subsequence. Amotz Bar-Noy (CUNY) Algorithms: Background 33 / 66

n = 2: Sequences of Length 5 Check all the 120 permutations of 1, 2, 3, 4, 5 and show either an increasing or a decreasing 3-subsequence. Assume 3 is in position 3 in the sequence (,, 3,, ): If 1 is in positions 4 or 5, then either 4 or 5 must be in positions 1 or 2, creating a decreasing 3-subsequence. E.g., (5,, 3,, 1). If 1 is in positions 1 or 2, then either 4 or 5 must be in positions 4 or 5, creating an increasing 3-subsequence. E.g., (, 1, 3,, 4). Similar arguments find a decreasing or an increasing 3-subsequence if 2, 3, or 4 are in positions 2, 3, or 4. The proof follows since by the pigeonhole principle one of 2, 3, and 4 must be in one of the positions 2, 3, or 4. Amotz Bar-Noy (CUNY) Algorithms: Background 33 / 66

Proofs Five Proofs of the Subsequence Theorem By William Gasarch http://www.cs.umd.edu/ gasarch/blogpapers/subseq4proofs.pdf The three proofs by induction are more involved than the two proofs that use the pigeonhole principle. However, all the proofs use similar arguments. All the proofs fail on the example of a sequence of length n 2 that does not have an n + 1-subsequence. Amotz Bar-Noy (CUNY) Algorithms: Background 34 / 66

First Proof from the Book Let x 1,..., x n 2 +1 be any sequence of distinct numbers. Let f (i) be the length of the longest increasing subsequence that ends at x i. If there exists i such that f (i) n + 1, then an increasing (n + 1)-subsequence exists. Otherwise, f (i) n for all i. There are n 2 + 1 indices, therefore by the generalized pigeonhole principle, there exists 1 v n and at least n + 1 indices i 1, i 2,..., i n+1 for which v = f (i 1 ) = f (i 2 ) = = f (i n+1 ). x ij > x ik for any 1 j < k n + 1 since otherwise f (k) f (j) + 1. Therefore, x i1 > x i2 > > x in+1 is a decreasing (n + 1)-subsequence. Amotz Bar-Noy (CUNY) Algorithms: Background 35 / 66

Second Proof from the Book Let x 1,..., x n 2 +1 be any sequence of distinct numbers. Let f (i) be the length of the longest increasing subsequence that ends at x i and let g(i) be the length of the longest decreasing subsequence that ends at x i. Assume towards contradiction that both f (i), g(i) n for all i. Then there are at most n 2 different pairs (f (i), g(i)). Since there are n 2 + 1 indices, by the pigeonhole principle, there exist indices 1 j < k n 2 + 1 such that f (j) = f (k) and g(j) = g(k). If x j < x k then f (k) f (j) + 1; a contradiction. If x j > x k then g(k) g(j) + 1; a contradiction. Amotz Bar-Noy (CUNY) Algorithms: Background 36 / 66

Properties of Logarithms For real numbers a > 1, b > 1, x > 0, and y > 0: log a x = z a z = x log a 1 = 0 log a a = 1 log a (x y ) = y log a x log a (xy) = log a x + log a y log a (x/y) = log a x log a y a log b x = x log b a log a b = 1 log b a log a x = log b x log b a = log a b log b x Amotz Bar-Noy (CUNY) Algorithms: Background 37 / 66

Summation Formulas n i=1 i0 = 1 + 1 + + 1 = n 1 1 n1 n i=1 i1 = 1 + 2 + + n = n(n+1) 2 1 2 n2 n i=1 i2 = 1 2 + 2 2 + + n 2 = n(n+1)(2n+1) 6 1 3 n3 n i=1 ik = 1 k + 2 k + + n k 1 k+1 nk+1 Amotz Bar-Noy (CUNY) Algorithms: Background 38 / 66

Summation Formulas Finite sums for a > 1: n i=0 ai = 1 + a + + a n = an+1 1 a 1 n i=0 2i = 1 + 2 + 4 + + 2 n = 2 n+1 1 Finite sums for a < 1: n i=0 ai = 1 + a + + a n = 1 an+1 n i=0 1 a ( 1 ) i 2 = 1 + 1 2 + 1 4 + + 1 2 = 2 1 n 2 n Infinite sums for a < 1: i=0 ai = 1 + a + a 2 + = 1 ( 1 i=0 2 1 a ) i = 1 + 1 2 + 1 4 + 1 8 + = 2 Amotz Bar-Noy (CUNY) Algorithms: Background 39 / 66

Summation Formulas n (i 2 i ) = 1 2 + 2 2 2 + + n 2 n = (n 1)2 n+1 + 2 i=1 2 4 4 8 8 8 16 16 16 16... 2 n 2 n 2 n 2 n 2 n 2(2 n 1) 4(2 n 1 1) 8(2 n 2 1) 16(2 n 3 1) 2 n (2 1). n n n (i 2 i ) = 2 i (2 n i+1 1) = (2 n+1 2 i ) i=1 i=1 i=1 = n2 n+1 2(2 n 1) = (n 1)2 n+1 + 2 Amotz Bar-Noy (CUNY) Algorithms: Background 40 / 66

Summation Formulas i=1 i 2 i = 1 2 + 2 4 + 3 8 + + i 2 i + = 2 1/2 1/4 1/4 1/8 1/8 1/8... 1/2 i 1/2 i 1/2 i 1/2 i..... 1 1/2 1/4 1/2 i 1 i=1 i 2 i = i=0 1 2 i = 2. Amotz Bar-Noy (CUNY) Algorithms: Background 41 / 66

Summation Formulas n log 2 i = log 2 1 + log 2 2 + + log 2 n i=1 = log 2 (1 2 n) = log 2 (n!) n log 2 n Upper bound: n log 2 i < i=1 n log 2 n = n log 2 n i=1 Lower bound: n n log 2 i > log 2 (n/2) = n/2 log 2 (n/2) n/2 i=1 i=n/2+1 Amotz Bar-Noy (CUNY) Algorithms: Background 42 / 66

Summation Formulas For n = 2 k : log 2 n i=0 log 2 ( n 2 i ) = log 2 ( n 1 ) ( n ) ( n ) + log 2 + + log 2 2 n = 1 + 2 + + log 2 n = log 2 n(log 2 n + 1) 2 log2 2 n 2 Amotz Bar-Noy (CUNY) Algorithms: Background 43 / 66

Sum Manipulation Rules u i=l ca i = c u i=l a i u i=l (a i ± b i ) = u i=l a i ± u i=l b i u i=l a i = m i=l a i + u i=m+1 a i for l m u u i=l+1 (a i a i 1 ) = a u a l Amotz Bar-Noy (CUNY) Algorithms: Background 44 / 66

Bounding Summations by Integrals For a monotonic non-decreasing function f (x): u l 1 f (x)dx u f (i) i=l u+1 l f (x)dx For a monotonic non-increasing function f (x): u+1 l f (x)dx u f (i) i=l u l 1 f (x)dx Amotz Bar-Noy (CUNY) Algorithms: Background 45 / 66

Bounding Summations by Integrals Amotz Bar-Noy (CUNY) Algorithms: Background 46 / 66

Harmonic Numbers H(n) = n i=1 1 i. f (x) = 1/x is a monotonic non-increasing function. Upper Bound: H(n) 1 + n dx 1 x Lower bound: H(n) n+1 dx 1 x = 1 + ln(n) ln(1) = 1 + ln(n). = ln(n + 1) ln(1) = ln(n + 1). Exact bound: H n = ln(n) + γ + 1/(2n) 1/(12n 2 ) + ɛ n /(120n 4 ) for 0 < ɛ n < 1 and γ 0.5772 (Euler s constant). Amotz Bar-Noy (CUNY) Algorithms: Background 47 / 66

Harmonic Numbers Amotz Bar-Noy (CUNY) Algorithms: Background 48 / 66

Floor and Ceiling Formulas For real x and integer n: x 1 < x x x < x + 1 x + n = x + n x + n = x + n n/2 + n/2 = n log 2 (n + 1) = 1 + log 2 n Amotz Bar-Noy (CUNY) Algorithms: Background 49 / 66

Modular Arithmetic For integers n and m and a positive integer p: (n + m) mod p = (n mod p + m mod p) mod p. (n m) mod p = (n mod p m mod p) mod p. Amotz Bar-Noy (CUNY) Algorithms: Background 50 / 66

Stirling s Formula n! = ( n ) n ( ( )) 1 2πn 1 + Θ e n n n! = ( n ) n 2πn e log 2 (n!) = Θ(n log 2 n) Amotz Bar-Noy (CUNY) Algorithms: Background 51 / 66

Fibonacci Numbers The sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144... Recursive Definition: 0 for k = 0, F k = 1 for k = 1, F k 1 + F k 2 for k 2. Wikipedia: https://en.wikipedia.org/wiki/fibonacci_number Amotz Bar-Noy (CUNY) Algorithms: Background 52 / 66

Fibonacci Numbers - The Original Problem Story: A young pair of rabbits (one of each sex) is placed on an island. A pair of rabbits does not breed until they are 2 months old. After they are 2 months old, each pair of rabbits produces another pair each month. Problem: Find a recurrence relation for the number of pairs of rabbits on the island after k months, assuming that no rabbits ever die. Solution: F k pairs of rabbits on the island after k months. Amotz Bar-Noy (CUNY) Algorithms: Background 53 / 66

The Golden Ratio Find a rectangle of size x 1 such that after removing a 1 1 square the remaining rectangle has size 1 1 x. x 1 = 1 x. Amotz Bar-Noy (CUNY) Algorithms: Background 54 / 66

Solving the Equation x = 1 + 1 x Start with x 1 = 1. Define x i = 1 + 1 x i 1 for i > 1. x 2 = 1 + 1 1 = 2. x 3 = 1 + 1 2 = 3 2 = 1.5. x 4 = 1 + 1 3/2 = 5 3 1.667. x 5 = 1 + 1 5/3 = 8 5 = 1.6. x 6 = 1 + 1 8/5 = 13 8 = 1.625. x 7 = 1 + 1 13/8 = 21 13 1.615. x 8 = 1 + 1 21/13 = 34 21 1.619. x 9 = 1 + 1 34/21 = 55 34 1.618. Amotz Bar-Noy (CUNY) Algorithms: Background 55 / 66

Solving the Equation x = 1 + 1 x 1 x = 1 + 1 1 + 1+ 1 1+ 1 1+ 1 1+ 1 1+ 1 1+ 1 1+ 1 1+... 1 Amotz Bar-Noy (CUNY) Algorithms: Background 56 / 66

Solving the Equation x = 1 + 1 x Proposition: x i = F i+1 F i. Proof: Initially x 1 = 1 = 1 1 = F 2 F 1. Assume the statement is correct for x i and prove it by induction for x i+1. x i+1 = 1 + 1 1 = 1 + x i F i+1 /F i = 1 + F i F i+1 = F i+1 + F i F i+1 = F i+2 F i+1. Amotz Bar-Noy (CUNY) Algorithms: Background 57 / 66

The Golden Ratio Definition: The positive root of the equation x 2 x 1 = 0. Remark: This equation is equivalent to x = 1 + 1 x. Solution to the quadratic equation: x = 1± 5 2. The positive root: φ = (1 + 5)/2 1.618. The negative root: ˆφ = (1 5)/2 = 1 φ 0.618. Amotz Bar-Noy (CUNY) Algorithms: Background 58 / 66

k as a Function of the Fibonacci Number F k F k = (φ k ˆφ k )/ 5. F k+1 = φf k + ˆφ k. ˆφ < 1 F k = φk 5 rounded to the nearest integer. Corollary: log φ (F k ) + 1 k log φ (F k ) + 2 Corollary: k = Θ(log(F k )). Amotz Bar-Noy (CUNY) Algorithms: Background 59 / 66

Interesting Facts F k 1 F k+1 F 2 k = ( 1)k for k 1. F 5 F 7 F 2 6 = 5 13 82 = 1. F 6 F 8 F 2 7 = 8 21 132 = 1. F mk is a multiple of F m and F k for m, k 1. F 15 = 610 is a multiple of F 5 = 5 and F 3 = 2. gcd(f m, F k ) = F gcd(m,k). gcd(f 12, F 18 ) = gcd(144, 2584) = 8 = F 6 = F gcd(18,12). Amotz Bar-Noy (CUNY) Algorithms: Background 60 / 66

A Paradox? The area of the left rectangle is 8 8 = 64. The area of the right rectangle is 5 13 = 65. But both rectangles are composed of the same 4 shapes! Animation: http://content.ytmnd.com/content/0/a/9/0a95e5060098bc06fe31901a7fc673b3.gif Amotz Bar-Noy (CUNY) Algorithms: Background 61 / 66

A Paradox? The area of the left rectangle is 8 8 = 64. The area of the right rectangle is 5 13 = 65. But both rectangles are composed of the same 4 shapes! Animation: http://content.ytmnd.com/content/0/a/9/0a95e5060098bc06fe31901a7fc673b3.gif Hint: F k 1 F k+1 F 2 k = ( 1)k. Amotz Bar-Noy (CUNY) Algorithms: Background 61 / 66

A Paradox? The area of the left rectangle is 8 8 = 64. The area of the right rectangle is 5 13 = 65. But both rectangles are composed of the same 4 shapes! Animation: http://content.ytmnd.com/content/0/a/9/0a95e5060098bc06fe31901a7fc673b3.gif Hint: F k 1 F k+1 F 2 k = ( 1)k. Solution: http://yozh.org/2011/05/15/an-area-paradox/ Amotz Bar-Noy (CUNY) Algorithms: Background 61 / 66

A Paradox? The area of the left rectangle is 8 8 = 64. The area of the right rectangle is 5 13 = 65. But both rectangles are composed of the same 4 shapes! Animation: http://content.ytmnd.com/content/0/a/9/0a95e5060098bc06fe31901a7fc673b3.gif Hint: F k 1 F k+1 F 2 k = ( 1)k. Solution: http://yozh.org/2011/05/15/an-area-paradox/ The missing square puzzle: https://en.wikipedia.org/wiki/missing_square_puzzle Amotz Bar-Noy (CUNY) Algorithms: Background 61 / 66

Kilometers and Miles One mile is approximately 1.609344 φ kilometers. F k1 + F k2 + + F kh kilometers are approximately F k1 1 + F k2 1 + + F kh 1 miles. 32 = 21 + 8 + 3 = F 8 + F 6 + F 4 kilometers are approximately F 7 + F 5 + F 3 = 13 + 5 + 2 = 20 miles. 32 = 21 + 8 + 3 = F 8 + F 6 + F 4 miles are approximately F 9 + F 7 + F 5 = 34 + 13 + 5 = 52 kilometers. Amotz Bar-Noy (CUNY) Algorithms: Background 62 / 66

Combinatorics Number of permutations of an n-element set: n! Number of k-combinations of an n-element set: ( ) n k = n! k!(n k)! Number of subsets of an n-element set: 2 n Number of binary strings of length n: 2 n Number of k-ary strings of length n: k n Amotz Bar-Noy (CUNY) Algorithms: Background 63 / 66

Binomial Coefficients C(n, k) = ( n k) : The number of size k subsets from the set {1, 2,..., n}. The coefficient of x k in the expansion of (1 + x) n : (1 + x) n = ( ( n 0) + n ( 1) x + n ) 2 x 2 + + ( ) n n x n Recursive Definition: C(n, k) = ( ) n k = 1 for k = 0 1 for k = n ( n 1 ) ( k 1 + n 1 ) k for 0 < k < n 0 otherwise Amotz Bar-Noy (CUNY) Algorithms: Background 64 / 66

The Pascal Triangle 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 Amotz Bar-Noy (CUNY) Algorithms: Background 65 / 66

Binomial Coefficients Some Facts ( n ) k = n! k!(n k)! = n(n 1) (n k+1) k(k 1) 1 ( n ( k) = n ) n k ( n k ) k n k n 1 k 1 n k+1 1 (n k + 1) k ( n ) k = Θ(n k ) for a fixed k Amotz Bar-Noy (CUNY) Algorithms: Background 66 / 66