0% found this document useful (0 votes)
7 views

Python Algorithms Mastering Basic Algorithms In The Python Language Second Edition 2nd Edition Magnus Lie Hetland download

Ebook access

Uploaded by

boyikaazeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Algorithms Mastering Basic Algorithms In The Python Language Second Edition 2nd Edition Magnus Lie Hetland download

Ebook access

Uploaded by

boyikaazeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Python Algorithms Mastering Basic Algorithms In

The Python Language Second Edition 2nd Edition


Magnus Lie Hetland download

https://ebookbell.com/product/python-algorithms-mastering-basic-
algorithms-in-the-python-language-second-edition-2nd-edition-
magnus-lie-hetland-50200310

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Python Algorithms Mastering Basic Algorithms In The Python Language


Second Edition Magnus Lie Hetland

https://ebookbell.com/product/python-algorithms-mastering-basic-
algorithms-in-the-python-language-second-edition-magnus-lie-
hetland-10817504

Python Algorithms Mastering Basic Algorithms In The Python Language


Second Edition 2nd Magnus Lie Hetland

https://ebookbell.com/product/python-algorithms-mastering-basic-
algorithms-in-the-python-language-second-edition-2nd-magnus-lie-
hetland-7384184

Python Algorithms Mastering Basic Algorithms In The Python Language


Hetland

https://ebookbell.com/product/python-algorithms-mastering-basic-
algorithms-in-the-python-language-hetland-21889438

Python Algorithms Mastering Basic Algorithms In The Python Language


2nd Edition Hetland

https://ebookbell.com/product/python-algorithms-mastering-basic-
algorithms-in-the-python-language-2nd-edition-hetland-38431100
300 Python Algorithms Mastering The Art Of Problemsolving Hernando
Abella

https://ebookbell.com/product/300-python-algorithms-mastering-the-art-
of-problemsolving-hernando-abella-63693184

300 Python Algorithms Mastering The Art Of Problemsolving Hernando


Abella

https://ebookbell.com/product/300-python-algorithms-mastering-the-art-
of-problemsolving-hernando-abella-79087836

300 Python Algorithms Mastering The Art Of Problemsolving Hernando


Abella

https://ebookbell.com/product/300-python-algorithms-mastering-the-art-
of-problemsolving-hernando-abella-80392536

Mastering Opencv With Python Use Numpy Scikit Tensorflow And


Matplotlib To Learn Advanced Algorithms For Machine Learning Through A
Set Of Practical Projects Ayush Vaishya

https://ebookbell.com/product/mastering-opencv-with-python-use-numpy-
scikit-tensorflow-and-matplotlib-to-learn-advanced-algorithms-for-
machine-learning-through-a-set-of-practical-projects-ayush-
vaishya-53747356

Coding Black Scholes Mastering Algorithmic Options Trading With Python


Van Der Post

https://ebookbell.com/product/coding-black-scholes-mastering-
algorithmic-options-trading-with-python-van-der-post-56240580
Python Algorithms

Mastering Basic Algorithms in the Python


Language

Second Edition

Magnus Lie Hetland


Python Algorithms: Mastering Basic Algorithms in the Python Language Copyright ©
2014 by Magnus Lie Hetland This work is subject to copyright. All rights are reserved by the
Publisher, whether the whole or part of the material is concerned, specifically the rights of
translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on
microfilms or in any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology
now known or hereafter developed. Exempted from this legal reservation are brief excerpts in
connection with reviews or scholarly analysis or material supplied specifically for the
purpose of being entered and executed on a computer system, for exclusive use by the
purchaser of the work. Duplication of this publication or parts thereof is permitted only under
the provisions of the Copyright Law of the Publisher’s location, in its current version, and
permission for use must always be obtained from Springer. Permissions for use may be
obtained through RightsLink at the Copyright Clearance Center. Violations are liable to
prosecution under the respective Copyright Law.

ISBN-13 (pbk): 978-1-4842-0056-8

ISBN-13 (electronic): 978-1-4842-0055-1

Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names,
logos, and images only in an editorial fashion and to the benefit of the trademark owner, with
no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even
if they are not identified as such, is not to be taken as an expression of opinion as to whether
or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date
of publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained herein.
Publisher: Heinz Weinheimer
Lead Editor: Steve Anglin
Technical Reviewer: Stefan Turalski Editorial Board: Steve Anglin, Mark
Beckner, Ewan Buckingham, Gary Cornell, Louise Corrigan, James T.
DeWolf, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James
Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben
Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Steve
Weiss Development Editor: Kenyon Brown Coordinating Editor: Anamika
Panchoo Copy Editor: Kim Wimpsett
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover Designer: Anna Ishchenko Photo Credit: Kai T. Dragland

Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-
4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.

For information on translations, please e-mail rights@apress.com, or visit


www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/bulk-sales.

Any source code or other supplementary material referenced by the author in this text is
available to readers at www.apress.com. For detailed information about how to locate
your book’s source code, go to www.apress.com/source-code/.
For JV, the silliest girl I know.
Contents at a Glance

About the Author


About the Technical Reviewer
Acknowledgments

Preface

Chapter 1: Introduction
Chapter 2: The Basics
Chapter 3: Counting 101
Chapter 4: Induction and Recursion ... and
Reduction
Chapter 5: Traversal: The Skeleton Key of
Algorithmics
Chapter 6: Divide, Combine, and Conquer
Chapter 7: Greed Is Good? Prove It!
Chapter 8: Tangled Dependencies and
Memoization
Chapter 9: From A to B with Edsger and
Friends
Chapter 10: Matchings, Cuts, and Flows
Chapter 11: Hard Problems and (Limited)
Sloppiness
Appendix A: Pedal to the Metal: Accelerating
Python
Appendix B: List of Problems and Algorithms
Appendix C: Graph Terminology
Appendix D: Hints for Exercises

Index
Contents

About the Author


About the Technical Reviewer
Acknowledgments

Preface

Chapter 1: Introduction
What’s All This, Then?
What the book is about:
What the book covers only briefly or partially:
What the book isn’t about:

Why Are You Here?


Some Prerequisites
What’s in This Book
Summary
If You’re Curious …
Exercises
References
Chapter 2: The Basics
Some Core Ideas in Computing
Asymptotic Notation
It’s Greek to Me!
Rules of the Road
Taking the Asymptotics for a Spin
Three Important Cases
Empirical Evaluation of Algorithms

Implementing Graphs and Trees


Adjacency Lists and the Like
Adjacency Matrices
Implementing Trees
A Multitude of Representations

Beware of Black Boxes


Hidden Squares
The Trouble with Floats

Summary
If You’re Curious …
Exercises
References
Chapter 3: Counting 101
The Skinny on Sums
More Greek
Working with Sums

A Tale of Two Tournaments


Shaking Hands
The Hare and the Tortoise

Subsets, Permutations, and Combinations


Recursion and Recurrences
Doing It by Hand
A Few Important Examples
Guessing and Checking
The Master Theorem: A Cookie-Cutter Solution

So What Was All That About?


Summary
If You’re Curious …
Exercises
References
Chapter 4: Induction and Recursion … and
Reduction
Oh, That’s Easy!
One, Two, Many
Mirror, Mirror
Designing with Induction (and Recursion)
Finding a Maximum Permutation
The Celebrity Problem
Topological Sorting

Stronger Assumptions
Invariants and Correctness
Relaxation and Gradual Improvement
Reduction + Contraposition = Hardness Proof
Problem Solving Advice
Summary
If You’re Curious …
Exercises
References
Chapter 5: Traversal: The Skeleton Key of
Algorithmics
A Walk in the Park
No Cycles Allowed
How to Stop Walking in Circles

Go Deep!
Depth-First Timestamps and Topological Sorting (Again)

Infinite Mazes and Shortest (Unweighted) Paths


Strongly Connected Components
Summary
If You’re Curious …
Exercises
References
Chapter 6: Divide, Combine, and Conquer
Tree-Shaped Problems: All About the Balance
The Canonical D&C Algorithm
Searching by Halves
Traversing Search Trees … with Pruning
Selection

Sorting by Halves
How Fast Can We Sort?
Three More Examples
Closest Pair
Convex Hull
Greatest Slice

Tree Balance … and Balancing*


Summary
If You’re Curious …
Exercises
References
Chapter 7: Greed Is Good? Prove It!
Staying Safe, Step by Step
The Knapsack Problem
Fractional Knapsack
Integer Knapsack

Huffman’s Algorithm
The Algorithm
The First Greedy Choice
Going the Rest of the Way
Optimal Merging

Minimum Spanning Trees


The Shortest Edge
What About the Rest?
Kruskal’s Algorithm
Prim’s Algorithm

Greed Works. But When?


Keeping Up with the Best
No Worse Than Perfect
Staying Safe

Summary
If You’re Curious …
Exercises
References
Chapter 8: Tangled Dependencies and
Memoization
Don’t Repeat Yourself
Shortest Paths in Directed Acyclic Graphs
Longest Increasing Subsequence
Sequence Comparison
The Knapsack Strikes Back
Binary Sequence Partitioning
Summary
If You’re Curious …
Exercises
References
Chapter 9: From A to B with Edsger and
Friends
Propagating Knowledge
Relaxing like Crazy
Finding the Hidden DAG
All Against All
Far-Fetched Subproblems
Meeting in the Middle
Knowing Where You’re Going
Summary
If You’re Curious …
Exercises
References
Chapter 10: Matchings, Cuts, and Flows
Bipartite Matching
Disjoint Paths
Maximum Flow
Minimum Cut
Cheapest Flow and the Assignment Problem*
Some Applications
Summary
If You’re Curious …
Exercises
References
Chapter 11: Hard Problems and (Limited)
Sloppiness
Reduction Redux
Not in Kansas Anymore?
Meanwhile, Back in Kansas …
But Where Do You Start? And Where Do You Go
from There?
A Ménagerie of Monsters
Return of the Knapsack
Cliques and Colorings
Paths and Circuits

When the Going Gets Tough, the Smart Get


Sloppy
Desperately Seeking Solutions
And the Moral of the Story Is …
Summary
If You’re Curious …
Exercises
References
Appendix A: Pedal to the Metal: Accelerating
Python
Appendix B: List of Problems and Algorithms
Problems
Algorithms and Data Structures
Appendix C: Graph Terminology
Appendix D: Hints for Exercises
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11

Index
About the Author

Magnus Lie Hetland is an experienced Python programmer, having used


the language since the late 1990s. He is also an associate professor of
algorithms at the Norwegian University of Science and Technology and
has taught algorithms for more than a decade. Hetland is the author of
Beginning Python.
About the Technical Reviewer

Stefan Turalski is just another coder who is perfectly happy delivering


