当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《Mathematics for Computer》Lecture 12 recur2

资源类别:文库,文档格式:PDF,文档页数:15,文件大小:256.18KB,团购合买
Recursion-breaking an object down into smaller objects of the same typeis a ma- jor theme in mathematics and computer science. For example, in an induction proof we establish the truth of a statement()from the truth of the statement P(n-1). In pro- gramming, a recursive algorithm solves a problem by applying itself to smaller instances
点击下载完整版文档(PDF)

6.042/18.] Mathematics for Computer Science March 17.2005 Srini devadas and Eric Lehman Lecture notes Recurrences Recursion-- breaking an object down into smaller objects of the same type-is a ma jor theme in mathematics and computer science. For example, in an induction proof we establish the truth of a statement P(n) from the truth of the statement P(n-1). In pro- gramming, a recursive algorithm solves a problem by applying itself to smaller instances of the problem. back on the mathematical side a recurrence equation describes the value of a function in terms of its value for smaller arguments. These various incarnations of re- cursion work together nicely. For example one might prove a recursive algorithm correct sing induction or analyze its running time using a recurrence equation In this lecture, well learn how to solve a family of recurrence equations, called"linear recurrences", that frequently arise in computer science and other disciplines 1 The Towers of hano In the Towers of Hanoi problem, there are three posts and seven disks of different sizes Each disk has a hole through the center so that it fits on a post at the start all seven disks are on post #1 as shown below. The disks are arranged by size so that the smallest is on top and the largest is on the bottom. The goal is to end up with all seven disks in the same order, but on a different post. This is not trivial because of two restrictions. First, the only ermitted action is removing the top disk from a post and dropping it onto another post Second, a larger disk can never lie above a smaller disk on any post. (These rules imply, for example, that it is no fair to pick up the whole stack of disks at once and then to drop them all on another post Post #1 Post #2 Post #3 It is not immediately clear that a solution to this problem exists; maybe the rules are so stringent that the disks cannot all be moved to another post!

6.042/18.062J Mathematics for Computer Science March 17, 2005 Srini Devadas and Eric Lehman Lecture Notes Recurrences Recursion— breaking an object down into smaller objects of the same type— is a ma￾jor theme in mathematics and computer science. For example, in an induction proof we establish the truth of a statement P(n) from the truth of the statement P(n − 1). In pro￾gramming, a recursive algorithm solves a problem by applying itself to smaller instances of the problem. Back on the mathematical side, a recurrence equation describes the value of a function in terms of its value for smaller arguments. These various incarnations of re￾cursion work together nicely. For example one might prove a recursive algorithm correct using induction or analyze its running time using a recurrence equation. In this lecture, we’ll learn how to solve a family of recurrence equations, called “linear recurrences”, that frequently arise in computer science and other disciplines. 1 The Towers of Hanoi In the Towers of Hanoi problem, there are three posts and seven disks of different sizes. Each disk has a hole through the center so that it fits on a post. At the start, all seven disks are on post #1 as shown below. The disks are arranged by size so that the smallest is on top and the largest is on the bottom. The goal is to end up with all seven disks in the same order, but on a different post. This is not trivial because of two restrictions. First, the only permitted action is removing the top disk from a post and dropping it onto another post. Second, a larger disk can never lie above a smaller disk on any post. (These rules imply, for example, that it is no fair to pick up the whole stack of disks at once and then to drop them all on another post!) Post #1 Post #2 Post #3 It is not immediately clear that a solution to this problem exists; maybe the rules are so stringent that the disks cannot all be moved to another post!

