0% found this document useful (0 votes)
204 views82 pages

Instant Download (Ebook) Introduction to the Design & Analysis of Algorithms, Second Edition, International edition by Anany Levitin ISBN 9780321364135, 0321364139 PDF All Chapters

The document provides information about the ebook 'Introduction to the Design & Analysis of Algorithms, Second Edition' by Anany Levitin, including its ISBN and download links. It also lists several other ebooks available for download on the same website. The content includes a detailed table of contents covering various algorithm design techniques and analysis methods.

Uploaded by

arjaansimond
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)
204 views82 pages

Instant Download (Ebook) Introduction to the Design & Analysis of Algorithms, Second Edition, International edition by Anany Levitin ISBN 9780321364135, 0321364139 PDF All Chapters

The document provides information about the ebook 'Introduction to the Design & Analysis of Algorithms, Second Edition' by Anany Levitin, including its ISBN and download links. It also lists several other ebooks available for download on the same website. The content includes a detailed table of contents covering various algorithm design techniques and analysis methods.

Uploaded by

arjaansimond
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/ 82

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Introduction to the Design & Analysis of


Algorithms, Second Edition, International
edition by Anany Levitin ISBN 9780321364135,
0321364139

_____ Click the link below to download _____


https://ebooknice.com/product/introduction-to-the-
design-analysis-of-algorithms-second-edition-
international-edition-2505338

Explore and download more ebooks at ebooknice.com


Here are some suggested products you might be interested in.
Click the link to download

(Ebook) Introduction to the Design and Analysis of Algorithms (2nd


Edition) by Anany Levitin ISBN 9788131718377

https://ebooknice.com/product/introduction-to-the-design-and-analysis-
of-algorithms-2nd-edition-2209914

(Ebook) Introduction to the design and analysis of algorithms by


Levitin, Anany ISBN 9780132316811, 9780273764113, 0132316811,
027376411X

https://ebooknice.com/product/introduction-to-the-design-and-analysis-
of-algorithms-11878072

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

(Ebook) Introduction to the design and analysis of algorithms by


Levitin, Anany V ISBN 9780132316811, 9780273764113, 9781231241240,
0132316811, 027376411X, 1231241241

https://ebooknice.com/product/introduction-to-the-design-and-analysis-
of-algorithms-21354940
(Ebook) Introduction to the design and analysis of algorithms by
Levitin A. ISBN 9780132316811, 0132316811

https://ebooknice.com/product/introduction-to-the-design-and-analysis-
of-algorithms-2597624

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans


Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:


the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)


by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042

https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094
Introduction to the Design Analysis of Algorithms Second
Edition International edition Anany Levitin Digital Instant
Download
Author(s): Anany Levitin
ISBN(s): 9780321364135, 0321364139
Edition: Second edition, International edition
File Details: PDF, 19.14 MB
Year: 2007
Language: english
Introduction to The Design &
~~ I_ND EDIIIQN ~
Analysis of Algorithms
*
Introduction to The Design &
~

IND EDITION "


Analysis of Algorithms
~

Anany Levitin
Villanova University

Boston San Francisco New York


London Toronto Sydney Tokyo Singapore Madrid
Mexico City Munich Paris Cape Town Hong Kong Montreal
Publisher Greg Tobin
Acquisitions Editor Matt Goldstein
Project Editor Katherine Harutunian
Production Supervisor Marilyn Lloyd
Marketing Manager Michelle Brown
Project Management & Composition Windfall Software, using ZzT£X
Technical Art George Nichols
Copyeditor Richard Camp
Cover Design Joyce Cosentino Wells
Cover Illustration Jennifer M. Kohnke
Senior Pre press Supervisor Caroline Fell

Access the latest information about Addison-Wesley titles from our World Wide Web site:
http://www.aw-bc.com/cornputing

Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and Addison-
Wesley was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

If you purchased this book within the United States or Canada you should be aware that
it has been wrongfully imported without the approval of the Publisher or the Author.

Copyright© 2007 by Pearson Education, Inc.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval
system, or transmitted, in any form or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior written permission of the publisher. Printed in
the United States of America.

ISBN 0-321-36413-9
3 4 5 6 7 8 9 10-DOH-09 08 07
Brief Contents

Preface xvii
1 Introduction 1
2 Fundamentals of the Analysis of Algorithm Efficiency 41
3 Brute Force 97
4 Divide-and-Conquer 123
5 Decrease-and-Conquer 157
6 Transform-and-Conquer 197
1 Space and Time Tradeoffs 249
8 Dynamic Programming 279
9 Greedy Technique 307
1 0 Iterative Improvement 335
11 limitations of Algorithm Power 379
12 Coping with the Limitations of Algorithm Power 415
Epilogue 465
APPENDIX A
Useful Formulas for the Analysis of Algorithms 469
APPENDIX B
Short Tutorial on Recurrence Relations 473
Bibliography 487
Hints to Exercises 497
Index 541
v
r.

I;
I!
Contents

Preface xvii

1 Introduction 1
1.1 What is an Algorithm? 3
Exercises 1.1 8
1.2 Fundamentals of Algorithmic Problem Solving 9
Understanding the Problem 9
Ascertaining the Capabilities of a Computational Device 11
Choosing between Exact and Approximate Problem Solving 11
Deciding on Appropriate Data Structures 12
Algorithm Design Techniques 12
Methods of Specifying an Algorithm 12
Proving an Algorithm's Correctness 13
Analyzing an Algorithm 14
Coding an Algorithm 15
Exercises 1.2 17

1.3 Important Problem Types 19


Sorting 19
Searching 20
String Processing 21
Graph Problems 21
Combinatorial Problems 22
Geometric Problems 22
Numerical Problems 23
Exercises 1.3 23

vii
---~----·-·

Ijli
;!'
viii Contents

rll
!:! 1.4 Fundamental Data Structures 26
II:., Linear Data Structures 26
il Graphs 28
,.'II 32
I! Trees
Sets and Dictionaries 36
1:1 38
Exercises 1.4
Summary 39
f:i

I'II: 2 fundamentals of the Analysis of Algorithm


Efficiency 41
1\,

I'-,,!
i!i 2.1 Analysis Framework 42
if! Measuring an Input's Size 43
li1 Units for Measuring Running Time 44
Orders of Growth 45
Worst-Case. Best-Case, and Average-Case Efficiencies 47
III Recapitulation of the Analysis Framework 50
Exercises 2.1 50
I
! 2.2 Asymptotic Notations and Basic Efficiency Classes 52
'
' Informal Introduction 52
a-notation 53
0-notation 54
e-notation 55
Useful Property Involving the Asymptotic Notations 56
Using Limits for Comparing Orders of Growth 57
Basic Efficiency Classes 58
Exercises 2.2 59

2.3 Mathematical Analysis of Non recursive Algorithms 61


Exercises 2.3 67

2.4 Mathematical Analysis of Recursive Algorithms 69


Exercises 2.4 76

2.5 Example: Fibonacci Numbers 78


Explicit Formula for the nth Fibonacci Number 79
Algorithms for Computing Fibonacci Numbers 80
Exercises 2.5 83
Contents ix

2.6 Empirical Analysis of Algorithms 84


Exercises 2.6 90
2.7 Algorithm Visualization 91
Summary 95

3 Brute Force 97
3.1 Selection Sort and Bubble Sort 98
Selection Sort 98
Bubble Sort 100
Exercises 3.1 102

3.2 Sequential Search and Brute-Force String Matching 103


Sequential Search 103
Brute-Force String Matching 104
Exercises 3.2 105

3.3 Closest-Pair and Convex-Hull Problems by Brute Force 107


Closest-Pair Problem 107
Convex-Hull Problem 108
Exercises 3.3 112

3.4 Exhaustive Search 114


Traveling Salesman Problem 114
Knapsack Problem 115
Assignment Problem 116
Exercises 3.4 119
Summary 120

4 Divide-and-Conquer 123
4.1 Mergesort 125
Exercises 4.1 128

4.2 Quicksort 129


Exercises 4.2 134

4.3 Binary Search 135


Exercises 4.3 138
r
111 )( Contents
I
' 139
i::! 4.4 Binary Tree Traversals and Related Properties
I:] Exercises 4.4 142
,,
4.5 Multiplication of Large Integers and Strassen's
Matrix Multiplication 144
Multiplication of Large Integers 144
Strassen's Matrix Multiplication 146
Exercises 4.5 148

l:i 4.6 Closest-Pair and Convex-Hull Problems by


,.,
i''
Divide-and-Conquer 149
II Closest-Pair Problem 149
II Convex-Hull Problem 150
II Exercises 4.6 154
!I
I
Summary 155
:,f,,

.,
Iii

iii
•i
5 Decrease-and-Conquer 157
I! 160
:l'I;i 5.1 Insertion Sort
Exercises 5.1 163
l!i
'I 5.2 Depth-First Search and Breadth-First Search 164
Depth-First Search 165
',1
Breadth-First Search 167
·:
!I
Exercises 5.2 170
!'I
5.3 Topological Sorting 172
II
j, Exercises 5.3 176
II
!I 5.4 Algorithms for Generating Combinatorial Objects 177
il
,,!i Generating Permutations 178
i! Generating Subsets 180
,,
lr
Exercises 5.4 181
f.!
lr'I 5.5 Decrease-by-a-Constant-Factor Algorithms 183
Fake-Coin Problem 183
Multiplication a Ia Russe 184
Josephus Problem 185
Exercises 5.5 187

5.6 Variable-Size-Decrease Algorithms 188


Computing a Median and the Selection Problem 188
Contents xi

Interpolation Search 190


Searching and Insertion in a Binary Search Tree 191
The Game of Nim 192
Exercises 5.6 194
Summary 195

6 Transform-and-Conquer 197

6.1 Presorting 198


Exercises 6.1 201

6.2 Gaussian Elimination 203


LU Decomposition and Other Applications 208
Computing a Matrix Inverse 209
Computing a Determinant 210
Exercises 6.2 212

6.3 Balanced Search Trees 214


AVL Trees 214
2-3 Trees 218
Exercises 6.3 222

6.4 Heaps and Heapsort 223


Notion of the Heap 223
Heapsort 227
Exercises 6.4 229

6.5 Horner's Rule and Binary Exponentiation 230


Horner's Rule 231
Binary Exponentiation 233
Exercises 6.5 236

6.6 Problem Reduction 237


Computing the Least Common Multiple 238
Counting Paths in a Graph 239
Reduction of Optimization Problems 240
Linear Programming 241
Reduction to Graph Problerns 244
Exercises 6.6 245
Summary 247
8 Dynamic Programming 279

8.1 Computing a Binomial Coefficient 280


Exercises 8.1 282

8.2 Warshall's and Floyd's Algorithms 284


Warshall"s Algorithm 284
Floyd"s Algorithm for the All-Pairs Shortest-Paths Problem 288
Exercises 8.2 292

8.3 Optimal Binary Search Trees 293


Exercises 8.3 298

8.4 The Knapsack Problem and Memory Functions 299


Memory Functions 301
Exercises 8.4 303
Summary 304
Contents xiii

Greedy Technique 307

9.1 Prim's Algorithm 308


Exercises 9.1 313

9.2 Kruskal's Algorithm 315


Disjoint Subsets and Union-Find Algorithms 317
Exercises 9.2 321

9.3 Dijkstra's Algorithm 323


Exercises 9.3 327

9.4 Huffman Trees 328


Exercises 9.4 332
Summary 333

10 Iterative Improvement 335


10.1 The Simplex Method 336
Geometric Interpretation of Linear Programming 337
An Outline of the Simplex Method 341
Further Notes on the Simplex Method 347
Exercises 10.1 349

10.2 The Maximum-Flow Problem 351


Exercises 10.2 361

10.3 Maximum Matching in Bipartite Graphs 363


Exercises 10.3 369

10.4 The Stable Marriage Problem 371


Exercises 10.4 375
Summary 376

11 Limitations of Algorithm Power 379

11.1 Lower-Bound Arguments 380


Trivial Lower Bounds 381
Information-Theoretic Arguments 382
~~

xiv Contents

Adversary Arguments 382


Problem Reduction 383
Exercises 11.1 385

11.2 Decision Trees 386


Decision Trees for Sorting Algorithms 387
Decision Trees for Searching a Sorted Array 390
Exercises 11.2 392

11.3 P, NP, and NP-complete Problems 393


P and NP Problems 394
NP-Complete Problems 398
Exercises 11.3 401

11.4 Challenges of Numerical Algorithms 404


Exercises 11.4 411
Summary 413

12 Coping with the Limitations of Algorithm Power 415

12.1 Backtracking 416


n-Oueens Problem 417
Hamiltonian Circuit Problem 418
Subset-Sum Problem 419
General Remarks 421
Exercises 12.1 422

12.2 Branch-and-Bound 424


Assignment Problem 425
Knapsack Problem 428
Traveling Salesman Problem 430
Exercises 12.2 432

12.3 Approximation Algorithms for NP-hard Problems 434


Approximation Algorithms for the Traveling Salesman Problem 436
Approximation Algorithms for the Knapsack Problem 446
Exercises 12.3 451

12.4 Algorithms for Solving Nonlinear Equations 452


Bisection Method 454
Method of False Position 457
Contents XV

Newton's Method 458


Exercises 12.4 461
Summary 462

Epilogue 465

