This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Algorithms Lecture 1: Recursion [ Fa’10 ] Our life is frittered away by detail. Simplify, simplify. — Henry David Thoreau The control of a large force is the same principle as the control of a few men: it is merely a question of dividing up their numbers. — Sun Zi, The Art of War (c. 400 C.E.), translated by Lionel Giles (1910) Nothing is particularly hard if you divide it into small jobs. — Henry Ford 1 Recursion 1.1 Simplify and delegate Reduction is the single most common technique used in designing algorithms. Reducing one problem X to another problem (or set of problems) Y means to write an algorithm for X , using an algorithm or Y as a subroutine or black box. For example, the congressional apportionment algorithm described in Lecture 0 reduces the problem of apportioning Congress to the problem of maintaining a priority queue under the operations I NSERT and E XTRACTMAX. Those data structure operations are black boxes; the apportionment algorithm does not depend on any specific implementation. Conversely, when we design a particular priority queue data structure, we typically neither know nor care how our data structure will be used. Whether or not the Census Bureau plans to use our code to apportion Congress is completely irrelevant to our design choices. As a general rule, when we design algorithms, we may not know— and we should not care —how the basic building blocks we use are implemented, or how your algorithm might be used as a basic building block to solve a bigger problem. A particularly powerful kind of reduction is recursion , which can be defined loosely as follows: • If the given instance of the problem is small or simple enough, just solve it. • Otherwise, reduce the problem to one or more simpler instances of the same problem . If the selfreference is confusing, it’s helpful to imagine that someone else is going to solve the simpler problems, just as you would assume for other types of reductions. Your only task is to simplify the original problem, or to solve it directly when simplification is either unnecessary or impossible. The Recursion Fairy will magically take care of the simpler subproblems. 1 There is one mild technical condition that must be satisfied in order for any recursive method to work correctly, namely, that there is no infinite sequence of reductions to ‘simpler’ and ‘simpler’ subproblems. Eventually, the recursive reductions must stop with an elementary base case that can be solved by some other method; otherwise, the recursive algorithm will never terminate. This finiteness condition is almost always satisfied trivially, but we should always be wary of ‘obvious’ recursive algorithms that actually recurse forever....
View
Full
Document
This note was uploaded on 03/05/2011 for the course ECE 514 taught by Professor Cormen during the Spring '11 term at MIT.
 Spring '11
 Cormen
 Algorithms, Recursion

Click to edit the document details