This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 10 “mcsftl” — 2010/9/8 — 0:40 — page 283 — #289 Recurrences A recurrence describes a sequence of numbers. Early terms are specified explic itly and later terms are expressed as a function of their predecessors. As a trivial example, this recurrence describes the sequence 1, 2, 3, etc.: T 1 D 1 T n D T n 1 C 1 (for n 2 ) : Here, the first term is defined to be 1 and each subsequent term is one more than its predecessor. Recurrences turn out to be a powerful tool. In this chapter, we’ll emphasize using recurrences to analyze the performance of recursive algorithms. However, recur rences have other applications in computer science as well, such as enumeration of structures and analysis of random processes. And, as we saw in Section 9.4 , they also arise in the analysis of problems in the physical sciences. A recurrence in isolation is not a very useful description of a sequence. One can not easily answer simple questions such as, “What is the hundredth term?” or “What is the asymptotic growth rate?” So one typically wants to solve a recurrence; that is, to find a closedform expression for the n th term. We’ll first introduce two general solving techniques: guessandverify and plug andchug. These methods are applicable to every recurrence, but their success re quires a ﬂash of insight—sometimes an unrealistically brilliant ﬂash. So we’ll also introduce two big classes of recurrences, linear and divideandconquer, that often come up in computer science. Essentially all recurrences in these two classes are solvable using cookbook techniques; you follow the recipe and get the answer. A drawback is that calculation replaces insight. The “Aha!” moment that is essential in the guessandverify and plugandchug methods is replaced by a “Huh” at the end of a cookbook procedure. At the end of the chapter, we’ll develop rules of thumb to help you assess many recurrences without any calculation. These rules can help you distinguish promis ing approaches from bad ideas early in the process of designing an algorithm. Recurrences are one aspect of a broad theme in computer science: reducing a big problem to progressively smaller problems until easy base cases are reached. This same idea underlies both induction proofs and recursive algorithms. As we’ll see, all three ideas snap together nicely. For example, one might describe the running time of a recursive algorithm with a recurrence and use induction to verify the solution. 284 “mcsftl” — 2010/9/8 — 0:40 — page 284 — #290 Chapter 10 Recurrences Figure 10.1 The initial configuration of the disks in the Towers of Hanoi problem. 10.1 The Towers of Hanoi According to legend, there is a temple in Hanoi with three posts and 64 gold disks of different sizes. Each disk has a hole through the center so that it fits on a post....
View
Full Document
 Fall '10
 TomLeighton,Dr.MartenvanDijk
 Computer Science, Recursion, Tn, Recurrence relation, Hanoi, Fibonacci number, recurrence

Click to edit the document details