APPENDIX A
Useful formulas for the Analysis of Algorithms 469
Properties of Logarithms 469
Combinatorics 469
Important Summation Formulas 470
Sum Manipulation Rules 470
Approximation of a Sum by a Definite Integral 471
Floor and Ceiling Formulas 471
Miscellaneous 471

APPENDIX 18
Short Tutorial on Recurrence Relations 473
Sequences and Recurrence Relations 473
Methods for Solving Recurrence Relations 474
Common Recurrence Types in Algorithm Analysis 479

Bibliography 487

Hints to Exercises 497

Index 541
r
I
Preface

The most valuable acquisitions in a scientific or technical education are the


general-purpose mental tools which remain serviceable for a life-time.
-George Forsythe, "What to do till the computer scientist comes," 1968

A lgorithms play the central role in both the science and practice of computing.
Recognition of this fact has Jed to the appearance of a considerable number
of textbooks on the subject. By and large, they follow one of two alternatives
in presenting algorithms. One classifies algorithms according to a problem type.
Such a book would have separate chapters on algorithms for sorting, searching,
graphs, and so on. The advantage of this approach is that it allows an immediate
comparison of, say, the efficiency of different algorithms for the same problem.
The drawback of this approach is that it emphasizes problem types at the expense
of algorithm design techniques.
The second alternative organizes the presentation around algorithm design
techniques. In this organization, algorithms from different areas of computing are
grouped together if they have the same design approach. I share the belief of many
(e.g., [BaY95]) that this organization is more appropriate for a basic course on the
design and analysis of algorithms. There are three principal reasons for empha-
sis on algorithm design techniques. First, these techniques provide a student with
tools for designing algorithms for new problems. This makes learning algorithm
design techniques a very valuable endeavor from the practical standpoint. Second,
they seek to classify multitudes of known algorithms according to an underlying
design idea. Learning to see such commonality among algorithms from different
application areas should be a major goal of computer science education. After
all, every science considers classification of its principal subject as a major if not
the central point of its discipline. Third, in my opinion, algorithm design tech-
niques have considerable utility as general problem solving strategies, applicable
to problems beyond computing.

xvii
xvm Preface

Unfortunately, the traditional classification of algorithm design techniques


has several serious shortcomings from both theoretical and educational points
of view. The most significant of these shortcomings is the failure to classify many
important algorithms. This limitation has forced the authors of textbooks to depart
from the design technique organization and to include chapters dealing with
specific problem types. Such a switch leads to a loss of course coherence and almost
unavoidably creates confusion in students' minds.

New Taxonomy of Algorithm Design Techniques


My frustration with the shortcomings of the traditional classification of algorithm
design techniques has motivated me to develop a new taxonomy of them [Lev99],
which is the basis of this book. Here are the principal advantages of the new
taxonomy:
111 The new taxonomy is more comprehensive than the traditional one. It in-
cludes several strategies-brute force, decrease-and-conquer, transform-and-
conquer, space and time tradeoffs, and iterative improvement-that are rarely
if ever recognized as important design paradigms.
Ill The new taxonomy covers naturally many classic algorithms (Euclid's algo-
rithm, heapsort, search trees, hashing, topological sorting, Gaussian elimi-
nation, Horner's rule, to name a few) that the traditional taxonomy cannot
classify. As a result, the new taxonomy makes it possible to present the stan-
dard body of classic algorithms in a unified and coherent fashion.
'" It naturally accommodates the existence of important varieties of several
design techniques. (For example, it recognizes three variations of decrease-
and-conquer and three variations of transform-and-conquer.)
'" It is better aligned with analytical methods for efficiency analysis (see Appen-
dix B).

Design Techniques as General Problem Solving Strategies


Most applications of the design techniques in the book are to classic problems of
computer science. (The only innovation here is the inclusion of some material on
numerical algorithms, which are covered within the same general framework.)
But these design techniques can be considered general problem solving tools,
whose applications are not limited to traditional computing and mathematical
problems. Two factors make this point particularly important. First, more and
more computing applications go beyond the traditional domain, and there are
reasons to believe that this trend will strengthen in the future. Second, developing
students' problem solving skills has come to be recognized as a major goal of
college education. Among all the courses in a computer science curriculum, a

L
Preface xix

course on the design and analysis of algorithms is uniquely suitable for this task
because it can offer a student specific strategies for solving problems.
I am not proposing that a course on the design and analysis of algorithms
should become a course on general problem solving. But I do believe that the
unique opportunity provided by studying the design and analysis of algorithms
should not be missed. Toward this goal, the book includes applications to puzzles
and puzzle-like games. Although using puzzles in teaching algorithms is certainly
not a new idea, the book tries to do so systematically by going well beyond a few
standard examples.

Textbook Pedagogy
My goal was to write a text that would not trivialize the subject but would still be
readable by most students on their own. Here are some of the things done toward
this objective.

" Sharing the opinion of George Forsythe expressed in the epigraph, I have
sought to stress major ideas underlying the design and analysis of algorithms.
In choosing specific algorithms to illustrate these ideas, I limited the number
of covered algorithms to those that most clearly demonstrate an underlying
design technique or analysis method. Fortunately, most classic algorithms
satisfy this criterion.
" In Chapter 2, which is devoted to efficiency analysis, the methods used for
analyzing nonrecursive algorithms are separated from those typically used for
analyzing recursive algorithms. The chapter also includes sections devoted to
empirical analysis and algorithm visualization.
" The narrative is systematically interrupted by questions to the reader. Some
of them are asked rhetorically, in anticipation of a concern or doubt, and are
answered immediately. The goal of the others is to prevent the reader from
drifting through the text without a satisfactory level of comprehension.
" Each chapter ends with a summary recapping the most important concepts
and results discussed in the chapter.
The book contains about 700 exercises. Some of them are drills; others make
important points about the material covered in the body of the text or intro-
duce algorithms not covered there at all. A few exercises take advantage of
Internet resources. More difficult problems-there are not many of them-are
marked with a special symbol in the Instructor's Manual. (Because designat-
ing problems as difficult may discourage some students from trying to tackle
them, problems are not marked in the book itself.) Puzzles, games, and puzzle-
like questions are marked in the exercises with a special icon.
" The book provides hints to all the exercises. Detailed solutions, except for
programming projects, are provided in the Instructor's Manual, available
r

XX Preface

to qualified adopters through Addison-Wesley's Instructor Resource Cen-


ter. (Please contact your local Addison-Wesley sales representative or visit
www.aw.com/irc to access this material.) Slides in PowerPoint are available to
all readers of this book at www.aw.comfcssupport.

Changes for the Second Edition


