This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Lecture Notes CMSC 251 Lecture 6: Divide and Conquer and MergeSort (Thursday, Feb 12, 1998) Read: Chapt. 1 (on MergeSort) and Chapt. 4 (on recurrences). Divide and Conquer: The ancient Roman politicians understood an important principle of good algorithm design (although they were probably not thinking about algorithms at the time). You divide your enemies (by getting them to distrust each other) and then conquer them piece by piece. This is called divideandconquer . In algorithm design, the idea is to take a problem on a large input, break the input into smaller pieces, solve the problem on each of the small pieces, and then combine the piecewise solutions into a global solution. But once you have broken the problem into pieces, how do you solve these pieces? The answer is to apply divideandconquer to them, thus further breaking them down. The process ends when you are left with such tiny pieces remaining (e.g. one or two items) that it is trivial to solve them. Summarizing, the main elements to a divideandconquer solution are Divide (the problem into a small number of pieces), Conquer (solve each piece, by applying divideandconquer recursively to it), and Combine (the pieces together into a global solution). There are a huge number computational problems that can be solved efficiently using divideand conquer. In fact the technique is so powerful, that when someone first suggests a problem to me, the first question I usually ask (after what is the bruteforce solution) is does there exist a divideand conquer solution for this problem? Divideandconquer algorithms are typically recursive, since the conquer part involves invoking the same technique on a smaller subproblem. Analyzing the running times of recursive programs is rather tricky, but we will show that there is an elegant mathematical concept, called a recurrence , which is useful for analyzing the sort of recursive programs that naturally arise in divideandconquer solutions. For the next couple of lectures we will discuss some examples of divideandconquer algorithms, and how to analyze them using recurrences. MergeSort: The first example of a divideandconquer algorithm which we will consider is perhaps the best known. This is a simple and very efficient algorithm for sorting a list of numbers, called MergeSort . We are given an sequence of n numbers A , which we will assume is stored in an array A [1 . . . n ] . The objective is to output a permutation of this sequence, sorted in increasing order. This is normally done by permuting the elements within the array A . How can we apply divideandconquer to sorting? Here are the major elements of the MergeSort algorithm....
View Full
Document
 Fall '11
 Staff

Click to edit the document details