Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
16Activity
0 of .
Results for:
No results containing your search query
P. 1
David Mount - Algorithm Notes Good

David Mount - Algorithm Notes Good

Ratings:

5.0

(1)
|Views: 1,003|Likes:
Published by api-26825468

More info:

Published by: api-26825468 on Oct 19, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

CMSC 451
Design and Analysis of Computer Algorithms1

David M. Mount
Department of Computer Science
University of Maryland
Fall 2003

1Copyright, David M. Mount, 2004, Dept. of Computer Science, University of Maryland, College Park, MD, 20742. These lecture notes were

prepared by David Mount for the course CMSC 451, Design and Analysis of Computer Algorithms, at the University of Maryland. Permission to use, copy, modify, and distribute these notes for educational purposes and without fee is hereby granted, provided that this copyright notice appear in all copies.

Lecture Notes
1
CMSC 451
Lecture 1: Course Introduction
Read:(All readings are from Cormen, Leiserson, Rivest and Stein,Introduction to Algorithms, 2nd Edition). Review
Chapts. 1\u20135 in CLRS.
What is an algorithm?Our text de\ufb01nes analgorithm to be any well-de\ufb01ned computational procedure that takes some

values asinput and produces some values asoutput. Like a cooking recipe, an algorithm provides a step-by-step method for solving a computational problem. Unlike programs, algorithms are not dependent on a particular programming language, machine, system, or compiler. They are mathematical entities, which can be thought of as running on some sort ofidealized computer with an in\ufb01nite random access memory and an unlimited word size. Algorithm design is all about the mathematical theory behind the design of good programs.

Why study algorithm design?Programming is a very complex task, and there are a number of aspects of program-

ming that make it so complex. The \ufb01rst is that most programming projects are very large, requiring the coor- dinated efforts of many people. (This is the topic a course like software engineering.) The next is that many programming projects involve storing and accessing large quantities of data ef\ufb01ciently. (This is the topic of courses on data structures and databases.) The last is that many programming projects involve solving complex computational problems, for which simplistic or naive solutions may not be ef\ufb01cient enough. The complex problems may involve numerical data (the subject of courses on numerical analysis), but often they involve discrete data. This is where the topic of algorithm design and analysis is important.

Although the algorithms discussed in this course will often represent only a tiny fraction of the code that is generated in a large software system, this small fraction may be very important for the success of the overall project. An unfortunately common approach to this problem is to \ufb01rst design an inef\ufb01cient algorithm and data structure to solve the problem, and then take this poor design and attempt to \ufb01ne-tune its performance. The problem is that if the underlying design is bad, then often no amount of \ufb01ne-tuning is going to make a substantial difference.

The focus of this course is on how to design good algorithms, and how to analyze their ef\ufb01ciency. This is among
the most basic aspects of good programming.
Course Overview:This course will consist of a number of major sections. The \ufb01rst will be a short review of some

preliminary material, including asymptotics, summations, and recurrences and sorting. These have been covered in earlier courses, and so we will breeze through them pretty quickly. We will then discuss approaches to designing optimization algorithms, including dynamic programming and greedy algorithms. The next major focus will be on graph algorithms. This will include a review of breadth-\ufb01rst and depth-\ufb01rst search and their application in various problems related to connectivity in graphs. Next we will discuss minimum spanning trees, shortest paths, and network \ufb02ows. We will brie\ufb02y discuss algorithmic problems arising from geometric settings, that is, computational geometry.

Most of the emphasis of the \ufb01rst portion of the course will be on problems that can be solved ef\ufb01ciently, in the latter portion we will discuss intractability and NP-hard problems. These are problems for which no ef\ufb01cient solution is known. Finally, we will discuss methods to approximate NP-hard problems, and how to prove how close these approximations are to the optimal solutions.

Issues in Algorithm Design:Algorithms are mathematical objects (in contrast to the must more concrete notion of

a computer program implemented in some programming language and executing on some machine). As such, we can reason about the properties of algorithms mathematically. When designing an algorithm there are two fundamental issues to be considered: correctness and ef\ufb01ciency.

It is important to justify an algorithm\u2019s correctness mathematically. For very complex algorithms, this typically requires a careful mathematical proof, which may require the proof of many lemmas and properties of the solution, upon which the algorithm relies. For simple algorithms (BubbleSort, for example) a short intuitive explanation of the algorithm\u2019s basic invariants is suf\ufb01cient. (For example, in BubbleSort, the principal invariant is that on completion of theith iteration, the lasti elements are in their proper sorted positions.)

Lecture Notes
2
CMSC 451

Establishing ef\ufb01ciency is a much more complex endeavor. Intuitively, an algorithm\u2019s ef\ufb01ciency is a function of the amount of computational resources it requires, measured typically as execution time and the amount of space, or memory, that the algorithm uses. The amount of computational resources can be a complex function of the size and structure of the input set. In order to reduce matters to their simplest form, it is common to consider ef\ufb01ciency as a function of input size. Among all inputs of the same size, we consider the maximum possible running time. This is calledworst-case analysis. It is also possible, and often more meaningful, to measure

average-case analysis. Average-case analyses tend to be more complex, and may require that some probability
distribution be de\ufb01ned on the set of inputs. To keep matters simple, we will usually focus on worst-case analysis
in this course.
Throughout out this course, when you are asked to present an algorithm, this means that you need to do three
things:
\u2022Present a clear, simple and unambiguous description of the algorithm (in pseudo-code, for example). They

key here is \u201ckeep it simple.\u201d Uninteresting details should be kept to a minimum, so that the key compu- tational issues stand out. (For example, it is not necessary to declare variables whose purpose is obvious, and it is often simpler and clearer to simply say, \u201cAddX to the end of listL\u201d than to present code to do this or use some arcane syntax, such as \u201cL.insertAtEnd(X).\u201d)

\u2022Present a justi\ufb01cation or proof of the algorithm\u2019s correctness. Your justi\ufb01cation should assume that the

reader is someone of similar background as yourself, say another student in this class, and should be con- vincing enough make a skeptic believe that your algorithm does indeed solve the problem correctly. Avoid rambling about obvious or trivial elements. A good proof provides an overview of what the algorithm does, and then focuses on any tricky elements that may not be obvious.

\u2022Present a worst-case analysis of the algorithms ef\ufb01ciency, typically it running time (but also its space, if
space is an issue). Sometimes this is straightforward, but if not, concentrate on the parts of the analysis
that are not obvious.

Note that the presentation does not need to be in this order. Often it is good to begin with an explanation of how you derived the algorithm, emphasizing particular elements of the design that establish its correctness and ef\ufb01ciency. Then, once this groundwork has been laid down, present the algorithm itself. If this seems to be a bit abstract now, don\u2019t worry. We will see many examples of this process throughout the semester.

Lecture 2: Mathematical Background
Read:Review Chapters 1\u20135 in CLRS.
Algorithm Analysis:Today we will review some of the basic elements of algorithm analysis, which were covered in
previous courses. These include asymptotics, summations, and recurrences.
Asymptotics:Asymptotics involves O-notation (\u201cbig-Oh\u201d) and its many relatives,\u2126,\u0398,o (\u201clittle-Oh\u201d),\u03c9. Asymp-

totic notation provides us with a way to simplify the functions that arise in analyzing algorithm running times by ignoring constant factors and concentrating on the trends for large values ofn. For example, it allows us to reason that for three algorithms with the respective running times

n3logn + 4n2+ 52n logn\u2208 \u0398(n3logn)
15n2+ 7n log3n\u2208 \u0398(n2)
3n + 4 log5n+ 19n2
\u2208\u0398(n2).
Thus, the \ufb01rst algorithm is signi\ufb01cantly slower for largen, while the other two are comparable, up to a constant
factor.
Since asymptotics were covered in earlier courses, I will assume that this is familiar to you. Nonetheless, here
are a few facts to remember about asymptotic notation:
Lecture Notes
3
CMSC 451

Activity (16)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Ashok liked this
Mrunal Ruikar liked this
mgdorzan liked this
lakayglenn liked this
Benjamin Tan liked this
@leph liked this
ic10503 liked this
FAGANSEAMUS8473 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->