The most important change in the second edition is a new chapter (Chapter 10)
dealing with the iterative-improvement technique. There are several reasons for
this addition.
10 Some of the most important algorithms in computer science, both from a
theoretical and practical standpoint, are based on this technique.
10 Iterative improvement is the principal alternative to the greedy strategy al-
ready covered in the book.
'" Since linear programming is discussed in Chapter 6, it is natural to cover its
principal algorithm (the simplex method) as well.
'" Iterative improvement is the only design technique of the new taxonomy that
was not included in the first edition. Therefore, its inclusion could also be
justified by the sheer need for completeness.
The four sections of the new chapter cover the following topics: the simplex
method, maximum network flows, maximum cardinality matching in bipartite
graphs, and the stable marriage problem. Each of these sections can be studied
independently of the rest, as is the case for the other chapters of the book.
There are two other additions in this edition worth mentioning. The first is
a new subsection about the game of Nim, included in Section 5.6 on variable-
decrease algorithms. The second is an expanded coverage of approximation algo-
rithms for the traveling salesman problem to give a better account of the remark-
able progress achieved in this area.
I also added about 80 new problems to the exercises. (A list of the new
problems is available on the book's Web site at www.aw-bc.com/info/levitin.)
About half of them are added to the old chapters, and a majority are puzzles or
puzzle-like questions. Judging by the feedback received, the inclusion of puzzles
and games in tbe exercises has been welcome by the book's readers, including
instructors and students using it as a textbook. As in the first edition, only the
puzzles related to the discussed topics were included in the exercises.

Prerequisites
The book assumes that a reader has gone through an introductory programming
course and a standard course on discrete structures. With such a background,
he or she should be able to handle the book's material without undue difficulty.
Still, fundamental data structures, necessary summation formulas, and recurrence
relations are reviewed in Section 1.4, Appendix A, and Appendix B, respectively.
Preface xxi

Calculus is used in only three sections (Sections 2.2, 11.4, and 12.4) and to a very
limited degree; if students lack calculus as an assured part of their background,
the portions of these three sections that involve calculus can be omitted without
hindering their understanding of the rest of the material.

Use in the Curriculum


The book can serve as a textbook for a basic course on design and analysis
of algorithms organized around algorithm design techniques. It might contain
too much material for a typical one-semester course. By and large, portions of
Chapters 3 through 12 can be skipped without the danger of making later parts
of the book incomprehensible to the reader. Any portion of the book can be
assigned for self-study. In particular, Sections 2.6 and 2.7 on empirical analysis and
algorithm visualization, respectively, can be assigned in conjunction with projects.
Here is a possible plan for a one-semester course; it assumes a 40-class meeting
format.

Lecture Topic Sections

1 Introduction 1.1-1.3
2,3 Analysis framework; 0, 8, n notations 2.1,2.2
4 Mathematical analysis of nonrecursive algorithms 2.3
5,6 Mathematical analysis of recursive algorithms 2.4, 2.5 (+ App. B)
7 Brute-force algorithms 3.1, 3.2 (+ 3.3)
8 Exhaustive search 3.4
9-10 Divide-and-conquer: mergesort, quicksort, binary 4.1-4.3
search
11 Other divide-and-conquer examples 4.4 or 4.5 or 4.6
12-14 Decrease-by-one: insertion sort, DFS and BFS, 5.1-5.3
topological sorting
15 Decrease-by-a-constant-factor algorithms 5.5
16 Variable-size-decrease algorithms 5.6
17-19 Instance simplification: presorting, Gaussian 6.1-6.3
elimination, balanced search trees
20 Representation change: heaps and heapsort or 6.4 or
Horner's rule and binary exponentiation 6.5
21 Problem reduction 6.6
22-24 Space-time tradeoffs: string matching, hashing, 7.2-7.4
B-trees
25-27 Dynamic programming algorithms 3 from 8.1-8.4
28-30 Greedy algorithms: Prim's, Kruskal's, Dijkstra's, 9.1-9.4
Huffman's
xxii Preface

Lecture Topic Sections

31-33 Iterative improvement algorithms 3 from 10.1-10.4


34 Lower-bound arguments 11.1
35 Decision trees 11.2
36 P, NP, and NP-complete problems 11.3
37 Numerical algorithms 11.4 ( + 12.4)
38 Backtracking 12.1
39 Branch-and-bound 12.2
40 Approximation algorithms for NP-hard problems 12.3

Acknowledgments
I would like to express my gratitude to the many people who have shared with
me their own and their students' opinions about the first edition and suggested
improvements and corrections. I have especially benefitted from the comments
by Eric Bach (University of Wisconsin), Stephen Bique (University of Alaska-
Fairbanks), Walter Hower (Albstadt-Sigmaringen University), Dan Joyce (Vil-
lanova University), Steven Lindell (Haverford College), and Mary-Angela Pa-
palaskari (Villanova University).
My thanks also go to Edward L. Bosworth (Columbus State University),
Philip Dorin (Loyola Marymount University), William Ford (University of the
Pacific), Jonathan Goldstine (Penn State University), Chin-Cheng Hung (South-
ern Polytechnic State University), and Brian Rosmaita (Hamilton College )-the
reviewers of the chapter on iterative-improvement algorithms-for supporting the
inclusion of this chapter in the new edition and for their ideas about presenting
these important algorithms.
In addition, I would like to convey my appreciation to the following review-
ers: David Avis (McGill University), Gordon Beavers (University of Arkansas),
Dinesh Mehta (Colorado School of Mines), Feridoon Moinian (Cameron Uni-
versity), Stephan Olariu (Old Dominion University), Stanley Selkow (WPI), Jerry
Trahan (Louisiana State University), and Yang Wang (Missouri State University).
I gratefully acknowledge the help I have received from my former student,
Rakhi Gandhi, whose assistance has certainly decreased the number of typos and
errors in the book.
I appreciate the contributions of all the reviewers of the first edition: Si-
mon Berkovich (George Washington University), Richard Borie (University of
Alabama), Douglas M. Campbell (Brigham Young University), Bin Cong (Cal-
ifornia State University, Fullerton), Steve Homer (Boston University), Roland
Htibscher (Auburn University), Sukhamay Kundu (Louisiana State University),
Sheau-Dong Lang (University of Central Florida), John C. Lusth (University of
Arkansas), John F. Meyer (University of Michigan), Steven R. Seidel (Michigan
Preface xxiii

Technological University), Ali Shokoufandeh (Drexel University), and George


H. Williams (Union College).
My thanks go to all the people at Addison-Wesley and their associates who
worked on my book. I am especially grateful to my editor Matt Goldstein, Michelle
Brown, Katherine Harutunian, Marilyn Lloyd, Joyce Wells, and Paul Anagnosto-
poulos of Windfall Software. I was lucky to have Richard Camp as the copy editor;
his numerous suggestions have definitely improved the book.
Finally, I am indebted to two members of my family. Living with a spouse
writing a book is probably more trying than doing the actual writing. My wife,
Maria, lived through several years of this, helping me any way she could. And help
she did: over 400 figures in the book and the Instructor's Manual were created by
her. My daughter Miriam has been my English prose guru over many years. She
not only read large portions of the book, but she was also instrumental in finding
the chapter epigraphs.

Anany Levitin
[email protected]
December 2005
Introduction toThe Design &
fiND EDFFIC>N .
Analysis of Algorithms
i

,I
:·!
:iJ
II.I
iil!
:i!
I'
il

[i
1
Introduction

Two ideas lie gleaming on the jeweler's velvet. The first is the calculus,
the second, the algorithm. The calculus and the rich body of mathematical
analysis to which it gave rise made modern science possible; but it has been
the algorithm that has rnade possible the modern world.
-David Berlinski, The Advent of the Algorithm, 2000

W hy do you need to study algorithms? If you are going to be a computer


professional, there are both practical and theoretical reasons to study algo-
rithms. From a practical standpoint, you have to know a standard set of important
algorithms from different areas of computing; in addition, you should be able to
design new algorithms and analyze their efficiency. From the theoretical stand-
point, the study of algorithms, sometimes called algorithmics, has come to be
recognized as the cornerstone of computer science. David Hare!, in his delightful
book pointedly titled Algorithmics: the Spirit of Computing, put it as follows:
Algorithmics is more than a branch of computer science. It is the core of
computer science, and, in all fairness, can be said to be relevant to most of
science, business, and technology. [Har92], p. 6.
But even if you are not a student in a computing-related program, there are
compelling reasons to study algorithms. To put it bluntly, computer programs
would not exist without algorithms. And with computer applications becoming
indispensable in almost all aspects of our professional and personal lives, studying
algorithms becomes a necessity for more and more people.
Another reason for studying algorithms is their usefulness in developing an-
alytical skills. After all, algorithms can be seen as special kinds of solutions to
problems-not answers but precisely defined procedures for getting answers. Con-
sequently, specific algorithm design techniques can be interpreted as problem-
solving strategies that can be useful regardless of whether a computer is involved.
Of course, the precision inherently imposed by algorithmic thinking limits the
kinds of problems that can be solved with an algorithm. You will not find, for
example, an algorithm for living a happy life or becoming rich and famous. On

1
.

w i!
'
.

2 Introduction

I' I
the other hand, this required precision has an important educational advantage.
Donald Knuth, one of the most prominent computer scientists in the history of
algorithmics, put it as follows:

A person well-trained in computer science knows how to deal with algorithms:


I
how to construct them, manipulate them, understand them, analyze them.
This knowledge is preparation for much more than writing good computer
programs; it is a general-purpose mental tool that will be a definite aid to
the understanding of other subjects, whether they be chemistry, linguistics,
or music, etc. The reason for this may be understood in the following way:
It has often been said that a person does not really understand something
until after teaching it to someone else. Actually, a person does not really
understand something until after teaching it to a computer, i.e., expressing
it as an algorithm ... An attempt to formalize things as algorithms leads to
a much deeper understanding than if we simply try to comprehend things in
the traditional way. [Knu96], p. 9.

We take up the notion of algorithm in Section 1.1. As examples, we use three


algorithms for the same problem: computing the greatest common divisor. There
are several reasons for this choice. First, it deals with a problem familiar to ev-
erybody from their middle-school days. Second, it makes the important point that
the same problem can often be solved by several algorithms. Quite typically, these
1: algorithms differ in their idea, level of sophistication, and efficiency. Third, one of
I
these algorithms deserves to be introduced first, both because of its age~it ap-
IIi peared in Euclid's famous treatise more than two thousand years ago~and its
f1 enduring power and importance. Finally, the middle-school procedure for com-
puting the greatest common divisor allows us to highlight a critical requirement
every algorithm must satisfy.
'I
I Section 1.2 deals with algorithmic problem solving. There we discuss several
important issues related to the design and analysis of algorithms. The different
aspects of algorithmic problem solving range from analysis of the problem and the
means of expressing an algorithm to establishing its correctness and analyzing its
II efficiency. The section does not contain a magic recipe for designing an algorithm
for an arbitrary problem. It is a well-established fact that such a recipe does not
'I exist. Still, the material of Section 1.2 should be useful for organizing your work
~i
·i,' on designing and analyzing algorithms.
'I
''! Section 1.3 is devoted to a few problem types that have proven to be partic-
!i ularly important to the study of algorithms and their application. In fact, there
i' are textbooks (e.g., [Sed88]) organized around such problem types. I hold the
view~shared by many others~that an organization based on algorithm design
techniques is superior. In any case, it is very important to be aware of the princi-
pal problem types. Not only are they the most commonly encountered problem
types in real-life applications, they are used throughout the book to demonstrate
particular algorithm design techniques.
I

'10
1
!J
t
1.1 What is an Algorithm? 3

Section 1.4 contains a review of fundamental data structures. It is meant to


serve as a reference rather than a deliberate discussion of this topic. If you need
a more detailed exposition, there is a wealth of good books on the subject, most
of them tailored to a particular programming language.

1.1 What is an Algorithm?


Although there is no universally agreed-on wording to describe this notion, there
is general agreement about what the concept means:
An algorithm is a sequence of unambiguous instructions for solving a
problem, i.e., for obtaining a required output for any legitimate input in
a finite amount of time.

This definition can be illustrated by a simple diagram (Figure 1.1 ).


The reference to "instructions" in the definition implies that there is some-
thing or someone capable of understanding and following the instructions given.
We call this a "computer," keeping in mind that before the electronic computer
was invented, the word "computer" meant a human being involved in perform-
ing numeric calculations. Nowadays, of course, "computers" are those ubiquitous
electronic devices that have become indispensable in almost everything we do.
Note, however, that although the majority of algorithms are indeed intended for
eventual computer implementation, the notion of algorithm does not depend on
such an assumption.
As examples illustrating the notion of algorithm, we consider in this section
three methods for solving the same problem: computing the greatest common
divisor of two integers. These examples will help us to illustrate several important
points:
"' The nonambiguity requirement for each step of an algorithm cannot be com·
promised.

problem

1
algorithm

input ---.[==·~c~om~p~ut~e~r·~·=}----+ output


FIGURE 1.1 Notion of algorithm
4 Introduction

" The range of inputs for which an algorithm works has to be specified carefully.
,. The same algorithm can be represented in several different ways.
" Several algorithms for solving the same problem may exist.
II! Algorithms for the same problem can be based on very different ideas and
can solve the problem with dramatically different speeds.
Recall that the greatest common divisor of two nonnegative, not -both-zero
integers m and n, denoted gcd(m, n), is defined as the largest integer that divides
both m and n evenly, i.e., with a remainder of zero. Euclid of Alexandria (third
century B.C.) outlined an algorithm for solving this problem in one of the volumes
of his Elements, most famous for its systematic exposition of geometry. In modern
terms, Euclid's algorithm is based on applying repeatedly the equality
gcd(m, n) = gcd(n, m mod n)
(where m mod n is the remainder of the division of m by n) until m mod n is equal
to 0; since gcd(m, 0) = m (why?), the last value of m is also the greatest common
divisor of the initial m and n.
For example, gcd(60, 24) can be computed as follows:
gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
(If you are not impressed by this algorithm, try finding the greatest common divisor
of larger numbers such as those in Problem 5 of Exercises 1.1.)
Here is a more structured description of this algorithm:
Euclid's algorithm for computing gcd(m, n)
Step 1 If n = 0, return the value of m as the answer and stop; otherwise,
proceed to Step 2.
Step 2 Divide m by n and assign the value of the remainder to r.
Step 3 Assign the value of n tom and the value of r ton. Go to Step 1.
Alternatively, we can express the same algorithm in a pseudocode:

ALGORITHM Euclid(m, n)
//Computes gcd(m, n) by Euclid's algorithm
!!Input: Two nonnegative, not -both-zero integers m and n
//Output: Greatest common divisor of m and n
while n oJ 0 do
r +-m modn
m +-n
n +---- r
return m

How do we know that Euclid's algorithm eventually comes to a stop? This


follows from the observation that the second number of the pair gets smaller with
1.1 What is an Algorithm? 5

each iteration and it cannot become negative. Indeed, the new value of n on the
next iteration ism mod n, which is always smaller than n. Hence, the value of the
second number in the pair eventually becomes 0, and the algorithm stops.
Just as with many other problems, there are several algorithms for computing
the greatest common divisor. Let us look at the other two methods for this prob-
lem. The first is simply based on the definition of the greatest common divisor of
m and n as the largest integer that divides both numbers evenly. Obviously, such
a common divisor cannot be greater than the smaller of these numbers, which we
will denote by t = min{m, n ). So we can start by checking whether t divides both
m and n: if it does, t is the answer; if it does not, we simply decrease t by 1 and
try again. (How do we know that the process will eventually stop?) For example,
for numbers 60 and 24, the algorithm will try first 24, then 23, and so on until it
reaches 12, where it stops.

Consecutive integer checking algorithm for computing gcd(m, n)


Step 1 Assign the value of min{m, n) tot.
Step 2 Divide m by t. If the remainder of this division is 0, go to Step 3;
otherwise, go to Step 4.
Step 3 Divide n by t. If the remainder of this division is 0, return the value of
t as the answer and stop; otherwise, proceed to Step 4.
Step 4 Decrease the value oft by 1. Go to Step 2.

Note that unlike Euclid's algorithm, this algorithm, in the form presented,
does not work correctly when one of its input numbers is zero. This example
illustrates why it is so important to specify the range of an algorithm's inputs
explicitly and carefully.
The third procedure for finding the greatest common divisor should be famil-
iar to you from middle school.

Middle-school procedure for computing gcd(m, n)


Step 1 Find the prime factors of m.
Step 2 Find the prime factors of n.
Step 3 Identify all the common factors in the two prime expansions found in
Step 1 and Step 2. (If p is a common factor occurring Pm and Pn times
in m and n, respectively, it should be repeated min{pm, p,) times.)
Step 4 Compute the product of all the common factors and return it as the
greatest common divisor of the numbers given.

Thus, for the numbers 60 and 24, we get


'7
60=2·2·3·5
24=2·2·2·3
gcd(60, 24) = 2. 2. 3 = 12.
6 Introduction

Nostalgia for the days when we learned this method should not prevent us
from noting that the last procedure is much more complex and slower than Euclid's
algorithm. (We will discuss methods for finding and comparing running times of
algorithms in the next chapter.) In addition to inferior efficiency, the middle-school
procedure does not qualify, in the form presented, as a legitimate algorithm. Why?
Because the prime factorization steps are not defined unambiguously: they require
a list of prime numbers, and I strongly suspect that your middle-school teacher
did not explain how to obtain such a list. You undoubtedly agree that this is not
a matter of unnecessary nitpicking. Unless this issue is resolved, we cannot, say,
write a program implementing this procedure. (Incidentally, Step 3 is also not
defined clearly enough. Its ambiguity is much easier to rectify than that of the
factorization steps, however. How would you find common elements in two sorted
lists?)
So let us introduce a simple algorithm for generating consecutive primes
not exceeding any given integer n. It was probably invented in ancient Greece
and is known as the sieve of Eratosthenes (ca. 200 B.C.). The algorithm starts by
initializing a list of prime candidates with consecutive integers from 2 ton. Then,
on the first iteration of the algorithm, it eliminates from the list all multiples of
2, i.e., 4, 6, and so on. Then it moves to the next item on the list, which is 3,
and eliminates its multiples. (In this straightforward version, there is an overhead
because some numbers, such as 6, are eliminated more than once.) No pass for
number 4 is needed: since 4 itself and all its multiples are also multiples of 2, they
were already eliminated on a previous pass. (By similar reasoning, we need not
consider multiples of any eliminated number.) The next remaining number on the
list, which is used on the third pass, is 5. The algorithm continues in this fashion
until no more numbers can be eliminated from the list. The remaining integers of
the list are the primes needed.
As an example, consider the application of the algorithm to finding the list of
primes not exceeding n = 25:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
2 3 5 7 9 11 13 15 17 19 21 23 25
2 3 5 7 11 13 17 19 23 25
2 3 5 7 11 13 17 19 23

For this example, no more passes are needed because they would eliminate num-
bers already eliminated on previous iterations of the algorithm. The remaining
numbers on the list are the consecutive primes less than or equal to 25.
In general, what is the largest number p whose multiples can still remain on
the list? Before we answer this question, let us first note that if p is a number
whose multiples are being eliminated on the current pass, then the first multiple
we should consider is p · p because all its smaller multiples 2p, ... , (p- l)p have
been eliminated on earlier passes through the list. This observation helps to avoid
1.1 What is an Algorithm? 7

eliminating the same number more than once. Obviously, p · p should not be
greater than n, and therefore p cannot exceed ,jn rounded down (denoted ,jn l J
using the so-called floor function). We assume in the following pseudocode that
l J;
there is a function available for computing ,jn alternatively, we could check
the inequality p · p S n as the loop continuation condition there.

ALGORITHM Sieve(n)
//Implements the sieve of Eratosthenes
//Input: An integer n ": 2
//Output: Array L of all prime numbers less than or equal ton
for p-<-- 2 ton do A[p]-<- p
l
for p -<-- 2 to ,Jnj do //see note before pseudocode
if A[p] i' 0 II p hasn't been eliminated on previous passes
j-<-P*P
while j S n do
A[j] -<-- 0 //mark element as eliminated
j-<-j+p
//copy the remaining elements of A to array L of the primes
i-<--0
forp-<-2tondo
ifA[p]i'O
L[i]+- A[p]
i-<-i+1
return L

So now we can incorporate the sieve of Eratosthenes into the middle-school


procedure to get a legitimate algorithm for computing the greatest common di-
visor of two positive integers. Note that special care needs to be exercised if one
or both input numbers are equal to 1: because mathematicians do not consider
1 to be a prime number, strictly speaking, the method does not work for such
inputs.
Before we leave this section, one more comment is in order. The examples
considered in this section notwithstanding, the majority of algorithms in use
today-even those that are implemented as computer programs-do not deal
with mathematical problems. Look around for algorithms helping us through our
daily routines, both professional and personal. May this ubiquity of algorithms in
today's world strengthen your resolve to learn more about these fascinating
engines of the information age.
8 Introduction

-----Exercises 1.1
1. Do some research on al-Khorezmi (also al-Khwarizmi), the man from whose
name the word "algorithm" is derived. 1n particular, you should learn what
the origins of the words "algorithm)' and "algebra" have in common.
2. Given that the official purpose of the U.S. patent system is the promotion
of the "useful arts," do you think algorithms are patentable in this country?
Should they be?
3. a. Write down driving directions for going from your school to your home
with the precision required by an algorithm.
b. Write down a recipe for cooking your favorite dish with the precision
required by an algorithm.
4. Design an algorithm for computing LftJ for any positive integer n. Besides
assignment and comparison, your algorithm may only use the four basic
arithmetical operations.
:I
5. a. Find gcd(31415, 14142) by applying Euclid's algorithm.
b. Estimate how many times faster it will be to find gcd(31415, 14142) by
Euclid's algorithm compared with the algorithm based on checking con-
secutive integers from min{m, n) down to gcd(m, n).
6. Prove the equality gcd(m, n) = gcd(n, m mod n) for every pair of positive
integers m and n.
7. What does Euclid's algorithm do for a pair of numbers in which the first
number is smaller than the second one? What is the largest number of times
this can happen during the algorithm's execution on such an input?
8. a. What is the smallest number of divisions made by Euclid's algorithm
among all inputs 1 ::= m, n ::= 10?
b. What is the largest number of divisions made by Euclid's algorithm among
all inputs 1 ::= m, n ::= 10?
9. a. Euclid's algorithm, as presented in Euclid's treatise, uses subtractions
rather than integer divisions. Write a pseudocode for this version of Eu-
clid's algorithm.
b. Euclid's game (see [Bog]) starts with two unequal positive numbers on the
board. Two players move in turn. On each move, a player has to write on
the board a positive number equal to the difference oftwo numbers already
on the board; this number must be new, i.e., different from all the numbers
already on the board. The player who cannot move loses the game. Should
you choose to move first or second in this game?
10. The extended Euclid's algorithm determines not only the greatest common
divisor d of two positive integers m and n but also integers (not necessarily
positive) x andy, such that mx + ny =d.
1.2 Fundamentals of Algorithmic Problem Solving 9

a. Look up a description of the extended Euclid's algorithm (see, e.g., [Knui],


p. 13) and implement it in the language of your choice.
b. Modify your program for finding integer solutions to the Diophantine
equation ax +by= c with any set of integer coefficients a, b, and c.
11. Locker doors There are n lockers in a hallway, numbered sequentially from
1 to n. Initially all the locker doors are closed. You make 11 passes by the
lockers, each time starting with locker #1. On the ith pass, i = 1, 2, ... , 11, you
toggle the door of every ith locker: if the door is closed, you open it; if it is
open, you close it. For example, after the first pass every door is open; on the
second pass you only toggle the even-numbered lockers (#2, #4, ... ) so that
after the second pass the even doors are closed and the odd ones are open;
the third time through, you close the door of locker #3 (opened from the first
pass), open the door of locker #6 (closed from the second pass), and so on.
After the last pass, which locker doors are open and which are closed? How
many of them are open?

1.2 Fundamentals of Algorithmic Problem Solving


Let us start by reiterating an important point made in the introduction to this
chapter:
We can consider algorithms to be procedural solutions to problems.
These solutions are not answers but specific instructions for getting answers. It is
this emphasis on precisely defmed constructive procedures that makes computer
science distinct from other disciplines. In particular, this distinguishes it from the-
oretical mathematics whose practitioners are typically satisfied with just proving
the existence of a solution to a problem and, possibly, investigating the solution's
properties.
We now list and briefly discuss a sequence of steps one typically goes through
in designing and analyzing an algorithm (Figure 1.2).

Understanding the Problem


From a practical perspective, the frrst thing you need to do before designing an
algorithm is to understand completely the problem given. Read the problem's
description carefully and ask questions if you have any doubts about the problem,
do a few small examples by hand, think about special cases, and ask questions
again if needed.
There are a few types of problems that arise in computing applications quite
often. We review them in the next section. If the problem in question is one of
them, you might be able to use a known algorithm for solving it. Of course, it
helps to understand how such an algorithm works and to know its strengths and
r 10 Introduction

Understand the problem

Decide on:
computational means,
exact vs. approximate solving,
data structure(s),
algorithm design technique

Design an algorithm

Prove correctness

Analyze the algorithm

Code the algorithm

FIGURE 1.2 Algorithm design and analysis process

weaknesses, especially if you have to choose among several available algorithms.


But often, you will not find a readily available algorithm and will have to design
your own. The sequence of steps outlined in this section should help you in this
exciting but not always easy task. .
An input to an algorithm specifies an ';nstanc~ of the problem the algorithm
solves. It is very important to specify exactly the range of instances the algorithm
needs to handle. (As an example, recall the variations in the range of instances for
the three greatest common divisor algorithms discussed in the previous section.)
If you fail to do this, your algorithm may work correctly for a majority of inputs
but crash on some "boundary" value.,t-gemember that a correct algorithm is not
one that works most of the time, but 'One that works correctly for alllegitiJ!!aty
inputs.
Do not skimp on this first step of the algorithmic problem-solving process; if
you do, you will run the risk of unnecessary rework.
1.2 Fundamentals of Algorithmic Problem Solving 11

Ascertaining the Capabilities of a Computational Device


Once you completely understand a problem. you need to ascertain the capabilities
of the computational device the algorithm is intended for. The vast majority of
algorithms in use today are still destined to be programmed for a computer closely
resembling the von Neumann machine-a computer architecture outlined by
the prominent Hungarian-American mathematician John von Neumann (1903-
1957), in collaboration with A. Burks and H. Goldstine, in 1946. The essence of
this architecture is captured by the so-called random-access machine (RAM).
Its central assumption is that instructions are executed one after another, one
operation at a time. Accordingly, algorithms designed to be executed on such
machines are called sequential algorithms.
The central assumption of the RAM model does not hold for some newer
computers that can execute operations concurrently, i.e., in parallel. Algorithms
that take advantage of this capability are called parallel algorithms. Still, studying
the classic techniques for design and analysis of algorithms under the RAM model
remains the cornerstone of algorithmics for the foreseeable future.
Should you worry about the speed and amount of memory of a computer
at your disposal? If you are designing an algorithm as a scientific exercise, the
answer is a qualified no. As you will see in Section 2.1, most computer scientists
prefer to study algorithms in terms independent of specification parameters for
a particular computer. If you are designing an algorithm as a practical tool, the
answer may depend on a problem you need to solve. Even "slow" computers of
today are almost unimaginably fast. Consequently, in many situations, you need
not worry about a computer being too slow for the task. There are important
problems, however, that are very complex by their nature, have to process huge
volumes of data, or deal with applications where time is critical. In such situations,
it is imperative to be aware of the speed and memory available on a particular
computer system.

Choosing between Exact and Approximate Problem Solving


The next principal decision is to choose between solving the problem exactly or
solving it approximately. In the former case, an algorithm is called an exact algo-
rithm; in the latter case, an algorithm is called an approximation algorithm. Why
would one opt for an approximation algorithm? First, there are important prob-
lems that simply cannot be solved exactly for most of their instances; examples
include extracting square roots, solving nonlinear equations, and evaluating def-
inite integrals. Second, available algorithms for solving a problem exactly can be
unacceptably slow because of the problem's intrinsic complexity. Tbis happens, in
particular, for many problems involving a very large number of choices; you will
see examples of such difficult problems in Chapters 3, 11, and 12. Third, an ap-
proximation algorithm can be a part of a more sophisticated algorithm that solves
a problem exactly.
12 Introduction l
Deciding on Appropriate Data Structures
Some algorithms do not demand any ingenuity in representing their inputs. But
l
others are, in fact, predicated on ingenious data structures. In addition, some
of the algorithm design techniques we shall discuss in Chapters 6 and 7 depend
intimately on structuring or restructuring data specifying a problem's instance.
Many years ago, an influential textbook proclaimed the fundamental importance
of both algorithms and data structures for computer programming by its very title:
Algorithms + Data Structures ~ Programs [Wir76]. In the new world of object-
oriented programming, data structures remain crucially important for both design
and analysis of algorithms. We review basic data structures in Section 1.4.

Algorithm Design Techniques


Now, with all the components of the algorithmic problem solving in place, how do
you design an algorithm to solve a given problem? This is the main question this
book seeks to answer by teaching you several general design techniques.
What is an algorithm design technique?
An algorithm design technique (or "strategy" or "paradigm") is a general
approach to solving problems algorithmically that is applicable to a variety
of problems from different areas of computing.
Check this book's table of contents and you will see that a majority of its
chapters are devoted to individual design techniques. They distill a few key ideas
that have proven to be useful in designing algorithms. Learning these techniques
is of utmost importance for the following reasons.
First, they provide guidance for designing algorithms for new problems, i.e.,
problems for which there is no known satisfactory algorithm. Therefore-to use
the language of a famous proverb-learning such techniques is akin to learning
to fish as opposed to being given a fish caught by somebody else. It is not true, of
course, that each of these general techniques will be necessarily applicable to every
problem you may encounter. But taken together, they do constitute a powerful
collection of tools that you will find quite handy in your studies and work.
Second, algorithms are the cornerstone of computer science. Every science is
interested in classifying its principal subject, and computer science is no exception.
Algorithm design techniques make it possible to classify algorithms according
to an underlying design idea; therefore, they can serve as a natural way to both
categorize and study algorithms.

Methods of Specifying an Algorithm


Once you have designed an algorithm, you need to specify it in some fashion. In
Section 1.1, to give you an example, we described Euclid's algorithm in words (in
a free and also a step-by-step form) and in pseudocode. These are the two options
that are most widely used nowadays for specifying algorithms.
1.2 Fundamentals of Algorithmic Problem Solving 13