pragmatic, not necessarily software, solutions and climbing the impassable
learning curve.
He has more than a decade of experience building solutions in such
diverse domains as knowledge management, embedded networking,
healthcare, power and gas trading, and, in the last few years, finance.
Focusing on code optimization and systems integration, he has dabbled
(or almost drowned) in quite a few programming languages and has
abused a number of open source and commercial software frameworks,
libraries, servers, and so on.
Stefan is currently working on a highly scalable, low-latency, intraday
risk valuation system at a financial institution in London. His latest
interests revolve around functional and reactive programming, F#,
Clojure, Python, OpenCL, and WebGL.
He still cannot believe that he was trusted enough to help on the
second edition of Magnus Lie Hetland’s superb book. Stefan hopes that
his (and your) brain cells injured while studying the algorithmic problems
covered by the author will recover stronger and wiser!
Acknowledgments

Thanks to everyone who contributed to this book, either directly or


indirectly. This certainly includes my algorithm mentors, Arne Halaas and
Bjørn Olstad, as well as the entire crew at Apress and my brilliant tech
editors, Alex Martelli (for the first edition) and Stefan Turalski. Thanks to
all the readers who pointed out errors in the first edition; I hope I have
corrected most of them. I’d especially like to thank Gerald Senarclens de
Grancy, who supplied an extensive, well-annotated list of errata covering
the entire book. Thanks to Nils Grimsmo, Jon Marius Venstad, Ole
Edsberg, Rolv Seehuus, and Jorg Rødsjø for useful input; to my girlfriend,
Janne Varvára Seem, my parents, Kjersti Lie and Tor M. Hetland, and my
sister, Anne Lie-Hetland, for their interest and support; and to my uncle
Axel, for checking my French. Finally, a big thank-you to the Python
Software Foundation for their permission to reproduce parts of the Python
standard library and to Randall Munroe for letting me include some of his
wonderful XKCD comics.
Preface
This book is a marriage of three of my passions: algorithms, Python
programming, and explaining things. To me, all three of these are about
aesthetics—finding just the right way of doing something, looking until
you uncover a hint of elegance, and then polishing that until it shines (or at
least until it is a bit shinier). Of course, when there’s a lot of material to
cover, you may not get to polish things quite as much as you want.
Luckily, though, most of the content in this book is prepolished because
I’m writing about really beautiful algorithms and proofs, as well as one of
the cutest programming languages out there. As for the third part, I’ve
tried hard to find explanations that will make things seem as obvious as
possible. Even so, I’m sure I have failed in many ways, and if you have
suggestions for improving the book, I’d be happy to hear from you. Who
knows, maybe some of your ideas could make it into a future edition. For
now, though, I hope you have fun with what’s here and that you take any
newfound insight and run with it. If you can, use it to make the world a
more awesome place, in whatever way seems right.
CHAPTER 1

Introduction
1. Write down the problem.
2. Think real hard.

3. Write down the solution.

— “The Feynman Algorithm”


as described by Murray Gell-Mann

Consider the following problem: You are to visit all the cities, towns,
and villages of, say, Sweden and then return to your starting point. This
might take a while (there are 24,978 locations to visit, after all), so you
want to minimize your route. You plan on visiting each location exactly
once, following the shortest route possible. As a programmer, you
certainly don’t want to plot the route by hand. Rather, you try to write
some code that will plan your trip for you. For some reason, however,
you can’t seem to get it right. A straightforward program works well for
a smaller number of towns and cities but seems to run forever on the
actual problem, and improving the program turns out to be surprisingly
hard. How come?
Actually, in 2004, a team of five researchers1 found such a tour of
Sweden, after a number of other research teams had tried and failed.
The five-man team used cutting-edge software with lots of clever
optimizations and tricks of the trade, running on a cluster of 96 Xeon
2.6GHz workstations. Their software ran from March 2003 until May
2004, before it finally printed out the optimal solution. Taking various
interruptions into account, the team estimated that the total CPU time
spent was about 85 years!
Consider a similar problem: You want to get from Kashgar, in the
westernmost region of China, to Ningbo, on the east coast, following
the shortest route possible.2 Now, China has 3,583,715 km of roadways
and 77,834 km of railways, with millions of intersections to consider
and a virtually unfathomable number of possible routes to follow. It
might seem that this problem is related to the previous one, yet this
shortest path problem is one solved routinely, with no appreciable
delay, by GPS software and online map services. If you give those two
cities to your favorite map service, you should get the shortest route in
mere moments. What’s going on here?
You will learn more about both of these problems later in the book;
the first one is called the traveling salesman (or salesrep) problem and
is covered in Chapter 11, while so-called shortest path problems are
primarily dealt with in Chapter 9. I also hope you will gain a rather deep
insight into why one problem seems like such a hard nut to crack while
the other admits several well-known, efficient solutions. More
importantly, you will learn something about how to deal with
algorithmic and computational problems in general, either solving them
efficiently, using one of the several techniques and algorithms you
encounter in this book, or showing that they are too hard and that
approximate solutions may be all you can hope for. This chapter briefly
describes what the book is about—what you can expect and what is
expected of you. It also outlines the specific contents of the various
chapters to come in case you want to skip around.
What’s All This, Then?
This is a book about algorithmic problem solving for Python
programmers. Just like books on, say, object-oriented patterns, the
problems it deals with are of a general nature—as are the solutions. For
an algorist, there is more to the job than simply implementing or
executing an existing algorithm, however. You are expected to come up
with new algorithms—new general solutions to hitherto unseen, general
problems. In this book, you are going to learn principles for
constructing such solutions.
This is not your typical algorithm book, though. Most of the
authoritative books on the subject (such as Knuth’s classics or the
industry-standard textbook by Cormen et al.) have a heavy formal and
theoretical slant, even though some of them (such as the one by
Kleinberg and Tardos) lean more in the direction of readability. Instead
of trying to replace any of these excellent books, I’d like to supplement
them. Building on my experience from teaching algorithms, I try to
explain as clearly as possible how the algorithms work and what
common principles underlie many of them. For a programmer, these
explanations are probably enough. Chances are you’ll be able to
understand why the algorithms are correct and how to adapt them to
new problems you may come to face. If, however, you need the full
depth of the more formalistic and encyclopedic textbooks, I hope the
foundation you get in this book will help you understand the theorems
and proofs you encounter there.

Note One difference between this book and other textbooks


on algorithms is that I adopt a rather conversational tone. While I
hope this appeals to at least some of my readers, it may not be
your cup of tea. Sorry about that—but now you have, at least,
been warned.

There is another genre of algorithm books as well: the “(Data


Structures and) Algorithms in blank” kind, where the blank is the
author’s favorite programming language. There are quite a few of these
(especially for blank = Java, it seems), but many of them focus on
relatively basic data structures, to the detriment of the meatier stuff.
This is understandable if the book is designed to be used in a basic
course on data structures, for example, but for a Python programmer,
learning about singly and doubly linked lists may not be all that exciting
(although you will hear a bit about those in the next chapter). And even
though techniques such as hashing are highly important, you get hash
tables for free in the form of Python dictionaries; there’s no need to
implement them from scratch. Instead, I focus on more high-level
algorithms. Many important concepts that are available as black-box
implementations either in the Python language itself or in the standard
library (such as sorting, searching, and hashing) are explained more
briefly, in special “Black Box” sidebars throughout the text.
There is, of course, another factor that separates this book from
those in the “Algorithms in Java/C/C++/C#” genre, namely, that the
blank is Python. This places the book one step closer to the language-
independent books (such as those by Knuth,3 Cormen et al., and
Kleinberg and Tardos, for example), which often use pseudocode, the
kind of fake programming language that is designed to be readable
rather than executable. One of Python’s distinguishing features is its
readability; it is, more or less, executable pseudocode. Even if you’ve
never programmed in Python, you could probably decipher the meaning
of most basic Python programs. The code in this book is designed to be
readable exactly in this fashion—you need not be a Python expert to
understand the examples (although you might need to look up some
built-in functions and the like). And if you want to pretend the examples
are actually pseudocode, feel free to do so. To sum up ...

What the book is about:


Algorithm analysis, with a focus on asymptotic running
time

Basic principles of algorithm design

How to represent commonly used data structures in Python

How to implement well-known algorithms in Python

What the book covers only briefly or


partially:
Algorithms that are directly available in Python, either as
part of the language or via the standard library

Thorough and deep formalism (although the book has its


share of proofs and proof-like explanations)

What the book isn’t about:


Numerical or number-theoretical algorithms (except for
some floating-point hints in Chapter 2)
Parallel algorithms and multicore programming

As you can see, “implementing things in Python” is just part of the


picture. The design principles and theoretical foundations are included
in the hope that they’ll help you design your own algorithms and data
structures.

Why Are You Here?


When working with algorithms, you’re trying to solve problems
efficiently. Your programs should be fast; the wait for a solution should
be short. But what, exactly, do I mean by efficient, fast, and short? And
why would you care about these things in a language such as Python,
which isn’t exactly lightning-fast to begin with? Why not rather switch
to, say, C or Java?
First, Python is a lovely language, and you may not want to switch.
Or maybe you have no choice in the matter. But second, and perhaps
most importantly, algorists don’t primarily worry about constant
differences in performance.4 If one program takes twice, or even ten
times, as long as another to finish, it may still be fast enough, and the
slower program (or language) may have other desirable properties, such
as being more readable. Tweaking and optimizing can be costly in many
ways and is not a task to be taken on lightly. What does matter, though,
no matter the language, is how your program scales. If you double the
size of your input, what happens? Will your program run for twice as
long? Four times? More? Will the running time double even if you add
just one measly bit to the input? These are the kind of differences that
will easily trump language or hardware choice, if your problems get big
enough. And in some cases “big enough” needn’t be all that big. Your
main weapon in whittling down the growth of your running time is—
you guessed it—a solid understanding of algorithm design.
Let’s try a little experiment. Fire up an interactive Python
interpreter, and enter the following:
>>> count = 10**5
>>> nums = []
>>> for i in range(count):
... nums.append(i)
...
>>> nums.reverse()

Not the most useful piece of code, perhaps. It simply appends a


bunch of numbers to an (initially) empty list and then reverses that list.
In a more realistic situation, the numbers might come from some
outside source (they could be incoming connections to a server, for
example), and you want to add them to your list in reverse order,
perhaps to prioritize the most recent ones. Now you get an idea: instead
of reversing the list at the end, couldn’t you just insert the numbers at
the beginning, as they appear? Here’s an attempt to streamline the code
(continuing in the same interpreter window):
>>> nums = []
>>> for i in range(count):
... nums.insert(0, i)

Unless you’ve encountered this situation before, the new code might
look promising, but try to run it. Chances are you’ll notice a distinct
slowdown. On my computer, the second piece of code takes around 200
times as long as the first to finish.5 Not only is it slower, but it also
scales worse with the problem size. Try, for example, to increase
count from 10**5 to 10**6. As expected, this increases the running
time for the first piece of code by a factor of about ten … but the second
version is slowed by roughly two orders of magnitude, making it more
than two thousand times slower than the first! As you can probably
guess, the discrepancy between the two versions only increases as the
problem gets bigger, making the choice between them ever more
crucial.