Recurrences One approach to this problem is to consider a simpler variant with only three disks We can quickly exhaust the possibilities of this simpler puzzle and find a 7-move solution such as the one shown below. (The disks on each post are indicated by the numbers immediately to the right. Larger numbers correspond to larger disks. 2 31 This problem was invented in 1883 by the French mathematician Edouard Lucas. In his original account, there were 64 disks of solid gold. At the beginning of time, all 64 were placed on a single post, and monks were assigned the task of moving them to another post according to the rules described above. According to legend, when the monks complete their task the Tower will crumble and the world will end The questions we must answer are, Given sufficient time, can the monks succeed? and if so, How long until the world ends? and, most importantly, "Will this happer before the 6.042 final? 1.1 Finding a Recurrence The Towers of Hanoi problem can be solved recursively as follows. Let Tn be the min imum number of steps needed to move an n-disk tower from one post to another. For example, a bit of experimentation shows that Ti= l and T2=3. For 3 disks, the solution given above proves that T3 <7. We can generalize the approach used for 3 disks to the following recursive algorithm for n disks. Step 1. Apply this strategy recursively to move the top n- 1 disks from the first post to the third post This can be done in Tn-1

2 Recurrences One approach to this problem is to consider a simpler variant with only three disks. We can quickly exhaust the possibilities of this simpler puzzle and find a 7­move solution such as the one shown below. (The disks on each post are indicated by the numbers immediately to the right. Larger numbers correspond to larger disks.) 1 2 3 ⇒ 2 3 1 ⇒ 3 1 2 ⇒ 3 1 2 ⇒ 3 1 2 ⇒ 1 3 2 ⇒ 1 2 3 ⇒ 1 2 3 This problem was invented in 1883 by the French mathematician Edouard Lucas. In his original account, there were 64 disks of solid gold. At the beginning of time, all 64 were placed on a single post, and monks were assigned the task of moving them to another post according to the rules described above. According to legend, when the monks complete their task, the Tower will crumble and the world will end! The questions we must answer are, “Given sufficient time, can the monks succeed?” and if so, “How long until the world ends?” and, most importantly, “Will this happen before the 6.042 final?” 1.1 Finding a Recurrence The Towers of Hanoi problem can be solved recursively as follows. Let Tn be the min￾imum number of steps needed to move an n­disk tower from one post to another. For example, a bit of experimentation shows that T1 = 1 and T2 = 3. For 3 disks, the solution given above proves that T3 ≤ 7. We can generalize the approach used for 3 disks to the following recursive algorithm for n disks. Step 1. Apply this strategy recursively to move the top n − 1 disks from the first post to the third post. This can be done in Tn−1 steps. 1 2 . . . n ⇒ n 1 2 . . . n −1

Step 2. Move the largest disk from the first post to the to the second post. This requires just I step n-1 Step 3. Recursively move the n-1 disks on the third post over to the second post. Again, Tn-I steps are required 2 Q. This algorithm shows that Tn, the number of steps required to move n disks to a dif- rent post, is at most 2Tn-1+ 1. We can use this fact to compute upper bounds on the number of steps required for various numbers of disks 13≤2·T2 74<2·T3+1 The algorithm described above answers our first question: given sufficient time, the monks will finish their task and end the world. which is a shame. After all that effort theyd probably want to smack a few high-fives and go out for burgers and ice cream, but nope--world's over. 1.2 A Lower bound for towers of hanoi We can not yet compute the exact number of steps that the monks need to move the 64 disks; we can only show an upper bound. Perhaps-having pondered the problem since the beginning of time-the monks have devised a better algorithm In fact, there is no better algorithm, and here is why. At some step, the monks must move the n-th disk from the first post to a different post. For this to happen, the n-1 smaller disks must all be stacked out of the way on the only remaining post. Arranging the n- l smaller disks this way requires at least Tn-1 moves. After the largest disk is moved at least another In-1 moves are required to pile the n- l smaller disks on top

Recurrences 3 Step 2. Move the largest disk from the first post to the to the second post. This requires just 1 step. 1 2 . . . ⇒ n n −1 n 1 2 . . . n −1 Step 3. Recursively move the n−1 disks on the third post over to the second post. Again, Tn−1 steps are required. 1 2 . . . ⇒ n n −1 1 2 . . . n This algorithm shows that Tn, the number of steps required to move n disks to a dif￾ferent post, is at most 2Tn−1 + 1. We can use this fact to compute upper bounds on the number of steps required for various numbers of disks: T3 ≤ 2 · T2 + 1 = 7 T4 ≤ 2 · T3 + 1 ≤ 15 The algorithm described above answers our first question: given sufficient time, the monks will finish their task and end the world. (Which is a shame. After all that effort they’d probably want to smack a few high­fives and go out for burgers and ice cream, but nope— world’s over.) 1.2 A Lower Bound for Towers of Hanoi We can not yet compute the exact number of steps that the monks need to move the 64 disks; we can only show an upper bound. Perhaps— having pondered the problem since the beginning of time— the monks have devised a better algorithm. In fact, there is no better algorithm, and here is why. At some step, the monks must move the n­th disk from the first post to a different post. For this to happen, the n − 1 smaller disks must all be stacked out of the way on the only remaining post. Arranging the n − 1 smaller disks this way requires at least Tn−1 moves. After the largest disk is moved, at least another Tn−1 moves are required to pile the n − 1 smaller disks on top

Recurrences This argument shows that the number of steps required is at least 2Tn-1+ 1. Since we gave an algorithm using exactly that number of steps, we now have a recurrence for Tn, the number of moves required to complete the tower of hanoi problem with n disks T1=1 Tn=21n-1+1 (forn≥2) can use this recurrence to conclude that T2=3, T3=7, T4=15, 1.3 Guess-and-Verify Computing T64 from the recurrence would require a lot of work. It would be nice to have a closed form expression for Tn, so that we could quickly compute the number of steps required to solve the Towers of Hanoi problem for any given number of disks.(For example, we might want to know how much sooner the world would end if the monks melted down one disk to purchase burgers and ice cream before the end of the world There are several different methods for solving recurrences. The simplest method is guess the solution and then to verify that the guess is correct, usually with an induction proof. This method is called guess-and-verify or"substitution". As a basis for a good guess, let's tabulate Tn for small values of n mI T 23 415 531 Based on this table, a natural guess is that Tn= 2n-1 Whenever you guess a solution to a recurrence, you should always verify it with a proof by induction or by some other technique; after all, your guess might be wrong. But why bother to verify in this case? After all, if were wrong, its not the end of the.no, lets check. Claim. If T1=1 Tn=2Tn-1+1 (forn≥2) the

4 Recurrences This argument shows that the number of steps required is at least 2Tn−1 + 1. Since we gave an algorithm using exactly that number of steps, we now have a recurrence for Tn, the number of moves required to complete the Tower of Hanoi problem with n disks: T1 = 1 Tn = 2Tn−1 + 1 (for n ≥ 2) We can use this recurrence to conclude that T2 = 3, T3 = 7, T4 = 15, . . .. 1.3 Guess­and­Verify Computing T64 from the recurrence would require a lot of work. It would be nice to have a closed form expression for Tn, so that we could quickly compute the number of steps required to solve the Towers of Hanoi problem for any given number of disks. (For example, we might want to know how much sooner the world would end if the monks melted down one disk to purchase burgers and ice cream before the end of the world.) There are several different methods for solving recurrences. The simplest method is to guess the solution and then to verify that the guess is correct, usually with an induction proof. This method is called guess­and­verify or “substitution”. As a basis for a good guess, let’s tabulate Tn for small values of n: n 1 1 2 3 3 7 4 15 5 31 6 63 Tn n Based on this table, a natural guess is that Tn = 2 − 1. Whenever you guess a solution to a recurrence, you should always verify it with a proof by induction or by some other technique; after all, your guess might be wrong. (But why bother to verify in this case? After all, if we’re wrong, its not the end of the. . . no, let’s check.) Claim. If: T1 = 1 Tn = 2Tn−1 + 1 (for n ≥ 2) then: Tn = 2n − 1

R Proof. The proof is by induction on n. Let P(n) be the proposition that Tn=2n-1. Base case: P(1)is true because T1=1=2-1 Inductive step: Now we assume Tn=2n-1 to prove that T+1=2n+I-l, wherein>1 2Tn+1 2(2-1) 2n+1-1 The first equality is the recurrence relation, and the second equation follows by the as- sumption P(n). The last step is simplification Our guess is now verified. This shows, for example, that the 7-disk puzzle will require 2-1=127 moves to complete. We can also now resolve our remaining questions about the 64-disk puzzle. Since T64=204-l, the monks must complete more than 18 billion billion steps before the world ends. Better study for the final 2 Graduate Student Job Prospects In a new academic field (say, computer science), there are only so many faculty positions available in all the universities of the world. Initially, there were not enough qualified candidates, and many positions were unfilled. But, over time, new graduates are filling the positions, making job prospects for later computer science students ever more bleak Worse, the increasing number of professors are able to train an increasing number of graduate students, causing positions to fill ever more rapidly. Eventually, the universities will be saturated; new computer science graduates will have no chance at an academic career. Our problem is to determine when the universities will stop hiring new computer science faculty and in particular, to answer the question, Are the 6.042 TAs doomed? Here are the details of the problem There are a total of N faculty positions available worldwide. This number never due to budgetary constraints Congress has passed a law forbidding forced retirement in universities, and no one will retire voluntarily.(This is true and a problem! ) In our analysis, therefore, once a faculty position is filled, it never opens up again Each year, every professor trains exactly 1 student who will go on to become a pro- fessor the following year. The only exception is that first year professors do not train students; they are too busy publishing teaching, getting grants, and serving on committees In year 0, there are no computer science professors in the world. In year 1, the first professor is hired

Recurrences 5 n Proof. The proof is by induction on n. Let P(n) be the proposition that Tn = 2 − 1. 1 Base case: P(1) is true because T1 = 1 = 2 − 1. Inductive step: Now we assume Tn = 2n − 1 to prove that Tn+1 = 2n+1 − 1, where n ≥ 1. Tn+1 = 2Tn + 1 = 2(2n − 1) + 1 = 2n+1 − 1 The first equality is the recurrence relation, and the second equation follows by the as￾sumption P(n). The last step is simplification. Our guess is now verified. This shows, for example, that the 7­disk puzzle will require 27 − 1 = 127 moves to complete. We can also now resolve our remaining questions about the 64­disk puzzle. Since T64 = 264 − 1, the monks must complete more than 18 billion billion steps before the world ends. Better study for the final. 2 Graduate Student Job Prospects In a new academic field (say, computer science), there are only so many faculty positions available in all the universities of the world. Initially, there were not enough qualified candidates, and many positions were unfilled. But, over time, new graduates are filling the positions, making job prospects for later computer science students ever more bleak. Worse, the increasing number of professors are able to train an increasing number of graduate students, causing positions to fill ever more rapidly. Eventually, the universities will be saturated; new computer science graduates will have no chance at an academic career. Our problem is to determine when the universities will stop hiring new computer science faculty and, in particular, to answer the question, “Are the 6.042 TAs doomed?” Here are the details of the problem. • There are a total of N faculty positions available worldwide. This number never changes due to budgetary constraints. • Congress has passed a law forbidding forced retirement in universities, and no one will retire voluntarily. (This is true and a problem!) In our analysis, therefore, once a faculty position is filled, it never opens up again. • Each year, every professor trains exactly 1 student who will go on to become a pro￾fessor the following year. The only exception is that first year professors do not train students; they are too busy publishing, teaching, getting grants, and serving on committees. • In year 0, there are no computer science professors in the world. In year 1, the first professor is hired

Recurrences 2.1 Finding a recurrence Ideally, we could find a formula for the number of professors in the world in a given year Then we could determine the year in which all N faculty positions are filled. Let f(n) be the number of professors during year n. To develop some intuition about the problem, we can compute values of this function for small n by hand f(0)=0 No CS professors; the dark ages f 1 new professor; too busy to train a student. f(2)=1 1 old professor; now training a student f 3)=2 1 new prof, 1 old prof; new prof too busy, old prof training f (4)=3 1 new prof, 2 old profs; new prof too busy, both old profs training f(5)=5 2 new profs, 3 old profs f(6)=8 3 new profs, 5 old profs In general, the number of professors in year n is equal to the number of professors last ear plus the number of new hires. The number of professors last year is f(n-1). The number of new hires is equal to the number of professors two years ago, f(n-2), since each of these professors trained a student last year. These observations give the following recurrence equation for the number of professors f(1)=1 f(m)=∫(n-1)+f(-2)(n≥2) This is the familiar Fibonacci recurrence. Looking back, the values of f(n) that we computed by hand are indeed the first few Fibonacci numbers. Fibonacci numbers arise in all sorts of applications. Fibonacci himself introduced the numbers in 1202 to study rabbit reproduction. Fibonacci numbers also appear, oddly enough, in the spiral patterns on the faces of sunflowers. And the input numbers that make Euclids GCD algorithm require the greatest number of steps are consecutive Fibonacci numbers. So how bi f(n)anyway? could many Fiona lbers as we like using the recurrence but it would be much nicer to find a closed form 2.2 Solving the recurrence Solving the Fibonacci recurrence is easy because the recurrence is linear (Well,"ea the sense that you can learn the technique in one lecture: discovering it actually took six

6 Recurrences 2.1 Finding a Recurrence Ideally, we could find a formula for the number of professors in the world in a given year. Then we could determine the year in which all N faculty positions are filled. Let f(n) be the number of professors during year n. To develop some intuition about the problem, we can compute values of this function for small n by hand. f(0) = 0 No CS professors; the dark ages. f(1) = 1 1 new professor; too busy to train a student. f(2) = 1 1 old professor; now training a student. f(3) = 2 1 new prof, 1 old prof; new prof too busy, old prof training. f(4) = 3 1 new prof, 2 old profs; new prof too busy, both old profs training f(5) = 5 2 new profs, 3 old profs f(6) = 8 3 new profs, 5 old profs In general, the number of professors in year n is equal to the number of professors last year plus the number of new hires. The number of professors last year is f(n − 1). The number of new hires is equal to the number of professors two years ago, f(n − 2), since each of these professors trained a student last year. These observations give the following recurrence equation for the number of professors: f(0) = 0 f(1) = 1 f(n) = f(n − 1) + f(n − 2) (n ≥ 2) This is the familiar Fibonacci recurrence. Looking back, the values of f(n) that we computed by hand are indeed the first few Fibonacci numbers. Fibonacci numbers arise in all sorts of applications. Fibonacci himself introduced the numbers in 1202 to study rabbit reproduction. Fibonacci numbers also appear, oddly enough, in the spiral patterns on the faces of sunflowers. And the input numbers that make Euclid’s GCD algorithm require the greatest number of steps are consecutive Fibonacci numbers. So how big is f(n) anyway? Of course, we could compute as many Fibonacci numbers as we like using the recurrence, but it would be much nicer to find a closed form. 2.2 Solving the Recurrence Solving the Fibonacci recurrence is easy because the recurrence is linear. (Well, “easy” in the sense that you can learn the technique in one lecture; discovering it actually took six

Recurrences centuries.)A linear recurrence has the form: f(n)=a1f(n-1)+a2f(m-2)+…+af(n-d) ∑bf(n-) where a1, a2,. ad are constants. The order of the recurrence is d. For example, the Fi bonacci recurrence is order 2 and has coefficients a1 a2=1.(Later on, we'll slightly expand the definition of a linear recurrence. For now, let's try to solve just the Fibonacci recurrence; well see how to solve general linear recurrences later in the lecture. Our rule of thumb is that guess-and-verify is the first method to apply to an unfamiliar recurrence. It turns out that for a linear recurrence, an exponential solution is a good guess. However, since we know nothing beyond this, our initial guess-and-erify attempt will really only be a"dry run"; that is, we will not make an exact guess and will not verify it with a complete proof. Rather, the goal of thi first attempt is only to clarify the form of the solution Guess. f(n)=ca" Here c and r are parameters introduced to improve our odds of having a correct guess, n the verification step, we can pick values that make the proof work. To further improve odds, let's neglect the boundary cond f(0)=0andf(1)=1 verification. Plugging our guess into the recurrence f(n)=f(n-1)+f(n-2) gives x2=x+1 l=0 1士√5 In the first step, we divide both sides of the equation by crn-. Then we rearrange terms and find a with the quadratic formula This calculation suggests that the constant c can be anything but that r must be (1±√⑤)/2. Evidently, there are two solutions to the recurrence: f(n) 1+√5 In fact, any linear combination of these two solutions is also a solution. The following theorem states that this is true in general for linear recurrences Theorem 1. If f(n)and g(n) are solutions to a linear recurrence(without boundary conditions), then cf(n)+ dg(n) is also a solution

� Recurrences 7 centuries.) A linear recurrence has the form: f(n) = a1f(n − 1) + a2f(n − 2) + . . . + adf(n − d) d = bif(n − i) i=1 where a1, a2, . . . ad are constants. The order of the recurrence is d. For example, the Fi￾bonacci recurrence is order 2 and has coefficients a1 = a2 = 1. (Later on, we’ll slightly expand the definition of a linear recurrence.) For now, let’s try to solve just the Fibonacci recurrence; we’ll see how to solve general linear recurrences later in the lecture. Our rule of thumb is that guess­and­verify is the first method to apply to an unfamiliar recurrence. It turns out that for a linear recurrence, an exponential solution is a good guess. However, since we know nothing beyond this, our initial guess­and­erify attempt will really only be a “dry run”; that is, we will not make an exact guess and will not verify it with a complete proof. Rather, the goal of this first attempt is only to clarify the form of the solution. Guess. n f(n) = cx Here c and x are parameters introduced to improve our odds of having a correct guess; in the verification step, we can pick values that make the proof work. To further improve our odds, let’s neglect the boundary conditions, f(0) = 0 and f(1) = 1. Verification. Plugging our guess into the recurrence f(n) = f(n − 1) + f(n − 2) gives: n n−1 cx = cx + cx n−2 2 x = x + 1 2 x − x − 1 = 0 1 ± √5 x = 2 In the first step, we divide both sides of the equation by cxn−2. Then we rearrange terms and find x with the quadratic formula. This calculation suggests that the connstant c can be anything, but that x must be (1 ± √5)/2. Evidently, there are two solutions to the recurrence: � � 1 − √5 n �n 1 + √5 � f(n) = c or f(n) = c 2 2 In fact, any linear combination of these two solutions is also a solution. The following theorem states that this is true in general for linear recurrences. Theorem 1. If f(n) and g(n) are solutions to a linear recurrence (without boundary conditions), then cf (n) + dg(n) is also a solution

ecurrences Proof. Since f(n)and g(n)are both solutions, then f(n)=∑ ait(n-2 g(n) aig (n Multiplying the first equation by c, the second by d, and summing gives cf(n)+dgn)=c a;f(n-)]+d n ∑a(c∫(n-1)+d(m-i) Thus, cf(n)+dg(n)is a solution as well al his same phenomenonthat a linear combination of solutions is another solution- pree rises in differential equations and, consequently many physical systems. In the +√5 f(n) +C2 2 is a solution to the Fibonacci recurrence without boundary conditions for all constants cr and c?. all that remains is to choose these constants to obtain a solution consistent with the boundary conditions, f(0)=0 and f(1)=1. From the first condition, we know: f(0)=c1 + C2 From the second boundary condition, we have f(1)=C1 +C2 We now have two linear equations in two unknowns. The system of equations is not have a complete solution to the Fibonacci recurrence with boundary condition. One! We degenerate, so there is a unique solution: C1= 1/v5 and f(n)

� � � � � � � � � � � 8 Recurrences Proof. Since f(n) and g(n) are both solutions, then: d f(n) = aif(n − i) i=1 d g(n) = aig(n − i) i=1 Multiplying the first equation by c, the second by d, and summing gives: d d cf (n) + dg(n) = c a · if(n − i) + d a · ig(n − i) i=1 i=1 d = ai cf (n − i) + dg(n − i) i=1 Thus, cf (n) + dg(n) is a solution as well. This same phenomenon— that a linear combination of solutions is another solution— also arises in differential equations and, consequently, many physical systems. In the present case, the theorem implies that � � 1 − √5 n �n 1 + √5 � f(n) = c1 + c2 2 2 is a solution to the Fibonacci recurrence without boundary conditions for all constants c1 and c2. All that remains is to choose these constants to obtain a solution consistent with the boundary conditions, f(0) = 0 and f(1) = 1. From the first condition, we know: � � 1 − √5 �0 1 + √5 �0 f(0) = c1 + c2 = c1 + c2 = 0 2 2 From the second boundary condition, we have: � � 1 − √5 �1 1 + √5 �1 f(1) = c1 + c2 = 1 2 2 We now have two linear equations in two unknowns. The system of equations is not degenerate, so there is a unique solution: c1 = 1/ √5 and c2 = −1/ √5. We’re done! We have a complete solution to the Fibonacci recurrence with boundary conditions: � � 1 − √5 n �n 1 1 + √5 � 1 f(n) = √5 2 − √5 2

Recurrences This looks completely wrong! All Fibonacci numbers are integers, but this expression is full of square roots of five! Amazingly, however, the square roots always cancel out. This on really does give the Fibonacci numbers if we plu 0,1,2,,…,It to see why no one stumbled across this solution for six centuries 2.3 Job Prospects Let's return to the original question: how long until all N faculty positions are taken? To answer this question, we must find the smallest n such that f(n)> N; that is,we must determine the year n in which there are as many potential professors as university positions. Graduates after year n will have to find other employment, e.g. shuffling golden disks in an obscure monastic community for the next 10 years Because f(n) has such a complicated form, it is hard to compute the right value of n exactly. However, we can find an excellent approximate answer. Note that in the closed form for Fibonacci numbers, the second term rapidly goes to zero ()=1 171+√5 11+√5 +o(1) This is because I(1-V5)/2=0.618..< l, and a big power of a number less than 1 is From this approximation for f(n), we can estimate the year in which all faculty posi tions will be filled. That happens when f(n)≈ Thus all jobs are filled in about n years where: log(√5N+o(1) log(1+25) e(log N) This makes sense, since the number of professors is increasing exponentially. For exam ple, N=10, 000 jobs would all be taken in about n= 20.8 years. Your TAs don t have a moment to lose The solution to the Fibonacci recurrence has an interesting corollary. The number

� � � Recurrences 9 This looks completely wrong! All Fibonacci numbers are integers, but this expression is full of square roots of five! Amazingly, however, the square roots always cancel out. This expression really does give the Fibonacci numbers if we plug in n = 0, 1, 2, . . .. It is easy to see why no one stumbled across this solution for six centuries! 2.3 Job Prospects Let’s return to the original question: how long until all N faculty positions are taken? To answer this question, we must find the smallest n such that f(n) ≥ N; that is, we must determine the year n in which there are as many potential professors as university positions. Graduates after year n will have to find other employment, e.g. shuffling golden disks in an obscure monastic community for the next 1019 years. Because f(n) has such a complicated form, it is hard to compute the right value of n exactly. However, we can find an excellent approximate answer. Note that in the closed form for Fibonacci numbers, the second term rapidly goes to zero: � � 1 − √5 n �n 1 1 + √5 � 1 f(n) = √5 2 − √5 2 n 1 1 + √5 � = √ + o(1) 5 2 This is because (1 − √ | | 5)/2 = 0.618 . . . < 1, and a big power of a number less than 1 is tiny. From this approximation for f(n), we can estimate the year in which all faculty posi￾tions will be filled. That happens when: n 1 1 + √5 � f(n) ≈ √ ≥ N 5 2 Thus, all jobs are filled in about n years where: log(√5 N + o(1)) n = log( 1+ 2 √5 ) = Θ(log N) This makes sense, since the number of professors is increasing exponentially. For exam￾ple, N = 10, 000 jobs would all be taken in about n = 20.8 years. Your TAs don’t have a moment to lose! The solution to the Fibonacci recurrence has an interesting corollary. The number: 1 + √5 � φ = 2

Recurrences is often called the"Golden ratio". We can write the dominant term in the closed form for the n-th Fibonacci number in terms of the f(n) √5 Weve just shown that this expression involving irrational numbers is actually very close to an integer for all large n- namely, the n-th Fibonacci number. This is just one of many curious properties of the Golden ratio 3 General Linear recurrences The method we used to solve the Fibonacci recurrence can actually be used to solve any linear recurrence. Recall that a recurrence is linear if it has the form: f(n)=a1f(n-1)+a2f(n-2)+…+aaf(m-d) Substituting the guess f(n)=r", as with the Fibonacci recurrence, gives 2 +ad_+ ad Dividing the first equation by an-d gives the second. This second equation is called the characteristic equation of the recurrence. The characteristic equation can be read off very quickly since the coefficients of the equation are the same as the coefficients of the recur- rence The solutions to a linear recurrence are defined by the roots of the characteristic equa- tion. Neglecting boundary conditions for the moment If r is a nonrepeated root of the characteristic equation, then rn is a solution to the recurrence. If r is a repeated root with multiplicity k, then are all solutions to the recurr Futhermore, Theorem 1 implies that every linear combination of these solutions is also a olution For example, suppose that the characteristic equation of a recurrence has roots r1, r2, and r3 twice. These four roots imply four distinct solutions f(n)=rn f(n)=r2 f(n)=r3 f(n)=nr3

10 Recurrences is often called the “Golden Ratio”. We can write the dominant term in the closed form for the n­th Fibonacci number in terms of the φ: n φ f(n) = + √ o(1) 5 We’ve just shown that this expression involving irrational numbers is actually very close to an integer for all large n— namely, the n­th Fibonacci number. This is just one of many curious properties of the Golden Ratio. 3 General Linear Recurrences The method we used to solve the Fibonacci recurrence can actually be used to solve any linear recurrence. Recall that a recurrence is linear if it has the form: f(n) = a1f(n − 1) + a2f(n − 2) + . . . + adf(n − d) Substituting the guess f(n) = xn, as with the Fibonacci recurrence, gives: n n−d x = a1x n−1 + a2x n−2 + . . . + adx d x = a1x d−1 + a2x d−2 + . . . + ad−1x + ad Dividing the first equation by xn−d gives the second. This second equation is called the characteristic equation of the recurrence. The characteristic equation can be read off very quickly since the coefficients of the equation are the same as the coefficients of the recur￾rence. The solutions to a linear recurrence are defined by the roots of the characteristic equa￾tion. Neglecting boundary conditions for the moment: • If r is a nonrepeated root of the characteristic equation, then rn is a solution to the recurrence. • If r is a repeated root with multiplicity k, then n n 2 n n r , nr , n r , . . . , n k−1 r are all solutions to the recurrence. Futhermore, Theorem 1 implies that every linear combination of these solutions is also a solution. For example, suppose that the characteristic equation of a recurrence has roots r1, r2, and r3 twice. These four roots imply four distinct solutions: n n n f(n) = r1 f(n) = r2 f(n) = n f(n) = nr3 r3

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共15页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有