Using a natural language has an obvious appeal; however, the inherent ambi-
guity of any natural language makes a succinct and clear description of algorithms
surprisingly difficult. Nevertheless, being able to do this is an important skill that
you should strive to develop in the process of learning algorithms.
A pseudocode is a mixture of a natural language and programming language-
like constructs. A pseudocode is usually more precise than a natural language, and
its usage often yields more succinct algorithm descriptions. Surprisingly, computer
scientists have never agreed on a single form of pseudocode, leaving textbook
authors to design their own "dialects." Fortunately, these dialects are so close to
each other that anyone familiar with a modern programming language should be
able to understand them all.
This book's dialect was selected to cause minimal difficulty for a reader. For
the sake of simplicity, we omit declarations of variables and use indentation to
show the scope of such statements as for, if, and while. As you saw in the previous
section, we use an arrow <-- for the assignment operation and two slashes I I for
comments.
In the earlier days of computing, the dominant vehicle for specifying algo-
rithms was a flowchart, a method of expressing an algorithm by a collection of
connected geometric shapes containing descriptions of the algorithm's steps. This
representation technique has proved to be inconvenient for all but very simple
algorithms; nowadays, it can be found only in old algorithm books.
The state of the art of computing has not yet reached a point where an
algorithm's description-whether in a natural language or a pseudocode-can be
fed into an electronic computer directly. Instead, it needs to be converted into a
computer program written in a particular computer language. We can look at such
a program as yet another way of specifying the algorithm, although it is preferable
to consider it as the algorithm's implementation.

Proving an Algorithm's Correctness


Once an algorithm has been specified, you have to prove its correctness. That is,
you have to prove that the algorithm yields a required result for every legitimate
input in a finite amount of time. For example, correctness of Euclid's algorithm
for computing the greatest common divisor stems from correctness of the equality
gcd(m, n) = gcd(n, m mod n) (which, in turn, needs a proof; see Problem 6 in
Exercises 1.1), the simple observation that the second number gets smaller on
every iteration of the algorithm, and the fact that the algorithm stops when the
second number becomes 0.
For some algorithms, a proof of correctness is quite easy; for others, it can
be quite complex. A common technique for proving correctness is to use mathe-
matical induction because an algorithm's iterations provide a natural sequence of
steps needed for such proofs. It might be worth mentioning that although tracing
the algorithm's performance for a few specific inputs can be a very worthwhile
activity, it cannot prove the algorithm's correctness conclusively. But in order to
l

14 Introduction