Note This is an example of linear vs. quadratic growth, a


topic dealt with in detail in Chapter 3. The specific issue
underlying the quadratic growth is explained in the discussion of
vectors (or dynamic arrays) in the “Black Box” sidebar on list
in Chapter 2.

Some Prerequisites
This book is intended for two groups of people: Python programmers,
who want to beef up their algorithmics, and students taking algorithm
courses, who want a supplement to their plain-vanilla algorithms
textbook. Even if you belong to the latter group, I’m assuming you have
a familiarity with programming in general and with Python in
particular. If you don’t, perhaps my book Beginning Python can help?
The Python web site also has a lot of useful material, and Python is a
really easy language to learn. There is some math in the pages ahead,
but you don’t have to be a math prodigy to follow the text. You’ll be
dealing with some simple sums and nifty concepts such as polynomials,
exponentials, and logarithms, but I’ll explain it all as we go along.
Before heading off into the mysterious and wondrous lands of
computer science, you should have your equipment ready. As a Python
programmer, I assume you have your own favorite text/code editor or
integrated development environment—I’m not going to interfere with
that. When it comes to Python versions, the book is written to be
reasonably version-independent, meaning that most of the code should
work with both the Python 2 and 3 series. Where backward-
incompatible Python 3 features are used, there will be explanations on
how to implement the algorithm in Python 2 as well. (And if, for some
reason, you’re still stuck with, say, the Python 1.5 series, most of the
code should still work, with a tweak here and there.)

GETTING WHAT YOU NEED


In some operating systems, such as Mac OS X and several flavors
of Linux, Python should already be installed. If it is not, most
Linux distributions will let you install the software you need
through some form of package manager. If you want or need to
install Python manually, you can find all you need on the Python
web site, http://python.org.

What’s in This Book


The book is structured as follows:

Chapter 1: Introduction. You’ve already gotten through


most of this. It gives an overview of the book.

Chapter 2: The Basics. This covers the basic concepts and


terminology, as well as some fundamental math. Among
other things, you learn how to be sloppier with your
formulas than ever before, and still get the right results,
using asymptotic notation.
Chapter 3: Counting 101. More math—but it’s really fun
math, I promise! There’s some basic combinatorics for
analyzing the running time of algorithms, as well as a
gentle introduction to recursion and recurrence relations.

Chapter 4: Induction and Recursion … and Reduction.


The three terms in the title are crucial, and they are closely
related. Here we work with induction and recursion, which
are virtually mirror images of each other, both for
designing new algorithms and for proving correctness.
We’ll also take a somewhat briefer look at the idea of
reduction, which runs as a common thread through almost
all algorithmic work.

Chapter 5: Traversal: A Skeleton Key to Algorithmics.


Traversal can be understood using the ideas of induction
and recursion, but it is in many ways a more concrete and
specific technique. Several of the algorithms in this book
are simply augmented traversals, so mastering this idea will
give you a real jump start.

Chapter 6: Divide, Combine, and Conquer. When


problems can be decomposed into independent
subproblems, you can recursively solve these subproblems
and usually get efficient, correct algorithms as a result. This
principle has several applications, not all of which are
entirely obvious, and it is a mental tool well worth
acquiring.

Chapter 7: Greed is Good? Prove It! Greedy algorithms


are usually easy to construct. It is even possible to
formulate a general scheme that most, if not all, greedy
algorithms follow, yielding a plug-and-play solution. Not
only are they easy to construct, but they are usually very
efficient. The problem is, it can be hard to show that they
are correct (and often they aren’t). This chapter deals with
some well-known examples and some more general
methods for constructing correctness proofs.

Chapter 8: Tangled Dependencies and Memoization.


This chapter is about the design method (or, historically,
the problem) called, somewhat confusingly, dynamic
programming. It is an advanced technique that can be hard
to master but that also yields some of the most enduring
insights and elegant solutions in the field.

Chapter 9: From A to B with Edsger and Friends.


Rather than the design methods of the previous three
chapters, the focus is now on a specific problem, with a
host of applications: finding shortest paths in networks, or
graphs. There are many variations of the problem, with
corresponding (beautiful) algorithms.

Chapter 10: Matchings, Cuts, and Flows. How do you


match, say, students with colleges so you maximize total
satisfaction? In an online community, how do you know
whom to trust? And how do you find the total capacity of a
road network? These, and several other problems, can be
solved with a small class of closely related algorithms and
are all variations of the maximum flow problem, which is
covered in this chapter.

Chapter 11: Hard Problems and (Limited) Sloppiness.


As alluded to in the beginning of the introduction, there are
problems we don’t know how to solve efficiently and that
we have reasons to think won’t be solved for a long time—
maybe never. In this chapter, you learn how to apply the
trusty tool of reduction in a new way: not to solve problems
but to show that they are hard. Also, we take a look at how
a bit of (strictly limited) sloppiness in the optimality criteria
can make problems a lot easier to solve.

Appendix A: Pedal to the Metal: Accelerating Python.


The main focus of this book is asymptotic efficiency—
making your programs scale well with problem size.
However, in some cases, that may not be enough. This
appendix gives you some pointers to tools that can make
your Python programs go faster. Sometimes a lot (as in
hundreds of times) faster.

Appendix B: List of Problems and Algorithms. This


appendix gives you an overview of the algorithmic
problems and algorithms discussed in the book, with some
extra information to help you select the right algorithm for
the problem at hand.

Appendix C: Graph Terminology and Notation. Graphs


are a really useful structure, both in describing real-world
systems and in demonstrating how various algorithms
work. This chapter gives you a tour of the basic concepts
and lingo, in case you haven’t dealt with graphs before.

Appendix D: Hints for Exercises. Just what the title says.


Summary
Programming isn’t just about software architecture and object-oriented
design; it’s also about solving algorithmic problems, some of which are
really hard. For the more run-of-the-mill problems (such as finding the
shortest path from A to B), the algorithm you use or design can have a
huge impact on the time your code takes to finish, and for the hard
problems (such as finding the shortest route through A–Z), there may
not even be an efficient algorithm, meaning that you need to accept
approximate solutions.
This book will teach you several well-known algorithms, along with
general principles that will help you create your own. Ideally, this will
let you solve some of the more challenging problems out there, as well
as create programs that scale gracefully with problem size. In the next
chapter, we get started with the basic concepts of algorithmics, dealing
with terms that will be used throughout the entire book.

If You’re Curious …
This is a section you’ll see in all the chapters to come. It’s intended to
give you some hints about details, wrinkles, or advanced topics that
have been omitted or glossed over in the main text and to point you in
the direction of further information. For now, I’ll just refer you to the
“References” section, later in this chapter, which gives you details about
the algorithm books mentioned in the main text.
Exercises
As with the previous section, this is one you’ll encounter again and
again. Hints for solving the exercises can be found in Appendix D. The
exercises often tie in with the main text, covering points that aren’t
explicitly discussed there but that may be of interest or that deserve
some contemplation. If you want to really sharpen your algorithm
design skills, you might also want to check out some of the myriad of
sources of programming puzzles out there. There are, for example, lots
of programming contests (a web search should turn up plenty), many of
which post problems that you can play with. Many big software
companies also have qualification tests based on problems such as these
and publish some of them online.
Because the introduction doesn’t cover that much ground, I’ll just
give you a couple of exercises here—a taste of what’s to come:

1-1. Consider the following statement: “As machines get


faster and memory cheaper, algorithms become less
important.” What do you think; is this true or false? Why?

1-2. Find a way of checking whether two strings are anagrams


