Lecture Notes
CMSC 251
Divide-and-conquer:
Understand how to design algorithms by divide-and-conquer. Understand the
divide-and-conquer algorithm for MergeSort, and be able to work an example by hand. Also
understand how the sieve technique works, and how it was used in the selection problem. (Chapt
10 on Medians; skip the randomized analysis. The material on the 2-d maxima and long integer
multiplication is not discussed in CLR.)
Lecture 11: First Midterm Exam
(Tuesday, March 3, 1998)
First midterm exam today. No lecture.
Lecture 12: Heaps and HeapSort
(Thursday, Mar 5, 1998)
Read:
Chapt 7 in CLR.
Sorting:
For the next series of lectures we will focus on sorting algorithms. The reasons for studying sorting
algorithms in details are twofold. First, sorting is a very important algorithmic problem. Procedures
for sorting are parts of many large software systems, either explicitly or implicitly. Thus the design of
efﬁcient sorting algorithms is important for the overall efﬁciency of these systems. The other reason is
more pedagogical. There are many sorting algorithms, some slow and some fast. Some possess certain
desirable properties, and others do not. Finally sorting is one of the few problems where there provable
lower bounds on how fast you can sort. Thus, sorting forms an interesting case study in algorithm
theory.
In the sorting problem we are given an array
A
[1
..n
]
of
n
numbers, and are asked to reorder these
elements into increasing order. More generally,
A
is of an array of records, and we choose one of these
records as the
key value
on which the elements will be sorted. The key value need not be a number. It
can be any object from a
totally ordered
domain. Totally ordered means that for any two elements of
the domain,
x
, and
y
, either
x<y
,
x
=
,or
x>y
.
There are some domains that can be partially ordered, but not totally ordered. For example, sets can
be partially ordered under the subset relation,
⊂
, but this is not a total order, it is not true that for any
two sets either
x
⊂
y
,
x
=
y
or
x