show that an algorithm is incorrect, you need just one instance of its input for
which the algorithm fails. If the algorithm is found to be incorrect, you need to ei-
ther redesign it under the same decisions regarding the data structures, the design
technique, and so on, or, in a more dramatic reversal, to reconsider one or more
of those decisions (see Figure 1.2).
The notion of correctness for approximation algorithms is less straightforward
than it is for exact algorithms. For an approximation algorithm, we usually would
like to be able to show that the error produced by the algorithm does not exceed
a predefined limit. You can find examples of such investigations in Chapter 12.

Analyzing an Algorithm
We usually want our algorithms to possess several qualities. After correctness, by
far the most important is efficiency. In fact, there are two kinds of algorithm effi-
ciency: time efficiency and space efficiency. Time ~fficiency indicates how fast the
algorithm runs; space efficiency indicates how much extra memory the algorithm
needs. A general framework and specific techniques for analyzing an algorithm's
efficiency appear in Chapter 2.
Another desirable characteristic of an algorithm is simplicity. Unlike effi-
ciency, which can be precisely defined and investigated with mathematical rigor,
simplicity, like beauty, is to a considerable degree in the eye of the beholder. For
example, most people would agree that Euclid's algorithm is simpler than the
middle-school procedure for computing gcd(m, n), but it is not clear whether Eu-
clid's algorithm is simpler than the consecutive integer checking algorithm. Still,
simplicity is an important algorithm characteristic to strive for. Why? Because sim-
pler algorithms are easier to understand and easier to program; consequently, the
resulting programs usually contain fewer bugs. There is also the undeniable aes-
thetic appeal of simplicity. Sometimes simpler algorithms are also more efficient
than more complicated alternatives. Unfortunately, it is not always true, in which
case a judicious compromise needs to be made.
Yet another desirable characteristic of an algorithm is generality. There are,
in fact, two issues here: generality of the problem the algorithm solves and the
range of inputs it accepts. On the first issue, note that it is sometimes easier to
design an algorithm for a problem posed in more general terms. Consider, for
example, the problem of determining whether two integers are relatively prime,
i.e., whether their only common divisor is equal to 1. It is easier to design an
algorithm for a more general problem of computing the greatest common divisor
of two integers and, to solve the former problem, check whether the gcd is 1 or
not. There are situations, however, where designing a more general algorithm is
unnecessary or difficult or even impossible. For example, it is unnecessary to sort
a list of n numbers to find its median, which is its rn/21 th smallest element. To give
another example, the standard formula for roots of a quadratic equation cannot
be generalized to handle polynomials of arbitrary degrees.
1.2 Fundamentals of Algorithmic Problem Solving 15

As to the range of inputs, your main concern should be designing an algorithm


that can handle a range of inputs that is natural for the problem at hand. For exam-
ple, excluding integers equal to 1 as possible inputs for a greatest common divisor
algorithm would be quite unnatural. On the other hand, although the standard
formula for the roots of a quadratic equation holds for complex coefficients, we
would normally not implement it on this level of generality unless this capability
is explicitly required.
If you are not satisfied with the algorithm's efficiency, simplicity, or general-
ity, you must return to the drawing board aud redesign the algorithm. In fact,
even if your evaluation is positive, it is still worth searching for other algorithmic
solutions. Recall the three different algorithms in the previous section for com-
puting the greatest common divisor; generally, you should not expect to get the
best algorithm on the first try. At the very least, you should try to fine-tunc the
algorithm you already have. For example, we made several improvements in our
implementation of the sieve of Eratosthenes compared with its initial outline in
Section 1.1. (Can you identify them?) You will do well if you keep in mind the
following observation of Antoine de Saint-Exupery, the French writer, pilot, and
aircraft designer: "A designer knows he has arrived at perfection not when there
is no longer anything to add, but when there is no longer anything to take away." 1

Coding an Algorithm
Most algorithms are destined to be ultimately implemented as computer pro-
grams. Programming an algorithm presents both a peril and an opportunity. The
peril lies in the possibility of making the transition from an algorithm to a pro-
gram either incorrectly or very inefficiently. Some influential computer scientists
strongly believe that unless the correctness of a computer program is proven with
full mathematical rigor, the program cannot be considered correct. They have de-
veloped special techniques for doing such proofs (see [Gri81]), but the power of
these techniques of formal verification is limited so far to very small programs.
As a practical matter, the validity of programs is still established by testing. Test-
ing of computer programs is an art rather than a science, but that does not mean
that there is nothing in it to learn. Look up books devoted to testing and debug-
ging; even more important, test and debug your program thoroughly whenever
you implement an algorithm.
Also note that throughout the book, we assume that inputs to algorithms fall
within their specified ranges and hence require no verification. When implement-
ing algorithms as programs to be used in actual applications, you should provide
such verifications.

1. I found this call for design simplicity in an essay collection by Jon Bentley [BenOO]; the essays deal
with a variety of issues in algorithm design and implementation, and arc justifiably titled Programming
Pearls. I wholeheartedly recommend writings of both Jon Bentley and Antoine de Saint-Exup6ry.
r I,
.

!'!
'

16 Introduction

Of course, implementing an algorithm correctly is necessary but not sufficient:


you would not like to diminish your algorithm's power by an inefficient implemen-
tation. Modern compilers do provide a certain safety net in this regard, especially
when they are used in their code optimization mode. Still, you need to be aware
of such standard tricks as computing a loop's invariant (an expression that does
not change its value) outside the loop, collecting common subexpressions, replac-
ing expensive operations by cheap ones, and so on. (See [Ker99] and [BenOO] for
a good discussion of code tuning and other issues related to algorithm program-
ming.) Typically, such improvements can speed up a program only by a constant
factor, whereas a better algorithm can make a difference in running time by orders
of magnitude. But once an algorithm is selected, a 10-50% speedup may be worth
an effort.
A working program provides an additional opportunity in allowing an em-
pirical analysis of the underlying algorithm. The analysis is based on timing the
program on several inputs and then analyzing the results obtained. We discuss the
advantages and disadvantages of this approach to analyzing algorithms in Sec-
tion 2.6.
In conclusion, let us emphasize again the main lesson of the process depicted
in Figure 1.2:
As a rule, a good algorithm is a result of repeated effort and rework.
Even if you have been fortunate enough to get an algorithmic idea that seems
perfect, you should still try to see whether it can he improved.
Actually, this is good news since it makes the ultimate result so much more
enjoyable. (Yes, I did think of naming this hook The Joy of Algorithms.) On the
other hand, how does one know when to stop? In the real world, more often than
not the project's schedule or the patience of your boss will stop you. And so it
should be: perfection is expensive and in fact not always called for. Designing
an algorithm is an engineering-like activity that calls for compromises among
competing goals under the constraints of available resources, with the designer's
time being one of the resources.
In the academic world, the question leads to an interesting but usually difficult
investigation of an algorithm's optimality. Actually, this question is not about the
efficiency of an algorithm but about the complexity of the problem it solves: what
is the minimum amount of effort any algorithm will need to exert to solve the
problem in question? For some problems, the answer to this question is known.
For example, any algorithm that sorts an array by comparing values of its elements
needs about n log2 n comparisons for some arrays of size n (see Section 11.2).
I
'.
I
But for many seemingly easy problems, such as matrix multiplication, computer
scientists do not yet have a final answer.
~
Another important issue of algorithmic problem solving is the question of E
I
1:
whether or not every problem can be solved by an algorithm. We are not talking
here about problems that do not have a solution, such as finding real roots of i
l
1-
i

il j
!
I
1.2 Fundamentals of Algorithmic Problem Solving 17

a quadratic equation with a negative discriminant. For such cases, an output


indicating that the problem does not have a solution is all we can and should
expect from an algorithm. Nor are we talking about ambiguously stated problems.
Even some unambiguous problems that must have a simple yes or no answer are
"undecidable," i.e., unsolvable by any algorithm. An important example of such
a problem appears in Section 11.3. Fortunately, a vast majority of problems in
practical computing can be solved by an algorithm.
Before leaving this section, let us be sure that you do not have the mis-
conception-possibly caused by the somewhat mechanical nature of the diagram
of Figure 1.2-that designing an algorithm is a dull activity. There is nothing
further from the truth: inventing (or discovering?) algorithms is a very creative
and rewarding process. This book is designed to convince you that this is the case.

-----Exercises 1 . 2 - - - - - - - - - - - - - - -
1. Old World puzzle A peasant finds himself on a riverbank with a wolf, a goat,
and a head of cabbage. He needs to transport all three to the other side of the
river in his boat. However, the boat has room for only the peasant himself
and one other item (either the wolf, the goat, or the cabbage). In his absence,
the wolf would eat the goat, and the goat would eat the cabbage. Solve this
problem for the peasant or prove it has no solution. (Note: The peasant is a
vegetarian but does not like cabbage and hence can eat neither the goat nor
the cabbage to help him solve the problem. And it goes without saying that
the wolf is a protected species.)
2. New World puzzle There are four people who want to cross a bridge; they
all begin on the same side. You have 17 minutes to get them all across to
the other side. It is night, and they have one flashlight. A maximum of two
people can cross the bridge at one time. Any party that crosses, either one
or two people, must have the flashlight with them. The flashlight must be
walked back and forth; it cannot be thrown, for example. Person 1 takes 1
minute to cross the bridge, person 2 takes 2 minutes, person 3 takes 5 minutes,
and person 4 takes 10 minutes. A pair must walk together at the rate of the
slower person's pace. For example, if person 1 and person 4 walk across first,
10 minutes have elapsed when they get to the other side of the bridge. If person
4 returns the flashlight, a total of 20 minutes have passed and you have failed
the mission. (Note: According to a rumor on the Internet, interviewers at a
well-known software company located near Seattle have given this problem
to interviewees.)
3. Which of the following formulas can be considered an algorithm for comput-
ing the area of a triangle whose side lengths are given positive numbers a, b,
and c?
18 Introduction

a. S = ,jp(p- a)(p- b)(p- c), where p =(a+ b + c)/2


b. S = 1hc sin A, where A is the angle between sides band c
c. S = iaha, where ha is the height to base a
4. Write a pseudocode for an algorithm for finding real roots of equation ax 2 +
bx + c = 0 for arbitrary real coefficients a, b, and c. (You may assume the
availability of the square root function sqrt(x).)
5. Describe the standard algorithm for finding the binary representation of a
positive decimal integer
a. in English.
b. in a pseudocode.
6. Describe the algorithm used by your favorite ATM machine in dispensing
cash. (You may give your description in either English or a pseudocode,
whichever you find more convenient.)
7. a. Can the problem of computing the number n be solved exactly?
b. How many instances does this problem have?
c. Look up an algorithm for this problem on the World Wide Web.
8. Give an example of a problem other than computing the greatest common
divisor for which you know more than one algorithm. Which of them is
simpler? Which is more efficient?
9. Consider the following algorithm for finding the distance between the two
closest elements in an array of numbers.

ALGORITHM MinDistance(A[O .. n - 1])


//Input: Array A[O .. n- 1] of numbers
//Output: Minimum distance between two of its elements
ii dmin +-- oo
i
fori <--0ton-1do
for} <--0ton-1do
if i I J and IA[i]- A[J]I < dmin
dmin <-- IA[i]- A[J]I
return dmin

Make as many improvements as you can in this algorithmic solution to the


problem. (If you need to, you may change the algorithm altogether; if not,
improve the implementation given.)
10. One of the most influential books on problem solving, titled How to Solve
It [Pol57], was written by the Hungarian-American mathematician George
Polya (1887-1985). Polya summarized his ideas in a four-point summary. Find
Exploring the Variety of Random
Documents with Different Content
returns. First of all, it is clear that meeting-houses which have
remained in existence half a century must be buildings of some
importance. Dissenting places of worship are of two classes—those
which have regular congregations and a regular ministry attached to
them, and those which are merely temporary preaching stations.
The number of these latter will surprise the reader. Mr. Edward
Baines, in his evidence before the Churchrates Committee, estimated
that no fewer than 7,360 of the 19,000 which he supposed belonged
to “the three denominations” were of this description. The total
number of mere preaching stations, however, may be easily
ascertained. It may be safely assumed that all places which have a
regular ministry are opened both on Sunday mornings and on
Sunday afternoons or evenings. The total number of this class in
1851 was only 10,583; so that each would represent an average of
462 sittings. Now, as the number of Dissenting places of worship
which date back to 1801 cannot be less, even if calculated on Mr.
Mann’s principle, than 3900, the number of sittings in that year must
have been upwards of 1,800,000. But it would be a great fallacy to
suppose that even first-class Dissenting congregations are exempt
from the tendency to decay and disappear. If Nottingham may be
taken as a fair example, it would seem that not two-thirds of the
regularly organised congregations existing in 1801 survive to this
day. The total number of sittings at the commencement of the
present century would thus be at least 2,700,000.
The matter does not, however, rest even here. These estimates are
purely conjectural; but since the writer first turned his attention to
the subject, a valuable piece of positive evidence has fallen in his
way. It is a Parliamentary return obtained by Mr. Bright last year,
which professes to show the number of places of worship licensed
under the Toleration Act. It is very imperfect in its earlier tables, but
those since 1800 seem to be tolerably complete. Comparing the
number of places licensed during each of the last five decennial
periods with the number of existing buildings returned to Mr. Mann
as opened in each, we get the following remarkable results:—[19]
Ten years Places Still in Still in existence (per
ending licensed. existence. cent.)
1810 5,460 1,169 21
1820 10,161 1,905 18
1830 10,585 2,865 27
1840 7,422 4,199 56
1850 5,810 4,397 75
39,438 14,535

