Learning_Algorithms_A_Programmers_Guide_to_Writing_Better_Code.pdf

(11668 KB) Pobierz
Learning
Algorithms
A Programmer’s Guide to Writing Better Code
George T. Heineman
A Programmer’s Guide to Writing Better Code
Learning Algorithms
George T. Heineman
Beijing
Boston Farnham Sebastopol
Tokyo
Learning Algorithms
by George T. Heineman
Copyright © 2021 George T. Heineman. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional
sales department: 800-998-9938 or
corporate@oreilly.com.
Acquisitions Editor:
Melissa Duffield
Developmental Editor:
Sarah Grey
Production Editor:
Beth Kelly
Copyeditor:
Piper Editorial Consulting, LLC
Proofreader:
Justin Billing
August 2021:
First Edition
Indexer:
nSight, Inc.
Interior Designer:
David Futato
Cover Designer:
Karen Montgomery
Illustrator:
Kate Dullea
Revision History for the First Edition
2021-07-20:
First Release
See
http://oreilly.com/catalog/errata.csp?isbn=9781492091066
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Learning Algorithms,
the cover image,
and related trade dress are trademarks of O’Reilly Media, Inc.
The views expressed in this work are those of the author, and do not represent the publisher’s views.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-492-09106-6
[GP]
Table of Contents
Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1.
Problem Solving. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is an Algorithm?
Finding the Largest Value in an Arbitrary List
Counting Key Operations
Models Can Predict Algorithm Performance
Find Two Largest Values in an Arbitrary List
Tournament Algorithm
Time Complexity and Space Complexity
Summary
Challenge Exercises
1
5
6
7
12
16
23
24
25
30
32
34
36
39
40
41
42
44
46
50
52
iii
2.
Analyzing Algorithms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Using Empirical Models to Predict Performance
Multiplication Can Be Faster
Performance Classes
Asymptotic Analysis
Counting All Operations
Counting All Bytes
When One Door Closes, Another One Opens
Binary Array Search
Almost as Easy as π
Two Birds with One Stone
Pulling It All Together
Curve Fitting Versus Lower and Upper Bounds
Zgłoś jeśli naruszono regulamin