of each other (such as "debit card" and "bad
credit"). How well do you think your solution scales? Can
you think of a naïve solution that will scale poorly?

References
Applegate, D., Bixby, R., Chvátal, V., Cook, W., and Helsgaun, K.
Optimal tour of Sweden.
www.math.uwaterloo.ca/tsp/sweden/. Accessed April
6, 2014.

Cormen, T. H., Leiserson, C. E., Rivest, R. L., and Stein, C. (2009).


Introduction to Algorithms, second edition. MIT Press.

Dasgupta, S., Papadimitriou, C., and Vazirani, U. (2006).


Algorithms. McGraw-Hill.

Goodrich, M. T. and Tamassia, R. (2001). Algorithm Design:


Foundations, Analysis, and Internet Examples. John Wiley &
Sons, Ltd.

Hetland, M. L. (2008). Beginning Python: From Novice to


Professional, second edition. Apress.

Kleinberg, J. and Tardos, E. (2005). Algorithm Design. Addison-


Wesley Longman Publishing Co., Inc.

Knuth, D. E. (1968). Fundamental Algorithms, volume 1 of The Art


of Computer Programming. Addison-Wesley.

———. (1969). Seminumerical Algorithms, volume 2 of The Art of


Computer Programming. Addison-Wesley.

———. (1973). Sorting and Searching, volume 3 of The Art of


Computer Programming. Addison-Wesley.

———. (2011). Combinatorial Algorithms, Part 1, volume 4A of


The Art of Computer Programming. Addison-Wesley.

Miller, B. N. and Ranum, D. L. (2005). Problem Solving with


Algorithms and Data Structures Using Python. Franklin Beedle &
Associates.
__________________
1
David Applegate, Robert Bixby, Vašek Chvátal, William Cook, and Keld Helsgaun
2
Let’s assume that flying isn’t an option.
3
Knuth is also well-known for using assembly code for an abstract computer of his own design.
4
I’m talking about constant multiplicative factors here, such as doubling or halving the
execution time.
5
See Chapter 2 for more on benchmarking and empirical evaluation of algorithms.
CHAPTER 2

The Basics

Tracey: I didn’t know you were out there.

Zoe: Sort of the point. Stealth—you may have heard of it.

Tracey: I don’t think they covered that in basic.

— From “The Message,” episode 14 of Firefly

Before moving on to the mathematical techniques, algorithmic design


principles, and classical algorithms that make up the bulk of this book,
we need to go through some basic principles and techniques. When you
start reading the following chapters, you should be clear on the meaning
of phrases such as “directed, weighted graph without negative cycles”
and “a running time of Θ(n lg n).” You should also have an idea of how
to implement some fundamental structures in Python.
Luckily, these basic ideas aren’t at all hard to grasp. The main two
topics of the chapter are asymptotic notation, which lets you focus on
the essence of running times, and ways of representing trees and graphs
in Python. There is also practical advice on timing your programs and
avoiding some basic traps. First, though, let’s take a look at the abstract
machines we algorists tend to use when describing the behavior of our
algorithms.

Some Core Ideas in Computing


In the mid-1930s the English mathematician Alan Turing published a
paper called “On computable numbers, with an application to the
Entscheidungsproblem”1 and, in many ways, laid the groundwork for
modern computer science. His abstract Turing machine has become a
central concept in the theory of computation, in great part because it is
intuitively easy to grasp. A Turing machine is a simple abstract device
that can read from, write to, and move along an infinitely long strip of
paper. The actual behavior of the machines varies. Each is a so-called
finite state machine: It has a finite set of states (some of which indicate
that it has finished), and every symbol it reads potentially triggers
reading and/or writing and switching to a different state. You can think
of this machinery as a set of rules. (“If I am in state 4 and see an X, I
move one step to the left, write a Y, and switch to state 9.”) Although
these machines may seem simple, they can, surprisingly enough, be
used to implement any form of computation anyone has been able to
dream up so far, and most computer scientists believe they encapsulate
the very essence of what we think of as computing.
An algorithm is a procedure, consisting of a finite set of steps,
possibly including loops and conditionals, that solves a given problem.
A Turing machine is a formal description of exactly what problem an
algorithm solves,2 and the formalism is often used when discussing
which problems can be solved (either at all or in reasonable time, as
discussed later in this chapter and in Chapter 11). For more fine-grained
analysis of algorithmic efficiency, however, Turing machines are not
usually the first choice. Instead of scrolling along a paper tape, we use a
big chunk of memory that can be accessed directly. The resulting
machine is commonly known as the random-access machine.
While the formalities of the random-access machine can get a bit
complicated, we just need to know something about the limits of its
capabilities so we don’t cheat in our algorithm analyses. The machine is
an abstract, simplified version of a standard, single-processor computer,
with the following properties:

We don’t have access to any form of concurrent execution;


the machine simply executes one instruction after the other.

Standard, basic operations such as arithmetic, comparisons,


and memory access all take constant (although possibly
different) amounts of time. There are no more complicated
basic operations such as sorting.

One computer word (the size of a value that we can work


with in constant time) is not unlimited but is big enough to
address all the memory locations used to represent our
problem, plus an extra percentage for our variables.

In some cases, we may need to be more specific, but this machine


sketch should do for the moment.
We now have a bit of an intuition for what algorithms are, as well as
the abstract hardware we’ll be running them on. The last piece of the
puzzle is the notion of a problem. For our purposes, a problem is a
relation between input and output. This is, in fact, much more precise
than it might sound: A relation, in the mathematical sense, is a set of
pairs—in our case, which outputs are acceptable for which inputs—and
by specifying this relation, we’ve got our problem nailed down. For
example, the problem of sorting may be specified as a relation between
two sets, A and B, each consisting of sequences.3 Without describing
how to perform the sorting (that would be the algorithm), we can
specify which output sequences (elements of B) that would be
acceptable, given an input sequence (an element of A). We would
require that the result sequence consisted of the same elements as the
input sequence and that the elements of the result sequence were in
increasing order (each bigger than or equal to the previous). The
elements of A here—that is, the inputs—are called problem instances;
the relation itself is the actual problem.
To get our machine to work with a problem, we need to encode the
input as zeros and ones. We won’t worry too much about the details
here, but the idea is important, because the notion of running time
complexity (as described in the next section) is based on knowing how
big a problem instance is, and that size is simply the amount of memory
needed to encode it. As you’ll see, the exact nature of this encoding
usually won’t matter.

Asymptotic Notation
Remember the append versus insert example in Chapter 1?
Somehow, adding items to the end of a list scaled better with the list
size than inserting them at the front; see the nearby “Black Box” sidebar
on list for an explanation. These built-in operations are both written
in C, but assume for a minute that you reimplement list.append in
pure Python; let’s say arbitrarily that the new version is 50 times slower
than the original. Let’s also say you run your slow, pure-Python
append-based version on a really slow machine, while the fast,
optimized, insert-based version is run on a computer that is 1,000 times
faster. Now the speed advantage of the insert version is a factor of
50,000. You compare the two implementations by inserting 100,000
numbers. What do you think happens?
Intuitively, it might seem obvious that the speedy solution should
win, but its “speediness” is just a constant factor, and its running time
grows faster than the “slower” one. For the example at hand, the
Python-coded version running on the slower machine will, actually,
finish in half the time of the other one. Let’s increase the problem size a
bit, to 10 million numbers, for example. Now the Python version on the
slow machine will be 2,000 times faster than the C version on the fast
machine. That’s like the difference between running for about a minute
and running almost a day and a half!
This distinction between constant factors (related to such things as
general programming language performance and hardware speed, for
example) and the growth of the running time, as problem sizes increase,
is of vital importance in the study of algorithms. Our focus is on the big
picture—the implementation-independent properties of a given way of
solving a problem. We want to get rid of distracting details and get
down to the core differences, but in order to do so, we need some
formalism.

BLACK BOX: LIST


Python lists aren’t really lists in the traditional computer science
sense of the word, and that explains the puzzle of why append is
so much more efficient than insert. A classical list—a so-called
linked list—is implemented as a series of nodes, each (except for
That’s not the case with arrays: An insertion would have to move
all elements that are to the right of the insertion point, possibly
even moving all the elements to a larger array, if needed. A
specific solution for appending is to use what’s often called a
dynamic array, or vector.4 The idea is to allocate an array that is
too big and then to reallocate it in linear time whenever it
overflows. It might seem that this makes the append just as bad as
the insert. In both cases, we risk having to move a large number of
elements. The main difference is that it happens less often with the
append. In fact, if we can ensure that we always move to an array
that is bigger than the last by a fixed percentage (say 20 percent or
even 100 percent), the average cost, amortized over many appends,
is constant.

It’s Greek to Me!


Asymptotic notation has been in use (with some variations) since the
late 19th century and is an essential tool in analyzing algorithms and
data structures. The core idea is to represent the resource we’re
analyzing (usually time but sometimes also memory) as a function, with
the input size as its parameter. For example, we could have a program
with a running time of T(n) = 2.4n + 7.
An important question arises immediately: What are the units here?
It might seem trivial whether we measure the running time in seconds or
milliseconds or whether we use bits or megabytes to represent problem
size. The somewhat surprising answer, though, is that not only is it
trivial, but it actually will not affect our results at all. We could measure
time in Jovian years and problem size in kilograms (presumably the
mass of the storage medium used), and it will not matter. This is
because our original intention of ignoring implementation details carries
over to these factors as well: The asymptotic notation ignores them all!
(We do normally assume that the problem size is a positive integer,
though.)
What we often end up doing is letting the running time be the
number of times a certain basic operation is performed, while problem
size is either the number of items handled (such as the number of
integers to be sorted, for example) or, in some cases, the number of bits
needed to encode the problem instance in some reasonable encoding.

Forgetting. Of course, the assert doesn’t work.


(http://xkcd.com/379)

Note Exactly how you encode your problems and solutions as


bit patterns usually has little effect on the asymptotic running
time, as long as you are reasonable. For example, avoid
representing your numbers in the unary number system (1=1,
2=11, 3=111…).
The asymptotic notation consists of a bunch of operators, written as
Greek letters. The most important ones, and the only ones we’ll be
using, are O (originally an omicron but now usually called “Big Oh”),
Ω (omega), and Θ (theta). The definition for the O operator can be used
as a foundation for the other two. The expression O(g), for some
function g(n), represents a set of functions, and a function f(n) is in this
set if it satisfies the following condition: There exists a natural number
n0 and a positive constant c such that

f(n) ≤ cg(n)

for all n ≥ n0. In other words, if we’re allowed to tweak the constant c
(for example, by running the algorithms on machines of different
speeds), the function g will eventually (that is, at n0) grow bigger than f.
See Figure 2-1 for an example.

2 2
Figure 2-1. For values of n greater than n0, T(n) is less than cn , so T(n) is O(n )

This is a fairly straightforward and understandable definition,


although it may seem a bit foreign at first. Basically, O(g) is the set of
functions that do not grow faster than g. For example, the function n2 is

2 2 2
in the set O(n2), or, in set notation, n2 ∈ O(n2). We often simply say that
n2 is O(n2).
The fact that n2 does not grow faster than itself is not particularly
interesting. More useful, perhaps, is the fact that neither 2.4n2 + 7 nor
the linear function n does. That is, we have both
2.4n2 + 7 ∈ O(n2)

and
n ∈ O(n2).

The first example shows us that we are now able to represent a


function without all its bells and whistles; we can drop the 2.4 and the 7
and simply express the function as O(n2), which gives us just the
information we need. The second shows us that O can be used to
express loose limits as well: Any function that is better (that is, doesn’t
grow faster) than g can be found in O(g).
How does this relate to our original example? Well, the thing is,
even though we can’t be sure of the details (after all, they depend on
both the Python version and the hardware you’re using), we can
describe the operations asymptotically: The running time of appending
n numbers to a Python list is O(n), while inserting n numbers at its
beginning is O(n2).
The other two, Ω and Θ, are just variations of O. Ω is its complete
opposite: A function f is in Ω(g) if it satisfies the following condition:
There exists a natural number n0 and a positive constant c such that
f(n) ≥ cg(n)

for all n ≥ n0. So, where O forms a so-called asymptotic upper bound, Ω
forms an asymptotic lower bound.
Note Our first two asymptotic operators, O and Ω, are each
other’s inverses: If f is O(g), then g is Ω(f). Exercise 2-3 asks you
to show this.

The sets formed by Θ are simply intersections of the other two, that
is, Θ(g) = O(g) ∩ Ω(g). In other words, a function f is in Θ(g) if it
satisfies the following condition: There exists a natural number n0 and
two positive constants c1 and c2 such that
c1g(n) ≤ f(n) ≤ c2g(n)

for all n ≥ n0. This means that f and g have the same asymptotic growth.
For example, 3n2 + 2 is Θ(n2), but we could just as well write that n2 is
Θ(3n2 + 2). By supplying an upper bound and a lower bound at the
same time, the Θ operator is the most informative of the three, and I will
use it when possible.

Rules of the Road


While the definitions of the asymptotic operators can be a bit tough to
use directly, they actually lead to some of the simplest math ever. You
can drop all multiplicative and additive constants, as well as all other
“small parts” of your function, which simplifies things a lot.
As a first step in juggling these asymptotic expressions, let’s take a
look at some typical asymptotic classes, or orders. Table 2-1 lists some
of these, along with their names and some typical algorithms with these
asymptotic running times, also sometimes called running-time
complexities. (If your math is a little rusty, you could take a look at the
sidebar “A Quick Math Refresher” later in the chapter.) An important
Random documents with unrelated
content Scribd suggests to you:
for the guests who had come with Jesus, wants her Son to give
them the wine they wanted. How does Christ answer her requests?
He answers it by a rebuke, a most solemn rebuke. Instead of saying:
“Yes, mother, I will do as you wish,” he says, “Woman, what have I
to do with thee?” which clearly means “Woman, thou hast nothing to
do in this matter. I do not want you to speak to me of the
bridegroom’s distress. It was my desire to come to their help and
show my divine power. I do not want you to put yourself between
the wants of humanity and me. I do not want the world to believe
that you had any right, any power or influence over me, or more
compassion on the miseries of man than I have. Is it not to me, and
me alone, the lost children of Adam must look to be saved? Woman,
what have I to do with thee in my great work of saving this
perishing world? Nothing, absolutely nothing. I know what I have to
do to fulfill, not your will, but my Father’s will!”
This is what Jesus meant by the solemn rebuke given to Mary. He
wanted to banish all idea of her ever becoming an intercessor
between man and Christ. He wanted to protest against the doctrine
of the Church of Rome, that it is through Mary that He will bestow
His favor, to His disciples, and Mary understood it well when she
said, “Whatsoever He saith unto you, do it.” Never come to me, but
go to Him. “For there is no other name given among men, whereby
we must be saved.”
Every one of these thoughts passed over my distressed soul like a
hurricane. Every sentence was like a flash of lightning in a dark
night. I was like the poor dismantled ship suddenly overtaken by the
tempest in the midst of the ocean.
Till the dawn of day, I felt powerless against the efforts of God to
pull down and demolish the huge fortress of sophisms, falsehoods,
idolatries, which Rome had built around my soul. What a fearful
thing it is to fight against the Lord!
During the long hours of that night, my God was contending with
me, and I was struggling against Him. But though brought down to
the dust; I was not conquered. My understanding was very nearly
convinced; but my rebellious and proud will was not yet ready to
yield.
The chains by which I was tied to the feet of the idols of Rome,
though rudely shaken, were not yet broken. However, to say the
truth, my views about the worship of Mary had received a severe
shock, and were much modified. That night had been sleepless; and
in the morning my eyes were red, and my face swollen with my
tears.
When, at breakfast, Bishop Prince, who was sitting by me, asked:
“Are you sick? Your eyes are as if you had wept all night?”
“Your lordship is not mistaken, I have wept the whole night!” I
answered.
“Wept all the night!” replied the bishop. “Might I know the cause
of your sorrow?”
“Yes, my lord. You can, you must know it. But please come to your
room. What I have to say is of such a private and delicate nature,
that I want to be alone with your lordship, when opening my mind to
the cause of my tears.”
Bishop Prince, then coadjutor of Bishop Bourget and late bishop of
St. Hyacinthe, where he became insane in 1858 and died in 1860,
had been my personal friend from the time I entered the college at
Nicolet, where he was professor of Rhetoric. He very often came to
confession to me, and had taken a lively interest in my labors on
temperance.
When alone with him, I said: “My lord, I thank you for your
kindness in allowing me to unburden my heart to you. I have passed
the most horrible night of my life. Temptations against our holy
religion such as I never had before, have assailed me all night. Your
lordship remembers the kind words you addressed to me, yesterday,
about the sermon I preached. But, last night, very different things
came to my mind, which have changed the joys of yesterday into
the most unspeakable desolation. You congratulated me, yesterday,
on the manner I had proved that Jesus had always granted the
request of His mother, and that He cannot refuse any of her
petitions. The whole night it has been told to me that this was a
blasphemous lie, and from the Holy Scriptures themselves, I have
been nearly convinced that you and I, nay, that our holy church, are
preaching a blasphemous falsehood every time we proclaim the
doctrines of the worship of Mary as the gospel truth.”
The poor bishop, thunderstruck by this simple and honest
declaration, quickly answered: “I hope you have not yielded to these
temptations, and that you will not become a Protestant as so many
of your enemies whisper to each other.”
“It is my hope, my lord, that our merciful God will keep me, to the
end of my life, a dutiful and faithful priest of our holy church.
However, I cannot conceal from your lordship that my faith was
terribly shaken, last night.
“As a bishop, your portion of light and wisdom must be greater
than mine. I hope you will grant me some of the lights which still
brightly shine before your eyes: I have never been so much in need
of the counsels of your piety and the help of your spiritual
knowledge as to-day. Please help me to come out from the
intellectual slough in which I spent the night.
“Your lordship has congratulated me for having said that Jesus
Christ has always granted the petitions of Mary. Please tell me how
you reconcile that proposition with this text,” and I handed him the
gospel of Matthew: pointing to the last five verses of the twelfth
chapter, I requested him to read them aloud.”
He read them and said: “Now what do you want from me?”
“My lord, I want respectfully to ask you how can we say that Jesus
has always granted the requests of His mother, when this evangelist
tells us that He never granted her petitions, when acting in His
capacity of Saviour of the world.
“Must we not fear that we proclaim a blasphemous falsehood
when we support a proposition directly opposed to the gospel?”
The poor bishop seemed absolutely confounded by this simple and
honest question. I also felt confused and sorry for his humiliation.
Beginning a phrase, he would give it up; trying arguments, he could
not push to their conclusion. It seemed to me that he had never
read that text, or if he had read it, he, like myself and the rest of the
priests of Rome, had never noted that they entirely demolish the
stupendous impostures of the church in reference to the worship of
Mary.
In order to help him out of the inextricable difficulties into which I
had once pushed him, I said: “My lord, will you allow me to put a
few more questions to you?”
“With pleasure,” he answered.
“Well! my lord, who came to this world to save you and me? Is it
Jesus or Mary?”
“It is Jesus,” answered the bishop.
“Who was called, and is, in reality, the sinner’s best friend? Was it
Jesus or Mary?”
The bishop answered: “It was Jesus.”
“Now please allow me a few more questions.”
“When Jesus and Mary were on earth, whose heart was most
devoted to sinners? Who loved them with a more efficacious and
saving love; was it Jesus or Mary?”
“Jesus, being God, His love was evidently more efficacious and
saving than Mary’s,” answered the bishop.
“In the days of Jesus and Mary, to whom did Jesus invite sinners
to go for their salvation; was it to himself or Mary?” I asked again.
The bishop answered: “Jesus has said to all sinners, ‘Come unto
me.’ He never said come or go to Mary.”
“Have we any examples, in the Scriptures, of sinners, who, fearing
to be rebuked by Jesus, have gone to Mary and obtained access to
him through her, and been saved through her intercessions?”
“I do not remember of any such cases,” replied the bishop.
I then asked: “To whom did the penitent thief, on the cross,
address himself to be saved; was it to Jesus or to Mary?”
“It was to Jesus,” replied the bishop.
“Did that penitent thief do well to address himself to Jesus on the
cross, rather than to Mary who was at His feet?” said I.
“Surely he did better,” answered the bishop.
“Now, my lord, allow me only one question more. You told me that
Jesus loved sinners, when on earth, infinitely more than Mary; that
he was infinitely more their true friend than she was; that he
infinitely took more interest in their salvation, than Mary; that it was
infinitely better for sinners to go to Jesus than to Mary, to be saved;
will you please tell me if you think that Jesus has lost, in heaven,
since he is sitting at the right hand of his Father, any of his divine
and infinite superiority of love and mercy over Mary for sinners: and
can you show me that what Jesus has lost has been gained by
Mary?”
“I do not think that Christ has lost any of his love, and power to
save us, now that he is in heaven,” answered the bishop.
“Now, my lord, if Jesus is still my best friend; my most powerful,
merciful and loving friend, why should I not go directly to him? Why
should we, for a moment, go to any one who is infinitely inferior, in
power, love and mercy, for our salvation?”
The bishop was stunned by my questions.
He stammered some unintelligible answer, excused himself for not
being able to remain any longer, on account of some pressing
business; and extending his hand to me before leaving he said: “You
will find an answer to your questions and difficulties in the Holy
Fathers.”
“Can you lend me the Holy Fathers, my lord?”
He replied: “No sir, I have them not.”
This last answer from my bishop, shook my faith to its foundation,
and left my mind in a state of great distress. With the sincere hope
of finding in the Holy Fathers, some explanations which would dispel
my painful doubts, I immediately went to Mr. Fabre, the great
bookseller of Montreal, who got me, from France, the splendid
edition of the Holy Fathers, by Migne. I studied with the utmost
attention, every page where I might find what they taught of the
worship of Mary, and the doctrines that Jesus had never refused any
of her prayers.
What was my desolation, my shame and my surprise, to find that
the Holy Fathers of the first six centuries had never advocated the
worship of Mary, and that the many eloquent pages on the power of
Mary in heaven, and her love for sinners, found in every page of my
theologians; and other ascetic books I had read till then, were but
impudent lies; additions interpolated in their works a hundred years
after their death.
When discovering these forgeries, under the name of the Holy
Fathers, of which my church was guilty, how many times, in the
silence of my long nights of study and prayerful meditations, did I
hear a voice telling me: “Come out of Babylon.”
But where could I go? Out of the Church of Rome, where could I
find that salvation which was to be found only within her walls? I
said to myself, “Surely there are some errors in my dear church.”
“The dust of ages may have fallen on the precious gold of her
treasures, but will I not find still more damnable errors among those
hundreds of Protestant churches, which, under the name of
Episcopalians, Presbyterians, Baptists, Methodists, &c., &c., are
divided and sub-divided into scores of contemptible sects
anathematizing and denouncing each other before the world?”
My ideas of the great family of evangelical churches, comprised
under the broad name of Protestantism, were so exaggerated then,
that it was absolutely impossible for me to find in them that unity
which I considered the essentials of the church of Christ.
The hour was not yet come, but it was coming fast, when my dear
Saviour would make me understand his sublime words: “I am the
vine and ye are the branches.”
It was some time later, when under the beautiful vine I had
planted in my own garden, and which I had cultivated with mine
own hands, I saw that there was not a single branch like another in
that prolific vine.
Some branches were very big, some very thin, some very long,
some very short, some going up, some going down, some straight
as an arrow, some crooked as a flash of lightning, some turning to
the west, some to the east, some to the north, and others to the
south.
But, although the branches were so different from each other in
so many things, they all gave me excellent fruit, so long as they
remained united to the vine.
Chapter XLVI.

THE HOLY FATHERS—NEW MENTAL TROUBLES AT NOT


FINDING THE DOCTRINES OF MY CHURCH IN THEIR
WRITINGS—PURGATORY AND THE SUCKING PIG OF THE
POOR MAN OF VARENNES.

The most desolate work of a sincere catholic priest is the study of


the Holy Fathers. He does not make a step in the labyrinth of their
discussions and controversies without seeing the dreams of his
theological studies and religious views disappear as the thick
morning mist, when the sun rises above the horizon. Bound, as he
is, by a solemn oath, to interpret the Holy Scriptures only according
to the unanimous consent of the Holy Fathers, the first thing which
puzzles and distresses him is their absolute want of unanimity on the
greater part of the subjects which they discuss. The fact is, that
more than two-thirds of what one Father has written, is to prove
that what some other Holy Father has written, is wrong and
heretical.
The student of the Fathers not only detects that they do not agree
with one another, but finds that many of them do not even agree
with themselves. Very often they confess that they were mistaken
when they said this and that; that they have lately changed their
minds; that they now hold for saving truth, what they formerly
condemned as damnable error!
What becomes of the solemn oath of every priest, in presence of
this undeniable fact? How can he make an act of faith when he feels
that its foundation is nothing but falsehood?
No words can give an idea of the mental tortures I felt, when I
saw positively, that I could not, any longer, preach on the eternity of
the suffering of the damned, nor believe in the real presence of the
body, soul and divinity of Christ in the sacrament of communion; nor
in the supremacy of the sovereign pontiff of Rome, nor in any of the
other dogmas of the church, without perjuring myself! For there was
not one of those dogmas which had not been flatly and directly
denied by some Holy Fathers.
It is true, that in my Roman Catholic theological books, I had long
extracts of Holy Fathers, very clearly supporting and confirming my
faith in these dogmas. For instance, I had the apostolic liturgies of
St. Peter, St. Mark, and St. James, to prove that the sacrifice of the
mass, purgatory, prayers for the dead, transubstantiation, were
believed and taught from the very days of the apostles.
But what was my dismay when I discovered that those liturgies
were nothing else than vile and audacious forgeries presented to the
world, by my Popes and my church, as gospel truths.
I could not find words to express my sense of shame and
consternation, when I became sure that the same church which had
invented these apostolic liturgies, had accepted and circulated the
false decretals of Isidore, and forged innumerable additions and
interpolations to the writings of the Holy Fathers, in order to make
them say the very contrary of what they intended.
How many times, when alone, studying the history of the
shameless fabrications, I said to myself: “Does the man whose
treasury is filled with pure gold, forge false coins, or spurious pieces
of money? No! How, then, is it possible that my church does possess
the pure truth, when she has been at work during so many
centuries, to forge such egregious lies, under the names of liturgies
and decretals, about the holy mass, purgatory, the supremacy of the
Pope, etc.”
“If those dogmas could have been proved by the gospel and the
true writings of the Fathers, where was the necessity of forging lying
documents? Would the Popes and councils have treasuries with
spurious bank bills, if they had had exhaustless mines of pure gold in
hand? What right has my church to be called holy and infallible,
when she is publicly guilty of such impostures?”
From my infancy I had been taught, with all the Roman Catholics,
that Mary is the mother of God, and many times every day, when
praying to her, I used to say, “Holy Mary, mother of God, pray for
me.”
But what was my distress when I read in the “Treatise on Faith
and Creed,” by St Augustine, chapter iv., § 9, these very words,
“When the Lord said: Woman, what have I to do with thee? Mine
hour is not yet come.” (John xix: 4.) He rather admonishes us to
understand that, in respect of His being God, there was no mother
for Him.
This was so completely demolishing the teachings of my church,
and telling me that it was blasphemy to call Mary, mother of God,
that I felt as if struck with a thunderbolt.
Several volumes might be written, if my plan were to give the
story of my mental agonies, when reading the Holy Fathers, I found
their furious battles against each other, and reviewed their fierce
divisions on almost every subject. The horror of many of them at the
dogmas which my church had taught to make me believe from my
infancy, as the most solemn and sacred revelations of God to man,
such as transubstantiation, auricular confession, purgatory, the
supremacy of Peter, the absolute supremacy of the Pope over the
whole church of Christ. Yes! what thrilling pages I would give to the
world, were it my intention to portray in their true colors, the dark
clouds, the flashing lights and destructive storms which, during the
long and silent hours of the many nights I spent in comparing the
Fathers with the Word of God and the teachings of my church. Their
fierce and constant conflicts; their unexpected, though undeniable
opposition to many of the articles of the faith I had to believe and
preach; were coming to me day after day, as the barbed darts
thrown at the doomed whale when coming out of the dark regions
of the deep to see the light and breathe the pure air.
Thus, as the unexpected contradictions of the Holy Fathers to the
tenets of my church, and their furious and uncharitable divisions
among themselves, were striking me, I plunged deeper and deeper
in the deep waters of the Fathers and the Word of God, with the
hope of getting rid of the deadly darts which were piercing my
Roman Catholic conscience. But it was in vain. The deeper I went,
the more the deadly weapons would stick to the flesh and bone of
my soul. How deep was the wound I received from Gregory the
Great, one of the most learned Popes of Rome, against supremacy
and universality of the power of the Pope of Rome as taught to-day,
the following extracts from his writings will show: “But I confidently
say that whosoever calls himself universal bishop, or desires to be
called so, in his pride, he prefers himself to the rest. And he is led to
error with a similar pride. For as that wicked one wishes to appear a
God, above all men, whosoever he is, who alone desires to be called
a supreme Bishop, extols himself above the other bishops.” (Bk. vii.
Int. 15. Epist. 33, to Maurituus Augustus.)
These words wounded me very painfully. I showed them to Mr.
Brassard, saying: “Do you not see here the incontrovertible proof of
what I have told you many times, that, during the first six centuries
of Christianity, we do not find the least proof that there was anything
like our dogma of the supreme power and authority of the Bishop of
Rome, or any other bishop, over the rest of the Christian world? If
there is anything which comes to the mind with an irresistible force,
when reading the Fathers of the first centuries, it is that, not one of
them had any idea that there was, in the church, any man chosen by
God, to be in fact or name, the universal and supreme pontiff. With
such an undeniable fact before us, how can we believe and say that
the religion we profess and teach is the same which was preached
from the beginning of Christianity?”
“My dear Chiniquy,” answered Mr. Brassard, “did I not tell you,
when you bought the Holy Fathers, that you were doing a foolish
and dangerous thing? In every age, the man who singularises
himself and walks out of the common tracks of life is subject to fall
into ridicule. As you are the only priest in Canada who has the Holy
Fathers, it is thought and said in many quarters, that it is through
pride you got them; that it is to raise yourself above the rest of the
clergy, that you study them, not only at home, but that you carry
some wherever you go. I see with regret, that you are fast losing
ground in the mind, not only of the bishop, but of the priests in
general, on account of your indomitable perseverance in giving all
your spare time in their study. You are also too free and imprudent
in speaking of what you call the contradictions of the Holy Fathers,
and their want of harmony with some of our religious views. Many
say that this too great application to study, without a moment of
relaxation, will upset your intelligence and trouble your mind. They
even whisper that there is danger ahead for your faith, which you do
not suspect, and that they would not be surprised if the reading of
the Bible and the Holy Fathers would drive you into the abyss of
Protestantism. I know that that they are mistaken, and I do all in my
power to defend you. But, I thought, as your most devoted friend,
that it was my duty to tell you those things, and warn you before it
is too late.”
I replied: “Bishop Prince told me the very same things, and I will
give you the answer he got from me; ‘When you ordain a priest, do
you not make him swear that he will never interpret the Holy
Scriptures, except according to the unanimous consent of the Holy
Fathers? Ought you not, then, to know what they teach? For, how
can we know their unanimous consent without studying them. Is it
not more than strange that not only the priests do not study the
Holy Fathers, but the only one in Canada who is trying to study
them, is turned into ridicule and suspected of heresy? Is it my fault if
that precious stone, called 'unanimous consent of the Holy Fathers’
which is the very foundation of our religious belief and teachings, is
to be found nowhere in them? Is it my fault if Origen never believed
in the eternal punishment of the damned; if St. Cyprien denied the
supreme authority of the Bishop of Rome, if St. Augustine positively
said that nobody was obliged to believe in purgatory, if St. John
Chrysostom publicly denied the obligations of auricular confession,
and the real presence of the body of Christ in the eucharist? Is it my
fault if one of the most learned and holy Popes, Gregory the Great,
has called by the name of Antichrist, all his successors, for taking the
name of supreme pontiff, and trying to persuade the world that they
had, by divine authority, a supreme jurisdiction and power over the
rest of the church?’”
“And what did Bishop Prince answer you?” rejoined Mr. Brassard.
“Just as you did, by expressing his fears that my too great
application to the study of the Bible and the Holy Fathers would
either send me to the lunatic asylum, or drive me into the
bottomless abyss of Protestantism.”
I answered him, in a jocose way: “that if the too great study of
the Bible and the Holy Fathers were to open me the gates of the
lunatic asylum, I feared I would be left alone there, for I know that
they are keeping themselves at a respectable distance from those
dangerous writings.” I added seriously. “So long as God keeps my
intelligence sound, I cannot join Protestants, for the numberless and
ridiculous sects of these heretics are a sure antidote against their
poisonous errors. I will not remain a good Catholic on account of the
unanimity of the Holy Fathers, which does not exist, but I will remain
a Catholic on account of the grand and visible unanimity of the
prophets, apostles and the evangelists, with Jesus Christ. My faith
will not be founded upon the fallible, obscure and wavering words of
Origen, Tertullian, Chrysostom, Augustine or Jerome; but on the
infallible word of Jesus, the Son of God, and His inspired writers;
Matthew, Mark, Luke, John, Peter, James and Paul. It is Jesus, not
Origen who will now guide me; for the second was a sinner, like
myself, and the first is forever my Saviour and my God. I know
enough of the Holy Fathers to assure your lordship that the oath we
take accepting the Word of God according to their unanimous
consent, is a miserable blunder, if not a blasphemous perjury. It is
evident that Pius IV., who imposed the obligation of that oath upon
us all, never read a single volume of the Holy Fathers. He would not
have been guilty of such an incredible blunder, if he had known that
the Holy Fathers are unanimous in only one thing, which is to differ
from each other on almost everything; except we suppose that, like
the last Pope, he was too fond of good champagne, and that he
wrote that ordinance after a luxurious dinner.”
I spoke this last sentence in a half-serious and half-joking way.
The bishop answered: “Who told you that about our last Pope?”
“Your lordship,” I answered, “told me that, when you
complimented me on the apostolical benediction which the present
Pope sent me through my Lord Baillargeon, ‘that his predecessor
would not have given me his benediction for preaching temperance
because he was too fond of wine!’”
“Oh yes! yes! I remember it now,” answered the bishop. “But it
was a bad joke on my part, which I regret.”
“Good or bad joke,” I replied, “It is not the less the fact, that our
last Pope was too fond of wine. There is not a single priest of
Canada who has gone to Rome, without bringing that back as a
public fact, from Italy.”
“And what did my Lord Prince say to that,” asked again Mr.
Brassard.
“Just as when he was cornered by me, on the subject of the Virgin
Mary, he abruptly put an end to the conversation, by looking at his
watch and saying that he had a call to make, at that very hour.”
Not long after that painful conversation about the Holy Fathers, it
was the will of God, that a new arrow should be thrust into my
Roman Catholic conscience, which went through and through, in
spite of myself.
I had been invited to give a course of three sermons at Varennes.
The second day, at tea time, after preaching and hearing confessions
for the whole afternoon, I was coming from the church with the
curate, when half-way to the parsonage, we were met by a poor
man, who looked more like one coming out of the grave, than a
living man; he was covered with rags, and his pale and trembling
lips indicated that he was reduced to the last degree of human
misery. Taking off his hat, through respect for us, he said to Rev.
Primeau, with a trembling voice; “You know, Mr. le Cure, that my
poor wife died, and was buried ten days ago, but I was too poor to
have a funeral service sung the day she was buried, and I fear she is
in purgatory, for almost every night, I see her in my dreams,
wrapped up in burning flames. She cries to me for help, and asks me
to have a high mass sung for the rest of her soul. I come to ask you
to be so kind as to sing that high mass for her.”
“Of course,” answered the curate, “your wife is in the flames of
purgatory, and suffers there the most unspeakable tortures, which
can be relieved only by the offering of the holy sacrifice of mass.
Give me five dollars and I will sing that mass to-morrow morning.”
“You know very well, Mr. le Cure,” answered the poor man, in a
most supplicating tone, “that my wife has been sick, as well as
myself, a good part of the year. I am too poor to give you five
dollars!”
“If you cannot pay, you cannot have any mass sung. You know it
is the rule. It is not in my power to change it.”
These words were said by the curate with a high and unfeeling
tone, which were in absolute contrast with the solemnity and
distress of the poor sick man. They made a very painful impression
upon me, for I felt for him. I knew the curate was well-off, at the
head of one of the richest parishes of Canada; that he had several
thousand dollars in the bank. I hoped at first, that he would kindly
grant the petition presented to him, without speaking of the pay, but
I was disappointed. My first thought, after hearing his hard rebuke,
was to put my hand in my pocket and take one of the several five-
dollar gold pieces I had, and give it to the poor man, that he might
be relieved from his terrible anxiety about his wife. It came also to
my mind to say to him: “I will sing your high mass for nothing to-
morrow.” But alas! I must confess, to my shame, I was too cowardly
to do that noble deed. I had a sincere desire to do it, but was
prevented by the fear of insulting that priest, who was older than
myself, and for whom I had always entertained great respect. It was
evident to me that he would have taken my action as a
condemnation of his conduct.
When I was feeling ashamed of my own cowardice, and still more
indignant against myself than against the curate, he said to the
disconcerted poor man: “That woman is your wife; not mine. It is
your business, and not mine, to see how to get her out of
purgatory.”
Turning to me, he said, in the most amiable way: “Please, sir,
come to tea.”
We hardly started, when the poor man, raising his voice, said, in a
most touching way: “I cannot leave my poor wife in the flames of
purgatory; if you cannot sing a high mass, will you please say five
low masses to rescue her soul from those burning flames?”
The priest turned towards him and said: “Yes, I can say five
masses to take the soul of your wife out of purgatory, but give me
five shillings; for you know the price of a low mass is one shilling.”
The poor man answered: “I can no more give one dollar than I
can five. I have not a cent; and my three poor little children are as
naked and starving as myself.”
“Well! well!” answered the curate, “when I passed this morning,
before your house, I saw two beautiful sucking pigs. Give me one of
them, and I will say your five low masses.”
The poor man said: “These small pigs were given me by a
charitable neighbor, that I might raise them to feed my poor children
next winter. They will surely starve to death, if I give my pigs away.”
But I could not listen any longer to that strange dialogue; every
word of which fell upon my soul as a shower of burning coals. I was
beside myself with shame and disgust. I abruptly left the merchant
of souls, finishing his bargains, went to my sleeping-room, locked
the door, and fell upon my knees to weep to my heart’s content.
A quarter of an hour later, the curate knocked at my door and
said: “Tea is ready; please come down!” I answered: “I am not well;
I want some rest. Please excuse me, if I do not take my tea to-
night.”
It would require a more eloquent pen than mine to give the
correct history of that sleepless night. The hours were dark and
long.
“My God! my God!” I cried, a thousand times, “Is it possible that,
in my so dear Church of Rome, there can be such abominations as I
have seen and heard to-day? Dear and adorable Saviour, if thou wert
still on earth, and should see the soul of a daughter of Israel fallen
into a burning furnace, wouldst thou ask a shilling to take it out?
Wouldst thou force the poor father, with his starving children, to give
their last morsel of bread, to persuade thee to extinguish the
burning flames? Thou hast shed the last drop of thy blood to save
her. And how cruel, how merciless, we, thy priests, are, for the same
precious soul! But are we really thy priests? Is it not blasphemous to
call ourselves thy priests, when not only we will not sacrifice
anything to save that soul, but will starve the poor husband and his
orphans? What right have we to extort such sums of money from thy
poor children to help them out of purgatory? Do not thy apostles say
that thy blood alone can purify the soul?
“Is it possible that there is such a fiery prison for the sinners after
death, and that neither thyself nor any of thy apostles has said a
word about it?
“Several of the Fathers consider purgatory as of Pagan origin.
Tertullian spoke of it only after he had joined the sect of the
Montanists, and he confesses that it is not through the Holy
Scriptures, but through the inspiration of the Paraclete of Montanus
that he knows anything about purgatory. Augustine, the most
learned and pious of the Holy Fathers, does not find purgatory in the
Bible, and positively says that its existence is dubious; that every
one may believe what he thinks proper about it. Is it possible that I
am so mean as to have refused to extend a helping hand to that
poor distressed man, for fear of offending the cruel priest?
“We priests believe, and say that we can help souls out of the
burning furnace of purgatory, by our prayers and masses; but
instead of rushing to their rescue, we turn to the parents, friends,
the children of those departed souls, and say: “Give me five dollars;
give me a shilling, and I will put an end to those tortures; but if you
refuse us that money, we will let your father, husband, wife, child, or
friend endure those tortures, hundreds of years more! Would not the
people throw us into the river, if they could once understand the
extent of our meanness and avarice? Ought we not to be ashamed
to ask a shilling to take out of the fire a human being who calls us to
the rescue? Who, except a priest, can descend so low in the regions
of depravity?”
It would take too long to give the thoughts which tortured me
during that terrible night. I literally bathed my pillow with my tears.
Before saying my mass next morning, I went to confess my criminal
cowardice and want of charity towards that poor man, and also the
terrible temptation against my faith which tortured my conscience
during the long hours of that night! And I repaired my cowardice by
giving $5.00 to that poor man.
I spent the morning in hearing confessions till ten o’clock, when I
delivered a very exciting sermon on the malice of sin, proved by the
sufferings of Christ on the cross. This address gave a happy
diversion to my mind, and made me forget the sad story of the
sucking pig.
After the sermon, the curate took me by the hand to his dining
room, where he gave me, in spite of myself, the place of honor.
He had the reputation of having one of the best cooks of Canada,
in the widow of one of the governors of Nova Scotia, whom he had
as his housekeeper. The dishes before our eyes did not diminish his
good reputation.
The first dish was a sucking pig, roasted with an art and
perfection as I had never seen; it looked like a piece of pure gold,
and its smell would have brought water to the lips of the most
penitent anchorite.
I had not tasted anything for the last twenty-four hours; had
preached two exciting sermons, and spent six hours in hearing
confessions. I felt hungry; and the sucking pig was the most
tempting thing to me. It was a real epicurean pleasure to look at it
and smell its fragrance. Besides, that was a favorite dish with me. I
cannot conceal that it was with real pleasure that I saw the curate,
after sharpening his long, glittering knife on the file, cutting a
beautiful slice from the shoulder, and offering it to me. I was too
hungry to be over patient. My knife and fork had soon done their
work. I was carrying to my mouth the tempting and succulent
mouthful, when, suddenly, the remembrance of the poor man’s
sucking pig came to my mind. I laid the piece on my plate, and with
painful anxiety, looked at the curate and said: “Will you allow me to
put you a question about this dish?”
“Oh! yes; ask me, not only one, but two questions, and I will be
happy to answer you to the best of my ability,” answered he, with
his fine manners.
“Is this the sucking pig of the poor man of yesterday?” I asked.
With a convulsive fit of laughter, he replied: “Yes; it is just it. If we
cannot take away the soul of the poor woman out of the flames of
purgatory, we will, at all events, eat a fine sucking pig!”
The other thirteen priests filled the room with laughter, to show
their appreciation of their host’s wit.
However, their laughter was not of long duration. With a feeling of
shame and uncontrollable indignation, I pushed away my plate with
such force, that it crossed the table, and nearly fell on the floor,
saying, with a sentiment of disgust which no pen can describe: “I
would rather starve to death than eat of that execrable dish; I see in
it the tears of the poor man; I see the blood of his starving children;
it is the price of a soul. No! no, gentlemen; do not touch it. You
know, Mr. Curate, how 30,000 priests and monks were slaughtered
in France, in the bloody days of 1792. It was for such iniquities as
this that God Almighty visited the church in France. The same future
awaits us here in Canada, the very day that people will awaken from
their slumber and see that, instead of being ministers of Christ, we
are vile traders of souls, under the mask of religion.”
The poor curate, stunned by the solemnity of my words, as well as
by the consciousness of his guilt, lisped some excuse. The sucking
pig remained untouched; and the rest of the dinner had more the
appearance of a burial ceremony than of a convivial repast.
By the mercy of God, I had redeemed my cowardice of the day
before. But I had mortally wounded the feelings of that curate and
his friends, and forever lost their good-will.
It is in such ways that God was directing the steps of his
unprofitable servant through ways unknown to him. Furious storms
were constantly blowing around my fragile bark, and tearing my sails
into fragments. But, every storm was pushing me, in spite of myself,
towards the shores of eternal life, where I was to land safely a few
years later.
Chapter XLVII.

LETTER FROM THE REV. BISHOP VANDEVELD, OF CHICAGO


—VAST PROJECT OF THE BISHOPS OF THE UNITED STATES
TO TAKE POSSESSION OF THE RICH VALLEY OF THE
MISSISSIPPI AND THE PRAIRIES OF THE WEST, TO RULE
THAT GREAT REPUBLIC—THEY WANT TO PUT ME AT THE
HEAD OF THE WORK—MY LECTURES ON TEMPERANCE AT
DETROIT—INTEMPERANCE OF THE BISHOP AND PRIESTS
OF THAT CITY.

On the 15th of December, 1850, I received the following letter:


Chicago, Ill., Dec. 1st, 1850.
Rev. Father Chiniquy,
Apostle of Temperance of Canada.
Dear Sir:—When I was in Canada, last fall, I intended to confer
with you on a very important subject. But you were then working in
the diocese of Boston, and my limited time prevented me from going
so far to meet you. You are aware that the lands of the State of
Illinois and the whole valley of the Mississippi are among the richest
and most fertile of the world. In a near future, those regions, which
are now a comparative wilderness, will be the granary, not only of
the United States, but of the whole world; and those who will
possess them, will not only possess the very heart and arteries of
this young and already so great republic, but will become its rulers.
It is our intention, without noise, to take possession of those vast
and magnificent regions of the west in the name and for the benefit
of our holy church. Our plan to attain that object is as sure as easy.
There is, every year, an increasing tide of emigration from the
Roman Catholic regions of Europe and Canada towards the United
States. Unfortunately, till now, our emigrants have blindly scattered
themselves among the Protestant populations, which too often
absorb them and destroy their faith.
Why should we not direct their steps to the same spot? Why
should we not, for instance, induce them to come and take
possession of these fertile States of Illinois, Missouri, Iowa, Kansas,
etc. They can get those lands now at a nominal price. If we succeed,
as I hope we will, our holy church will soon count her children here
by ten and twenty millions, and through their numbers, their wealth
and unity, they will have such a weight in the balance of power that
they will rule everything.
The Protestants, always divided among themselves, will never
form any strong party without the help of the united vote of our
Catholic people; and that party alone which will ask and get our help
by yielding to our just demands, will rule the country. Then, in
reality, though not in appearance, our holy church will rule the
United States, as she is called by our Saviour Himself to rule the
whole world. There is, to-day, a wave of emigration from Canada
towards the United States which, if not stopped or well directed, is
threatening to throw the good French Canadian people into the mire
of Protestantism. Your countrymen, when once mixed with the
numberless sects which try to attract them, are soon shaken in their
faith. Their children sent to Protestant schools, will be unable to
defend themselves against the wily and united efforts made to
pervert them.
But put yourself at the head of the emigrants from Canada, France
and Belgium; prevent them from settling any longer among the
Protestants, by inducing them to follow you to Illinois, and with
them you will soon see here a Roman Catholic people, whose
number, wealth and influence will amaze the world. God Almighty
has wonderfully blessed your labors in Canada, in that holy cause of
temperance. But now the work is done, the same Great God
presents to your Christian ambition a not less great and noble work
for the rest of your life. Make use of your great influence over your
countrymen to prevent them from scattering any longer among
Protestants, by inducing them to come here, in Illinois. You will then
lay the foundation of a Roman Catholic French people whose piety,
unity, wealth and number will soon renew and revive, on this
continent, the past and fading glories of the Church of France.
We have already, at Bourbonnais, a fine colony of French
Canadians. They long to see and hear you. Come and help me to
make that comparatively small, though thriving people, grow with
the emigrants from the French-speaking countries of Europe and
America, till it covers the whole territory of Illinois with its sturdy
sons and pious daughters. I will ask the pope to make you my
coadjutor, and you will soon become my successor, for I already feel
too weak and unhealthy to bear alone the burden of my too large
diocese.
Please consider what I propose to you before God, and answer
me. But be kind enough to consider this overture as strictly
confidential between you and me, till we have brought our plans into
execution.
Truly Yours, ✠Oliv Vandeveld,
Bishop of Chicago.
I answered him that the bishops of Boston, Buffalo and Detroit
had already advised me to put myself at the head of the French
Canadian emigration, in order to direct its tide towards the vast and
rich regions of the West. I wrote him that I felt as he did, that it was
the best way to prevent my countrymen from falling into the snares
laid before them by Protestants, among whom they were scattering
themselves. I told him that I would consider it a great honor and
privilege to spend the last part of my life in extending the power and
influence of our holy church over the United States, and that I
would, in June next, pay my respects to him in Chicago, when on my
way towards the colony of my countrymen at Bourbonnais Grove. I
added that after I should have seen those territories of Illinois and
the Mississippi valley with my own eyes it would be more easy to
give him a definite answer. I ended my letter by saying: “But I
respectfully request your lordship to give up the idea of selecting me
for your coadjutor or successor. I have already twice refused to
become a bishop. That high dignity is too much above my merits
and capacities to be ever accepted by me. I am happy and proud to
fight the battles of our holy church; but let my superiors allow me to
continue to remain in her ranks simply as a soldier to defend her
honor and extend her power. I may, then, with the help of God, do
some good. But I feel and know that I would spoil everything, if
raised to an elevated position, for which I am not fit.”
Without speaking to anybody of the proposition of the Bishop of
Chicago, I was preparing to go and see the new field where he
wanted me to work, when, in the beginning of May, 1851, I received
a very pressing invitation from my Lord Lefebre, Bishop of Detroit, to
lecture on temperance to the French Canadians, who were then
forming the majority of the Roman Catholics of that city.
That bishop had taken the place of Bishop Rese, whose public
scandals and infamies had covered the whole Catholic church of
America with shame. During the last years he had spent in his
diocese, very few weeks had been passed without his being picked
up beastly drunk in the lowest taverns, and even in the streets of
Detroit, and dragged, unconscious to his palace.
After long and vain efforts to reform him, the pope and the
bishops of America had happily succeeded in persuading him to go
to Rome, and pay his respects to the so-called vicar of Jesus Christ.
This was a snare too skilfully laid to be suspected by the drunken
bishop. He had hardly set his feet in Rome when the inquisitors
threw him into one of their dungeons, where he remained till the
republicans set him at liberty, in 1848, after Pope Pius IX. had fled to
Civita Vecchia.
In order to blot out from the face of his church the black spots
with which his predecessor had covered it, my Lord Lefebre made
the greatest display of zeal for the cause of temperance. As soon as
he was inducted, he invited his people to follow his example and
enroll themselves under its banners, in a very powerful address on
the evils caused by the use of intoxicating drinks. At the end of his
eloquent sermon, laying his right hand on the altar, he made a
solemn promise never to drink any alcoholic liquors.
His telling sermon on temperance, with his solemn and public
promise, were published through nearly all the papers of that time,
and I read it many times to the people with good effect. When on
my way to Illinois, I reached the city of Detroit to give the course of
lectures demanded by the bishop, in the first week in June. Though
the bishop was absent, I immediately began to preach to an
immense audience in the Cathedral. I had agreed to give five
lectures, and it was only during the third one that Bishop Lefebre
arrived. After paying me great compliments for my zeal and success
in the temperance cause, he took me by the hand to his dining-room
and said: “Let us go and refresh ourselves.”
I shall never forget my surprise and dismay, when I perceived the
long dining table covered with bottles of brandy, wine, beer, etc.,
prepared for himself and his six or seven priests, who were already
around it, joyfully emptying their glasses. My first thought was to
express my surprise and indignation, and leave the room in disgust,
but by a second and better thought I waited a little to see more of
that unexpected spectacle. I accepted the seat offered me by the
bishop at his right hand.
“Father Chiniquy,” he said, “this is the sweetest claret you ever
drank.” And before I could utter a word, he had filled my large glass
with the wine and drank his own to my health.
Looking at the bishop in amazement, I said: “What does this
mean, my lord?”
“It means that I want to drink with you the best claret you ever
tasted.”
“Do you take me for a comedian? and have you called me here to
play such a strange comedy?” I replied, with lips trembling with
indignation.
“I did not invite you to play a comedy,” he answered. “I invited
you to lecture on temperance to my people, and you have done it in
a most admirable way these last three days. Though you did not see
me, I was present at this evening’s address. I never heard anything
so eloquent on that subject as what you said. But now that you have
fulfilled your duty, I must do mine, which is to treat you as a
gentleman and drink that bottle of wine with you.”
“But, my lord, allow me to tell you that I would not deserve to be
called or treated as a gentleman were I vile enough to drink wine
after the address I gave this evening.”
“I beg your pardon for differing from you,” answered the bishop.“
Those drunken people to whom you spoke so well against the evils
of intemperance are in need of the stringent and bitter remedies you
offer them in your teetotalism. But here we are sober men and
gentlemen, we do not want such remedies. I never thought that the
physicians were absolutely bound to take the pills they administer to
their patients.”
“I hope your lordship will not deny me the right you claim for
yourself, to differ with me in this matter. I entirely differ from you,
when you say that men who drink as you do with your priests, have
a right to be called sober men.”
“I fear, Mr. Chiniquy, that you forget where you are, and to whom
you speak just now,” replied the bishop.
“It may be that I have made a blunder, and that I am guilty of
some grave error in coming here and speaking to you as I am doing,
my lord. In that case, I am ready to ask your pardon. But before I
retract what I have said, please allow me to respectfully ask you a
very simple question.”
Then taking from my pocket-book his printed address, and his
public and solemn promise never to drink, neither to offer any
intoxicating drinks to others, I read it aloud, and said:
“Are you the same Bishop of Detroit, called Lefebre, who has
made this solemn promise? If you are not the same man, I will
retract and beg your pardon, but if you are the same, I have nothing
to retract.”
My answer fell upon the poor bishop as a thunderbolt.
He lisped some unintelligible and insignificant explanation, which,
however, he ended by a coup d’etat, in saying:
“My dear Mr. Chiniquy, I did not invite you to preach to the bishop,
but only to the people of Detroit.”
“You are right, my lord, I was not called to preach to the bishop,
but allow me to tell you that if I had known sooner that when the
Bishop of Detroit, with his priests, solemnly, publicly, and with their
right hand on the altar, promised that they would never drink any
intoxicating drinks, it means that they will drink and fill themselves
with those detestable liquors till their brains shiver with their
poisonous fumes, I would not have troubled you with my presence
or my remarks here. However, allow me to tell your lordship to be
kind enough to find another lecturer for your temperance meetings;
for I am determined to take the train to-morrow morning for
Chicago.”
There is no need to say that during that painful conversation the
priests (with only one exception) were as full of indignation against
me as they were full of wine. I left the table and went to my
sleeping apartment, overwhelmed with sadness and shame.
Half an hour later, the bishop was with me, conjuring me to
continue my lectures, on account of the fearful scandals which would
result from my sudden and unexpected exit from Detroit, when the
whole people had the assurance from me that very night that I
would continue to lecture the two following evenings. I
acknowledged that there would be a great scandal, but I told him
that he was the only one responsible for it, by his want of faith and
consistency.
He, at first, tried to persuade me that he was ordered to drink by
his own physicians, for his health; but I showed him that this was a
miserable illusion. He then said that he regretted what had occurred,
and confessed that it would be better if the priests practiced what
they preached to the people. After which, he asked me, in the name
of our Lord Jesus Christ, to forget the errors of the bishop and
priests of Detroit, in order to think only of the good which the
conversion of the numberless drunkards of that city would do to the
people.
He spoke to me with such earnestness of the souls saved, the
tears dried, the happiness restored to hundreds of families by
temperance, that he touched the most sensitive chords of my heart,
and got from me the promise that I would deliver the other two
expected lectures. He was so glad that he pressed me on his bosom
and gave me, what we call in French, Le baiser de paix (kiss of
peace), to show me his esteem and gratitude.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like