Related Titles
 Full Description

Python Algorithms explains the Python approach to algorithm analysis and design. Written by Magnus Lie Hetland, author of Beginning Python, this book is sharply focused on classical algorithms, but it also gives a solid understanding of fundamental algorithmic problemsolving techniques.
 The book deals with some of the most important and challenging areas of programming and computer science, but in a highly pedagogic and readable manner.
 The book covers both algorithmic theory and programming practice, demonstrating how theory is reflected in real Python programs.
 Wellknown algorithms and data structures that are built into the Python language are explained, and the user is shown how to implement and evaluate others himself.
What you’ll learn
 Transform new problems to wellknown algorithmic problems with efficient solutions, or show that the problems belong to classes of problems thought not to be efficiently solvable.
 Analyze algorithms and Python programs both using mathematical tools and basic experiments and benchmarks.
 Prove correctness, optimality, or bounds on approximation error for Python programs and their underlying algorithms.
 Understand several classical algorithms and data structures in depth, and be able to implement these efficiently in Python.
 Design and implement new algorithms for new problems, using timetested design principles and techniques.
 Speed up implementations, using a plethora of tools for highperformance computing in Python.
Who this book is for
The book is intended for Python programmers who need to learn about algorithmic problemsolving, or who need a refresher. Students of computer science, or similar programmingrelated topics, such as bioinformatics, may also find the book to be quite useful.
 Table of Contents

Table of Contents
 Introduction
 The Basics
 Counting 101
 Induction and Recursion ... and Reduction
 Traversal: The Skeleton Key of Algorithmics
 Divide, Combine, and Conquer
 Greed Is Good? Prove It!
 Tangled Dependencies and Memoization
 From A to B with Edsger and Friends
 Matchings, Cuts, and Flows
 Hard Problems and (Limited) Sloppiness
 Source Code/Downloads
 Errata

Please Login to submit errata.
On page 19:Your code sample has a formatting error with the else statement:
def sort_w_check(seq):
n = len(seq)
for i in range(n1):
if seq[i] > seq[i+1]:
break
else:
return
...
On page 53:
"Subsets, Permutations, and Combinations"
The formula for sum of binomial coefficient is wrong.
it should be k=0 to n SUM (n choose k) = 2 ** n
in the book we have:
k=0 to n SUM (n choose k) = 2 ** k
On page 55 (location 887 in ebook):There is a typo in the formula that sums combinations. It says 2^k, but it should be 2^n
On page 61:The text at the end of the solution to recurrence 6 says "That means the sum is equal to the number of nodes, which is \Theta(n)."
But this seems incorrect. The sum should be equal to (2n1), since it counts the leaf level of the tree (n) as well as the nodes in the tree (n1), which add up to (2n1). Of course this is still \Theta(n), but it is not equal to the number of nodes as the book says.
On page 88:
The native algorithm for Topological sorting doesn't work for the following input
G={0:[1],4:[0],1:[]}
Essentially the problem is (i believe), while finding the right place of the nth node in a topologically sorted list of n1 nodes, it checks after which all nodes in the sorted list the nth node should go.
But if it happens that the nth node is not in the adjacency list of any of the n1 nodes, but it is in the adjacency of say, (n+m)th node, and this (n+m)th node is in the adjacency list of one of these n1 nodes, the nth node will go at the start of the list, which is not its right place.
On page 142:Code for greatest slice is given as
best = A[0]
for size in range(1,n+1):
cur = sum(A[:size])
for i in range(nsize):
cur += A[i+size] = A[i] #Problem
best = max(best, cur)
There the statement with Problem should be
cur += A[i+size]  A[i]