This is a comparison which cannot fail to startle the editor of the


Patriot, and to shake the nerves of the Society for the Liberation of
Religion. It proves beyond the possibility of cavil that the enormous
and constantly increasing growth which Mr. Mann’s tables assign to
modern Dissent is “a mockery, a delusion, and a snare.” It shows,
moreover (which is the matter more immediately in hand), that
barely two in seven (21/75ths) of the Dissenting places of worship
which were in existence in 1801, are still remaining. The number of
such places was not 3,701, as Mr. Mann states, but between 13,000
and 14,000; and the estimate of sittings first made, after every
conceivable allowance for increase of average capacity, and other
sources of error, is thus greatly under rather than over the mark.
The Dissenting increase may, therefore, be safely taken at 2,758,309
sittings instead of 4,013,408; and if it be distributed according to the
proportion of places licensed, matters will stand thus:—

Ten years ending 1811 381,875


,, „ 1821 710,664
,, „ 1831 740,319
,, „ 1841 519,097
,, „ 1851 406,354
If it be objected that the average capacity of Dissenting buildings
has increased of late years, there are two answers—first, there is no
evidence of such increase to any material extent; and, secondly, that
there is an antagonistic influence at work, which would
counterbalance such increase if it existed. It must be clear that the
number of “causes” which annually collapse becomes greater in the
same ratio as the congregations themselves increase. Thus, almost
the same number of places were licensed in the ten years ending
1810 as in the same period ending 1850; but the number of places
discontinued out of 13,000 would obviously be less than the number
discontinued out of, say 18,500; so that unless the new Dissenting
meeting-houses are larger nowadays than was formerly the case,
the amount of sittings attributed to the latter periods is too large,
rather than too small.
We have now materials for the reconstruction of our table:—

Population. Church Dissenting Total


Sittings. Sittings. Sittings.
1801 8,892,536 3,024,615 2,136,339 5,160,954
Subsequent decennial increase:—
1811 1,271,720 55,250 381,875 437,125
1821 1,835,930 96,900 710,664 807,564
1831 1,896,561 276,250 740,319 1,016,569
1841 2,017,351 667,250 519,097 1,186,347
1851 2,013,161 1,197,650 406,354 1,604,004
Total 9,035,073 2,293,300 2,758,309 5,051,609
Increase
Total 17,927,609 5,317,915 4,894,648 10,212,583

The number of sittings per thousand of the population was, at the


different periods, as follows:—
according to the above table. According to Mr. Mann’s Table.
Church. Dissent. Church. Dissent.
1801 340 240 482 99
1811 303 247 424 120
1821 264 269 363 145
1831 248 285 323 181
1841 258 282 300 238
1851 297 273 297 273

Thus it will be seen that every inference drawn from Mr. Mann’s
tables has proved false.
Dissent has not, during the half century, supplied four times as much
new accommodation as the Church—if it has supplied any more at
all, the excess does not amount to a fourth.
Dissent has not, during the last 20 years, supplied three times as
much accommodation as the Church—it has barely supplied half as
much.
Dissent is not advancing at a pace twice as rapid as the Church; on
the contrary, the Church is advancing at nearly three times the
speed of Dissent.
Dissent has not improved its position, and the Church has not lost
position since 1831; on the contrary, the Church has gained, and
Dissent has lost, ground since that year.
Finally, as churches, save only where there is an excess of
accommodation as compared with the population, are at least as
well attended as dissenting places of worship, the charge of
comparative inefficiency which has been so rashly brought against
the clergy proves to be utterly without foundation.
Here, then, the present inquiry might be brought to a close; and yet
it would be palpably unfair to the Church to rest the case upon a
mere comparison of the additional sittings supplied by her rivals and
by herself. A new church, generally speaking, means a very
different thing from a new meeting-house. It means a substantially
built and even highly-decorative structure, the freehold of which is
the property of the community to which it belongs; it means decent
and becoming furniture for the performance of divine service;
provision for a properly educated minister in perpetuity; service
performed at least twice every Sunday, or even twice every day; a
house for the resident minister; a day-school, or rather a group of
day-schools; and a host of other benevolent and educational
agencies. If the establishment of the day-school be taken as a
criterion how far the parochial machinery has been completed, the
following table from the report of the Educational Census will be
instructive:—
Day Schools Supported by Religious Bodies.

Founded before Church Schools. Dissenting Schools. Total.


1801 709 57 766
1811 350 60 410
1821 756 123 879
1831 897 124 1,021
1841 2,002 415 2,417
1855 3,448 1,156 4,604
Not stated 409 89 498
8,571 2,024 10,595

What, on the other hand, is the status of a majority of the 20,390


buildings returned to the Census office as “chapels” may be guessed
from the fact that the total number of professional dissenting
ministers of every description in 1851 was only 8,658.
A very tangible mode of settling the question which body has done
most to evangelise the people would be to inquire how much each
has spent? The “Society for the Liberation of Religion,” in a tract
they have put forth, grounded on the Census report, states that the
achievements of voluntaryism during the half century have been
“astonishing.” On the authority of Mr. Edward Baines, they assume
that of the 16,689 dissenting chapels opened since 1801, “only”
10,000 are separate buildings, and that the cost of each has been
“but” £1,500—in other words, that dissenters have spent
£15,000,000 on their meeting-houses during the last fifty years!
That would, indeed, be an “astonishing” result, but it is not half so
surprising as the perfervid imagination which dictated the
calculation. In point of fact, it is equivalent to saying that the
dissenters have provided three millions of permanent sittings, at the
rate of five pounds per sitting. The real truth, however, is that they
have not supplied more than two millions and three quarters of new
sittings of any kind; and when it is considered in how many cases
opening a new meeting-house means hiring a room or building, in
the popular phrase, “on tick”; when it is further borne in mind that
the average cost of churches is not above £5 or £6 per sitting, it will
be admitted that five or six millions sterling would be a remarkably
liberal sum to put down for the amount really raised by dissenters
for the purpose of self-extension during the half century. On the
other hand, the sum which must have been spent on churches
cannot have been less than ten or twelve millions—of which one-half
has been raised during the ten years 1841–51. The expenditure on
church extension at the present moment is at least five times as
great as that of all the dissenters put together.
The votaries of Iscariotism, or the “cheap and nasty” in religion, will
perhaps turn this fact to account, and abuse Churchmen for
lavishing such large sums of money on a few buildings, while there
is so much spiritual destitution calling for relief. They will perhaps
say, “Look what an amount of spiritual agency the Dissenters bring
to bear for half the sum you expend; and, after all, the Dissenters
‘get more out of’ their buildings than Churchmen.” At first sight, Mr.
Mann’s tables appear to justify this assertion; but here, as in every
other respect, they only mislead. According to Table 16 there were
on the Census Sunday 190 services in every 100 dissenting places of
worship; whereas, there were only 171 in the same number of
churches. But if this table be any criterion, it would appear that the
machinery of Dissent is, by comparison, more efficient in the rural
districts than in the towns; for while the Non-conformists opened
their town buildings on the average 2.10 times, and the Churchmen
2.06 times, they opened their country buildings 1.84 times and the
Churchmen only 1.64 times. Yet it must be obvious that the
proportion of country congregations which possess a regular ministry
must be very small, the greater part of the 8,658 professional
Dissenting preachers being required for the towns. The fact is, the
majority of country meeting-houses are served by non-professional
persons. As soon as the morning service is over in the towns, a
swarm of “Spiritual Bashi-Bazooks,” issue forth, who, for the rest of
the day, play the more ambitious, if not more edifying, rôle of
preacher. The sort of congregations to which they minister may be
gathered from a comparison of the number of meeting-houses and
the number of sittings open at the different periods of the day:—

Meeting Houses (open). Sittings (open).


Morning 11,875 3,645,875
Afternoon 11,338 2,506,116
Evening 15,619 3,983,725

So that in the afternoon, with only 537 fewer places open, the
number of sittings was 1,139,759 fewer than in the morning. In the
evening (when, of course, all the more important buildings which
were open in the morning were again accessible to the public) the
exertions of 3,744 additional preachers, nearly a third more, only
rendered available 337,850 additional sittings, or about one-eleventh
more; and they attracted only 97,668 additional hearers, an increase
of less than one in twenty-one! It may, perhaps, be allowable to
doubt whether the labours of non-resident, non-professional
preachers can be attended with any results worth speaking of; but,
at all events, their irregular ministrations can have no real bearing
on the question whether the regular meeting-houses are used more
or less frequently than the churches. Obviously, the fairest way
would be to inquire which class of buildings are opened the oftener
throughout the whole week; and, in that case, there is no doubt that
the comparison would show greatly in favour of the churches. If,
however, we must confine ourselves to Sunday, the proper question
to ask would be—in how many cases there is a service before, and
another after, noon? The answer, according to Table 16, would be
as follows:—

Churches. Meeting Houses.


(per cent.) (per cent.)
Town districts 85 75
Rural ditto 62 43
Whole country 66 51

If the investigation could be limited to the new accommodation, the


result would strikingly show that the extra outlay on the churches
had in no sense been thrown away.
After all, the number of sittings a religious body can open in the
morning is the real test of its strength. Amongst persons of every
denomination there is a strong feeling that they ought to frequent
their own place of worship in the morning, but in the after part of
the day many persons do not consider themselves called upon to
attend again, or they feel themselves at liberty to visit other
churches or meetings. In short, to speak technically, the morning
service is looked upon by everybody as a service of “obligation,”
while all the rest are regarded as mere services of “devotion.” Now,
of the 5,317,915 sittings belonging to the Church, no fewer than
4,852,645 were actually available on the Census morning. The
remaining 465,270 were almost exclusively in the country, where
one clergyman has still often to serve more than one parish or
chapelry. Cases of this kind have of late years been much
diminished, owing to the operation of the Pluralities Act, and still
more in consequence of the increased zeal, both of the clergy and
the laity. The Bishop of Salisbury stated in his primary charge that
the number of churches in that diocese having two sermons on
Sunday had increased during the episcopate of Dr. Denison (16
years) from 143 to 426; and the number having monthly
communions from 35 to 181. The increase in the number of church
sittings during the past half century may be considered as nett, for
there can be no doubt that nearly all the new buildings have the
double service. At all events, if there are any that have not, they are
more than compensated for by those ancient churches where there
was formerly only one service on the Lord’s Day, but where there are
now two. On the other hand, the Dissenters are not able to open
quite three-fourths of their sittings on the Sunday morning; and as
there is no reason whatever for supposing that their new
accommodation is exempt from this deduction, we may subtract
one-fourth from the gross number assigned in the tables to each
period.
The following table, compiled on the assumption that 58 per cent. of
the population might attend divine worship on any Sunday morning,
will show at a glance the number of sittings really required at each
decennial period, and the real provision made to supply the
deficiency:—

Sittings (open) Furnished by the By Total.


required. Church. dissent.
1801 5,157,671 2,559,345 1,577,143 4,136,488
Increase decennially:—
1811 737,598 55,250 286,407 341,657
1821 1,064,869 96,900 532,998 629,898
1831 1,100,005 276,250 555,239 831,488
1841 1,170,064 667,250 389,323 1,056,573
1851 1,167,807 1,197,650 304,766 1,502,416
Total 5,240,342 2,293,300 2,068,732 4,362,032
increase
Total 10,398,013 4,852,645 3,645,875 8,498,520

Or, exhibiting the same results in a somewhat different form:—

Sittings per 1,000 of Provided by By Total.


population required. Church. Dissent.
1801 580 287 177 464
1811 580 257 183 441
1821 580 225 199 424
1831 580 214 212 426
1841 580 229 209 438
1851 580 270 203 473

