logo资料库

Grokking Algorithm.pdf

第1页 / 共258页
第2页 / 共258页
第3页 / 共258页
第4页 / 共258页
第5页 / 共258页
第6页 / 共258页
第7页 / 共258页
第8页 / 共258页
资料共258页,剩余部分请下载后查看
Cover
contents
preface
acknowledgments
about this book
Chapter 1 Introduction to Algorithms
Introduction
What you’ll learn about performance
What you’ll learn about solving problems
Binary search
A better way to search
Running time
Big O notation
Algorithm running times grow at different rates
Visualizing different Big O run times
Big O establishes a worst-case run time
Some common Big O run times
The traveling salesperson
Recap
Chapter 2 Selection Sort
How memory works
Arrays and linked lists
Linked lists
Arrays
Terminology
Inserting into the middle of a list
Deletions
Selection sort
Recap
Chapter 3 Recursion
Recursion
Base case and recursive case
The stack
The call stack
The call stack with recursion
Recap
Chapter 4 Quicksort
Divide & conquer
Quicksort
Big O notation revisited
Merge sort vs. quicksort
Average case vs. worst case
Recap
Chapter 5 Hash Tables
Hash functions
Use cases
Using hash tables for lookups
Preventing duplicate entries
Using hash tables as a cache
Recap
Collisions
Performance
Load factor
A good hash function
Recap
Chapter 6 Breadth-First Search
Introduction to graphs
What is a graph?
Breadth-first search
Finding the shortest path
Queues
Implementing the graph
Implementing the algorithm
Running time
Recap
Chapter 7 Dijkstra’s Algorithm
Working with Dijkstra’s algorithm
Terminology
Trading for a piano
Negative-weight edges
Implementation
Recap
Chapter 8 Greedy Algorithms
The classroom scheduling problem
The knapsack problem
The set-covering problem
Approximation algorithms
NP-complete problems
Traveling salesperson, step by step
How do you tell if a problem is NP-complete?
Recap
Chapter 9 Dynamic Programming
The knapsack problem
The simple solution
Dynamic programming
Knapsack problem FAQ
What happens if you add an item?
What happens if you change the order of the rows?
Can you fill in the grid column-wise insteadof row-wise?
What happens if you add a smaller item?
Can you steal fractions of an item?
Optimizing your travel itinerary
Handling items that depend on each other
Is it possible that the solution will requiremore than two sub-knapsacks?
Is it possible that the best solution doesn’tfill the knapsack completely?
Longest common substring
Making the grid
Filling in the grid
The solution
Longest common subsequence
Longest common subsequence—solution
Recap
Chapter 10 K-nearestneighbors
Classifying oranges vs. grapefruit
Building a recommendations system
Feature extraction
Regression
Picking good features
Introduction to machine learning
OCR
Building a spam filter
Predicting the stock market
Recap
Chapter 11 Where to Go Next
Trees
Inverted indexes
The Fourier transform
Parallel algorithms
MapReduce
Why are distributed algorithms usefule?
The map function
The reduce function
Bloom filters and HyperLogLog
Bloom filters
HyperLogLog
The SHA algorithms
Comparing files
Checking passwords
Locality-sensitive hashing
Diffie-Hellman key exchange
Linear programming
Epilogue
Answers to Exercises
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
CHAPTER 7
CHAPTER 8
CHAPTER 9
CHPATER 10
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
W
grokking algorithms Licensed to
Licensed to
grokking algorithms An illustrated guide for programmers and other curious people Aditya Y. Bhargava M A N N I N G Shelter ISland Licensed to
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road, PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com ©2016 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. ∞ Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. 20 Baldwin Road Shelter Island, NY 11964 Development editor: Jennifer Stout Technical development editor: Damien White Project manager: Tiffany Taylor Copyeditor: Tiffany Taylor Technical proofreader: Jean-François Morin Typesetter: Leslie Haimes Cover and interior design: Leslie Haimes Illustrations by the author ISBN: 9781617292231 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 21 20 19 18 17 16 Licensed to
For my parents, Sangeeta and Yogesh Licensed to
Licensed to
vii contents preface acknowledgments about this book 1 Introduction to algorithms Introduction What you’ll learn about performance What you’ll learn about solving problems Binary search A better way to search Running time Big O notation Algorithm running times grow at different rates Visualizing different Big O run times Big O establishes a worst-case run time Some common Big O run times The traveling salesperson Recap 2 Selection sort How memory works Arrays and linked lists Linked lists Arrays Terminology Inserting into the middle of a list Deletions xiii xiv xv 1 1 2 2 3 5 10 10 11 13 15 15 17 19 21 22 24 25 26 27 29 30 Licensed to
分享到:
收藏