{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

divide and conquer-patterns - Chapter 5 Fundamental...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 Divide-and-Conquer . . . . . . . . . . . . . . . . . . . 263 5.2.1 Divide-and-Conquer Recurrence Equations . . . . . . 263 5.2.2 Integer Multiplication . . . . . . . . . . . . . . . . . 270 5.2.3 Matrix Multiplication . . . . . . . . . . . . . . . . . 272 5.3 Dynamic Programming . . . . . . . . . . . . . . . . . 274 5.3.1 Matrix Chain-Product . . . . . . . . . . . . . . . . . 274 5.3.2 The General Technique . . . . . . . . . . . . . . . . 278 5.3.3 The 0-1 Knapsack Problem . . . . . . . . . . . . . . 278 5.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 282
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
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 general-purpose 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, divide-and-conquer, 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. Divide-and-conquer is used in the merge-sort and quick-sort 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 divide-and- 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 divide-and-conquer recurrence equations, including a gen- eral master theorem that can be applied to a variety of equations.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern