Introduction To Algorithms (The MIT Press) 3rd Edition, (Ebook PDF
Introduction To Algorithms (The MIT Press) 3rd Edition, (Ebook PDF
com
https://ebookmass.com/product/introduction-to-algorithms-
the-mit-press-3rd-edition-ebook-pdf/
OR CLICK HERE
DOWLOAD NOW
https://ebookmass.com/product/trapped-brides-of-the-kindred-
book-29-faith-anderson/
ebookmass.com
https://ebookmass.com/product/the-rise-of-smart-cities-advanced-
structural-sensing-and-monitoring-systems-amir-alavi/
ebookmass.com
Faking It With My Best Friend: A Sweet Small-Town Friends-
to-Lovers Romantic Comedy (Second Chance Café Book 2) Kate
O'Keeffe
https://ebookmass.com/product/faking-it-with-my-best-friend-a-sweet-
small-town-friends-to-lovers-romantic-comedy-second-chance-cafe-
book-2-kate-okeeffe/
ebookmass.com
https://ebookmass.com/product/the-challenge-danielle-steel/
ebookmass.com
C H A R L E S E. L E I S E R S O N
R O N A L D L. R I V E S T
C L I F F O R D STEIN
INTRODUCTION TO
ALGORITHMS
T H I R D E D I T I O N
Contents vii
Introduction 357
15 Dynamic Programming 359
15.1 Rod cutting 360
15.2 Matrix-chain multiplication 370
15.3 Elements of dynamic programming 378
15.4 Longest common subsequence 390
15.5 Optimal binary search trees 397
16 Greedy Algorithms 414
16.1 An activity-selection problem 415
16.2 Elements of the greedy strategy 423
16.3 Huffman codes 428
? 16.4 Matroids and greedy methods 437
? 16.5 A task-scheduling problem as a matroid 443
17 Amortized Analysis 451
17.1 Aggregate analysis 452
17.2 The accounting method 456
17.3 The potential method 459
17.4 Dynamic tables 463
viii Contents
VI Graph Algorithms
Introduction 587
22 Elementary Graph Algorithms 589
22.1 Representations of graphs 589
22.2 Breadth-first search 594
22.3 Depth-first search 603
22.4 Topological sort 612
22.5 Strongly connected components 615
23 Minimum Spanning Trees 624
23.1 Growing a minimum spanning tree 625
23.2 The algorithms of Kruskal and Prim 631
Contents ix
Introduction 769
27 Multithreaded Algorithms 772
27.1 The basics of dynamic multithreading 774
27.2 Multithreaded matrix multiplication 792
27.3 Multithreaded merge sort 797
28 Matrix Operations 813
28.1 Solving systems of linear equations 813
28.2 Inverting matrices 827
28.3 Symmetric positive-definite matrices and least-squares approximation
832
29 Linear Programming 843
29.1 Standard and slack forms 850
29.2 Formulating problems as linear programs 859
29.3 The simplex algorithm 864
29.4 Duality 879
29.5 The initial basic feasible solution 886
x Contents
Introduction 1143
A Summations 1145
A.1 Summation formulas and properties 1145
A.2 Bounding summations 1149
B Sets, Etc. 1158
B.1 Sets 1158
B.2 Relations 1163
B.3 Functions 1166
B.4 Graphs 1168
B.5 Trees 1173
C Counting and Probability 1183
C.1 Counting 1183
C.2 Probability 1189
C.3 Discrete random variables 1196
C.4 The geometric and binomial distributions 1201
? C.5 The tails of the binomial distribution 1208
D Matrices 1217
D.1 Matrices and matrix operations 1217
D.2 Basic matrix properties 1222
Bibliography 1231
Index 1251
Preface
Before there were computers, there were algorithms. But now that there are com-
puters, there are even more algorithms, and algorithms lie at the heart of computing.
This book provides a comprehensive introduction to the modern study of com-
puter algorithms. It presents many algorithms and covers them in considerable
depth, yet makes their design and analysis accessible to all levels of readers. We
have tried to keep explanations elementary without sacrificing depth of coverage
or mathematical rigor.
Each chapter presents an algorithm, a design technique, an application area, or a
related topic. Algorithms are described in English and in a pseudocode designed to
be readable by anyone who has done a little programming. The book contains 244
figures—many with multiple parts—illustrating how the algorithms work. Since
we emphasize efficiency as a design criterion, we include careful analyses of the
running times of all our algorithms.
The text is intended primarily for use in undergraduate or graduate courses in
algorithms or data structures. Because it discusses engineering issues in algorithm
design, as well as mathematical aspects, it is equally well suited for self-study by
technical professionals.
In this, the third edition, we have once again updated the entire book. The
changes cover a broad spectrum, including new chapters, revised pseudocode, and
a more active writing style.
To the teacher
We have designed this book to be both versatile and complete. You should find it
useful for a variety of courses, from an undergraduate course in data structures up
through a graduate course in algorithms. Because we have provided considerably
more material than can fit in a typical one-term course, you can consider this book
to be a “buffet” or “smorgasbord” from which you can pick and choose the material
that best supports the course you wish to teach.
xiv Preface
You should find it easy to organize your course around just the chapters you
need. We have made chapters relatively self-contained, so that you need not worry
about an unexpected and unnecessary dependence of one chapter on another. Each
chapter presents the easier material first and the more difficult material later, with
section boundaries marking natural stopping points. In an undergraduate course,
you might use only the earlier sections from a chapter; in a graduate course, you
might cover the entire chapter.
We have included 957 exercises and 158 problems. Each section ends with exer-
cises, and each chapter ends with problems. The exercises are generally short ques-
tions that test basic mastery of the material. Some are simple self-check thought
exercises, whereas others are more substantial and are suitable as assigned home-
work. The problems are more elaborate case studies that often introduce new ma-
terial; they often consist of several questions that lead the student through the steps
required to arrive at a solution.
Departing from our practice in previous editions of this book, we have made
publicly available solutions to some, but by no means all, of the problems and ex-
ercises. Our Web site, http://mitpress.mit.edu/algorithms/, links to these solutions.
You will want to check this site to make sure that it does not contain the solution to
an exercise or problem that you plan to assign. We expect the set of solutions that
we post to grow slowly over time, so you will need to check it each time you teach
the course.
We have starred (?) the sections and exercises that are more suitable for graduate
students than for undergraduates. A starred section is not necessarily more diffi-
cult than an unstarred one, but it may require an understanding of more advanced
mathematics. Likewise, starred exercises may require an advanced background or
more than average creativity.
To the student
We hope that this textbook provides you with an enjoyable introduction to the
field of algorithms. We have attempted to make every algorithm accessible and
interesting. To help you when you encounter unfamiliar or difficult algorithms, we
describe each one in a step-by-step manner. We also provide careful explanations
of the mathematics needed to understand the analysis of the algorithms. If you
already have some familiarity with a topic, you will find the chapters organized so
that you can skim introductory sections and proceed quickly to the more advanced
material.
This is a large book, and your class will probably cover only a portion of its
material. We have tried, however, to make this a book that will be useful to you
now as a course textbook and also later in your career as a mathematical desk
reference or an engineering handbook.
Preface xv
To the professional
The wide range of topics in this book makes it an excellent handbook on algo-
rithms. Because each chapter is relatively self-contained, you can focus in on the
topics that most interest you.
Most of the algorithms we discuss have great practical utility. We therefore
address implementation concerns and other engineering issues. We often provide
practical alternatives to the few algorithms that are primarily of theoretical interest.
If you wish to implement any of the algorithms, you should find the transla-
tion of our pseudocode into your favorite programming language to be a fairly
straightforward task. We have designed the pseudocode to present each algorithm
clearly and succinctly. Consequently, we do not address error-handling and other
software-engineering issues that require specific assumptions about your program-
ming environment. We attempt to present each algorithm simply and directly with-
out allowing the idiosyncrasies of a particular programming language to obscure
its essence.
We understand that if you are using this book outside of a course, then you
might be unable to check your solutions to problems and exercises against solutions
provided by an instructor. Our Web site, http://mitpress.mit.edu/algorithms/, links
to solutions for some of the problems and exercises so that you can check your
work. Please do not send your solutions to us.
To our colleagues
We have supplied an extensive bibliography and pointers to the current literature.
Each chapter ends with a set of chapter notes that give historical details and ref-
erences. The chapter notes do not provide a complete reference to the whole field
xvi Preface
of algorithms, however. Though it may be hard to believe for a book of this size,
space constraints prevented us from including many interesting algorithms.
Despite myriad requests from students for solutions to problems and exercises,
we have chosen as a matter of policy not to supply references for problems and
exercises, to remove the temptation for students to look up a solution rather than to
find it themselves.
Web site
You can use our Web site, http://mitpress.mit.edu/algorithms/, to obtain supple-
mentary information and to communicate with us. The Web site links to a list of
known errors, solutions to selected exercises and problems, and (of course) a list
explaining the corny professor jokes, as well as other content that we might add.
The Web site also tells you how to report errors or make suggestions.
1 We investigated several drawing programs that run under Mac OS X, but all had significant short-
comings compared with MacDraw Pro. We briefly attempted to produce the illustrations for this
book with a different, well known drawing program. We found that it took at least five times as long
to produce each illustration as it took with MacDraw Pro, and the resulting illustrations did not look
as good. Hence the decision to revert to MacDraw Pro running on older Macintoshes.
Preface xix
Science and Artificial Intelligence Laboratory, and the Columbia University De-
partment of Industrial Engineering and Operations Research. We thank our re-
spective universities and colleagues for providing such supportive and stimulating
environments.
Julie Sussman, P.P.A., once again bailed us out as the technical copyeditor. Time
and again, we were amazed at the errors that eluded us, but that Julie caught. She
also helped us improve our presentation in several places. If there is a Hall of Fame
for technical copyeditors, Julie is a sure-fire, first-ballot inductee. She is nothing
short of phenomenal. Thank you, thank you, thank you, Julie! Priya Natarajan also
found some errors that we were able to correct before this book went to press. Any
errors that remain (and undoubtedly, some do) are the responsibility of the authors
(and probably were inserted after Julie read the material).
The treatment for van Emde Boas trees derives from Erik Demaine’s notes,
which were in turn influenced by Michael Bender. We also incorporated ideas
from Javed Aslam, Bradley Kuszmaul, and Hui Zha into this edition.
The chapter on multithreading was based on notes originally written jointly with
Harald Prokop. The material was influenced by several others working on the Cilk
project at MIT, including Bradley Kuszmaul and Matteo Frigo. The design of the
multithreaded pseudocode took its inspiration from the MIT Cilk extensions to C
and by Cilk Arts’s Cilk++ extensions to C++.
We also thank the many readers of the first and second editions who reported
errors or submitted suggestions for how to improve this book. We corrected all the
bona fide errors that were reported, and we incorporated as many suggestions as
we could. We rejoice that the number of such contributors has grown so great that
we must regret that it has become impractical to list them all.
Finally, we thank our wives—Nicole Cormen, Wendy Leiserson, Gail Rivest,
and Rebecca Ivry—and our children—Ricky, Will, Debby, and Katie Leiserson;
Alex and Christopher Rivest; and Molly, Noah, and Benjamin Stein—for their love
and support while we prepared this book. The patience and encouragement of our
families made this project possible. We affectionately dedicate this book to them.
February 2009
Other documents randomly have
different content
A gibbon-rokonság elméletével nehéz megbarátkoznunk. A mai
gibbonok csak egy méter magasságot érnek el, ami
összhangzásban van örökösen a fákon tornászó, könnyű testet
követelő életmódjukkal. Ezzel szemben a Pithecanthropust 45 cm
hosszú combcsontjából ítélve legalább gorillanagyságunak, ha nem
nagyobbnak kell képzelnünk; ekkora testsúllyal alig folytathatott ez a
lény a törékeny gallyakon himbálódzó életmódot. Általában azt
látjuk, hogy kisebb alakok nagyobbakká fejlődnek a fajfejlődés
során, s nem megfordítva, a valószínűség tehát ellene szól annak,
hogy a Pithecanthropus őse volna a mai gibbonoknak, bár az
ellenkezőre is van több példa. Még inkább elfogadható volna a
csimpánzzal való rokonság, csakhogy a koponya alakja nem igen
egyezik a csimpánzéval s még kevésbé a combcsont alakja. A
majomelmélet ellen szól még az a különösen Lechétől59) kiemelt
körülmény is, hogy a koponyatető felszíne feltünően síma; teljesen
hiányzanak rajta azok az izomlécek, különösen a halántéktájékon,
amelyek mindig megvannak az emberszabású majmok teljesen
kifejlődött nagy példányainak, kivált a hímeknek koponyáján,
legerősebb fejlődésben a gorilláén, leggyengébben a csimpánzén és
gibbonén. Ez az állat Leche szerint nem lehetett valami nagy majom,
mert különben ott volnának koponyáján a hatalmas rágóizomzat
tapadását jelző csonttaréjok. De leginkább ellene szól a
majomminőségnek a koponya nagy térfogata s az ebből
megállapítható 750 grammnyi agysúly (Duckworth), mely nem áll
arányban a combcsontból kiszámítható magassággal; említettem,
hogy a combcsontja szerint a Pithecanthropust gorillanagyságúnak
kell gondolnunk, míg a koponya térfogata 300–350 grammal
meghaladja a gorilláét. Manouvrier szerint a Pithecanthropus 175 cm
magas lehetett.
Ezzel szemben Klaatsch, Bumüller stb. nem tulajdonítanak oly
nagy jelentőséget a Pithecanthropus nagy koponyatérfogatának,
hanem inkább a morfológiai viszonyokat veszik irányadóul s ezen az
alapon nem látnak elég okot arra, hogy ezt a lényt másnak
minősítsék, mint egy nagy, kihalt emberszabású majomnak. A
koponyatető görbületéről és egész alakfejlődéséről maga Schwalbe
is elismeri, hogy nem nagyon különbözik a gibbonétól. Valóban,
egymás fölé rajzolva a Pithecanthropus és a gibbon fejtetői
profilgörbéjét, alig látunk eltérést. Török60) nyomatékkal utal a
Pithecanthropus koponyájának nagyfokú megszűkülésére a
halántéktájékon a szemöldökléc mögött, miből hatalmas
halántékizomra, vagyis rendkívül erősen fejlett rágókészülékre kell
következtetni. Ilyen halántéktáji megszűkülés még a neandervölgyi
embernek s a mai rasszok legalacsonyabbrendűjének koponyáján
sincs s ezért úgy véli, hogy a koponyatető állati lénytől ered.
Klaatsch szerint61) ez a lény nem lehetett egyenesen álló, mert
nyakszirtcsontjának nagy nyílása, az «öreglik», amellyel
odarögzítődik a koponya a gerincoszlophoz, sokkal hátrább volt,
mint az emberen, hátrább, mintsem hogy fennálló helyzetben a
koponya a gerincoszlopon szilárdan állhatott volna.
A szerzők nagy része úgy véli, hogy a Pithecanthropus az ember
közvetetlen fejlődési láncolatából már a geológiai kora miatt is kiesik.
Dubois harmadkorinak, nevezetesen pliocénbelinek tartotta, de a
lelet helyszínén végzett újabb földtani, őslénytani és florisztikai
vizsgálatok (Martin, Volz, Elbert, Schuster)62) ha nem is egészen
bizonyossá, de legalább is nagyon valószínűvé teszik, hogy
valamivel fiatalabbkorú, mint Dubois hitte, vagyis nem a pliocénből,
hanem a pleisztocén elejéről, sőt Volz szerint talán a közepéről való,
tehát olyan korszakból származik, amikor az ember is már biztosan
élt a Földön. Ennek a körülménynek ugyan a magam részéről döntő
jelentőséget nem tulajdonítanék s nem tudnám elismerni, hogy a
Pithecanthropus már csak ezért sem vehető számba az emberi
nemet megelőző állatforma gyanánt. Elképzelhető, hogy egyes
vidékeken a fajbeli továbbfejlődést előmozdító tényezők híján az
ősalak egy csoportja megmaradt, mint élő anachronizmus, a maga
eredeti formájában s nem fejlődött tovább emberré; más esetekben
is találkozunk ezzel a tüneménnyel, melyet Eimer genepistasisnak
nevezett. Az őstulok (Bos primigenius) például, mely valószínűleg
törzsalakja a mai szarvasmarhának, csak néhány száz éve pusztult
ki.
Csak futólag említem, mint furcsaságot, Brancának azt a bizarr
nézetét (idézett helyen, 76. lap), hogy a Pithecanthropus egy
emberszabású majom és egy diluviumi ősember kereszteződésének
eredménye.
A Pithecanthropus combcsontja Bumüller pontos vizsgálatai
szerint inkább majomszabású; leginkább hasonlít a gibbon
combcsontjához, csak kissé hosszabb, karcsúbb. Klaatschnak kissé
homályos nyilatkozata szerint63) «a csont egész viselkedése szerint
olyan formakörhöz tartozik, amely közel áll az ausztráliaiakhoz,
ázsiai népfajokhoz és az indo-ázsiai emberszabású majmokhoz».
1. ábra.
A Pithecanthropus erectus koponyateteje, felülről és
oldalról.
2. ábra.
A piltdowni ember koponyája; Woodward után
(2. reconstructio). A pontozott részek
hiányzanak.
3. ábra. A maueri állkapocs (Homo heidelbergensis)
és a maueri állkapocsnak s egy mostani ember
állkapcsának körvonala, egymásra rajzolva; az ujkori
állkapocs pontozott.
4. ábra.
A neandervölgyi ember koponyája, a hiányzó
részek pótlásával, Klaatsch nyomán.
5. ábra.
A la chapelle-aux-saints-i neandertipusú koponya,
a hiányzó részek kiegészítésével. Boule nyomán.
6. ábra.
A combe-capelle-i koponya (Homo Aurignacensis) koponyája,
Klaatsch nyomán.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com