Church loss since 1801, 17; Dissenting gain, 26: total Church loss,
43.
Church gain since 1831, 56; Dissenting loss, 9; total Church gain,
65.
This, then, is really the rate at which each body “is advancing in the
path of self extension;” and the best proof of its accuracy is, that it
exactly tallies with what one would have expected beforehand. Mr.
Mann’s tables, on the contrary, are absolutely incredible. We must
never forget, that during the Great Rebellion, Puritanism was
actually the dominant faction; and even at the Restoration it cannot
be supposed that the Dissenters were a small or an uninfluential
class. In 1662 no fewer than 2,000 ministers were ejected under
the new Act of Uniformity; and as at the last census there were only
6405 professional Protestant Ministers, it will be seen that the
ejected preachers alone formed a larger body, in comparison with
the existing population, than the Protestant Dissenting Ministry does
now. It cannot be doubted that every one of those men had a
greater or less following; and it must be remembered that in the
days of the Commonwealth there was always a rabble of sects who
might even then be called Dissenters. It is true that, after the
Restoration, Nonconformity was subjected to severe repressive laws,
but those laws were not enforced with unvarying rigour. In 1672
there was the Indulgence, and in 1681 the House of Commons
passed a strong resolution against the prosecution of Protestant
Dissenters. Besides, after all, the Conventicle Acts only continued in
force about 23 years—not much longer, in fact, than Episcopacy had
been proscribed by law. The natural result which would follow the
famous proclamation of James II., and the subsequent passing of
the Toleration Act, would be a great and sudden revival of Dissent.
How small was the church-feeling of Parliament at the Revolution
may be gathered from a curious fact mentioned in Mr. Macaulay’s
third volume. It was proposed that the Commons should sit on
Easter Monday. The Churchmen vigorously protested against the
innovation; but they did not dare to divide, and the House did sit on
the festival in question. Without at all straining the inference to be
drawn from this incident, it would be difficult, indeed, to suppose
that Churchmen had matters their own way. Even under the penal
laws, the Dissenters must have been a large body; for James the
Second’s scheme for forming a coalition of Roman Catholic and
Protestant Dissenters against the Establishment would have been
stark folly unless the two bodies, when combined, would have made
up, at least, a powerful minority. From the Revolution to 1801 the
Dissenters had more than a century to increase and multiply; and all
the circumstances of the case were in their favour. Worn out by the
political struggles of a century and a half, during which she had been
made the tool of contending factions; deprived of her Legislative
powers; silenced and frowned upon by the powers that were, the
Church had sunk into that fatal lethargy from which the present
generation has only just seen her awake. During that long and
dreary period, all the prominent theologians, with a few bright
exceptions, were either Dissenters or inclined to Dissent. The
eighteenth century, too, was the golden age of popular
Nonconformist preachers. Not to mention a host of smaller names,
Wesley and Whitfield both rose, flourished, and died before its
close. And yet, if we are to believe Mr. Mann, the Dissenters in 1801
were a much smaller body, compared with the whole population,
than they were under the penal laws! [25] On the other hand, all
who remember the obloquy and contempt under which the Church
continued until the passing of the Reform Act, will reject, without a
moment’s hesitation, the notion that, in 1831, she actually
possessed more accommodation, in proportion to the population,
than at the present day. The change which has taken place in the
popular sentiment towards her has not been caused by any
document like this Census report, which suddenly appeared and
disabused the public mind of its preconceived ideas. It has, on the
contrary, been brought about by the silent influence of those
spectacles of zeal and self-denying liberality which have been
witnessed in every corner of the land. The Church has, in fact, lived
down her traducers. A hundred proverbs bear witness to the vast
amount of good deeds which are required to remove an evil
reputation; and yet Mr. Mann calls upon us to believe that the
Establishment has achieved this, although, with all her numbers and
all her wealth, she has not, since 1831, done so much as the
Wesleyan sects alone, towards supplying the people with the means
of religious instruction and worship! One has no language to
characterize such a daring attempt on the public credulity. The most
charitable hypothesis will be to conclude that Mr. Mann, though an
arithmetician by his office, knows nothing about arithmetic; and so
remit him to the consideration of Mr. Roebuck and the Administrative
Reform Society. [26]
The inquiry through which the reader has been invited to travel will
probably suggest several considerations; and first of all the
importance of putting a stop to the statistical nuisance which has of
late years flourished with so rank a growth. Surely it is time that
members of both Houses of Parliament, who resent so jealously any
attempt on the part of Government officials to exceed or fall short of
the precise instructions given them, in making returns, should raise
their voices against the system of publishing with official statistics
the crude, and, as it has been seen, the nonsensical but pernicious
theorizings of the persons entrusted with the task of compiling
reports. Like Mr. Mantalini, the majority of persons never trouble
themselves to examine a numerical process, but content themselves
with simply asking what is the total; and it therefore becomes the
duty of Parliament to see that the unsuspecting confidence of the
public is not abused. The reader must not suppose that the Report
on Religious Worship is the only recent one which is open to
objection. The Census Report on Schools is just as full of fallacies;
and it has certainly been one of the strangest phenomena ever
witnessed in the history of public discussion, that the schemes of
Lord John Russell and Sir John Pakington, assailed as they were on
every side, should have escaped what would, after all, have been
the most effective blow that could have been aimed against them—
the simple but conclusive fact, so easily deducible from the premises
of the Report on Schools, that nearly as many children were under
education as could be induced to attend unless they were driven to
the class of the teacher by the policeman’s staff. [27]
Again, the inquiry will probably satisfy the reader that the anti-
Church legislation of the day ought to proceed no further. It is easy
to assign the cause which in the first instance gave it birth. Most
statesmen, it may be presumed, will be ready to adopt, with regard
to the multifarious sects of modern Christianity, the last clause, at
least, of Gibbon’s famous dictum respecting the ancient religions of
Pagan Rome—“to the people equally true, to the philosopher equally
false, to the magistrate equally useful.” Persons who profess with
sincerity almost any form of Christian doctrine are comparatively
easy to govern; they throw but a light burden upon the poor-rate
and they cost nothing at all in the shape of police. A statesman,
then, might dislike Dissent, but what was he to say to a state of
things like that revealed in the Census report? The Church,
according to Mr. Mann’s tables, could not, by dint of the utmost
exertions she is ever likely to put forth, find accommodation for half
the souls who are year by year added to the population. On the
other hand the Dissenters, who are far less wealthy, and have few
endowments, provide without difficulty and without fuss more than
twice the amount of new accommodation supplied by the Church.
The irresistible inference in the mind of a mere statesman would be
that Dissent ought to be aided and encouraged. But if it turns out
that the facts are precisely the reverse of what has been represented
—if in reality Dissent is making no progress, while the Church is
providing new accommodation sufficient for the whole of the new
population—why should the Legislature go out of its path to foster
mere religious discord, and to impede the spread of what the
country has, after all, long since recognised as the “more excellent
way.” Why, for instance, should Churchrates be abolished? If they
were right in 1831, when there were more Dissenters and fewer
Churchmen, why are they wrong now? If Parliament has conferred
upon parishes, as a boon, the right to tax themselves (if a majority
of the ratepayers think fit) for the purpose of building and
maintaining public baths, museums, and libraries, why should
parishes now be deprived of a right which they possessed before
there was a Chancellor of the Exchequer or a budget—before the
Norman set foot upon our shores, or there was a House of
Commons worthy of the name—the right to tax themselves in order
to maintain edifices which may be museums second in interest to
none, and which may have been centres of enlightenment long
before the days of Caxton and Guttenberg?
There is another view of the case which ought not to be overlooked
by statesmen who regard a religious Establishment as a mere matter
of police. Granting that Dissent teaches men to be neither
drunkards nor thieves, is it calculated to make them as good citizens
and as good neighbours as the Church? The answer must surely be
a negative. The common consent of mankind has pronounced the
famous descriptions of the old Puritans in “Hudibras” to be almost as
applicable to modern Dissenters as to their ancient prototypes. Nor,
indeed, would it be easy, if they were not, to account for the
popularity of Butler’s oft-quoted lines; for even just satires, to say
nothing of unjustifiable lampoons, rarely survive the persons against
whom they are directed. Of course, men are often much better than
the system to which they belong. There are hundreds—nay,
thousands—of Dissenters whose Dissent is a mere accident of birth
and education, and who are truly catholic at heart; but of Dissent in
the abstract, no one who has either studied its history or is
acquainted with its practical working will deny the applicability to it
not only of Butler’s portraiture, but of another yet more famous
description, qualified in the latter case, however, with the insertion
or omission throughout of the important word—“not.” Dissent
suffers not long, and is not kind—Dissent is envious—behaves itself
unseemly—vaunts itself, and is puffed up—seeks every tittle of its
“rights”—is easily provoked—thinks evil—gloats over every slip on
the part of its opponents—attributes what is good in them to a
wrong motive—will bear nothing of which it can rid itself by agitation
or clamour—will put a good construction upon nothing when an evil
one is possible—hopes nothing—endures nothing. If this were not
so, how would it be possible to account for its inveterate propensity
to internal schism? The scriptural account of the Kingdom of Heaven
is that it should grow as from a seed; but Dissent is propagated
chiefly by cuttings. It is not yet two hundred years since the Kirk
was established in Scotland, and yet there are no fewer than six
sorts of Presbyterians. The case of Wesleyanism is still worse.
Within sixty years after the death of its founder it had split into
seven antagonistic sects. Whitfield himself quarrelled with Wesley,
and his followers have, since his death, separated into two bodies.
There are four sorts of Baptists. Of the Independents, Mr. Mann
speaks with refreshing innocence as forming “a compact and
undivided body.” It would be nearer the truth to say that they
consist of nearly as many sects as there are meeting-houses. Nearly
every congregation is of volcanic origin, and every one contains
within it elements which might at any moment explode and shatter
the whole concern.
That the writer may not be thought to be unsupported by facts, he
will here summarize the history of Anabaptistic and Congregational
Dissent in the first town to the annals of which he has ready access
—Nottingham, his authority being Mr. Wylie’s local history, published
in 1853. Nottingham, however, is a remarkably good example for
the purpose. It has a manufacturing population of 57,000, having
doubled itself since 1801. It is almost at the head of those places in
which Dissent is most rampant, and the Church most depressed. It
possessed, according to Mr. Mann’s table K, 35.2 Dissenting sittings
to every hundred inhabitants, the only other places equal or superior
to it in that respect being Merthyr Tydvil (52.4), Sunderland (35.2),
Rochdale (36.5), and Swansea (42.8). It boasts of 74.1 per cent. of
the whole religious accommodation within its boundaries, the only
places having more being Merthyr (89.7), and Rochdale (78.7).

About the middle of the last century, then, the Presbyterian


congregation on the High Pavement adopted Socinian tenets;
and many families thereupon left it and joined a small
congregation of Calvinistic Independents in Castle-gate. Their
meeting-house was immediately enlarged, and it has ever since
been considered the leading Dissenting place of worship. In
1761, a second secession from High Pavement, this time of
Sabellians, built themselves a new meeting-house in Halifax-
place. In 1801, they erected themselves a new building in St.
Mary’s-gate, which has long since been closed. In 1798, a third
swarm, again Calvinistic Independents, left High Pavement, and
settled in the Halifax-place meeting-house, vacated by their
Sabellian predecessors. In 1819, they built themselves a new
meeting-house, called “Zion Chapel,” in Fletcher-gate, the old
one being now a school. In 1822, a secession from Castle-gate
built a new meeting-house in St. James’s-street; and six years
later a secession from St. James’s-street built a meeting-house
in Friar-lane. In 1804, a secession from Zion Chapel erected
“Hephzibah Chapel,” which being in debt, was sold to the
Universalists in 1808, and was soon afterwards converted into a
National School. In 1828, another secession from “Zion Chapel”
erected a meeting called “Bethesda Chapel.”
The General Baptists at first met in a disused Wesleyan
meeting-house, called “The Tabernacle,” which has long since
been pulled down. In 1799 they built themselves a place in
Stoney-street. In 1817 a quarrel arose between Mr. Smith, the
senior pastor, and his junior, of whose pulpit talents he was said
to be jealous. The congregation dismissed them both, and
appointed a Mr. George. On Sunday, the 3rd of August, in the
same year, there was a personal conflict after the Donnybrook
manner, between the partisans of Smith and George. The
friends of Smith being beaten drew off, and built themselves a
meeting-house in Broad-street. In 1850 there was another
secession from Stoney-street, who built themselves a meeting-
house on the Mansfield-road.
The Particular Baptists originally occupied an ancient meeting-
house in Park-street: but in 1815 they built themselves a larger
place in George-street. In 1847 there was a secession of extra-
Particulars. These met first in a room in Clinton-street, then in
an old building which had been disused by the Quakers, and
finally, in a splendid gothic edifice, which they built for
themselves on Derby-road. The old meeting-house in Park-
street fell into the hands of a congregation of the Scotch variety
of the sect, whose peace has only been disturbed by the
Bethesdians, who joined them in 1828, until they decided upon
setting up for themselves.

Thus it will be seen that of the nine new congregations enumerated


above, not one was originated without a quarrel—a quarrel, too, of
the worst kind, a personal one. Nobody can study the history of
religious polemics without perceiving that the root of all that
bitterness which has made the odium theologicum a proverb, is to
be found in the tendency there is in men to transfer the indignation
they might reasonably feel against error, from the error itself to
those who hold it. If people would only consent to forget history
and would conduct the argument upon purely abstract principles,
even the Roman controversy might be made instructive and edifying;
but somehow, before long, the debate wanders away from the truth
or falsehood of the creed under discussion to that most irrelevant of
all issues, the virtues or failings of those by whom it is professed.
What shall we say, then, of a system which gives rise to
controversies which, from their commencement to their close, are
purely personal? Lest it should be supposed that the case of
Nottingham is an isolated instance, here is an extract on which the
writer stumbled the other day in a tract written in praise of
Congregationalism, and stated on the title page to be “commended
by J. Bennett, D.D.” It appears to be quoted from a work called
“The Library of Ecclesiastical Knowledge,” and the scene of the
incident is stated to be “one of the principal cities of the United
States:”—

A Baptist congregation, originally small, had increased so rapidly


that an enlargement of the chapel became necessary. It was
immediately effected. The congregation still continued to
increase, and a second time it became necessary to enlarge.
Everything still going on prosperously, a third enlargement,
some time after, was proposed. The noble-minded pastor,
however, thinking that he had already as much on his hands as
any mere mortal could conscientiously discharge, with a
generous contempt for his own interests, opposed this step, and
suggested that they should exert themselves to raise a new
interest, entirely independent of the old one. The people
entered cheerfully into his design; nay, they made a nobler
sacrifice than that of their money. For as soon as the new
building was finished, one of the deacons, with a few of the
most respectable members of the old church, voluntarily
separated from it, and proceeded to form the infant colony that
had branched off from the mother church. What is still more
delightful, the two churches formed a common fund for the
erection of a third chapel. This was soon accomplished. In a
short time a large and flourishing church was the result; and, at
the time our informant related this fact, all three churches were
actually subscribing towards a fourth chapel. This is noble
conduct. Who can tell how soon cities and towns might be
evangelised, if this principle were sternly (!) acted upon? A
somewhat similar fact has, we understand, been recently
witnessed in a city of our own country, where some
congregational churches have imitated their Baptist brethren of
America. When will all ministers “go and do likewise?”

