Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
7.1 Recurrence Relations β’ A recurrence relation is a recursive definition for the terms of a sequence β’ A solution to a recurrence relation is a non-recursive formula for the terms of the sequence Example: Determine whether the sequences ππ = 2π and ππ = π4π are solutions of the recurrence relation ππ = 8ππβ1 β 16ππβ2 . Another Example β The Towers of Hanoi How many moves are made in solving the puzzle if there are n disks? Solution by Iterationβ¦ 7.2 Solving Recurrence Relations β’ Definition: A linear homogeneous recurrence relation of degree k with constant coefficients Solving Linear Homogeneous Recurrence Relations with Constant Coefficients Theorem 1 Let c1 and c2 be real numbers. Suppose the quadratic r2 β c1r β c2 has two real roots r1 and r2. Then {an} is a solution to the recurrence relation an = c1an-1 + c2an-2 if and only if an = Ξ±1r1n + Ξ±2r2n for n = 0, 1, 2, β¦, where Ξ±1 and Ξ±2 are constants. Example β’ Solve the recurrence relation for the Fibonacci sequence 0, 1, 1, 2, 3, 5, β¦ Another Example β’ Solve the recurrence relation for the sequence defined by a0 = 1, a1 = 2, and for n > 1 an = 2an-1 + 3an-2 Theorem 2 β’ Let c1 and c2 be real numbers with c2 nonzero. Suppose that r2 β c1r β c2 = 0 has only one real root r0. A sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 if and only if an = Ξ±1r0n + Ξ±2nr0n for n = 0, 1, 2, β¦, where Ξ±1 and Ξ±2 are constants Example β’ Solve the recurrence relation for the sequence defined by a0 = 1, a1 = 2, and for n>1 an = 2an-1 β an-2 Example β’ Solve the recurrence relation for the sequence defined by a0 = 6, a1 = 8, and for n>1 an = 4an-1 β 4an-2 Theorem 3 Let c1, c2 , c3 , β¦, ck be real numbers with ck nonzero. Suppose the equation rk β c1rk-1 β c2rk-2 β β¦ β ck-1r β ck = 0 has k distinct real roots r1 , r2 , β¦ , rk. A sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 + β¦ + ckan-k if and only if an = Ξ±1r1n + Ξ±2r2n + β¦ + Ξ±krkn for n = 0, 1, 2, β¦, where Ξ±1, Ξ±2, β¦, Ξ±k are constants Example β’ Solve the recurrence relation for the sequence defined by a0 = 1, a1 = 1, a2 = 2, and for n > 1 an = 2an-1 + an-2 β 2an-3 7.3 Divide and Conquer Algorithms and Recurrence Relations Suppose an algorithm requires f(n) operations for a problem of size n, and suppose that for significant values of n the algorithm reduces to a recursive calls each of size n/b. Suppose also that the overhead of performing the calls and consolidating the results takes g(n) operations. This gives rise to a recurrence relation, namely f(n) = af(n/b) + g(n) Examples β’ Binary Search: f(n) = f(n/2)+2 β’ Maximum value in a sequence: f(n) = 2f(n/2)+2 β’ Merge Sort: 2f(n/2) + n Binary Search Solution by Iteration β’ Binary Search: f(n) = f(n/2)+2 Theorem 1 Let π be an increasing function that satisfies the recurrence relation π π = ππ π π +π whenever π is divisible by π, where π β₯ 1, π is an integer greater than 1, and π is a positive real number. Then π πlogπ π ππ π > 1 π(π) is . π(log π) ππ π = 1 Furthermore, when π = ππ , where π is a positive integer, π π = πΆ1 πlogπ π + πΆ2 , π π where πΆ1 = π 1 + πβ1 and πΆ2 = β πβ1. Example: Find π π when π = 3π , where π satisfies the recurrence relation π π π = 2π 3 + 4 with π 1 = 1. The Master Theorem If a recursive algorithm for a problem of size n makes a recursive calls on itself, each for a problem of size n/b, and if the overhead of performing the calls and consolidating the results is cnd, then the number f(n) of operations performed by the call is f(n) = af(n/b) + cnd, and f(n) is (a) O(nd) if a < bd, (b) O(nd log n) if a = bd, and (c) O(nlogb a ) if a > bd. Binary Search Solution using the Master Theorem β’ Binary Search: f(n) = f(n/2)+2 Fast Matrix Multiplication f(n) = 7f(n/2) + 15n2/4 7.5 Inclusion/Exclusion β’ Two-Set Version β’ Three-Set Version Example: Find the number of elements in π΄1 βͺ π΄2 βͺ π΄3 if there are 100 elements in each set and if a) The sets are pairwise disjoint b) There are 50 common elements in each pair of sets and no elements in all three sets c) There are 50 common elements in each pair of sets and 25 elements in all three sets d) The sets are equal Example: Suppose that 14 students receive an A on the first exam in a class, and 18 receive an A on the second exam. If 22 students received an A on either the first or the second exam, how many students received an A on both exams? The Generalized Principle of Inclusion/Exclusion 7.6 Applications of Inclusion/Exclusion β’ Finding a set with none of the properties P1, P2, β¦, Pn Example: Find the number of primes less than 40 Example: Find the number of onto functions from a set of 6 elements to a set of 4 elements. Find a formula for the number of onto functions from a set of m elements to a set of n elements where m β₯ n.