Chapter
5
Fundamental Techniques
Contents
5.1
The Greedy Method
. . . . . . . . . . . . . . . . . . .
259
5.1.1
The Fractional Knapsack Problem
. . . . . . . . . .
259
5.1.2
Task Scheduling
. . . . . . . . . . . . . . . . . . . .
261
5.2
DivideandConquer
. . . . . . . . . . . . . . . . . . .
263
5.2.1
DivideandConquer Recurrence Equations
. . . . . .
263
5.2.2
Integer Multiplication
. . . . . . . . . . . . . . . . .
270
5.2.3
Matrix Multiplication
. . . . . . . . . . . . . . . . .
272
5.3
Dynamic Programming
. . . . . . . . . . . . . . . . .
274
5.3.1
Matrix ChainProduct
. . . . . . . . . . . . . . . . .
274
5.3.2
The General Technique
. . . . . . . . . . . . . . . .
278
5.3.3
The 01 Knapsack Problem
. . . . . . . . . . . . . .
278
5.4
Exercises
. . . . . . . . . . . . . . . . . . . . . . . . .
282
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
258
Chapter 5. Fundamental Techniques
A popular television network broadcasts two different shows about carpentry.
In one show, the host builds furniture using specialized power tools, and in the other
the host builds furniture using generalpurpose hand tools. The specialized tools,
used in the first show, are good at the jobs they are intended for, but none of them
is very versatile. The tools in the second show are fundamental, however, because
they can be used effectively for a wide variety of different tasks.
These two television shows provide an interesting metaphor for data structure
and algorithm design. There are some algorithmic tools that are quite specialized.
They are good for the problems they are intended to solve, but they are not very
versatile. There are other algorithmic tools, however, that are
fundamental
in that
they can be applied to a wide variety of different data structure and algorithm design
problems. Learning to use these fundamental techniques is a craft, and this chapter
is dedicated to developing the knowledge for using these techniques effectively.
The fundamental techniques covered in this chapter are the greedy method,
divideandconquer, and dynamic programming.
These techniques are versatile,
and examples are given both in this chapter and in other chapters of this book.
The greedy method is used in algorithms for weighted graphs discussed in
Chapter 7, as well as a data compression problem presented in Section 9.3. The
main idea of this technique, as the name implies, is to make a series of greedy
choices in order to construct an optimal solution (or close to optimal solution) for a
given problem. In this chapter, we give the general structure for the greedy method
and show how it can be applied to knapsack and scheduling problems.
Divideandconquer is used in the mergesort and quicksort algorithms of Chap
ter 4. The general idea behind this technique is to solve a given problem by dividing
it into a small number of similar subproblems, recursively solve each of the sub
problems until they are small enough to solve by brute force, and, after the recursive
calls return, merge all the subproblems together to derive a solution to the original
problem. In this chapter, we show how to design and analyze general divideand
conquer algorithms and we give additional applications of this technique to the
problems of multiplying big integers and large matrices. We also give a number of
techniques for solving divideandconquer recurrence equations, including a gen
eral master theorem that can be applied to a variety of equations.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '14
 Dynamic Programming, Fundamental Techniques

Click to edit the document details