Analysis o f A lgorithms
~~ I_ND EDIIIQN ~
I ntroduction t o
*
The Design &
Analysis o f Algorithms
I ND EDITION "
I ntroduction t o
~
~
~
Anany Levitin
Villanova University
B oston San Francisco N ew York
L ondon T oronto S ydney Tokyo Singapore Madrid
M exico City M unich Paris C ape Town H ong K ong M ontreal
Publisher
Acquisitions E ditor
P roject E ditor
P roduction Supervisor
M arketing Manager
P roject Management & Composition
Technical A rt
C opyeditor
C over Design
C over Illustration
S enior P re press Supervisor
Greg Tobin
Matt Goldstein
Katherine Harutunian
Marilyn L loyd
Michelle Brown
Windfall Software, using Z zT£X
George Nichols
Richard Camp
Joyce Cosentino Wells
Jennifer M. K ohnke
Caroline Fell
Access the latest information a bout Addison-Wesley titles from o ur World Wide Web site: http://www.aw-bc.com/cornputing Many o f t he designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, a nd AddisonWesley was aware o f a t rademark claim, the designations have been printed in initial caps o r all caps.
I f y ou purchased this book within the United S tates o r C anada you should b e a ware that
i t has been wrongfully imported without the approval o f t he Publisher o r t he Author.
C opyright© 2007 by P earson E ducation, Inc.
All rights reserved. N o p art o f this publication may b e r eproduced, stored in a retrieval system, o r t ransmitted, in any form o r by any means, electronic, mechanical, photocopying, recording, o r otherwise, without the prior written permission of the publisher. P rinted i n t he U nited States o f America.
ISBN 0-321-36413-9
3 4 5 6 7 8 9 1 0-DOH-09 08 07
B rief C ontents
Preface
1 I ntroduction
2 F undamentals o f t he A nalysis o f A lgorithm E fficiency
3 B rute Force
4 D ivide-and-Conquer
5 D ecrease-and-Conquer
6