This is truly edifying and amusing. First of all, mark the habitat of
this Nonconformist phœnix, a congregation which has actually given
birth to another without a preliminary quarrel. We must actually
cross the Atlantic, and seek the phenomenon in the land where the
penny-a-liner places his sea-serpents, and his other choicer
wonders. To increase without envy, hatred, and uncharitableness is,
it seems, to a Dissenter, something inexpressibly “noble”—and
brotherly love is something that must be “sternly” acted upon! We
may be quite certain that it is something the congregational sects
very rarely see, or it would not throw them into such lamentable,
and yet, in some sense, ludicrous contortions of surprise.
Perhaps some Dissenter will be whispering, after the manner of Mr.
Roebuck, the three words, Gorham, Liddell, Denison; but the tu
quoque wholly fails. In the first place, it is the surprising peculiarity
of the present Church controversies that the noisiest, if not the
weightiest, disputants are not Churchmen at all. In the next place,
those who are Churchmen, and enter with any bitterness into the
strife, are remarkable neither for their number nor their influence.
The great party in the Church of England is, after all, the middle
party; and however fierce the cannonade which the extreme left,
and its allies outside the pale, may direct against the extreme right,
their missiles fly harmlessly over the vast body which lies between.
The truth is, the recent outburst of controversy, so far as the Church
herself is responsible for it, is nothing but the natural recoil of that
conservative sentiment which must always be a powerful feeling in a
religious community, from doctrines and usages which had become
unfamiliar. As the unfamiliarity passes away, the controversy will
also gradually cease. Already the doctrines and usages in question
have been unconsciously adopted by many of those who fancy
themselves most opposed to them; and, indeed, if our doughtiest
combatants would only take pains to understand what it is their
antagonists really hold, they would often find that they are fighting
against mere shadows. The recent suits in the ecclesiastical courts
cannot but open the eyes of Churchmen to the extreme tenuity of
the points in dispute. Take the S. Barnabas case. Everybody will
remember the language which was applied to the “practices” revived
by Mr. Bennett. “Popish,” “histrionic,” “mummery,” were the mildest
terms in the repertory of that gentleman’s assailants. Those
“practices” remain to this day—if anything, they have been
elaborated rather than subjected to any mitigating process. Messrs.
Westerton and Beal bring the matter before the proper tribunal; but
what are the only issues they can find to raise? Such notable
questions as whether the cross, which glitters on the crown, the orb,
and sceptre of the Sovereign, which glows on the national banner,
which crowns almost every church gable in the land, with which
every Churchman is marked at his baptism, which the very Socinians
place upon their buildings, is, forsooth, a lawful ornament?—whether
a table ceases to be a table by being made of stone?—whether the
altar which has never been moved these two hundred years, and
which nobody wants to move, must nevertheless be movable?—
whether the altar vestments and the “fair linen cloths” used during
Communion time, may have fringes, or must be plain-hemmed?
Even if Dr. Lushington’s judgment should eventually be confirmed, if
in this age of schools of design, Mr. Westerton’s crusade against art
should prove successful, the alterations that would be made at S.
Barnabas would be discernible by none out the keenest eyes—so
little can there be found in matters ritual to fight about. Even in the
Denison case the points of difference are almost as infinitesimal. It
is true that under the revived act of Elizabeth—compared with which
the laws of Draco seem a mild and considerate code—the
Archdeacon has been sentenced to lose his preferments; but his
doctrine on the Real Presence has, in sober fact, never been so
much as challenged. His opponents, passing over all that was
material in his propositions, have only attacked a quasi corollary
which he has added to his main position, but which is, in reality, a
complete non-sequitur. Whether Dr. Lushington is right or wrong, it
is clear that a person holding the dogma of transubstantiation itself
might, with perfect logical consistency, accept the ruling of the
Court.
The differences between the highest and the lowest schools being so
impalpable, it would seem absurd to suppose that the present
controversies can have a much longer continuance. But whether
that be so or not, there is a very important distinction (and one that
is well worth the notice of statesmen) between the extension of the
Church and the spread of Dissent. Church extension, as far as it
goes, tends to compose differences. The consecration of a new
church is almost invariably regarded as an occasion when party
differences should be laid aside—the opening of a new meeting-
house is too commonly the crowning act of an irreparable schism.
Another lesson which the report of Mr. Mann ought to teach
Churchmen is the necessity there is for insisting upon the next
religious census being made a complete and accurate one. The next
religious census ought to include all such institutions as colleges,
workhouses, hospitals, and the like—it ought to be enforced by the
same penalties as the civil census; and it ought to be understood
that all the returns would be printed in a blue book. With these
precautions the Church need not fear the result. Even if the census
of 1861 should prove no more trustworthy than that of 1851, it will
remove a great deal of the misconceptions to which the latter has
given rise. As far as one may judge, the work of church extension is
progressing just as rapidly now as it was ten years ago; the number
of the clergy is just as rapidly augmenting; [33] and as all additional
clergymen have now to be supported on the voluntary principle, we
may presume that they follow the ordinary laws of supply and
demand. We may, therefore, confidently expect that the number of
church sittings open on the census morning in 1861 will not be
fewer than six millions; and if there be an average attendance
(which there was not on the last occasion) the number of persons
present will be about three millions and a half. That the Dissenters
will be able to open any more sittings than in 1851, is doubtful; for it
must be remembered that since 1841 the Church has been annually
absorbing a population equal to the entire yearly increase. But
allowing them the same increase as has been assigned to them for
the decade 1841–51, they will not be able to open more than four
million sittings, and they will not have more than two millions and a
half of attendants. This estimate is formed on the supposition that
the next census will be made on the voluntary principle like the last.
If a more complete and accurate account is taken, the result may be
very different. It is quite within the bounds of possibility that the
number of church attendants may turn out to be near four millions,
while that of the Dissenters may not much exceed two.
Looking at all the facts of the case, there is every reason why the
Church should take courage. Never since the Reformation has she
had so much real power for good—never has she been so free from
abuses. Each year sees thousands returning to the fold from which
they or their parents had strayed; each year sees her enemies more
and more “dwindle, peak, and pine.” Everything, too, points to a
daily acceleration of the process. At the very time that Convocation
is resuming its functions, the Non-conformist Union is compelled by
internal dissentions to abandon their yearly meeting. What Mr. Miall
calls “the dissidence of dissent”—that is to say, all in it that is pre-
eminently narrow-minded, ignorant, and infected with bigotry—is
concentrating itself, and is thus getting free the more respectable
elements of modern non-conformity. Meanwhile the better class of
Dissenters are doing all in their power to cut the ground from under
their own feet. They are building “steeple-houses,” inventing
liturgies, and adopting even choral services; in other words they are
expressing in the most emphatic manner their opinion that the
whole theory of dissent is wrong. For a short time a Brummagem
ecclesiology may satisfy them; but in the end they will no doubt rank
themselves amongst the best sons of the Church. The truth is, there
is no other religious community at the present day which can bid so
high for the reverent attachment of Englishmen. Whatever the
claims of Rome—her antiquity, her catholicity, her apostolicity—they
are equally the Church of England’s. Her succession of bishops is
the same, her regard for the primitive church greater, her conception
of Christendom far more grand. The glories of the ancient rituals
belong equally to the Book of Common Prayer. It contains nothing
material which was not in them, there was nothing material in them
(save only certain invocations and legends of the saints) which is not
in it. The Prayer Book is, in fact, nothing but a translation
(magnificently done) of the older offices, a little compressed and
simplified. The structure is the same—the mode of using it the
same; and if it has lost somewhat of the multiplied ceremonies
which were anciently observed, it has gained far more in the majesty
and breadth which it has acquired from its thoroughly congregational
character. Besides, it is throughout a reality, whereas the office
books of the Latin Communion have, to some extent at least,
become a sham. Thus the Breviary has long since been practically
abolished as a public form of prayer, and even as a manual of private
devotions for the clergy, that which forms its staple, the Book of
Psalms, has been virtually reduced to a fourth its bulk. In nearly a
thousand churches belonging to the Anglican communion the whole
Psalter is publicly recited every month, and in twenty times that
number it is said through twice every year.
If Protestant Dissenters boast of their enlightenment or of their
reverence for Scripture, the Church may meet them on that ground
likewise with the utmost confidence. The Prayer-book scarcely
recognises a person to be a Churchman if he cannot read; and she
directs some forty psalms and some thirty chapters of the Bible to be
gone through every week. In a word, approach the Church of
England from the most opposite points, and she will be found to
possess exactly that attribute which a person might think is most
admirable. The man who reverences antiquity—who has a taste for
art—who has a passion for ritual—who would have everything
“understanded of the people,”—he who insists upon ranks and
orders—and he who stands up for popular rights, will equally find in
the Church of this country the very quality which he deems
important. Never was there any institution so “many-sided;” never
one that became with so much success “all things to all men.” How
she could ever have lost her hold on the affections of Englishmen is
indeed wonderful; but, in truth, until lately, she has never had a
chance of making herself understood. Now, for the first time, her
theory is beginning to be appreciated; and the success which has
attended her, wonderful as it has been, is probably but the foretaste
of a future more brilliant than anything of which we can now form
an idea.
FOOTNOTES.

[11] The above tables, it is right to say, have been obtained by


subtracting Mr. Mann’s tables relating to the Church from the tables
relating to places of worship in the aggregate.
[19] It is right to say that the decennial periods do not exactly
agree. In Mr. Mann’s tables they are from 1801–11, &c.; in Mr.
Bright’s return, from 1800–10, &c. It is not, however, apprehended
that this circumstance would materially affect the calculation.
[25] Neale estimates the Nonconformists, in the time of Charles II.,
at a hundred and fifty thousand families, or three quarters of a
million persons; in other words, at about a sixth of the population.
If the Dissenters had in 1801 only 881,240 sittings, their number of
morning attendants would be considerably less than 400,000; and,
allowing each attendant to represent three persons, that would give
a Dissenting population of about 1,100,000.
[26] The faculty of reasoning correctly in figures is not so ordinary
an accomplishment as might have been supposed. Even so
intelligent a writer as Mr. Henry Mayhew prints, at page 391 of his
“Great World of London,” a table, of which the following is a
specimen:—

1842. Can neither Can read


read nor only (percent)
write (percent).
Convicted at assizes and sessions 39.79 27.21
Convicted—summarily 39.90 21.65
Average 39.84 24.43

—the average being found by adding together the two lines and
dividing the sum by two. It need hardly, however, be pointed out
that the result so arrived at could not be true unless the number of
persons in each class was exactly the same. A man who had
invested in the Great Western Railway £900 which yielded him two
per cent., and £100 in the South Western which paid him six, might
say, on Mr. Mayhew’s principle, that he had invested £1000 at 4 per
cent; but he would soon find out that he would have to receive only
£24 for his yearly dividend instead of £40—£2.8 percent. instead of
£4.
[27] Mr. Mann calculates that without in the least interfering with
juvenile labour, and without questioning the discretion of parents
who kept children between the ages of 3 and 5 and 12 and 15 at
home, there ought to have been more than three million children at
school in 1851. It would be easy to show that this estimate is based
upon nothing better than a series of blunders and bad guesses, but
there is a much shorter mode of dealing with it. The children of the
middle and upper classes do not remain under professional
instructors at home or at school for a longer average period than six
years. Now, the total number of children in 1851 between the ages
of 4 and 10 was 2,484,866, or 13.8 per cent. of the entire
population. The number actually on the school books was
2,200,000, or 12.2 per cent. So that either all the children in the
country were at school, but the average time was one-eighth too
short; or the average time was of the right length, but the number
of scholars was one-eighth too few. The truth, of course, lay
somewhere between these two alternatives. Since 1851
considerable progress has no doubt been made; but it unfortunately
turns out that the effect of improved machinery is not to improve the
general education, but merely to shorten the time allotted to
schooling. It is found that if by better modes of tuition a child can
be made sooner to acquire what its parents think sufficient for it to
know, it is only so much the sooner taken away. It would therefore
be vain to expect that the school per centage will ever be much
higher than it was in 1851—at least, until the middle classes raise
their own standard. Of the children on the schoolbooks in 1851, the
per centage of actual daily attendants was 83—91 for the private,
and 79 for the public scholar. In America, where the schools are
wholly free, the per centage was still less. In Massachusetts, for
example, it was only 75. In other words, the attendance in England
and Wales in 1851 was 1,826,000 daily. If the 2,200,000 had all
been private scholars, it would have been 2,002,000. On the other
hand if there had been 2,400,000 free scholars, it would only have
been 1,800,000. These figures will speak for themselves.
[33] The number of additional clergy ordained every year is stated
to be 300. The number required to maintain the proportion of clergy
to population which existed in 1851 would be under 200.
*** END OF THE PROJECT GUTENBERG EBOOK THE TRUTH ABOUT
CHURCH EXTENSION ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like