lect6-divide-conquer-mergesort

lect6-divide-conquer-mergesort - Lecture Notes CMSC 251...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 divide-and-conquer . 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 divide-and-conquer 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 divide-and-conquer solution are Divide (the problem into a small number of pieces), Conquer (solve each piece, by applying divide-and-conquer 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 divide-and- 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 brute-force solution) is does there exist a divide-and- conquer solution for this problem? Divide-and-conquer 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 divide-and-conquer solutions. For the next couple of lectures we will discuss some examples of divide-and-conquer algorithms, and how to analyze them using recurrences. MergeSort: The first example of a divide-and-conquer 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 divide-and-conquer to sorting? Here are the major elements of the MergeSort algorithm....
View Full Document

Page1 / 4

lect6-divide-conquer-mergesort - Lecture Notes CMSC 251...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online