Foundations of Data Science1

John Hopcroft

Ravindran Kannan

Version 21/8/2014

These notes are a ﬁrst draft of a book being written by Hopcroft and Kannan and
in many places are incomplete. However, the notes are in good enough shape to prepare
lectures for a modern theoretical course in computer science. Please do not put solutions
to exercises online as it is important for students to work out solutions for themselves
rather than copy them from the internet.

Thanks
JEH

1Copyright 2011. All rights reserved

1

Contents

1 Introduction

7

2 High-Dimensional Space

10
2.1 Properties of High-Dimensional Space . . . . . . . . . . . . . . . . . . . . . 12
2.2 The Law of Large Numbers
. . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 The High-Dimensional Sphere . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.1 The Sphere and the Cube in High Dimensions . . . . . . . . . . . . 16
2.3.2 Volume and Surface Area of the Unit Sphere . . . . . . . . . . . . . 17
2.3.3 The Volume is Near the Equator
. . . . . . . . . . . . . . . . . . . 20
2.3.4 The Volume is in a Narrow Annulus . . . . . . . . . . . . . . . . . . 23
. . . . . . . . . . . . . . . . 24
2.3.5 The Surface Area is Near the Equator
2.4 Volumes of Other Solids
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.5 Generating Points Uniformly at Random on the Surface of a Sphere . . . . 27
2.6 Gaussians in High Dimension . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.7 Bounds on Tail Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.8 Applications of the tail bound . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.9 Random Projection and Johnson-Lindenstrauss Theorem . . . . . . . . . . 38
2.10 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

3 Best-Fit Subspaces and Singular Value Decomposition (SVD)

52
3.1 Singular Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.2 Singular Value Decomposition (SVD) . . . . . . . . . . . . . . . . . . . . . 56
3.3 Best Rank k Approximations
. . . . . . . . . . . . . . . . . . . . . . . . . 58
3.4 Left Singular Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.5 Power Method for Computing the Singular Value Decomposition . . . . . . 62
3.6 Applications of Singular Value Decomposition . . . . . . . . . . . . . . . . 64
3.6.1 Principal Component Analysis . . . . . . . . . . . . . . . . . . . . . 64
3.6.2 Clustering a Mixture of Spherical Gaussians . . . . . . . . . . . . . 65
Spectral Decomposition . . . . . . . . . . . . . . . . . . . . . . . . 71
3.6.3
3.6.4
. . . . . . . . . . . . . . 71
Singular Vectors and Ranking Documents
3.6.5 An Application of SVD to a Discrete Optimization Problem . . . . 72
3.7 Singular Vectors and Eigenvectors . . . . . . . . . . . . . . . . . . . . . . . 75
3.8 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

4 Random Graphs

4.1 The G(n, p) Model

85
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.1 Degree Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
. . . . . . . . . . . . . . . . . . 91
4.1.2 Existence of Triangles in G(n, d/n)
4.2 Phase Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.3 The Giant Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

2

4.4 Branching Processes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
4.5 Cycles and Full Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.5.1 Emergence of Cycles
. . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.5.2 Full Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
4.5.3 Threshold for O(ln n) Diameter . . . . . . . . . . . . . . . . . . . . 118
4.6 Phase Transitions for Increasing Properties . . . . . . . . . . . . . . . . . . 119
4.7 Phase Transitions for CNF-sat . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.8 Nonuniform and Growth Models of Random Graphs . . . . . . . . . . . . . 126
4.8.1 Nonuniform Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
4.8.2 Giant Component in Random Graphs with Given Degree Distribution127
4.9 Growth Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
4.9.1 Growth Model Without Preferential Attachment . . . . . . . . . . . 128
. . . . . . . . . . . . 135
4.9.2 Growth Model With Preferential Attachment
4.10 Small World Graphs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
4.11 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

5 Random Walks and Markov Chains

153
5.1 Stationary Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
5.2 Electrical Networks and Random Walks . . . . . . . . . . . . . . . . . . . . 158
5.3 Random Walks on Undirected Graphs with Unit Edge Weights . . . . . . . 162
5.4 Random Walks in Euclidean Space . . . . . . . . . . . . . . . . . . . . . . 169
5.5 The Web as a Markov Chain . . . . . . . . . . . . . . . . . . . . . . . . . . 173
5.6 Markov Chain Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . 177
5.6.1 Metropolis-Hasting Algorithm . . . . . . . . . . . . . . . . . . . . . 178
5.6.2 Gibbs Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
5.7 Areas and Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
5.8 Convergence of Random Walks on Undirected Graphs . . . . . . . . . . . . 183
5.8.1 Using Normalized Conductance to Prove Convergence . . . . . . . . 188
5.9 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
5.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192

6 Learning and VC-dimension

202
6.1 Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
6.2 Linear Separators, the Perceptron Algorithm, and Margins . . . . . . . . . 204
6.3 Nonlinear Separators, Support Vector Machines, and Kernels . . . . . . . . 209
6.4 Strong and Weak Learning - Boosting . . . . . . . . . . . . . . . . . . . . . 214
6.5 Number of Examples Needed for Prediction: VC-Dimension . . . . . . . . 216
6.6 Vapnik-Chervonenkis or VC-Dimension . . . . . . . . . . . . . . . . . . . . 219
6.6.1 Examples of Set Systems and Their VC-Dimension . . . . . . . . . 220
. . . . . . . . . . . . . . . . . . . . . . . . . 223
6.6.2 The Shatter Function
6.6.3
. . . 224
. . . . . . . . . . . . . . . . . . . . . . . . . . 226
6.6.4

Shatter Function for Set Systems of Bounded VC-Dimension
Intersection Systems

3

6.7 The VC Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
6.8 Simple Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
6.9 Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
6.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

7 Algorithms for Massive Data Problems

238
7.1 Frequency Moments of Data Streams . . . . . . . . . . . . . . . . . . . . . 238
7.1.1 Number of Distinct Elements in a Data Stream . . . . . . . . . . . 239
. . . . . 243
7.1.2 Counting the Number of Occurrences of a Given Element.
7.1.3 Counting Frequent Elements . . . . . . . . . . . . . . . . . . . . . . 243
7.1.4 The Second Moment . . . . . . . . . . . . . . . . . . . . . . . . . . 245
7.2 Matrix Algorithms Using Sampling . . . . . . . . . . . . . . . . . . . . . . 248
7.2.1 Matrix Multiplication Using Sampling . . . . . . . . . . . . . . . . 248
Sketch of a Large Matrix . . . . . . . . . . . . . . . . . . . . . . . . 250
7.2.2
7.3 Sketches of Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
7.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

8 Clustering

260
8.1 Some Clustering Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
8.2 A k-means Clustering Algorithm . . . . . . . . . . . . . . . . . . . . . . . 263
8.3 A Greedy Algorithm for k-Center Criterion Clustering
. . . . . . . . . . . 265
8.4 Spectral Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
8.5 Recursive Clustering Based on Sparse Cuts . . . . . . . . . . . . . . . . . . 273
8.6 Kernel Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.7 Agglomerative Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
8.8 Dense Submatrices and Communities . . . . . . . . . . . . . . . . . . . . . 278
8.9 Flow Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
8.10 Finding a Local Cluster Without Examining the Whole Graph . . . . . . . 284
8.11 Axioms for Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
. . . . . . . . . . . . . . . . . . . . . . . . 289
. . . . . . . . . . . . . . . . . . . . . . 295
8.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

8.11.1 An Impossibility Result
8.11.2 A Satisﬁable Set of Axioms

9 Topic Models, Hidden Markov Process, Graphical Models, and Belief

301
Propagation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
9.1 Topic Models
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
9.2 Hidden Markov Model
9.3 Graphical Models, and Belief Propagation . . . . . . . . . . . . . . . . . . 310
9.4 Bayesian or Belief Networks . . . . . . . . . . . . . . . . . . . . . . . . . . 311
9.5 Markov Random Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
9.6 Factor Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
9.7 Tree Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
9.8 Message Passing in general Graphs
. . . . . . . . . . . . . . . . . . . . . . 315
. . . . . . . . . . . . . . . . . . . . . . . . . . 317
9.9 Graphs with a Single Cycle

4

9.10 Belief Update in Networks with a Single Loop . . . . . . . . . . . . . . . . 319
9.11 Maximum Weight Matching . . . . . . . . . . . . . . . . . . . . . . . . . . 320
9.12 Warning Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
9.13 Correlation Between Variables . . . . . . . . . . . . . . . . . . . . . . . . . 325
9.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330

10 Other Topics

332
10.1 Rankings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
10.2 Hare System for Voting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
. . . . . . . . . . . . . . . . . . . 335
10.3 Compressed Sensing and Sparse Vectors
10.3.1 Unique Reconstruction of a Sparse Vector
. . . . . . . . . . . . . . 336
10.3.2 The Exact Reconstruction Property . . . . . . . . . . . . . . . . . . 339
10.3.3 Restricted Isometry Property . . . . . . . . . . . . . . . . . . . . . 340
10.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
. . . . . . . . . . . . . . . 342

10.4.1 Sparse Vector in Some Coordinate Basis
10.4.2 A Representation Cannot be Sparse in Both Time and Frequency

Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
10.4.3 Biological
10.4.4 Finding Overlapping Cliques or Communities
. . . . . . . . . . . . 345
10.4.5 Low Rank Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
10.5 Gradient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
10.6 Linear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
10.6.1 The Ellipsoid Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 350
10.7 Integer Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
10.8 Semi-Deﬁnite Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 352
10.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354

11 Appendix

357
11.1 Asymptotic Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
11.2 Useful relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
11.3 Useful Inequalities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
11.4 Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
11.4.1 Sample Space, Events, Independence . . . . . . . . . . . . . . . . . 370
11.4.2 Linearity of Expectation . . . . . . . . . . . . . . . . . . . . . . . . 371
11.4.3 Union Bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
11.4.4 Indicator Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
11.4.5 Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
11.4.6 Variance of the Sum of Independent Random Variables . . . . . . . 372
11.4.7 Median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
11.4.8 The Central Limit Theorem . . . . . . . . . . . . . . . . . . . . . . 373
11.4.9 Probability Distributions . . . . . . . . . . . . . . . . . . . . . . . . 373
11.4.10 Bayes Rule and Estimators . . . . . . . . . . . . . . . . . . . . . . . 376
11.4.11 Tail Bounds and Chernoﬀ inequalities . . . . . . . . . . . . . . . . . 378

5

11.5 Eigenvalues and Eigenvectors

. . . . . . . . . . . . . . . . . . . . . . . . . 382
. . . . . . . . . . . . . . . . . . . . . 382
11.5.1 Eigenvalues and Eigenvectors
11.5.2 Symmetric Matrices
. . . . . . . . . . . . . . . . . . . . . . . . . . 384
11.5.3 Relationship between SVD and Eigen Decomposition . . . . . . . . 386
11.5.4 Extremal Properties of Eigenvalues . . . . . . . . . . . . . . . . . . 386
11.5.5 Eigenvalues of the Sum of Two Symmetric Matrices . . . . . . . . . 388
11.5.6 Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
11.5.7 Important Norms and Their Properties . . . . . . . . . . . . . . . . 391
11.5.8 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
11.5.9 Distance between subspaces . . . . . . . . . . . . . . . . . . . . . . 395
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396

11.6 Generating Functions

11.6.1 Generating Functions for Sequences Deﬁned by Recurrence Rela-

tionships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

11.6.2 The Exponential Generating Function and the Moment Generating

Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
11.7 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.7.1 Lagrange multipliers
. . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.7.2 Finite Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.7.3 Hash Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
11.7.4 Application of Mean Value Theorem . . . . . . . . . . . . . . . . . 402
11.7.5 Sperner’s Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
11.7.6 Pr¨ufer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
11.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405

Index

410

6

Foundations of Data Science†

John Hopcroft and Ravindran Kannan

21/8/2014

1

Introduction

Computer science as an academic discipline began in the 60’s. Emphasis was on pro-
gramming languages, compilers, operating systems, and the mathematical theory that
supported these areas. Courses in theoretical computer science covered ﬁnite automata,
regular expressions, context free languages, and computability. In the 70’s, algorithms
was added as an important component of theory. The emphasis was on making computers
useful. Today, a fundamental change is taking place and the focus is more on applications.
There are many reasons for this change. The merging of computing and communications
has played an important role. The enhanced ability to observe, collect and store data in
the natural sciences, in commerce, and in other ﬁelds calls for a change in our understand-
ing of data and how to handle it in the modern setting. The emergence of the web and
social networks, which are by far the largest such structures, presents both opportunities
and challenges for theory.

While traditional areas of computer science are still important and highly skilled indi-
viduals are needed in these areas, the majority of researchers will be involved with using
computers to understand and make usable massive data arising in applications, not just
how to make computers useful on speciﬁc well-deﬁned problems. With this in mind we
have written this book to cover the theory likely to be useful in the next 40 years, just as
automata theory, algorithms and related topics gave students an advantage in the last 40
years. One of the major changes is the switch from discrete mathematics to more of an
emphasis on probability, statistics, and numerical methods.

Early drafts of the book have been used for both undergraduate and graduate courses.
Background material needed for an undergraduate course has been put in the appendix.
For this reason, the appendix has homework problems.

This book starts with the treatment of high dimensional geometry. Modern data in
diverse ﬁelds such as Information Processing, Search, Machine Learning, etc., is often

†Copyright 2011. All rights reserved

7

represented advantageously as vectors with a large number of components. This is so
even in cases when the vector representation is not the natural ﬁrst choice. Our intuition
from two or three dimensional space can be surprisingly oﬀ the mark when it comes to
high dimensional space. Chapter 2 works out the fundamentals needed to understand the
diﬀerences. The emphasis of the chapter, as well as the book in general, is to get across
the mathematical foundations rather than dwell on particular applications that are only
brieﬂy described.

The mathematical areas most relevant to dealing with high-dimensional data are ma-
trix algebra and algorithms. We focus on singular value decomposition, a central tool in
this area. Chapter 4 gives a from-ﬁrst-principles description of this. Applications of sin-
gular value decomposition include principal component analysis, a widely used technique
which we touch upon, as well as modern applications to statistical mixtures of probability
densities, discrete optimization, etc., which are described in more detail.

Central to our understanding of large structures, like the web and social networks, is
building models to capture essential properties of these structures. The simplest model is
that of a random graph formulated by Erd¨os and Renyi, which we study in detail proving
that certain global phenomena, like a giant connected component, arise in such structures
with only local choices. We also describe other models of random graphs.

One of the surprises of computer science over the last two decades is that some domain-
independent methods have been immensely successful in tackling problems from diverse
areas. Machine learning is a striking example. We describe the foundations of machine
learning, both learning from given training examples, as well as the theory of Vapnik-
Chervonenkis dimension, which tells us how many training examples suﬃce for learning.
Another important domain-independent technique is based on Markov chains. The un-
derlying mathematical theory, as well as the connections to electrical networks, forms the
core of our chapter on Markov chains.

The ﬁeld of algorithms has traditionally assumed that the input data to a problem
is presented in random access memory, which the algorithm can repeatedly access. This
is not feasible for modern problems. The streaming model and other models have been
formulated to better reﬂect this. In this setting, sampling plays a crucial role and, indeed,
we have to sample on the ﬂy. in Chapter ?? we study how to draw good samples eﬃciently
and how to estimate statistical, as well as linear algebra quantities, with such samples.

One of the most important tools in the modern toolkit is clustering, dividing data into
groups of similar objects. After describing some of the basic methods for clustering, such
as the k-means algorithm, we focus on modern developments in understanding these, as
well as newer algorithms. The chapter ends with a study of clustering criteria.

This book also covers graphical models and belief propagation, ranking and voting,

8

sparse vectors, and compressed sensing. The appendix includes a wealth of background
material.

A word about notation in the book. To help the student, we have adopted certain
notations, and with a few exceptions, adhered to them. We use lower case letters for
scaler variables and functions, bold face lower case for vectors, and upper case letters
for matrices. Lower case near the beginning of the alphabet tend to be constants, in the
middle of the alphabet, such as i, j, and k, are indices in summations, n and m for integer
sizes, and x, y and z for variables. Where the literature traditionally uses a symbol for
a quantity, we also used that symbol, even if it meant abandoning our convention. If we
have a set of points in some vector space, and work with a subspace, we use n for the
number of points, d for the dimension of the space, and k for the dimension of the subspace.

The term ”almost surely” means with probability one. We use ln n for the natural
logarithm and log n for the base two logarithm. If we want base ten, we will use log10 .
To simplify notation and to make it easier to read we use E2(1 − x) for (cid:0)E(1 − x)(cid:1)2
and
E(1 − x)2 for E (cid:0)(1 − x)2(cid:1) .

9

2 High-Dimensional Space

In many applications data is in the form of vectors. In other applications, data is not
in the form of vectors, but could be usefully represented by vectors. The Vector Space
Model [SWY75] is a good example. In the vector space model, a document is represented
by a vector, each component of which corresponds to the number of occurrences of a par-
ticular term in the document. The English language has on the order of 25,000 words or
terms, so each document is represented by a 25,000 dimensional vector. A collection of n
documents is represented by a collection of n vectors, one vector per document. The vec-
tors may be arranged as columns of a 25, 000 × n matrix. See Figure 2.1. A query is also
represented by a vector in the same space. The component of the vector corresponding to
a term in the query, speciﬁes the importance of the term to the query. To ﬁnd documents
about cars that are not race cars, a query vector will have a large positive component for
the word car and also for the words engine and perhaps door, and a negative component
for the words race, betting, etc.

One needs a measure of relevance or similarity of a query to a document. The dot
product or cosine of the angle between the two vectors is an often used measure of sim-
ilarity. To respond to a query, one computes the dot product or the cosine of the angle
between the query vector and each document vector and returns the documents with the
highest values of these quantities. While it is by no means clear that this approach will
do well for the information retrieval problem, many empirical studies have established the
eﬀectiveness of this general approach.

The vector space model is useful in ranking or ordering a large collection of documents
in decreasing order of importance. For large collections, an approach based on human
Instead, an automated procedure is
understanding of each document is not feasible.
needed that is able to rank documents with those central to the collection ranked highest.
Each document is represented as a vector with the vectors forming the columns of a matrix
A. The similarity of pairs of documents is deﬁned by the dot product of the vectors. All
pairwise similarities are contained in the matrix product AT A. If one assumes that the
documents central to the collection are those with high similarity to other documents, then
computing AT A enables one to create a ranking. Deﬁne the total similarity of document
i to be the sum of the entries in the ith row of AT A and rank documents by their total
similarity.
It turns out that with the vector representation on hand, a better way of
ranking is to ﬁrst ﬁnd the best ﬁt direction. That is, the unit vector u, for which the sum
of squared perpendicular distances of all the vectors to u is minimized. See Figure 2.2.
Then, one ranks the vectors according to their dot product with u. The best-ﬁt direction
is a well-studied notion in linear algebra. There is elegant theory and eﬃcient algorithms
presented in Chapter 3 that facilitate the ranking as well as applications in many other
domains.

In the vector space representation of data, properties of vectors such as dot products,

10

Figure 2.1: A document and its term-document vector along with a collection of docu-
ments represented by their term-document vectors.

distance between vectors, and orthogonality, often have natural interpretations and this
is what makes the vector representation more important than just a book keeping device.
For example, the squared distance between two 0-1 vectors representing links on web pages
is the number of web pages linked to by only one of the pages. In Figure 2.3, pages 4 and
5 both have links to pages 1, 3, and 6, but only page 5 has a link to page 2. Thus, the
squared distance between the two vectors is one. We have seen that dot products measure
similarity. Orthogonality of two nonnegative vectors says that they are disjoint. Thus, if
a document collection, e.g., all news articles of a particular year, contained documents on
two or more disparate topics, vectors corresponding to documents from diﬀerent topics
would be nearly orthogonal.

The dot product, cosine of the angle, distance, etc., are all measures of similarity or
dissimilarity, but there are important mathematical and algorithmic diﬀerences between
them. The random projection theorem presented in this chapter states that a collection
of vectors can be projected to a lower-dimensional space approximately preserving all
pairwise distances between vectors. Thus, the nearest neighbors of each vector in the
collection can be computed in the projected lower-dimensional space. Such a savings in
time is not possible for computing pairwise dot products using a simple projection.

Our aim in this book is to present the reader with the mathematical foundations to
deal with high-dimensional data. There are two important parts of this foundation. The
ﬁrst is high-dimensional geometry, along with vectors, matrices, and linear algebra. The
second more modern aspect is the combination with probability.

High dimensionality is a common characteristic in many models and for this reason
much of this chapter is devoted to the geometry of high-dimensional space, which is quite
diﬀerent from our intuitive understanding of two and three dimensions. We focus ﬁrst
on volumes and surface areas of high-dimensional objects like hyperspheres. We will not
present details of any one application, but rather present the fundamental theory useful
to many applications.

One reason probability comes in is that many computational problems are hard if
our algorithms are required to be eﬃcient on all possible data. In practical situations,
domain knowledge often enables the expert to formulate stochastic models of data. In

11

best ﬁt line

Figure 2.2: The best ﬁt line is the line that minimizes the sum of the squared perpendicular
distances.

(1,0,1,0,0,1)

(1,1,1,0,0,1)

web page 4

web page 5

Figure 2.3: Two web pages as vectors. The squared distance between the two vectors is
the number of web pages linked to by just one of the two web pages.

customer-product data, a common assumption is that the goods each customer buys
are independent of what goods the others buy. One may also assume that the goods
a customer buys satisﬁes a known probability law, like the Gaussian distribution.
In
keeping with the spirit of the book, we do not discuss speciﬁc stochastic models, but
present the fundamentals. An important fundamental is the law of large numbers that
states that under the assumption of independence of customers, the total consumption
of each good is remarkably close to its mean value. The central limit theorem is of a
similar ﬂavor. Indeed, it turns out that picking random points from geometric objects
like hyperspheres exhibits almost identical properties in high dimensions. One calls this
phenomena the “law of large dimensions”. We will establish these geometric properties
ﬁrst before discussing Chernoﬀ bounds and related theorems on aggregates of independent
random variables.

2.1 Properties of High-Dimensional Space

Our intuition about space was formed in two and three dimensions and is often mis-
leading in high dimensions. Consider placing 100 points uniformly at random in a unit
square. Each coordinate is generated independently and uniformly at random from the
interval [0, 1]. Select a point and measure the distance to all other points and observe

12

the distribution of distances. Then increase the dimension and generate the points uni-
formly at random in a 100-dimensional unit cube. The distribution of distances becomes
concentrated about an average distance. The reason is easy to see. Let x and y be two
such points in d-dimensions. The distance between x and y is

|x − y| =

(cid:118)
(cid:117)
(cid:117)
(cid:116)

d
(cid:88)

i=1

(xi − yi)2.

Since (cid:80)d
i=1 (xi − yi)2 is the summation of a number of independent random variables of
bounded variance, by the law of large numbers the distribution of |x − y|2 is concentrated
about its expected value. Contrast this with the situation where the dimension is two or
three and the distribution of distances is spread out.

For another example, consider the diﬀerence between picking a point uniformly at
random from a unit-radius circle and from a unit-radius sphere in d-dimensions. In d-
dimensions the distance from the point to the center of the sphere is very likely to be
between 1 − c
d and 1, where c is a constant independent of d. This implies that most of
the mass is near the surface of the sphere. Furthermore, the ﬁrst coordinate, x1, of such a
point is likely to be between − c√
, which we express by saying that most of the
d
mass is near the equator. The equator perpendicular to the x1 axis is the set {x|x1 = 0}.
We will prove these results in this chapter, but ﬁrst a review of some probability.

and + c√
d

2.2 The Law of Large Numbers

In the previous section, we claimed that points generated at random in high dimen-
sions were all essentially the same distance apart. The reason is that if one averages
n independent samples x1, x2, . . . , xn of a random variable x, the result will be close to
the expected value of x. Speciﬁcally the probability that the average will diﬀer from the
expected value by more than (cid:15) is less than some value σ2
n(cid:15)2 .
(cid:12)
(cid:12)
(cid:12)
(cid:12)

x1 + x2 + · · · + xn
n

σ2
n(cid:15)2 .

− E(x)

(cid:18)(cid:12)
(cid:12)
(cid:12)
(cid:12)

Prob

(2.1)

> (cid:15)

≤

(cid:19)

Here the σ2 in the numerator is the variance of x. The larger the variance of the random
variable, the greater the probability that the error will exceed (cid:15). The number of points n
is in the denominator since the more values that are averaged, the smaller the probability
that the diﬀerence will exceed (cid:15). Similarly the larger (cid:15) is, the smaller the probability that
the diﬀerence will exceed (cid:15) and hence (cid:15) is in the denominator. Notice that squaring (cid:15)
makes the fraction a dimensionalless quantity.

To prove the law of large numbers we use two inequalities. The ﬁrst is Markov’s
inequality. One can bound the probability that a nonnegative random variable exceeds a
by the expected value of the variable divided by a.

13

Theorem 2.1 (Markov’s inequality) Let x be a nonnegative random variable. Then
for a > 0,

Prob(x ≥ a) ≤

E(x)
a

.

Proof: We prove the theorem for continuous random variables. So we use integrals. The
same proof works for discrete random variables with sums instead of integrals.

E (x) =

≥

∞
(cid:90)

0
∞
(cid:90)

a

xp(x)dx =

a
(cid:90)

0

xp(x)dx +

∞
(cid:90)

a

xp(x)dx ≥

∞
(cid:90)

a

xp(x)dx

ap(x)dx = a

∞
(cid:90)

a

p(x)dx = ap(x ≥ a)

Thus, Prob(x ≥ a) ≤ E(x)
a .

Corollary 2.2 Prob (x ≥ cE(x)) ≤ 1
c

Proof: Substitute cE(x) for a.

Markov’s inequality bounds the tail of a distribution using only information about the

mean. A tighter bound can be obtained by also using the variance.

Theorem 2.3 (Chebyshev’s inequality) Let x be a random variable with mean m and
variance σ2. Then

Prob(|x − m| ≥ aσ) ≤

1
a2 .

Proof: Prob(|x − m| ≥ aσ) = Prob (cid:0)(x − m)2 ≥ a2σ2(cid:1). Note that (x − m)2 is a nonneg-
ative random variable, so Markov’s inequality can be a applied giving:

Prob (cid:0)(x − m)2 ≥ a2σ2(cid:1) ≤

E (cid:0)(x − m)2(cid:1)
a2σ2

=

σ2
a2σ2 =

1
a2 .

Thus, Prob (|x − m| ≥ aσ) ≤ 1
a2 .

The law of large numbers follows from Chebyshev’s inequality. Recall that E(x + y) =
E(x) + E(y), σ2(cx) = c2σ2(x), σ2(x − m) = σ2(x), and if x and y are independent, then
E(xy) = E(x)E(y) and σ2(x + y) = σ2(x) + σ2(y). To prove σ2(x + y) = σ2(x) + σ2(y)
when x and y are independent, since σ2(x − m) = σ2(x), one can assume E(x) = 0 and
E(y) = 0. Thus,

σ2(x + y) = E (cid:0)(x + y)2(cid:1) = E(x2) + E(y2) + 2E(xy)

= E(x2) + E(y2) + 2E(x)E(y) = σ2(x) + σ2(y).

Replacing E(xy) by E(x)E(y) required independence.

14

1

√

2
2

1

1

1
2

1
2

√

d
2

1

1
2

Figure 2.4: Illustration of the relationship between the sphere and the cube in 2, 4, and
d-dimensions.

Theorem 2.4 (Law of large numbers) Let x1, x2, . . . , xn be n samples of a random
variable x. Then

Prob

(cid:18)(cid:12)
(cid:12)
(cid:12)
(cid:12)

x1 + x2 + · · · + xn
n

(cid:12)
(cid:12)
− E(x)
(cid:12)
(cid:12)

(cid:19)

> (cid:15)

≤

σ2
n(cid:15)2

Proof: By Chebychev’s inequality

Prob

(cid:18)(cid:12)
(cid:12)
(cid:12)
(cid:12)

x1 + x2 + · · · + xn
n

(cid:12)
(cid:12)
− E(x)
(cid:12)
(cid:12)

(cid:19)

> (cid:15)

≤

σ2 (cid:0) x1+x2+···+xn
(cid:15)2

n

(cid:1)

≤

≤

≤

1
n2(cid:15)2 σ2(x1 + x2 + · · · + xn)
1
n2(cid:15)2
σ2(x)
n(cid:15)2 .

(cid:0)σ2(x1) + σ2(x2) + · · · + σ2(xn)(cid:1)

The law of large numbers bounds the diﬀerence of the sample average and the expected
value. Note that the size of the sample for a given error bound is independent of the size
of the population class. In the limit, when the sample size goes to inﬁnity, the central
limit theorem says that the distribution of the sample average is Gaussian provided the
random variable has ﬁnite variance. Later, we will consider random variables that are
the sum of random variables. That is, x = x1 + x2 + · · · + xn. Chernoﬀ bounds will tell
us about the probability of x diﬀering from its expected value. We will delay this until
Section 11.4.11.

2.3 The High-Dimensional Sphere

One of the interesting facts about a unit-radius sphere in high dimensions is that
as the dimension increases, the volume of the sphere goes to zero. This has important

15

√

d
2

1

1
2

Unit radius sphere

Nearly all of the volume

Vertex of hypercube

Figure 2.5: Conceptual drawing of a sphere and a cube.

implications. Also, the volume of a high-dimensional sphere is essentially all contained in
a thin slice at the equator and simultaneously in a narrow annulus at the surface. There is
essentially no interior volume. Similarly, the surface area is essentially all at the equator.
These facts, which are contrary to our two or three-dimensional intuition, will be proved
by integration.

2.3.1 The Sphere and the Cube in High Dimensions

Consider the diﬀerence between the volume of a cube with unit-length sides and the
volume of a unit-radius sphere as the dimension d of the space increases. As the dimen-
sion of the cube increases, its volume is always one and the maximum possible distance
d. In contrast, as the dimension of a unit-radius sphere
between two points grows as
increases, its volume goes to zero and the maximum possible distance between two points
stays at two.

√

For d=2, the unit square centered at the origin lies completely inside the unit-radius

circle. The distance from the origin to a vertex of the square is

(cid:113)

2 )2
( 1

+( 1

2)2

=

√

2

2

∼= 0.707.

Here, the square lies inside the circle. At d=4, the distance from the origin to a vertex of
a unit cube centered at the origin is

(cid:113)

2)2
( 1

+( 1

2)2

+( 1

2)2

+( 1

2 )2 = 1.

Thus, the vertex lies on the surface of the unit 4-sphere centered at the origin. As the
dimension d increases, the distance from the origin to a vertex of the cube increases as
√
d
2 , and for large d, the vertices of the cube lie far outside the unit radius sphere. Figure
2.5 illustrates conceptually a cube and a sphere. The vertices of the cube are at distance

16

Figure 2.6: Volume of sphere in 2 and 3 dimensions.

√
d
2 from the origin and for large d lie outside the unit sphere. On the other hand, the mid
point of each face of the cube is only distance 1/2 from the origin and thus is inside the
sphere. For large d, almost all the volume of the cube is located outside the sphere.

2.3.2 Volume and Surface Area of the Unit Sphere

For ﬁxed dimension d, the volume of a sphere is a function of its radius and grows as
rd. For ﬁxed radius, the volume of a sphere is a function of the dimension of the space.
What is interesting is that the volume of a unit sphere goes to zero as the dimension of
the sphere increases.

To calculate the volume of a unit-radius sphere, one can integrate in either Cartesian

or polar coordinates. In Cartesian coordinates the volume of a unit sphere is given by

√
x2=
(cid:90)

1−x2
1

x1=1
(cid:90)

√

xd=

· · ·

V (d) =

1−···−x2

d−1

1−x2
(cid:90)

dxd · · · dx2dx1.

x1=−1

x2=−

√

1−x2
1

√

xd=−

1−x2

1−···−x2

d−1

Since the limits of the integrals are complicated, it is easier to integrate using polar
coordinates. First, lets work out what happens in polar coordinates for d = 2 and d = 3.
[See Figure (2.6).]
If d = 2, the volume is really the area (which we know to be π).
Consider a inﬁnitesimal radial triangle with the origin as the apex. The area between r
and r + dr of this triangle is bounded by two parallel arcs and two radial lines and since
the (inﬁnitesimal) arcs are perpendicular to the radius, the area of this piece is just dΩdr,
where, dΩ is the arc length. In three dimensions, dΩ is the area (2-dimensional volume)
and again, the surface of dΩ is perpendicular to the radial direction, so the volume of the
piece is dΩdr.

In polar coordinates, V (d) is given by

V (d) =

(cid:90)

1
(cid:90)

Sd

r=0

rd−1drdΩ.

Here, dΩ is the surface area of the inﬁnitesimal piece of the solid angle Sd of the unit
sphere. See Figure 2.7. The convex hull of the dΩ piece and the origin form a cone. At
radius r, the surface area of the top of the cone is rd−1dΩ since the surface area is d − 1
dimensional and each dimension scales by r. The volume of the inﬁnitesimal piece is base
times height, and since the surface of the sphere is perpendicular to the radial direction
at each point, the height is dr giving the above integral.

17

dΩ

dr

r

rd−1dΩ

dr

Figure 2.7: Inﬁnitesimal volume in a d-dimensional sphere of unit radius.

Since the variables Ω and r do not interact,

V (d) =

1
(cid:90)

(cid:90)

dΩ

Sd

r=0

rd−1dr =

1
d

(cid:90)

Sd

dΩ =

A(d)
d

where A(d) is the surface area of a d-dimensional unit-radius sphere. The question re-
mains, how to determine the surface area A (d) = (cid:82)
Sd

dΩ.

Consider a diﬀerent integral

∞
(cid:90)

∞
(cid:90)

∞
(cid:90)

· · ·

I (d) =

−∞

−∞

−∞

e−(x2

1+x2

2+···x2

d)dxd · · · dx2dx1.

Including the exponential allows integration to inﬁnity rather than stopping at the surface
of the sphere. Thus, I(d) can be computed by integrating in both Cartesian and polar
coordinates. Integrating in polar coordinates will relate I(d) to the surface area A(d).
Equating the two results for I(d) allows one to solve for A(d).

First, calculate I(d) by integration in Cartesian coordinates.

I (d) =


d

e−x2dx



∞
(cid:90)





−∞

= (cid:0)√

π(cid:1)d = π

d
2 .

Here, we have used the fact that (cid:82) ∞
π. For a proof of this, see Section ??
of the appendix. Next, calculate I(d) by integrating in polar coordinates. The volume of
the diﬀerential element is rd−1dΩdr. Thus,

−∞ e−x2 dx =

√

I (d) =

(cid:90)

Sd

∞
(cid:90)

dΩ

e−r2rd−1dr.

0

18

Cartesian coordinates

V (d) =

(cid:90) (cid:90)

(cid:90)

· · ·

dxd · · · dx1

(cid:124)

(cid:123)(cid:122)
too hard because of limits

(cid:125)

I (d) =


d

e−x2dx



= π

∞
(cid:90)





−∞

(cid:124)

(cid:123)(cid:122)
evaluate I(d) instead

d
2

(cid:125)

Polar coordinates

V (d) =

1
(cid:90)

(cid:90)

dΩ

Sd

r=0

rd−1dr =

A(d)
d

(cid:109) equate and solve for A(d)

I (d) =

dΩ

∞
(cid:90)

0

(cid:90)

Sd

e−r2rd−1dr = A(d)

(cid:19)

1
2

Γ

(cid:18) d
2

⇐=

substitute value of A(d)
into formula for V (d)

Equate integrals for I(d) in Cartesian and polar coordinates and solve for A(d).
Substitute A(d) into the formula for volume of the sphere obtained by integrating in
polar coordinates. This gives the result for V (d).

Figure 2.8: Strategy for calculating the volume of a d-dimensional sphere.

dΩ is the integral over the entire solid angle and gives the surface area,

A(d), of a unit sphere. Thus, I (d) = A (d)

e−r2rd−1dr. Evaluating the remaining

∞
(cid:82)

0

The integral (cid:82)
Sd

integral gives

∞
(cid:90)

e−r2rd−1dr =

∞
(cid:90)

1
2

e−tt

d

2 − 1dt =

(cid:19)

1
2

Γ

(cid:18) d
2

0
(cid:1) where the gamma function Γ (x) is a generalization of the
and hence, I(d) = A(d) 1
factorial function for noninteger values of x. Γ (x) = (x − 1) Γ (x − 1), Γ (1) = Γ (2) = 1,
and Γ (cid:0) 1

π. For integer x, Γ (x) = (x − 1)!.

2Γ (cid:0) d

(cid:1) =

√

2

0

2

Combining I (d) = π

d
2 with I (d) = A (d) 1

2Γ (cid:0) d

2

(cid:1) yields

A (d) =

establishing the following lemma.

d
2

π
2Γ (cid:0) d

1

2

(cid:1)

Lemma 2.5 The surface area A(d) and the volume V (d) of a unit-radius sphere in d

19

dimensions are given by

A (d) =

2π d
2
(cid:1)
Γ (cid:0) d

2

and

V (d) =

2
d

2

π d
Γ (cid:0) d

2

(cid:1) .

= 4

3
π
2
2 )
Γ( 3

V (3) = 2
3

To check the formula for the volume of a unit sphere, note that V (2) = π and
3π, which are the correct volumes for the unit spheres in two and
three dimensions. To check the formula for the surface area of a unit sphere, note that
3
A(2) = 2π and A(3) = 2π
2
= 4π, which are the correct surface areas for the unit sphere
√
π
(cid:1) grows as the
in two and three dimensions. Note that π d
factorial of d

2 is an exponential in d

V (d) = 0, as claimed.

2 and Γ (cid:0) d

1
2

2

2 . This implies that lim
d→∞

The volume of a d-dimensional sphere of radius r grows as rd. This follows since the
unit sphere can be mapped to a sphere of radius r by the linear transformation speciﬁed
by a diagonal matrix with diagonal elements r. The determinant of this matrix is rd. See
Section 2.4. Since the surface area is the derivative of the volume, the surface area grows
as rd−1. See last paragraph of Section 2.3.5.

The proof of Lemma 2.5 illustrates the relationship between the surface area of the

sphere and the Gaussian probability density

1
√
2π

e−(x1+x2+···+xd)2/2.

This relationship is an important one and will be used several times in this chapter.

2.3.3 The Volume is Near the Equator

Consider a high-dimensional unit-radius sphere and ﬁx the North Pole on the x1 axis
at x1 = 1. Divide the sphere in half by intersecting it with the plane x1 = 0. The
intersection of the plane with the sphere forms a region of one lower dimension, namely
(cid:8)x (cid:12)
(cid:12) |x| ≤ 1, x1 = 0(cid:9) , called the equator. The intersection is a sphere of dimension d − 1
and has volume V (d − 1). In three dimensions this region is a circle, in four dimensions
the region is a 3-dimensional sphere, etc. In our terminology, a circle is a 2-dimensional
sphere and its volume is what one usually refers to as the area of a circle. The surface
area of the 2-dimensional sphere is what one usually refers to as the circumference of a
circle.

It turns out that essentially all of the volume of the upper hemisphere lies between
the plane x1 = 0 and a parallel plane, x1 = ε, that is slightly higher. For what value of
ε does essentially all the volume lie between x1 = 0 and x1 = ε? The answer depends
on the dimension. For dimension d, it is O(
). Before we prove this, some intuition
is in order. Since |x|2 = x2
2 + · · · + x2
1 + x2
i ’s to be
generally equal (or close to each other), we expect each x2
i to be at most O(1/d). Now for

d and by symmetry, we expect the x2

1√

d−1

20

dx1

x1

1

1 radius of

(cid:112)1 − x2
(d − 1)-dimensional
sphere

Figure 2.9: The volume of a cross-sectional slab of a d-dimensional sphere.

the proof, we compute the ratio of the volume above the slice lying between x1 = 0 and
x1 = (cid:15) and the volume of the entire upper hemisphere. Actually we compute the ratio of
an upper bound on the volume above the slice and a lower bound on the volume of the
entire hemisphere and show that this ratio is very small when (cid:15) is Ω(

1√

).

d−1

Volume above slice
Volume upper hemisphere

≤

Upper bound on volume above slice
Lower bound on volume upper hemisphere

Let T = (cid:8)x (cid:12)

(cid:12) |x| ≤ 1, x1 ≥ ε(cid:9) be the portion of the sphere above the slice. To calculate
the volume of T , integrate over x1 from ε to 1. The incremental volume is a disk of width
dx1 whose face is a (d−1)-dimensional sphere of radius (cid:112)1 − x2
1. See Figure 2.9. Therefore,
the surface area of the disk is

(cid:0)1 − x2

1

(cid:1) d−1

2 V (d − 1)

and

Volume (T ) =

1
(cid:90)

ε

(cid:0)1 − x2

1

(cid:1) d−1

2 V (d − 1) dx1 = V (d − 1)

(cid:0)1 − x2

1

(cid:1) d−1

2 dx1.

1
(cid:90)

ε

Note that V (d) denotes the volume of the d-dimensional unit sphere. For the volume of
other sets such as the set T , we use the notation Volume(T ) for the volume.

The above integral is diﬃcult to evaluate, so we use some approximations. First, we
use the inequality 1 + x ≤ ex for all real x and change the upper bound on the integral
to inﬁnity. Since x1 is always greater than ε over the region of integration, we can insert
x1/ε in the integral. This gives

Volume (T ) ≤ V (d − 1)

∞
(cid:90)

e−

d−1

2 x2

1dx1

≤ V (d − 1)

ε
∞
(cid:90)

ε

x1
ε

e−

21

d−1

2 x2

1dx1.

Now, (cid:82) x1e− d−1

2 x2

1 dx1 = − 1

d−1e− d−1

2 x2

1 and, hence,

Volume (T ) ≤ 1

ε(d−1)e−

d−1

2 ε2

V (d − 1) .

(2.2)

The actual volume of the upper hemisphere is exactly 1

2V (d). However, we want the
volume in terms of V (d − 1) instead of V (d) so we can cancel the V (d − 1) in the upper
bound of the volume above the slice. We do this by calculating a lower bound on the
volume of the entire upper hemisphere. Clearly, the volume of the upper hemisphere is at
least the volume between the slabs x1 = 0 and x1 = 1√
, which is at least the volume of
1 − 1

. The volume of the cylinder is 1/

the cylinder of radius

d − 1

1√

(cid:113)

d−1

√

d−1 and height

d−1

times the d − 1-dimensional volume of the disk R =

a d − 1-dimensional sphere of radius

(cid:113)

1 − 1

d−1 and so its volume is

(cid:110)

x (cid:12)

(cid:12) |x| ≤ 1; x1 = 1√

d−1

(cid:111)

. Now R is

Volume(R) = V (d − 1)

1 −

(cid:18)

(cid:19)(d−1)/2

.

1
d − 1

Using (1 − x)a ≥ 1 − ax

Volume(R) ≥ V (d − 1)

1 −

(cid:18)

1
d − 1

d − 1
2

(cid:19)

=

1
2

V (d − 1).

Thus, the volume of the upper hemisphere is at least

√

1
d−1

2

V (d − 1).

The fraction of the volume above the plane x1 = ε is upper bounded by the ratio of the
upper bound on the volume of the hemisphere above the plane x1 = ε to the lower bound
e− d−1
on the total volume. This ratio is

2 ε2 which leads to the following lemma.

√
ε

2
(d−1)

Lemma 2.6 For any c > 0, the fraction of the volume of the unit hemisphere above the
plane x1 = c√

is less than 2

c e−c2/2.

d−1

Proof: Substitute

c√

d−1

for ε in the above.

For a large constant c, 2

c e−c2/2 is small. However, if c is large relative to

d − 1, the
band is not narrow. In fact, if c =
d − 1, the band is the entire sphere. The important
item to remember is that most of the volume of the d-dimensional unit sphere lies within
distance O(1/
d) of the equator. If the sphere is of radius r, then the upper bound on
the volume above x1 = (cid:15) becomes

√

√

√

V (d−1)

(cid:90) r

ε

(r2−x2

1)(d−1)/2dx1 = V (d−1)rd−1

(cid:90) r

ε

(1−(x2

1/r2))(d−1)/2 ≤ V (d−1)rd−1

(cid:90)

ε

x1
ε

e−x2

1(d−1)/2r2dx1,

22

r

0( r√
d

)

Figure 2.10: Most of the volume of the d-dimensional sphere of radius r is within distance
O( r√
d

) of the equator.

from which we see that the upper bound increases by a factor of rd+1. The lower bound
on the volume of the upper hemisphere increases by rd, which results in an upper bound
on the fraction above the plane x1 = (cid:15) of

2r
d − 1

√
(cid:15)

e− d−1

2

(cid:15)2
r2 .

cr√

Substituting
d−1
r sphere lies within distance O( r√
d

for (cid:15), results in a bound of 2

c e− c2

) of the equator as shown in Figure 2.10.

2 . Thus, most of the volume of a radius

For c ≥ 2, the fraction of the volume of the hemisphere above x1 = c√

is less than
2e−8 ≈ 3 × 10−4. Essentially all the

d−1

e−2 ≈ 0.14 and for c ≥ 4 the fraction is less than 1
volume of the sphere lies in a narrow band at the equator.

Note that we selected a unit vector in the x1 direction and deﬁned the equator to
be the intersection of the sphere with a (d − 1)-dimensional plane perpendicular to the
unit vector. However, we could have selected an arbitrary point on the surface of the
sphere and considered the vector from the center of the sphere to that point and deﬁned
the equator using the plane through the center perpendicular to this arbitrary vector.
Essentially all the volume of the sphere lies in a narrow band about this equator also.

2.3.4 The Volume is in a Narrow Annulus

The ratio of the volume of a sphere of radius 1 − ε to the volume of a unit sphere in

d-dimensions is

(1 − ε)dV (d)
V (d)

= (1 − ε)d,

and thus goes to zero as d goes to inﬁnity when ε is a ﬁxed constant. In high dimensions,
all of the volume of the sphere is concentrated in a narrow annulus at the surface.

23

1

1 − (cid:15)

Annulus of
width 1
d

Figure 2.11: Most of the volume of the d-dimensional sphere of radius r is contained in
an annulus of width O(r/d) near the boundary.

Since, (1 − ε)d ≤ e−εd, if ε = c

d , for a large constant c, all but e−c of the volume of the
sphere is contained in a thin annulus of width c/d. The important item to remember is
that most of the volume of the d-dimensional unit sphere is contained in an annulus of
width O(1/d) near the boundary. If the sphere is of radius r, then for suﬃciently large d,
the volume is contained in an annulus of width O (cid:0) r

(cid:1) .

d

2.3.5 The Surface Area is Near the Equator

Just as a 2-dimensional circle has an area and a circumference and a 3-dimensional
sphere has a volume and a surface area, a d-dimensional sphere has a volume and a surface
area. The surface of the sphere is the set (cid:8)x (cid:12)
(cid:12) |x| = 1(cid:9). The surface of the equator is the
set (cid:8)x (cid:12)
(cid:12) |x| = 1, x1 = 0(cid:9) and it is the surface of a sphere of one lower dimension, i.e., for a
3-dimensional sphere, it is the circumference of a circle. Just as with volume, essentially
all the surface area of a high-dimensional sphere is near the equator. To see this, we use
an analogous argument to that used for volume.

First, upper bound the surface area of the sphere above x1 = ε. Let S = (cid:8)x (cid:12)

(cid:12) |x| = 1, x1 ≥ ε(cid:9).

To calculate the surface area S of the sphere above x1 = ε, integrate x1 from ε to 1. The
incremental surface unit will be a band of width dx1 whose edge is the surface area of a
(d − 1)-dimensional sphere of radius depending on x1. The radius of the band is (cid:112)1 − x2
and therefore, the surface area of the (d − 1)-dimensional sphere is

1

A (d − 1) (cid:0)1 − x2

1

(cid:1) d−2
2

where A(d − 1) is the surface area of a unit sphere of dimension d − 1. The slice is not a
cylinder since when x1 increases by dx1, the radius r decreases by dr. Thus,

A(S) = A(d − 1)

(cid:90) 1

(cid:15)

(1 − x2
1)

d−2

2 ds

24

where ds2 = dr2 + dx2

1. Since r = (cid:112)1 − x2

1, dr = −x1√
1−x2
1

dx1 and hence

ds2 =

(cid:18) x2
1
1 − x2
1

(cid:19)

+ 1

dx2

1 =

1
1 − x2
1

dx2
1

and ds = 1√

1−x2
1

dx1. Thus,

A(S) = A(d − 1)

(cid:90) 1

(1 − x2
1)

d−3

2 dx1.

(cid:15)
The above integral is diﬃcult to integrate and the same approximations, as in the earlier
section on volume, lead to the bound

A (S) ≤ 1

ε(d−3)e−

d−3

2 ε2

A (d − 1) .

(2.3)

Next, lower bound the surface area of the entire upper hemisphere. Clearly, the surface
area of the upper hemisphere is greater than the surface area of the side of a d-dimensional
cylinder of height

d−2. The surface area of the cylinder is

and radius

1 − 1

1√

1√

(cid:113)

times the circumference area of the d-dimensional cylinder of radius

d−2

d−2
d−2 which is
2 . Using (1 − x)a ≥ 1 − ax, the surface area of the hemisphere is at

1 − 1

(cid:113)

A(d − 1)(1 − 1
least

d−2) d−2

√

1
d − 2

(1 −

1
d − 2

d−2
2 A(d − 1) ≥

)

≥

√

1
d − 2
1
d − 2

√
2

(1 −

d − 2
2

1
d − 2

)A(d − 1)

A(d − 1).

(2.4)

Comparing the upper bound on the surface area of S in (2.3) with the lower bound on
the surface area of the hemisphere in (2.4), we see that the surface area above the band
(cid:8)x (cid:13)
e−
4
d−3
Lemma 2.7 For any c > 0, the fraction of the surface area above the plane x1 = c√

(cid:13) |x| = 1, 0 ≤ x1 ≤ ε(cid:9) is less than

of the total surface area.

2 ε2

√
ε

d−3

is

d−2

less than or equal to 4

c e−

c2
2 .

Proof: Substitute

c√

d−2

for ε in the above.

We conclude this section by relating the surface area and volume of a d-dimensional
sphere. So far, we have considered unit-radius spheres of dimension d. Now ﬁx the
dimension d and vary the radius r. Let V (d, r) denote the volume and let A(d, r) denote
the surface area of a d-dimensional sphere of radius r. Then,

(cid:90) r

V (d, r) =

A(d, x)dx.

x=0
Thus, it follows that the surface area is the derivative of the volume with respect to the
radius. In two dimensions, the volume of a circle is πr2 and the circumference is 2πr. In
three dimensions, the volume of a sphere is 4

3πr3 and the surface area is 4πr2.

25

2.4 Volumes of Other Solids

There are very few high-dimensional solids for which there are closed-form formulae

for the volume. The volume of the rectangular solid

R = {x|l1 ≤ x1 ≤ u1, l2 ≤ x2 ≤ u2, . . . , ld ≤ xd ≤ ud}

is the product of the lengths of its sides. Namely, it is

d
(cid:81)
i=1

(ui − li).

A parallelepiped is a solid described by

P = {x | l ≤ Ax ≤ u}

where A is an invertible d × d matrix, and l and u are lower and upper bound vectors,
respectively. The statements l ≤ Ax and Ax ≤ u are to be interpreted row by row
asserting 2d inequalities. A parallelepiped is a generalization of a parallelogram. It is
easy to see that P is the image under an invertible linear transformation of a rectangular
solid. Let

R = {y | l ≤ y ≤ u}.

The map x = A−1y maps R to P . This implies that
(cid:12)Det(A−1)(cid:12)

Volume(P ) = (cid:12)

(cid:12) Volume(R).

Simplices, which are generalizations of triangles, are another class of solids for which
volumes can be easily calculated. Consider the triangle in the plane with vertices
{(0, 0), (1, 0), (1, 1)}, which can be described as {(x, y) | 0 ≤ y ≤ x ≤ 1}.
Its area is
1/2 because two such right triangles can be combined to form the unit square. The
generalization is the simplex in d-space with d + 1 vertices,

{(0, 0, . . . , 0), (1, 0, 0, . . . , 0), (1, 1, 0, 0, . . . 0), . . . , (1, 1, . . . , 1)},

which is the set

S = {x | 1 ≥ x1 ≥ x2 ≥ · · · ≥ xd ≥ 0}.

How many copies of this simplex exactly ﬁt into the unit square, {x | 0 ≤ xi ≤ 1}?
Every point in the square has some ordering of its coordinates. Since there are d! order-
ings, exactly d! simplices ﬁt into the unit square. Thus, the volume of each simplex
is 1/d!. Now consider the right angle simplex R whose vertices are the d unit vec-
tors (1, 0, 0, . . . , 0), (0, 1, 0, . . . , 0), . . . , (0, 0, 0, . . . , 0, 1) and the origin. A vector y in R
is mapped to an x in S by the mapping: xd = yd; xd−1 = yd + yd−1;
; x1 =
y1 + y2 + · · · + yd. This is an invertible transformation with determinant one, so the
volume of R is also 1/d!.

. . .

A general simplex is obtained by a translation, adding the same vector to every point,
followed by an invertible linear transformation on the right simplex. Convince yourself

26

that in the plane every triangle is the image under a translation plus an invertible linear
transformation of the right triangle. As in the case of parallelepipeds, applying a linear
transformation A multiplies the volume by the determinant of A. Translation does not
change the volume. Thus, if the vertices of a simplex T are v1, v2, . . . , vd+1, then trans-
lating the simplex by −vd+1 results in vertices v1 − vd+1, v2 − vd+1, . . . , vd − vd+1, 0. Let
A be the d × d matrix with columns v1 − vd+1, v2 − vd+1, . . . , vd − vd+1. Then, A−1T = R
and AR = T where R is the right angle simplex. Thus, the volume of T is 1

d! |Det(A)|.

2.5 Generating Points Uniformly at Random on the Surface of

a Sphere

Consider generating points uniformly at random on the surface of a unit-radius sphere.
First, consider the 2-dimensional version of generating points on the circumference of a
unit-radius circle by the following method. Independently generate each coordinate uni-
formly at random from the interval [−1, 1]. This produces points distributed over a square
that is large enough to completely contain the unit circle. Project each point onto the
unit circle. The distribution is not uniform since more points fall on a line from the origin
to a vertex of the square than fall on a line from the origin to the midpoint of an edge
of the square due to the diﬀerence in length. To solve this problem, discard all points
outside the unit circle and project the remaining points onto the circle.

One might generalize this technique in the obvious way to higher dimensions. However,
the ratio of the volume of a d-dimensional unit sphere to the volume of a d-dimensional
2 by 2 cube decreases rapidly making the process impractical for high dimensions since
almost no points will lie inside the sphere. The solution is to generate a point each
of whose coordinates is a Gaussian variable. The probability distribution for a point
(x1, x2, . . . , xd) is given by

p (x1, x2, . . . , xd) =

1+x2
x2

2+···+x2
d
2

e−

1

d
2

(2π)

and is spherically symmetric. Normalizing the vector x = (x1, x2, . . . , xd) to a unit vec-
tor gives a distribution that is uniform over the sphere. Note that once the vector is
normalized, its coordinates are no longer statistically independent.

2.6 Gaussians in High Dimension

A 1-dimensional Gaussian has its mass close to the origin. However, as the dimension
is increased something diﬀerent happens. The d-dimensional spherical Gaussian with zero
mean and variance σ2 has density function

p(x) =

1
(2π)d/2 σd

exp

(cid:16)

− |x|2
2σ2

(cid:17)

.

27

The value of the Gaussian is maximum at the origin, but there is very little volume
there. When σ2 = 1, integrating the probability density over a unit sphere centered at
the origin yields nearly zero mass since the volume of a unit sphere is negligible. In fact,
d before there is a signiﬁcant nonzero
one needs to increase the radius of the sphere to
volume and hence a nonzero probability mass. If one increases the radius beyond
d,
the integral ceases to increase, even though the volume increases, since the probability
density is dropping oﬀ at a much higher rate. The natural scale for the Gaussian is in
units of σ

√

√

√

d.

Expected squared distance of a point from the center of a Gaussian

Consider a d-dimensional Gaussian centered at the origin with variance σ2. For a point
x = (x1, x2, . . . , xd) chosen at random from the Gaussian, the expected squared length of
x is

E (cid:0)x2

1 + x2

2 + · · · + x2
d

(cid:1) = d E (cid:0)x2

(cid:1) = dσ2.

1

For large d, the value of the squared length of x is tightly concentrated about its mean and
thus, although E(x2) (cid:54)= E2(x), E(x) ≈ (cid:112)E(x2). We call the square root of the expected
squared distance σ
d the radius of the Gaussian. In the rest of this section, we consider
spherical Gaussians with σ = 1. All results can be scaled up by σ.

√

The probability mass of a unit-variance Gaussian as a function of the distance from
its center is given by rd−1e−r2/2 times some constant normalization factor where r is the
distance from the center and d is the dimension of the space. The probability mass
function has its maximum at

√

r =

d − 1,

which can be seen from setting the derivative equal to zero.

∂

∂r rd−1e−

r2
2 = (d − 1)rd−2e−

r2
2 − rde−

r2
2 = 0

Dividing by rd−2e− r2

2 , yields r2 = d − 1.

Width of the annulus

The Gaussian distribution in high dimensions, centered at the origin, has its maxi-
mum value at the origin. However, there is no probability mass in a sphere of radius one
centered at the origin since the sphere has zero volume. In fact, there is no probability
mass until one gets suﬃciently far from the origin so a sphere of that radius has nonzero
volume. This occurs at radius
d. Once one gets a little farther from the origin there
is again no probability mass since the probability distribution is dropping exponentially
fast and the volume of the sphere is only increasing polynomially fast. All the probability
mass is in a narrow annulus of radius approximately
d. In Section 2.7 we prove that
d, all but 3e−cβ2 of the mass lies within the annulus
for any positive real number β <
√
√

√

√

√

d − β ≤ r ≤

d + β. See Theorem 2.10.

28

Separating Gaussians

Gaussians are often used to model data. A common stochastic model is the mixture
model where one hypothesizes that the data is generated from a convex combination of
simple probability densities. An example is two Gaussian densities p1(x) and p2(x) where
data is drawn from the mixture p(x) = w1p1(x) + w2p2(x) with positive weights w1 and
w2 summing to one. Assume that p1 and p2 are spherical with unit variance. If their
means are very close, then given data from the mixture, one cannot tell for each data
point whether it came from p1 or p2. The question arises as to how much separation is
needed between the means to determine which Gaussian generated which data point. We
will see that a separation of Ω(d1/4) suﬃces. The algorithm to separate two Gaussians is
simple. Calculate the distance between all pairs of points. Points whose distance apart
is smaller are from the same Gaussian, points whose distance is larger are from diﬀerent
Gaussians. Later, we will see that with more sophisticated algorithms, even a separation
of Ω(1) suﬃces.

√

i e−x2

Consider two spherical unit-variance Gaussians. From Theorem 2.10, most of the
d − 1. Also
probability mass of each Gaussian lies on an annulus of width O(1) at radius
e−|x|2/2 = (cid:81)
i /2 and almost all of the mass is within the slab { x | − c ≤ x1 ≤ c }, for
c ∈ O(1). Pick a point x from the ﬁrst Gaussian. After picking x, rotate the coordinate
system to make the ﬁrst axis point towards x. Independently pick a second point y also
from the ﬁrst Gaussian. The fact that almost all of the mass of the Gaussian is within
the slab {x | − c ≤ x1 ≤ c, c ∈ O(1)} at the equator implies that y’s component along
x’s direction is O(1) with high probability. Thus, y is nearly perpendicular to x. So,
|x − y| ≈ (cid:112)|x|2 + |y|2. See Figure 2.12. More precisely, since the coordinate system
has been rotated so that x is at the North Pole, x = (
d ± O(1), 0, . . . , 0). Since y is
almost on the equator, further rotate the coordinate system so that the component of
y that is perpendicular to the axis of the North Pole is in the second coordinate. Then
y = (O(1),

√

√

d ± O(1), 0, . . . , 0). Thus,
√

(x − y)2 = d ± O(

d) + d ± O(

√

d) = 2d ± O(

√

d)

and |x − y| =

√

2d ± O(1).

Given two spherical unit variance Gaussians with centers p and q separated by a
distance δ, the distance between a randomly chosen point x from the ﬁrst Gaussian and
δ2 + 2d, since x − p, p − q, and
a randomly chosen point y from the second is close to
q − y are nearly mutually perpendicular. Pick x and rotate the coordinate system so
that x is at the North Pole. Let z be the North Pole of the sphere approximating the
second Gaussian. Now pick y. Most of the mass of the second Gaussian is within O(1)
of the equator perpendicular to q − z. Also, most of the mass of each Gaussian is within
distance O(1) of the respective equators perpendicular to the line q − p. See Figure 2.13.

√

29

√

d

√

2d

√

d

Figure 2.12: Two randomly chosen points in high dimension are almost surely nearly
orthogonal.

Thus,

|x − y|2 ≈ δ2 + |z − q|2 + |q − y|2
= δ2 + 2d ± O(

d)).

√

To ensure that the distance between two points picked from the same Gaussian are
closer to each other than two points picked from diﬀerent Gaussians requires that the
upper limit of the distance between a pair of points from the same Gaussian is at most
the lower limit of distance between points from diﬀerent Gaussians. This requires that
√
√
d) ≤ 2d + δ2, which holds when δ ∈ Ω(d1/4).
Thus, mixtures of spherical Gaussians can be separated, provided their centers are sepa-
rated by more than d 1
4 . One can actually separate Gaussians where the centers are much
closer. Chapter 4 contains an algorithm that separates a mixture of k spherical Gaussians
whose centers are much closer.

2d + δ2 − O(1) or 2d + O(

2d + O(1) ≤

√

Algorithm for separating points from two Gaussians

Calculate all pairwise distances between points. The cluster of smallest
pairwise distances must come from a single Gaussian. Remove these
points. The remaining points come from the second Gaussian.

Fitting a single spherical Gaussian to data

Given a set of sample points, x1, x2, . . . , xn, in a d-dimensional space, we wish to ﬁnd
the spherical Gaussian that best ﬁts the points. Let F be the unknown Gaussian with

30

√

d

x

p

δ

√

δ2 + 2d

δ

√

2d

y

z

q

Figure 2.13: Distance between a pair of random points from two diﬀerent unit spheres
approximating the annuli of two Gaussians.

mean µ and variance σ2 in each direction. The probability of picking these points when
sampling according to F is given by

(cid:32)

c exp

−

(x1 − µ)2 + (x2 − µ)2 + · · · + (xn − µ)2
2σ2

(cid:33)

where the normalizing constant c is the reciprocal of

(cid:20)

(cid:21)n
. In integrating from

2σ2 dx

(cid:82) e− |x−µ|2
(cid:20)

(cid:21)−n

(cid:82) e− |x|2

2σ2 dx

= 1
(2π)

n
2

and is

−∞ to ∞, one could shift the origin to µ and thus c is

independent of µ.

The Maximum Likelihood Estimator (MLE) of F, given the samples x1, x2, . . . , xn, is

the F that maximizes the above probability.

Lemma 2.8 Let {x1, x2, . . . , xn} be a set of n points in d-space. Then (x1 − µ)2 +
(x2 − µ)2+· · ·+(xn − µ)2 is minimized when µ is the centroid of the points x1, x2, . . . , xn,
namely µ = 1

n (x1 + x2 + · · · + xn).

Proof: Setting the gradient of (x1 − µ)2 + (x2 − µ)2 + · · · + (xn − µ)2 with respect µ to
zero yields

−2 (x1 − µ) − 2 (x2 − µ) − · · · − 2 (xn − µ) = 0.

Solving for µ gives µ = 1

n (x1 + x2 + · · · + xn).

To determine the maximum likelihood estimate of σ2 for F , set µ to the true centroid.
Next, we show that σ is set to the standard deviation of the sample. Substitute ν = 1
2σ2

31

and a = (x1 − µ)2 + (x2 − µ)2 + · · · + (xn − µ)2 into the formula for the probability of
picking the points x1, x2, . . . , xn. This gives

e−aν

e−x2νdx

(cid:21)n .

(cid:20)
(cid:82)

x

Now, a is ﬁxed and ν is to be determined. Taking logs, the expression to maximize is

−aν − n ln



e−νx2dx

 .



(cid:90)



x

To ﬁnd the maximum, diﬀerentiate with respect to ν, set the derivative to zero, and solve
for σ. The derivative is

(cid:82)

|x|2e−νx2dx

−a + n

x

Setting y = |

√

νx| in the derivative, yields

−a +

n
ν

(cid:82)

x

(cid:82)

e−νx2dx

.

y2e−y2dy

.

e−y2dy

y

(cid:82)

y

Since the ratio of the two integrals is the expected distance squared of a d-dimensional
spherical Gaussian of standard deviation 1√
2 , we
2
get −a + nd
2ν . Substituting σ2 for 1
2ν gives −a + ndσ2. Setting −a + ndσ2 = 0 shows that
the maximum occurs when σ =
. Note that this quantity is the square root of the
average coordinate distance squared of the samples to their mean, which is the standard
deviation of the sample. Thus, we get the following lemma.

to its center, and this is known to be d

a
nd

√
√

Lemma 2.9 The maximum likelihood spherical Gaussian for a set of samples is the one
with center equal to the sample mean and standard deviation equal to the standard devia-
tion of the sample from the true mean.

Let x1, x2, . . . , xn be a sample of points generated by a Gaussian probability distri-
bution. µ = 1
n (x1 + x2 + · · · + xn) is an unbiased estimator of the expected value of
the distribution. However, if in estimating the variance from the sample set, we use the
estimate of the expected value rather than the true expected value, we will not get an
unbiased estimate of the variance, since the sample mean is not independent of the sam-
ple set. One should use µ = 1
n−1(x1 + x2 + · · · + xn) when estimating the variance. See
Section ?? of the appendix.

32

2.7 Bounds on Tail Probability

Markov’s inequality bounds the tail probability of a nonnegative random variable x

based only on its expectation. For a > 0,

Prob(x > a) ≤

E(x)
a

.

As a grows, the bound drops oﬀ as 1/a. Given the second moment of x, Chebyshev’s
inequality, which does not assume x is a nonnegative random variable, gives a tail bound
falling oﬀ as 1/a2

Prob(|x − E(x)| ≥ a) ≤

E

(cid:16)(cid:0)x − E(x)(cid:1)2(cid:17)
a2

.

Higher moments yield bounds by applying either of these two theorems. For example,
if r is a nonnegative even integer, then xr is a nonnegative random variable even if x takes
on negative values. Applying Markov’s inequality to xr,

Prob(|x| ≥ a) = Prob(xr ≥ ar) ≤

E(xr)
ar

,

a bound that falls oﬀ as 1/ar. The larger the r, the greater the rate of fall, but a bound
on E(xr) is needed to apply this technique.

For a random variable x that is the sum of a large number of independent random
variables, x1, x2, . . . , xn, one can derive bounds on E(xr) for high even r. There are many
situations where the sum of a large number of independent random variables arises. For
example, xi may be the amount of a good that the ith consumer buys, the length of the ith
message sent over a network, or the indicator random variable of whether the ith record
in a large database has a certain property. Each xi is modeled by a simple probability
distribution. Gaussian, exponential (probability density at any t > 0 is e−t), or binomial
distributions are typically used, in fact, respectively in the three examples here. If the xi
have 0-1 distributions, there are a number of theorems called Chernoﬀ bounds, bounding
the tails of x = x1 + x2 + · · · + xn, typically proved by the so-called moment-generating
function method (see Section 11.4.11 of the appendix). But exponential and Gaussian ran-
dom variables are not bounded and these methods do not apply. However, good bounds
on the moments of these two distributions are known. Indeed, for any integer s > 0, the
sth moment for the unit variance Gaussian and the exponential are both at most s!.

Given bounds on the moments of individual xi the following theorem proves moment
bounds on their sum. We use this theorem to derive tail bounds not only for sums of 0-1
random variables, but also Gaussians, exponentials, Poisson, etc.

The gold standard for tail bounds is the central limit theorem for independent, iden-
tically distributed random variables x1, x2, · · · , xn with zero mean and Var(xi) = σ2 that

33

states as n → ∞ the distribution of x = (x1 + x2 + · · · + xn)/
n tends to the Gaus-
sian density with zero mean and variance σ2. Loosely, this says that in the limit, the
tails of x = (x1 + x2 + · · · + xn)/
n are bounded by that of a Gaussian with variance
σ2. But this theorem is only in the limit, whereas, we prove a bound that applies for all n.

√

√

In the following theorem, x is the sum of n independent, not necessarily identically
distributed, random variables x1, x2, . . . , xn, each of zero mean and variance at most σ2.
By the central limit theorem, in the limit the probability density of x goes to that of
the Gaussian with variance at most nσ2. In a limit sense, this implies an upper bound
of ce−a2/(2nσ2) for the tail probability Prob(|x| > a) for some constant c. The following
theorem assumes bounds on higher moments, but asserts a quantitative upper bound of
3e−a2/(8nσ2) on the tail probability, not just in the limit, but for every n. We will apply
this theorem to get tail bounds on sums of Gaussian, binomial, and power law distributed
random variables.

Theorem 2.10 Let x = x1 + x2 + · · · + xn, where x1, x2, . . . , xn are mutually independent
random variables with zero mean and variance at most σ2. If for 3 ≤ s ≤ (a2/4nσ2),
|E(xs

i )| ≤ σ2s!, then for 0 ≤ a ≤

2nσ2),

√

Prob (|x1 + x2 + · · · xn| ≥ a) ≤ 3e−a2/(8nσ2).

Proof: We ﬁrst prove an upper bound on E(xr) for any even positive integer r and then
use Markov’s inequality as discussed earlier. Expand (x1 + x2 + · · · + xn)r.

(x1 + x2 + · · · + xn)r =

(cid:88) (cid:18)

r
r1, r2, . . . , rn

(cid:19)

1 xr2
xr1

2 · · · xrn
n

=

(cid:88) r!

r1!r2! · · · rn!

1 xr2
xr1

2 · · · xrn
n

where the ri range over all nonnegative integers summing to r. By independence

E(xr) =

(cid:88) r!

r1!r2! · · · rn!

E(xr1

1 )E(xr2

2 ) · · · E(xrn

n ).

If in a term, any ri = 1, the term is zero since E(xi) = 0. Assume henceforth that
(r1, r2, . . . , rn) runs over sets of nonzero ri summing to r where each nonzero ri is at least
two. There are at most r/2 nonzero ri in each set. Since |E(xri

i )| ≤ σ2ri!,

E(xr) ≤ r!

(cid:88)

σ2( number of nonzero ri in set).

(r1,r2,...,rn)

Collect terms of the summation with t nonzero ri for t = 1, 2, . . . , r/2. There are (cid:0)n
(cid:1)
subsets of {1, 2, . . . , n} of cardinality t. Once a subset is ﬁxed as the set of t values of i
with nonzero ri, set each of the ri ≥ 2. That is, allocate two to each of the ri and then

t

34

allocate the remaining r − 2t to the t ri arbitrarily. The number of such allocations is just
(cid:0)r−2t+t−1
t−1

(cid:1) = (cid:0)r−t−1

(cid:1). So,

t−1

E(xr) ≤ r!

r/2
(cid:88)

t=1

f (t), where

f (t) =

(cid:18)n
t

(cid:19)(cid:18)r − t − 1

(cid:19)

σ2t.

t − 1

Thus f (t) ≤ h(t), where h(t) = (nσ2)t
and s ≤ a2
by at least nσ2/(2t), which is at least two. This gives

2 nσ2
4nσ2 . Thus r is at most nσ2/2. For t ≤ r/2, increasing t by one, increases h(t)

t! 2r−t−1. In the hypotheses of the theorem a ≤

√

E(xr) = r!

r/2
(cid:88)

t=1

f (t) ≤ r!h(r/2)(1 +

1
2

+

1
4

+ · · · ) ≤

r!
(r/2)!

2r/2(nσ2)r/2.

Applying Markov inequality,

Prob(|x| > a) = Prob(|x|r > ar) ≤

r!(nσ2)r/22r/2
(r/2)!ar

= g(r).

For even r, g(r)/g(r − 2) = 4(r−1)nσ2
and so g(r) decreases as long as r − 1 ≤ a2/(4nσ2).
Taking r to be the largest even integer less than or equal to a2/(4nσ2), the tail probability
is at most e−r/2, which is at most e · e−a2/(8nσ2) ≤ 3 · e−a2/(8nσ2), proving the theorem.

a2

2.8 Applications of the tail bound

Calculation of width of the Gaussian annulus

Let (y1, y2, . . . , yd) be a unit variance Gaussian centered at the origin. We argue that
the mass of the Gaussian is in a narrow annulus of radius approximately
d. It is easier
to deal with squared distance to the origin rather than distance. Thus, we ask what is
the probability that |y2
i − 1 and change the question
to what is the probability that |x1+x2+· · ·+xd| ≥ β to which we can apply Theorem 2.10.

d − d| ≥ β? Let xi = y2

2 + · · · + y2

1 + y2

√

Theorem 2.10 requires bounds on the moments of the xi. For |yi| ≤ 1, |xi|s ≤ 1 and

for |yi| ≥ 1, |xi|s ≤ |yi|2s. Thus

|E(xs

i )| = E(|xi|s) ≤ E(1 + y2s
(cid:114) 2
π

= 1 +

(cid:90) ∞

y2se−y2/2dy

0

i ) = 1 + E(y2s
i )

Using the substitution y2 = 2z,

|E(xs

i )| = 1 +

2s
√
π

(cid:90) ∞

0

≤ 2ss!.

2szs−(1/2)e−zdz

35

The last inequality is from the Gamma integral.

Theorem 2.10 requires |E(xs

i )| ≤ σ2(zi)s! not 2ss!. Let zi = xi

2 and apply the theorem

to

|z1 + z2 + · · · + zd| ≥

c
2

.

From the above |E(zs
of Theorem 2.10 is satisﬁed.

i )| = |E( xs

2s )| ≤ s!. and σ2(zi) ≤ 2. Since |E(zs

i )| ≤ s!, the hypothesis

Theorem 2.11 For a d−dimensional unit variance spherical Gaussian, for any positive
d+c.
real number c ≤

64 of the mass lies within the annulus

d, all but 3e− c2

√

√

√

d−c ≤ r ≤
√

Proof: Let r be the distance to a point generated by the Gaussian. If |r −
since |r +

d| ≥

√

√

d,

d| ≥ c, then

|r2 − d| = |r −

d||r +

d| ≥ c

d.

√

√

√

Thus

and hence

or

|y2

1 + y2

2 + · · · + y2

d − d| ≥ c

√

d

|x1 + x2 + · · · + xd| ≥ c

√

d

|z1 + z2 + · · · + zd| ≥

√

c

2

d

.

Applying Theorem 2.10 where σ2 = 2 and n = d, this occurs with probability less than
or equal to 3e− c2
64 .

Chernoﬀ Bounds

Chernoﬀ bounds deal with sums of Bernoulli random variables. Here we apply Theo-

rem 2.10 to derive similar bounds.

Theorem 2.12 Suppose y1, y2, . . . , yn are independent 0-1 random variables with E(yi) =
p for all i. Let y = y1 + y2 + · · · + yn. Then for any c ∈ [0, 1],

Prob (|y − E(y)| ≥ cnp) ≤ 3e−npc2/8.

Proof: Let xi = yi − p. Then, E(xi) = 0 and E(x2

i ) = E(y − p)2 = p. For s ≥ 3,

|E(xs

i )| = |E(yi − p)s|

= |p(1 − p)s + (1 − p)(0 − p)s|
= (cid:12)
≤ p.

(cid:12)p(1 − p) (cid:0)(1 − p)s−1 + (−p)s−1(cid:1)(cid:12)
(cid:12)

Apply Theorem 2.10 with a = cnp. Noting that a <

√

2 np, completes the proof.

36

The appendix contains a diﬀerent proof that uses a standard method based on moment-

generating functions, which gives a better constant in the exponent.

Power Law Distributions

The power law distribution of order k where k is a positive integer is

f (x) =

k − 1
xk

for x ≥ 1.

If a random variable x has this distribution for k ≥ 4, then

µ = E(x) =

k − 1
k − 2

and Var(x) =

k − 1
(k − 2)2(k − 3)

.

Theorem 2.13 Suppose y obeys a power law of order k ≥ 4 and x1, x2, . . . , xn are
independent random variables, each with the same distribution as y − E(y). Let x =
x1 + x2 + · · · + xn. For any nonnegative a ≤ 1
10

(cid:112) n
k ,

Prob (|x| ≥ a) ≤ e− a2

8var(x) .

Proof: For integer s, the sth moment of xi, namely, E(xs
For s ≤ k − 2,

i ), exists if and only if s ≤ k − 2.

E(xs

i ) = (k − 1)

Using the substitution of variable z = µ/y

(cid:90) ∞

1

(y − u)s
yk

dy

(y − u)s
yk

= ys−k(1 − z)s =

zk−s
uk−s (1 − z)s

As y goes from 1 to ∞, z goes from µ to 0, and dz = − µ

y2 dy. Thus

E(xs

i ) =(k − 1)

(cid:90) ∞

(y − µ)s
yk

dy

1
k − 1
µk−s−1

=

(cid:90) 1

0

(1 − z)szk−s−2dz +

k − 1
µk−s−1

(cid:90) µ

1

(1 − z)szk−s−2dz.

The ﬁrst integral is just the standard integral of the beta function and its value is s!(k−2−s)!
To bound the second integral, note that for z ∈ [1, µ], |z − 1| ≤ 1

(k−1)!

k−2 and

.

zk−s−2 ≤ (cid:0)1 + (cid:0)1/(k − 2)(cid:1)(cid:1)k−s−2

≤ e(k−s−2)/(k−2) ≤ e.

Apply Theorem 2.10 requires bounding |E(xs
it follows that

i )| for 3 ≤ s ≤

(cid:106)

a2
4nVar(xi)

(cid:107)
. Since a ≤ 1
10

(cid:112) n
k ;

(cid:22)

a2
4nVar(xi)

(cid:23)

≤

n
100k

1
4n

(k − 2)2(k − 3)
k − 1

≤

(k − 2)2(k − 3)
k(k − 1)

≤ k − 2.

37

So it suﬃces to prove that |E(xs
only up to 2 and there is nothing to prove. So assume k ≥ 5. Since µ > 1,

i )| ≤ s!Var(x) for 3 ≤ s ≤ . . . , k − 2. If k = 4, s can go

|E(xs

i )| ≤

(k − 1)s!(k − 2 − s)!
(k − 1)!

+

e(k − 1)
(k − 2)s+1 ≤ s!Var(y)

(cid:18) 1

k − 4

+

(cid:19)

e
3!

≤ s!Var(x).

Now, the theorem follows from Theorem 2.10.

2.9 Random Projection and Johnson-Lindenstrauss Theorem

Many high-dimensional problems, such as the nearest neighbor problem, can be sped
up by projecting the data to a lower-dimensional subspace and solving the problem there.
It would be convenient to have a projection to a lower-dimensional subspace that re-
duced all distances by the same common factor, thereby leaving the relative ordering
of distances unchanged. The Johnson-Lindenstrauss theorem states that a projection
to a random low-dimensional subspace has this property. In this section, we prove the
Johnson-Lindenstrauss theorem and illustrate its application.

A random subspace of dimension one is a random line through the origin. A random
subspace of dimension k is speciﬁed by picking a random line through the origin, then a
second random line through the origin orthogonal to the ﬁrst line, and then a third line
orthogonal to the ﬁrst two, etc. Their span is the random subspace.

Project a ﬁxed unit-length vector v in d-dimensional space onto a random k-dimensional
space. By the Pythagoras theorem, the length squared of a vector is the sum of the
squares of its components. Intuitively, in a random direction the squared length of the
vector should be about 1
d and so the squared length of the projection into a random k
dimensional space should be about k/d. Thus, we would expect the length of the projec-
d . The following theorem asserts that with high probability the length of the
tion to be
projection is very close to this quantity with failure probability exponentially small in k.

(cid:113) k

Theorem 2.14 (The Random Projection Theorem) Let v be a ﬁxed unit length
vector in a d-dimensional space and let W be a random k-dimensional subspace. Let w

be the projection of v onto W . For 0 ≤ ε ≤ 1, Prob

(cid:16) (cid:12)
(cid:12)
(cid:12)|w| −

(cid:113) k
d

(cid:12)
(cid:12)
(cid:12) ≥ ε

(cid:113) k
d

(cid:17)

≤ 3e − kε2
64 .

Proof: It is diﬃcult to work with a random subspace. However, projecting a ﬁxed vector
onto a random subspace is the same as projecting a random vector onto a ﬁxed subspace
since one can rotate the coordinate system so that a set of basis vectors for the random
subspace are the ﬁrst k coordinate axes. The ﬁxed vector then becomes a random vector.
Thus, the probability distribution of w in the theorem is the same as the probability dis-
tribution of the vector obtained by taking a random unit length vector z and projecting
z onto the ﬁxed subspace U spanned by the ﬁrst k coordinate vectors.

38

Pick a random vector z of length one by picking independent Gaussian random vari-
ables x1, x2, . . . , xd, each with mean zero and variance one. Let x = (x1, x2, . . . , xd) and
z = x/|x|. The vector z is a random vector of length one.

Let ˜z be the projection of z onto U . We will prove that |˜z| ≈
2 + · · · + x2

d with high
k be the length of the projection of x and let
d be the length of x. Then the length of the projection of z = x

2 + · · · + x2

1 + x2

|x|

probability. Let a = (cid:112)x2
b = (cid:112)x2
1 + x2
is |˜z| = a
b .

(cid:113) k

If kε2 < 64, then 3e− kε2

bound on the probability that the projection deviates signiﬁcantly from
the theorem is greater than one. Assume that kε2 ≥ 64 which implies ε ≥ 8√
k
c = ε

64 > 3e−1 > 1, and there is nothing to prove since the upper
d asserted in
. Deﬁne

(cid:113) k

k/4.

√

Applying Theorem 2.11 twice, all of the following inequalities hold with probability at

least 1 − 3e− kε2
128 .

From (2.5) and (2.6),

√

√

√

√

k − c ≤ a ≤

k + c

d − c ≤ b ≤

d + c.

(2.5)

(2.6)

√
√

k − c
d + c

≤

a
b

≤

√
√

k + c
d − c

Thus, the length, |w| = a

moment we will show that
projection is bounded by

b , of the projection is bounded between
√
k−c√
d+c

≥ (1 − ε) k

≤ (1 − ε) k

√
k+c√
d−c

and
. In a
d . Thus, the length of the

d and

√
k−c√
d+c

√
k+c√
d−c

or (cid:12)

(cid:12)|w| − k
d

(cid:12)
(cid:12) ≤ ε k
√
k−c√
d+c

To see that

k
d
d with probability less than or equal to 3e− kε2

≤ |w| ≤ (1 + ε)

(1 − ε)

k
d

64 completing the proof.

d , multiply out

≥ (1 − ε)

√
k−c√
d+c
√
√

√
k√
, to get
d
√

≥ (1 − ε) k
√

√

k

d − c

√

d ≥ (1 − ε)
√

√

k

d + c(1 − ε)
√

√

k.

d ≥ c

d + c

k. Substituting c = ε

√

k/4 and

Collecting terms, this is equivalent to ε
k ≤ d, establishes that the inequality holds.

k

Similarly, to see that

≥ (1 − ε) k

√
k+c√
d−c

√

√

d , multiply out
√
√

(1 + ε)

k

d − c(1 + ε)

k ≥

√

√

√
k+c√
d−c
√

k
√

d + c
√

√

d.

≤ (1 − ε) k

d , to get

k + c

d. Substituting c = ε

√

k/4

Collecting terms, this is equivalent to
and k ≤ d, establishes that the inequality holds.

k

d ≥ c(1 + ε)

39

The random projection theorem establishes that the probability of the length of the
projection of a single vector diﬀering signiﬁcantly from its expected value is exponentially
small in k, the dimension of the target subspace. By a union bound, the probability that
any of O(n2) pairwise diﬀerences among n vectors diﬀers signiﬁcantly from their expected
values is small, provided kε2 is Ω(ln n). Thus, the projection to a random subspace
preserves all relative pairwise distances between points in a set of n points. This is the
content of the Johnson-Lindenstrauss theorem.

Theorem 2.15 (Johnson-Lindenstrauss Theorem) For any 0 < ε < 1 and any
integer n, let k satisfy kε2 ≥ 192 ln n. For any set P of n points in Rd, a random projection
f mapping f : Rd → Rk has the property that for all u and v in P with probability at
least 1 − (1.5/n),

(cid:114)

(1 − ε)

k
d

|u − v| ≤ |f (u) − f (v)| ≤ (1 + ε)

(cid:114)

k
d

|u − v| .

Proof: Applying the random projection theorem (Theorem 2.14), for any ﬁxed u and v,
the probability that |f (u) − f (v)| is outside the range

(cid:34)

(cid:114)

(1 − ε)

k
d

|u − v|, (1 + ε)

(cid:35)

|u − v|

(cid:114)

k
d

is at most

3e−

kε2
64 ≤

3
n3

for k ≥ 3×64 ln n
is less than (cid:0)n

ε2

2

. By the union bound, the probability that some pair has a large distortion
(cid:1) × 3

n3 ≤ 1.5
n .

Remark: It is important to note that the conclusion of Theorem 2.15 asserts for all u
and v in P , not just for most u and v. The weaker assertion for most u and v is not that
useful, since we do not know which v might end up being the closest point to u and an
assertion for most may not cover the particular v. A remarkable aspect of the theorem is
that the number of dimensions in the projection is only dependent logarithmically on n.
Since k is often much less than d, this is called a dimension reduction technique.

For the nearest neighbor problem, if the database has n1 points and n2 queries are
expected during the lifetime, take n = n1 + n2 and project the database to a random
k-dimensional space, where k ≥ 192 ln n
. On receiving a query, project the query to the
same subspace and compute nearby database points. The Johnson Lindenstrauss theorem
says that with high probability this will yield the right answer whatever the query. Note
that the exponentially small in k probability in Theorem 2.14 was useful here in making
k only dependent on ln n, rather than n.

ε2

40

2.10 Bibliographic Notes

The word vector model was introduced by Salton [SWY75]. Taylor series remainder
material can be found in Whittaker and Watson 1990, pp. 95-96 and Section 11.7.4 of the
appendix. There is vast literature on the Gaussian distribution, its properties, drawing
samples according to it, etc. The reader can choose the level and depth according to
his/her background. For Chernoﬀ bounds and their applications, see [MU05] or [MR95b].
The proof here and the application to heavy-tailed distributions is simpliﬁed from [Kan09].
The original proof of the random projection theorem by Johnson and Lindenstrauss was
complicated. Several authors used Gaussians to simplify the proof. See [Vem04] for de-
tails and applications of the theorem. The proof here is due to Das Gupta and Gupta
[DG99].

41

2.11 Exercises

Exercise 2.1

1. Let x and y be independent random variables with uniform distribution in [0, 1].

What is the expected value E(x), E(x2), E(x − y), E(xy), and E((x − y)2)?

2. Let x and y be independent random variables with uniform distribution in [− 1
What is the expected value E(x), E(x2), E(x − y), E(xy), and E((x − y)2)?

2, 1
2].

3. What is the expected squared distance between two points generated at random inside

a unit d-dimensional cube centered at the origin?

4. Randomly generate a number of points inside a d-dimensional unit cube centered
at the origin and plot distance between and the angle between the vectors from the
origin to the points for all pairs of points.

Exercise 2.2 Consider two random 0-1 vectors in high dimension. What is the angle
between them?

Exercise 2.3 In Section 2.1 on properties of high-dimensional space, we state that the
distance of a point to the center of a sphere in d-dimensions is likely to be between 1 − c
d
and 1. We also claim that the ﬁrst coordinate of such a point is likely to be between − c√
d
and c√
d

. Justify the role of d in these statements.

Exercise 2.4 Show that Markov’s inequality is tight by showing the following:

1. For each of a = 2, 3, and 4 give a probability distribution for a nonnegative random
variable x where Prob (cid:0)x ≥ aE(x)(cid:1) = 1
a.

2. For arbitrary a ≥ 1 give a probability distribution for a nonnegative random variable

x where Prob (cid:0)x ≥ aE(x)(cid:1) = 1
a.

Exercise 2.5 In what sense is Chebyshev’s inequality tight?

Exercise 2.6 Consider the probability function p(x) = c 1
random samples. How close is the average of the samples to the expected value of x?

x4 , x ≥ 1, and generate 100

Exercise 2.7 Consider the portion of the surface area of a unit radius, 3-dimensional
sphere with center at the origin that lies within a circular cone whose vertex is at the
origin. What is the formula for the incremental unit of area when using polar coordinates
to integrate the portion of the surface area of the sphere that is lying inside the circular
cone? What is the formula for the integral? What is the value of the integral if the angle
of the cone is 36◦? The angle of the cone is measured from the axis of the cone to a ray
on the surface of the cone.

42

Exercise 2.8 For what value of d does the volume, V (d), of a d-dimensional unit sphere
take on its maximum?
Hint: Consider the ratio V (d)

V (d−1).

Exercise 2.9 Write a recurrence relation for V (d) in terms of V (d − 1) by integrating
using an incremental unit that is a disk of thickness dr.

Exercise 2.10 How does the volume of a sphere of radius two behave as the dimension
of the space increases? What if the radius was larger than two but a constant independent
of d? What function of d would the radius need to be for a sphere of radius r to have
approximately constant volume as the dimension increases?

Exercise 2.11 A 3-dimensional cube has vertices, edges, and faces. In a d-dimensional
cube, these components are called faces. A vertex is a 0-dimensional face, an edge a 1-
dimensional face, etc. For 0 ≤ i ≤ d, how many i-dimensional faces does a d-dimensional
hyper cube have? What is the total number of faces of all dimensions? The d-dimensional
face is the cube itself which you can include in your count.

Exercise 2.12 Consider a unit radius, circular cylinder in 3-dimensions of height one.
The top of the cylinder could be an horizontal plane or we could have half of a cir-
cular sphere. Consider these two possibilities for a unit radius, circular cylinder in 4-
dimensions.
In each of the two cases, what is the surface area of the top face of the
cylinder? You can use V (d) for the volume of a unit radius, d-dimension sphere and A(d)
for the surface area of a unit radius, d-dimensional sphere. An inﬁnite length, unit radius,
circular cylinder in 4-dimensions would be the set {(x1, x2, x3, x4)|x2
4 ≤ 1} where
the coordinate x1 is the axis.

2 + x2

3 + x2

Exercise 2.13 What is the surface area of a d-dimensional cylinder of radius two and
height one in terms of V (d) and A(d)?

Exercise 2.14 Consider vertices of a d-dimensional cube of width two centered at the
origin. Vertices are the points (±1, ±1, . . . , ±1). Place a unit-radius sphere at each vertex.
Each sphere ﬁts in a cube of width two and thus no two spheres intersect. Show that the
probability that a point of the cube picked at random will fall into one of the 2d unit-radius
spheres, centered at the vertices of the cube, goes to 0 as d tends to inﬁnity.

Exercise 2.15 Place two unit-radius spheres in d-dimensions, one at (-2,0,0,. . . ,0 ) and
the other at (2,0,0,. . . ,0). Give an upper bound on the probability that a random line
through the origin will intersect the spheres.

Exercise 2.16 Let x be a random sample from the unit sphere {x||x| ≤ 1} in d-dimensions
with the origin as center.

1. What is the mean of the random variable x? The mean, denoted E(x), is the vector,

whose ith component is E(xi).

43

2. What is the component-wise variance of x?

3. For any unit length vector u, the variance of the real-valued random variable uT x is

i E(x2
u2

d
(cid:80)
i=1
for the variance of x.

i ). Note that the xi are not independent. Using (2), simplify this expression

4. * Given two spheres in d-space, both of radius one whose centers are distance a

apart, show that the volume of their intersection is at most

4e− a2(d−1)
√
d − 1
a

8

times the volume of each sphere. Hint: Relate the volume of the intersection to the
volume of a cap; then, use Lemma 2.6.

√

5. From (4), conclude that if the inter-center separation of the two spheres of radius
d), then they share very small mass. Theoretically, at this separation,
r is Ω(r/
given randomly generated points from the two distributions, one inside each sphere,
it is possible to tell which sphere contains which point, i.e., classify them into two
clusters so that each cluster is exactly the set of points generated from one sphere.
The actual classiﬁcation requires an eﬃcient algorithm to achive this. Note that
the inter-center separation required here goes to zero as d gets larger, provided the
radius of the spheres remains the same. So, it is easier to tell apart spheres (of the
same radii) in higher dimensions.

6. * In this part, you will carry out the same exercise for Gaussians. First, restate the
shared mass of two spheres as (cid:82)
x∈ space min(f (x), g(x))dx, where f and g are just
the uniform densities in the two spheres respectively. Make a similar deﬁnition for
the shared mass of two spherical Gaussians. Using this, show that for two spherical
Gaussians, each with standard deviation σ in every direction and with centers at
distance a apart, the shared mass is at most (c1/a) exp(−c2a2/.σ2), where c1 and c2
are constants. This translates to “if two spherical Gaussians have centers which are
Ω(σ) apart, then they share very little mass”. Explain.

Exercise 2.17 Prove that 1 + x ≤ ex for all real x. For what values of x is the approxi-
mation 1 + x ≈ ex good?

Exercise 2.18 Derive an upper bound on (cid:82) ∞
for what values of a this is a good bound.
a e −x2
Hint: Use e −x2

for x ≥ a.

2 ≤ x

2

x=a e −x2

2 dx where a is a positive real. Discuss

Exercise 2.19 Verify the formula V (d) = 2 (cid:82) 1
1) d−1
0 V (d − 1)(1 − x2
d = 2 by integrating and comparing with V (2) = π and V (3) = 4
3π

2 dx1 for d = 1 and

44

Exercise 2.20 What is the volume of a radius r cylinder of height h in d-dimensions?

Exercise 2.21 Consider the upper hemisphere of a unit-radius sphere in d-dimensions.
What is the height of the maximum volume cylinder that can be placed entirely inside the
hemisphere? As you increase the height of the cylinder, you need to reduce the cylinder’s
radius so that it will lie entirely within the hemisphere.

Exercise 2.22 What is the volume of the maximum size d-dimensional hypercube that
can be placed entirely inside a unit radius d-dimensional sphere?

Exercise 2.23 In showing that the volume of a unit sphere was near the equator we
obtained an upper bound on the volume of the upper hemisphere above the slice of

1
(cid:15)(d − 1)

d−1

2 (cid:15)2V (d − 1)

e

and a lower bound on the volume of the upper hemisphere of
for a radius r sphere these bounds become rd+1

1
2
d−1
V (d − 1) and

2 ( (cid:15)

r )2

d−1

√

(cid:15)(d−1)e

V (d − 1). Show that

√

rd
d−1

2

V (d − 1) and

that the ratio is

2r
d−1

√
(cid:15)

e

d−1

2 ( (cid:15)

r )2

.

Exercise 2.24 For a 1,000-dimensional unit-radius sphere centered at the origin, what
fraction of the volume of the upper hemisphere is above the plane x1 = 0.1? Above the
plane x1 = 0.01?

Exercise 2.25 Let (cid:8)x (cid:12)
origin. What fraction of the volume is the set
{(x1, x2, . . . , xd)|∀i |xi| ≤ 1√
d

}?

(cid:12) |x| ≤ 1(cid:9) be a d-dimensional, unit radius sphere centered at the

Exercise 2.26 Almost all of the volume of a sphere in high dimensions lies in a narrow
slice of the sphere at the equator. However, the narrow slice is determined by the point on
the surface of the sphere that is designated the North Pole. Explain how this can be true
if several diﬀerent locations are selected for the North Pole.

Exercise 2.27 Explain how the volume of a sphere in high dimensions can simultaneously
be in a narrow slice at the equator and also be concentrated in a narrow annulus at the
surface of the sphere.

Exercise 2.28 Project the vertices of a high-dimensional cube onto a line from (0, 0, . . . , 0)
to (1, 1, . . . , 1). Argue that the “density” of the number of projected points (per unit dis-
tance) varies roughly as a Gaussian with variance O(1) with the mid-point of the line as
center.

Exercise 2.29

45

1. A unit cube has vertices, edges, faces, etc. How many k-dimensional objects are in

a d-dimensional cube?

2. What is the surface area of a unit cube in d-dimensions?

3. What is the surface area of the cube if the length of each side was 2?

4. Prove that the volume of a unit cube is close to its surface.

Exercise 2.30 Deﬁne the equator of a d-dimensional unit cube to be the hyperplane
(cid:26)

(cid:27)

x|

d
(cid:80)
i=1

xi = d
2

.

1. Are the vertices of a unit cube concentrated close to the equator?

2. Is the volume of a unit cube concentrated close to the equator?

3. Is the surface area of a unit cube concentrated close to the equator?

Exercise 2.31 How large must ε be for 99% of the volume of a d-dimensional unit-radius
sphere to lie in the shell of ε-thickness at the surface of the sphere?

Exercise 2.32 Calculate the ratio of area above the plane x1 = (cid:15) of a unit radius sphere
in d-dimensions for (cid:15) = 0.01, 0.02, 0.03, 0.04, 0.05 and for d = 100 and d = 1, 000. Also
calculate the ratio for (cid:15) = 0.001 and d = 1, 000.

Exercise 2.33

1. What is the maximum size rectangle that can be ﬁtted in a unit

variance Gaussian?

2. What rectangle best approximates a unit variance Gaussian if one measure goodness

of ﬁt by how small the symmetric diﬀerence of the Gaussian and rectangle is.

Exercise 2.34 Generate 500 points uniformly at random on the surface of a unit-radius
sphere in 50 dimensions. Then randomly generate ﬁve additional points. For each of
the ﬁve new points, calculate a narrow band at the equator, assuming the point was the
North Pole. How many of the 500 points are in each band corresponding to one of the ﬁve
equators? How many of the points are in all ﬁve bands?

Exercise 2.35 We have claimed that a randomly generated point on a sphere lies near
the equator of the sphere, wherever we place the North Pole. Is the same claim true for a
randomly generated point on a cube? To test this claim, randomly generate ten ±1 valued
vectors in 128 dimensions. Think of these ten vectors as ten choices for the North Pole.
Then generate some additional ±1 valued vectors. To how many of the original vectors is
each of the new vectors close to being perpendicular; that is, how many of the equators is
each new vectors close to?

46

Exercise 2.36 Consider two random vectors in a high-dimensional space. Assume the
vectors have been normalized so that their lengths are one and thus the points lie on a
unit sphere. Assume one of the vectors is the North pole. Prove that the ratio of the area
of a cone, with axis at the North Pole of ﬁxed angle say 45◦ to the area of a hemisphere,
goes to zero as the dimension increases. Thus, the probability that the angle between two
random vectors is at most 45◦ goes to zero. How does this relate to the result that most
of the volume is near the equator?

Exercise 2.37 Consider a slice of a 100-dimensional sphere that lies between two parallel
planes, each equidistant from the equator and perpendicular to the line from the North to
the South Pole. What percentage of the distance from the center of the sphere to the poles
must the planes be to contain 95% of the surface area?

Exercise 2.38 Place n points at random on a d-dimensional unit-radius sphere. Assume
d is large. Pick a random vector and let it deﬁne two parallel hyperplanes on opposite sides
of the origin that are equal distance from the origin. How far apart can the hyperplanes
be moved and still have the probability that none of the n points lands between them be at
least .99?

d onto a
Exercise 2.39 Project the surface area of a d-dimensions sphere of radius
line through the center. For large d, give an intuitive argument that the projected surface
area should behave like a Gaussian.

√

Exercise 2.40 * Consider the simplex

S = {x | xi ≥ 0, 1 ≤ i ≤ d;

d
(cid:88)

i=1

xi ≤ 1}.

For a random point x picked with uniform density from S, ﬁnd E(x1 + x2 + · · · + xd).
Find the centroid of S.

Exercise 2.41 How would you sample uniformly at random from the parallelepiped

P = {x | 0 ≤ Ax ≤ 1},

where A is a given nonsingular matrix? How about from the simplex

{x | 0 ≤ (Ax)1 ≤ (Ax)2 · · · ≤ (Ax)d ≤ 1}?

Your algorithms must run in polynomial time.

Exercise 2.42 Let G be a d-dimensional spherical Gaussian with variance 1
the origin. Derive the expected squared distance to the origin.

2 centered at

Exercise 2.43

47

1. Write a computer program that generates n points uniformly distributed over the

surface of a unit-radius d-dimensional sphere.

2. Generate 200 points on the surface of a sphere in 50 dimensions.

3. Create several random lines through the origin and project the points onto each line.

Plot the distribution of points on each line.

4. What does your result from (3) say about the surface area of the sphere in relation

to the lines, i.e., where is the surface area concentrated relative to each line?

Exercise 2.44 If one generates points in d-dimensions with each coordinate a unit vari-
d.
ance Gaussian, the points will approximately lie on the surface of a sphere of radius

√

1. What is the distribution when the points are projected onto a random line through

the origin?

2. If one uses a Gaussian with variance four, where in d-space will the points lie?

Exercise 2.45 Randomly generate a 100 points on the surface of a sphere in 3-dimensions
and in 100-dimensions. Create a histogram of all distances between the pairs of points in
both cases.

Exercise 2.46 We have claimed that in high dimensions, a unit variance Gaussian cen-
tered at the origin has essentially zero probability mass in a unit-radius sphere centered at
the origin. Show that as the variance of the Gaussian goes down, more and more of its
mass is contained in the unit-radius sphere. How small must the variance be for 0.99 of
the mass of the Gaussian to be contained in the unit-radius sphere?

Exercise 2.47 Consider two unit-radius spheres in d-dimensions whose centers are dis-
tance δ apart where δ is a constant independent of d. Let x be a random point on the
surface of the ﬁrst sphere and y a random point on the surface of the second sphere. Prove
that the probability that |x − y|2 is more than 2 + δ2 + a, falls oﬀ exponentially with a.

Exercise 2.48 * Pick a point x uniformly at random from the following set in d-space:

K = {x|x4

1 + x4

2 + · · · + x4

d ≤ 1}.

1. Show that the probability that x4

1 + x4

2 + · · · + x4

d ≤ 1

2 is

1
2d/4 .

2. Show that with high probability, x4

1 + x4

2 + · · · + x4

d ≥ 1 − O(1/d).

3. Show that with high probability, |x1| ≤ O(1/d1/4).

Exercise 2.49 Suppose there is an object moving at constant velocity along a straight
line. You receive the gps coordinates corrupted by Gaussian noise every minute. How do
you estimate the current position?

48

Exercise 2.50 Generate ten values by a Gaussian probability distribution with zero mean
and variance one. What is the center determined by averaging the points? What is the
variance? In estimating the variance, use both the real center and the estimated center.
When using the estimated center to estimate the variance, use both n = 10 and n = 9.
How do the three estimates compare?

Exercise 2.51 Let x1, x2, . . . , xn be independent samples of a random variable x with
mean m and variance σ2. Let ms = 1
xi be the sample mean. Suppose one estimates
n

n
(cid:80)
i=1

the variance using the sample mean rather than the true mean, that is,

σ2
s =

1
n

n
(cid:88)

i=1

(xi − ms)2

Prove that E(σ2

s ) = n−1

n σ2 and thus one should have divided by n − 1 rather than n.

Hint: First calculate the variance of the sample mean and show that var(ms) = 1
Then calculate E(σ2

nvar(x).
i=1(xi −ms)2] by replacing xi −ms with (xi −m)−(ms −m).

s ) = E[ 1
n

(cid:80)n

Exercise 2.52 Suppose you want to estimate the unknown center of a Gaussian in d-
space which has variance one in each direction. Show that O(log d/ε2) random samples
from the Gaussian are suﬃcient to get an estimate ˜µ of the true center µ, so that with
probability at least 99/100,

How many samples are suﬃcient to ensure that

|µ − ˜µ|∞ ≤ ε.

|µ − ˜µ| ≤ ε?

Exercise 2.53 Use the probability distribution

(x−5)2
2×9

1√

2π3

e−

to generate ten points.

(a) From the ten points estimate µ. How close is the estimate of µ to the true mean of

5?

(b) Using the true mean of 5, estimate σ2 by the fomula σ2 = 1
10

is the estimate of σ2 to the true variance of 9?

10
(cid:80)
i=1

(xi − 5)2. How close

(c) Using your estimate of the mean, estimate σ2 by the fomula σ2 = 1
10

close is the estimate of σ2 to the true variance of 9?

(d) Using your estimate of the mean, estimate σ2 by the fomula σ2 = 1
9

close is the estimate of σ2 to the true variance of 9?

10
(cid:80)
i=1

(xi − 5)2. How

10
(cid:80)
i=1

(xi − 5)2. How

49

Exercise 2.54 The Cauchy distribution in one dimension is Prob(x) = 1
c+x2 . What
would happen if one tried to extend the distribution to higher dimensions by the formula
Prob(r) = 1
1+r2 , where r is the distance from the origin? What happens when you try to
determine a normalization constant c?

Exercise 2.55 Consider the power law probability density

p(x) =

c
max(1, x2)

=

(cid:26) c

0 ≤ x ≤ 1

c
x2 x > 1

over the nonnegative real line.

1. Determine the constant c.

2. For a nonnegative random variable x with this density, does E(x) exist? How about

E(x2)?

Exercise 2.56 Consider d-space and the following density over the positive orthant:

p(x) =

c
max(1, |x|a)

.

Show that a > d is necessary for this to be a proper density function. Show that a > d + 1
is a necessary condition for a (vector-valued) random variable x with this density to have
an expected value E(|x|). What condition do you need if we want E(|x|2) to exist?

Exercise 2.57 Assume you can generate a value uniformly at random in the interval
[0, 1]. How would you generate a value according to a probability distribution p(x)?

Exercise 2.58 Let x be a random variable with probability density 1
zero elsewhere.

4 for 0 ≤ x ≤ 4 and

1. Use Markov’s inequality to bound the probability that x > 3.

2. Make use of Prob(|x| > a) = Prob(x2 > a2) to get a tighter bound.

3. What is the bound using Prob(|x| > a) = Prob(xr > ar)?

a and p(x = a) = 1
Exercise 2.59 Consider the probability distribution p(x = 0) = 1 − 1
a.
Plot the probability that x is greater than or equal to b as a function of b for the bound
given by Markov’s inequality and by Markov’s inequality applied to x2 and x4.

Exercise 2.60 Suppose x and y are two random 0-1 d-vectors. Show that with high
probability the cosine of the angle between them is close to 1
2. Hint: Model your proof after
that of the random projection theorem.

50

Exercise 2.61 Generate 20 points uniformly at random on a 1,000-dimensional sphere
of radius 100. Calculate the distance between each pair of points. Then, project the data
onto subspaces of dimension k=100, 50, 10, 5, 4, 3, 2, 1 and calculate the diﬀerence
d times the original distances and the new pair-wise distances. For each value

between

(cid:113) k

of k what is the maximum diﬀerence as a percent of

(cid:113) k
d .

Exercise 2.62 You are given two sets, P and Q, of n points each in n-dimensional space.
Your task is to ﬁnd the closest pair of points, one each from P and Q, i.e., ﬁnd x in P
and y in Q such that |x − y| is minimum.

1. Show that this can be done in time O(n3).

2. Show how to do this with relative error 0.1% in time O(n2 ln n), i.e., you must ﬁnd
a pair x ∈ P, y ∈ Q so that the distance between them is, at most, 1.001 times the
minimum possible distance. If the minimum distance is 0, you must ﬁnd x = y.

Exercise 2.63 Given n data points in d-space, ﬁnd a subset of k data points whose vector
sum has the smallest length. You can try all (cid:0)n
(cid:1) subsets, compute each vector sum in time
O(kd) for a total time of O (cid:0)(cid:0)n
(cid:1)kd(cid:1). Show that we can replace d in the expression above
by O(k ln n), if we settle for an answer with relative error .02%.

k

k

Exercise 2.64 In d-dimensions there are exactly d-unit vectors that are pairwise orthog-
onal. However, if you wanted a set of vectors that were almost orthogonal you might
squeeze in a few more. For example, in 2-dimensions if almost orthogonal meant at least
45 degrees apart you could ﬁt in three almost orthogonal vectors. Suppose you wanted to
ﬁnd 900 almost orthogonal vectors in 100 dimensions where almost orthogonal meant an
angle of between 85 and 95 degrees. How would you generate such a set?
Hint: Consider projecting a 1,000 orthonormal vectors to a random 100-dimensional
space.

Exercise 2.65 To preserve pairwise distances between n data points in d space, we pro-
jected to a random O(ln n/ε2) dimensional space. To save time in carrying out the pro-
jection, we may try to project to a space spanned by sparse vectors, vectors with only
a few nonzero entries. that is, choose say O(ln n/ε2) vectors at random, each with 100
nonzero components and project to the space spanned by them. Will this work (to preserve
approximately all pairwise distances) ? Why?

Exercise 2.66 Create a list of the ﬁve most important things that you learned about high
dimensions.

Exercise 2.67 Write a short essay whose purpose is to excite a college freshman to learn
about high dimensions.

51

3 Best-Fit Subspaces and Singular Value Decompo-

sition (SVD)

Think of the rows of an n × d matrix A as n data points in a d-dimensional space
and consider the problem of ﬁnding the best k-dimensional subspace with respect to the
set of points. Here best means minimize the sum of the squares of the perpendicular dis-
tances of the points to the subspace. We begin with a special case where the subspace is
1-dimensional, namely a line through the origin. The best ﬁtting k-dimensional subspace
is found by repeated applications of the best ﬁtting line algorithm, each time ﬁnding the
best ﬁtting line perpendicular to the subspace found so far. When k reaches the rank
of the matrix, a decomposition of the matrix, called the Singular Value Decomposition
(SVD), is obtained from the best ﬁtting lines.

The singular value decomposition of a matrix A is the factorization of A into the
product of three matrices, A = U DV T , where the columns of U and V are orthonormal
In many applications, a data
and the matrix D is diagonal with positive real entries.
matrix A is close to a low rank matrix and a low rank approximation to A is desired. The
singular value decomposition of A gives the best rank k approximation to A, for any k .

The singular value decomposition is deﬁned for all matrices, whereas the more com-
monly used eigenvector decomposition requires the matrix A be square and certain other
conditions on the matrix to ensure orthogonality of the eigenvectors.
In contrast, the
columns of V in the singular value decomposition, called the right-singular vectors of A,
always form an orthonormal set with no assumptions on A. The columns of U are called
the left-singular vectors and they also form an orthonormal set. A simple consequence
of the orthonormality is that for a square and invertible matrix A, the inverse of A is
V D−1U T .

Project a point ai = (ai1, ai2, . . . , aid) onto a line through the origin. Then

i1 + a2
a2

i2 + · · · + a2

id = (length of projection)2 + (distance of point to line)2 .

See Figure 3.1. Thus

(distance of point to line)2 = a2

i1 + a2

i2 + · · · + a2

id − (length of projection)2 .

n
(cid:80)
i=1

(a2

Since

i1 + a2

i2 + · · · + a2

id) is a constant independent of the line, minimizing the sum
of the squares of the distances to the line is equivalent to maximizing the sum of the
squares of the lengths of the projections onto the line. Similarly for best-ﬁt subspaces,
maximizing the sum of the squared lengths of the projections onto the subspace minimizes
the sum of squared distances to the subspace.

Thus, there are two interpretations of the best-ﬁt subspace. The ﬁrst is that it min-
imizes the sum of squared distances of the data points to it. This interpretation and its

52

Minimizing (cid:80)
lent to maximizing (cid:80)

α2
i

i

is equiva-

β2
i

i

v

xi

αi

βi

Figure 3.1: The projection of the point xi onto the line through the origin in the direction
of v.

use are akin to the notion of least-squares ﬁt from calculus. But there is a diﬀerence. Here
the perpendicular distance to the line or subspace is minimized, whereas, in the calculus
notion, given n pairs (x1, y1), (x2, y2), . . . , (xn, yn), one ﬁnds a line l = {(x, y)|y = mx + b}
minimizing the vertical distance of the points to it, namely, (cid:80)n

i=1(yi − mxi − b)2.

The second interpretation of best-ﬁt-subspace is that it maximizes the sum of projec-
tions squared of the data points on it. In some sense the subspace contains the maximum
content of data among all subspaces of the same dimension.

The reader may wonder why we minimize the sum of squared distances to the line.
We could alternatively have deﬁned the best-ﬁt line to be the one that minimizes the
sum of distances to the line. There are examples where this deﬁnition gives a diﬀerent
answer than the line minimizing the sum of squared distances. The choice of the objective
function as the sum of squared distances seems arbitrary, but the square has many nice
mathematical properties. The ﬁrst of these is the use of Pythagoras theorem to say that
minimizing the sum of squared distances is equivalent to maximizing the sum of squared
projections.

3.1 Singular Vectors

Consider the best ﬁt line through the origin for the points determined by the rows of
A. Let v be a unit vector along this line. The length of the projection of ai, the ith row of
A, onto v is |ai · v| and the sum of length squared of the projections is |Av|2. The best ﬁt
line is the one maximizing |Av|2 and hence minimizing the sum of the squared distances
of the points to the line.

With this in mind, deﬁne the ﬁrst singular vector , v1, of A, which is a column vector,
as the vector deﬁning the best ﬁt line through the origin for the n points in d-space that

53

are the rows of A. Thus

v1 = arg max
|v|=1

|Av|.

There may be a tie for the vector attaining the maximum and so technically we should
not use the article “the”. If there is a tie, arbitrarily pick one of the vectors and refer
to it as “the ﬁrst singular vector” avoiding the more cumbersome “one of the the vectors
achieving the maximum”. We adopt this terminology for all uses of arg max .

The value σ1 (A) = |Av1| is called the ﬁrst singular value of A. Note that σ2
1 =
(ai · v1)2 is the sum of the squares of the projections of the points to the line deter-

n
(cid:80)
i=1
mined by v1.

If the data points were all either on a line or close to a line, v1 would give the direction
of that line. It is possible that data points are not close to one line, but lie close to a
2-dimensional plane or more generally a low dimensional aﬃne space. A widely applied
technique called Principal Component Analysis (PCA) indeed deals with such situations
using singular vectors. How do we ﬁnd the best-ﬁt 2-dimensional plane or more generally
the k-dimensional aﬃne space?

The greedy approach to ﬁnd the best ﬁt 2-dimensional subspace for a matrix A, takes
v1 as the ﬁrst basis vector for the 2-dimensional subspace and ﬁnds the best 2-dimensional
subspace containing v1. The fact that we are using the sum of squared distances helps.
For every 2-dimensional subspace containing v1, the sum of squared lengths of the pro-
jections onto the subspace equals the sum of squared projections onto v1 plus the sum
of squared projections along a vector perpendicular to v1 in the subspace. Thus, instead
of looking for the best 2-dimensional subspace containing v1, look for a unit vector v2
perpendicular to v1 that maximizes |Av|2 among all such unit vectors. Using the same
greedy strategy to ﬁnd the best three and higher dimensional subspaces, deﬁne v3, v4, . . .
in a similar manner. This is captured in the following deﬁnitions.

The second singular vector , v2, is deﬁned by the best ﬁt line perpendicular to v1.

v2 = arg max

|Av|

v⊥v1
|v|=1

The value σ2 (A) = |Av2| is called the second singular value of A. The third singular
vector v3 and third singular value are deﬁned similarly by

and

v3 = arg max
v⊥v1,v2
|v|=1

|Av|

σ3(A) = |Av3|,

54

and so on. The process stops when we have found singular vectors v1, v2, . . . , vr, singular
values σ1, σ2, . . . , σr, and

max
v⊥v1,v2,...,vr
|v|=1

|Av| = 0.

There is no apriori guarantee that the greedy algorithm gives the best ﬁt. But, in
fact, the greedy algorithm does work and yields the best-ﬁt subspaces of every dimension
as we will show. If instead of ﬁnding the v1 that maximized |Av| and then the best ﬁt
2-dimensional subspace containing v1, we had found the best ﬁt 2-dimensional subspace,
we might have done better. This is not the case. We give a simple proof that the greedy
algorithm indeed ﬁnds the best subspaces of every dimension.

Theorem 3.1 Let A be an n × d matrix with singular vectors v1, v2, . . . , vr. For 1 ≤
k ≤ r, let Vk be the subspace spanned by v1, v2, . . . , vk. For each k, Vk is the best-ﬁt
k-dimensional subspace for A.

Proof: The statement is obviously true for k = 1. For k = 2, let W be a best-ﬁt 2-
dimensional subspace for A. For any orthonormal basis (w1, w2) of W , |Aw1|2 + |Aw2|2
is the sum of squared lengths of the projections of the rows of A onto W . Choose an
orthonormal basis (w1, w2) of W so that w2 is perpendicular to v1. If v1 is perpendicular
to W , any unit vector in W will do as w2. If not, choose w2 to be the unit vector in W
perpendicular to the projection of v1 onto W. This makes w2 perpendicular to v1. Since
v1 maximizes |Av|2, it follows that |Aw1|2 ≤ |Av1|2. Since v2 maximizes |Av|2 over all
v perpendicular to v1, |Aw2|2 ≤ |Av2|2. Thus

|Aw1|2 + |Aw2|2 ≤ |Av1|2 + |Av2|2.

Hence, V2 is at least as good as W and so is a best-ﬁt 2-dimensional subspace.

For general k, proceed by induction. By the induction hypothesis, Vk−1 is a best-ﬁt
k-1 dimensional subspace. Suppose W is a best-ﬁt k-dimensional subspace. Choose an
orthonormal basis w1, w2, . . . , wk of W so that wk is perpendicular to v1, v2, . . . , vk−1.
Then

|Aw1|2 + |Aw2|2 + · · · + |Awk|2 ≤ |Av1|2 + |Av2|2 + · · · + |Avk−1|2 + |Awk|2

since Vk−1 is an optimal k -1 dimensional subspace. Since wk is perpendicular to
v1, v2, . . . , vk−1, by the deﬁnition of vk, |Awk|2 ≤ |Avk|2. Thus

|Aw1|2 + |Aw2|2 + · · · + |Awk−1|2 + |Awk|2 ≤ |Av1|2 + |Av2|2 + · · · + |Avk−1|2 + |Avk|2,

proving that Vk is at least as good as W and hence is optimal.

Note that the n-vector Avi is a list of lengths with signs of the projections of the rows
of A onto vi. Think of |Avi| = σi(A) as the “component” of the matrix A along vi. For
this interpretation to make sense, it should be true that adding up the squares of the

55

components of A along each of the vi gives the square of the “whole content of the matrix
A”. This is indeed the case and is the matrix analogy of decomposing a vector into its
components along orthogonal directions.

Consider one row, say aj, of A. Since v1, v2, . . . , vr span the space of all rows of A,
(aj · vi)2 =

aj · v = 0 for all v perpendicular to v1, v2, . . . , vr. Thus, for each row aj,

r
(cid:80)
i=1

|aj|2. Summing over all rows j,

n
(cid:88)

j=1

|aj|2 =

n
(cid:88)

r
(cid:88)

j=1

i=1

(aj · vi)2 =

r
(cid:88)

n
(cid:88)

i=1

j=1

(aj · vi)2 =

r
(cid:88)

i=1

|Avi|2 =

r
(cid:88)

i=1

σ2
i (A).

But

n
(cid:80)
j=1

|aj|2 =

n
(cid:80)
j=1

d
(cid:80)
k=1

a2
jk, the sum of squares of all the entries of A. Thus, the sum of

squares of the singular values of A is indeed the square of the “whole content of A”, i.e.,
the sum of squares of all the entries.

There is an important norm associated with this quantity, the Frobenius norm of A,

denoted ||A||F deﬁned as

||A||F =

(cid:115)(cid:88)

j,k

a2
jk.

Lemma 3.2 For any matrix A, the sum of squares of the singular values equals the square
of the Frobenius norm. That is, (cid:80) σ2
i (A) = ||A||2
F .

Proof: By the preceding discussion.

The vectors v1, v2, . . . , vr are called the right-singular vectors. The vectors Avi form

a fundamental set of vectors and we normalize them to length one by

ui =

1
σi(A)

Avi.

The vectors, u2, . . . , ur are called the left-singular vectors. Later we will show that they
are orthogonal and ui maximizes |uT A| over all unit length u perpendicular to alluj, j < i.

3.2 Singular Value Decomposition (SVD)

Let A be an n × d matrix with singular vectors v1, v2, . . . , vr and corresponding sin-
gular values σ1, σ2, . . . , σr. The left-singular vectors of A are ui = 1
Avi where σiui is a
σi
vector whose coordinates correspond to the projections of the rows of A onto vi. Each
σiuivT
is a rank one matrix whose columns are weighted versions of σiui, weighted pro-
i
portional to the coordinates of vi.

56

We will prove that A can be decomposed into a sum of rank one matrices as

A =

r
(cid:88)

i=1

σiuivT
i .

We ﬁrst prove a simple lemma stating that two matrices A and B are identical if Av = Bv
for all v.

Lemma 3.3 Matrices A and B are identical if and only if for all vectors v, Av = Bv.

Proof: Clearly, if A = B then Av = Bv for all v. For the converse, suppose that
Av = Bv for all v. Let ei be the vector that is all zeros except for the ith component
which has value one. Now Aei is the ith column of A and thus A = B if for each i,
Aei = Bei.

Theorem 3.4 Let A be an n × d matrix with right-singular vectors v1, v2, . . . , vr, left-
singular vectors u1, u2, . . . , ur, and corresponding singular values σ1, σ2, . . . , σr. Then

A =

r
(cid:88)

i=1

σiuivT
i .

Proof: We ﬁrst show that multiplying both A and

Avj.

(cid:33)

σiuivT
i

vj = σjuj = Avj

(cid:32) r

(cid:88)

i=1

r
(cid:80)
i=1

σiuivT

i by vj results in quantity

Since any vector v can be expressed as a linear combination of the singular vectors

σiuivT

i v for all v and by Lemma 3.3,

plus a vector perpendicular to the vi, Av =

A =

r
(cid:80)
i=1

σiuivT
i .

r
(cid:80)
i=1

i σiuivT
i

The decomposition A = (cid:80)

is called the singular value decomposition, SVD, of
A. In matrix notation A = U DV T where the columns of U and V consist of the left and
right-singular vectors, respectively, and D is a diagonal matrix whose diagonal entries are
the singular values of A. To see that A = U DV T , observe that each σiuivT
is a rank one
i
matrix and A = (cid:80)
i σiuivT
i , term contributes
i
σiujivik to the jkth element of A. Thus, ajk = (cid:80)

is a sum of rank one matrices. Each σiuivT

i σiujiuik which is correct.

For any matrix A, the sequence of singular values is unique and if the singular val-
ues are all distinct, then the sequence of singular vectors is unique also. When some
set of singular values are equal, the corresponding singular vectors span some subspace.
Any set of orthonormal vectors spanning this subspace can be used as the singular vectors.

57

D
r × r

V T
r × d

A
n × d

U
n × r

=

Figure 3.2: The SVD decomposition of an n × d matrix.

3.3 Best Rank k Approximations

Let A be an n × d matrix and let

A =

r
(cid:88)

i=1

σiuivT
i

be the SVD of A. For k ∈ {1, 2, . . . , r}, let

Ak =

k
(cid:88)

i=1

σiuivT
i

be the sum truncated after k terms. It is clear that Ak has rank k. It is also the case
that Ak is the best rank k approximation to A, where error is measured in Frobenius norm.

To show that Ak is the best rank k approximation to A when error is measured by
the Frobenius norm, we ﬁrst show that the rows of A − Ak are the projections of the rows
of A onto the subspace Vk spanned by the ﬁrst k singular vectors of A. This implies that
||A − Ak||2

F equals the sum of squared distances of the rows of A to the subspace Vk.

Lemma 3.5 Let Vk be the subspace spanned by the ﬁrst k singular vectors of A. The
rows of Ak are the projections of the rows of A onto the subspace Vk.

Proof: Let a be an arbitrary row vector. Since the vi are orthonormal, the projection

of the vector a onto Vk is given by

k
(cid:80)
i=1

(a · vi)vi

T . Thus, the matrix whose rows are the

projections of the rows of A onto Vk is given by

k
(cid:80)
i=1

AvivT

i . This last expression simpliﬁes

to

k
(cid:88)

i=1

Avivi

T =

k
(cid:88)

i=1

58

σiuivi

T = Ak.

Thus, the rows of Ak are the projections of the rows of A onto the subspace Vk.

We next show that if B is a rank k matrix minimizing ||A − B||2

F among all rank
k matrices, that each row of B must be the projection of the corresponding row of A
onto the space spanned by rows of B. This implies that ||A − B||2
F is the sum of squared
distances of rows of A to the space spanned by the rows of B. Since the space spanned by
the rows of B is a k dimensional subspace and since the subspace spanned by the ﬁrst k
singular vectors minimizes the sum of squared distances over all k-dimensional subspaces,
it must be that (cid:107)A − Ak(cid:107)F ≤ (cid:107)A − B(cid:107)F .

Theorem 3.6 For any matrix B of rank at most k

(cid:107)A − Ak(cid:107)F ≤ (cid:107)A − B(cid:107)F

Proof: Let B minimize (cid:107)A − B(cid:107)2
F among all rank k or less matrices. Let V be the space
spanned by the rows of B. The dimension of V is at most k. Since B minimizes (cid:107)A − B(cid:107)2
F ,
it must be that each row of B is the projection of the corresponding row of A onto V ,
otherwise replacing the row of B with the projection of the corresponding row of A onto
V does not change V and hence the rank of B but would reduce (cid:107)A − B(cid:107)2
F . Since now
each row of B is the projection of the corresponding row of A, it follows that (cid:107)A − B(cid:107)2
F
is the sum of squared distances of rows of A to V . By Theorem 3.1, Ak minimizes the
sum of squared distance of rows of A to any k-dimensional subspace.
It follows that
(cid:107)A − Ak(cid:107)F ≤ (cid:107)A − B(cid:107)F .

There is another matrix norm, called the 2-norm, that is of interest. To motivate,
consider the example of a document-term matrix A. Suppose we have a large database
of documents which form the rows of an n × d matrix A. There are d terms and each
document is a d-vector with one component per term which is the number of occurrences
of the term in the document. We are allowed to “preprocess” A. After the preprocessing,
we receive queries. Each query x is an d-vector specifying how important each term is
to the query. The desired answer is a n-vector which gives the similarity (dot product)
of the query to each document in the database, namely, the “matrix-vector” product,
Ax. Query time should be much less than processing time, one answers many queries
for the data base. N¨aively, it would take O(nd) time to do the product Ax. However,
if we approximate A by Ak = (cid:80)k
i=1 σiui(vi · x) as
the approximation to Ax. This only takes k dot products of d-vectors and takes time
O(kd) which is a win provided k is fairly small. How do we measure the error? Since
x is unknown, the approximation needs to be good for every x. So we should take the
maximum over all x of |(Ak − A)x|. But unfortunately, this is inﬁnite since |x| can grow
without bound. So we restrict to |x| ≤ 1.

T we could return Akx = (cid:80)k

i=1 σiuivi

The 2-norm or spectral norm of a matrix A is

||A||2 = max
|x|≤1

|Ax|.

59

Note that the 2-norm of A equals σ1(A).

We will prove in Section 3.4 that Ak is the best rank k, 2-norm approximation to A.

3.4 Left Singular Vectors

In this section we show that he left singular vectors are orthogonal and that Ak is the

best 2-norm approximation to A.

Theorem 3.7 The left singular vectors are pairwise orthogonal.

Proof: First we show that each ui, i ≥ 2 is orthogonal to u1. Suppose not, and for some
i ≥ 2, uT
1 ui > 0. The proof is symmetric
for the case where uT

1 ui (cid:54)= 0. Without loss of generality assume that uT

1 ui < 0. Now, for inﬁnitesimally small ε > 0, the vector

A

(cid:19)

(cid:18) v1 + εvi
|v1 + εvi|

=

σ1u1 + εσiui
1 + ε2

√

has length at least as large as its component along u1 which is

uT
1 (

σ1u1 + εσiui
1 + ε2

√

) = (cid:0)σ1 + εσiuT

1 ui

(cid:1) (cid:16)

1 − ε2

(cid:17)
2 + O (ε4)

= σ1 + εσiuT

1 ui − O (cid:0)ε2(cid:1) > σ1,

a contradiction. Thus u1 · ui = 0 for i ≥ 2.

The proof for other ui and uj, j > i > 1 is similar. Suppose without loss of generality

that ui

T uj > 0.

A

(cid:19)

(cid:18) vi + εvj
|vi + εvj|

=

σiui + εσjuj
1 + ε2

√

has length at least as large as its component along ui which is

uT
i (

σ1ui + εσjuj
1 + ε2

√

) = (cid:0)σi + εσjuT

i uj

(cid:1) (cid:16)

1 − ε2

(cid:17)
2 + O (ε4)

= σi + εσjuT

i uj − O (cid:0)ε2(cid:1) > σi,

a contradiction since vi + εvj is orthogonal to v1, v2, . . . , vi−1 and σi is the maximum
over such vectors of |Av|.

In Theorem 3.9 we show that A − k is the best 2-norm approximation to A. We ﬁrst
show that the square of the 2-norm of A − Ak is the square of the (k + 1)st singular value
of A,

Lemma 3.8 (cid:107)A − Ak(cid:107)2

2 = σ2

k+1.

60

Proof: Let A =

and A − Ak =

r
(cid:80)
i=1
r
(cid:80)
i=k+1

σiuivi

T be the singular value decomposition of A. Then Ak =

k
(cid:80)
i=1

σiuivi

T

σiuivi

T . Let v be the top singular vector of A − Ak. Express v as a

linear combination of v1, v2, . . . , vr. That is, write v =

αivi. Then

r
(cid:80)
i=1
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

|(A − Ak)v| =

=

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

r
(cid:88)

i=k+1

r
(cid:88)

i=k+1

σiuivi

T

r
(cid:88)

j=1

αjvj

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

=

r
(cid:88)

i=k+1

αiσiuivi

T vi

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

αiσiui

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:118)
(cid:117)
(cid:117)
(cid:116)

=

r
(cid:88)

i=k+1

i σ2
α2
i ,

since the ui are orthonormal. The v maximizing this last quantity, subject to the con-
straint that |v|2 =
i = 1, occurs when αk+1 = 1 and the rest of the αi are 0. Thus,

α2

r
(cid:80)
i=1

(cid:107)A − Ak(cid:107)2

2 = σ2

k+1 proving the lemma.

Finally, we prove that Ak is the best rank k, 2-norm approximation to A.

Theorem 3.9 Let A be an n × d matrix. For any matrix B of rank at most k

(cid:107)A − Ak(cid:107)2 ≤ (cid:107)A − B(cid:107)2 .
Proof: If A is of rank k or less, the theorem is obviously true since (cid:107)A − Ak(cid:107)2 = 0.
Assume that A is of rank greater than k. By Lemma 3.8, (cid:107)A − Ak(cid:107)2
k+1. The null
space of B, the set of vectors v such that Bv = 0, has dimension at least d − k. Let
v1, v2, . . . , vk+1 be the ﬁrst k + 1 singular vectors of A. By a dimension argument, it
follows that there exists a z (cid:54)= 0 in

2 = σ2

Null (B) ∩ Span {v1, v2, . . . , vk+1} .

Let w1, w2, . . . , wd−k be d−k independent vectors in Null(B). Now, w1, w2, . . . , wd−k, v1,
v2, . . . , vk+1 are d+1 vectors in d space and thus are linearly dependent. Let α1, α2, . . . , αd−k
and β1, β2, . . . , βk be such that (cid:80)d−k
i=1 αiui. Scale z so
that |z| = 1. We now show that for this vector z, which lies in the space of the ﬁrst k + 1
singular vectors of A, that (A − B) z ≥ σk+1. Hence the 2-norm of A − B is at least σk+1.
First

j=1 βjvj. Let z = (cid:80)d−k

i=1 αiui = (cid:80)k

(cid:107)A − B(cid:107)2

2 ≥ |(A − B) z|2 .

Since Bz = 0,

(cid:107)A − B(cid:107)2

2 ≥ |Az|2 .

Since z is in the Span {v1, v2, . . . , vk+1}

2

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

n
(cid:88)

|Az|2 =

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)
i=1
i=1
It follows that (cid:107)A − B(cid:107)2
2 ≥ σ2

σiuivi

n
(cid:88)

T z

=

σ2
i

(cid:0)vi

T z(cid:1)2

=

k+1
(cid:88)

i=1

σ2
i

(cid:0)vi

T z(cid:1)2

≥ σ2

k+1

k+1
(cid:88)

i=1

(cid:0)vi

T z(cid:1)2

= σ2

k+1.

k+1 and the theorem is proved.

61

3.5 Power Method for Computing the Singular Value Decom-

position

Computing the singular value decomposition is an important branch of numerical
analysis in which there have been many sophisticated developments over a long period of
time. Here we present an “in-principle” method to establish that the approximate SVD
of a matrix A can be computed in polynomial time. The reader is referred to numerical
analysis texts for more details. The method we present, called the power method, is simple
and is in fact the conceptual starting point for many algorithms. Let A be a matrix whose
SVD is (cid:80)
T . We wish to work with a matrix that is square and symmetric. By direct

σiuivi

i

multiplication, since uT

i uj is the dot product of the two vectors and is zero unless i = j

B = AT A =

(cid:32)

(cid:88)

i

(cid:33) (cid:32)

(cid:88)

(cid:33)

σjujvT
j

σiviuT
i

(cid:88)

=

i,j

σiσjvi(uT

i · uj)vT

j =

j
(cid:88)

i

i vivT
σ2
i .

The matrix B is square and symmetric, and has the same left and right-singular vectors.
If A is itself square and symmetric, it will have the same right and left-singular vectors,
namely A = (cid:80)

T and computing B is unnecessary.

σivivi

i

Now consider computing B2.

B2 =

(cid:32)

(cid:88)

i

i vivT
σ2
i

(cid:33) (cid:32)

(cid:88)

j

j vjvT
σ2
j

(cid:33)

(cid:88)

=

ij

i σ2
σ2

j vi(vi

T vj)vj

T

When i (cid:54)= j, the dot product vi
matrix and is not zero even for i (cid:54)= j. Thus, B2 =

of B, all the cross product terms are zero and

r
(cid:80)
i=1

T vj equals 0. However the “outer product” vivj

T is a

σ4
i vivi

T . In computing the kth power

If σ1 > σ2, then

Bk =

r
(cid:88)

i=1

σ2k
i vivi

T .

1
σ2k
1

Bk → v1v1

T .

We do not know σ1. However, if we divide Bk by ||Bk||F so that the Frobenius norm is
T from which v1
normalized to one, the matrix will converge to the rank one matrix v1v1
may be computed by normalizing the ﬁrst column to be a unit vector.

The diﬃculty with the above method is that A may be a very large, sparse matrix, say
a 108 × 108 matrix with 109 nonzero entries. Sparse matrices are often represented by just

62

a list of non-zero entries, say, a list of triples of the form (i, j, aij). Though A is sparse, B
need not be and in the worse case all 1016 elements may be non-zero in which case it is
impossible to even store B, let alone compute the product B2. Even if A is moderate in
size, computing matrix products is costly in time. Thus, we need a more eﬃcient method.

Instead of computing Bk = σ2k

T , select a random vector x and compute the
product Bkx. The way Bkx is computed is by a series of matrix vector products, instead
of matrix products. Bx = A(Ax) and Bkx = (AT ABk−1x). Thus, we perform 2k vector
times sparse matrix multiplications. The vector x can be expressed in terms of the singular
vectors of B augmented to a full orthonormal basis as x = (cid:80) civi. Then

1 v1v1

Bkx ≈ (σ2k

1 v1v1

T )

(cid:16) n
(cid:88)

(cid:17)

civi

i=1

= σ2k

1 c1v1

Normalizing the resulting vector yields v1, the ﬁrst singular vector of A.

An issue occurs if there is no signiﬁcant gap between the ﬁrst and second singular
values of a matrix. If σ1 = σ2, then the above argument fails. Theorem 3.10 below states
that even with ties, the power method converges to some vector in the span of those sin-
gular vectors corresponding to the “nearly highest” singular values. The theorem needs
a vector x that has a component of at least δ along the ﬁrst right singular vector v1 of
A. Lemma 3.11 establishes that a random vector satisﬁes this condition.

Theorem 3.10 Let A be an n×d matrix and x a unit length vector in Rd with |xT v1| ≥ δ,
where, δ > 0. Let V be the space spanned by the right singular vectors of A corresponding
to singular values greater than (1 − ε) σ1. Let w be unit vector after k = ln(1/εδ)/ε
iterations of the power method, namely,

w =

(cid:0)AT A(cid:1)k x
(cid:12)
(cid:12)
(cid:12)(AT A)k x
(cid:12)
(cid:12)
(cid:12)

.

Then w has a component of at most ε perpendicular to V .

Proof: Let

r
(cid:88)

A =

σiuivT
i

i=1
be the SVD of A. If the rank of A is less than d, then complete {v1, v2, . . . vr} into an
orthonormal basis {v1, v2, . . . vd} of d-space. Write x in the basis of the vi

(cid:48)s as

civi.

x =

n
(cid:88)

i=1

63

Since (AT A)k =

|c1| ≥ δ.

n
(cid:80)
i=1

i vivT
σ2k
i ,

it follows that (AT A)kx =

n
(cid:80)
i=1

σ2k
i civi. By hypothesis,

Suppose that σ1, σ2, . . . , σm are the singular values of A that are greater than or equal
to (1 − ε) σ1 and that σm+1, . . . , σn are the singular values that are less than (1 − ε) σ1.
Then

|(AT A)kx|2 =

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

d
(cid:88)

i=1

σ2k
i civi

2

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

=

n
(cid:88)

i=1

i c2
σ4k

i ≥ σ4k

1 c2

1 ≥ σ4k

1 δ2.

The square of the component of |(AT A)kx|2 perpendicular to the space V is

n
(cid:88)

i=m+1

σ4k
i c2

i ≤ (1 − ε)4k σ4k

1

n
(cid:88)

i=m+1

i ≤ (1 − ε)4k σ4k
c2

1

since (cid:80)d

i=1 c2

i = |x| = 1. Thus, the component of w perpendicular to V is at most

(1 − ε)2kσ2k
1
δσ2k
1

= (1 − ε)2k/δ ≤ e−2kε−ln δ = ε.

Lemma 3.11 Let y ∈ Rn be a random vector with the unit variance spherical Gaussian
as its probability density. Let x = y/|y|. Let v be any ﬁxed unit length vector. Then

Prob(|xT v| ≤

1
√
20

d

) ≤

+ 3e−d/64.

1
10
√

d substituted in that theorem, we see
Proof: By Theorem 2.11 of Chapter 2 with c =
d is at most 3e−d/64. Further, yT v is a random variable
that the probability that |y| ≥ 2
with the distribution of a unit variance Gaussian with zero mean. Thus, the probability
that |yT v| ≤ 1
10 is at most 1/10. Combining these two and using the union bound, proves
the lemma.

√

3.6 Applications of Singular Value Decomposition

3.6.1 Principal Component Analysis

The traditional use of SVD is in Principal Component Analysis (PCA). PCA is il-
lustrated by a customer-product data problem where there are n customers buying d
products. Let matrix A with elements aij represent the probability of customer i pur-
chasing product j. One hypothesizes that there are only k underlying basic factors like
age, income, family size, etc. that determine a customer’s purchase behavior. An individ-
ual customer’s behavior is determined by some weighted combination of these underlying
factors. That is, a customer’s purchase behavior can be characterized by a k-dimensional

64

















factors

















=

















U





















A

customers

products

V





Figure 3.3: Customer-product data

vector where k is much smaller than n or d. The components of the vector are weights
for each of the basic factors. Associated with each basic factor is a vector of probabilities,
each component of which is the probability of purchasing a given product by someone
whose behavior depends only on that factor. More abstractly, A is an n × d matrix that
can be expressed as the product of two matrices U and V where U is an n × k matrix
expressing the factor weights for each customer and V is a k × d matrix expressing the
purchase probabilities of products that correspond to that factor. Finding the best rank k
approximation Ak by SVD gives such a U and V . One twist is that A may not be exactly
equal to U V , but close to it since there may be noise or random perturbations in which
case A − U V is treated as noise.

In the above setting, A was available fully and we wished to ﬁnd U and V to identify
the basic factors. If n and d are very large, on the order of thousands or even millions,
there is probably little one could do to estimate or even store A. In this setting, we may
assume that we are given just a few elements of A and wish to estimate A. If A was an
arbitrary matrix of size n × d, this would require Ω(nd) pieces of information and cannot
be done with a few entries. But again hypothesize that A was a small rank matrix with
added noise. If now we also assume that the given entries are randomly drawn according
to some known distribution, then there is a possibility that SVD can be used to estimate
the whole of A. This area is called collaborative ﬁltering and one of its uses is to target
an ad to a customer based on one or two purchases. We do not describe it here.

3.6.2 Clustering a Mixture of Spherical Gaussians

Clustering, is the task of partitioning a set of points in d-space into k subsets or clus-
ters where each cluster consists of “nearby” points. Diﬀerent deﬁnitions of the goodness
of a clustering lead to diﬀerent solutions. Clustering is an important area which we will
study in detail in Chapter ??. Here we solve a particular clustering problem using singular
value decomposition.

65

In general, a solution to any clustering problem comes up with k cluster centers that
deﬁne the k clusters. A cluster is the set of data points that are closest to a particular
cluster center. Hence the Vornoi cells of the cluster centers determine the clusters. Using
this observation, it is relatively easy to cluster points in two or three dimensions. However,
clustering is not so easy in higher dimensions. Many problems have high-dimensional data
and clustering problems are no exception.

Clustering problems tend to be NP-hard, so we there are no polynomial time algo-
rithms to solve them. One way around this is to assume stochastic models of input data
and devise algorithms to cluster data generated by such models. Mixture models are a
very important class of stochastic models. A mixture is a probability density or distri-
bution that is the weighted sum of simple component probability densities. It is of the
form

F = w1p1 + w2p2 + · · · + wkpk,

where p1, p2, . . . , pk are the basic probability densities and w1, w2, . . . , wk are positive real
numbers called weights that add up to one. Clearly, F is a probability density, it inte-
grates to one.

The model ﬁtting problem is to ﬁt a mixture of k basic densities to n independent,
identically distributed samples, each sample drawn according to the same mixture dis-
tribution F . The class of basic densities is known, but various parameters such as their
means and the component weights of the mixture are not. Here, we deal with the case
where the basic densities are all spherical Gaussians. There are two equivalent ways of
thinking of the sample generation process which is hidden, only the samples are given.

1. Pick each sample according to the density F on Rd.

2. Pick a random i from {1, 2, . . . , k} where probability of picking i is wi. Then, pick

a sample according to the density Fi.

The model-ﬁtting problem can be broken up into two sub problems:

• The ﬁrst sub problem is to cluster the set of samples into k clusters C1, C2, . . . , Ck,
where, Ci is the set of samples generated according to Fi, see (2) above, by the
hidden generation process.

• The second sub problem is to ﬁt a single Gaussian distribution to each cluster of

sample points.

The second problem is easier than the ﬁrst and in Chapter (2) we showed that taking
the empirical mean, the mean of the sample, and the empirical standard deviation gives
the best-ﬁt Gaussian. The ﬁrst problem is harder and this is what we discuss here.

66

If the component Gaussians in the mixture have their centers very close together, then
the clustering problem is unresolvable. In the limiting case where a pair of component
densities are the same, there is no way to distinguish between them. What condition on
the inter-center separation will guarantee unambiguous clustering? First, by looking at
1-dimensional examples, it is clear that this separation should be measured in units of the
standard deviation, since the density is a function of the number of standard deviation
from the mean. In one dimension, if two Gaussians have inter-center separation at least
six times the maximum of their standard deviations, then they hardly overlap.

How far apart must the means be to determine which Gaussian a point belongs to. In
one dimension, if the distance is at least six standard deviations, we separate the Gaus-
sians. What is the analog of this in higher dimensions?

We discussed in Chapter (2) distances between two sample points from the same
Gaussian as well the distance between two sample points from two diﬀerent Gaussians.
Recall from that discussion that if

• If x and y are two independent samples from the same spherical Gaussian with

standard deviation1 σ, then

|x − y|2 ≈ 2(

d ± c)2σ2.

√

• If x and y are samples from diﬀerent spherical Gaussians each of standard deviation

σ and means separated by distance δ, then

|x − y|2 ≈ 2(

√

d ± c)2σ2 + δ2.

Now we would like to assert that points from the same Gaussian are closer to each other
than points from diﬀerent Gaussians. To ensure this, we need
√

√

2(

d − c)2σ2 + δ2 > 2(

d + c)2σ2.

Expanding the squares, the high order term 2d cancels and we need that

δ > c(cid:48)d1/4.

While this was not a completely rigorous argument, it can be used to show that a distance
based clustering approach requires an inter-mean separation of at least c(cid:48)d1/4 standard
deviations to succeed, thus unfortunately not keeping within a constant number of stan-
dard deviations separation of the means. Here, indeed, we will show that Ω(1) standard
deviations suﬃce, provided k ∈ O(1).

1Since a spherical Gaussian has the same standard deviation in every direction, we call it the standard

deviation of the Gaussian.

67

The central idea is the following. Suppose we can ﬁnd the subspace spanned by the
k centers and project the sample points to this subspace. The projection of a spherical
Gaussian with standard deviation σ remains a spherical Gaussian with standard deviation
σ, Lemma 3.12. In the projection, the inter-center separation remains the same. So in the
projection, the Gaussians are distinct provided the inter-center separation in the whole
space is Ω(k1/4 σ) which is a lot smaller than the Ω(d1/4 σ) for k << d. Interestingly, we
will see that the subspace spanned by the k-centers is essentially the best-ﬁt k-dimensional
subspace that can be found by singular value decomposition.

Lemma 3.12 Suppose p is a d-dimensional spherical Gaussian with center µ and stan-
dard deviation σ. The density of p projected onto a k-dimensional subspace V is a spherical
Gaussian with the same standard deviation.

Proof: Rotate the coordinate system so V is spanned by the ﬁrst k coordinate vectors.
The Gaussian remains spherical with standard deviation σ although the coordinates of
its center have changed. For a point x = (x1, x2, . . . , xd), we will use the notation x(cid:48) =
(x1, x2, . . . xk) and x(cid:48)(cid:48) = (xk+1, xk+2, . . . , xn). The density of the projected Gaussian at
the point (x1, x2, . . . , xk) is

|x(cid:48)−µ(cid:48)|2
2σ2

(cid:90)

|x(cid:48)(cid:48)−µ(cid:48)(cid:48)|2
2σ2

e−

ce−

dx(cid:48)(cid:48) = c(cid:48)e−

|x(cid:48)−µ(cid:48)|2
2σ2

.

x(cid:48)(cid:48)

This clearly implies the lemma.

We now show that the top k singular vectors produced by the SVD span the space of
the k centers. First, we extend the notion of best ﬁt to probability distributions. Then
we show that for a single spherical Gaussian whose center is not the origin, the best ﬁt
1-dimensional subspace is the line though the center of the Gaussian and the origin. Next,
we show that the best ﬁt k-dimensional subspace for a single Gaussian whose center is not
the origin is any k-dimensional subspace containing the line through the Gaussian’s center
and the origin. Finally, for k spherical Gaussians, the best ﬁt k-dimensional subspace is
the subspace containing their centers. Thus, the SVD ﬁnds the subspace that contains
the centers.

Recall that for a set of points, the best-ﬁt line is the line passing through the origin
that minimizes the sum of squared distances to the points. We extend this deﬁnition to
probability densities instead of a set of points.

Deﬁnition 3.1 If p is a probability density in d space, the best ﬁt line for p is the line l
passing through the origin that minimizes the expected squared perpendicular distance to
the line, namely,

(cid:82) dist (x, l)2 p (x) dx.

68

1. The best ﬁt 1-dimension subspace
to a spherical Gaussian is the line
through its center and the origin.

2. Any k-dimensional subspace contain-
ing the line is a best ﬁt k-dimensional
subspace for the Gaussian.

3. The best ﬁt k-dimensional subspace
for k spherical Gaussians is the sub-
space containing their centers.

Figure 3.4: Best ﬁt subspace to a spherical Gaussian.

A word of caution: The integral may not exist. We assume that it does when we write

it down.

For the uniform density on the unit circle centered at the origin, it is easy to see that
any line passing through the origin is a best ﬁt line for the probability distribution. Our
next lemma shows that the best ﬁt line for a spherical Gaussian centered at µ (cid:54)= 0 is the
line passing through µ and the origin.

Lemma 3.13 Let the probability density p be a spherical Gaussian with center µ (cid:54)= 0.
The unique best ﬁt 1-dimensional subspace is the line passing through µ and the origin.
If µ = 0, then any line through the origin is a best-ﬁt line.

Proof: For a randomly chosen x (according to p) and a ﬁxed unit length vector v,

E (cid:2)(vT x)2(cid:3) = E

= E

= E

(cid:104)(cid:0)vT (x − µ) + vT µ(cid:1)2(cid:105)
(cid:104)(cid:0)vT (x − µ)(cid:1)2
(cid:104)(cid:0)vT (x − µ)(cid:1)2(cid:105)
(cid:104)(cid:0)vT (x − µ)(cid:1)2(cid:105)

+ (cid:0)vT µ(cid:1)2

= E
= σ2 + (cid:0)vT µ(cid:1)2

+ 2 (cid:0)vT µ(cid:1) (cid:0)vT (x − µ)(cid:1) + (cid:0)vT µ(cid:1)2(cid:105)
+ 2 (cid:0)vT µ(cid:1) E (cid:2)vT (x − µ)(cid:3) + (cid:0)vT µ(cid:1)2

(cid:104)(cid:0)vT (x − µ)(cid:1)2(cid:105)

is the variance in the direction v and E (cid:0)vT (x − µ)(cid:1) = 0. The
since E
lemma follows from the fact that the best ﬁt line v is the one that maximizes (cid:0)vT µ(cid:1)2

69

which is maximized when v is aligned with the center µ. To see the uniqueness, just note
that if µ (cid:54)= 0, then vT µ is strictly smaller when v is not aligned with the center.

Recall that a k-dimensional subspace is the best-ﬁt subspace if the sum of squared
distances to it is minimized or equivalently, the sum of squared lengths of projections onto
it is maximized. This was deﬁned for a set of points, but again it can be extended to a
density as we did for best-ﬁt lines.

Deﬁnition 3.2 If p is a probability density in d-space and V is a subspace, then the
expected squared perpendicular distance of V to p, denoted f (V, p), is given by

(cid:90)

f (V, p) =

(cid:0)dist (x, V )(cid:1)2

p (x) dx,

where dist(x, V ) denotes the perpendicular distance from the point x to the subspace V .

Lemma 3.14 For a spherical Gaussian with center µ, a k-dimensional subspace is a best
ﬁt subspace if and only if it contains µ.

Proof: If µ = 0, then by symmetry any k-dimensional subspace is a best-ﬁt subspace. If
µ (cid:54)= 0, then the best-ﬁt line must pass through µ by Lemma 3.13. Now, as in the greedy
algorithm for ﬁnding subsequent singular vectors, we would project perpendicular to the
ﬁrst singular vector. But after the projection, the mean of the Gaussian becomes 0 and
then any vectors will do as subsequent best-ﬁt directions.

This leads to the following theorem.

Theorem 3.15 If p is a mixture of k spherical Gaussians , then the best ﬁt k-dimensional
subspace contains the centers. In particular, if the means of the Gaussians are linearly
independent, the space spanned by them is the unique best-ﬁt k dimensional subspace.

Proof: Let p be the mixture w1p1+w2p2+· · ·+wkpk. Let V be any subspace of dimension
k or less. The expected squared perpendicular distance of V to p is

(cid:90)

f (V, p) =

dist2(x, V )p(x)dx

(cid:90)

wi

dist2(x, V )pi(x)dx

wi( distance squared of pi to its best ﬁt k-dimensional subspace).

=

≥

k
(cid:88)

i=1
k
(cid:88)

i=1

If a subspace V contains the centers of the densities pi, by Lemma ?? the last inequality
becomes an equality proving the theorem. Indeed, for each i individually, we have equality
which is stronger than just saying we have equality for the sum.

70

For an inﬁnite set of points drawn according to the mixture, the k-dimensional SVD
subspace gives exactly the space of the centers. In reality, we have only a large number
of samples drawn according to the mixture. However, it is intuitively clear that as the
number of samples increases, the set of sample points approximates the probability density
and so the SVD subspace of the sample is close to the space spanned by the centers. The
details of how close it gets as a function of the number of samples are technical and we
do not carry this out here.

3.6.3 Spectral Decomposition

Let B be a square matrix. If the vector x and scalar λ are such that Bx = λx, then x
is an eigenvector of the matrix B and λ is the corresponding eigenvalue. We present here
a spectral decomposition theorem for the special case where B is of the form B = AAT for
some possibly rectangular matrix A. If A is a real valued matrix, then B is symmetric and
positive deﬁnite. That is, xT Bx > 0 for all nonzero vectors x. The spectral decomposition
theorem holds more generally and the interested reader should consult a linear algebra
book.

Theorem 3.16 (Spectral Decomposition) If B = AAT then B = (cid:80)
A = (cid:80)

is the singular valued decomposition of A.

i

σiuivT
i

i

Proof:

i uiuT
σ2

i where

B = AAT =

(cid:32)

(cid:88)

σiuivi

T

(cid:33) (cid:32)

(cid:88)

σjujvT
j

(cid:33)T

=

=

i
(cid:88)
(cid:88)

j
T vjuj

T

σiσjuivi

i
(cid:88)

j
σ2
i uiui

T .

i

When the σi are all distinct, the ui are the eigenvectors of B and the σ2

i are the
If the σi are not distinct, then any vector that is a linear

corresponding eigenvalues.
combination of those ui with the same eigenvalue is an eigenvector of B.

3.6.4 Singular Vectors and Ranking Documents

An important task for a document collection is to rank the documents according to
their intrinsic relevance to the collection. A good candidate is a document’s projection
onto the best-ﬁt direction for the collection of term-document vectors, namely the top
left-singular vector of the term-document matrix. An intuitive reason for this is that this
direction has the maximum sum of squared projections of the collection and so can be

71

thought of as a synthetic term-document vector best representing the document collection.

Ranking in order of the projection of each document’s term vector along the best ﬁt
direction has a nice interpretation in terms of the power method. For this, we consider
a diﬀerent example, that of the web with hypertext links. The World Wide Web can
be represented by a directed graph whose nodes correspond to web pages and directed
edges to hypertext links between pages. Some web pages, called authorities, are the most
prominent sources for information on a given topic. Other pages called hubs, are ones
that identify the authorities on a topic. Authority pages are pointed to by many hub
pages and hub pages point to many authorities. One is led to what seems like a circular
deﬁnition: a hub is a page that points to many authorities and an authority is a page
that is pointed to by many hubs.

One would like to assign hub weights and authority weights to each node of the web.
If there are n nodes, the hub weights form a n-dimensional vector u and the authority
weights form a n-dimensional vector v. Suppose A is the adjacency matrix representing
the directed graph. Here aij is 1 if there is a hypertext link from page i to page j and 0
otherwise. Given hub vector u, the authority vector v could be computed by the formula

vj =

d
(cid:88)

i=1

uiaij

since the right hand side is the sum of the hub weights of all the nodes that point to node
j. In matrix terms,

v = AT u.

Similarly, given an authority vector v, the hub vector u could be computed by u = Av.
Of course, at the start, we have neither vector. But the above discussion suggests a power
iteration. Start with any v. Set u = Av; then set v = AT u and repeat the process. We
know from the power method that this converges to the left and right-singular vectors.
So after suﬃciently many iterations, we may use the left vector u as hub weights vector
and project each column of A onto this direction and rank columns (authorities) in order
of their projections. But the projections just form the vector AT u which equals v. So we
can rank by order of the vj. This is the basis of an algorithm called the HITS algorithm,
which was one of the early proposals for ranking web pages.

A diﬀerent ranking called page rank is widely used. It is based on a random walk on

the graph described above. We will study random walks in detail in Chapter 5.

3.6.5 An Application of SVD to a Discrete Optimization Problem

In Gaussian clustering the SVD was used as a dimension reduction technique. It found
a k-dimensional subspace containing the centers of the Gaussians in a d-dimensional space
and made the Gaussian clustering problem easier by projecting the data to the subspace.

72

Here, instead of ﬁtting a model to data, we have an optimization problem. Again ap-
plying dimension reduction to the data makes the problem easier. The use of SVD to
solve discrete optimization problems is a relatively new subject with many applications.
We start with an important NP-hard problem, the maximum cut problem for a directed
graph G(V, E).

The maximum cut problem is to partition the node set V of a directed graph into two
subsets S and ¯S so that the number of edges from S to ¯S is maximized. Let A be the
adjacency matrix of the graph. With each vertex i, associate an indicator variable xi.
The variable xi will be set to 1 for i ∈ S and 0 for i ∈ ¯S. The vector x = (x1, x2, . . . , xn)
is unknown and we are trying to ﬁnd it or equivalently the cut, so as to maximize the
number of edges across the cut. The number of edges across the cut is precisely

(cid:88)

i,j

xi(1 − xj)aij.

Thus, the maximum cut problem can be posed as the optimization problem

Maximize (cid:80)

xi(1 − xj)aij

subject to xi ∈ {0, 1}.

In matrix notation,

i,j

(cid:88)

i,j

xi(1 − xj)aij = xT A(1 − x),

where 1 denotes the vector of all 1’s . So, the problem can be restated as

Maximize xT A(1 − x)

subject to xi ∈ {0, 1}.

(3.1)

The SVD is used to solve this problem approximately by computing the SVD of A and

replacing A by Ak =

k
(cid:80)
i=1

σiuivi

T in (3.1) to get

Maximize xT Ak(1 − x)

subject to xi ∈ {0, 1}.

(3.2)

Note that the matrix Ak is no longer a 0-1 adjacency matrix.

We will show that:

1. For each 0-1 vector x, xT Ak(1 − x) and xT A(1 − x) diﬀer by at most

√

n2
k+1

. Thus,

the maxima in (3.1) and (3.2) diﬀer by at most this amount.

2. A near optimal x for (3.2) can be found by exploiting the low rank of Ak, which by
Item 1 is near optimal for (3.1) where near optimal means with additive error of at
most

√

.

n2
k+1

73

√

First, we prove Item 1. Since x and 1 − x are 0-1 n-vectors, each has length at most
n||A − Ak||2. Now since
xT (A − Ak)(1 − x) is the dot product of the vector x with the vector (A − Ak)(1 − x),

n. By the deﬁnition of the 2-norm, |(A − Ak)(1 − x)| ≤

√

|xT (A − Ak)(1 − x)| ≤ n||A − Ak||2.

By Lemma 3.8, ||A − Ak||2 = σk+1(A). The inequalities,

(k + 1)σ2

k+1 ≤ σ2

1 + σ2

2 + · · · σ2

k+1 ≤ ||A||2

F =

(cid:88)

i,j

ij ≤ n2
a2

imply that σ2

k+1 ≤ n2

k+1 and hence ||A − Ak||2 ≤ n√

k+1

proving Item 1.

Next we focus on Item 2. It is instructive to look at the special case when k=1 and A
is approximated by the rank one matrix A1. An even more special case when the left and
right-singular vectors u and v are required to be identical is already NP-hard to solve ex-
actly because it subsumes the problem of whether for a set of n integers, {a1, a2, . . . , an},
there is a partition into two subsets whose sums are equal. So, we look for algorithms
that solve the maximum cut problem approximately.

For Item 2, we want to maximize (cid:80)k

T (1 − x)) over 0-1 vectors x. A
piece of notation will be useful. For any S ⊆ {1, 2, . . . n}, write ui(S) for the sum of
coordinates of the vector ui corresponding to elements in the set S and also for vi. That
is, ui(S) = (cid:80)

i=1 σiui(S)vi( ¯S) using dynamic programming.

uij. We will maximize (cid:80)k

i=1 σi(xT ui)(vi

j∈S

For a subset S of {1, 2, . . . , n}, deﬁne the 2k-dimensional vector

w(S) = (u1(S), v1( ¯S), u2(S), v2( ¯S), . . . , uk(S), vk( ¯S)).

If we had the list of all such vectors, we could ﬁnd (cid:80)k
i=1 σiui(S)vi( ¯S) for each of them
and take the maximum. There are 2n subsets S, but several S could have the same
w(S) and in that case it suﬃces to list just one of them. Round each coordinate of
1
nk2 . Call the rounded vector ˜ui. Similarly ob-
each ui to the nearest integer multiple of
tain ˜vi. Let ˜w(S) denote the vector (˜u1(S), ˜v1( ¯S), ˜u2(S), ˜v2( ¯S), . . . , ˜uk(S), ˜vk( ¯S)). We
will construct a list of all possible values of the vector ˜w(S). Again, if several diﬀer-
ent S’s lead to the same vector ˜w(S), we will keep only one copy on the list. The list
will be constructed by dynamic programming. For the recursive step of dynamic pro-
gramming, assume we already have a list of all such vectors for S ⊆ {1, 2, . . . , i} and
wish to construct the list for S ⊆ {1, 2, . . . , i + 1}. Each S ⊆ {1, 2, . . . , i} leads to two
possible S(cid:48) ⊆ {1, 2, . . . , i + 1}, namely, S and S ∪ {i + 1}. In the ﬁrst case, the vector
˜w(S(cid:48)) = (˜u1(S), ˜v1( ¯S) + ˜v1,i+1, ˜u2(S), ˜v2( ¯S) + ˜v2,i+1, . . . , ...).
In the second case, it is
˜w(S(cid:48)) = (˜u1(S) + ˜u1,i+1, ˜v1( ¯S), ˜u2(S) + ˜u2,i+1, ˜v2( ¯S), . . . , ...) We put in these two vectors
for each vector in the previous list. Then, crucially, we prune - i.e., eliminate duplicates.

74

Assume that k is constant. Now, we show that the error is at most

as claimed.
Since ui, vi are unit length vectors, |ui(S)|, |vi( ¯S)| ≤
nk2 = 1
k2
and similarly for vi. To bound the error, we use an elementary fact: if a, b are reals with
|a|, |b| ≤ M and we estimate a by a(cid:48) and b by b(cid:48) so that |a − a(cid:48)|, |b − b(cid:48)| ≤ δ ≤ M , then
a(cid:48)b(cid:48) is an estimate of ab in the sense

n. Also |˜ui(S) − ui(S)| ≤ n

√

√

n2
k+1

|ab − a(cid:48)b(cid:48)| = |a(b − b(cid:48)) + b(cid:48)(a − a(cid:48))| ≤ |a||b − b(cid:48)| + (|b| + |b − b(cid:48)|)|a − a(cid:48)| ≤ 3M δ.

Using this, we get that

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

k
(cid:88)

i=1

σi˜ui(S)˜vi( ¯S) −

k
(cid:88)

i=1

(cid:12)
(cid:12)
(cid:12)
σiui(S)vi(S)
(cid:12)
(cid:12)

√

≤ 3kσ1

n/k2 ≤ 3n3/2/k ≤ n2/k,

and this meets the claimed error bound.

Next, we show that the running time is polynomially bounded. |˜ui(S)|, |˜vi(S)| ≤ 2

n.
nk2 possible
Since ˜ui(S), ˜vi(S) are all integer multiples of 1/(nk2), there are at most 2/
values of ˜ui(S), ˜vi(S) from which it follows that the list of ˜w(S) never gets larger than
(1/

nk2)2k which for ﬁxed k is polynomially bounded.

√

√

√

We summarize what we have accomplished.

Theorem 3.17 Given a directed graph G(V, E), a cut of size at least the maximum cut
minus O

can be computed in polynomial time n for any ﬁxed k.

(cid:17)

(cid:16) n2
√
k

It would be quite a surprise to have an algorithm that actually achieves the same
accuracy in time polynomial in n and k because this would give an exact max cut in
polynomial time.

3.7 Singular Vectors and Eigenvectors

An eigenvector of a square matrix A is a vector v satisfying Av = λv, for a non-zero
scaler λ which is the corresponding eigenvalue. A square matrix A can be viewed as a
linear transformation from a space into itself which transforms an eigenvector into a scaler
multiple of itself. The eigenvector decomposition of A is V T DV where the columns of V
are the eigenvectors of A and D is a diagonal matrix with the eigenvalues on the diagonal.

A non square m × n matrix A also deﬁnes a linear transformation, but now from Rn
to Rm. In this case, eigenvectors do not make sense. But singular vectors can be deﬁned.
They serve the purpose of decomposing the linear transformation deﬁned by the matrix
A into the sum of simple linear transformations, each of which maps Rn to a one dimen-
sional space, i.e., to a line through the origin.

75

A positive semi-deﬁnite matrix can be decomposed into a product AAT . Thus, the
eigenvector decomposition can be obtained from the singular value decomposition of A =
U DV T since

AAT = U DV T V DU T = U D2U T =

(cid:88)

σi(A)2uiui

T ,

where the ui, the columns of U, are the eigenvectors of AAT .

i

There are many applications of singular vectors and eigenvectors. For square non-
symmetric matrices, both singular vectors and eigenvectors are deﬁned but they may be
diﬀerent. In an important application, the pagerank, one represents the web by a n × n
matrix A, where, aij is one if there is a hypertext link from the ith page in the web to the
jth page. Otherwise, it is zero. The matrix is scaled by dividing each entry by the sum of
entries in its row to get a stochastic matrix P. A stochastic matrix is one with nonnegative
entries where each row sums to one. Note that P is not necessarily symmetric. Since the
row sums of P are all one, the vector 1 of all one’s is a right eigenvector with eigenvalue
one, i.e., P 1 = 1. This eigenvector contains no information. But the left eigenvector v
with eigenvalue one satisﬁes vT P = vT and is the stationary probability of the Markov
chain with transition probability matrix P . So, it is the proportion of time a Markov
chain spends at each vertex (page) in the long run. A simpliﬁed deﬁnition of pagerank
ranks the page in order of its component in the top left eigenvector v.

3.8 Bibliographic Notes

Singular value decomposition is fundamental to numerical analysis and linear algebra.
There are many texts on these subjects and the interested reader may want to study these.
A good reference is [GvL96]. The material on clustering a mixture of Gaussians in Section
3.6.2 is from [VW02]. Modeling data with a mixture of Gaussians is a standard tool in
statistics. Several well-known heuristics like the expectation-minimization algorithm are
used to ﬁt the mixture model to data. Recently, in theoretical computer science, there
has been modest progress on provable polynomial-time algorithms for learning mixtures.
Some references are [DS07], [AK], [AM05], [MV10]. The application to the discrete opti-
mization problem is from [FK99]. The section on ranking documents/webpages is from
two inﬂuential papers, one on hubs and authorities by Jon Kleinberg [Kle99] and the other
on pagerank by Page, Brin, Motwani and Winograd [BMPW98].

76

3.9 Exercises

Exercise 3.1 (Best ﬁt functions versus best least squares ﬁt) In many experiments
one collects the value of a parameter at various instances of time. Let yi be the value of
the parameter y at time xi. Suppose we wish to construct the best linear approximation
to the data in the sense that we wish to minimize the mean square error. Here error is
measured vertically rather than perpendicular to the line. Develop formulas for m and b to
minimize the mean square error of the points {(xi, yi) |1 ≤ i ≤ n} to the line y = mx + b.

Exercise 3.2 Given ﬁve observed parameters, height, weight, age, income, and blood
pressure of n people, how would one ﬁnd the best least squares ﬁt subspace of the form

a1 (height) + a2 (weight) + a3 (age) + a4 (income) + a5 (blood pressure) = 0

Here a1, a2, . . . , a5 are the unknown parameters. If there is a good best ﬁt 4-dimensional
subspace, then one can think of the points as lying close to a 4-dimensional sheet rather
than points lying in 5-dimensions. Why is it better to use the perpendicular distance to the
subspace rather than vertical distance where vertical distance to the subspace is measured
along the coordinate axis corresponding to one of the unknowns?

Exercise 3.3 What is the best ﬁt line through the origin for each of the following set of
points?

1. {(0, 1) , (1, 0)}

2. {(0, 1) , (2, 0)}

3. The rows of the matrix





4
17
−2 26
7
11





Exercise 3.4 Find the left and right-singular vectors, the singular values, and the SVD
decomposition of the matrix M in Figure 3.5.

Exercise 3.5 Let

M =





1 1
0 3
3 0





Compute the ﬁrst right-singular vector, the ﬁrst singular value, and the ﬁrst left-singular
vector of M. Hint: ﬁrst plot the rows of M on the 2-dimensional plane.

Exercise 3.6 Let A be a square n × n matrix whose rows are orthonormal. Prove that
the columns of A are orthonormal.

77

(1,3)

(0,2)

(3,1)

(2,0)

M =







0 2
2 0
1 3
3 1







Figure 3.5: SVD problem

Exercise 3.7 Suppose A is a n × n matrix with block diagonal structure with k equal size
blocks where all entries of the ith block are ai with a1 > a2 > · · · > ak > 0. Show that A
has exactly k nonzero singular vectors v1, v2, . . . , vk where vi has the value ( k
n )1/2 in the
coordinates corresponding to the ith block and 0 elsewhere. In other words, the singular
vectors exactly identify the blocks of the diagonal. What happens if a1 = a2 = · · · = ak?
In the case where the ai are equal, what is the structure of the set of all possible singular
vectors?
Hint: By symmetry, the top singular vector’s components must be constant in each block.

Exercise 3.8 Prove that the left-singular vectors of A are the right-singular vectors of
AT .

Exercise 3.9 Interpret the ﬁrst right and left-singular vectors for the document term
matrix.

Exercise 3.10

1. Show that the rank of A is r where r is the miminum i such that arg max

|A v| = 0.

v⊥v1,v2,...,vi
|v|=1

2. Show that (cid:12)

1 A(cid:12)

(cid:12)uT

(cid:12) = max
|u|=1

(cid:12)uTA(cid:12)
(cid:12)

(cid:12) = σ1.

Hint: Use SVD.

Exercise 3.11 If σ1, σ2, . . . , σr are the singular values of A and v1, v2, . . . , vr are the
corresponding right-singular vectors, show that

1. AT A =

r
(cid:80)
i=1

σ2
i vivi

T

2. v1, v2, . . . vr are eigenvectors of AT A.

78

3. Assuming that the set of eigenvectors of a matrix is unique, conclude that the set of

singular values of the matrix is unique.

See the appendix for the deﬁnition of eigenvectors.

Exercise 3.12 Let (cid:80)

i

σiuivT

i be the singular value decomposition of a rank r matrix A.

Let Ak =

σiuivT

i be a rank k approximation to A. Express the following quantities in

k
(cid:80)
i=1

terms of the singular values {σi, 1 ≤ i ≤ r}.

1. ||Ak||2
F

2. ||Ak||2
2

3. ||A − Ak||2
F

4. ||A − Ak||2
2

Exercise 3.13 If A is a symmetric matrix with distinct singular values, show that the
left and right singular vectors are the same and that A = V DV T .

Exercise 3.14 Let A be a matrix. Given an algorithm for ﬁnding

v1 = arg max

|Av| ,

|v|=1

describe an algorithm to ﬁnd the SVD of A.

Exercise 3.15 Compute the singular valued decomposition of the matrix

A =

(cid:19)

(cid:18) 1 2
3 4

Exercise 3.16 Write a program to implement the power method for computing the ﬁrst
singular vector of a matrix. Apply your program to the matrix

A =










1
2
...
9
10

3 · · ·
2
4 · · ·
3
...
...
10 0 · · ·
0 · · ·
0

9
10

0
0










.

10
0
...
0
0

Exercise 3.17 Modify the power method to ﬁnd the ﬁrst four singular vectors of a matrix
A as follows. Randomly select four vectors and ﬁnd an orthonormal basis for the space
spanned by the four vectors. Then multiple each of the basis vectors times A and ﬁnd a
new orthonormal basis for the space spanned by the resulting four vectors. Apply your
method to ﬁnd the ﬁrst four singular vectors of matrix A of Exercise 3.16

79

Exercise 3.18 Let A be a real valued matrix. Prove that B = AAT is positive semi
deﬁnite. A matrix B is positive semi deﬁnite if for all x, xT Bx ≥ 0.

Exercise 3.19 Let A be the adjacency matrix of a graph. The Laplacian of A is L =
D − A where D is a diagonal matrix whose diagonal entries are the row sums of A. Prove
that L is positive semi deﬁnite. A matrix L is positive semi deﬁnite if for all x, xT Lx ≥ 0.

Exercise 3.20 Prove that the eigenvalues of a symmetric real valued matrix are real.

Exercise 3.21 Suppose A is a square invertible matrix and the SVD of A is A = (cid:80)
Prove that the inverse of A is (cid:80)

i

1
σi

viuT
i .

i

σiuivT
i .

σiuivT

Exercise 3.22 Suppose A is square, but not necessarily invertible and has SVD A =
r
(cid:80)
i . Show that BAx = x for all x in the span of the right-
i=1
singular vectors of A. For this reason B is sometimes called the pseudo inverse of A and
can play the role of A−1 in many applications.

i . Let B =

r
(cid:80)
i=1

viuT

1
σi

Exercise 3.23

1. For any matrix A, show that σk ≤ ||A||F√
k

.

2. Prove that there exists a matrix B of rank at most k such that ||A − B||2 ≤ ||A||F√
k

.

3. Can the 2-norm on the left hand side in (b) be replaced by Frobenius norm?

Exercise 3.24 Suppose an n × d matrix A is given and you are allowed to preprocess
A. Then you are given a number of d-dimensional vectors x1, x2, . . . , xm and for each of
these vectors you must ﬁnd the vector Axi approximately, in the sense that you must ﬁnd a
|ui − Axi| ≤ ε||A||F |xi|. Here ε >0 is a given error bound. Describe
vector ui satisfying
(cid:1) per xi not counting the preprocessing
an algorithm that accomplishes this in time O (cid:0) d+n
ε2
time.

Exercise 3.25 (Constrained Least Squares Problem using SVD) Given A, b,
and m, use the SVD algorithm to ﬁnd a vector x with |x| < m minimizing |Ax − b|. This
problem is a learning exercise for the advanced student. For hints/solution consult Golub
and van Loan, Chapter 12.

Exercise 3.26 (Document-Term Matrices): Suppose we have a m×n document-term
matrix where each row corresponds to a document where the rows have been normalized
to length one. Deﬁne the “similarity” between two such documents by their dot product.

80

1. Consider a “synthetic” document whose sum of squared similarities with all docu-
ments in the matrix is as high as possible. What is this synthetic document and how
would you ﬁnd it?

2. How does the synthetic document in (1) diﬀer from the center of gravity?

3. Building on (1), given a positive integer k, ﬁnd a set of k synthetic documents such
that the sum of squares of the mk similarities between each document in the matrix
and each synthetic document is maximized. To avoid the trivial solution of selecting
k copies of the document in (1), require the k synthetic documents to be orthogonal
to each other. Relate these synthetic documents to singular vectors.

4. Suppose that the documents can be partitioned into k subsets (often called clusters),
where documents in the same cluster are similar and documents in diﬀerent clusters
are not very similar. Consider the computational problem of isolating the clusters.
This is a hard problem in general. But assume that the terms can also be partitioned
into k clusters so that for i (cid:54)= j, no term in the ith cluster occurs in a document
in the jth cluster. If we knew the clusters and arranged the rows and columns in
them to be contiguous, then the matrix would be a block-diagonal matrix. Of course
the clusters are not known. By a “block” of the document-term matrix, we mean
a submatrix with rows corresponding to the ithcluster of documents and columns
corresponding to the ithcluster of terms . We can also partition any n vector into
blocks. Show that any right-singular vector of the matrix must have the property
that each of its blocks is a right-singular vector of the corresponding block of the
document-term matrix.

5. Suppose now that the singular values of all the blocks are distinct (also across blocks).

Show how to solve the clustering problem.

Hint: (4) Use the fact that the right-singular vectors must be eigenvectors of AT A. Show
that AT A is also block-diagonal and use properties of eigenvectors.

Exercise 3.27 Generate a number of samples according to a mixture of 1-dimensional
Gaussians. See what happens as the centers get closer. Alternatively, see what happens
when the centers are ﬁxed and the standard deviation is increased.

Exercise 3.28 (Newcomb/Binford) The frequency distribution of ﬁrst digits in many
data sets is not uniform. One might expect the distribution to be scale free in that changing
the units of measure should not change the distribution. Determine a distribution where
multiplying each number by two does not change the distribution. Hint: Construct a graph
with nine vertices where each vertex corresponds to one of the nine ﬁrst digits. The edge
from vertex i to vertex j is labeled with the probability that multiplying a number whose ﬁrst
digit is i by 2 results in a number whose ﬁrst digit is j. What is the stationary probability
of a random walk on this graph?

81

For scale factor 3 the adjacency matrix is













1
3

1
0 0 1
3 0 0 0 0
3
3 0 0 0 0 0 0 0 1
2
3
1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
2
1
3 0 0 0 0 0 0 0
3
0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0













The ﬁrst eigenvector of AT is
0.3214 0.1607 0.1071 0.1071 0.0536 0.0536 0.0536 0.0536 0.0357

Exercise 3.29 Show that maximizing xT uuT (1 − x) subject to xi ∈ {0, 1} is equivalent
to partitioning the coordinates of u into two subsets where the sum of the elements in both
subsets are equal.

Exercise 3.30 Read in three photos, convert each photo to a matrix, perform a singular
value decomposition, and plot the singular values of the matrices. To read in a photo see
the hint in Exercise 3.31.

Exercise 3.31 Read in a photo and convert to a matrix. Perform a singular value de-
composition of the matrix. Reconstruct the photo using only

1. 10%, 25%, 50% of the singular values. What percent of the Forbenius norm is

captured in each case?

2. the subset of singular vlaues {σ1, σ2, . . . , σk} where (cid:80)k

i=1 σ2

i = f ||A||2

F and f = 0.1,

0.25, and 0.5.

Print the reconstructed photos. How good is the quality of the reconstructed photos?

Hint: If you use Matlab, the command to read a photo is imread. The types of ﬁles
that can be read are given by imformats. To print the ﬁle use imwrite. Print using jpeg
format. To access the ﬁle afterwards you may need to add the ﬁle extension .jpg. The
command imread will read the ﬁle in uint8 and you will need to convert to double for the
SVD code. Afterwards you will need to convert back to uint8 to write the ﬁle. If the photo
is a color photo you will get three matrices for the three colors used.

Exercise 3.32 Create a set of 100, 100 × 100 matrices of random numbers between 0 and
1 such that each entry is highly correlated with the adjacency entries. Find the SVD of
A. What fraction of the Frobenius norm of A is captured by the top 10 singular vectors?
How many singular vectors are required to capture 95% of the Frobenius norm?

Exercise 3.33 Create a 100 × 100 matrix A of random numbers between 0 and 1 such
that each entry is highly correlated with the adjacency entries and ﬁnd the ﬁrst 10 vectors
for a single basis that is reasonably good for all 100 matrices. How does one do this?
What fraction of the Frobenius norm of a new matrix is captured by the basis?

82

Exercise 3.34 Show that the running time for the maximum cut algorithm in Section ??
can be carried out in time O(n3 + poly(n)kk), where poly is some polynomial.

Exercise 3.35 Let x1, x2, . . . , xn be n points in d-dimensional space and let X be the
n × d matrix whose rows are the n points. Suppose we know only the matrix D of pairwise
distances between points and not the coordinates of the points themselves. The set of points
x1, x2, . . . , xn giving rise to the distance matrix D is not unique since any translation,
rotation, or reﬂection of the coordinate system leaves the distances invariant. Fix the
origin of the coordinate system so that the centroid of the set of points is at the origin.
That is, (cid:80)n

i=1 xi = 0.

1. Show that the elements of XX T are given by

xixT

j = −

(cid:34)

1
2

d2
ij −

1
n

n
(cid:88)

j=1

d2
ij −

1
n

n
(cid:88)

i=1

d2
ij +

1
n2

n
(cid:88)

n
(cid:88)

i=1

j=1

(cid:35)

d2
ij

.

2. Describe an algorithm for determining the matrix X whose rows are the xi.

Exercise 3.36

1. Consider the pairwise distance matrix for twenty US cities given below. Use the
algorithm of Exercise 3.35 to place the cities on a map of the US. The algorithm is
called classical multidimensional scaling, cmdscale, in Matlab. Alternatively use the
pairwise distance matrix to place the cities on a map of China.

Note: Any rotation or a mirror image of the map will have the same pairwise
distances.

2. Suppose you had airline distances for 50 cities around the world. Could you use

these distances to construct a world map?

B
O
S
-
400
851
1551
1769
1605
2596
1137
1255
1123
188
1282
271
2300
483
1038
2099
2699
2493
393

B
U
F
400
-
454
1198
1370
1286
2198
803
1181
731
292
883
279
1906
178
662
1699
2300
2117
292

C
H
I
851
454
-
803
920
940
1745
482
1188
355
713
432
666
1453
410
262
1260
1858
1737
597

D
A
L
1551
1198
803
-
663
225
1240
420
1111
862
1374
586
1299
887
1070
547
999
1483
1681
1185

Boston
Buﬀalo
Chicago
Dallas
Denver
Houston
Los Angeles
Memphis
Miami
Minneapolis
New York
Omaha
Philadelphia
Phoenix
Pittsburgh
Saint Louis
Salt Lake City
San Francisco
Seattle
Washington D.C.

L
A

2596
2198
1745
1240
831
1374
-
1603
2339
1524
2451
1315
2394
357
2136
1589
579
347
959
2300

M
E
M
1137
803
482
420
879
484
1603
-
872
699
957
529
881
1263
660
240
1250
1802
1867
765

M
I
A
1255
1181
1188
1111
1726
968
2339
872
-
1511
1092
1397
1019
1982
1010
1061
2089
2594
2734
923

M
I
M
1123
731
355
862
700
1056
1524
699
1511
-
1018
290
985
1280
743
466
987
1584
1395
934

D
E
N
1769
1370
920
663
-
879
831
879
1726
700
1631
488
1579
586
1320
796
371
949
1021
1494

H
O
U
1605
1286
940
225
879
-
1374
484
968
1056
1420
794
1341
1017
1137
679
1200
1645
1891
1220

83

N
Y

188
292
713
1374
1631
1420
2451
957
1092
1018
-
1144
83
2145
317
875
1972
2571
2408
230

O
M
A
1282
883
432
586
488
794
1315
529
1397
290
1144
-
1094
1036
836
354
833
1429
1369
1014

P
H
I
271
279
666
1299
1579
1341
2394
881
1019
985
83
1094
-
2083
259
811
1925
2523
2380
123

P
H
O
2300
1906
1453
887
586
1017
357
1263
1982
1280
2145
1036
2083
-
1828
1272
504
653
1114
1973

P
I
T
483
178
410
1070
1320
1137
2136
660
1010
743
317
836
259
1828
-
559
1668
2264
2138
192

S
t
L
1038
662
262
547
796
679
1589
240
1061
466
875
354
811
1272
559
-
1162
1744
1724
712

S
L
C
2099
1699
1260
999
371
1200
579
1250
2089
987
1972
833
1925
504
1668
1162
-
600
701
1848

S
F

2699
2300
1858
1483
949
1645
347
1802
2594
1584
2571
1429
2523
653
2264
1744
600
-
678
2442

S
E
A
2493
2117
1737
1681
1021
1891
959
1867
2734
1395
2408
1369
2380
1114
2138
1724
701
678
-
2329

D
C

393
292
597
1185
1494
1220
2300
765
923
934
230
1014
123
1973
192
712
1848
2442
2329
-

Boston
Buﬀalo
Chicago
Dallas
Denver
Houston
Los Angeles
Memphis
Miami
Minneapolis
New York
Omaha
Philadelphia
Phoenix
Pittsburgh
Saint Louis
Salt Lake City
San Francisco
Seattle
Washington D.C.

Nan- Har- Chang-
ning
2373
2389
1892
993
2657
4279
3431
2673
0
3592
3340
3046

chun
979
955
2090
2905
1458
4279
4715
2170
3340
256
0
294

bin
1230
1207
2342
3156
1710
4531
4967
2422
3592
0
256
546

Shen-
yang
684
661
1796
2610
1164
3985
4421
1876
3046
546
294
0

City

Beijing
Tianjin
Shanghai
Chongqing
Hohhot
Urumqi
Lhasa
Yinchuan
Nanning
Harbin
Changchun
Shenyang

Bei-
jing
0
125
1239
3026
480
3300
3736
1192
2373
1230
979
684

Tian-
jin
125
0
1150
1954
604
3330
3740
1316
2389
1207
955
661

Shang- Chong- Hoh- Urum-

hai
1239
1150
0
1945
1717
3929
4157
2092
1892
2342
2090
1796

qing
3026
1954
1945
0
1847
3202
2457
1570
993
3156
2905
2610

hot
480
604
1717
1847
0
2825
3260
716
2657
1710
1458
1164

qi
3300
3330
3929
3202
2825
0
2668
2111
4279
4531
4279
3985

Lha-
sa
3736
3740
4157
2457
3260
2668
0
2547
3431
4967
4715
4421

Yin-
chuan
1192
1316
2092
1570
716
2111
2547
0
2673
2422
2170
1876

84

4 Random Graphs

Large graphs appear in many contexts such as the World Wide Web, the internet,
social networks, journal citations, and other places. What is diﬀerent about the modern
study of large graphs from traditional graph theory and graph algorithms is that here
one seeks statistical properties of these very large graphs rather than an exact answer to
questions. This is akin to the switch physics made in the late 19th century in going from
mechanics to statistical mechanics. Just as the physicists did, one formulates abstract
models of graphs that are not completely realistic in every situation, but admit a nice
mathematical development that can guide what happens in practical situations. Perhaps
the most basic such model is the G (n, p) model of a random graph. In this chapter, we
study properties of the G(n, p) model as well as other models.

4.1 The G(n, p) Model

The G (n, p) model, due to Erd¨os and R´enyi, has two parameters, n and p. Here n is
the number of vertices of the graph and p is the edge probability. For each pair of distinct
vertices, v and w, p is the probability that the edge (v,w) is present. The presence of each
edge is statistically independent of all other edges. The graph-valued random variable
with these parameters is denoted by G (n, p). When we refer to “the graph G (n, p)”, we
mean one realization of the random variable. In many cases, p will be a function of n
such as p = d/n for some constant d. In this case, the expected degree of a vertex of the
graph is d
n(n − 1) ≈ d. The interesting thing about the G(n, p) model is that even though
edges are chosen independently with no “collusion”, certain global properties of the graph
emerge from the independent choices. For small p, with p = d/n, d < 1, each connected
component in the graph is small. For d > 1, there is a giant component consisting of a
constant fraction of the vertices. In addition, there is a rapid transition at the threshold
d = 1. Below the threshold, the probability of a giant component is very small, and above
the threshold, the probability is almost one.

The phase transition at the threshold d = 1 from very small o(n) size components to a
giant Ω(n) sized component is illustrated by the following example. Suppose the vertices
represent people and an edge means the two people it connects know each other. Given a
chain of connections, such as A knows B, B knows C, C knows D, ..., and Y knows Z, we
say that A indirectly knows Z. Thus, all people belonging to a connected component of
the graph indirectly know each other. Suppose each pair of people, independent of other
pairs, tosses a coin that comes up heads with probability p = d/n. If it is heads, they
know each other; if it comes up tails, they don’t. The value of d can be interpreted as the
expected number of people a single person directly knows. The question arises as to how
large are sets of people who indirectly know each other ?

If the expected number of people each person knows is more than one, then a giant
component of people, all of whom indirectly know each other, will be present consisting

85

Constant fraction
know each other
indirectly

1 − o(1)

Probability
of a giant
component

Vanishing fraction
know each other
indirectly

o(1)

1 − ε

1 + ε

Expected number of people each person knows

Figure 4.1: Probability of a giant component as a function of the expected number of
people each person knows directly.

of a constant fraction of all the people. On the other hand, if in expectation, each person
knows less than one person, the largest set of people who know each other indirectly is a
vanishingly small fraction of the whole. Furthermore, the transition from the vanishing
fraction to a constant fraction of the whole, happens abruptly between d slightly less than
one to d slightly more than one. See Figure 4.1. Note that there is no global coordination
of who knows whom. Each pair of individuals decides independently. Indeed, many large
real-world graphs, with constant average degree, have a giant component. This is perhaps
the most important global property of the G(n, p) model.

4.1.1 Degree Distribution

One of the simplest quantities to observe in a real graph is the number of vertices of
given degree, called the vertex degree distribution. It is also very simple to study these
distributions in G (n, p) since the degree of each vertex is the sum of n − 1 independent
random variables, which results in a binomial distribution. Since we will be dealing with
graphs where the number of vertices n, is large, from here on we often replace n − 1 by n
to simplify formulas.

Example: In G(n, 1
2), each vertex is of degree close to n/2. In fact, for any ε > 0, the
degree of each vertex almost surely is within 1 ± ε times n/2. To see this, note that the
probability that a vertex is of degree k is

Prob (k) =

(cid:18)n − 1
k

(cid:19) (cid:18)1
2

(cid:19)k (cid:18) 1
2

(cid:19)n−k
≈

(cid:18)n
k

(cid:19) (cid:18)1
2

(cid:19)k (cid:18) 1
2

(cid:19)n−k
=

1
2n

(cid:19)

(cid:18)n
k

.

86

35

34

33

32

31

40

39

38

37

36

5

4

3

2

1

10

9

8

7

6

15

14

13

12

11

20

19

18

17

16

25

24

23

22

21

A graph with 40 vertices and 24 edges

17

22

1

30

34

3

2

18

23

31

35

19

7

9

6

8

4

5

10

11

12

13

14

15

16

36

37

38

20

24

26

28

32

39

30

29

28

27

26

21

25

27

29

33

40

A randomly generated G(n, p) graph with 40 vertices and 24 edges

Figure 4.2: Two graphs, each with 40 vertices and 24 edges. The second graph was
randomly generated using the G(n, p) model with p = 1.2/n. A graph similar to the top
graph is almost surely not going to be randomly generated in the G(n, p) model, whereas
a graph similar to the lower graph will almost surely occur. Note that the lower graph
consists of a giant component along with a number of small components that are trees.

87

Binomial distribution

Power law distribution

Figure 4.3: Illustration of the binomial and the power law distributions.

This probability distribution has a mean m = n/2 and variance σ2 = n/4. To see this,
observe that the degree k is the sum of n indicator variables that take on value zero or
one depending whether an edge is present or not. The expected value of the sum is the
sum of the expected values and the variance of the sum is the sum of the variances.

Near the mean, the binomial distribution is well approximated by the normal distri-

bution. See Section 11.4.9 in the appendix.

√

1
2πσ2

1
2

e−

(k−m)2

σ2 =

1
(cid:112)πn/2

e− (k−n/2)2

n/2

The standard deviation of the normal distribution is
ability mass is within an additive term ±c
thus is certainly within a multiplicative factor of 1 ± ε of n/2 for suﬃciently large n.

√
n
2 and essentially all of the prob-
n of the mean n/2 for some constant c and

√

The degree distribution of G (n, p) for general p is also binomial. Since p is the prob-
ability of an edge being present, the expected degree of a vertex is d ≈ pn. The actual
degree distribution is given by

Prob(vertex has degree k) = (cid:0)n−1

(cid:1)pk(1 − p)n−k−1 ≈ (cid:0)n

(cid:1)pk(1 − p)n−k.

k

k

(cid:1) is the number of ways of choosing k edges, out of the possible n − 1
The quantity (cid:0)n−1
edges, and pk(1 − p)n−k−1 is the probability that the k selected edges are present and the
remaining n−k−1 are not. Since n is large, replacing n−1 by n does not cause much error.

k

The binomial distribution falls oﬀ exponentially fast as one moves away from the mean.
However, the degree distributions of graphs that appear in many applications do not ex-
hibit such sharp drops. Rather, the degree distributions are much broader. This is often

88

referred to as having a “heavy tail”. The term tail refers to values of a random variable
far away from its mean, usually measured in number of standard deviations. Thus, al-
though the G (n, p) model is important mathematically, more complex models are needed
to represent real world graphs.

Consider an airline route graph. The graph has a wide range of degrees, from degree
one or two for a small city, to degree 100, or more, for a major hub. The degree distribution
is not binomial. Many large graphs that arise in various applications appear to have power
law degree distributions. A power law degree distribution is one in which the number of
vertices having a given degree decreases as a power of the degree, as in

Number(degree k vertices) = c n
kr ,

for some small positive real r, often just slightly less than three. Later, we will consider
a random graph model giving rise to such degree distributions.

The following theorem claims that the degree distribution of the random graph G (n, p)
is tightly concentrated about its expected value. That is, the probability that the degree of
a vertex diﬀers from its expected degree, np, by more than λ
np, drops oﬀ exponentially
fast with λ.

√

Theorem 4.1 Let v be a vertex of the random graph G(n, p). Let α be a real number in
(0,

np).

√

Prob(|np − deg(v)| ≥ α

√

np) ≤ 3e−α2/8.

Proof: The degree deg(v) is the sum of n − 1 independent Bernoulli random variables,
y1, y2, . . . , yn−1, where, yi is the indicator variable that the ith edge from v is present. So
the theorem follows from Theorem 2.12.

Theorem 4.1.1 was for one vertex. The corollary below deals with all vertices.

Corollary 4.2 Suppose ε is a positive constant. If p is Ω(ln n/nε2), then, almost surely,
every vertex has degree in the range (1 − ε)np to (1 + ε)np.

np to get that the probability that an individual
Proof: Apply Theorem with α = ε
vertex has degree outside the range [(1 − ε)np, (1 + ε)np] is at most 3e−ε2np/8. By the
union bound, the probability that some vertex has degree outside this range is at most
3ne−ε2np/8. For this to be o(1), it suﬃces for p to be Ω(ln n/nε2). Hence the Corollary.

√

Note that the assumption p is Ω(ln n/nε2) is necessary. If p = d/n for d a constant,
then, indeed, some vertices may have degrees outside the range. Without the Ω(ln n/nε2)
assumption, for p = 1
n , Corollary 4.1.1 would claim almost surely no vertex had a degree
that was greater than a constant independent of n. But shortly we will see that it is highly

89

likely that for p = 1

n there is a vertex of degree Ω(log n/ log log n).

When p is a constant, the expected degree of vertices in G (n, p) increases with n. For
(cid:1), the expected degree of a vertex is n/2. In many real applications,
example, in G (cid:0)n, 1
we will be concerned with G (n, p) where p = d/n, for d a constant, i.e., graphs whose
expected degree is a constant d independent of n. Holding d = np constant as n goes to
inﬁnity, the binomial distribution

2

Prob (k) =

(cid:19)

pk (1 − p)n−k

(cid:18)n
k

approaches the Poisson distribution

Prob(k) =

(np)k
k!

e−np =

dk
k!

e−d.

To see this, assume k = o(n) and use the approximations n − k ∼= n, (cid:0)n
(cid:0)1 − 1

(cid:1)n−k ∼= e−1 to approximate the binomial distribution by

k

n

(cid:1) ∼= nk

k! , and

(cid:19)

(cid:18)n
k

lim
n→∞

pk(1 − p)n−k =

(cid:19)k

nk
k!

(cid:18) d
n

(1 −

d
n

)n =

dk
k!

e−d.

Note that for p = d
n , where d is a constant independent of n, the probability of the
binomial distribution falls oﬀ rapidly for k > d, and is essentially zero for all but some
ﬁnite number of values of k. This justiﬁes the k = o(n) assumption. Thus, the Poisson
distribution is a good approximation.

Example: In G(n, 1
n ) many vertices are of degree one, but not all. Some are of degree
zero and some are of degree greater than one. In fact, it is highly likely that there is a
vertex of degree Ω(log n/ log log n). The probability that a given vertex is of degree k is

Prob (k) =

(cid:18)n
k

(cid:19) (cid:18) 1
n

(cid:19)k(cid:18)

1 −

(cid:19)n−k
≈

1
n

e−1
k!

.

If k = log n/ log log n,

log kk = k log k ∼=

log n
log log n

(log log n − log log log n) ∼= log n

and thus kk ∼= n. Since k! ≤ kk ∼= n, the probability that a vertex has degree k =
log n/ log log n is at least 1
en. If the degrees of vertices were independent random
variables, then this would be enough to argue that there would be a vertex of degree
1
log n/ log log n with probability at least 1 − (cid:0)1 − 1
e ∼= 0.31. But the degrees
are not quite independent since when an edge is added to the graph it aﬀects the degree
of two vertices. This is a minor technical point, which one can get around.

(cid:1)n = 1 − e−

k! e−1 ≥ 1

en

90

4.1.2 Existence of Triangles in G(n, d/n)

What is the expected number of triangles in G (cid:0)n, d

(cid:1), when d is a constant? As the
number of vertices increases one might expect the number of triangles to increase, but this
is not the case. Although the number of triples of vertices grows as n3, the probability
of an edge between two speciﬁc vertices decreases linearly with n. Thus, the probability
of all three edges between the pairs of vertices in a triple of vertices being present goes
down as n−3, exactly canceling the rate of growth of triples.

n

A random graph with n vertices and edge probability d/n, has an expected number
(cid:1) triples of vertices.
of triangles that is independent of n, namely d3/6. There are (cid:0)n
(cid:1)3 of being a triangle. Let ∆ijk be the indicator variable
Each triple has probability (cid:0) d
for the triangle with vertices i, j, and k being present. That is, all three edges (i, j),
(j, k), and (i, k) being present. Then the number of triangles is x = (cid:80)
ijk ∆ijk. Even
though the existence of the triangles are not statistically independent events, by linearity
of expectation, which does not assume independence of the variables, the expected value
of a sum of random variables is the sum of the expected values. Thus, the expected
number of triangles is

n

3

E(x) = E

(cid:16) (cid:88)

(cid:17)

=

(cid:88)

∆ijk

E(∆ijk) =

ijk

ijk

(cid:19)3

(cid:18)n
3

(cid:19) (cid:18) d
n

≈

d3
6

.

Even though on average there are d3

6 triangles per graph, this does not mean that with
high probability a graph has a triangle. Maybe half of the graphs have d3
3 triangles and
the other half have none for an average of d3
6 triangles. Then, with probability 1/2, a
graph selected at random would have no triangle. If 1/n of the graphs had d3
6 n triangles
and the remaining graphs had no triangles, then as n goes to inﬁnity, the probability that
a graph selected at random would have a triangle would go to zero.

We wish to assert that with some nonzero probability there is at least one triangle
in G(n, p) when p = d
n . If all the triangles were on a small number of graphs, then the
number of triangles in those graphs would far exceed the expected value and hence the
variance would be high. A second moment argument rules out this scenario where a small
fraction of graphs have a large number of triangles and the remaining graphs have none.

Calculate E(x2) where x is the number of triangles. Write x as x = (cid:80)

ijk ∆ijk, where
∆ijk is the indicator variable of the triangle with vertices i, j, and k being present. Ex-
panding the squared term

E(x2) = E

(cid:16) (cid:88)

(cid:17)2

= E

(cid:16) (cid:88)

∆ijk

∆ijk∆i(cid:48)j(cid:48)k(cid:48)

(cid:17)

.

i,j,k

i, j, k
i(cid:48),j(cid:48),k(cid:48)

91

or

The two triangles of Part 1 are either
disjoint or share at most one vertex

The two triangles
of Part 2 share an
edge

The two triangles in
Part 3 are the same tri-
angle

Figure 4.4: The triangles in Part 1, Part 2, and Part 3 of the second moment argument
for the existence of triangles in G(n, d

n ).

Split the above sum into three parts. Split the above sum into three parts. In Part 1,
let S1 be the set of i, j, k and i(cid:48), j(cid:48), k(cid:48) which share at most one vertex and hence the two
triangles share no edge. In this case, ∆ijk and ∆i(cid:48)j(cid:48)k(cid:48) are independent and

(cid:16) (cid:88)

E

S1

∆ijk∆i(cid:48)j(cid:48)k(cid:48)

(cid:17)

=

(cid:88)

S1

E(∆ijk)E(∆i(cid:48)j(cid:48)k(cid:48)) ≤

(cid:16) (cid:88)

E(∆ijk)

(cid:17) (cid:16) (cid:88)

E(∆i(cid:48)j(cid:48)k(cid:48))

(cid:17)

= E2(x).

all
ijk

all
i(cid:48)j(cid:48)k(cid:48)

In Part 2, i, j, k and i(cid:48), j(cid:48), k(cid:48) share two vertices and hence one edge. See Figure 4.4.
Four vertices and ﬁve edges are involved overall. There are at most (cid:0)n
(cid:1) ∈ O(n4), 4-vertex
subsets and (cid:0)4
(cid:1) ways to partition the four vertices into two triangles with a common edge.
The probability of all ﬁve edges in the two triangles being present is p5, so this part sums
to O(n4p5) = O(d5/n) and is o(1). There are so few triangles in the graph, the probability
of two triangles sharing an edge is extremely unlikely.

2

4

In Part 3, i, j, k and i(cid:48), j(cid:48), k(cid:48) are the same sets. The contribution of this part of the

summation to E(x2) is (cid:0)n

(cid:1)p3 = d3

3

6 . Thus,

which implies

E(x2) ≤ E2(x) +

d3
6

+ o(1),

Var(x) = E(x2) − E2(x) ≤

d3
6

+ o(1).

For x to be less than or equal to zero, it must diﬀer from its expected value by at least

its expected value. Thus,

Prob(x = 0) ≤ Prob (cid:0)|x − E(x)| ≥ E(x)(cid:1) .

By Chebychev inequality,

Prob(x = 0) ≤

Var(x)
E2(x)

≤

d3/6 + o(1)
d6/36

≤

6
d3 + o(1).

(4.1)

92

√
Thus, for d > 3
√
probability. For d < 3
graph for there to be a triangle.

6 ∼= 1.8, Prob(x = 0) < 1 and G(n, p) has a triangle with nonzero
6 and very close to zero, there simply are not enough edges in the

4.2 Phase Transitions

Many properties of random graphs undergo structural changes as the edge probability
passes some threshold value. This phenomenon is similar to the abrupt phase transitions
in physics, as the temperature or pressure increases. Some examples of this are the abrupt
appearance of cycles in G(n, p) when p reaches 1/n and the disappearance of isolated ver-
tices when p reaches log n
n . The most important of these transitions is the emergence of a
giant component, a connected component of size Θ(n), which happens at d = 1. Recall
Figure 4.1.

have the property, and when lim
n→∞

For these and many other properties of random graphs, a threshold exists where an
abrupt transition from not having the property to having the property occurs. If there
p1(n)
p(n) = 0, G (n, p1 (n)) almost surely does not
exists a function p (n) such that when lim
n→∞
p2(n)
p(n) = ∞, G (n, p2 (n)) almost surely has the property,
then we say that a phase transition occurs, and p (n) is the threshold. Recall that G(n, p)
“almost surely does not have the property” means that the probability that it has the
property goes to zero in the limit, as n goes to inﬁnity. We shall soon see that every
increasing property has a threshold. This is true not only for increasing properties of
G (n, p), but for increasing properties of any combinatorial structure. If for cp (n), c < 1,
the graph almost surely does not have the property and for cp (n) , c > 1, the graph
almost surely has the property, then p (n) is a sharp threshold. The existence of a giant
component has a sharp threshold at 1/n. We will prove this later.

In establishing phase transitions, we often use a variable x(n) to denote the number
of occurrences of an item in a random graph. If the expected value of x(n) goes to zero as
n goes to inﬁnity, then a graph picked at random almost surely has no occurrence of the
item. This follows from Markov’s inequality. Since x is a nonnegative random variable
Prob(x ≥ a) ≤ 1
a E(x), which implies that the probability of x(n) ≥ 1 is at most E(x(n)).
That is, if the expected number of occurrences of an item in a graph goes to zero, the
probability that there are one or more occurrences of the item in a randomly selected
graph goes to zero. This is called the ﬁrst moment method.

The previous section showed that the property of having a triangle has a threshold
at p(n) = 1/n.
If the edge probability p1(n) is o(1/n), then the expected number of
triangles goes to zero and by the ﬁrst moment method, the graph almost surely has no
triangle. However, if the edge probability p2(n) satisﬁes np2(n) → ∞, then from (4.1),
the probability of having no triangle is at most 6/d3 + o(1) = 6/(np2(n))3 + o(1), which
goes to zero. This latter case uses what we call the second moment method. The ﬁrst

93

1

Prob(x)>0

0

1
n1+(cid:15)

1
n log n

1
n

log n
n

1
2

0.6
n

0.8
n

1
n

1.2
n

1.4
n

1−o(1)
n

1
n

1+o(1)
n

(a)

(b)

(c)

Figure 4.5: Figure 4.5(a) shows a phase transition at p = 1
n . The dotted line shows an
abrupt transition in Prob(x) from 0 to 1. For any function asymptotically less than 1
n,
Prob(x)>0 is zero and for any function asymptotically greater than 1
n , Prob(x)>0 is one.
Figure 4.5(b) expands the scale and shows a less abrupt change in probability unless
the phase transition is sharp as illustrated by the dotted line. Figure 4.5(c) is a further
expansion and the sharp transition is now more smooth.

No items

E(x) ≥ 0.1

At least one
occurrence
of item in
10% of the
graphs

For 10% of the
graphs, x ≥ 1

Figure 4.6: If the expected fraction of the number of graphs in which an item occurs did
not go to zero, then E (x), the expected number of items per graph, could not be zero.
Suppose 10% of the graphs had at least one occurrence of the item. Then the expected
number of occurrences per graph must be at least 0.1. Thus, E (x) = 0 implies the
probability that a graph has an occurrence of the item goes to zero. However, the other
direction needs more work. If E (x) were not zero, a second moment argument is needed
to conclude that the probability that a graph picked at random had an occurrence of the
item was nonzero since there could be a large number of occurrences concentrated on a
vanishingly small fraction of all graphs. The second moment argument claims that for a
nonnegative random variable x with E (x) > 0, if Var(x) is o(E2 (x)) or alternatively if
E (x2) ≤ E2 (x) (1 + o(1)), then almost surely x > 0.

94

and second moment methods are broadly used. We describe the second moment method
in some generality now.

When the expected value of x(n), the number of occurrences of an item, goes to inﬁn-
ity, we cannot conclude that a graph picked at random will likely have a copy since the
items may all appear on a small fraction of the graphs. We resort to a technique called
the second moment method. It is a simple idea based on Chebyshev’s inequality.

Theorem 4.3 (Second Moment method) Let x(n) be a random variable with E(x) >
0. If

then x is almost surely greater than zero.

Var(x) = o

(cid:16)

E2(x)

(cid:17)

,

Proof: If E(x) > 0, then for x to be less than or equal to zero, it must diﬀer from its
expected value by at least its expected value. Thus,

Prob(x ≤ 0) ≤ Prob

By Chebyshev inequality

(cid:16)

|x − E(x)| ≥ E(x)

.

(cid:17)

(cid:16)

Prob

|x − E(x)| ≥ E(x)

(cid:17)

≤

Var(x)
E2(x)

→ 0.

Thus, Prob(x ≤ 0) goes to zero if Var(x) is o (E2(x)) .

Corollary 4.4 Let x be a random variable with E(x) > 0. If

E(x2) ≤ E2(x)(1 + o(1)),

then x is almost surely greater than zero.

Proof: If E(x2) ≤ E2(x)(1 + o(1)), then

V ar(x) = E(x2) − E2(x) ≤ E2(x)o(1) = o(E2(x)).

Threshold for graph diameter two

We now present the ﬁrst example of a sharp phase transition for a property. This
means that slightly increasing the edge probability p near the threshold takes us from
almost surely not having the property to almost surely having it. The property is that of
a random graph having diameter less than or equal to two. The diameter of a graph is

95

the maximum length of the shortest path between a pair of nodes.

The following technique for deriving the threshold for a graph having diameter two
is a standard method often used to determine the threshold for many other objects. Let
x be a random variable for the number of objects such as triangles, isolated vertices, or
Hamilton circuits, for which we wish to determine a threshold. Then we determine the
value of p, say p0, where the expected value of x goes from zero to inﬁnity. For p < p0
almost surely a graph selected at random will not have a copy of x. For p > p0, a second
moment argument is needed to establish that the items are not concentrated on a vanish-
ingly small fraction of the graphs and that a graph picked at random will almost surely
have a copy.

Our ﬁrst task is to ﬁgure out what to count to determine the threshold for a graph
having diameter two. A graph has diameter two if and only if for each pair of vertices i
and j, either there is an edge between them or there is another vertex k to which both i
and j have an edge. The set of neighbors of i and the set of neighbors of j are random
n or
subsets of expected cardinality np. For these two sets to intersect requires np ≈
p ≈ 1√
n. Such statements often go under the general name of “birthday paradox” though
n) for a graph
it is not a paradox. In what follows, we will prove a threshold of O(
(cid:1) pairs of
to have diameter two. The extra factor of
2, the graph almost surely

ln n ensures that every one of the (cid:0)n
√

i and j has a common neighbor. When p = c
√

n , for c <

(cid:113) ln n

ln n/

√

√

√

√

2

2, the graph almost surely has diameter less

has diameter greater than two and for c >
than or equal to two.

Theorem 4.5 The property that G (n, p) has diameter two has a sharp threshold at

p =

√

(cid:113) ln n
n .
2

Proof: If G has diameter greater than two, then there exists a pair of nonadjacent ver-
tices i and j such that no other vertex of G is adjacent to both i and j. This motivates
calling such a pair bad .

Introduce a set of indicator random variables Iij, one for each pair of vertices (i, j)

with i < j, where Iij is 1 if and only if the pair (i, j) is bad. Let

x =

(cid:88)

i<j

Iij

be the number of bad pairs of vertices. Putting i < j in the sum ensures each pair (i, j)
is counted only once. A graph has diameter at most two if and only if it has no bad pair,
E (x) = 0, then for large n, almost surely, a graph has no bad
i.e., x = 0. Thus, if
pair and hence has diameter at most two.

lim
n→∞

96

The probability that a given vertex is adjacent to both vertices in a pair of vertices
(i, j) is p2. Hence, the probability that the vertex is not adjacent to both vertices is
1 − p2. The probability that no vertex is adjacent to the pair (i, j) is (1 − p2)n−2 and the
probability that i and j are not adjacent is 1 − p. Since there are (cid:0)n
(cid:1) pairs of vertices,
the expected number of bad pairs is

2

E (x) =

(cid:19)

(cid:18)n
2

(1 − p) (cid:0)1 − p2(cid:1)n−2 .

Setting p = c

(cid:113) ln n
n ,

(cid:16)

1 − c

(cid:113) ln n
n

(cid:17) (cid:0)1 − c2 ln n

n

(cid:1)n

E (x) ∼= n2
2
∼= n2
∼= 1

2 e−c2 ln n
2n2−c2.

√

2,

lim
n→∞

E (x) → 0. Thus, by the ﬁrst moment method, for p = c

(cid:113) ln n

n with

For c >
√

c >

2, G (n, p) almost surely has no bad pair and hence has diameter at most two.

Next, consider the case c <

E (x) → ∞. We appeal to a second moment
argument to claim that almost surely a graph has a bad pair and thus has diameter greater
than two.

2 where lim
n→∞

√

E(x2) = E

(cid:33)2

Iij

= E

(cid:32)

(cid:88)

i<j

(cid:32)

(cid:88)

(cid:88)

Iij

i<j

k<l

(cid:33)

Ikl

= E



IijIkl


 =






(cid:88)

i<j
k<l

(cid:88)

i<j
k<l

E (IijIkl).

The summation can be partitioned into three summations depending on the number of
distinct indices among i, j, k, and l. Call this number a.

E (cid:0)x2(cid:1) =

(cid:88)

E (IijIkl) +

E (IijIik) +

(cid:88)

E (cid:0)I 2

ij

(cid:1).

(4.2)

i < j

(cid:88)

i < j
i < k

i < j
k < l

a = 4

a = 3

a = 2

Consider the case a = 4 where i, j, k, and l are all distinct. If IijIkl = 1, then both
pairs (i, j) and (k, l) are bad and so for each u /∈ {i, j, k, l}, one of the edges (i, u) or (j, u)
is absent and, in addition, one of the edges (k, u) or (l, u) is absent. The probability of
this for one u not in {i, j, k, l} is (1 − p2)2. As u ranges over all the n − 4 vertices not in
{i, j, k, l}, these events are all independent. Thus,

E(IijIkl) ≤ (1 − p2)2(n−4) ≤ (1 − c2 ln n
n

)2n(1 + o(1)) ≤ n−2c2(1 + o(1))

97

and the ﬁrst sum is

E(IijIkl) ≤ n4−2c2(1 + o(1)).

(cid:88)

i < j
k < l

For the second summation, observe that if IijIik = 1, then for every vertex u not equal
to i, j, or k, either there is no edge between i and u or there is an edge (i, u) and both
edges (j, u) and (k, u) are absent. The probability of this event for one u is

1 − p + p(1 − p)2 = 1 − 2p2 + p3 ≈ 1 − 2p2.

Thus, the probability for all such u is (1 − 2p2)n−3. Substituting c

(cid:113) ln n

n for p yields

(cid:16)

1 − 2c2 ln n

n

(cid:17)n−3

∼= e−2c2 ln n = n−2c2,

which is an upper bound on E(IijIkl) for one i, j, k, and l with a = 3. Summing over all
distinct triples yields n3−2c2 for the second summation in (4.2).

For the third summation, since the value of Iij is zero or one, E (cid:0)I 2
(cid:88)

ij

E (cid:0)I 2

ij

(cid:1) = E (x) .

(cid:1) = E (Iij). Thus,

ij

√

Hence, E (x2) ≤ n4−2c2 + n3−2c2 + n2−c2 and E (x) ∼= n2−c2, from which it follows that
2, E (x2) ≤ E2 (x) (1 + o(1)). By a second moment argument, Corollary 4.4, a
for c <
graph almost surely has at least one bad pair of vertices and thus has diameter greater
than two. Therefore, the property that the diameter of G(n, p) is less than or equal to

two has a sharp threshold at p =

√

(cid:113) ln n
2
n

Disappearance of Isolated Vertices

The disappearance of isolated vertices

n . At
this point the giant component has absorbed all the small components and with the
disappearance of isolated vertices, the graph becomes connected.

in G (n, p) has a sharp threshold at ln n

Theorem 4.6 The disappearance of isolated vertices in G (n, p) has a sharp threshold of
ln n
n .

Proof: Let x be the number of isolated vertices in G (n, p). Then,

E (x) = n (1 − p)n−1 .

Since we believe the threshold to be ln n

lim
n→∞

E (x) = lim
n→∞

n , consider p = c ln n
(cid:1)n = lim

n (cid:0)1 − c ln n

n

n . Then,

ne−c ln n = lim
n→∞

n1−c.

n→∞

98

If c >1, the expected number of isolated vertices, goes to zero. If c < 1, the expected
number of isolated vertices goes to inﬁnity. If the expected number of isolated vertices
goes to zero, it follows that almost all graphs have no isolated vertices. On the other
hand, if the expected number of isolated vertices goes to inﬁnity, a second moment ar-
gument is needed to show that almost all graphs have an isolated vertex and that the
isolated vertices are not concentrated on some vanishingly small set of graphs with almost
all graphs not having isolated vertices.

Assume c < 1. Write x = I1 + I2 + · · · + In where Ii is the indicator variable indicating
E (IiIj). Since Ii

whether vertex i is an isolated vertex. Then E (x2) =

E (I 2

i ) + 2 (cid:80)

n
(cid:80)
i=1

i<j

equals 0 or 1, I 2
sum are equal

i = Ii and the ﬁrst sum has value E (x). Since all elements in the second

E (cid:0)x2(cid:1) = E (x) + n (n − 1) E (I1I2)

= E (x) + n (n − 1) (1 − p)2(n−1)−1 .

The minus one in the exponent 2(n − 1) − 1 avoids counting the edge from vertex 1 to
vertex 2 twice. Now,

E (x2)
E2 (x)

=

=

n (1 − p)n−1 + n (n − 1) (1 − p)2(n−1)−1
n2 (1 − p)2(n−1)
1
1 − p

n (1 − p)n−1 + (1 −

1
n

1

)

.

For p = c ln n

n with c < 1,

lim
n→∞

E (x) = ∞ and

lim
n→∞

E (x2)
E2 (x)

= lim
n→∞

(cid:34)

1
n1−c + (1 −

1
n

)

1
1 − c ln n
n

(cid:35)

= 1 + o(1).

By the second moment argument, Corollary 4.4, the probability that x = 0 goes to zero
implying that almost all graphs have an isolated vertex. Thus, ln n
n is a sharp threshold
for the disappearance of isolated vertices. For p = c ln n
n , when c > 1 there almost surely
are no isolated vertices, and when c < 1 there almost surely are isolated vertices.

Hamilton circuits

So far in establishing phase transitions in the G(n, p) model for an item such as the
disappearance of isolated vertices, we introduced a random variable x that was the num-
ber of occurrences of the item. We then determined the probability p for which the
expected value of x went from zero to inﬁnity. For values of p for which E(x) = 0, we
argued that with probability one, a graph generated at random had no occurrences of x.
For values of x for which E(x) → ∞, we used the second moment argument to conclude

99

Figure 4.7: A degree three vertex with three adjacent degree two vertices. Graph cannot
have a Hamilton circuit.

that with probability one a graph generated at random had occurrences of x. That is,
the occurrences that forced E(x) to inﬁnity were not all concentrated on a vanishingly
small fraction of the graphs. One might raise the question for the G(n, p) graph model,
do there exist items that are so concentrated on a small fraction of the graphs that the
value of p where E(x) goes from zero to inﬁnity is not the threshold? An example where
this happens is Hamilton circuits.

Let x be the number of Hamilton circuits in G(n, p) and let p = d

n for some constant
2(n − 1)! potential Hamilton circuits in a graph and each has probability

d. There are 1
( d
n)n of actually being a Hamilton circuit. Thus,

(n − 1)!

1
2
(cid:16)n
e
(cid:26) 0

E(x) =

(cid:39)

=

(cid:18) d
n
(cid:19)n

(cid:19)n

.

(cid:17)n (cid:18) d
n
d < e
∞ d > e

This suggests that the threshold for Hamilton circuits occurs when d equals Euler’s con-
stant e. This is not possible since the graph still has isolated vertices and is not even
connected for p = e

n . Thus, the second moment argument is indeed necessary.

The actual threshold for Hamilton circuits is d = ω(log n + log log n). For any p(n)
asymptotically greater than 1
n(log n + log log n), G(n, p) will have a Hamilton circuit with
probability one. This is the same threshold as for the disappearance of degree one vertices.
Clearly a graph with a degree one vertex cannot have a Hamilton circuit. But it may seem
surprising that Hamilton circuits appear as soon as degree one vertices disappear. You
may ask why at the moment degree one vertices disappear there cannot be a subgraph
consisting of a degree three vertex adjacent to three degree two vertices as shown in Figure
4.7. The reason is that the frequency of degree two and three vertices in the graph is very
small and the probability that four such vertices would occur together in such a subgraph
is too small for it to happen.

100

4.3 The Giant Component

Consider G(n, p) as p grows. Starting with p = 0, the graph has n vertices and no
edges. As p increases and edges are added, a forest of trees emerges. When p is o(1/n)
the graph is almost surely a forest of trees, i.e., there are no cycles. When p is d/n, d
a constant, cycles appear. For d < 1, no connected component has asymptotically more
than log n vertices. The number of components containing a single cycle is a constant
independent of n. Thus, the graph consists of a forest of trees plus a few components that
have a single cycle with no Ω(log n) size components.

At p equal 1/n, a phase transition occurs in which a giant component emerges. The
transition consists of a double jump. At p = 1/n, components of n2/3 vertices emerge,
which are almost surely trees. Then at p = d/n, d > 1, a true giant component emerges
that has a number of vertices proportional to n. This is a seminal result in random graph
theory and the main subject of this section. Giant components also arise in many real
world graphs; the reader may want to look at large real-world graphs, like portions of the
web and ﬁnd the size of the largest connected component.

When one looks at the connected components of large graphs that appear in various
contexts, one observes that often there is one very large component. One example is
a graph formed from a data base of protean interactions2 where vertices correspond to
proteins and edges correspond to pairs of proteins that interact. By an interaction, one
means two amino acid chains that bind to each other for a function. The graph has 2735
vertices and 3602 edges. At the time we looked at the data base, the associated graph
had the number of components of various sizes shown in Table 3.1. There are a number
of small components, but only one component of size greater than 16, and that is a giant
component of size 1851. As more proteins are added to the data base the giant component
will grow even larger and eventually swallow up all the smaller components.

Size of
component
Number of
components

1

2

3

4

5

48 179

50

25

14

6

6

7

4

8

6

9

1

10

11

12

· · ·

15

16

· · ·

1851

1

1

0

0

0

1

0

1

Table 1: Table 3.1 Size of components in the graph implicit in the database of interacting
proteins.

The existence of a giant component is not unique to the graph produced from the
protein data set. Take any data set that one can convert to a graph and it is likely
that the graph will have a giant component, provided that the ratio of edges to vertices
is a small number greater than one half. Table 3.2 gives two other examples. This phe-
nomenon, of the existence of a giant component in many real world graphs deserves study.

2Science 1999 July 30 Vol. 285 No. 5428 pp751-753.

101

ftp://ftp.cs.rochester.edu/pub/u/joel/papers.lst
Vertices are papers and edges mean that two papers shared an author.

1
2712

2
549

3
129

4
51

5
16

6
12

7
8

8
3

14
1

27488
1

http://www.gutenberg.org/etext/3202
Vertices represent words and edges connect words that are synonyms of one another.

1
7

2
1

3
1

4
1

5
0

14
1

16
1

18
1

48
1

117
1

125
1

128
1

30242
1

Table 2: Table 3.2 Size of components in two graphs constructed from data sets.

Returning to G(n, p), as p increases beyond d/n, all nonisolated vertices are absorbed
into the giant component, and at p = 1
ln n
n , the graph consists only of isolated vertices
2
plus a giant component. At p = ln n
n , the graph becomes completely connected. By
p = 1/2, the graph is not only connected, but is suﬃciently dense that it has a clique of
size (2 − ε) log n for any ε > 0. We prove many of these facts in this chapter.

To compute the size of a connected component of G (n, p), do a breadth ﬁrst search
of a component starting from an arbitrary vertex and generate an edge only when the
search process needs to know if the edge exists. Start at an arbitrary vertex and mark it
discovered and unexplored. At a general step, select a discovered, but unexplored vertex
v, and explore it as follows. For each undiscovered vertex u, independently decide with
probability p = d/n whether the edge (v, u) is in and if it is, mark u discovered and
unexplored. After this, mark v explored. Discovered but unexplored vertices are called
the frontier. The algorithm has found the entire connected component when the frontier
becomes empty.

For each vertex u, other than the start vertex, the probability that u is undiscovered
after the ﬁrst i steps is precisely (1 − d
n )i. A step is the full exploration of one vertex. Let
zi be the number of vertices discovered in the ﬁrst i steps of the search. The distribution
of zi is Binomial

n − 1, 1 − (cid:0)1 − d

(cid:1)i(cid:17)

(cid:16)

.

n

Consider the case d > 1. For small values of i, the probability that a vertex is

undiscovered after i steps is

(cid:18)

1 −

(cid:19)i

d
n

≈ 1 −

id
n

.

The probability that a vertex is discovered after i steps is id

n . The expected number of

102

1

1

2

4

3

5

2

4

3

5

Figure 4.8: A graph (left) and the breadth ﬁrst search of the graph (right). At vertex 1
the algorithm queried all edges. The solid edges are real edges, the dashed edges are edges
that were queried but do not exist. At vertex 2 the algorithm queried all possible edges to
vertices not yet discovered. The algorithm does not query whether the edge (2,3) exists
since vertex 3 has already been discovered when the algorithm is at vertex 2. Potential
edges not queried are illustrated with dotted edges.

discovered vertices grows as id and the expected size of the frontier grows as (d − 1) i.
As the fraction of discovered vertices increases, the expected rate of growth of newly
discovered vertices decreases since many of the vertices adjacent to the vertex currently
being searched have already been discovered. Once d−1
d n vertices have been discovered,
the growth of newly discovered vertices slows to one at each step. Eventually for d >1,
the growth of discovering new vertices drops below one per step and the frontier starts
to shrink. For d <1, (d − 1) i, the expected size of the frontier is negative. The expected
rate of growth is less than one, even at the start.

It is easy to make this argument rigorous to prove that for the d < 1 case, almost
surely, there is no connected component of size Ω(ln n). We do this before tackling the
more diﬃcult d > 1 case.

Theorem 4.7 Let p=d/n with d < 1. The probability that G(n, p) has a component of
size more than c ln n
(1−d)2 is at most 1/n for a suitable constant c depending on d but not on
n.

Proof: There is a connected component of size at least k containing a particular vertex
v only if the breadth ﬁrst search started at v has a nonempty frontier at all times up
to k. Let zk be the number of discovered vertices after k steps. The probability that
v is in a connected component of size greater than or equal to k is less than or equal
to Prob(zk > k). Now the distribution of zk is Binomial(cid:0)n − 1, 1 − (1 − d/n)k(cid:1). Since
(1 − d/n)k ≥ 1 − dk/n, the mean of Binomial(cid:0)n − 1, 1 − (1 − d/n)k(cid:1) is less than the mean
of Binomial(n, dk
n ) has mean dk, the mean of zk is at most dk where
d < 1. By a Chernoﬀ bound, the probability that zk is greater than k is at most e−c0k for

n ). Since Binomial(n, dk

103

0

ln n

θ

1

Figure 4.9: The solid curve is the expected size of the frontier. The two dashed curves
indicate the range of possible values for the actual size of the frontier.

some constant c0 > 0. If k ≥ c ln n for a suitably large c, then this probability is at most
1/n2. This bound is for a single vertex v. Multiplying by n for the union bound completes
the proof.

Now assume d > 1. As we saw, the expected size of the frontier grows as (d − 1)i
for small i. The actual size of the frontier is a random variable. What is the probability
that the actual size of the frontier will diﬀer from the expected size of the frontier by
a suﬃcient amount so that the actual size of the frontier is zero? To answer this, we
need to understand the distribution of the number of discovered vertices after i steps.
For small i, the probability that a vertex has been discovered is 1 − (1 − d/n)i ≈ id/n
and the binomial distribution for the number of discovered vertices, binomial(n, id
n ), is
well approximated by the Poisson distribution with the same mean id. The probability
that a total of k vertices have been discovered in i steps is approximately e−di (di)k
. For a
connected component to have exactly i vertices, the frontier must drop to zero for the ﬁrst
time at step i. A necessary condition is that exactly i vertices must have been discovered
in the ﬁrst i steps. The probability of this approximately equals

k!

e−di (di)i
i!

= e−di diii

ii ei = e−(d−1)idi = e−(d−1−ln d)i.

For d > 1, ln d ≤ d−1 and hence d−1−ln d > 0. This probability drops oﬀ exponentially
with i. For i > c ln n and suﬃciently large c, the probability that the breadth ﬁrst search
starting from a particular vertex terminates with a component of size i is o(1/n) as long
as the Poisson approximation is valid. In the range of this approximation, the probability
that a breadth ﬁrst search started from any vertex terminates with i > c ln n vertices is
o(1). Intuitively, if the component has not stopped growing within Ω(ln n) steps, it is
likely to continue to grow until it becomes much larger and the expected value of the size
of the frontier again becomes small. While the expected value of the frontier is large, the
probability that the actual size will diﬀer from the expected size suﬃciently for the actual
size of the frontier to be zero is vanishingly small.

104

In Theorem 4.9, we prove that there is one giant component of size Ω(n) along with
a number of components of size O(ln n). We ﬁrst prove a technical lemma stating that
the probability of a vertex being in a small component is strictly less than one and hence
there is a giant component. We refer to a connected component of size O(log n) as a small
component.

Lemma 4.8 Assume d > 1. The probability that cc(v), the connected component contain-
ing vertex v, is small (i.e., of size O(log n)) is a constant strictly less than 1.

n ) distribution. Having picked k, pick one of the (cid:0)m

Proof: Let p be the probability that cc(v) is small, i.e., the probability that the breadth
ﬁrst search started at v terminates before c1 log n vertices are discovered. Slightly modify
the breadth ﬁrst search as follows: If in exploring a vertex u at some point, there are m
undiscovered vertices, choose the number k of vertices which will be adjacent to u from
(cid:1) subsets of m undiscov-
Binomial(m, d
ered vertices to be the set of vertices adjacent to u, and make the other m − k vertices
not adjacent to u. This process has the same distribution as picking each edge from u
independently at random to be present with probability d/n. As the search proceeds, m
decreases. If cc(v) is small, m is always greater than s = n − c1 log n. Modify the process
once more picking k from Binomial(s, d
n). Let p(cid:48) be the
probability that cc(v) is small for the modiﬁed process. Clearly, p(cid:48) ≥ p, so it suﬃces
to prove that p(cid:48) is a constant strictly less than one. The mean of the binomial now is
d1 = sd/n which is strictly greater than one. It is clear that the probability that the mod-
iﬁed process ends before c1 log n vertices are discovered is at least the probability for the
original process, since picking from n−c1 log n vertices has decreased the number of newly
discovered vertices each time. Modifying the process so that the newly discovered vertices
are picked from a ﬁxed size set, converts the problem to what is called a branching process..

n ) instead of from Binomial(m, d

k

A branching process is a method for creating a possibly inﬁnite random tree. There
is a nonnegative integer-valued random variable y that is the number of children of the
node being explored. First, the root v of the tree chooses a value of y according to the
distribution of y and spawns that number of children. Each of the children independently
chooses a value according to the same distribution of y and spawns that many children.
The process terminates when all of the vertices have spawned children. The process may
go on forever. If it does terminate with a ﬁnite tree, we say that the process has become
“extinct”. Let Binomial(s, d
n ) be the distribution of y. Let q be the probability of ex-
tinction. Then, q ≥ p(cid:48), since, the breadth ﬁrst search terminating with at most c1 log n
vertices is one way of becoming extinct. Let pi = (cid:0)s
(cid:1)(d/n)i(1 − (d/n))s−i be the proba-
bility that y spawns i children. We have (cid:80)s

i=1 ipi = E(y) = ds/n > 1.

i=0 pi = 1 and (cid:80)s

i

The depth of a tree is at most the number of nodes in the tree. Let at be the probability
that the branching process terminates at depth at most t. If the root v has no children,
then the process terminates with depth one where the root is counted as a depth one node
which is at most t. If v has i children, the process from v terminates at depth at most t if

105

For a small number i of steps, the probability distribution of the size of the set of
discovered vertices at time i is p(k) = e−di (di)k
k! and has expected value di. Thus, the
expected size of the frontier is (d − 1)i. For the frontier to be empty would require that
the size of the set of discovered vertices be smaller than its expected value by (d − 1)i.
That is, the size of the set of discovered vertices would need to be di − (d − 1)i = i. The
probability of this is

e−di (di)i

i! = e−di diii

ii ei = e−(d−1)idi = e−(d−1−ln d)i

which drops oﬀ exponentially fast with i provided d > 1. Since d − 1 − ln d is some
constant c > 0, the probability is e−ci which for i = ln n is e−c ln n = 1
nc . Thus, with high
probability, the largest small component in the graph is of size at most ln n.

Illustration 4.1

and only if the i sub processes, one rooted at each child of v terminate at depth t − 1 or
less. The i processes are independent, so the probability that they all terminate at depth
at most t − 1 is exactly ai

t−1. With this we get:

at = p0 +

s
(cid:88)

i=1

piai

t−1 =

s
(cid:88)

i=0

piai

t−1.

We have a1 = p0 < 1. There is a constant α ∈ [p0, 1) such that whenever at−1 ≤ α, the
above recursion implies that at ≤ α. This would ﬁnish the proof since then a1 ≤ α implies
a2 ≤ α which implies a3 ≤ α etc. and so q = limt→∞ at ≤ α.

To prove the claim, consider the polynomial

h(x) = x −

s
(cid:88)

i=0

pixi.

We see that h(1) = 0 and h(cid:48)(1) = 1 − (cid:80)s
n , which is at most a strictly
negative constant. By continuity of h(·), there is exists some x0 < 1 such that h(x) ≥ 0
for x ∈ [x0, 1]. Take α = Max(x0, p0). Now since (cid:80)s
i=0 pixi has all nonnegative coeﬃcients,
it is an increasing function of x and so if at−1 is at least α, then, (cid:80)s
t−1 is at least
(cid:80)s

i=1 ipi ≈ 1 − sd

i=0 piai

i=0 piαi ≥ α. Now, if at−1 ≤ α,

at =

s
(cid:88)

i=0

piai

t−1 ≥

s
(cid:88)

i=1

piαi = α − h(α) ≤ α,

proving the claim.

We now prove in Theorem 4.9 that in G(n, d

n ), d > 1 there is one giant component
containing a fraction of the n vertices and that the remaining vertices are in components

106

of size less than some constant c1 times log n. There are no components greater than
c1 log n other than the giant component.

Theorem 4.9 Let p=d/n with d > 1.

1. There are constants c1 and c2 such that the probability that there is a connected

component of size between c1 log n and c2n is at most 1/n.

2. The number of vertices in components of size O(ln n) is almost surely at most cn
for some c < 1. Thus, with probability 1 − o(1), there is a connected component of
size Ω(n).

3. The probability that there are two or more connected components, each of size more

than n2/3, is at most 1/n.

Proof: In the breadth ﬁrst search of a component, the probability that a vertex has
(cid:1)i . It is easy to see that the approximation
not been discovered in i steps is (cid:0)1 − d
(1 − d/n)i ≈ 1 − id/n is valid as long as i ≤ c2n for a suitable constant c2 since the
error term in the approximation is O(i2d2/n2), which for i ≤ c2n is at most a small con-
stant times id/n. This establishes (1).

n

Next consider (2). For a vertex v, let cc(v) denote the set of vertices in the connected
component containing v. By (1), almost surely, cc(v) is a small set of size at most c1 log n
or a large set of size at least c2n for every vertex v. The central part of the proof of
(2) that the probability of a vertex being in a small component is strictly less than one
was established in Lemma 4.8. Let x be the number of vertices in a small connected
component. Lemma 4.8 implies that the expectation of the random variable x equals the
number of vertices in small connected components is at most some c3n, for a constant c3
strictly less than one. But we need to show that for any graph almost surely the actual
number x of such vertices is at most some constant strictly less than one times n. For
this, we use the second moment method. In this case, the proof that the variance of x is
o(E2(x)) is easy. Let xi be the indicator random variable of the event that cc(i) is small.
Let S and T run over all small sets. Noting that for i (cid:54)= j, cc(i) and cc(j) either are the

107

same or are disjoint,

E(x2) = E

(cid:32) n

(cid:88)





i=1

(cid:33)2

xi

 =

(cid:88)

i,j

E(xixj) =

(cid:88)

i

E(x2

i ) +

= E(x) +

(cid:88)

(cid:88)

Prob (cid:0)cc(i) = cc(j) = S(cid:1) +

(cid:88)

(cid:88)

i(cid:54)=j
(cid:88)

E(xixj)

Prob (cid:0)cc(i) = S; cc(j) = T (cid:1)

= E(x) +

i(cid:54)=j

S

(cid:88)

(cid:88)

i(cid:54)=j

S

Prob (cid:0)cc(i) = cc(j) = S(cid:1)

i(cid:54)=j

S,T
disjoint

(cid:88)

(cid:88)

+

Prob (cid:0)cc(i) = S(cid:1) Prob (cid:0)cc(j) = T (cid:1) (1 − p)−|S||T |

i(cid:54)=j

S,T
disjoint

≤ O(n) + (1 − p)−|S||T |

(cid:32)

(cid:88)

Prob (cid:0)cc(i) = S(cid:1)

(cid:33) (cid:32)

(cid:88)

Prob (cid:0)cc(j) = T (cid:1)

(cid:33)

≤ O(n) + (cid:0)1 + o(1)(cid:1) E(x)E(x).

S

T

In the next to last line, if S containing i and T containing j are disjoint sets, then the two
events, S is a connected component and T is a connected component, depend on disjoint
sets of edges except for the |S||T | edges between S vertices and T vertices. Let c4 be a
constant in the interval (c3, 1). Then, by Chebyshev inequality,

Prob(x > c4n) ≤

Var(x)
(c4 − c3)2n2 ≤

O(n) + o(1)c2

3n2
(c4 − c3)2n2 = o(1).

For the proof of (3) suppose a pair of vertices u and v belong to two diﬀerent connected
components, each of size at least n2/3. With high probability, they should have merged
into one component producing a contradiction. First, run the breadth ﬁrst search process
starting at v for 1
2n2/3 steps. Since v is in a connected component of size n2/3, there
are Ω(n2/3) frontier vertices. The expected size of the frontier continues to grow until
some constant times n and the actual size of the frontier does not diﬀer signiﬁcantly
from the expected size. The size of the component also grows linearly with n. Thus,
the frontier is of size n 2
3 . See Exercise 4.27. By the assumption, u does not belong to
this connected component. Now, temporarily stop the breadth ﬁrst search tree of v and
begin a breadth ﬁrst search tree starting at u, again for 1
2n2/3 steps. It is important to
understand that this change of order of building G(n, p) does not change the resulting
graph. We can choose edges in any order since the order does not aﬀect independence or
conditioning. The breadth ﬁrst search tree from u also will have Ω(n2/3) frontier vertices
with high probability . Now grow the u tree further. The probability that none of the
edges between the two frontier sets is encountered is (1 − p)Ω(n4/3) ≤ e−Ω(dn1/3), which
converges to zero. So almost surely, one of the edges is encountered and u and v end up
in the same connected component. This argument shows for a particular pair of vertices

108

u and v, the probability that they belong to diﬀerent large connected components is very
(cid:1)
small. Now use the union bound to conclude that this does not happen for any of the (cid:0)n
pairs of vertices. The details are left to the reader.

2

4.4 Branching Processes

A branching process is a method for creating a random tree. Starting with the root
node, each node has a probability distribution for the number of its children. The root
of the tree denotes a parent and its descendants are the children with their descendants
being the grandchildren. The children of the root are the ﬁrst generation, their children
the second generation, and so on. Branching processes have obvious applications in pop-
ulation studies, but also in exploring a connected component in a random graph.

We analyze a simple case of a branching process where the distribution of the number
of children at each node in the tree is the same. The basic question asked is what is the
probability that the tree is ﬁnite, i.e., the probability that the branching process dies out?
This is called the extinction probability.

Our analysis of the branching process will give the probability of extinction, as well
as the expected size of the components conditioned on extinction. Not surprisingly, the
expected size of components conditioned on extinction is O(1). This says that in G(n, d
n ),
with d > 1, there is one giant component of size Ω(n), the rest of the components are
O(ln n) in size and the expected size of the small components is O(1).

An important tool in our analysis of branching processes is the generating func-
tion. The generating function for a nonnegative integer valued random variable y is
pixi where pi is the probability that y equals i. The reader not familiar with

f (x) =

∞
(cid:80)
i=0

generating functions should consult Section 11.6 of the appendix.

Let the random variable zj be the number of children in the jth generation and let
fj (x) be the generating function for zj. Then f1 (x) = f (x) is the generating function for
the ﬁrst generation where f (x) is the generating function for the number of children at a
node in the tree. The generating function for the 2nd generation is f2(x) = f (f (x)). In
general, the generating function for the j + 1st generation is given by fj+1 (x) = fj (f (x)).
To see this, observe two things.

First, the generating function for the sum of two identically distributed integer valued

random variables x1 and x2 is the square of their generating function

f 2 (x) = p2

0 + (p0p1 + p1p0) x + (p0p2 + p1p1 + p2p0) x2 + · · · .

For x1 + x2 to have value zero, both x1 and x2 must have value zero, for x1 + x2 to have
value one, exactly one of x1 or x2 must have value zero and the other have value one, and

109

m < 1

f (x)

m > 1

p0

m = 1 and p1 < 1

q

x

Figure 4.10: Illustration of the root of equation f (x) = x in the interval [0,1).

so on. In general, the generating function for the sum of i independent random variables,
each with generating function f (x), is f i (x).

The second observation is that the coeﬃcient of xi in fj (x) is the probability of
there being i children in the jth generation. If there are i children in the jth generation,
the number of children in the j + 1st generation is the sum of i independent random
variables each with generating function f (x). Thus, the generating function for the j + 1st
generation, given i children in the jth generation, is f i(x). The generating function for
the j + 1st generation is given by

fj+1(x) =

∞
(cid:88)

i=0

Prob(zj = i)f i(x).

If fj(x) =

∞
(cid:80)
i=0

aixi, then fj+1 is obtained by substituting f (x) for x in fj(x).

Since f (x) and its iterates, f2, f3, . . ., are all polynomials in x with nonnegative co-
eﬃcients, f (x) and its iterates are all monotonically increasing and convex on the unit
interval. Since the probabilities of the number of children of a node sum to one, if p0 < 1,
some coeﬃcient of x to a power other than zero in f (x) is nonzero and f (x) is strictly
increasing.

Let q be the probability that the branching process dies out. If there are i children
in the ﬁrst generation, then each of the i subtrees must die out and this occurs with
probability qi. Thus, q equals the summation over all values of i of the product of the
probability of i children times the probability that i subtrees will die out. This gives
q = (cid:80)∞

i=0 piqi. Thus, q is the root of x = (cid:80)∞

i=0 pixi, that is x = f (x).

This suggests focusing on roots of the equation f (x) = x in the interval [0,1]. The value

x = 1 is always a root of the equation f (x) = x since f (1) =

110

∞
(cid:80)
i=0

pi = 1. When is there a

smaller nonnegative root? The derivative of f (x) at x = 1 is f (cid:48)(1) = p1 + 2p2 + 3p3 + · · · .
Let m = f (cid:48)(1). Thus, m is the expected number of children of a node. If m > 1, one
might expect the tree to grow forever, since each node at time j is expected to have more
than one child. But this does not imply that the probability of extinction is zero. In fact,
if p0 > 0, then with positive probability, the root will have no children and the process
will become extinct right away. Recall that for G(n, d
n), the expected number of children
is d, so the parameter m plays the role of d.

If m < 1, then the slope of f (x) at x = 1 is less than one. This fact along with
convexity of f (x) implies that f (x) > x for x in [0, 1) and there is no root of f (x) = x in
the interval [0, 1).

If m = 1 and p1 < 1, then once again convexity implies that f (x) > x for x ∈ [0, 1)
and there is no root of f (x) = x in the interval [0, 1). If m = 1 and p1 = 1, then f (x) is
the straight line f (x) = x.

If m >1, then the slope of f (x) is greater than the slope of x at x = 1. This fact,
along with convexity of f (x), implies f (x) = x has a unique root in [0,1). When p0 = 0,
the root is at x = 0.

Let q be the smallest nonnegative root of the equation f (x) = x. For m < 1 and for
m=1 and p0 < 1, q equals one and for m >1, q is strictly less than one. We shall see
that the value of q is the extinction probability of the branching process and that 1 − q is
the immortality probability. That is, q is the probability that for some j, the number of
children in the jth generation is zero. To see this, note that for m > 1, lim
fj (x) = q for
j→∞
0 ≤ x < 1. Figure 4.11 illustrates the proof which is given in Lemma 4.10. Similarly note
that when m < 1 or m = 1 with p0 < 1, fj (x) approaches one as j approaches inﬁnity.

Lemma 4.10 Assume m > 1. Let q be the unique root of f(x)=x in [0,1). In the limit as
j goes to inﬁnity, fj (x) = q for x in [0, 1).

Proof: If 0 ≤ x ≤ q, then x < f (x) ≤ f (q) and iterating this inequality

x < f1 (x) < f2 (x) < · · · < fj (x) < f (q) = q.

Clearly, the sequence converges and it must converge to a ﬁxed point where f (x) = x.
Similarly, if q ≤ x < 1, then f (q) ≤ f (x) < x and iterating this inequality

x > f1 (x) > f2 (x) > · · · > fj (x) > f (q) = q.

In the limit as j goes to inﬁnity fj (x) = q for all x, 0 ≤ x < 1.

Recall that fj (x) is the generating function

Prob (zj = i) xi. The fact that in the

limit the generating function equals the constant q, and is not a function of x, says

∞
(cid:80)
i=0

111

f (x)

q

p0

f (f (x))

f (x)

x

Figure 4.11: Illustration of convergence of the sequence of iterations f1(x), f2(x), . . . to q.

that Prob (zj = 0) = q and Prob (zj = i) = 0 for all ﬁnite nonzero values of i. The
remaining probability is the probability of a nonﬁnite component. Thus, when m >1, q
is the extinction probability and 1-q is the probability that zj grows without bound, i.e.,
immortality.

Theorem 4.11 Consider a tree generated by a branching process. Let f (x) be the gener-
ating function for the number of children at each node.

1. If the expected number of children at each node is less than or equal to one, then the
probability of extinction is one unless the probability of exactly one child is one.

2. If the expected number of children of each node is greater than one, then the proba-

bility of extinction is the unique solution to f (x) = x in [0, 1).

Proof: Let pi be the probability of i children at each node. Then f (x) = p0 + p1x +
p2x2 + · · · is the generating function for the number of children at each node and f (cid:48)(1) =
is the slope of f (x) at x = 1. Observe that f (cid:48)(1) is the expected
p1 + 2p2 + 3p3 + · · ·
number of children at each node.

Since the expected number of children at each node is the slope of f (x) at x = 1, if
the expected number of children is less than or equal to one, the slope of f (x) at x = 1
is less than or equal to one and the unique root of f (x) = x in (0, 1] is at x = 1 and the
probability of extinction is one unless f (cid:48)(1) = 1 and p1 = 1. If f (cid:48)(1) = 1 and p1 = 1,
f (x) = x and the tree is an inﬁnite degree one chain. If the slope of f (x) at x = 1 is
greater than one, then the probability of extinction is the unique solution to f (x) = x in
[0, 1).

112

A branching process with m <1 or m=1 and p1 < 1 dies out with probability one. If
m=1 and p1 = 1, then the branching process consists of an inﬁnite chain with no fan out.
If m >1, then the branching process will die out with some probability less than one un-
less p0 = 0 in which case it cannot die out, since a node always has at least one descendent.

Note that the branching process corresponds to ﬁnding the size of a component in
an inﬁnite graph. In a ﬁnite graph, the probability distribution of descendants is not a
constant as more and more vertices of the graph get discovered.

The simple branching process deﬁned here either dies out or goes to inﬁnity. In bio-
logical systems there are other factors, since processes often go to stable populations. One
possibility is that the probability distribution for the number of descendants of a child
depends on the total population of the current generation.

Expected size of extinct families

We now show that the expected size of an extinct family is ﬁnite, provided that m (cid:54)= 1.
Note that at extinction, the size must be ﬁnite. However, the expected size at extinction
could conceivably be inﬁnite, if the probability of dying out did not decay fast enough.
To see how the expected value of a random variable that is always ﬁnite could be inﬁnite,
let x be an integer valued random variable. Let pi be the probability that x = i.
If
∞
(cid:80)
i=1

pi = 1, then with probability one, x will be ﬁnite. However, the expected value of x

may be inﬁnite. That is,

ipi = ∞. For example, if for i >0, pi = 6
π

1
i2 , then

pi = 1,

∞
(cid:80)
i=0

∞
(cid:80)
i=1

but

ipi = ∞. The value of the random variable x is always ﬁnite, but its expected

∞
(cid:80)
i=1

value is inﬁnite. This does not happen in a branching process, except in the special case
where the slope m = f (cid:48)(1) equals one and p1 (cid:54)= 1

Lemma 4.12 If the slope m = f (cid:48) (1) does not equal one, then the expected size of an
extinct family is ﬁnite. If the slope m equals one and p1 = 1, then the tree is an inﬁnite
degree one chain and there are no extinct families. If m=1 and p1 < 1, then the expected
size of the extinct family is inﬁnite.

Proof: Let zi be the random variable denoting the size of the ith generation and let q be
the probability of extinction. The probability of extinction for a tree with k children in
the ﬁrst generation is qk since each of the k children has an extinction probability of q.
Note that the expected size of z1, the ﬁrst generation, over extinct trees will be smaller
than the expected size of z1 over all trees since when the root node has a larger number
of children than average, the tree is more likely to be inﬁnite.

113

By Bayes rule

Prob (z1 = k|extinction) = Prob (z1 = k)

Prob (extinction|z1 = k)
Prob (extinction)

= pk

qk
q

= pkqk−1.

Knowing the probability distribution of z1 given extinction, allows us to calculate the
expected size of z1 given extinction.

E (z1|extinction) =

∞
(cid:88)

k=0

kpkqk−1 = f (cid:48) (q) .

We now prove, using independence, that the expected size of the ith generation given
extinction is

E (zi|extinction) =

(cid:16)

(cid:17)i

f (cid:48) (q)

.

For i = 2, z2 is the sum of z1 independent random variables, each independent of the ran-
dom variable z1. So, E(z2|z1 = j and extinction) = E( sum of j copies of z1|extinction) =
jE(z1|extinction). Summing over all values of j

E(z2|extinction) =

=

∞
(cid:88)

j=1
∞
(cid:88)

j=1

E(z2|z1 = j and extinction)Prob(z1 = j|extinction)

jE(z1|extinction)Prob(z1 = j|extinction)

= E(z1|extinction)

∞
(cid:88)

j=1

jProb(z1 = j|extinction) = E2(z1|extinction).

Since E(z1|extinction) = f (cid:48)(q), E (z2|extinction) = (f (cid:48) (q))2. Similarly, E (zi|extinction) =
(f (cid:48) (q))i . The expected size of the tree is the sum of the expected sizes of each generation.
That is,

Expected size of
tree given extinction

=

∞
(cid:88)

i=0

E (zi|extinction) =

∞
(cid:88)

i=0

(f (cid:48) (q))i =

1
1 − f (cid:48) (q)

.

Thus, the expected size of an extinct family is ﬁnite since f (cid:48) (q) < 1 provided m (cid:54)= 1.

The fact that f (cid:48)(q) < 1 is illustrated in Figure 4.10. If m <1, then q=1 and f (cid:48)(q) = m
is less than one. If m >1, then q ∈ [0, 1) and again f (cid:48)(q) <1 since q is the solution to
f (x) = x and f (cid:48)(q) must be less than one for the curve f (x) to cross the line x. Thus,
for m <1 or m >1, f (cid:48)(q) <1 and the expected tree size of
1−f (cid:48)(q) is ﬁnite. For m=1 and
p1 < 1, one has q=1 and thus f (cid:48)(q) = 1 and the formula for the expected size of the tree
diverges.

1

114

4.5 Cycles and Full Connectivity

This section considers when cycles form and when the graph becomes fully connected.
For both of these problems, we look at each subset of k vertices and see when they form
either a cycle or a connected component.

4.5.1 Emergence of Cycles

The emergence of cycles in G (n, p) has a threshold when p equals to 1/n.

Theorem 4.13 The threshold for the existence of cycles in G (n, p) is p = 1/n.

Proof: Let x be the number of cycles in G (n, p). To form a cycle of length k, the vertices
(cid:1) ways. Given the k vertices of the cycle, they can be ordered by
can be selected in (cid:0)n
arbitrarily selecting a ﬁrst vertex, then a second vertex in one of k-1 ways, a third in one
of k − 2 ways, etc. Since a cycle and its reversal are the same cycle, divide by 2. Thus,
there are (cid:0)n

cycles of length k and

k

(cid:1) (k−1)!
2

k

E (x) =

n
(cid:88)

k=3

(cid:19)

(cid:18)n
k

(k−1)!

2 pk ≤

n
(cid:80)
k=3

nk
2k pk ≤

n
(cid:80)
k=3

(np)k = (np)3 1−(np)n−2

1−np ≤ 2(np)3,

provided that np < 1/2. When p is asymptotically less than 1/n, then lim
n→∞

np = 0 and

n
(cid:80)
k=3

(np)k = 0. So, as n goes to inﬁnity, E(x) goes to zero. Thus, the graph almost

lim
n→∞
surely has no cycles by the ﬁrst moment method. A second moment argument can be
used to show that for p = d/n, d > 1, a graph will have a cycle with probability tending
to one.

The argument above does not yield a sharp threshold since we argued that E(x) → 0
n .. A sharp threshold re-

only under the assumption that p is asymptotically less that 1
quires E(x) → 0 for p = d/n, d < 1.

Consider what happens in more detail when p = d/n, d a constant.

n
(cid:88)

E (x) =

(cid:18)n
k

(cid:19) (k − 1)!
2

pk

n
(cid:88)

k=3
1
2

k=3
n
(cid:88)

1
2

k=3

=

=

n(n − 1) · · · (n − k + 1)
k!

(k − 1)! pk

n(n − 1) · · · (n − k + 1)
nk

dk
k

.

E (x) converges if d < 1, and diverges if d ≥ 1. If d < 1, E (x) ≤ 1
2

equals a constant greater than zero. If d = 1, E (x) = 1
2

n
(cid:80)
k=3

115

n
(cid:80)
k=3

dk
k and lim
n→∞

E (x)

n(n−1)···(n−k+1)
nk

1
k . Consider

Property

Threshold

cycles
giant component
giant component
+ isolated vertices
connectivity, disappearance
of isolated vertices

diameter two

1/n
1/n

1
2

ln n
n

ln n
n
(cid:113) 2 ln n
n

only the ﬁrst log n terms of the sum. Since
n(n−1)···(n−k+1)
nk

≥ 1/2. Thus,

n

n−i = 1 + i

n−i ≤ ei/n−i, it follows that

log n
(cid:80)
k=3
Then, in the limit as n goes to inﬁnity

E (x) ≥ 1
2

n(n−1)···(n−k+1)
nk

1

k ≥ 1

4

log n
(cid:80)
k=3

1
k .

lim
n→∞

E (x) ≥ lim
n→∞

1
4

log n
(cid:80)
k=3

1
k ≥ lim
n→∞

(log log n) = ∞.

For p = d/n, d < 1, E (x) converges to a nonzero constant and with some nonzero
probability, graphs will have a constant number of cycles independent of the size of the
graph. For d > 1, E(x) converges to inﬁnity and a second moment argument shows that
graphs will have an unbounded number of cycles increasing with n.

4.5.2 Full Connectivity

As p increases from p = 0, small components form. At p = 1/n a giant component
emerges and swallows up smaller components, starting with the larger components and
ending up swallowing isolated vertices forming a single connected component at p = ln n
n ,
at which point the graph becomes connected. We begin our development with a technical
lemma.

Lemma 4.14 The expected number of connected components of size k in G(n, p) is at
most

(cid:19)

(cid:18)n
k

kk−2pk−1(1 − p)kn−k2.

Proof: The probability that k vertices form a connected component consists of the prod-
uct of two probabilities. The ﬁrst is the probability that the k vertices are connected,
and the second is the probability that there are no edges out of the component to the
remainder of the graph. The ﬁrst probability is at most the sum over all spanning trees
of the k vertices, that the edges of the spanning tree are present. The ”at most” in the

116

lemma statement is because G (n, p) may contain more than one spanning tree on these
nodes and, in this case, the union bound is higher than the actual probability. There are
kk−2 spanning trees on k nodes. See Section 11.7.6 in the appendix. The probability of
all the k − 1 edges of one spanning tree being present is pk−1 and the probability that
there are no edges connecting the k vertices to the remainder of the graph is (1 − p)k(n−k).
Thus, the probability of one particular set of k vertices forming a connected component
is at most kk−2pk−1 (1 − p)kn−k2
. Thus, the expected number of connected components of
size k is (cid:0)n

(cid:1)kk−2pk−1(1 − p)kn−k2.

k

We now prove that for p = 1
2
nents except for isolated vertices.

ln n
n , the giant component has absorbed all small compo-

Theorem 4.15 Let p = c ln n
and a giant component. For c > 1, almost surely the graph is connected.

n . For c > 1/2, almost surely there are only isolated vertices

Proof: We prove that almost surely for c > 1/2, there is no connected component with
k vertices for any k, 2 ≤ k ≤ n/2. This proves the ﬁrst statement of the theorem since, if
there were two or more components that are not isolated vertices, both of them could not
be of size greater than n/2. The second statement that for c > 1 the graph is connected
then follows from Theorem 4.6 which states that isolated vertices disappear at c = 1.

We now show that for p = c ln n

n , the expected number of components of size k,
2 ≤ k ≤ n/2, is less than n1−2c and thus for c > 1/2 there are no components, except
for isolated vertices and the giant component. Let xk be the number of connected com-
ponents of size k. Substitute p = c ln n
and simplify using
(cid:0)n
k

(cid:1) ≤ (en/k)k, 1 − p ≤ e−p, k − 1 < k, and x = eln x to get

(cid:1)kk−2pk−1 (1 − p)kn−k2

n into (cid:0)n

k

(cid:18)

E(xk) ≤ exp

ln n + k + k ln ln n − 2 ln k + k ln c − ck ln n + ck2 ln n
n

(cid:19)

.

Keep in mind that the leading terms here for large k are the last two and, in fact, at k = n,
they cancel each other so that our argument does not prove the fallacious statement for
c ≥ 1 that there is no connected component of size n, since there is. Let
f (k) = ln n + k + k ln ln n − 2 ln k + k ln c − ck ln n + ck2 ln n
n

.

Diﬀerentiating with respect to k,

f (cid:48)(k) = 1 + ln ln n −

2
k

+ ln c − c ln n +

2ck ln n
n

and

2
k2 +
Thus, the function f (k) attains its maximum over the range [2, n/2] at one of the extreme
points 2 or n/2. At k = 2, f (2) ≈ (1 − 2c) ln n and at k = n/2, f (n/2) ≈ −c n
4 ln n. So

2c ln n
n

f (cid:48)(cid:48) (k) =

> 0.

117

f (k) is maximum at k = 2. For k = 2, E(x)k = ef (k) is approximately e(1−2c) ln n = n1−2c
and is geometrically falling as k increases from 2. At some point E(xk) starts to increase
but never gets above n− c
4 n. Thus, the expected sum of the number of components of size
k, for 2 ≤ k ≤ n/2 is



E



n/2
(cid:88)

k=2

xk


 = O(n1−2c).

This expected number goes to zero for c > 1/2 and the ﬁrst-moment method implies that,
almost surely, there are no components of size between 2 and n/2. This completes the
proof of Theorem 4.15.

4.5.3 Threshold for O(ln n) Diameter

We now show that within a constant factor of the threshold for graph connectivity,
not only is the graph connected, but its diameter is O(ln n). That is, if p is Ω(ln n/n), the
diameter of G(n, p) is O(ln n).

Consider a particular vertex v. Let Si be the set of vertices at distance i from v. We
argue that as i grows, |S1| + |S2| + · · · + |Si| grows by a constant factor up to a size of
n/1000. This implies that in O(ln n) steps, at least n/1000 vertices are connected to v.
Then, there is a simple argument at the end of the proof of Theorem 4.17 that a pair of
n/1000 sized subsets, connected to two diﬀerent vertices v and w, have an edge between
them.

Lemma 4.16 Consider G(n, p) for suﬃciently large n with p = c ln n/n for any c > 0.
Let Si be the set of vertices at distance i from some ﬁxed vertex v. If |S1|+|S2|+· · ·+|Si| ≤
n/1000, then

Prob (cid:0)|Si+1| < 2(|S1| + |S2| + · · · + |Si|)(cid:1) ≤ e−10|Si|.

Proof: Let |Si| = k. For each vertex u not in S1 ∪ S2 ∪ . . . ∪ Si, the probability that
u is not in Si+1 is (1 − p)k and these events are independent. So, |Si+1| is the sum of
n − (|S1| + |S2| + · · · + |Si|) independent Bernoulli random variables, each with probability
of

1 − (1 − p)k ≥ 1 − e−ck ln n/n

of being one. Note that n − (|S1| + |S2| + · · · + |Si|) ≥ 999n/1000. So,

E(|Si+1|) ≥

999n
1000

(1 − e−ck ln n

n ).

Subtracting 200k from each side

E(|Si+1|) − 200k ≥

(cid:18)

n
2

1 − e−ck ln n

n − 400

(cid:19)

.

k
n

Let α = k
n and f (α) = 1 − e−cα ln n − 400α. By diﬀerentiation f (cid:48)(cid:48)(α) ≤ 0, so f is concave
and the minimum value of f over the interval [0, 1/1000] is attained at one of the end

118

points. It is easy to check that both f (0) and f (1/1000) are greater than or equal to
zero for suﬃciently large n. Thus, f is nonnegative throughout the interval proving that
E(|Si+1|) ≥ 200|Si|. The lemma follows from Chernoﬀ bounds.

Theorem 4.17 For p ≥ c ln n/n, where c is a suﬃciently large constant, almost surely,
G(n, p) has diameter O(ln n).

Proof: By Corollary 4.2, almost surely, the degree of every vertex is Ω(np) = Ω(ln n),
which is at least 20 ln n for c suﬃciently large. Assume this holds. So, for a ﬁxed vertex
v, S1 as deﬁned in Lemma 4.16 satisﬁes |S1| ≥ 20 ln n.

Let i0 be the least i such that |S1|+|S2|+· · ·+|Si| > n/1000. From Lemma 4.16 and the
union bound, the probability that for some i, 1 ≤ i ≤ i0−1, |Si+1| < 2(|S1|+|S2|+· · ·+|Si|)
is at most (cid:80)n/1000
k=20 ln n e−10k ≤ 1/n4. So, with probability at least 1 − (1/n4), each Si+1 is
at least double the sum of the previous Sj ’s, which implies that in O(ln n) steps, i0 + 1
is reached.

Consider any other vertex w. We wish to ﬁnd a short O(ln n) length path between
v and w. By the same argument as above, the number of vertices at distance O(ln n)
from w is at least n/1000. To complete the argument, either these two sets intersect in
which case we have found a path from v to w of length O(ln n) or they do not intersect.
In the latter case, with high probability there is some edge between them. For a pair of
disjoint sets of size at least n/1000, the probability that none of the possible n2/106 or
more edges between them is present is at most (1−p)n2/106 = e−Ω(n ln n). There are at most
22n pairs of such sets and so the probability that there is some such pair with no edges
is e−Ω(n ln n)+O(n) → 0. Note that there is no conditioning problem since we are arguing
this for every pair of such sets. Think of whether such an argument made for just the n
subsets of vertices, which are vertices at distance at most O(ln n) from a speciﬁc vertex,
would work.

4.6 Phase Transitions for Increasing Properties

For many graph properties such as connectivity, having no isolated vertices, having a
cycle, etc., the probability of a graph having the property increases as edges are added to
the graph. Such a property is called an increasing property. Q is an increasing property
of graphs if when a graph G has the property, any graph obtained by adding edges to
G must also have the property. In this section we show that any increasing property, in
fact, has a threshold, although not necessarily a sharp one.

The notion of increasing property is deﬁned in terms of adding edges. The following
lemma proves that if Q is an increasing property, then increasing p in G (n, p) increases
the probability of the property Q.

119

Lemma 4.18 If Q is an increasing property of graphs and 0 ≤ p ≤ q ≤ 1, then the
probability that G (n, q) has property Q is greater than or equal to the probability that
G (n, p) has property Q.

Proof: This proof uses an interesting relationship between G (n, p) and G (n, q). Generate
G (n, q) as follows. First generate G (n, p). This means generating a graph on n vertices
and
with edge probabilities p. Then, independently generate another graph G
take the union by putting in an edge if either of the two graphs has the edge. Call the
resulting graph H. The graph H has the same distribution as G (n, q). This follows since
the probability that an edge is in H is p + (1 − p) q−p
1−p = q, and, clearly, the edges of H are
independent. The lemma follows since whenever G (n, p) has the property Q, H also has
the property Q.

n, q−p
1−p

(cid:16)

(cid:17)

We now introduce a notion called replication. An m-fold replication of G(n, p) is a
random graph obtained as follows. Generate m independent copies of G(n, p). Include an
edge in the m-fold replication if the edge is in any one of the m copies of G(n, p). The
resulting random graph has the same distribution as G(n, q) where q = 1 − (1 − p)m since
the probability that a particular edge is not in the m-fold replication is the product of
probabilities that it is not in any of the m copies of G(n, p). If the m-fold replication of
G(n, p) does not have an increasing property Q, then none of the m copies of G(n, p) has
the property. The converse is not true. If no copy has the property, their union may have
it. Since Q is an increasing property and q = 1 − (1 − p)m ≤ 1 − (1 − mp) = mp

Prob (cid:0)G(n, mp) has Q(cid:1) ≥ Prob (cid:0)G(n, q) has Q(cid:1)

(4.3)

We now show that any increasing property Q has a phase transition. The transition
occurs at the point at which the probability that G(n, p) has property Q is 1
2. We will
prove that for any function asymptotically less then p(n) that the probability of having
property Q goes to zero as n goes to inﬁnity.

Theorem 4.19 Every increasing property Q of G(n, p) has a phase transition at p(n),
where for each n, p(n) is the minimum real number an for which the probability that
G(n, an) has property Q is 1/2.

Proof: Let p0(n) be any function such that

lim
n→∞

p0(n)
p(n)

= 0.

We assert that almost surely G(n, p0) does not have the property Q. Suppose for con-
tradiction, that this is not true. That is, the probability that G(n, p0) has the property
Q does not converge to zero. By the deﬁnition of a limit, there exists ε > 0 for which
the probability that G(n, p0) has property Q is at least ε on an inﬁnite set I of n. Let
m = (cid:100)(1/ε)(cid:101). Let G(n, q) be the m-fold replication of G(n, p0). The probability that

120

(cid:124)

(cid:123)(cid:122)

copies of G

(cid:125)

If any graph has three or more edges, then the
m-fold replication has three or more edges.

The m-fold
replication H

(cid:124)

(cid:123)(cid:122)

copies of G

(cid:125)

Even if no graph has three or more edges, the
m-fold replication might have three or more edges.

The m-fold
replication H

Figure 4.12: The property that G has three or more edges is an increasing property. Let
H be the m-fold replication of G. If any copy of G has three or more edges, H has three
or more edges. However, H can have three or more edges even if no copy of G has three
or more edges.

G(n, q) does not have Q is at most (1 − ε)m ≤ e−1 ≤ 1/2 for all n ∈ I. For these n, by
(4.3)

Prob(G(n, mp0) has Q) ≥ Prob(G(n, q) has Q) ≥ 1/2.

Since p(n) is the minimum real number an for which the probability that G(n, an) has
property Q is 1/2, it must be that mp0(n) ≥ p(n). This implies that p0(n)
is at least 1/m
p(n)
inﬁnitely often, contradicting the hypothesis that lim
n→∞

p0(n)
p(n) = 0.

A symmetric argument shows that for any p1(n) such that lim
n→∞

almost surely has property Q.

p(n)

p1(n) = 0, G(n, p1)

4.7 Phase Transitions for CNF-sat

Phase transitions occur not only in random graphs, but in other random structures as
well. An important example is that of satisﬁability for a Boolean formula in conjunctive
normal form.

Generate a random CNF formula f with n variables, m clauses, and k literals per
clause. Each clause is picked independently with k literals picked uniformly at random
from the set of 2n possible literals to form the clause. Here, the number of clauses n

121

is going to inﬁnity, m is a function of n, and k is a ﬁxed constant. A reasonable value
to think of for k is k = 3. A literal is a variable or its negation. Unsatisﬁability is an
increasing property since adding more clauses preserves unsatisﬁability. By arguments
similar to the last section, there is a phase transition, i.e., a function m(n) such that if
m1(n) is o(m(n)), a random formula with m1(n) clauses is, almost surely, satisﬁable and
for m2(n) with m2(n)/m(n) → ∞, a random formula with m2(n) clauses is, almost surely,
unsatisﬁable. It has been conjectured that there is a constant rk independent of n such
that rkn is a sharp threshold.

Here we derive upper and lower bounds on rk. It is relatively easy to get an upper
bound on rk. A ﬁxed truth assignment satisﬁes a random k clause with probability 1 − 1
2k .
Of the 2k truth assignments to the k variables in the clause, only one fails to satisfy the
2k , the clause is not satisﬁed, and with probability 1 − 1
clause. Thus, with probability 1
2k ,
the clause is satisﬁed. Let m = cn. Now, cn independent clauses are all satisﬁed by the
(cid:1)cn. Since there are 2n truth assignments, the
ﬁxed assignment with probability (cid:0)1 − 1
2k
expected number of satisfying assignments for a formula with cn clauses is 2n (cid:0)1 − 1
(cid:1)cn.
2k
If c = 2k ln 2, the expected number of satisfying assignments is

2n (cid:0)1 − 1
2k

(cid:1)n2k ln 2 .

(cid:0)1 − 1
2k

(cid:1)2k

is at most 1/e and approaches 1/e in the limit. Thus,

2n (cid:0)1 − 1
2k

(cid:1)n2k ln 2 ≤ 2ne−n ln 2 = 2n2−n = 1.

For c > 2k ln 2, the expected number of satisfying assignments goes to zero as n → ∞.
Here the expectation is over the choice of clauses which is random, not the choice of a
truth assignment. From the ﬁrst moment method, it follows that a random formula with
cn clauses is almost surely not satisﬁable. Thus, rk ≤ 2k ln 2.

The other direction, showing a lower bound for rk, is not that easy. From now on, we
focus only on the case k = 3. The statements and algorithms given here can be extended
to k ≥ 4, but with diﬀerent constants.
It turns out that the second moment method
cannot be directly applied to get a lower bound on r3 because the variance is too high. A
simple algorithm, called the Smallest Clause Heuristic (abbreviated SC), yields a satisfy-
ing assignment with probability tending to one if c < 2
3. Other more
diﬃcult to analyze algorithms, push the lower bound on r3 higher.

3, proving that r3 ≥ 2

The Smallest Clause Heuristic repeatedly executes the following. Assign true to a
random literal in a random smallest length clause and delete the clause since it is now
satisﬁed. Pick at random a 1-literal clause, if one exists, and set that literal to true. If
there is no 1-literal clause, pick a 2-literal clause, select one of its two literals and set the
literal to true. Otherwise, pick a 3-literal clause and a literal in it and set the literal to
true. If we encounter a 0-length clause, then we have failed to ﬁnd a satisfying assignment;

122

otherwise, we have found one.

A related heuristic, called the Unit Clause Heuristic, selects a random clause with one
literal, if there is one, and sets the literal in it to true. Otherwise, it picks a random
as yet unset literal and sets it to true. The “pure literal” heuristic sets a random “pure
literal”, a literal whose negation does not occur in any clause, to true, if there are any
pure literals; otherwise, it sets a random literal to true.

When a literal w is set to true, all clauses containing w are deleted, since they are
satisﬁed, and ¯w is deleted from any clause containing ¯w. If a clause is reduced to length
zero (no literals), then the algorithm has failed to ﬁnd a satisfying assignment to the
formula. The formula may, in fact, be satisﬁable, but the algorithm has failed.

Example: Consider a 3-CNF formula with n variables and cn clauses. With n variables
there are 2n literals, since a variable and its complement are distinct literals. The expected
number of times a literal occurs is calculated as follows. Each clause has three literals.
Thus, each of the 2n diﬀerent literals occurs (3cn)
2c times on average. Suppose c = 5.
Then each literal appears 7.5 times on average. If one sets a literal to true, one would
expect to satisfy 7.5 clauses. However, this process is not repeatable since after setting a
literal to true there is conditioning so that the formula is no longer random.

2n = 3

Theorem 4.20 If the number of clauses in a random 3-CNF formula grows as cn where
c is a constant less than 2/3, then with probability 1 − o(1), the Shortest Clause Heuristic
ﬁnds a satisfying assignment.

The proof of this theorem will take the rest of the section. A general impediment to
proving that simple algorithms work for random instances of many problems is condition-
ing. At the start, the input is random and has properties enjoyed by random instances.
But, as the algorithm is executed; the data is no longer random, it is conditioned on the
steps of the algorithm so far. In the case of SC and other heuristics for ﬁnding a satisfying
assignment for a Boolean formula, the argument to deal with conditioning is relatively
simple.

We supply some intuition before going to the proof. Imagine maintaining a queue of
1 and 2-clauses. A 3-clause enters the queue when one of its literals is set to false and
it becomes a 2-clause. SC always picks a 1 or 2-clause if there is one and sets one of its
literals to true. At any step when the total number of 1 and 2-clauses is positive, one of
the clauses is removed from the queue. Consider the arrival rate, the expected number
of arrivals into the queue. For a particular clause to arrive into the queue at time t to
become a 2-clause, it must contain the negation of the literal being set to true at time t.
It can contain any two other literals not yet set. The number of such clauses is (cid:0)n−t
(cid:1)22.
2
So, the probability that a particular clause arrives in the queue at time t is at most

(cid:0)n−t
2
(cid:0)n
3

(cid:1)22
(cid:1)23

≤

3
2(n − 2)

.

123

Since there are cn clauses in total, the arrival rate is 3c
2 , which for c < 2/3 is a constant
strictly less than one. The arrivals into the queue of diﬀerent clauses occur independently
(Lemma 4.21), the queue has arrival rate strictly less than one, and the queue loses one
or more clauses whenever it is nonempty. This implies that the queue never has too many
clauses in it. A slightly more complicated argument will show that no clause remains as
a 1 or 2-clause for Ω(ln n) steps (Lemma 4.22). This implies that the probability of two
contradictory 1-length clauses, which is a precursor to a 0-length clause, is very small.

Lemma 4.21 Let Ti be the ﬁrst time that clause i turns into a 2-clause. Ti is ∞ if clause
i gets satisﬁed before turning into a 2-clause. The Ti are mutually independent and for
any t,

Prob(Ti = t) ≤

3
2(n − 2)

.

Proof: For the proof, generate the clauses in a diﬀerent way. The important thing is
that the new method of generation, called the method of “deferred decisions”, results in
the same distribution of input formulae as the original. The method of deferred decisions
is tied in with the SC algorithm and works as follows. At any time, the length of each
clause (number of literals) is all that we know; we have not yet picked which literals are
in each clause. At the start, every clause has length three and SC picks one of the clauses
uniformly at random. Now, SC wants to pick one of the three literals in that clause to
set to true, but we do not know which literals are in the clause. At this point, we pick
uniformly at random one of the 2n possible literals. Say for illustration, we picked ¯x102.
The literal ¯x102 is placed in the clause and set to true. The literal x102 is set to false. We
must also deal with occurrences of the literal or its negation in all other clauses, but again,
we do not know which clauses have such an occurrence. We decide that now. For each
clause, independently, with probability 3/n, include the variable x102 or ¯x102 in the clause
and if included, with probability 1/2, include the literal ¯x102 in the clause and with the
other 1/2 probability include its negation, namely, x102. In either case, we decrease the
residual length of the clause by one. The algorithm deletes the clause since it is satisﬁed
and we do not care which other literals are in it. If we had included the negation of the
literal instead, then we delete just that occurrence, and decrease the length of the clause
by one.

At a general stage, suppose the fates of i variables have already been decided and n − i
remain. The residual length of each clause is known. Among the clauses that are not yet
satisﬁed, choose a random shortest length clause. Among the n − i variables remaining,
pick one uniformly at random, then pick it or its negation as the new literal. Include
this literal in the clause thereby satisfying it. Since the clause is satisﬁed, the algorithm
deletes it. For each other clause, do the following. If its residual length is l, decide with
probability l/(n − i) to include the new variable in the clause and if so with probability
1/2 each, include it or its negation. If literal v is included in a clause, delete the clause
as it is now satisﬁed. If ¯v is included in a clause, then just delete the literal and decrease
the residual length of the clause by one.

124

Why does this yield the same distribution as the original one? First, observe that the
order in which the variables are picked by the method of deferred decisions is independent
of the clauses; it is just a random permutation of the n variables. Look at any one clause.
For a clause, we decide in order whether each variable or its negation is in the clause. So
for a particular clause and a particular triple i, j, and k with i < j < k, the probability
that the clause contains the ith, the jth, and kth literal (or their negations) in the order
determined by deferred decisions is:
(cid:0)1 − 3
(cid:0)1 − 2
(cid:16)

(cid:1) · · · (cid:0)1 − 3
(cid:1) · · ·
(cid:17)

(cid:1) (cid:0)1 − 2
(cid:17) (cid:16)

n−i+2
1 − 2

(cid:1) (cid:0)1 − 3

3
n−i+1
(cid:17)

n−j+2

n−i−1

n−1

n−i

(cid:16)

(cid:1)

n

1 − 1
n−j

1 − 1

n−j−1

· · · (cid:0)1 − 1

n−k+2

1
n−k+1 =

3
n(n−1)(n−2),

2
n−j+1
(cid:1)

where the (1 − · · · ) factors are for not picking the current variable or negation to be in-
cluded and the others are for including the current variable or its negation. Independence
among clauses follows from the fact that we have never let the occurrence or nonoccur-
rence of any variable in any clause inﬂuence our decisions on other clauses.

Now, we prove the lemma by appealing to the method of deferred decisions to generate
the formula. Ti = t if and only if the method of deferred decisions does not put the current
literal at steps 1, 2, . . . , t − 1 into the ith clause, but puts the negation of the literal at
step t into it. Thus, the probability is precisely
(cid:0)1 − 3

(cid:1) · · · (cid:0)1 − 3

(cid:1) (cid:0)1 − 3

(cid:1)

3

n−t+1 ≤ 3

2(n−2),

n−t+2

n−1

1
2

n

as claimed. Clearly the Ti are independent since again deferred decisions deal with diﬀer-
ent clauses independently.

Lemma 4.22 With probability 1 − o(1), no clause remains a 2 or 1-clause for Ω(ln n)
steps. I.e., once a 3-clause becomes a 2-clause, it is either satisﬁed or reduced to a 0-clause
in O(ln n) steps.

Proof: Without loss of generality, again focus on the ﬁrst clause. Suppose it becomes a
2-clause at step s1 and remains a 2 or 1-clause until step s. Suppose s − s1 ≥ c2 ln n. Let r
be the last time before s when there are no 2 or 1-clauses at all. Since at time 0, there are
no 2 or 1-clauses, r is well-deﬁned. We have s − r ≥ c2 ln n. In the interval r to s, at each
step, there is at least one 2 or 1-clause. Since SC always decreases the total number of 1
and 2-clauses by one whenever it is positive, we must have generated at least s − r new
2-clauses between r and s. Now, deﬁne an indicator random variable for each 3-clause
which has value one if the clause turns into a 2-clause between r and s. By Lemma 4.21
these variables are independent and the probability that a particular 3-clause turns into
a 2-clause at a time t is at most 3/(2(n − 2)). Summing over t between r and s,

Prob (cid:0)a 3-clause turns into a 2-clause during [r, s](cid:1) ≤

3(s − r)
2(n − 2)

.

125

2

2(n−2) ≈ 3c(s−r)

Since there are cn clauses in all, the expected sum of the indicator random variables is
cn 3(s−r)
. Note that 3c/2 < 1, which implies the arrival rate into the queue of 2
and 1-clauses is a constant strictly less than one. Using Chernoﬀ bounds, the probability
that more than s − r clauses turn into 2-clauses between r and s is at most o(1/n5). This
is for one choice of a clause, one choice of s1 and one choice each of r and s within O(ln n)
of s1. Applying the union bound over O(n3) choices of clauses, O(n) choices of s1 and
O(ln n)2 choices of r and s, we get that the probability that any clause remains a 2 or
1-clause for Ω(ln n) steps is o(1).

Now, suppose SC terminates in failure. At some time t, the algorithm generates a
0-clause. At time t − 1, this clause must have been a 1-clause. Suppose the clause consists
of the literal w. Since at time t − 1, there is at least one 1-clause, the shortest clause rule
of SC selects a 1-clause and sets the literal in that clause to true. This other clause must
have been ¯w. Let t1 be the ﬁrst time either of these two clauses, w or ¯w, became a 2-clause.
We have t − t1 ∈ O(ln n). Clearly, until time t, neither of these two clauses is picked by
SC. So, the literals which are set to true during this period are chosen independent of
these clauses. Say the two clauses were w + x + y and ¯w + u + v at the start. x, y, u,
and v must all be negations of literals set to true during steps t1 to t. So, there are
only O (cid:0)(ln n)4(cid:1) choices for x, y, u, and v. There are O(n) choices of w, O(n2) choices of
which two clauses of the input become these w and ¯w, and n choices for t1. Thus, there
are O (cid:0)n4(ln n)4(cid:1) choices for these clauses. The probability of these choices is therefore
O (cid:0)n4(ln n)4/n6(cid:1) = o(1), as required.

4.8 Nonuniform and Growth Models of Random Graphs

4.8.1 Nonuniform Models

So far we have considered the random graph G(n, p) in which all vertices have the
same expected degree and showed that the degree is concentrated close to its expecta-
tion. However, large graphs occurring in the real world tend to have power law degree
distributions. For a power law degree distribution, the number f (d) of vertices of degree
d plotted as a function of d satisﬁes f (d) ≤ c/dα, where α and c are constants.

To generate such graphs, we stipulate that there are f (d) vertices of degree d and
choose uniformly at random from the set of graphs with this degree distribution. Clearly,
in this model the graph edges are not independent and this makes these random graphs
harder to analyze. But the question of when phase transitions occur in random graphs
with arbitrary degree distributions is still of interest. In this section, we consider when
a random graph with a nonuniform degree distribution has a giant component. Our
treatment in this section, and subsequent ones, will be more intuitive without providing
rigorous proofs.

126

Consider a graph in which half of the vertices are degree one and half
are degree two. If a vertex is selected at random, it is equally likely to
be degree one or degree two. However, if we select an edge at random
and walk to its endpoint, the vertex is twice as likely to be degree two as
degree one. In many graph algorithms, a vertex is reached by randomly
selecting an edge and traversing the edge to reach an endpoint. In this
case, the probability of reaching a degree i vertex is proportional to iλi
where λi is the fraction of vertices that are degree i.

Figure 4.13: Probability of encountering a degree d vertex when following a path in a
graph.

4.8.2 Giant Component in Random Graphs with Given Degree Distribution

Molloy and Reed address the issue of when a random graph with a nonuniform degree
distribution has a giant component. Let λi be the fraction of vertices of degree i. There
will be a giant component if and only if

i(i − 2)λi > 0.

∞
(cid:80)
i=0

To see intuitively that this is the correct formula, consider exploring a component
of a graph starting from a given seed vertex. Degree zero vertices do not occur except
in the case where the vertex is the seed.
If a degree one vertex is encountered, then
that terminates the expansion along the edge into the vertex. Thus, we do not want to
encounter too many degree one vertices. A degree two vertex is neutral in that the vertex
is entered by one edge and left by the other. There is no net increase in the size of the
frontier. Vertices of degree i greater than two increase the frontier by i − 2 vertices. The
vertex is entered by one of its edges and thus there are i − 1 edges to new vertices in the
frontier for a net gain of i − 2. The iλi in i (i − 2) λi is proportional to the probability of
reaching a degree i vertex and the i − 2 accounts for the increase or decrease in size of
the frontier when a degree i vertex is reached.

Example: Consider applying the Molloy Reed conditions to the G(n, p) model. The
summation (cid:80)n
i=0 i(i − 2)pi gives value zero precisely when p = 1/n, the point at which
the phase transition occurs. At p = 1/n, the average degree of each vertex is one and
there are n/2 edges. However, the actual degree distribution of the vertices is binomial,
(cid:1)pi(1 − p)n−i. We now
where the probability that a vertex is of degree i is given by pi = (cid:0)n
show that lim
n→∞

(cid:1)pi(1 − p)n−i when p = 1/n.

i(i − 2)pi = 0 for pi = (cid:0)n

i

i

n
(cid:80)
i=0

127

lim
n→∞

n
(cid:88)

i=0

i(i − 2)

(cid:18)n
i

(cid:19) (cid:18) 1
n

(cid:19)i (cid:18)

1 −

1
n

(cid:19)n−i

= lim
n→∞

n
(cid:88)

i=0

i(i − 2)

n(n − 1) · · · (n − i + 1)
i! ni

(cid:18)

1 −

1
n
(cid:18) n

(cid:19)n (cid:18)

1 −

(cid:19)−i

1
n

(cid:19)i

n(n − 1) · · · (n − i + 1)
i! ni

n − 1

=

≤

n
(cid:88)

i(i − 2)

1
e

lim
n→∞

i=0
i(i − 2)
i!

.

∞
(cid:88)

i=0

To see that

∞
(cid:80)
i=0

i(i−2)

i! = 0, note that

∞
(cid:88)

i=0

i
i!

=

∞
(cid:88)

i=1

i
i!

=

∞
(cid:88)

i=1

1
(i − 1)!

=

∞
(cid:88)

i=0

1
i!

∞
(cid:88)

i=0

i2
i!

=

∞
(cid:88)

i=1

i
(i − 1)!

=

∞
(cid:88)

i=0

i + 1
i!

=

∞
(cid:88)

i=0

i
i!

+

∞
(cid:88)

i=0

1
i!

= 2

∞
(cid:88)

i=0

1
i!

.

and

Thus,

∞
(cid:80)
i=0

i(i−2)

i! =

∞
(cid:80)
i=0

i2
i! − 2

∞
(cid:80)
i=0

i
i! = 0.

4.9 Growth Models

4.9.1 Growth Model Without Preferential Attachment

Many graphs that arise in the outside world started as small graphs that grew over
time. In a model for such graphs, vertices and edges are added to the graph over time.
In such a model there are many ways in which to select the vertices for attaching a
new edge. One is to select two vertices uniformly at random from the set of existing
vertices. Another is to select two vertices with probability proportional to their degree.
This latter method is referred to as preferential attachment. A variant of this method
would be to add a new vertex at each unit of time and with probability δ add an edge
where one end of the edge is the new vertex and the other end is a vertex selected with
probability proportional to its degree. The graph generated by this latter method is a tree.

128

Consider a growth model for a random graph without preferential attachment. Start
with zero vertices at time zero. At each unit of time a new vertex is created and with
probability δ, two vertices chosen at random are joined by an edge. The two vertices
may already have an edge between them. In this case, we will add another edge. So, the
resulting structure is a multi-graph, rather then a graph. But since at time t, there are t
vertices and in expectation only O(δt) edges where there are t2 pairs of vertices, it is very
unlikely that there will be multiple edges.

The degree distribution for this growth model is calculated as follows. The number of
vertices of degree k at time t is a random variable. Let dk(t) be the expectation of the
number of vertices of degree k at time t. The number of isolated vertices increases by one
at each unit of time and decreases by the number of isolated vertices, b(t), that are picked
to be end points of the new edge. b(t) can take on values 0,1, or 2. Taking expectations,

d0(t + 1) = d0(t) + 1 − E(b(t)).

Now b(t) is the sum of two 0-1 valued random variables whose values are the number
of degree zero vertices picked for each end point of the new edge. Even though the
two random variables are not independent, the expectation of b(t) is the sum of the
expectations of the two variables and is 2δ d0(t)

. Thus,

t

d0(t + 1) = d0(t) + 1 − 2δ

d0(t)
t

.

The number of degree k vertices increases whenever a new edge is added to a degree k − 1
vertex and decreases when a new edge is added to a degree k vertex. Reasoning as above,

dk (t + 1) = dk(t) + 2δ

dk−1(t)
t

− 2δ

dk(t)
t

.

(4.4)

Note that this formula, as others in this section, is not quite precise. For example, the
same vertex may be picked twice, so that the new edge is a self-loop. For k << t, this
problem contributes a minuscule error. Restricting k to be a ﬁxed constant and letting
t → ∞ in this section avoids these problems.

Assume that the above equations are exactly valid. Clearly, d0(1) = 1 and d1(1) =
d2(1) = · · · = 0. By induction on t, there is a unique solution to (4.4), since given dk(t)
for all k, the equation determines dk(t + 1) for all k. There is a solution of the form
dk(t) = pkt, where pk depends only on k and not on t, provided k is ﬁxed and t → ∞.
Again, this is not precisely true, d1(1) = 0 and d1(2) > 0 clearly contradict the existence
of a solution of the form d1(t) = p1t.

Set dk(t) = pkt. Then,

(t + 1) p0 = p0t + 1 − 2δ

p0t
t

p0 = 1 − 2δp0

129

Figure 4.14: In selecting a component at random, each of the two components is equally
likely to be selected. In selecting the component containing a random vertex, the larger
component is twice as likely to be selected.

and

p0 =

1
1 + 2δ

(t + 1) pk = pkt + 2δ

pk−1t
t

− 2δ

pkt
t

pk = 2δpk−1 − 2δpk

pk =

=

=

2δ
1 + 2δ
(cid:18) 2δ

pk−1

(cid:19)k

1 + 2δ

p0

1
1 + 2δ

(cid:18) 2δ

(cid:19)k

1 + 2δ

.

(4.5)

Thus, the model gives rise to a graph with a degree distribution that falls oﬀ exponentially
fast with degree.

The generating function for component size

Let nk(t) be the expected number of components of size k at time t. Then nk(t) is
proportional to the probability that a randomly picked component is of size k. This is
not the same as picking the component containing a randomly selected vertex (see Figure
4.14). Indeed, the probability that the size of the component containing a randomly se-
lected vertex is k is proportional to knk(t). We will show that there is a solution for nk(t)
of the form akt where ak is a constant independent of t. After showing this, we focus on
the generating function g(x) for the numbers kak(t) and use g(x) to ﬁnd the threshold
for giant components.

Consider n1(t), the expected number of isolated vertices at time t. At each unit of
t many isolated

time, an isolated vertex is added to the graph and an expected 2δn1(t)
vertices are chosen for attachment and thereby leave the set of isolated vertices. Thus,

n1(t + 1) = n1(t) + 1 − 2δ

n1(t)
t

.

130

For k >1, nk(t) increases when two smaller components whose sizes sum to k are joined
by an edge and decreases when a vertex in a component of size k is chosen for attachment.
The probability that a vertex selected at random will be in a size k component is knk(t)
.
Thus,

t

nk(t + 1) = nk(t) + δ

k−1
(cid:88)

j=1

jnj(t)
t

(k − j)nk−j(t)
t

− 2δ

knk(t)
t

.

To be precise, one needs to consider the actual number of components of various sizes,
rather than the expected numbers. Also, if both vertices at the end of the edge are in the
same k-vertex component, then nk(t) does not go down as claimed. These small inaccu-
racies can be ignored.

Consider solutions of the form nk(t) = akt. Note that nk(t) = akt implies the num-
ber of vertices in a connected component of size k is kakt. Since the total number of
vertices at time t is t, kak is the probability that a random vertex is in a connected
component of size k. The recurrences here are valid only for k ﬁxed as t → ∞. So
(cid:80)∞
k=0 kak may be less than 1, in which case, there are nonﬁnite size components whose

sizes are growing with t. Solving for ak yields a1 = 1

1+2δ and ak = δ

1+2kδ

j(k − j)ajak−j.

k−1
(cid:80)
j=1

Consider the generating function g(x) for the distribution of component sizes where
the coeﬃcient of xk is the probability that a vertex chosen at random is in a component
of size k.

∞
(cid:88)

g(x) =

kakxk.

k=1

Now, g(1) = (cid:80)∞
k=0 kak is the probability that a randomly chosen vertex is in a ﬁnite sized
component. For δ = 0, this is clearly one, since all vertices are in components of size one.
On the other hand, for δ = 1, the vertex created at time one has expected degree log n,
so it is in a nonﬁnite size component. This implies that for δ = 1, g(1) < 1 and there is a
nonﬁnite size component. Assuming continuity, there is a δcritical above which g(1) < 1.
From the formula for the a(cid:48)

is, we will derive the diﬀerential equation

g = −2δxg(cid:48) + 2δxgg(cid:48) + x

and then use the equation for g to determine the value of δ at which the phase transition
for the appearance of a nonﬁnite sized component occurs.

Derivation of g(x)

From

and

a1 =

1
1 + 2δ

ak =

δ
1 + 2kδ

k−1
(cid:88)

j=1

j(k − j)ajak−j

131

derive the equations

and

a1 (1 + 2δ) − 1 = 0

ak (1 + 2kδ) = δ

k−1
(cid:88)

j=1

j(k − j)ajak−j

for k ≥ 2. The generating function is formed by multiplying the kth equation by kxk and
summing over all k. This gives

−x +

∞
(cid:88)

k=1

kakxk + 2δx

∞
(cid:88)

k=1

akk2xk−1 = δ

∞
(cid:88)

kxk

k−1
(cid:88)

k=1

j=1

j(k − j)ajak−j.

Note that

Thus,

g(x) =

∞
(cid:80)
k=1

kakxk and g(cid:48)(x) =

∞
(cid:80)
k=1

akk2xk−1.

−x + g(x) + 2δxg(cid:48)(x) = δ

∞
(cid:88)

kxk

k−1
(cid:88)

k=1

j=1

j(k − j)ajak−j.

Working with the right hand side

∞
(cid:88)

δ

kxk

k−1
(cid:88)

k=1

j=1

j(k − j)ajak−j = δx

∞
(cid:88)

k−1
(cid:88)

k=1

j=1

j(k − j)(j + k − j)xk−1ajak−j.

Now breaking the j + k − j into two sums gives

∞
(cid:88)

k−1
(cid:88)

δx

k=1

j=1

j2ajxj−1(k − j)ak−jxk−j + δx

∞
(cid:88)

k−1
(cid:88)

k=1

j=1

jajxj(k − j)2ak−jxk−j−1.

Notice that the second sum is obtained from the ﬁrst by substituting k − j for j and that
both terms are δxg(cid:48)g. Thus,

−x + g(x) + 2δxg(cid:48)(x) = 2δxg(cid:48)(x)g(x).

Hence,

g(cid:48) =

1
2δ

1 − g
x
1 − g

.

Phase transition for nonﬁnite components

The generating function g(x) contains information about the ﬁnite components of the
graph. A ﬁnite component is a component of size 1, 2, . . . which does not depend on t.

132

∞
(cid:80)
k=0

Observe that g(1) =

kak and hence g(1) is the probability that a randomly chosen

vertex will belong to a component of ﬁnite size. If g(1) = 1 there are no nonﬁnite com-
ponents. When g(1) (cid:54)= 1, then 1 − g(1) is the expected fraction of the vertices that are in
nonﬁnite components. Potentially, there could be many such nonﬁnite components. But
an argument similar to Part 3 of Theorem 4.9 concludes that two fairly large components
would merge into one. Suppose there are two connected components at time t, each of
size at least t4/5. Consider the earliest created 1
2t4/5 vertices in each part. These vertices
must have lived for at least 1
2t4/5 time after creation. At each time, the probability of an
edge forming between two such vertices, one in each component, is at least δΩ(t−2/5) and
so the probability that no such edge formed is at most (cid:0)1 − δt−2/5(cid:1)t4/5/2 ≤ e−Ω(δt2/5) → 0.
So with high probability, such components would have merged into one. But this still
leaves open the possibility of many components of size tε, (ln t)2, or some other slowly
growing function of t.

We now calculate the value of δ at which the phase transition for a nonﬁnite component

occurs. Recall that the generating function for g (x) satisﬁes

g(cid:48) (x) =

1
2δ

1 − g(x)
x
1 − g (x)

.

If δ is greater than some δcritical, then g(1) (cid:54)= 1. In this case the above formula simpliﬁes
with 1 − g(1) canceling from the numerator and denominator, leaving just 1
2δ . Since kak
is the probability that a randomly chosen vertex is in a component of size k, the average
size of the ﬁnite components is g(cid:48)(1) =

k2ak. Now, g(cid:48)(1) is given by

∞
(cid:80)
k=1

g(cid:48)(1) =

1
2δ

(4.6)

for all δ greater than δcritical. If δ is less than δcritical, then all vertices are in ﬁnite compo-
nents. In this case g(1) = 1 and both the numerator and the denominator approach zero.
Appling L’Hopital’s rule

or

lim
x→1

g(cid:48)(x) = 1
2δ

xg(cid:48)(x)−g(x)
x2
g(cid:48)(x)

(cid:12)
(cid:12)
(cid:12)
(cid:12)x=1

(g(cid:48)(1))2 = 1
2δ

(cid:0)g(cid:48)(1) − g(1)(cid:1).

The quadratic (g(cid:48)(1))2 − 1

2δ g(cid:48)(1) + 1

2δ g(1) = 0 has solutions

1
2δ ±

g(cid:48)(1) =

(cid:113) 1

4δ2 − 4
2

2δ

1 ±

=

√

1 − 8δ
4δ

.

(4.7)

133

The two solutions given by (4.7) become complex for δ > 1/8 and thus can be valid only
for 0 ≤ δ ≤ 1/8. For δ > 1/8, the only solution is g(cid:48)(1) = 1
2δ and a nonﬁnite component
exists. As δ is decreased, at δ = 1/8 there is a singular point where for δ < 1/8 there are
three possible solutions, one from (4.6) which implies a giant component and two from
(4.7) which imply no giant component. To determine which one of the three solutions is
valid, consider the limit as δ → 0. In the limit all components are of size one since there
are no edges. Only (4.7) with the minus sign gives the correct solution

1 −

g(cid:48) (1) =

√

1 − 8δ
4δ

=

1 − (cid:0)1 − 1

464δ2 + · · ·(cid:1)

28δ − 1
4δ

= 1 + 4δ + · · · = 1.

In the absence of any nonanalytic behavior in the equation for g(cid:48) (x) in the region
0 ≤ δ < 1/8, we conclude that (4.7) with the minus sign is the correct solution for
0 ≤ δ < 1/8 and hence the critical value of δ for the phase transition is 1/8. As we shall
see, this is diﬀerent from the static case.

As the value of δ is increased, the average size of the ﬁnite components increase from

one to

1 −

√

1 − 8δ
4δ

(cid:12)
(cid:12)
(cid:12)
(cid:12)δ=1/8

= 2

when δ reaches the critical value of 1/8. At δ = 1/8, the average size of the ﬁnite com-
ponents jumps to 1
2δ as the giant component swallows
2δ
up the ﬁnite components starting with the larger components.

(cid:12)
(cid:12)δ=1/8 = 4 and then decreases as 1

Comparison to static random graph

Consider a static random graph with the same degree distribution as the graph in the
growth model. Again let pk be the probability of a vertex being of degree k. From (4.5)

pk =

(2δ)k
(1 + 2δ)k+1 .

Recall the Molloy Reed analysis of random graphs with given degree distributions which
∞
(cid:80)
i=0

i(i − 2)pi = 0. Using this, it is easy to see

asserts that there is a phase transition at

that a phase transition occurs for δ = 1/4. For δ = 1/4,

pk = (2δ)k

(1+2δ)k+1 =

and

(cid:17)k
(cid:17)k+1 =

(cid:16) 1
2
1
2

(cid:16)

1+

(cid:17)k

(cid:16) 1
2
(cid:0) 3
2

3
2

(cid:1)k = 2

3

(cid:1)k

(cid:0) 1
3

134

Size of
nonﬁnite
component

grown

static

1/8 1/4

δ

Figure 4.15: Comparison of the static random graph model and the growth model. The
curve for the growth model is obtained by integrating g(cid:48).

∞
(cid:88)

i=0

i(i − 2) 2
3

(cid:0) 1
3

(cid:1)i = 2

3

∞
(cid:80)
i=0

i2 (cid:0) 1

3

(cid:1)i − 4

3

∞
(cid:80)
i=0

i (cid:0) 1

3

(cid:1)i = 2

3 × 3

2 − 4

3 × 3

4 = 0.

Recall that 1 + a + a2 + · · · = 1

1−a , a + 2a2 + 3a3 · · · = a

(1−a)2 , and a + 4a2 + 9a3 · · · = a(1+a)
(1−a)3 .

See references at end of the chapter for calculating the size Sstatic of the giant compo-

nent in the static graph. The result is

Sstatic =

(cid:26) 0

1 −

√

δ+

1
δ2+2δ

δ ≤ 1
4
δ > 1
4

4.9.2 Growth Model With Preferential Attachment

Consider a growth model with preferential attachment. At each time unit, a vertex is
added to the graph. Then with probability δ, an edge is attached to the new vertex and
to a vertex selected at random with probability proportional to its degree. This model
generates a tree with a power law distribution.

Let di(t) be the expected degree of the ith vertex at time t. The sum of the degrees of
all vertices at time t is 2δt and thus the probability that an edge is connected to vertex i
at time t is di(t)

2δt . The degree of vertex i is governed by the equation

∂
∂t

di(t) = δ

di (t)
2δt

=

di(t)
2t

where δ is the probability that an edge is added at time t and di(t)
2δt
the vertex i is selected for the end point of the edge.

is the probability that

The two in the denominator governs the solution which is of the form at
1
2 or a = δi−

of a is determined by the initial condition di (t) = δ at t = i. Thus, δ = ai

1
2 . The value
1
2 .

135

degree

d

(cid:122)
1, 2, 3

(cid:113) t
i

δ

di(t) > d
(cid:125)(cid:124)

(cid:123) (cid:122)
δ2
d2 t
←− vertex number −→

di(t) < d
(cid:125)(cid:124)

(cid:123)

t

Figure 4.16: Illustration of degree of ith vertex at time t. At time t, vertices numbered 1
to δ2

d2 t have degrees greater than d.

Hence, di(t) = δ

(cid:113) t
i .

Next, we determine the probability distribution of vertex degrees. Now, di(t) is less
d2 t and thus
d2 . Hence, the probability that a vertex has degree

d2 t. The fraction of the t vertices at time t for which i > δ2

than d provided i > δ2
that the degree is less than d is 1 − δ2
less than d is 1 − δ2

d2 . The probability density P (d) satisﬁes

(cid:90) d

0

P (d)∂d = Prob(degree < d) = 1 −

δ2
d2

and can be obtained from the derivative of Prob(degree < d).

P (d) =

∂
∂d

(cid:18)

1 −

(cid:19)

δ2
d2

= 2

δ2
d3 ,

a power law distribution.

4.10 Small World Graphs

In the 1960’s, Stanley Milgram carried out an experiment that indicated that any two
individuals in the United States were connected by a short sequence of acquaintances.
Milgram would ask a source individual, say in Nebraska, to start a letter on its journey
to a target individual in Massachusetts. The Nebraska individual would be given basic
information about the target including his address and occupation and asked to send the
letter to someone he knew on a ﬁrst name basis, who was closer to the target individual,
in order to transmit the letter to the target in as few steps as possible. Each person
receiving the letter would be given the same instructions. In successful experiments, it
would take on average ﬁve to six steps for a letter to reach its target. This research
generated the phrase “six degrees of separation” along with substantial research in social

136

science on the interconnections between people. Surprisingly, there was no work on how
to ﬁnd the short paths using only local information.

In many situations, phenomena are modeled by graphs whose edges can be partitioned
into local and long distance. We adopt a simple model of a directed graph due to Klein-
berg, having local and long distance edges. Consider a 2-dimensional n × n grid where
each vertex is connected to its four adjacent vertices. In addition to these local edges,
there is one long distance edge out of each vertex. The probability that the long distance
edge from vertex u terminates at v, v (cid:54)= u, is a function of the distance d(u, v) from u to
v. Here distance is measured by the shortest path consisting only of local grid edges. The
probability is proportional to 1/dr (u, v) for some constant r. This gives a one parameter
family of random graphs. For r equal zero, 1/d0 (u, v) = 1 for all u and v and thus the
end of the long distance edge at u is uniformly distributed over all vertices independent
of distance. As r increases the expected length of the long distance edge decreases. As
r approaches inﬁnity, there are no long distance edges and thus no paths shorter than
that of the lattice path. What is interesting is that for r less than two, there are always
short paths, but no local algorithm to ﬁnd them. A local algorithm is an algorithm that
is only allowed to remember the source, the destination, and its current location and can
query the graph to ﬁnd the long-distance edge at the current location. Based on this
information, it decides the next vertex on the path.

The diﬃculty is that for r < 2, the end points of the long distance edges tend to
be uniformly distributed over the vertices of the grid. Although short paths exist, it is
unlikely on a short path to encounter a long distance edge whose end point is close to
the destination. When r equals two, there are short paths and the simple algorithm that
always selects the edge that ends closest to the destination will ﬁnd a short path. For r
greater than two, again there is no local algorithm to ﬁnd a short path. Indeed, with high
probability, there are no short paths at all.

The probability that the long distance edge from u goes to v is proportional to
d−r(u, v). Note that the constant of proportionality will vary with the vertex u depend-
ing on where u is relative to the border of the n × n grid. However, the number of
vertices at distance exactly k from u is at most 4k and for k ≤ n/2 is at least k. Let
cr(u) = (cid:80)
It is the inverse of the constant of
proportionality.

v d−r(u, v) be the normalizing constant.

For r > 2, cr(u) is lower bounded by

cr(u) =

(cid:88)

v

d−r(u, v) ≥

n/2
(cid:88)

k=1

(k)k−r =

n/2
(cid:88)

k=1

k1−r ≥ 1.

No matter how large r is the ﬁrst term of (cid:80)n/2

k=1 k1−r is at least one.

137

r > 2 The lengths of long distance edges tend to be short so the
probability of encountering a suﬃciently long, long-distance edge is
too low.

r = 2 Selecting the edge with end point closest to the destina-
tion ﬁnds a short path.

r < 2 The ends of long distance edges tend to be uniformly dis-
Short paths exist but a polylog length path is unlikely
tributed.
to encounter a long distance edge whose end point is close to the
destination.

Figure 4.17: Eﬀects of diﬀerent values of r on the expected length of long distance edges
and the ability to ﬁnd short paths.

For r = 2 the normalizing constant cr(u) is upper bounded by

cr(u) =

(cid:88)

v

d−r(u, v) ≤

2n
(cid:88)

(4k)k−2 ≤ 4

k=1

2n
(cid:88)

k=1

1
k

= θ(ln n).

For r < 2, the normalizing constant cr(u) is lower bounded by

cr(u) =

(cid:88)

v

d−r(u, v) ≥

n/2
(cid:88)

(k)k−r ≥

n/2
(cid:88)

k1−r.

k=1

k=n/4

The summation

n/2
(cid:80)

k=n/4

k1−r has n

4 terms, the smallest of which is (cid:0) n

4

(cid:1)1−r or (cid:0) n

2

(cid:1)1−r depending

on whether r is greater or less than one. This gives the following lower bound on cr(u).

cr(u) ≥

n
4

ω(n1−r) = ω(n2−r).

No short paths exist for the r > 2 case.

For r > 2, we ﬁrst show that for at least one half the pairs of vertices there is no short
path between them. We begin by showing that the expected number of edges of length
greater than n r+2
2r goes to zero. The probability of an edge from u to v is d−r(u, v)/cr(u)
where cr(u) is lower bounded by a constant. Thus, the probability that a long edge is of
(cid:17)−r
length greater than or equal to n r+2
or cn−( r+2
n r+2

2 ). Since there are n2 long edges, the expected number of edges of length at least
2 , which for r > 2 goes to zero. Thus, by the ﬁrst

is upper bounded by some constant c times

is at most cn2n− (r+2)

or cn 2−r

n r+2

(cid:16)

2r

2r

2r

2

138

moment method, almost surely, there are no such edges.

For at least one half of the pairs of vertices, the grid distance, measured by grid edges
between the vertices, is greater than or equal to n/4. Any path between them must have
4n r−2
4n/n r+2
at least 1
2r and so there is
no polylog length path.

2r edges since there are no edges longer than n r+2

2r = 1

An algorithm for the r = 2 case

For r = 2, the local algorithm that selects the edge that ends closest to the destination
t ﬁnds a path of expected length O(ln n)3. Suppose the algorithm is at a vertex u which
is a at distance k from t. Then within an expected O(ln n)2 steps, the algorithm reaches
a point at distance at most k/2. The reason is that there are Ω(k2) vertices at distance at
most k/2 from t. Each of these vertices is at distance at most k + k/2 = O(k) from u. See
Figure 4.18. Recall that the normalizing constant cr is upper bounded by O(ln n), and
hence, the constant of proportionality is lower bounded by some constant times 1/ ln n.
Thus, the probability that the long-distance edge from u goes to one of these vertices is
at least

Ω(k2k−r/ ln n) = Ω(1/ ln n).

Consider Ω(ln n)2 steps of the path from u. The long-distance edges from the points
visited at these steps are chosen independently and each has probability Ω(1/ ln n) of
reaching within k/2 of t. The probability that none of them does is

(cid:0)1 − Ω(1/ ln n)(cid:1)c(ln n)2

= c1e− ln n =

c1
n

for a suitable choice of constants. Thus, the distance to t is halved every O(ln n)2 steps
and the algorithm reaches t in an expected O(ln n)3 steps.

A local algorithm cannot ﬁnd short paths for the r < 2 case

For r < 2 no local polylog time algorithm exists for ﬁnding a short path. To illustrate
the proof, we ﬁrst give the proof for the special case r = 0, and then give the proof for
r < 2.

When r = 0, all vertices are equally likely to be the end point of a long distance edge.
Thus, the probability of a long distance edge hitting one of the n vertices that are within
distance
n, the probability that
the path does not encounter such an edge is (1 − 1/n)

n of the destination is 1/n. Along a path of length

n . Now,

√

√

√

√

(cid:19)

n

(cid:18)

lim
n→∞

1 −

1
n

(cid:18)

= lim
n→∞

1 −

(cid:19)n 1√

n

1
n

= lim
n→∞

e− 1√

n = 1.

139

< 3k/2

k/2

u

k

t

Ω(k2) vertices at
distance k/2 from t

Figure 4.18: Small worlds.

√

Since with probability 1/2 the starting point is at distance at least n/4 from the desti-
n steps, the path will not encounter a long distance edge ending within
nation and in
n of the destination, for at least half of the starting points the path length will
distance
√
n and hence not in polylog time.
be at least

n. Thus, the expected time is at least 1
2

√

√

For the general r < 2 case, we show that a local algorithm cannot ﬁnd paths of length
O(n(2−r)/4). Let δ = (2 − r)/4 and suppose the algorithm ﬁnds a path with at most nδ
edges. There must be a long-distance edge on the path which terminates within distance
nδ of t; otherwise, the path would end in nδ grid edges and would be too long. There are
O(n2δ) vertices within distance nδ of t and the probability that the long distance edge from
(cid:1) = n(r−2)/2. To
one vertex of the path ends at one of these vertices is at most n2δ (cid:0) 1
n2−r
see this, recall that the lower bound on the normalizing constant is θ(n2−r) and hence an
upper bound on the probability of a long distance edge hitting v is θ (cid:0) 1
(cid:1) independent
n2−r
of where v is. Thus, the probability that the long distance edge from one of the nδ vertices
n2−r = n r−2
on the path hits any one of the n2δ vertices within distance nδ of t is n2δ
2 .
The probability that this happens for any one of the nδ vertices on the path is at most
n r−2

4 = n(r−2)/4 = o(1) as claimed.

2 nδ = n r−2

2 n 2−r

1

Short paths exist for r < 2

Finally we show for r < 2 that there are O(ln n) length paths between s and t. The
proof is similar to the proof of Theorem 4.17 showing O(ln n) diameter for G(n, p) when
p is Ω(ln n/n), so we do not give all the details here. We give the proof only for the case
when r = 0.

For a particular vertex v, let Si denote the set of vertices at distance i from v. Using
ln n), then |Si| is Ω(ln n). For later i, we argue a constant

only local edges, if i is O(

√

140

n2 )|Si| ≤ 1 − |Si|

factor growth in the size of Si as in Theorem 4.17. As long as |S1|+|S2|+· · ·+|Si| ≤ n2/2,
for each of the n2/2 or more vertices outside, the probability that the vertex is not in
Si+1 is (1 − 1
2n2 since the long-distance edge from each vertex of Si chooses
a long-distance neighbor at random. So, the expected size of Si+1 is at least |Si|/4 and
using Chernoﬀ, we get constant factor growth up to n2/2. Thus, for any two vertices v
and w, the number of vertices at distance O(ln n) from each is at least n2/2. Any two
sets of cardinality at least n2/2 must intersect giving us a O(ln n) length path from v to
w.

4.11 Bibliographic Notes

The G(n, p) random graph model is from Erd¨os R´enyi [ER60]. Among the books writ-
ten on properties of random graphs a reader may wish to consult Palmer [Pal85], Jansen,
Luczak and Ruci´nski [JLR00],or Bollob´as [Bol01]. Material on phase transitions can be
found in [BT87]. The work on phase transitions for CNF was started by Chao and Franco
[CF86]. Further work was done in [FS96], [AP03], [Fri99], and others. The proof here
that the SC algorithm produces a solution when the number of clauses is cn for c < 2
3 is
from [Chv92].

For material on the giant component consult [Kar90] or [JKLP93]. Material on branch-
ing process can be found in [AN72]. The phase transition for giant components in random
graphs with given degree distributions is from Molloy and Reed [MR95a].

There are numerous papers on growth models. The material in this chapter was based
primarily on [CHK+] and [BA]. The material on small world is based on Kleinberg, [Kle00]
which follows earlier work by Watts and Strogatz [WS98a].

141

4.12 Exercises

Exercise 4.1 Search the World Wide Web to ﬁnd some real world graphs in machine
readable form or data bases that could automatically be converted to graphs.

1. Plot the degree distribution of each graph.

2. Compute the average degree of each graph.

3. Count the number of connected components of each size in each graph.

4. Describe what you ﬁnd.

Exercise 4.2 Find a data base in machine readable form that can be viewed as a graph.
What is the average vertex degree? If the graph were a G(n, p) graph, what would the
value of p be? Find the number of components of various sizes. Check that your work
is correct by multiplying the number of components of size s by s and summing over all
sizes. Is the sum equal to the total number of vertices? Examine the small components
and see if any have cycles.
Exercise 4.3 In G(n, p) the probability of a vertex having degree k is (cid:0)n

(cid:1)pk(1 − p)n−k.

k

1. Show by direct calculation that the expected degree is np.

2. Compute directly the variance of the distribution.

3. Where is the mode of the binomial distribution for a given value of p? The mode is

the point at which the probability is maximum.

Exercise 4.4

1. Plot the degree distribution for G(1000, 0.003).

2. Plot the degree distribution for G(1000, 0.030).

Exercise 4.5 In G (cid:0)n, 1
Give an exact formula; also derive simple approximations.

(cid:1) , what is the probability that there is a vertex of degree log n?

n

Exercise 4.6 The example of Section 4.1.1 showed that if the degrees in G(n, 1
n) were
independent there would almost surely be a vertex of degree log n/ log log n. However, the
degrees are not independent. Show how to overcome this diﬃculty.

Exercise 4.7 Let f (n) be a function that is asymptotically less than n. Some such func-

tions are 1/n, a constant d, log n or n

1
3 . Show that
(cid:17)n

(cid:39) ef (n).

(cid:16)

1 + f (n)
n

for large n. That is

(cid:17)n

(cid:16)

1 + f (n)
n
ef (n)

lim
n→∞

= 1.

142

Exercise 4.8

1. In the limit as n goes to inﬁnity, how does (cid:0)1 − 1

n

(cid:1)n ln n behave.

2. What is lim
n→∞

(cid:0) n+1
n

(cid:1)n?

Exercise 4.9 Consider a random permutation of the integers 1 to n. The integer i is
said to be a ﬁxed point of the permutation if i is the integer in the ith position of the
permutation. Use indicator variables to determine the expected number of ﬁxed points in
a random permutation.

Exercise 4.10 Generate a graph G (cid:0)n, d
number of triangles in each graph. Try the experiment with n=100.

(cid:1) with n = 1000 and d=2, 3, and 6. Count the

n

Exercise 4.11 What is the expected number of squares (4-cycles) in G (cid:0)n, d
the expected number of 4-cliques in G (cid:0)n, d

(cid:1)?

n

n

(cid:1)? What is

Exercise 4.12 Carry out an argument, similar to the one used for triangles, to show that
p = 1
n2/3 is a threshold for the existence of a 4-clique. A 4-clique consists of four vertices
with all (cid:0)4

(cid:1) edges present.

2

Exercise 4.13 What is the expected number of paths of length 3, log n,
in G(n, d
that a graph selected at random has such a path.

n, and n − 1
n )? The expected number of paths of a given length being inﬁnite does not imply

√

Exercise 4.14 Consider G(n, 1

2). Give an algorithm that with high probability will ﬁnd

1. a clique of size log n.

2. an independent set of size log n. A set of vertices is an independent set if there is

no edge between any pair of vertices in the set.

3. a subgraph3 S in G(n, 1

2), where S is any speciﬁed graph with log n vertices.

Exercise 4.15 Let x be an integer chosen uniformly at random from {1, 2, . . . , n}. Count
the number of distinct prime factors of n. The exercise is to show that the number of prime
factors almost surely is Θ(ln ln n). Let p stand for a prime number between 2 and n.

1. For each ﬁxed prime p, let Ip be the indicator function of the event that p divides x.
(cid:1). It is known that (cid:80)
1
p = ln ln n and you may assume

Show that E(Ip) = 1

p + O (cid:0) 1

n

p≤n

this.

3A subgraph of a graph is a subset of the vertices along with all the edges of the graph that connect

pairs of vertices in the subset. Some books refer to this as an induced subgraph.

143

2. The random variable of interest, y = (cid:80)

Ip, is the number of prime divisors of x

p
picked at random. Show that the variance of y is O(ln ln n). For this, assume the
known result that the number of primes up to n is O(n/ ln n). To bound the variance
of y, think of what E(IpIq) is for p (cid:54)= q, both primes.

3. Use (1) and (2) to prove that the number of prime factors is almost surely θ(ln ln n).

Exercise 4.16 Show for (cid:15) > 0 that with high probability there exists a clique of size
(2 − (cid:15)) log n in G(n, 1

2), but no clique of size 2 log n.

(cid:1). I.e.,
Exercise 4.17 Suppose one hides a clique of size k in a random graph G (cid:0)n, 1
in the random graph, choose some subset S of k vertices and put in the missing edges to
make S a clique. Presented with the modiﬁed graph, ﬁnd S. The larger S is, the easier
it should be to ﬁnd. In fact, if k is more than c
n ln n, then the clique leaves a telltale
sign identifying S as the k vertices of largest degree. Prove this statement by appealing
to Theorem 4.1.1. It remains a puzzling open problem to do this when k is smaller, say,
O(n1/3).

√

2

Exercise 4.18 The clique problem in a graph is to ﬁnd the maximal size clique. This
problem is known to be NP-hard and so a polynomial time algorithm is thought unlikely.
(cid:1)
We can ask the corresponding question about random graphs. For example, in G (cid:0)n, 1
there almost surely is a clique of size (2 − ε) log n for any ε > 0. But it is not known how
to ﬁnd one in polynomial time.

2

1. Show that in G(n, 1

2), there are, almost surely, no cliques of size 2 log2 n.

2. Use the second moment method to show that in G(n, 1

2), almost surely there are

cliques of size (2 − ε) log2 n.

3. Show that for any ε > 0, a clique of size (2 − ε) log n can be found in G (cid:0)n, 1

(cid:1) in

2

time nO(ln n).

4. Give an O (n2) algorithm for ﬁnding a clique of size Ω (log n) in G(n, 1

a greedy algorithm. Apply your algorithm to G (cid:0)1000, 1
ﬁnd?

2

2). Hint: use
(cid:1). What size clique do you

5. An independent set of vertices in a graph is a set of vertices, no two of which are
connected by an edge. Give a polynomial time algorithm for ﬁnding an independent
set in G (cid:0)n, 1

(cid:1)of size Ω (log n).

2

Exercise 4.19 Does there exist a copy of every subgraph with (2 − (cid:15)) log n vertices and
1
4

(cid:1) edges in G(n, 1

(cid:0)(2−(cid:15)) log n
2

4)?

Exercise 4.20 Given two instances, G1 and G2 of G(n, 1
common to both G1 and G2?

2), what is the largest subgraph

144

Exercise 4.21 (Birthday problem) What is the number of integers that must be drawn
with replacement from a set of n integers so that some integer, almost surely, will be
selected twice?

Exercise 4.22 Suppose the graph of a social network has 20,000 vertices. You have a
program that starting from a random seed produces a community. A community is a set
of vertices where each vertex in the set has more edges connecting it toother vertices in
the set than to vertices outside of the set. In running the algorithm you ﬁnd thousands of
communities and wonder how many communities there are in the graph. Finally, when
you ﬁnd the 10, 000th community, it is a duplicate. It is the same community as one found
earlier.

1. Use the birthday problem to derive a lower bound on the number of communities.

2. Why do you only get a lower bound and not a good estimate?
Exercise 4.23 To better understand the binomial distribution plot (cid:0)n
(cid:1)pk(1 − p)(n − k) as
a function of k for n = 50 and k = 0.05, 0.5, 0.95. For each value of p check the sum over
all k to ensure that the sum is one.

k

for d > 1.
Exercise 4.24 Consider the binomial distribution binomial
Here the distribution giving the probability of drawing i items is a diﬀerent distribution
for each value of i.Prove that as n → ∞, the distribution goes to zero for all i except for
√
i in the two ranges [0, c1 log n] and [θn − c2

n, θn + c2

n].

√

n

(cid:16)

n, 1 − (cid:0)1 − d

(cid:1)i(cid:17)

Exercise 4.25 Let s be the expected number of vertices discovered as a function of the
(cid:1). Write a diﬀerential equation using
number of steps t in a breadth ﬁrst search of G (cid:0)n, d
expected values for the size of s. Show that the normalized size f = s−t
n of the frontier is
f (x) = 1 − e−dx − x where x = t

n is the normalized time.

n

Exercise 4.26 The normalized frontier in a breadth ﬁrst search of G(n, d
n ) is f (x) =
1 − e−dx − x For d > 1 let θ be the unique root in (0, 1) of 1 − e−dx − x = 0. Prove that the
expected value of the size of the frontier increases varies with i for i in the neighborhood
of θ.

Exercise 4.27 For f (x) = 1 − e−dx − x, what is the value of xmax = arg max f (x)? What
is the value of f (xmax)? Where does the maximum expected value of the frontier of a
breadth search in G(n, d

n ) occur as a function of n?

Exercise 4.28 If y and z are independent, nonnegative random variables, then the gen-
erating function of the sum y + z is the product of the generating function of y and z.
Show that this follows from E(xy+z) = E(xyxz) = E(xy)E(xz).

Exercise 4.29 Let fj(x) be the jth iterate of the generating function f (x) of a branch-
ing process. When m > 1, limj→∞fj(x) = q for 0 < x < 1. In the limit this implies
Prob (zj = 0) = q and Prob (zj = i) = 0 for all nonzero ﬁnite values of i. Shouldn’t the
probabilities add up to 1? Why is this not a contradiction?

145

Exercise 4.30 Try to create a probability distribution for a branching process which
varies with the current population in which future generations neither die out, nor grow
to inﬁnity.

Exercise 4.31 Let d be a constant strictly greater than 1. Show that for a branching
process with number of children distributed as Binomial(n − c1n2/3, d
n ), the root of the
f (x) = 1 in (0, 1) is at most a constant strictly less than 1.

Exercise 4.32 Randomly generate G (50, p) for several values of p. Start with p = 1
50.

1. For what value of p do cycles ﬁrst appear?

2. For what value of p do isolated vertices disappear and the graphs become connected?

Exercise 4.33 Consider G(n, p) with p = 1
of length 10.

3n . Then, almost surely, there are no cycles

1. Use the second moment method to show that, almost surely, there is a simple path

of length 10.

2. What goes wrong if we try to modify the argument that, almost surely, there are no

cycles of length 10 to show that there is no path of length 10?

n, d > 1, G(n, p) almost surely has a cycle.

Exercise 4.34 Complete the second moment argument of Theorem 4.13 to show that for
p = d
Hint: If two cycles share one or more edges, then the union of the two cycles is at least
one greater than the union of the vertices.

Exercise 4.35 Let G (n, p) be a random graph and let x be the random variable denoting
the number of unordered pairs of nonadjacent vertices (u, v) such that no other vertex of G
E (x) = 0, then for large n there are almost
is adjacent to both u and v. Prove that if lim
n→∞
no disconnected graphs, i.e. Prob(x = 0) → 1 and hence Prob (G is connected) → 1.
Actually, the graph becomes connected long before this condition is true.

Exercise 4.36 Draw a tree with 10 vertices and label each vertex with a unique integer
from 1 to 10. Construct the Pr¨ufer sequence (Appendix 11.7.6) for the tree. Given the
Pr¨ufer sequence, recreate the tree.

Exercise 4.37 Construct the tree corresponding to the following Pr¨ufer sequences (Ap-
pendix 11.7.6)

1. 113663 (1,2),(1,3),(1,4),(3,5),(3,6),(6,7), and (6,8)

2. 552833226.

Exercise 4.38 What is the expected number of isolated vertices in G(n, p) for p = 1
2

ln n
n ?

146

Exercise 4.39 Theorem 4.17 shows that for some c > 0 and p = c ln n/n, G(n, p) has
diameter O (ln n). Tighten the argument to pin down as low a value as possible for c.

Exercise 4.40 Let f (n) be a function that is asymptotically less than n. Some such
1
3 . Show that

functions are 1/n, a constant d, log n or n

for large n. That is

(cid:16)

1 + f (n)
n

(cid:17)n

(cid:39) ef (n).

(cid:17)n

(cid:16)

1 + f (n)
n
ef (n)

lim
n→∞

= 1.

Exercise 4.41 What is diameter of G(n,p) for various values of p?

Exercise 4.42

1. List ﬁve increasing properties of G (n, p).

2. List ﬁve non increasing properties .

Exercise 4.43 Consider generating the edges of a random graph by ﬂipping two coins,
one with probability p1 of heads and the other with probability p2 of heads. Add the edge
to the graph if either coin comes down heads. What is the value of p for the generated
G(n, p) graph?

p0(n)
p(n) = 0
Exercise 4.44 In the proof of Theorem 4.19, we proved for p0(n) such that lim
n→∞
that G(n, p0) almost surely did not have property Q. Give the symmetric argument that
for any p1(n) such that lim
n→∞

p1(n) = 0, G(n, p1) almost surely has property Q.

p(n)

Exercise 4.45 Consider a model of a random subset N (n, p) of integers {1, 2, . . . n}
where, N (n, p) is the set obtained by independently at random including each of {1, 2, . . . n}
into the set with probability p. Deﬁne what an “increasing property” of N (n, p) means.
Prove that every increasing property of N (n, p) has a threshold.

Exercise 4.46 N (n, p) is a model of a random subset of integers {1, 2, . . . n} where,
N (n, p) is the set obtained by independently at random including each of {1, 2, . . . n} into
the set with probability p. What is the threshold for N (n, p) to contain

1. a perfect square,

2. a perfect cube,

3. an even number,

4. three numbers such that x + y = z ?

147

Exercise 4.47 Explain why the property, that N (n, p) contains the integer 1, has a
threshold. What is the threshold?

Exercise 4.48 Is there a condition such that any property satisfying the condition has a
sharp threshold? For example, is monotonicity such a condition?

Exercise 4.49 The Sudoku game consists of a 9 × 9 array of squares. The array is parti-
tioned into nine 3 × 3 squares. Each small square should be ﬁlled with an integer between
1 and 9 so that each row, each column, and each 3 × 3 square contains exactly one copy
of each integer. Initially the board has some of the small squares ﬁlled in in such a way
that there is exactly one way to complete the assignments of integers to squares. Some
simple rules can be developed to ﬁll in the remaining squares such as if the row and column
containing a square already contain a copy of every integer except one, that integer should
be placed in the square.

Start with a 9 × 9 array of squares with each square containing a number between 1

and 9 such that no row, column, or 3 × 3 square has two copies of any integer.

1. How many integers can you randomly erase and there still be only one way to cor-

rectly ﬁll in the board?

2. Develop a set of simple rules for ﬁlling in squares such as if a row does not contain
a given integer and if every column except one in which the square in the row is
blank contains the integer, then place the integer in the remaining blank entry in the
row. How many integers can you randomly erase and your rules will still completely
ﬁll in the board?

Exercise 4.50 Generalize the Sudoku game for arrays of size n2 × n2. Develop a simple
set of rules for completing the game. An example of a rule is the following. If the a row
does not contain a given integer and if every column except one in which the square in
the row is blank contains the integer, then place the integer in the remaining blank entry
in the row. Start with a legitimate completed array and erase k entries at random.

1. Is there a threshold for the integer k such that if only k entries of the array are

erased, your set of rules will ﬁnd a solution?

2. Experimentally determine k for some large value of n.

Exercise 4.51 Let {xi|1 ≤ i ≤ n}, be a set of indicator variables with identical probability

distributions. Let x =

xi and suppose E (x) → ∞. Show that if the xi are statistically

n
(cid:80)
i=1

independent, then Prob (x = 0) → 0.

Exercise 4.52 In a square n × n grid, each of the O(n2) edges is randomly chosen to
be present with probability p and absent with probability 1 − p. Consider the increasing
property that there is a path from the bottom left corner to the top right corner which
always goes to the right or up. Show that p = 1/2 is a threshold for the property. Is it a
sharp threshold?

148

Exercise 4.53 The threshold property seems to be related to uniform distributions. What
if we considered other distributions? Consider a model where i is selected from the set
{1, 2, . . . , n} with probability c(n)
Is there a threshold for perfect squares? Is there a
i
threshold for arithmetic progressions?

.

Exercise 4.54 Modify the proof that every increasing property of G(n, p) has a threshold
to apply to the 3-CNF satisﬁability problem.

Exercise 4.55 Evaluate (cid:0)1 − 1
2k

(cid:1)2k

for k=3, 5, and 7. How close is it to 1/e?

Exercise 4.56 Randomly generate clauses for a Boolean formula in 3-CNF. Compute
the number of solutions and the number of connected components of the solution set as a
function of the number of clauses generated. What happens?

Exercise 4.57 Consider a random process for generating a Boolean function f in con-
junctive normal form where each of c clauses is generated by placing each of n variables
in the clause with probability p and complementing the variable with probability 1/2. What
is the distribution of clause sizes for various p such as p = 3/n, 1/2, other values? Experi-
mentally determine the threshold value of p for f to cease to be satisﬁed.

Exercise 4.58 For a random 3-CNF formula with n variables and cn clauses, what is
the expected number of satisfying assignments?

Exercise 4.59 Which of the following variants of the SC algorithm admit a theorem like
Theorem 4.21?

1. Among all clauses of least length, pick the ﬁrst one in the order in which they appear

in the formula.

2. Set the literal appearing in most clauses independent of length to 1.

Exercise 4.60 Suppose we have a queue of jobs serviced by one server. There is a total
of n jobs in the system. At time t, each remaining job independently decides to join the
queue to be serviced with probability p = d/n, where d < 1 is a constant. Each job has a
processing time of 1 and at each time the server services one job, if the queue is nonempty.
Show that with high probability, no job waits more than Ω(ln n) time to be serviced once
it joins the queue.

Exercise 4.61 Consider G (n, p).

1. Where is phase transition for 2-colorability? Hint: For p = d/n with d < 1, G(n, p)
is acyclic, so it is bipartite and hence 2-colorable. When pn → ∞, the expected
number of triangles goes to inﬁnity. Show that, almost surely, there is a triangle?
What does this do for 2-colorability?

2. What about 3-colorability?

149

Exercise 4.62 A vertex cover of size k for a graph is a set of k vertices such that one end
of each edge is in the set. Experimentally play with the following problem. For G(n, 1
2),
for what value of k is there a vertex cover of size k?

Exercise 4.63 Consider graph 3-colorability. Randomly generate the edges of a graph
and compute the number of solutions and the number of connected components of the
solution set as a function of the number of edges generated. What happens?

Exercise 4.64 In G(n, p), let xk be the number of connected components of size k. Using
xk, write down the probability that a randomly chosen vertex is in a connected component
of size k. Also write down the expected size of the connected component containing a
randomly chosen vertex.

Exercise 4.65 For p asymptotically greater than 1
∞
(cid:80)
i=0

i(i − 2)λi > 0.

n , show that

Exercise 4.66 Consider generating a random graph adding one edge at a time. Let n(i,t)
be the number of components of size i at time t.

n(1, 1) = n
n(1, t) = 0

t > 1

n(i, t) = n(i, t − 1) +

(cid:88) j(i − j)

n2

n (j, t − 1) n (i − j, t − 1) −

2i
n

n (i)

Compute n(i,t) for a number of values of i and t. What is the behavior? What is the

sum of n(i,t) for ﬁxed t and all i? Can you write a generating function for n(i,t)?

Exercise 4.67 The global clustering coeﬃcient of a graph is deﬁned as follows. Let dv
be the degree of vertex v and let ev be the number of edges connecting vertices adjacent to
vertex v. The global clustering coeﬃcient c is given by

(cid:88)

c =

2ev
dv(dv−1).

v

In a social network, for example, it measures what fraction of pairs of friends of each
person are themselves friends. If many are, the clustering coeﬃcient is high. What is c
for a random graph with p = d
n ? For a denser graph? Compare this value to that for some
social network.

Exercise 4.68 Consider a structured graph, such as a grid or cycle, and gradually add
edges or reroute edges at random. Let L be the average distance between all pairs of
vertices in a graph and let C be the ratio of triangles to connected sets of three vertices.
Plot L and C as a function of the randomness introduced.

150

Exercise 4.69 Consider an n × n grid in the plane.

1. Prove that for any vertex u, there are at least k vertices at distance k for 1 ≤ k ≤

n/2.

2. Prove that for any vertex u, there are at most 4k vertices at distance k.

3. Prove that for one half of the pairs of points, the distance between them is at least

4/4.

Exercise 4.70 Show that in a small-world graph with r ≤ 2, that there exist short paths
with high probability. The proof for r = 0 is in the text.

Exercise 4.71 Change the small worlds graph as follows. Start with a n × n grid where
each vertex has one long-distance edge to a vertex chosen uniformly at random. These are
exactly like the long-distance edges for r = 0. But the grid edges are not present. Instead,
we have some other graph with the property that for each vertex, there are Θ(t2) vertices
at distance t from the vertex for t ≤ n. Show that, almost surely, the diameter is O(ln n).

Exercise 4.72 Given an n node directed graph with two random out edges from each
node. For two vertices s and t chosen at random, prove that there exists a path of length
at most O(ln n) from s to t with high probability.

Exercise 4.73 How does the diameter of a graph consisting of a cycle change as one
adds a few random long distance edges? This question explores how much randomness is
needed to get a small world.

Exercise 4.74 Ideas and diseases spread rapidly in small world graphs. What about
spread of social contagion? A disease needs only one contact and with some probability
transfers. Social contagion needs several contacts. How many vertices must one start with
to spread social contagion, if the spread of contagion requires two adjacent vertices?

Exercise 4.75 How many edges are needed to disconnect a small world graph? By dis-
connect we mean at least two pieces each of reasonable size.
Is this connected to the
emergence of a giant component?

Exercise 4.76 In the small world model, would it help if the algorithm could look at edges
at any node at a cost of one for each node looked at?

Exercise 4.77 Consider the n × n grid in the section on small world graphs.
If the
probability of an edge from vertex u to vertex v is proportional to d−r(u, v), show that the
constant of proportionality cr(u) is

θ(n2−r)
θ(ln n)
θ(1)

for r > 2
for r = 2
for r < 2

151

Exercise 4.78 In the n × n grid prove that for at least half of the pairs of vertices, the
distance between the vertices is greater than or equal to n/4

Exercise 4.79 Show that for r < 2 in the small world graph model that short paths exist
but a polylog length path is unlikely to encounter a long distance edge whose end point is
close to the destination.

Exercise 4.80 Make a list of the ten most interesting things you learned about random
graphs.

152

5 Random Walks and Markov Chains

A random walk on a directed graph consists of a sequence of vertices generated from
a start vertex by selecting an edge, traversing the edge to a new vertex, and repeating
the process. We will see that if the graph is strongly connected, then the fraction of time
the walk spends at the various vertices of the graph converges to a stationary probability
distribution.

Since the graph is directed, there might be vertices with no out edges and hence
nowhere for the walk to go. Vertices in a strongly connected component with no in edges
from the remainder of the graph can never be reached unless the component contains the
start vertex. Once a walk leaves a strongly connected component it can never return.
Most of our discussion of random walks will involve strongly connected graphs.

Start a random walk at a vertex x0 and think of the starting probability distribution
as putting a mass of one on x0 and zero on every other vertex. More generally, one
could start with any probability distribution p, where p is a row vector with nonnegative
components summing to one, with px being the probability of starting at vertex x. The
probability of being at vertex x at time t + 1 is the sum over each adjacent vertex y of
being at y at time t and taking the transition from y to x. Let p(t) be a row vector with
a component for each vertex specifying the probability mass of the vertex at time t and
let p(t+1) be the row vector of probabilities at time t + 1. In matrix notation4

p(t)P = p(t+1)

where the ijth entry of the matrix P is the probability of the walk at vertex i selecting
the edge to vertex j.

A fundamental property of a random walk is that in the limit, the long-term average
probability of being at a particular vertex is independent of the start vertex, or an initial
probability distribution over vertices, provided only that the underlying graph is strongly
connected. The limiting probabilities are called the stationary probabilities. This funda-
mental theorem is proved in the next section.

A special case of random walks, namely random walks on undirected graphs, has
important connections to electrical networks. Here, each edge has a parameter called
conductance, like the electrical conductance, and if the walk is at vertex u, it chooses
the edge from among all edges incident to u to walk to the next vertex with probabilities
proportional to their conductance. Certain basic quantities associated with random walks
are hitting time, the expected time to reach vertex y starting at vertex x, and cover time,
the expected time to visit every vertex. Qualitatively, these quantities are all bounded
above by polynomials in the number of vertices. The proofs of these facts will rely on the

4Probability vectors are represented by row vectors to simplify notation in equations like the one here.

153

random walk

Markov chain

graph
vertex
strongly connected
aperiodic
strongly connected
and aperiodic
undirected graph

stochastic process
state
persistent
aperiodic

ergotic

time reversible

Table 5.1: Correspondence between terminology of random walks and Markov chains

analogy between random walks and electrical networks.

Aspects of the theory of random walks was developed in computer science with an
important application in deﬁning the pagerank of pages on the World Wide Web by their
stationary probability. An equivalent concept called a Markov chain had previously been
developed in the statistical literature. A Markov chain has a ﬁnite set of states. For each
pair of states x and y, there is a transition probability pxy of going from state x to state y
where for each x, (cid:80)
y pxy = 1. A random walk in the Markov chain starts at some state. At
a given time step, if it is in state x, the next state y is selected randomly with probability
pxy. A Markov chain can be represented by a directed graph with a vertex representing
each state and an edge with weight pxy from vertex x to vertex y. We say that the Markov
chain is connected if the underlying directed graph is strongly connected. That is, if there
is a directed path from every vertex to every other vertex. The matrix P consisting of the
pxy is called the transition probability matrix of the chain. The terms “random walk” and
“Markov chain” are used interchangeably. The correspondence between the terminologies
of random walks and Markov chains is given in Table 5.1.

A state of a Markov chain is persistent if it has the property that should the state ever
be reached, the random process will return to it with probability one. This is equivalent
to the property that the state is in a strongly connected component with no out edges.
For most of the chapter, we assume that the underlying directed graph is strongly con-
nected. We discuss here brieﬂy what might happen if we do not have strong connectivity.
Consider the directed graph in Figure 5.1b with three strongly connected components,
A, B, and C. Starting from any vertex in A, there is a nonzero probability of eventually
reaching any vertex in A. However, the probability of returning to a vertex in A is less
than one and thus vertices in A, and similarly vertices in B, are not persistent. From
any vertex in C, the walk eventually will return with probability one to the vertex, since
there is no way of leaving component C. Thus, vertices in C are persistent.

Markov chains are used to model situations where all the information of the system

154

A

A

B

(a)

B

(b)

C

C

Figure 5.1: (a) A directed graph with vertices having no out out edges and a strongly
connected component A with no in edges.
(b) A directed graph with three strongly connected components.

necessary to predict the future can be encoded in the current state. A typical example
is speech, where for a small k the current state encodes the last k syllables uttered by
the speaker. Given the current state, there is a certain probability of each syllable being
uttered next and these can be used to calculate the transition probabilities. Another
example is a gambler’s assets, which can be modeled as a Markov chain where the current
state is the amount of money the gambler has on hand. The model would only be valid
if the gambler’s bets depend only on current assets, not the past.

Later in the chapter, we study the widely used Markov Chain Monte Carlo method
(MCMC). Here, the objective is to sample a large space according to some probability
distribution p. The number of elements in the space may be very large, say 10100. One
designs a Markov chain where states correspond to the elements of the space. The transi-
tion probabilities of the chain are designed so that the stationary probability of the chain
is the probability distribution p with which we want to sample. One samples by taking
a random walk until the probability distribution is close to the stationary distribution of
the chain and then selects the point the walk is at. The walk continues a number of steps
until the probability distribution is no longer dependent on where the walk was when the
ﬁrst element was selected. A second point is then selected, and so on. Although it is
impossible to store the graph in a computer since it has 10100 vertices, to do the walk one
needs only store the vertex the walk is at and be able to generate the adjacent vertices
by some algorithm. What is critical is that the probability of the walk converges to the
stationary probability in time logarithmic in the number of states.

155

We mention two motivating examples. The ﬁrst is to estimate the probability of a
region R in d-space according to a probability density like the Gaussian. Put down a
grid and make each grid point that is in R a state of the Markov chain. Given a proba-
bility density p, design transition probabilities of a Markov chain so that the stationary
distribution is exactly p. In general, the number of states grows exponentially in the di-
mension d, but the time to converge to the stationary distribution grows polynomially in d.

A second example is from physics. Consider an n × n grid in the plane with a particle
at each grid point. Each particle has a spin of ±1. There are 2n2 spin conﬁgurations.
The energy of a conﬁguration is a function of the spins. A central problem in statistical
mechanics is to sample a spin conﬁguration according to their probability. It is easy to
design a Markov chain with one state per spin conﬁguration so that the stationary prob-
ability of a state is proportional to the state’s energy. If a random walk gets close to the
stationary probability in time polynomial to n rather than 2n2, then one can sample spin
conﬁgurations according to their probability.

A quantity called the mixing time, loosely deﬁned as the time needed to get close to
the stationary distribution, is often much smaller than the number of states. In Section
5.8, we relate the mixing time to a combinatorial notion called normalized conductance
and derive good upper bounds on the mixing time in many cases.

5.1 Stationary Distribution

Let p(t) be the probability distribution after t steps of a random walk. Deﬁne the

long-term probability distribution a(t) by

a(t) =

1
t

(cid:0)p(0) + p(1) + · · · + p(t−1)(cid:1) .

The fundamental theorem of Markov chains asserts that the long-term probability distri-
bution of a connected Markov chain converges to a unique limit probability vector, which
we denote by π. Executing one more step, starting from this limit distribution, we get
back the same distribution. In matrix notation, πP = π where P is the matrix of transi-
tion probabilities. In fact, there is a unique probability vector (nonnegative components
summing to one) satisfying πP = π and this vector is the limit. Also since one step does
not change the distribution, any number of steps would not either. For this reason, π is
called the stationary distribution.

Before proving the fundamental theorem of Markov chains, we ﬁrst prove a technical

lemma.

Lemma 5.1 Let P be the transition probability matrix for a connected Markov chain.
The n × (n + 1) matrix A = [P − I , 1] obtained by augmenting the matrix P − I with an
additional column of ones has rank n.

156

Proof: If the rank of A = [P − I, 1] was less than n there would be two linearly indepen-
dent solutions to Ax = 0. Each row in P sums to one so each row in P − I sums to zero.
Thus x = (1, 0), where all but the last coordinate of x is 1, is one solution to Ax = 0.
Assume there was a second solution (x, α) perpendicular to (1, 0). Then (P −I)x+α1 = 0
or xi = (cid:80)
j pijxj + α. Each xi is a convex combination of some xj plus α. Let S be the set
of i for which xi attains its maximum value. ¯S is not empty since x is perpendicular to 1
and hence (cid:80)
j xj = 0. Connectedness implies that some xk of maximum value is adjacent
to some xl of lower value. Thus, xk > (cid:80)
j pkjxj. Therefore α must be greater than 0 in
xk = (cid:80)

j pkjxj + α..

A symmetric argument with T the set of i with xi taking its minimum value implies

α < 0 producing a contradiction thereby proving the lemma.

Theorem 5.2 (Fundamental Theorem of Markov Chains) For a connected Markov
chain there is a unique probability vector π satisfying πP = π. Moreover, for any starting
distribution, lim
t→∞

a(t) exists and equals π.

Proof: Note that a(t) is itself a probability vector, since its components are nonnegative
and sum to 1. Run one step of the Markov chain starting with distribution a(t); the
distribution after the step is a(t)P . Calculate the change in probabilities due to this step.

a(t)P − a(t) =

=

=

1
t
1
t
1
t

(cid:2)p(0)P + p(1)P + · · · + p(t−1)P (cid:3) −

(cid:2)p(1) + p(2) + · · · + p(t)(cid:3) −

1
t

(cid:0)p(t) − p(0)(cid:1) .

(cid:2)p(0) + p(1) + · · · + p(t−1)(cid:3)

1
t

(cid:2)p(0) + p(1) + · · · + p(t−1)(cid:3)

Thus, b(t) = a(t)P − a(t) satisﬁes |b(t)| ≤ 2

t → 0, as t → ∞.

By Lemma 5.1 above, A has rank n. The n × n submatrix B of A consisting of all
its columns except the ﬁrst is invertible. Let c(t) be obtained from b(t) by removing the
ﬁrst entry. Then, a(t)B = [c(t), 1] and so a(t) = [c(t) , 1]B−1 → [0 , 1]B−1. We have the
theorem with π = [0 , 1]B−1.

Observe that the expected time rx for a Markov chain starting in state x to return to
state x is the reciprocal of the stationary probability of x. That is rx = 1
. Intuitively
πx
this follows by observing that if a long walk always returns to state x in exactly rx steps,
the frequency of being in a state x would be 1
. A rigorous proof requires the Strong Law
rx
of Large Numbers.

We ﬁnish this section with the following lemma useful in establishing that a probability
distribution is the stationary probability distribution for a random walk on a connected
graph with edge probabilities.

157

Lemma 5.3 For a random walk on a strongly connected graph with probabilities on the
edges, if the vector π satisﬁes πxpxy = πypyx for all x and y and (cid:80)
x πx = 1, then π is
the stationary distribution of the walk.

Proof: Since π satisﬁes πxpxy = πypyx, take the sum of both sides to get πx = (cid:80)

πypyx

y

and hence π satisﬁes π = πP. By Theorem 5.2, π is the unique stationary probability.

5.2 Electrical Networks and Random Walks

In the next few sections, we study the relationship between electrical networks and
random walks on undirected graphs. The graphs have nonnegative weights on each edge.
A step is executed by picking a random edge from the current vertex with probability
proportional to the edge’s weight and traversing the edge.

An electrical network is a connected, undirected graph in which each edge (x, y) has
a resistance rxy > 0. In what follows, it is easier to deal with conductance deﬁned as the
reciprocal of resistance, cxy = 1
, rather than resistance. Associated with an electrical
rxy
network is a random walk on the underlying graph deﬁned by assigning a probability
pxy = cxy
to the edge (x, y) incident to the vertex x, where the normalizing constant cx
cx
equals (cid:80)
cxy. Note that although cxy equals cyx, the probabilities pxy and pyx may not be

y

equal due to the normalization required to make the probabilities at each vertex sum to
one. We shall soon see that there is a relationship between current ﬂowing in an electrical
network and a random walk on the underlying graph.

Since we assume that the undirected graph is connected, by Theorem 5.2 there is
a unique stationary probability distribution.The stationary probability distribution is π
where πx = cx
cx. To see this, for all x and y
c0

where c0 = (cid:80)

x

πxpxy =

cx
c0

cxy
cx

=

cxy
c0

=

cy
c0

cyx
cy

= πypyx

and hence by Lemma 5.3, π is the unique stationary probability.

Harmonic functions

Harmonic functions are useful in developing the relationship between electrical net-
works and random walks on undirected graphs. Given an undirected graph, designate
a nonempty set of vertices as boundary vertices and the remaining vertices as interior
vertices. A harmonic function g on the vertices is one in which the value of the function
at the boundary vertices is ﬁxed to some boundary condition and the value of g at any
interior vertex x is a weighted average of the values at all the adjacent vertices y, with

158

6

1

8

1

6

5

4

5

8

5

3

5

3

Graph with boundary vertices
dark and boundary conditions
speciﬁed.

Values of harmonic function
satisfying boundary conditions

Figure 5.2: Graph illustrating an harmonic function.

weights pxy satisfying (cid:80)
set of weights pxy satisfying (cid:80)

y pxy = 1 for each x. Thus, if at every interior vertex x for some

gypxy, then g is an harmonic function.

y pxy = 1, gx = (cid:80)

y

Example: Convert an electrical network with conductances cxy to a weighted, undirected
graph with probabilities pxy. Let f be a function satisfying f P = f where P is the matrix
of probabilities. It follows that the function gx = fx
cx

is harmonic.

gx = fx
cx

= 1
cx

= 1
cx

(cid:80)
y

fy

(cid:80)
y

cxy
cy

fypyx = 1
cx

(cid:80)
y

fy

cyx
cy

= (cid:80)

y

fy
cy

cxy
cx

= (cid:80)

gypxy

y

A harmonic function on a connected graph takes on its maximum and minimum on
the boundary. Suppose the maximum does not occur on the boundary. Let S be the
set of interior vertices at which the maximum value is attained. Since S contains no
boundary vertices, ¯S is nonempty. Connectedness implies that there is at least one edge
(x, y) with x ∈ S and y ∈ ¯S. The value of the function at x is the average of the value at
its neighbors, all of which are less than or equal to the value at x and the value at y is
strictly less, a contradiction. The proof for the minimum value is identical.

There is at most one harmonic function satisfying a given set of equations and bound-
ary conditions. For suppose there were two solutions, f (x) and g(x). The diﬀerence of two
solutions is itself harmonic. Since h(x) = f (x)−g(x) is harmonic and has value zero on the
boundary, by the min and max principles it has value zero everywhere. Thus f (x) = g(x).

159

The analogy between electrical networks and random walks

There are important connections between electrical networks and random walks on
undirected graphs. Choose two vertices a and b. For reference purposes let the voltage
vb equal zero. Attach a current source between a and b so that the voltage va equals
one. Fixing the voltages at va and vb induces voltages at all other vertices along with a
current ﬂow through the edges of the network. The analogy between electrical networks
and random walks is the following. Having ﬁxed the voltages at the vertices a and b, the
voltage at an arbitrary vertex x equals the probability of a random walk starting at x
reaching a before reaching b. If the voltage va is adjusted so that the current ﬂowing into
vertex a corresponds to one walk, then the current ﬂowing through an edge is the net
frequency with which a random walk from a to b traverses the edge.

Probabilistic interpretation of voltages

Before showing that the voltage at an arbitrary vertex x equals the probability of a
random walk starting at x reaching a before reaching b, we ﬁrst show that the voltages
form a harmonic function. Let x and y be adjacent vertices and let ixy be the current
ﬂowing through the edge from x to y. By Ohm’s law,

ixy =

vx − vy
rxy

= (vx − vy)cxy.

By Kirchhoﬀ’s law the currents ﬂowing out of each vertex sum to zero.

(cid:88)

y

ixy = 0

Replacing currents in the above sum by the voltage diﬀerence times the conductance
yields

(cid:88)

(vx − vy)cxy = 0

or

y

(cid:88)

vx

cxy =

(cid:88)

vycxy.

y

y

Observing that (cid:80)
vx = (cid:80)

y

cxy = cx and that pxy = cxy
cx

, yields vxcx = (cid:80)

vypxycx. Hence,

y

vypxy. Thus, the voltage at each vertex x is a weighted average of the volt-

y

ages at the adjacent vertices. Hence the voltages form a harmonic function with {a, b} as
the boundary.

Let px be the probability that a random walk starting at vertex x reaches a before b.
Clearly pa = 1 and pb = 0. Since va = 1 and vb = 0, it follows that pa = va and pb = vb.

160

Furthermore, the probability of the walk reaching a from x before reaching b is the sum
over all y adjacent to x of the probability of the walk going from x to y in the ﬁrst step
and then reaching a from y before reaching b. That is

px =

(cid:88)

y

pxypy.

Hence, px is the same harmonic function as the voltage function vx and v and p satisfy the
same boundary conditions at a and b.. Thus, they are identical functions. The probability
of a walk starting at x reaching a before reaching b is the voltage vx.

Probabilistic interpretation of current

In a moment, we will set the current into the network at a to have a value which we will
equate with one random walk. We will then show that the current ixy is the net frequency
with which a random walk from a to b goes through the edge xy before reaching b. Let
ux be the expected number of visits to vertex x on a walk from a to b before reaching b.
Clearly ub = 0. Every time the walk visits x, x not equal to a, it must come to x from
some vertex y. Thus, the number of visits to x before reaching b is the sum over all y of
the number of visits uy to y before reaching b times the probability pyx of going from y
to x. For x not equal to b or a

ux =

uypyx.

(cid:88)

y(cid:54)=b

Since ub = 0 and cxpxy = cypyx

(cid:88)

ux =

and hence ux
cx

= (cid:80)

y

all y
pxy. It follows that ux
cx

uy
cy

uy

cxpxy
cy

is harmonic with a and b as the boundary

. Now ux
cx

where the boundary conditions are ub = 0 and ua equals some ﬁxed value. Now, ub
= 0.
cb
Setting the current into a to one, ﬁxed the value of va. Adjust the current into a so that
va equals ua
and vx satisfy the same harmonic conditions and thus are the same
ca
harmonic function. Let the current into a correspond to one walk. Note that if the walk
starts at a and ends at b, the expected value of the diﬀerence between the number of times
the walk leaves a and enters a must be one. This implies that the amount of current into
a corresponds to one walk.

Next we need to show that the current ixy is the net frequency with which a random

walk traverses edge xy.

ixy = (vx − vy)cxy =

(cid:19)

(cid:18) ux
cx

−

uy
cy

cxy = ux

cxy
cx

− uy

cxy
cy

= uxpxy − uypyx

The quantity uxpxy is the expected number of times the edge xy is traversed from x to y
and the quantity uypyx is the expected number of times the edge xy is traversed from y to

161

x. Thus, the current ixy is the expected net number of traversals of the edge xy from x to y.

Eﬀective resistance and escape probability

Set va = 1 and vb = 0. Let ia be the current ﬂowing into the network at vertex a and
out at vertex b. Deﬁne the eﬀective resistance ref f between a and b to be ref f = va
and
ia
the eﬀective conductance cef f to be cef f = 1
. Deﬁne the escape probability, pescape, to
ref f
be the probability that a random walk starting at a reaches b before returning to a. We
now show that the escape probability is cef f
. For convenience, assume that a and b are
ca
not adjacent. A slight modiﬁcation of our argument suﬃces for the case when a and b are
adjacent.

(cid:88)

ia =

(va − vy)cay

Since va = 1,

y

(cid:88)

ia =

cay − ca

y

(cid:34)

= ca

1 −

(cid:88)

y

(cid:88)

y

vy

cay
ca

(cid:35)

payvy

.

For each y adjacent to the vertex a, pay is the probability of the walk going from vertex
a to vertex y. Earlier we showed that vy is the probability of a walk starting at y going
to a before reaching b. Thus, (cid:80)
payvy is the probability of a walk starting at a returning
to a before reaching b and 1 − (cid:80)

payvy is the probability of a walk starting at a reaching

y

b before returning to a. Thus, ia = capescape. Since va = 1 and cef f = ia
va
cef f = ia . Thus, cef f = capescape and hence pescape = cef f
ca

.

, it follows that

y

For a ﬁnite connected graph the escape probability will always be nonzero. Now
consider an inﬁnite graph such as a lattice and a random walk starting at some vertex
a. Form a series of ﬁnite graphs by merging all vertices at distance d or greater from a
into a single vertex b for larger and larger values of d. The limit of pescape as d goes to
inﬁnity is the probability that the random walk will never return to a. If pescape → 0, then
eventually any random walk will return to a. If pescape → q where q > 0, then a fraction
of the walks never return. Thus, the escape probability terminology.

5.3 Random Walks on Undirected Graphs with Unit Edge Weights

We now focus our discussion on random walks on undirected graphs with uniform
edge weights. At each vertex, the random walk is equally likely to take any edge. This
corresponds to an electrical network in which all edge resistances are one. Assume the
graph is connected. We consider questions such as what is the expected time for a random

162

walk starting at a vertex x to reach a target vertex y, what is the expected time until the
random walk returns to the vertex it started at, and what is the expected time to reach
every vertex?

Hitting time

The hitting time hxy, sometimes called discovery time, is the expected time of a ran-
dom walk starting at vertex x to reach vertex y. Sometimes a more general deﬁnition is
given where the hitting time is the expected time to reach a vertex y from a given starting
probability distribution.

One interesting fact is that adding edges to a graph may either increase or decrease
hxy depending on the particular situation. Adding an edge can shorten the distance from
x to y thereby decreasing hxy or the edge could increase the probability of a random walk
going to some far oﬀ portion of the graph thereby increasing hxy. Another interesting
fact is that hitting time is not symmetric. The expected time to reach a vertex y from a
vertex x in an undirected graph may be radically diﬀerent from the time to reach x from y.

We start with two technical lemmas. The ﬁrst lemma states that the expected time

to traverse a path of n vertices is Θ (n2).

Lemma 5.4 The expected time for a random walk starting at one end of a path of n
vertices to reach the other end is Θ (n2).

Proof: Consider walking from vertex 1 to vertex n in a graph consisting of a single path
of n vertices. Let hij, i < j, be the hitting time of reaching j starting from i. Now h12 = 1
and

hi,i+1 = 1

2 + 1

2(1 + hi−1,i+1) = 1 + 1

2 (hi−1,i + hi,i+1)

2 ≤ i ≤ n − 1.

Solving for hi,i+1 yields the recurrence

hi,i+1 = 2 + hi−1,i.

Solving the recurrence yields

hi,i+1 = 2i − 1.
To get from 1 to n, go from 1 to 2, 2 to 3, etc. Thus

h1,n =

n−1
(cid:88)

i=1

hi,i+1 =

n−1
(cid:88)

i=1

(2i − 1)

n−1
(cid:88)

n−1
(cid:88)

1

i −

= 2

i=1

i=1
n (n − 1)
2

− (n − 1)

= 2

= (n − 1)2 .

163

The lemma says that in a random walk on a line where we are equally likely to take
one step to the right or left each time, the farthest we will go away from the start in n
steps is Θ(

n).

√

The next lemma shows that the expected time spent at vertex i by a random walk

from vertex 1 to vertex n in a chain of n vertices is 2(i − 1) for 2 ≤ i ≤ n − 1.

Lemma 5.5 Consider a random walk from vertex 1 to vertex n in a chain of n vertices.
Let t(i) be the expected time spent at vertex i. Then

t (i) =






i = 1
n − 1
2 (n − i) 2 ≤ i ≤ n − 1
1

i = n.

Proof: Now t (n) = 1 since the walk stops when it reaches vertex n. Half of the time when
the walk is at vertex n − 1 it goes to vertex n. Thus t (n − 1) = 2. For 3 ≤ i < n − 1,
t (i) = 1
2t (2) + 1 and t (2) =
t (1) + 1

2 [t (i − 1) + t (i + 1)] and t (1) and t (2) satisfy t (1) = 1
2t (3). Solving for t(i + 1) for 3 ≤ i < n − 1 yields

t(i + 1) = 2t(i) − t(i − 1)

which has solution t(i) = 2(n − i) for 3 ≤ i < n − 1. Then solving for t(2) and t(1) yields
t (2) = 2 (n − 2) and t (1) = n − 1. Thus, the total time spent at vertices is

n − 1 + 2 (1 + 2 + · · · + n − 2) + 1 = (n − 1) + 2

(n − 1)(n − 2)
2

+ 1 = (n − 1)2 + 1

which is one more than h1n and thus is correct.

Adding edges to a graph might either increase or decrease the hitting time hxy. Con-
sider the graph consisting of a single path of n vertices. Add edges to this graph to get the
graph in Figure 5.3 consisting of a clique of size n/2 connected to a path of n/2 vertices.
Then add still more edges to get a clique of size n. Let x be the vertex at the midpoint of
the original path and let y be the other endpoint of the path consisting of n/2 vertices as
shown in the ﬁgure. In the ﬁrst graph consisting of a single path of length n, hxy = Θ (n2).
In the second graph consisting of a clique of size n/2 along with a path of length n/2,
hxy = Θ (n3). To see this latter statement, note that starting at x, the walk will go down
the path towards y and return to x n/2 times on average before reaching y for the ﬁrst
time. Each time the walk in the path returns to x, with probability (n/2 − 1)/(n/2) it
enters the clique and thus on average enters the clique Θ(n) times before starting down
the path again. Each time it enters the clique, it spends Θ(n) time in the clique before
returning to x. Thus, each time the walk returns to x from the path it spends Θ(n2) time
in the clique before starting down the path towards y for a total expected time that is

164

clique of
size n/2

x

(cid:124)

(cid:123)(cid:122)
n/2

y

(cid:125)

Figure 5.3: Illustration that adding edges to a graph can either increase or decrease hitting
time.

Θ(n3) before reaching y. In the third graph, which is the clique of size n, hxy = Θ (n).
Thus, adding edges ﬁrst increased hxy from n2 to n3 and then decreased it to n.

Hitting time is not symmetric even in the case of undirected graphs. In the graph of
Figure 5.3, the expected time, hxy, of a random walk from x to y, where x is the vertex of
attachment and y is the other end vertex of the chain, is Θ(n3). However, hyx is Θ(n2).

Commute time

The commute time, commute(x, y), is the expected time of a random walk starting at
x reaching y and then returning to x. So commute(x, y) = hxy + hyx. Think of going
from home to oﬃce and returning home. We now relate the commute time to an electrical
quantity, the eﬀective resistance. The eﬀective resistance between two vertices x and y in
an electrical network is the voltage diﬀerence between x and y when one unit of current
is inserted at vertex x and withdrawn from vertex y.

Theorem 5.6 Given an undirected graph, consider the electrical network where each edge
of the graph is replaced by a one ohm resistor. Given vertices x and y, the commute time,
commute(x, y), equals 2mrxy where rxy is the eﬀective resistance from x to y and m is the
number of edges in the graph.

Proof: Insert at each vertex i a current equal to the degree di of vertex i. The total
current inserted is 2m where m is the number of edges. Extract from a speciﬁc vertex j
all of this 2m current. Let vij be the voltage diﬀerence from i to j. The current into i
divides into the di resistors at vertex i. The current in each resistor is proportional to the
voltage across it. Let k be a vertex adjacent to i. Then the current through the resistor
between i and k is vij − vkj, the voltage drop across the resister. The sum of the currents
out of i through the resisters must equal di, the current injected into i.

di =

(cid:88)

k adj
to i

(vij − vkj) = divij −

vkj.

(cid:88)

k adj
to i

165

Solving for vij

vij = 1 +

(cid:88)

k adj
to i

1
di

vkj =

(cid:88)

k adj
to i

1
di

(1 + vkj).

(5.1)

Now the hitting time from i to j is the average time over all paths from i to k adjacent

to i and then on from k to j. This is given by

hij =

(cid:88)

k adj
to i

1
di

(1 + hkj).

(5.2)

Subtracting (5.2) from (5.1), gives vij −hij = (cid:80)

1
di

(vkj − hkj). Thus, the function vij −hij

k adj
to i

is harmonic. Designate vertex j as the only boundary vertex. The value of vij − hij at
i = j, namely vjj − hjj, is zero, since both vjj and hjj are zero. So the function vij − hij
must be zero everywhere. Thus, the voltage vij equals the expected time hij from i to j.

To complete the proof, note that hij = vij is the voltage from i to j when currents are
inserted at all vertices in the graph and extracted at vertex j. If the current is extracted
from i instead of j, then the voltages change and vji = hji in the new setup. Finally,
reverse all currents in this latter step. The voltages change again and for the new voltages
−vji = hji. Since −vji = vij, we get hji = vij.

Thus, when a current is inserted at each vertex equal to the degree of the vertex
and the current is extracted from j, the voltage vij in this set up equals hij. When we
extract the current from i instead of j and then reverse all currents, the voltage vij in
this new set up equals hji. Now, superpose both situations, i.e., add all the currents and
voltages. By linearity, for the resulting vij, which is the sum of the other two vij’s, is
vij = hij + hji. All currents cancel except the 2m amps injected at i and withdrawn at j.
Thus, 2mrij = vij = hij + hji = commute(i, j) or commute(i, j) = 2mrij where rij is the
eﬀective resistance from i to j.

The following corollary follows from Theorem 5.6 since the eﬀective resistance ruv is

less than or equal to one when u and v are connected by an edge.

Corollary 5.7 If vertices x and y are connected by an edge, then hxy + hyx ≤ 2m where
m is the number of edges in the graph.

Proof: If x and y are connected by an edge, then the eﬀective resistance rxy is less than
or equal to one.

166

↓

↓

i

↑

j

↑

=⇒

↑

↑

Insert current at each vertex
equal to degree of vertex.
Extract 2m at vertex j.
vij = hij
(a)

=⇒

i

↓

↑

↑

j

↓

↓

↓

Reverse currents in (b).
For new voltages −vji = hji.
Since −vji = vij, hji = vij.
(c)

⇐=

i

↑

↓

↑

↓

↑

j

↑

Extract current from i instead of j.
For new voltages vji = hji.
(b)

i

2m
=⇒

j

2m
=⇒

Superpose currents in (a) and (c).
2mrij = vij = hij + hji = commute(i, j)
(d)

Figure 5.4: Illustration of proof that commute(x, y) = 2mrxy where m is the number of
edges in the undirected graph and rxy is the eﬀective resistance between x and y.

Corollary 5.8 For vertices x and y in an n vertex graph, the commute time, commute(x, y),
is less than or equal to n3.

Proof: By Theorem 5.6 the commute time is given by the formula commute(x, y) =
2mrxy where m is the number of edges. In an n vertex graph there exists a path from
x to y of length at most n. This implies rxy ≤ n since the resistance can not be greater
(cid:1)
than that of any path from x to y. Since the number of edges is at most (cid:0)n

2

commute(x, y) = 2mrxy ≤ 2

(cid:18)n
2

(cid:19)

n ∼= n3.

Again adding edges to a graph may increase or decrease the commute time. To see
this, consider the graph consisting of a chain of n vertices, the graph of Figure 5.3, and
the clique on n vertices.

Cover time

The cover time, cover(x, G) , is the expected time of a random walk starting at vertex x
in the graph G to reach each vertex at least once. We write cover(x) when G is understood.

167

The cover time of an undirected graph G, denoted cover(G), is

cover(G) = max

x

cover(x, G).

For cover time of an undirected graph, increasing the number of edges in the graph
may increase or decrease the cover time depending on the situation. Again consider three
graphs, a chain of length n which has cover time Θ(n2), the graph in Figure 5.3 which has
cover time Θ(n3), and the complete graph on n vertices which has cover time Θ(n log n).
Adding edges to the chain of length n to create the graph in Figure 5.3 increases the
cover time from n2 to n3 and then adding even more edges to obtain the complete graph
reduces the cover time to n log n.

Note: The cover time of a clique is θ(n log n) since this is the time to select every
integer out of n integers with high probability, drawing integers at random. This is called
the coupon collector problem. The cover time for a straight line is Θ(n2) since it is the
same as the hitting time. For the graph in Figure 5.3, the cover time is Θ(n3) since one
takes the maximum over all start states and cover(x, G) = Θ (n3) where x is the vertex
of attachment.

Theorem 5.9 Let G be a connected graph with n vertices and m edges. The time for a
random walk to cover all vertices of the graph G is bounded above by 4m(n − 1).

Proof: Consider a depth ﬁrst search of the graph G starting from some vertex z and let
T be the resulting depth ﬁrst search spanning tree of G. The depth ﬁrst search covers
every vertex. Consider the expected time to cover every vertex in the order visited by the
depth ﬁrst search. Clearly this bounds the cover time of G starting from vertex z. Note
that each edge in T is traversed twice, once in each direction.

cover (z, G) ≤

(cid:88)

hxy.

(x,y)∈T
(y,x)∈T

If (x, y) is an edge in T , then x and y are adjacent and thus Corollary 5.7 implies hxy ≤
2m. Since there are n − 1 edges in the dfs tree and each edge is traversed twice, once
in each direction, cover(z) ≤ 4m(n − 1). This holds for all starting vertices z. Thus,
cover(G) ≤ 4m(n − 1)

The theorem gives the correct answer of n3 for the n/2 clique with the n/2 tail. It

gives an upper bound of n3 for the n-clique where the actual cover time is n log n.

Let rxy be the eﬀective resistance from x to y. Deﬁne the resistance ref f (G) of a graph

G by ref f (G) = max
x,y

(rxy).

168

Theorem 5.10 Let G be an undirected graph with m edges. Then the cover time for G
is bounded by the following inequality

mref f (G) ≤ cover(G) ≤ 2e3mref f (G) ln n + n

where e=2.71 is Euler’s constant and ref f (G) is the resistance of G.

Proof: By deﬁnition ref f (G) = max
x,y

(rxy). Let u and v be the vertices of G for which

rxy is maximum. Then ref f (G) = ruv. By Theorem 5.6, commute(u, v) = 2mruv. Hence
mruv = 1
2commute(u, v). Clearly the commute time from u to v and back to u is less
than twice the max(huv, hvu) and max(huv, hvu) is clearly less than the cover time of G.
Putting these facts together gives the ﬁrst inequality in the theorem.

mref f (G) = mruv = 1

2commute(u, v) ≤ max(huv, hvu) ≤ cover(G)

For the second inequality in the theorem, by Theorem 5.6, for any x and y, commute(x, y)

equals 2mrxy which is less than or equal to 2mref f (G), implying hxy ≤ 2mref f (G). By
the Markov inequality, since the expected time to reach y starting at any x is less than
2mref f (G), the probability that y is not reached from x in 2mref f (G)e3 steps is at most
1
e3 . Thus, the probability that a vertex y has not been reached in 2e3mref f (G) log n steps
is at most 1
n3 because a random walk of length 2e3mr(G) log n is a sequence of
e3
log n independent random walks, each of length 2e3mr(G)ref f (G). Suppose after a walk
of 2e3mref f (G) log n steps, vertices v1, v2, . . . , vl had not been reached. Walk until v1 is
reached, then v2, etc. By Corollary 5.8 the expected time for each of these is n3, but since
each happens only with probability 1/n3, we eﬀectively take O(1) time per vi, for a total
time at most n. More precisely,

ln n = 1

cover(G) ≤ 2e3mref f (G) log n +

≤ 2e3mref f (G) log n +

(cid:88)

v
(cid:88)

v

Prob (cid:0)v was not visited in the ﬁrst 2e3mref f (G) steps(cid:1) n3

1
n3 n3 ≤ 2e3mref f (G) + n.

5.4 Random Walks in Euclidean Space

Many physical processes such as Brownian motion are modeled by random walks.
Random walks in Euclidean d-space consisting of ﬁxed length steps parallel to the coor-
dinate axes are really random walks on a d-dimensional lattice and are a special case of
random walks on graphs. In a random walk on a graph, at each time unit an edge from
the current vertex is selected at random and the walk proceeds to the adjacent vertex.
We begin by studying random walks on lattices.

Random walks on lattices

169

We now apply the analogy between random walks and current to lattices. Consider
a random walk on a ﬁnite segment −n, . . . , −1, 0, 1, 2, . . . , n of a one dimensional lattice
starting from the origin. Is the walk certain to return to the origin or is there some prob-
ability that it will escape, i.e., reach the boundary before returning? The probability of
reaching the boundary before returning to the origin is called the escape probability. We
shall be interested in this quantity as n goes to inﬁnity.

Convert the lattice to an electrical network by replacing each edge with a one ohm
resister. Then the probability of a walk starting at the origin reaching n or –n before
returning to the origin is the escape probability given by

pescape =

cef f
ca

where cef f is the eﬀective conductance between the origin and the boundary points and ca
is the sum of the conductance’s at the origin. In a d-dimensional lattice, ca = 2d assuming
that the resistors have value one. For the d-dimensional lattice

pescape =

1
2d ref f

In one dimension, the electrical network is just two series connections of n one ohm re-
sistors connected in parallel. So as n goes to inﬁnity, ref f goes to inﬁnity and the escape
probability goes to zero as n goes to inﬁnity. Thus, the walk in the unbounded one dimen-
sional lattice will return to the origin with probability one. This is equivalent to ﬂipping
a balanced coin and keeping tract of the number of heads minus the number of tails. The
count will return to zero inﬁnitely often. By the law of large numbers in n steps with
high probability the walk will be within

n distance of the origin.

√

Two dimensions

For the 2-dimensional lattice, consider a larger and larger square about the origin for
the boundary as shown in Figure 5.5a and consider the limit of ref f as the squares get
larger. Shorting the resistors on each square can only reduce ref f . Shorting the resistors
results in the linear network shown in Figure 5.5b. As the paths get longer, the number
of resistors in parallel also increases. The resistor between vertex i and i + 1 is really
4(2i + 1) unit resistors in parallel. The eﬀective resistance of 4(2i + 1) resistors in parallel
is 1/4(2i + 1). Thus,

ref f ≥ 1

4 + 1

12 + 1

20 + · · · = 1

4(1 + 1

3 + 1

5 + · · · ) = Θ(ln n).

Since the lower bound on the eﬀective resistance and hence the eﬀective resistance goes
to inﬁnity, the escape probability goes to zero for the 2-dimensional lattice.

Three dimensions

170

0

1

2

3

4
20
12
Number of resistors
in parallel

(a)

(b)

Figure 5.5: 2-dimensional lattice along with the linear network resulting from shorting
resistors on the concentric squares about the origin.

In three dimensions, the resistance along any path to inﬁnity grows to inﬁnity but
the number of paths in parallel also grows to inﬁnity. It turns out there are a suﬃcient
number of paths that ref f remains ﬁnite and thus there is a nonzero escape probability.
We will prove this now. First note that shorting any edge decreases the resistance, so
we do not use shorting in this proof, since we seek to prove an upper bound on the
resistance. Instead we remove some edges, which increases their resistance to inﬁnity and
hence increases the eﬀective resistance, giving an upper bound. To simplify things we
consider walks on on quadrant rather than the full grid. The resistance to inﬁnity derived
from only the quadrant is an upper bound on the resistance of the full grid.

The construction used in three dimensions is easier to explain ﬁrst in two dimensions.
Draw dotted diagonal lines at x + y = 2n − 1. Consider two paths that start at the origin.
One goes up and the other goes to the right. Each time a path encounters a dotted
diagonal line, split the path into two, one which goes right and the other up. Where
two paths cross, split the vertex into two, keeping the paths separate. By a symmetry
argument, splitting the vertex does not change the resistance of the network. Remove
all resistors except those on these paths. The resistance of the original network is less
than that of the tree produced by this process since removing a resistor is equivalent to
increasing its resistance to inﬁnity.

The distances between splits increase and are 1, 2, 4, etc. At each split the number
of paths in parallel doubles. See Figure 5.7. Thus, the resistance to inﬁnity in this two
dimensional example is

1
2

+

1
4

2 +

1
8

4 + · · · =

1
2

+

1
2

+

1
2

+ · · · = ∞.

171

y

7

3

1

1

3

7

x

Figure 5.6: Paths in a 2-dimensional lattice obtained from the 3-dimensional construction
applied in 2-dimensions.

In the analogous three dimensional construction, paths go up, to the right, and out of
the plane of the paper. The paths split three ways at planes given by x + y + z = 2n − 1.
Each time the paths split the number of parallel segments triple. Segments of the paths
between splits are of length 1, 2, 4, etc. and the resistance of the segments are equal to
the lengths. The resistance out to inﬁnity for the tree is

1

3 + 1

92 + 1

274 + · · · = 1

3

(cid:0)1 + 2

3 + 4

9 + · · ·(cid:1) = 1

3

= 1

1

1−

2
3

The resistance of the three dimensional lattice is less. It is important to check that the
paths are edge-disjoint and so the tree is a subgraph of the lattice. Going to a subgraph is
equivalent to deleting edges which only increases the resistance. That is why the resistance
of the lattice is less than that of the tree. Thus, in three dimensions the escape probability
is nonzero. The upper bound on ref f gives the lower bound

pescape = 1
2d

1
ref f

≥ 1
6.

172

1

2

4

Figure 5.7: Paths obtained from 2-dimensional lattice. Distances between splits double
as do the number of parallel paths.

A lower bound on ref f gives an upper bound on pescape. To get the upper bound on

pescape, short all resistors on surfaces of boxes at distances 1, 2, 3,, etc. Then
(cid:2)1 + 1

25 + · · ·(cid:3) ≥ 1.23

ref f ≥ 1
6

6 ≥ 0.2

9 + 1

This gives

pescape = 1
2d

1
ref f

≤ 5
6.

5.5 The Web as a Markov Chain

A modern application of random walks on directed graphs comes from trying to es-
tablish the importance of pages on the World Wide Web. One way to do this would be
to take a random walk on the web viewed as a directed graph with an edge correspond-
ing to each hypertext link and rank pages according to their stationary probability. A
connected, undirected graph is strongly connected in that one can get from any vertex to
any other vertex and back again. Often the directed case is not strongly connected. One
diﬃculty occurs if there is a vertex with no out edges. When the walk encounters this
vertex the walk disappears. Another diﬃculty is that a vertex or a strongly connected
component with no in edges is never reached. One way to resolve these diﬃculties is to
introduce a random restart condition. At each step, with some probability r, jump to a
vertex selected uniformly at random and with probability 1 − r select an edge at random
and follow it. If a vertex has no out edges, the value of r for that vertex is set to one.
This has the eﬀect of converting the graph to a strongly connected graph so that the
stationary probabilities exist.

Page rank and hitting time

The page rank of a vertex in a directed graph is the stationary probability of the vertex,
where we assume a positive restart probability of say r = 0.15. The restart ensures that
the graph is strongly connected. The page rank of a page is the fractional frequency with
which the page will be visited over a long period of time.
If the page rank is p, then
the expected time between visits or return time is 1/p. Notice that one can increase the
pagerank of a page by reducing the return time and this can be done by creating short
cycles.

173

1
20.85πi

pji

j

i

1
20.85πi

0.15πj

0.15πi

πi = 0.85πjpji + 0.85

2 πi

πi = 1.48πjpji

Figure 5.8: Impact on page rank of adding a self loop

Consider a vertex i with a single edge in from vertex j and a single edge out. The

stationary probability π satisﬁes πP = π, and thus

Adding a self-loop at i, results in a new equation

πi = πjpji.

or

πi = πjpji +

1
2

πi

πi = 2 πjpji.

Of course, πj would have changed too, but ignoring this for now, pagerank is doubled by
the addition of a self-loop. Adding k self loops, results in the equation

πi = πjpji +

k
k + 1

πi,

and again ignoring the change in πj, we now have πi = (k + 1)πjpji. What prevents
one from increasing the page rank of a page arbitrarily? The answer is the restart. We
neglected the 0.15 probability that is taken oﬀ for the random restart. With the restart
taken into account, the equation for πi when there is no self-loop is

whereas, with k self-loops, the equation is

πi = 0.85πjpji

πi = 0.85πjpji + 0.85

k
k + 1

πi.

Solving for πi yields

0.85k + 0.85
0.15k + 1
which for k = 1 is πi = 1.48πjPji and in the limit as k → ∞ is πi = 5.67πjpji. Adding a
single loop only increases pagerank by a factor of 1.74 and adding k loops increases it by
at most a factor of 6.67 for arbitrarily large k.

πjpji

πi =

174

Hitting time

Related to page rank is a quantity called hitting time. Hitting time is closely related
to return time and thus to the reciprocal of page rank. One way to return to a vertex
v is by a path in the graph from v back to v. Another way is to start on a path that
encounters a restart, followed by a path from the random restart vertex to v. The time
to reach v after a restart is the hitting time. Thus, return time is clearly less than the
expected time until a restart plus hitting time. The fastest one could return would be if
there were only paths of length two since self loops are ignored in calculating page rank. If
r is the restart value, then the loop would be traversed with at most probability (1 − r)2.
With probability r + (1 − r) r = (2 − r) r one restarts and then hits v. Thus, the return
time is at least 2 (1 − r)2 + (2 − r) r × (hitting time). Combining these two bounds yields

2 (1 − r)2 + (2 − r) rE (hitting time) ≤ E (return time) ≤ E (hitting time) .

The relationship between return time and hitting time can be used to see if a vertex has
unusually high probability of short loops. However, there is no eﬃcient way to compute
hitting time for all vertices as there is for return time. For a single vertex v, one can com-
pute hitting time by removing the edges out of the vertex v for which one is computing
hitting time and then run the page rank algorithm for the new graph. The hitting time
for v is the reciprocal of the page rank in the graph with the edges out of v removed.
Since computing hitting time for each vertex requires removal of a diﬀerent set of edges,
the algorithm only gives the hitting time for one vertex at a time. Since one is probably
only interested in the hitting time of vertices with low hitting time, an alternative would
be to use a random walk to estimate the hitting time of low hitting time vertices.

Spam

Suppose one has a web page and would like to increase its page rank by creating some
other web pages with pointers to the original page. The abstract problem is the following.
We are given a directed graph G and a vertex v whose page rank we want to increase.
We may add new vertices to the graph and add edges from v or from the new vertices
to any vertices we want. We cannot add edges out of other vertices. We can also delete
edges from v.

The page rank of v is the stationary probability for vertex v with random restarts. If
we delete all existing edges out of v, create a new vertex u and edges (v, u) and (u, v),
then the page rank will be increased since any time the random walk reaches v it will
be captured in the loop v → u → v. A search engine can counter this strategy by more
frequent random restarts.

A second method to increase page rank would be to create a star consisting of the
vertex v at its center along with a large set of new vertices each with a directed edge to

175

v. These new vertices will sometimes be chosen as the target of the random restart and
hence the vertices increase the probability of the random walk reaching v. This second
method is countered by reducing the frequency of random restarts.

Notice that the ﬁrst technique of capturing the random walk increases page rank but
does not eﬀect hitting time. One can negate the impact of someone capturing the random
walk on page rank by increasing the frequency of random restarts. The second technique
of creating a star increases page rank due to random restarts and decreases hitting time.
One can check if the page rank is high and hitting time is low in which case the page
rank is likely to have been artiﬁcially inﬂated by the page capturing the walk with short
cycles.

Personalized page rank

In computing page rank, one uses a restart probability, typically 0.15, in which at each
step, instead of taking a step in the graph, the walk goes to a vertex selected uniformly
at random. In personalized page rank, instead of selecting a vertex uniformly at random,
one selects a vertex according to a personalized probability distribution. Often the distri-
bution has probability one for a single vertex and whenever the walk restarts it restarts
at that vertex.

Algorithm for computing personalized page rank

First, consider the normal page rank. Let α be the restart probability with which
the random walk jumps to an arbitrary vertex. With probability 1 − α the random walk
selects a vertex uniformly at random from the set of adjacent vertices. Let p be a row
vector denoting the page rank and let G be the adjacency matrix with rows normalized
to sum to one. Then

or

p = α

n (1, 1, . . . , 1) + (1 − α) pG

p[I − (1 − α)G] =

α
n

(1, 1, . . . , 1)

p = α

n (1, 1, . . . , 1) [I − (1 − α) G]−1.

Thus, in principle, p can be found by computing the inverse of [I − (1 − α)G]−1. But
this is far from practical since for the whole web one would be dealing with matrices with
billions of rows and columns. A more practical procedure is to run the random walk and
observe using the basics of the power method in Chapter 3 that the process converges to
the solution p.

For the personalized page rank, instead of restarting at an arbitrary vertex, the walk
restarts at a designated vertex. More generally, it may restart in some speciﬁed neighbor-
hood. Suppose the restart selects a vertex using the probability distribution s. Then, in

176

the above calculation replace the vector 1
n (1, 1, . . . , 1) by the vector s. Again, the compu-
tation could be done by a random walk. But, we wish to do the random walk calculation
for personalized pagerank quickly since it is to be performed repeatedly. With more care
this can be done, though we do not describe it here.

5.6 Markov Chain Monte Carlo

The Markov Chain Monte Carlo (MCMC) method is a technique for sampling a mul-
tivariate probability distribution p(x), where x = (x1, x2, . . . , xd). The MCMC method is
used to estimate the expected value of a function f (x)

E(f ) =

(cid:88)

x

f (x)p(x).

If each xi can take on two or more values, then there are at least 2d values for x, so an
explicit summation requires exponential time. Instead, one could draw a set of samples,
each sample x with probability p(x). Averaging f over these samples provides an estimate
of the sum.

To sample according to p(x), design a Markov Chain whose states correspond to the
possible values of x and whose stationary probability distribution is p(x). There are two
general techniques to design such a Markov Chain: the Metropolis-Hastings algorithm
and Gibbs sampling. The Fundamental Theorem of Markov Chains, Theorem 5.2, states
that the average of f over states seen in a suﬃciently long run is a good estimate of E(f ).
The harder task is to show that the number of steps needed before the long-run average
probabilities are close to the stationary distribution grows polynomially in d, though the
total number of states may grow exponentially in d. This phenomenon known as rapid
mixing happens for a number of interesting examples. Section 5.8 presents a crucial tool
used to show rapid mixing.

We used x ∈ Rd to emphasize that distributions are multi-variate. From a Markov
chain perspective, each value x can take on is a state, i.e., a vertex of the graph on which
the random walk takes place. Henceforth, we will use the subscripts i, j, k, . . . to denote
states and will use pi instead of p(x1, x2, . . . , xd) to denote the probability of the state
corresponding to a given set of values for the variables. Recall that in the Markov chain
terminology, vertices of the graph are called states.

Recall the notation that p(t) is the row vector of probabilities of the random walk
being at each state (vertex of the graph) at time t. So, p(t) has as many components as
there are states and its ith component, p(t)
, is the probability of being in state i at time
i
t. Recall the long-term t-step average is

a(t) =

1
t

(cid:2)p(0) + p(1) + · · · + p(t−1)(cid:3) .

(5.3)

177

The expected value of the function f under the probability distribution p is E(f ) =
(cid:80)
i fipi where fi is the value of f at state i. Our estimate of this quantity will be the
average value of f at the states seen in a t step walk. Call this estimate a. Clearly, the
expected value of a is

E(a) =

(cid:88)

fi

i

(cid:32)

1
t

t
(cid:88)

j=1

Prob (walk is in state i at time j)

=

(cid:33)

(cid:88)

fia(t)
i

.

i

The expectation here is with respect to the “coin tosses” of the algorithm, not with respect
to the underlying distribution p. Let fmax denote the maximum absolute value of f . It is
easy to see that

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:88)

i

fipi − E(a)

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

≤ fmax

(cid:88)

i

|pi − a(t)
i

| = fmax|p − a(t)|1

(5.4)

where the quantity |p − a(t)|1 is the l1 distance between the probability distributions p
and a(t) and is often called the “total variation distance” between the distributions. We
will build tools to upper bound |p − a(t)|1. Since p is the stationary distribution, the t for
which |p − a(t)|1 becomes small is determined by the rate of convergence of the Markov
chain to its steady state.

The following proposition is often useful.

Proposition 5.11 For two probability distributions p and q,

|p − q|1 = 2

(cid:88)

i

(pi − qi)+ = 2

(cid:88)

(qi − pi)+

i

where x+ = x if x ≥ 0 and x+ = 0 if x < 0.

The proof is left as an exercise.

5.6.1 Metropolis-Hasting Algorithm

The Metropolis-Hasting algorithm is a general method to design a Markov chain whose
stationary distribution is a given target distribution p. Start with a connected undirected
graph G on the set of states. If the states are the lattice points (x1, x2, . . . , xd) in Rd with
xi ∈ {0, 1, 2, , . . . , n}, then G is the lattice graph with 2d coordinate edges at each interior
vertex. In general, let r be the maximum degree of any vertex of G. The transitions of
the Markov chain are deﬁned as follows. At state i select neighbor j with probability 1
r .
Since the degree of i may be less than r, with some probability no edge is selected and the
walk remains at i. If a neighbor j is selected and pj ≥ pi, go to j. If pj < pi, go to j with
probability pj/pi and stay at i with probability 1 − pj
. Intuitively, this favors “heavier”
pi
states with higher p values. So, for i (cid:54)= j, adjacent in G,

pij =

(cid:18)

min

1,

1
r

(cid:19)

pj
pi

178

p(a) = 1
2
p(b) = 1
4
p(c) = 1
8
p(d) = 1
8

1
2

a

d

1
8

1
4

b

c

1
8

2

6

a → b
1
1
3
4
a → c
1
1
3
8
a → d 1
1
3
8
a → a 1− 1

1 = 1
1 = 1
1 = 1
12 − 1
6 − 1

12

12

2

2

12 = 2

3

c → a 1
3
c → b
1
3
c → d
1
3
c → c
1− 1

3 − 1

3 − 1

3 = 0

b → a
b → c
b → b

1
3
1
1
3
8
1− 1

6

4

1 = 1
3 − 1

6 = 1

2

d → a 1
3
d → c
1
3
d → d 1− 1

3 − 1

3 = 1

3

p(a) = p(a)p(a → a) + p(b)p(b → a) + p(c)p(c → a) + p(d)p(d → a)

= 1
2

2

3 + 1

4

1

3 + 1

8

1

3 + 1

8

1

3 = 1

2

p(b) = p(a)p(a → b) + p(b)p(b → b) + p(c)p(c → b)
3 = 1

6 + 1

2 + 1

= 1
2

1

4

4

1

8

1

p(c) = p(a)p(a → c) + p(b)p(b → c) + p(c)p(c → c) + p(d)p(d → c)
3 = 1

8 0 + 1

12 + 1

6 + 1

= 1
2

4

8

1

8

1

1

p(d) = p(a)p(a → d) + p(c)p(c → d) + p(d)p(d → d)
3 = 1

12 + 1

3 + 1

= 1
2

8

1

1

8

1

8

Figure 5.9: Using the Metropolis-Hasting algorithm to set probabilities for a random walk
so that the stationary probability will be the desired probability.

and

Thus,

pii = 1 −

(cid:88)

j(cid:54)=i

pij.

pipij =

pi
r

(cid:18)

min

1,

(cid:19)

pj
pi

=

1
r

min(pi, pj) =

pj
r

(cid:18)

min

1,

(cid:19)

pi
pj

= pjpji.

By Lemma 5.3, the stationary probabilities are indeed p(x) as desired.

2, p(b) = 1

4, p(c) = 1

8, and p(d) = 1

Example: Consider the graph in Figure 5.9. Using the Metropolis-Hasting algorithm,
assign transition probabilities so that the stationary probability of a random walk is
p(a) = 1
8. The maximum degree of any vertex is three,
so at a, the probability of taking the edge (a, b) is 1
6. The probability of taking the
3
edge (a, c) is 1
1 or 1
2
1
12. Thus, the probability
8
3
of staying at a is 2
3. The probability
of taking the edge from c to a is 1
3 and the probability of taking the edge from d to a is
2
1
3. Thus, the stationary probability of a is 1
2, which is the desired
2
probability.

1 or 1
3. The probability of taking the edge from b to a is 1

1 or 1
12 and of taking the edge (a, d) is 1

3 = 1

3 + 1

3 + 1

3 + 1

1
4

1
8

2

1

1

8

1

8

3

4

2

179

5.6.2 Gibbs Sampling

Gibbs sampling is another Markov Chain Monte Carlo method to sample from a
multivariate probability distribution. Let p (x) be the target distribution where x =
(x1, . . . , xd). Gibbs sampling consists of a random walk on an undirectd graph whose
vertices correspond to the values of x = (x1, . . . , xd) and in which there is an edge from
x to y if x and y diﬀer in only one coordinate. Thus, the underlying graph is like a
d-dimensional lattice except that the vertices in the same coordinate line form a clique.

To generate samples of x = (x1, . . . , xd) with a target distribution p (x), the Gibbs
sampling algorithm repeats the following steps. One of the variables xi is chosen to be
updated. Its new value is chosen based on the marginal probability of xi with the other
variables ﬁxed. There are two commonly used schemes to determine which xi to update.
One scheme is to choose xi randomly, the other is to choose xi by sequentially scanning
from x1 to xd.

Suppose that x and y are two states that diﬀer in only one coordinate. Without loss
of generality let that coordinate be the ﬁrst. Then, in the scheme where a coordinate is
randomly chosen to modify, the probability pxy of going from x to y is

pxy =

1
d

p(y1|x2, x3, . . . , xd).

The normalizing constant is 1/d since for a given value i the probability distribution of
p(yi|x1, x2, . . . , xi−1, xi+1, . . . , xd) sums to one, and thus summing i over the d-dimensions
results in a value of d. Similarly,

pyx =

=

1
d
1
d

p(x1|y2, y3, . . . , yd)

p(x1|x2, x3, . . . , xd).

Here use was made of the fact that for j (cid:54)= i, xj = yj.

It is simple to see that this chain has stationary probability proportional to p (x).

Rewrite pxy as

pxy =

=

=

1
d
1
d
1
d

p(y1|x2, x3, . . . , xd)p(x2, x3, . . . , xd)
p(x2, x3, . . . , xd)

p(y1, x2, x3, . . . , xd)
p(x2, x3, . . . , xd)

p(y)
p(x2, x3, . . . , xd)

again using xj = yj for j (cid:54)= i. Similarly write

pyx =

1
d

p(x)
p(x2, x3, . . . , xd)

180

5
8

3,1

2,1

1,1

1
6

1
8

1
3

7
12

3,2

2,2

1,2

1
6

1
6

1
4

1
3

3,3

1
12

2,3

1
12

1,3

1
6

5
12

3
8

3
4

p(1, 1) = 1
3
p(1, 2) = 1
4
p(1, 3) = 1
6
p(2, 1) = 1
8
p(2, 2) = 1
6
p(2, 3) = 1
12
p(3, 1) = 1
6
p(3, 2) = 1
6
p(3, 3) = 1
12

p(11)(12) = 1
4/( 1
3
Calculation of edge probability p(11)(12)

d p12/(p11 + p12 + p13 = 1

2

1

1
4

1

6 = 1

2

1

4/ 9

12 = 1

2

1
4

4

3 = 1

6

4

6

4

p(11)(12) = 1
3 = 1
2
3 = 1
p(11)(13) = 1
2
5 = 1
p(11)(21) = 1
2
5 = 2
p(11)(31) = 1
2
15
Edge probabilities.

1
4
1
6
1
8
1
6

10

8

9

8

p(12)(11) = 1
2
p(12)(13) = 1
2
p(12)(22) = 1
2
p(12)(32) = 1
2

1
3
1
6
1
6
1
6

4

4

9

9

3 = 2
3 = 1
7 = 1
7 = 1

7

7

12

12

p(13)(11) = 1
2
p(13)(12) = 1
2
p(13)(23) = 1
2
p(13)(33) = 1
2

1
3
1
4
1
12
1
12

4

9

6

4

3 = 2
3 = 1
1 = 1
1 = 1

8

3

3

8

p(21)(22) = 1
2
p(21)(23) = 1
2
p(21)(11) = 1
2
p(21)(31) = 1
2

8

9

8

1
6
1
12
8
1
3
1
6

3 = 2
3 = 1
5 = 4
5 = 2

15

15

9

8

1

4

p11p(11)(12) = 1
3
p11p(11)(13) = 1
3
p11p(11)(21) = 1
3
Veriﬁcation of a few edges.

6 = 1
9 = 1
10 = 1

2
9 = p12p(12)(11)
2
9 = p13p(13)(11)
4
15 = p21p(21)(11)

6

1

8

1

Note that the edge probabilities out of a state such as (1,1) do not add up to one.
That is, with some probability the walk stays at the state that it is in. For example,
p(11)(11) = p(11)(12) + p(11)(13) + p(11)(21) + p(11)(31) = 1 − 1

32 − 1

24 = 9
32.

6 − 1

24 − 1

Figure 5.10: Using the Gibbs algorithm to set probabilities for a random walk so that the
stationary probability will be a desired probability.

181

from which it follows that p(x)pxy = p(y)pyx. By Lemma 5.3 the stationary probability
of the random walk is p(x).

5.7 Areas and Volumes

Computing areas and volumes is a classical problem. For many regular ﬁgures in
two and three dimensions there are closed form formulae. In Chapter 2, we saw how to
compute volume of a high dimensional sphere by integration. For general convex sets in
d-space, there are no closed form formulae. Can we estimate volumes of d-dimensional
convex sets in time that grows as a polynomial function of d? The MCMC method answes
this question in the aﬃrmative.

One way to estimate the area of the region is to enclose it in a rectangle and estimate
the ratio of the area of the region to the area of the rectangle by picking random points
in the rectangle and seeing what proportion land in the region. Such methods fail in high
dimensions. Even for a sphere in high dimension, a cube enclosing the sphere has expo-
nentially larger area, so exponentially many samples are required to estimate the volume
of the sphere.

It turns out that the problem of estimating volumes of sets is reducible to the problem
of drawing uniform random samples from sets. Suppose one wants to estimate the volume
of a convex set R. Create a concentric series of larger and larger spheres S1, S2, . . . , Sk
such that S1 is contained in R and Sk contains R. Then

Vol(R) = Vol(Sk ∩ R) =

Vol(Sk ∩ R)
Vol(Sk−1 ∩ R)

Vol(Sk−1 ∩ R)
Vol(Sk−2 ∩ R)

· · ·

Vol(S2 ∩ R)
Vol(S1 ∩ R)

Vol(S1)

If the radius of the sphere Si is 1 + 1
of

d times the radius of the sphere Si−1, then the value

Vol(Sk−1 ∩ R)
Vol(Sk−2 ∩ R)
can be estimated by rejection sampling provided one can select points at random from a
d-dimensional region. Since the radii of the spheres grows as 1 + 1
d , the number of spheres
is at most

O(log1+(1/d) R) = O(Rd).

It remains to show how to draw a uniform random sample from a d-dimensional set.
It is at this point that we require the set to be convex so that the Markov chain technique
we use will converge quickly to its stationary probability. To select a random sample from
a d-dimensional convex set impose a grid on the region and do a random walk on the grid
points. At each time, pick one of the 2d coordinate neighbors of the current grid point,
each with probability 1/(2d) and go to the neighbor if it is still in the set; otherwise, stay
put and repeat. If the grid length in each of the d coordinate directions is at most some
a, the total number of grid points in the set is at most ad. Although this is exponential in

182

Figure 5.11: A network with a constriction.

d, the Markov chain turns out to be rapidly mixing (the proof is beyond our scope here)
and leads to polynomial time bounded algorithm to estimate the volume of any convex
set in Rd.

5.8 Convergence of Random Walks on Undirected Graphs

The Metropolis-Hasting algorithm and Gibbs sampling both involve a random walk.
Initial states of the walk are highly dependent on the start state of the walk. Both
these walks are random walks on edge-weighted undirected graphs. Such Markov chains
are derived from electrical networks. Recall the following notation which we will use
throughout this section. Given a network of resistors, the conductance of edge (x, y)
is denoted cxy and the normalizing constant cx equals (cid:80)
y cxy. The Markov chain has
transition probabilities pxy = cxy/cx. We assume the chain is connected. Since

cxpxy = cccxy/cx = cxy = cyx = cycyx/cy = cypxy

the stationary probabilities are proportional to cx where the normalization constant is
c0 = (cid:80)

x cx.

An important question is how fast the walk starts to reﬂect the stationary probability
of the Markov process. If the convergence time was proportional to the number of states,
the algorithms would not be very useful since the number of states can be exponentially
large.

There are clear examples of connected chains that take a long time to converge. A
chain with a constriction, see Figure 5.11, takes a long time to converge since the walk is
unlikely to reach the narrow passage between the two halves, both of which are reasonably
big. We will show in Theorem 5.12 that the time to converge is quantitatively related to

183

the tightest constriction.

A function is unimodal if it has a single maximum, i.e., it increases and then decreases.
A unimodal function like the normal density has no constriction blocking a random walk
from getting out of a large set of states, whereas a bimodal function can have a con-
Interestingly, many common multivariate distributions as well as univariate
striction.
probability distributions like the normal and exponential are unimodal and sampling ac-
cording to these distributions can be done using the methods here.

A natural problem is estimating the probability of a convex region in d-space according
to a normal distribution. One technique to do this is rejection sampling. Let R be the
region deﬁned by the inequality x1 + x2 + · · · + xd/2 ≤ xd/2+1 + · · · + xd. Pick a sample
according to the normal distribution and accept the sample if it satisﬁes the inequality. If
not, reject the sample and retry until one gets a number of samples satisfying the inequal-
ity. The probability of the region is approximated by the fraction of the samples that
satisﬁed the inequality. However, suppose R was the region x1 + x2 + · · · + xd−1 ≤ xd. The
probability of this region is exponentially small in d and so rejection sampling runs into
the problem that we need to pick exponentially many samples before we accept even one
sample. This second situation is typical. Imagine computing the probability of failure of
a system. The object of design is to make the system reliable, so the failure probability is
likely to be very low and rejection sampling will take a long time to estimate the failure
probability.

In general, there could be constrictions that prevent rapid convergence of a Markov
chain to its stationary probability. However, if the set is convex in any number of dimen-
sions, then there are no constrictions and there is rapid convergence although the proof
of this is beyond the scope of this book.

We deﬁne below a combinatorial measure of constriction for a Markov chain, called the
normalized conductance, and relate this quantity to the rate at which the chain converges
to the stationarity probability. The conductance of an edge (x, y) leaving a set of states
S is deﬁned to be πxcxy where πx is the stationary probability of vertex x. One way to
avoid constrictions like the one in the picture of Figure 5.11 is to insure that the total
conductance of edges leaving every subset of states to be high. This is not possible if S
was itself small or even empty. So, in what follows, we “normalize” the total conductance
of edges leaving S by the size of S as measured by total cx for x ∈ S. Recall that pxy = cxy
cx
and the stationary probability πx = cx
x cx. In deﬁning the conductance of
c0
edges leaving a set we have ignored the normalizing constants.

where c0 = (cid:80)

Deﬁnition 5.1 For a subset S of vertices, the normalized conductance Φ(S) of S is the

184

ratio of the total conductance of all edges from S to ¯S to the total of the cx for x ∈ S.

Φ(S) =

(cid:80)

(x,y)
(cid:80)
x∈S

cxy

cx

(cid:80)

(x,y)
(cid:80)
x∈S

cxpxy

c0πx

=

(cid:80)

c0πxpxy

(cid:80)

πxpxy

=

(x,y)
(cid:80)
x∈S

c0πx

=

(x,y)
(cid:80)
x∈S

πx

The normalized conductance5 of S is the probability of taking a step from S to outside
S conditioned on starting in S in the stationary probability distribution π. The stationary
distribution for state x conditioned on being in S is

πx
π(S)

=

cx
(cid:80)
x∈S

cx

.

where π(S) = (cid:80)

πx.

x∈S

Deﬁnition 5.2 The normalized conductance of the Markov chain, denoted Φ, is deﬁned
by

Φ = min

Φ(S).

S
π(S)≤1/2

The restriction to sets with π ≤ 1/2 in the deﬁnition of Φ is natural. The deﬁnition of
Φ guarantees that if Φ is high, there is high probability of moving from S to ¯S so it is
unlikely to get stuck in S provided π(S) ≤ 1
4, then since for
every edge πipij = πjpji

2, say π(S) = 3

2. If π(S) > 1

Φ(S) =

(cid:80)

i∈S πipij
(cid:80)
i∈S πi

=

(cid:80)
3 (cid:80)

j∈S πjpji
j∈S πk

= Φ( ¯S)/3

Since Φ( ¯S) ≥ Φ , we still have at least Φ/3 probability of moving out of S. The larger
π(S) is the smaller the probability of moving out, which is as it should be. We cannot
move out of the whole set! One does not need to escape from big sets. Note that a
constriction would mean a small Φ.

Deﬁnition 5.3 Fix ε > 0. The ε-mixing time of a Markov chain is the minimum integer t
such that for any starting distribution p(0), the 1-norm distance between the t-step running
average probability distribution6 and the stationary distribution is at most ε.

5We will often drop the word “normalized” and just say “conductance”.
6Recall that a(t) = 1

t (p(0) + p(1) + · · · + p(t−1)) is called the running average distribution.

185

The theorem below states that if Φ, the normalized conductance of the Markov chain,
is large, then there is fast convergence of the running average probability. Intuitively, if
Φ is large, the walk rapidly leaves any subset of states. Later we will see examples where
the mixing time is much smaller than the cover time. That is, the number of steps before
a random walk reaches a random state independent of its starting state is much smaller
than the average number of steps needed to reach every state. In fact for some graphs,
called expenders, the mixing time is logarithmic in the number of states.

Theorem 5.12 The ε-mixing time of a random walk on an undirected graph is

(cid:18) ln(1/πmin)
Φ2ε3

(cid:19)

O

where πmin is the minimum stationary probability of any state.

Proof: Let

t =

c ln(1/πmin)
Φ2ε2

,

for a suitable constant c. Let a = a(t) be the running average distribution for this value
of t. We need to show that |a − π| ≤ ε.

Let vi denote the ratio of the long term average probability for state i at time t di-
vided by the stationary probability for state i. Thus, vi = ai
. Renumber states so that
πi
v1 ≥ v2 ≥ · · · . A state i for which vi > 1 has more probability than its stationary proba-
bility. Execute one step of the Markov chain starting at probabilities a. The probability
vector after that step is aP . Now, a − aP is the net loss of probability for each state due
to the step. Let k be any integer with vk > 1. Let A = {1, 2, . . . , k}. A is a “heavy” set,
consisting of states with ai ≥ πi. The net loss of probability for each state from the set
A in one step is (cid:80)k

t as in the proof of Theorem 5.2.

i=1(ai − (aP )i) ≤ 2

Another way to reckon the net loss of probability from A is to take the diﬀerence of

the probability ﬂow from A to ¯A and the ﬂow from ¯A to A. For i < j,

net-ﬂow(i, j) = ﬂow(i, j) − ﬂow(j, i) = πipijvi − πjpjivj = πjpji(vi − vj) ≥ 0,

Thus, for any l ≥ k, the ﬂow from A to {k + 1, k + 2, . . . , l} minus the ﬂow from {k +
1, k + 2, . . . , l} to A is nonnegative. At each step, heavy sets loose probability. Since for
i ≤ k and j > l, we have vi ≥ vk and vj ≤ vl+1, the net loss from A is at least

Thus,

(cid:88)

i≤k
j>l

πjpji(vi − vj) ≥ (vk − vl+1)

πjpji.

(cid:88)

i≤k
j>l

(vk − vl+1)

πjpji ≤

2
t

.

(cid:88)

i≤k
j>l

186

If the total stationary probability π({i|vi ≤ 1}) of those states where the current proba-
bility is less than their stationary probability is less than ε/2, then

|a − π|1 = 2

(cid:88)

i
vi≤1

(1 − vi)πi ≤ ε,

so we are done. Assume π({i|vi ≤ 1}) > ε/2 so that π(A) ≥ ε min(π(A), π( ¯A))/2. Choose
l to be the largest integer greater than or equal to k so that

l
(cid:88)

j=k+1

πj ≤ εΦπ(A)/2.

Since

by the deﬁnition of Φ,

k
(cid:88)

l
(cid:88)

l
(cid:88)

πjpji ≤

i=1

j=k+1

j=k+1

πj ≤ εΦπ(A)/2

(cid:88)

i≤k<j

πjpji ≥ Φ min(π(A), π( ¯A)) ≥ εΦπ(A).

Thus, (cid:80)

i≤k
j>l

πjpji ≥ εΦπ(A)/2. Substituting into the inequality 5.8 gives

vk − vl+1 ≤

8
tεΦπ(A)

.

(5.5)

This inequality says that v does not drop too much as we go from k to l + 1. On the
other hand, the cumulative total of π will have increased, since, π1 + π2 + · · · + πl+1 ≥
ρ(π1 + π2 + · · · + πk), where, ρ = 1 + εΦ
2 . We will be able to use this repeatedly to argue
that overall v does not drop too much. If that is the case (in the extreme, for example,
if all the vi are 1 each), then intuitively, a ≈ π, which is what we are trying to prove.
Unfortunately, the technical execution of this argument is a bit messy - we have to divide
{1, 2, . . . , n} into groups and consider the drop in v as we move from one group to the
next and then add up. We do this now.

Now, divide {1, 2, . . .} into groups as follows. The ﬁrst group G1 is {1}. In general, if
the rth group Gr begins with state k, the next group Gr+1 begins with state l + 1 where
l is as deﬁned above. Let i0 be the largest integer with vi0 > 1. Stop with Gm, if Gm+1
would begin with an i > i0. If group Gr begins in i, deﬁne ur = vi.

|a − π|1 ≤ 2

i0(cid:88)

i=1

πi(vi − 1) ≤

m
(cid:88)

r=1

π(Gr)(ur − 1) =

m
(cid:88)

r=1

π(G1 ∪ G2 ∪ . . . ∪ Gr)(ur − ur+1),

187

where the analog of integration by parts for sums is used in the last step using the
convention that um+1 = 1. Since ur − ur+1 ≤ 8/εΦπ(G1 ∪ . . . ∪ Gr), the sum is at most
8m/tεΦ. Since π1 + π2 + · · · + πl+1 ≥ ρ(π1 + π2 + · · · + πk),

m ≤ lnρ(1/π1) ≤ ln(1/π1)/(ρ − 1).

Thus |a − π|1 ≤ O(ln(1/πmin)/tΦ2ε2) ≤ ε for a suitable choice of c and this completes
the proof.

5.8.1 Using Normalized Conductance to Prove Convergence

We now apply Theorem 5.12 to some examples to illustrate how the normalized con-
ductance bounds the rate of convergence. Our ﬁrst examples will be simple graphs. The
graphs do not have rapid converge, but their simplicity helps illustrate how to bound the
normalized conductance and hence the rate of convergence.

A 1-dimensional lattice

Consider a random walk on an undirected graph consisting of an n-vertex path with
self-loops at the both ends. With the self loops, the stationary probability is a uniform
1
n over all vertices. The set with minimum normalized conductance is the set with the
maximum number of vertices with the minimum number of edges leaving it. This set
consists of the ﬁrst n/2 vertices, for which total conductance of edges from S to ¯S is
is the stationary probability of vertex numbered
πn/2pn/2, n
n
2 .) Thus

n ) and π(S) = 1

2 +1 = Ω( 1

2. (π n

2

Φ(S) = 2π n
2

p n

2 +1 = Ω(1/n).

2 , n
By Theorem 5.12, for ε a constant such as 1/100, after O(n2 log n) steps, |a(t) − π|1 ≤
1/100. This graph does not have rapid convergence. The hitting time and the cover time
are O(n2). In many interesting cases, the mixing time may be much smaller than the
cover time. We will see such an example later.

A 2-dimensional lattice

Consider the n × n lattice in the plane where from each point there is a transition to
each of the coordinate neighbors with probability 1/4. At the boundary there are self-loops
with probability 1-(number of neighbors)/4. It is easy to see that the chain is connected.
Since pij = pji, the function fi = 1/n2 satisﬁes fipij = fjpji and by Lemma 5.3 is the
stationary probability. Consider any subset S consisting of at most half the states. Index
states by their x and y coordinates. For at least half the states in S, either row x or
column y intersects ¯S (Exercise 5.46). So at least Ω(|S|/n) points in S are adjacent to
points in ¯S. Each such point contributes πipij = Ω(1/n2) to ﬂow(S, ¯S). So

(cid:88)

(cid:88)

i∈S

j∈ ¯S

πipij ≥ c|S|/n3.

188

Thus, Φ ≥ Ω(1/n). By Theorem 5.12, after O(n2 ln n/ε2) steps, |a(t) − π|1 ≤ 1/100.

A lattice in d-dimensions

Next consider the n × n × · · · × n lattice in d-dimensions with a self-loop at each
boundary point with probability 1 − (number of neighbors)/2d. The self loops make all
πi equal to n−d. View the lattice as an undirected graph and consider the random walk
on this undirected graph. Since there are nd states, the cover time is at least nd and thus
exponentially dependent on d. It is possible to show (Exercise 5.62) that Φ is Ω(1/dn).
Since all πi are equal to n−d, the mixing time is O(d3n2 ln n/ε2), which is polynomially
bounded in n and d.
The d-dimensional lattice is related to the Metropolis-Hastings algorithm and Gibbs sam-
pling although in those constructions there is a nonuniform probability distribution at
the vertices. However, the d-dimension lattice case suggests why the Metropolis-Hastings
and Gibbs sampling constructions might converge fast.

A clique

Consider an n vertex clique with a self loop at each vertex. For each edge, cxy = 1

and thus for each vertex, cx = n. Let S be a subset of the vertices. Then

(cid:88)

x∈S

cx = n|S|.

(cid:88)

(x,y)

cxy = |S||S|

and

Now Φ = min Φ(S) for |S| ≤ n
of

2 . Thus Φ = 1

2. This gives a mixing time

=

|S|
n

.

(cid:80)

(cid:80)

Φ(S) =

(x,y) cxy
x∈S cx
2 and hence |S| ≥ n
(cid:32)ln 1
πmin
Φ2(cid:15)3

(cid:18) ln n
1
4(cid:15)3

= O

(cid:33)

O

(cid:19)

= O(ln n).

A connected undirected graph

Next consider a random walk on a connected n vertex undirected graph where at each
vertex all edges are equally likely. The stationary probability of a vertex equals the degree
of the vertex divided by the sum of degrees which equals twice the number of edges. The
sum of the vertex degrees is at most n2 and thus, the steady state probability of each
vertex is at least 1
n2 . Since the degree of a vertex is at most n, the probability of each edge

189

n . For any S, the total conductance of edges out of S is greater

at a vertex is at least 1
than or equal to

Thus, Φ is at least 1
O(n6(ln n)/ε2).

1
1
n3 .
n2
n2 , ln 1
n3 . Since πmin ≥ 1
πmin

1
n

=

= O(ln n). Thus, the mixing time is

The Gaussian distribution on the interval [-1,1]

Consider the interval [−1, 1]. Let δ be a “grid size” speciﬁed later and let G be the
graph consisting of a path on the 2
δ + 1 vertices {−1, −1 + δ, −1 + 2δ, . . . , 1 − δ, 1} having
self loops at the two ends. Let πx = ce−αx2 for x ∈ {−1, −1 + δ, −1 + 2δ, . . . , 1 − δ, 1}
where α > 1 and c has been adjusted so that (cid:80)

x πx = 1.

We now describe a simple Markov chain with the πx as its stationary probability and
argue its fast convergence. With the Metropolis-Hastings’ construction, the transition
probabilities are

px,x+δ =

(cid:32)

min

1,

1
2

e−α(x+δ)2
e−αx2

(cid:33)

and px,x−δ =

(cid:32)

min

1,

e−α(x−δ)2
e−αx2

(cid:33)

.

1
2

Let S be any subset of states with π(S) ≤ 1
[kδ, 1] for k ≥ 1. It is easy to see that

2. Consider the case when S is an interval

(cid:90) ∞

π(S) ≤

ce−αx2 dx

x=(k−1)δ

(cid:90) ∞

(k−1)δ
(cid:32)

x
(k − 1)δ
ce−α((k−1)δ)2
α(k − 1)δ

≤

= O

(cid:33)

.

ce−αx2 dx

Now there is only one edge from S to ¯S and total conductance of edges out of S is

(cid:88)

(cid:88)

i∈S

j /∈S

πipij = πkδpkδ,(k−1)δ = min(ce−αk2δ2, ce−α(k−1)2δ2) = ce−αk2δ2.

Using 1 ≤ k ≤ 1/δ and α ≥ 1, Φ(S) is

Φ(S) =

ﬂow(S, ¯S)
π(S)

≥ ce−αk2δ2 α(k − 1)δ
ce−α((k−1)δ)2

≥ Ω(α(k − 1)δe−αδ2(2k−1)) ≥ Ω(δe−O(αδ)).

For δ < 1

α, we have αδ < 1, so e−O(αδ) = Ω(1), thus, Φ(S) ≥ Ω(δ). Now, πmin ≥ ce−α ≥

190

e−1/δ, so ln(1/πmin) ≤ 1/δ.

If S is not an interval of the form [k, 1] or [−1, k], then the situation is only better
since there is more than one “boundary” point which contributes to ﬂow(S, ¯S). We do
not present this argument here. By Theorem 5.12 in Ω(1/δ3ε2) steps, a walk gets within
ε of the steady state distribution.

In these examples, we have chosen simple probability distributions. The methods ex-

tend to more complex situations.

5.9 Bibliographic Notes

The material on the analogy between random walks on undirected graphs and electrical
networks is from [DS84] as is the material on random walks in Euclidean space. Addi-
tional material on Markov chains can be found in [MR95b], [MU05], and [per10]. For
material on Markov Chain Monte Carlo methods see [Jer98] and [Liu01].

The use of normalized conductance to prove convergence of Markov Chains is by
Sinclair and Jerrum, [SJ] and Alon [Alo86]. A polynomial time bounded Markov chain
based method for estimating the volume of convex sets was developed by Dyer, Frieze and
Kannan [DFK91].

191

5.10 Exercises

Exercise 5.1 The Fundamental Theorem of Markov chains proves that for a connected
Markov chain, the long-term average distribution a(t) converges to a stationary distribu-
tion. Does the t step distribution p(t) also converge for every connected Markov Chain ?
Consider the following examples : (i) A two-state chain with p12 = p21 = 1. (ii) A three
state chain with p12 = p23 = p31 = 1 and the other pij = 0. Generalize these examples to
produce Markov Chains with many states.

A connected Markov Chain is said to be aperiodic if the greatest common divisor of
the lengths of directed cycles is 1. It is known (though we do not prove it here) that for
connected aperiodic chains, p(t) converges to the stationary distribution.

Exercise 5.2

1. What is the set of possible harmonic functions on a connected graph if there are only
interior vertices and no boundary vertices that supply the boundary condition?

2. Let qx be the stationary probability of vertex x in a random walk on an undirected
graph where all edges at a vertex are equally likely and let dx be the degree of vertex
x. Show that qx
dx

is a harmonic function.

3. If there are multiple harmonic functions when there are no boundary conditions why
is the stationary probability of a random walk on an undirected graph unique?

4. What is the stationary probability of a random walk on an undirected graph?

Exercise 5.3 In Section ?? we associate a graph and edge probabilities with an electric
network such that voltages and currents in the electrical network corresponded to properties
of random walks on the graph. Can we go in the reverse order and construct the equivalent
electrical network from a graph with edge probabilities?

Exercise 5.4 Given an undirected graph consisting of a single path of ﬁve vertices num-
bered 1 to 5, what is the probability of reaching vertex 1 before vertex 5 when starting at
vertex 4.

Exercise 5.5 Consider the electrical resistive network in Figure 5.12 consisting of ver-
tices connected by resistors. Kirchoﬀ ’s law states that the currents at each vertex sum to
zero. Ohm’s law states that the voltage across a resistor equals the product of the resis-
tance times the current through it. Using these laws calculate the eﬀective resistance of
the network.

Exercise 5.6 Consider the electrical network of Figure 5.13.

1. Set the voltage at a to one and at b to zero. What are the voltages at c and d?

2. What is the current in the edges a to c, a to d, c to d. c to b and d to b?

192

R1

R3

i1

R2

i2

Figure 5.12: An electrical network of resistors.

a

R=1

R=2

c

d

R=2

R=1

b

R=1

Figure 5.13: An electrical network of resistors.

3. What is the eﬀective resistance between a and b?

4. Convert the electrical network to a graph. What are the edge probabilities at each

vertex?

5. What is the probability of a walk starting at c reaching a before b? a walk starting

at d?

6. What is the net frequency that a walk from a to b goes through the edge from c to

d?

7. What is the probability that a random walk starting at a will return to a before

reaching b?

Exercise 5.7 Consider a graph corresponding to an electrical network with vertices a and
b. Prove directly that cef f
must be less than or equal to one. We know that this is the
ca
escape probability and must be at most 1. But, for this exercise, do not use that fact.

Exercise 5.8 (Thomson’s Principle) The energy dissipated by the resistance of edge xy
in an electrical network is given by i2
xyrxy. The total energy dissipation in the network

193

u

v

u

v

u

v

Figure 5.14: Three graphs

1

1

1

2

2

2

3

3

3

4

4

4

Figure 5.15: Three graph

(cid:80)
x,y

is E = 1
2

xyrxy where the 1
i2

2 accounts for the fact that the dissipation in each edge
is counted twice in the summation. Show that the actual current distribution is that
distribution satisfying Ohm’s law that minimizes energy dissipation.

Exercise 5.9 (Rayleigh’s law) Prove that reducing the value of a resistor in a network
cannot increase the eﬀective resistance. Prove that increasing the value of a resistor cannot
decrease the eﬀective resistance. You may use Thomson’s principle 5.8.

Exercise 5.10 What is the hitting time huv for two adjacent vertices on a cycle of length
n? What is the hitting time if the edge (u, v) is removed?

Exercise 5.11 What is the hitting time huv for the three graphs if Figure 5.14.

Exercise 5.12 Show that adding an edge can either increase or decrease hitting time by
calculating h24 for the three graphs in Figure 5.15.

Exercise 5.13 Consider the n vertex connected graph shown in Figure 5.16 consisting of
an edge (u, v) plus a connected graph on n − 1 vertices and some number of edges. Prove
that huv = 2m − 1 where m is the number of edges in the n − 1 vertex subgraph.

194

n − 1
vertices
m edges

u

v

Figure 5.16: A connected graph consisting of n − 1 vertices and m edges along with a
single edge (u, v).

Exercise 5.14 What is the most general solution to the diﬀerence equation t(i + 2) −
5t(i + 1) + 6t(i) = 0. How many boundary conditions do you need to make the solution
unique?

Exercise 5.15 Given the diﬀerence equation akt(i + k) + ak−1t(i + k − 1) + · · · + a1t(i +
1)+a0t(i) = 0 the polynomial aktk +ak−itk−1 +· · ·+a1t+a0 = 0 is called the characteristic
polynomial.

1. If the equation has a set of r distinct roots, what is the most general form of the

solution?

2. If the roots of the characteristic polynomial are not unique what is the most general

form of the solution?

3. What is the dimension of the solution space?

4. If the diﬀerence equation is not homogeneous and f(i) is a speciﬁc solution to the
nonhomogeneous diﬀerence equation, what is the full set of solutions to the diﬀerence
equation?

Exercise 5.16 Given the integers 1 to n, what is the expected number of draws with
replacement until the integer 1 is drawn.

Exercise 5.17 Consider the set of integers {1, 2, . . . , n}. What is the expected number
of draws d with replacement so that every integer is drawn?

Exercise 5.18 Consider a random walk on a clique of size n. What is the expected
number of steps before a given vertex is reached?

Exercise 5.19 Show that adding an edge to a graph can either increase or decrease com-
mute time.

Exercise 5.20 For each of the three graphs below what is the return time starting at
vertex A? Express your answer as a function of the number of vertices, n, and then
express it as a function of the number of edges m.

195

A B

n vertices

a

A

B

← n − 2 →
b

A

B
n − 1
clique

c

Exercise 5.21 Suppose that the clique in Exercise 5.20 was an arbitrary graph with m−1
edges. What would be the return time to A in terms of m, the total number of edges.

Exercise 5.22 Suppose that the clique in Exercise 5.20 was an arbitrary graph with m−d
edges and there were d edges from A to the graph. What would be the expected length of
a random path starting at A and ending at A after returning to A exactly d times.

Exercise 5.23 Given an undirected graph with a component consisting of a single edge
ﬁnd two eigenvalues of the Laplacian L = D − A where D is a diagonal matrix with vertex
degrees on the diagonal and A is the adjacency matrix of the graph.

Exercise 5.24 A researcher was interested in determining the importance of various
edges in an undirected graph. He computed the stationary probability for a random walk
on the graph and let pi be the probability of being at vertex i. If vertex i was of degree
di, the frequency that edge (i, j) was traversed from i to j would to 1
pi and the frequency
di
that the edge was traversed in the opposite direction would be 1
pj. Thus, he assigned an
dj

importance of

(cid:12)
(cid:12)
(cid:12)

1
di

pi − 1
dj

pj

(cid:12)
(cid:12)
(cid:12) to the edge. What is wrong with his idea?

Exercise 5.25 Prove that two independent random walks starting at the origin on a two
dimensional lattice will eventually meet with probability one.

Exercise 5.26 Suppose two individuals are ﬂipping balanced coins and each is keeping
tract of the number of heads minus the number of tails. Will both individual’s count return
to zero at the same time?

Exercise 5.27 Consider the lattice in 2-dimensions. In each square add the two diagonal
edges. What is the escape probability for the resulting graph?

Exercise 5.28 Determine by simulation the escape probability for the 3-dimensional lat-
tice.

Exercise 5.29 What is the escape probability for a random walk starting at the root of
an inﬁnite binary tree?

196

E

D

A

C

B

D

A

C

B

Figure 5.17: An undirected and a directed graph.

Exercise 5.30 Consider a random walk on the positive half line, that is the integers
0, 1, 2, . . .. At the origin, always move right one step. At all other integers move right
with probability 2/3 and left with probability 1/3. What is the escape probability?

Exercise 5.31 ** What is the probability of returning to the start vertex on a random
walk on an inﬁnite planar graph?

Exercise 5.32 Create a model for a graph similar to a 3-dimensional lattice in the way
that a planar graph is similar to a 2-dimensional lattice. What is probability of returning
to the start vertex in your model?

Exercise 5.33 Consider the graphs in Figure 5.17. Calculate the stationary distribution
for a random walk on each graph and the ﬂow through each edge. What condition holds
on the ﬂow through edges in the undirected graph? In the directed graph?

Exercise 5.34 Create a random directed graph with 200 vertices and roughly eight edges
per vertex. Add k new vertices and calculate the page rank with and without directed edges
from the k added vertices to vertex 1. How much does adding the k edges change the page
rank of vertices for various values of k and restart frequency? How much does adding
a loop at vertex 1 change the page rank? To do the experiment carefully one needs to
consider the page rank of a vertex to which the star is attached. If it has low page rank
its page rank is likely to increase a lot.

Exercise 5.35 Repeat the experiment in Exercise 5.34 for hitting time.

Exercise 5.36 Search engines ignore self loops in calculating page rank. Thus, to increase
page rank one needs to resort to loops of length two. By how much can you increase the
page rank of a page by adding a number of loops of length two?

197

Exercise 5.37 Can one increase the page rank of a vertex v in a directed graph by doing
something some distance from v? The answer is yes if there is a long narrow chain of
vertices into v with no edges leaving the chain. What if there is no such chain?

Exercise 5.38 Given a very large directed graph with many vertices of out degree one or
in degree one, can one compute page rank of a reduced graph in which the vertices of in
degree or out degree one have been merged and then compute the page rank of the original
graph from the pagerank of the reduced graph? Does the method work if there are random
restarts?

Exercise 5.39 If we model random restarts by adding a restart vertex, do we get the
same results as if we eliminated the restart vertex and added n2 edges?

Exercise 5.40 Consider modifying personal page rank as follows. Start with the uniform
restart distribution and calculate the steady state probabilities. Then run the personalized
page rank algorithm using the stationary distribution calculated instead of the uniform
distribution. Keep repeating until the process converges. That is, we get a stationary
probability distribution such that if we use the stationary probability distribution for the
restart distribution we will get the stationary probability distribution back. Does this pro-
cess converge? What is the resulting distribution? What distribution do we get for the
graph consisting of two vertices u and v with a single edge from u to v?

Exercise 5.41 Number the vertices of a graph {1, 2, . . . , n}. Deﬁne hitting time to be the
expected time from vertex 1. In (2) assume that the vertices in the cycle are sequentially
numbered.

1. What is the hitting time for a vertex in a complete directed graph with self loops?

2. What is the hitting time for a vertex in a directed cycle with n vertices?

Create exercise relating strongly connected and full rank
Full rank implies strongly connected.
Strongly connected does not necessarily imply full rank









0 0 1
0 0 1
1 1 0

Is graph aperiodic iﬀ λ1 > λ2?

Exercise 5.42 Using a web browser bring up a web page and look at the source html.
How would you extract the url’s of all hyperlinks on the page if you were doing a crawl
of the web? With Internet Explorer click on “source” under “view” to access the html
representation of the web page. With Firefox click on “page source” under “view”.

198

Exercise 5.43 Sketch an algorithm to crawl the World Wide Web. There is a time delay
between the time you seek a page and the time you get it. Thus, you cannot wait until the
page arrives before starting another fetch. There are conventions that must be obeyed if
one were to actually do a search. Sites specify information has to how long or which ﬁles
can be searched. Do not attempt an actual search without guidance from a knowledgeable
person.

Exercise 5.44 Let p(x), where x = (x1, x2, . . . , xd) xi ∈ {0, 1}, be a multivariate proba-
bility distribution. For d = 100, how would you estimate the marginal distribution

p(x) =

(cid:88)

x2,...,xd

p(x1, x2, . . . , xd)?

Exercise 5.45 Prove Proposition 5.11 that for two probability distributions p, q, |p −
q|1 = 2 (cid:80)

i(pi − qi)+.

Exercise 5.46 Suppose S is a subset of at most n2/2 points in the n × n lattice. Show
that

|{(i, j) ∈ S|all elements in row i and all elements in column j are inS}| ≤ |S|/2.

Exercise 5.47 Show that the stationary probabilities of the chain described in the Gibbs
sampler is the correct p.

Exercise 5.48 A Markov chain is said to be symmetric if for all i and j, pij = pji. What
is the stationary distribution of a connected symmetric chain? Prove your answer.

Exercise 5.49 How would you integrate a multivariate polynomial distribution over some
region?

Exercise 5.50 Given a time-reversible Markov chain, modify the chain as follows. At
the current state, stay put (no move) with probability 1/2. With the other probability 1/2,
move as in the old chain. Show that the new chain has the same stationary distribution.
What happens to the convergence time in this modiﬁcation?

Exercise 5.51 Using the Metropolis-Hasting Algorithm create a Markov chain whose sta-
tionary probability is that given in the following table.

x1x2
Prob

00
1/16

01
1/8

02
1/16

10
1/8

11
1/4

12
1/8

20
1/16

21
1/8

22
1/16

Exercise 5.52 Let p be a probability vector (nonnegative components adding up to 1) on
the vertices of a connected graph. Set pij (the transition probability from i to j) to pj for
all i (cid:54)= j which are adjacent in the graph. Show that the stationary probability vector for
the chain is p. Is running this chain an eﬃcient way to sample according to a distribution
close to p? Think, for example, of the graph G being the n × n × n × · · · n grid.

199

Exercise 5.53 Construct the edge probability for a three state Markov chain where each
pair of states is connected by an edge so that the stationary probability is (cid:0) 1

(cid:1).

2, 1

3, 1

6

Exercise 5.54 Consider a three state Markov chain with stationary probability (cid:0) 1
(cid:1).
Consider the Metropolis-Hastings algorithm with G the complete graph on these three
vertices. What is the expected probability that we would actually make a move along a
selected edge?

2, 1

3, 1

6

Exercise 5.55 Try Gibbs sampling on p (x) =

(cid:18) 1

2 0
1
0
2

(cid:19)
.

What happens? How does the Metropolis Hasting Algorithm do?

Exercise 5.56 Consider p(x), where, x = (x1, . . . , x100) and p (0) = 1
0. How does Gibbs sampling behave?

2, p (x) =

1

(2100−1) x (cid:54)=

Exercise 5.57 Construct an algorithm and compute the volume of a unit radius sphere in
20 dimensions by carrying out a random walk on a 20 dimensional grid with 0.1 spacing.

Exercise 5.58 Given a graph G and an integer k how would you generate connected
subgraphs of G with k vertices with probability proportional to the number of edges in the
subgraph induced on those vertices? The probabilities need not be exactly proportional to
the number of edges and you are not expected to prove your algorithm for this problem.

Exercise 5.59 Suppose one wishes to generate uniformly at random regular, degree three
undirected, connected multi-graphs each with 1,000 vertices. A multi-graph may have
multiple edges between a pair of vertices and self loops. One decides to do this by a Markov
Chain Monte Carlo technique. They design a network where each vertex is a regular degree
three, 1,000 vertex multi-graph. For edges they say that the vertices corresponding to two
graphs are connected by an edge if one graph can be obtained from the other by a ﬂip of a
pair of disjoint edges. In a ﬂip, a pair of edges (a, b) and (c, d) are replaced by (a, c) and
(b, d).

1. Prove that a swap on a connected multi-graph results in a connected multi-graph.

2. Prove that the network whose vertices correspond to the desired graphs is connected.

3. Prove that the stationary probability of the random walk is uniform.

4. Give an upper bound on the diameter of the network.

In order to use a random walk to generate the graphs uniformly at random, the ran-
dom walk must rapidly converge to the stationary probability. Proving this is beyond the
material in this book.

Exercise 5.60 What is the mixing time for

200

1. Two cliques connected by a single edge?

2. A graph consisting of an n vertex clique plus one additional vertex connected to one

vertex in the clique.

Exercise 5.61 What is the mixing time for

1. G(n, p) with p = log n
n ?

2. a circle with n vertices where at each vertex an edge has been added to another vertex
chosen at random. On average each vertex will have degree four, two circle edges,
and edge from that vertex to a vertex chosen at random, and possible some edges
that are the ends of the random edges from other vertices.

Exercise 5.62 Show that for the n×n×· · ·×n grid in d space, the normalized conductance
is Ω(1/dn).
Hint: The argument is a generalization of the argument in Exercise 5.46. Argue that for
any subset S containing at most 1/2 the grid points, for at least 1/2 the grid points in S,
among the d coordinate lines through the point, at least one intersects ¯S.

201

6 Learning and VC-dimension

6.1 Learning

Learning algorithms are general purpose tools that solve problems from many domains
without detailed domain-speciﬁc knowledge. They have proven to be very eﬀective in a
large number of contexts. The task of a learning algorithm is to learn to classify a set
of objects. To illustrate with an example, suppose one wants an algorithm to distinguish
among diﬀerent types of motor vehicles such as cars, trucks, and tractors. Using domain
knowledge about motor vehicles, one can create a set of features. Some examples of fea-
tures are the number of wheels, the power of the engine, the number of doors, and the
length of vehicle. If there are d features, each object can be represented as a d-dimensional
vector, called the feature vector, with each component of the vector giving the value of
one feature. The objective is to design a “prediction” algorithm that given a vector will
correctly predict the corresponding type of vehicle. Earlier rule-based approaches to this
problem used domain knowledge to develop a set of rules such as: if the number of wheels
is four, it is a car. Prediction was done by checking the rules.

In the learning approach, the process of developing the prediction rules is not domain-
speciﬁc; it is automated. In learning, domain expertise is used to decide on the choice of
features, reducing the problem to one of classifying feature vectors. Further, a domain
expert is called on to classify a set of feature vectors, called training examples, and present
these as input to the learning algorithm. The role of the expert ends here.

The learning algorithm takes as input the set of labeled training examples and devel-
ops a set of rules that applied to the training vectors gives the correct labels. In the motor
vehicle example, the learning algorithm needs no knowledge of this domain at all. It just
deals with a set of training vectors in d-dimensional space and produces a rule to classify
d-dimensional space into regions, one region corresponding to each of “car”, “truck”, etc.

The task of the learning algorithm is to output a set of rules that correctly labels all
training examples. Of course, for this limited task, one could output the rule “for each
training example, use the label that the expert has already supplied”. But, we insist
on Occam’s razor principle that states that the rules output by the algorithm, must be
more succinct than the table of all labeled training examples. This is akin to developing
a scientiﬁc theory to explain extensive observations. The theory must be more succinct
than just a list of observations.

The general task is not to be correct just on the training examples, but have the learnt
rules correctly predict the labels of future examples. Intuitively, if the classiﬁer is trained
on suﬃciently many training examples, then it seems likely that it would work well on the
space of all examples. We will see later that the theory of Vapnik-Chervonenkis dimension
(VC-dimension) conﬁrms this intuition. For now, our attention is focussed on getting a

202

Labeled Examples

Rule

Figure 6.1: Training set and the rule that is learnt

succinct set of rules that correctly classiﬁes the training examples. This is referred to as
“learning”.

Throughout this chapter, we assume all the labels are binary. It is not diﬃcult to see
that the general problem of classifying into one of several types can be reduced to binary
classiﬁcation. Classifying into car or non-car, tractor or non-tractor, etc. will pin down
the type of vehicle. So the teacher’s labels are assumed to be +1 or -1. For an illustra-
tion, see Figure 6.1 where examples are in 2-dimensions corresponding to two features.
Examples labeled -1 are unﬁlled circles and those labeled +1 are ﬁlled circles. The right
hand picture illustrates a rule that the algorithm could come up with, the examples above
the line are -1 and those below are +1.

The simplest rule in d-dimensional space is the generalization of a line in the plane,
namely, a half-space. Does a weighted sum of feature values exceed a threshold? Such
a rule may be thought of as being implemented by a threshold gate that takes the fea-
ture values as inputs, computes their weighted sum and outputs yes or no depending on
whether or not the sum is greater than the threshold. One could also look at a network of
interconnected threshold gates called a neural net. Threshold gates are sometimes called
perceptrons since one model of human perception is that it is done by a neural net in the
brain.

203

6.2 Linear Separators, the Perceptron Algorithm, and Margins

The problem of learning a half-space or a linear separator consists of n labeled exam-
ples, a1, a2, . . . , an, in d-dimensional space. The task is to ﬁnd a d-dimensional vector w,
if one exists, and a threshold b such that

wT ai > b for each ai labelled +1
wT ai < b for each ai labelled −1.

(6.1)

A vector-threshold pair, (w, b), satisfying the inequalities is called a linear separator.

The above formulation is a linear program (LP) in the unknowns w and b that can be
solved by a general purpose LP algorithm. Linear programming is solvable in polynomial
time but a simpler algorithm called the perceptron learning algorithm can be much faster
when there is a feasible solution w with a lot of wiggle room or margin, though it is not
polynomial time bounded in general.

We begin by adding an extra coordinate to each ai and w, writing ˆai = (ai, 1) and
ˆw = (w, −b). Suppose li is the ±1 label on ai. Then, the inequalities in (6.1) can be
rewritten as

( ˆwT ˆai)li > 0 1 ≤ i ≤ n.
Since the right hand side is zero, we may scale ˆai so that | ˆai| = 1. Adding the extra
coordinate increased the dimension by one but now the separator contains the origin. For
simplicity of notation, in the rest of this section, we drop the hats and let ai and w stand
for the corresponding ˆai and ˆw.

The perceptron learning algorithm

The perceptron learning algorithm is simple and elegant. We wish to ﬁnd a solution

w to

(6.2)
where |ai| = 1. Starting with w = l1a1, pick any ai with (wT ai)li ≤ 0, and replace w by
w + liai. Repeat until (wT ai)li > 0 for all i.

1 ≤ i ≤ n

(wT ai)li > 0

The intuition behind the algorithm is that correcting w by adding aili causes the new
i = |ai|2 = 1. This is good for this ai. But this change
(wT ai)li to be higher by ai
may be bad for other aj. The proof below shows that this very simple process quickly
yields a solution w provided there exists a solution with a good margin.

T ail2

Deﬁnition 6.1 For a solution w to (6.2), where |ai| = 1 for all examples, the margin is
deﬁned to be the minimum distance of the hyperplane {x|wT x = 0} to any ai, namely,
min
i

(wT ai)li
|w|

.

204

margin

Figure 6.2: Margin of a linear separator.

If we did not require that all |ai| = 1 in (6.2), then one could artiﬁcially increase the
margin by scaling up the ai. If we did not divide by |w| in the deﬁnition of margin, then
again, one could artiﬁcially increase the margin by scaling w up. The interesting thing is
that the number of steps of the algorithm depends only upon the best margin any solution
can achieve, not upon n or d. In practice, the perceptron learning algorithm works well.

Theorem 6.1 Suppose there is a solution w∗ to (6.2) with margin δ > 0. Then, the
perceptron learning algorithm ﬁnds some solution w with (wTai)li > 0 for all i in at most
1
δ2 − 1 iterations.
Proof: Scale w∗ so that |w∗| = 1. Consider the cosine of the angle between the current
vector w and w∗, that is, wT w∗
. In each step of the algorithm, the numerator of this
|w|
fraction increases by at least δ because

(w + aili)T w∗ = wT w∗ + liai

T w∗ ≥ wT w∗ + δ.

On the other hand, the square of the denominator increases by at most one because

|w + aili|2 = (w + aili)T (w + aili) = |w|2 + 2(wT ai)li + |ai|2l2

i ≤ |w|2 + 1

since wT aili ≤ 0, the cross term is nonpositive.

After t iterations, wT w∗ ≥ (t + 1)δ since at the start wT w∗ = l1(a1

T w∗) ≥ δ and at
each iteration wT w∗ increases by at least δ. Similarly after t iterations |w|2 ≤ t + 1 since
at the start |w| = |a1| = 1 and at each iteration |w|2 increases by at most one. Thus, the
cosine of the angle between w and w∗ is at least (t+1)δ
t+1 and the cosine cannot exceed one.
Now

√

(t + 1)δ
√
t + 1

≤ 1

√

t + 1δ ≤ 1

t + 1 ≤

205

1
δ2

t ≤

1
δ2 − 1

Therefore the algorithm must stop before 1
for all i. This proves the theorem.

δ2 −1 iterations and at termination, (wTai)li > 0

√

How strong is the assumption that there is a separator with margin at least δ? Sup-
pose for the moment, the ai are picked from the uniform density on the surface of the
unit hypersphere. We saw in Chapter 2 that for any ﬁxed hyperplane passing through the
d) of the hyperplane.
origin, most of the mass of the unit sphere is within distance O(1/
√
d is low.
So, the probability of one ﬁxed hyperplane having a margin of more than c/
But this does not mean that there is no hyperplane with a larger margin. By the union
bound, one can only assert that the probability of some hyperplane having a large margin
is at most the probability of a speciﬁc one having a large margin times the number of
hyperplanes which is inﬁnite. Later we will see using VC-dimension arguments that in-
deed the probability of some hyperplane having a large margin is low if the examples are
selected at random from the hypersphere. So, the assumption of large margin separators
existing may not be valid for the simplest random models. But intuitively, if what is to
be learnt, like whether something is a car, is not very hard, then, with enough features in
the model, there will not be many “near cars” that could be confused with cars nor many
“near non-cars”. In a real problem such as this, uniform density is not a valid assumption.
In this case, there should be a large margin separator and the theorem would work.

The question arises as to how small margins can be. Suppose the examples a1, a2, . . . , an
were vectors with d coordinates, each coordinate a 0 or 1 and the decision rule for labeling
the examples was the following.

If the ﬁrst 1 coordinate of the example is odd, label the example +1.
If the ﬁrst 1 coordinate of the example is even, label the example -1.

This rule can be represented by the decision rule

(ai1, ai2, . . . , ain) (cid:0)1, − 1

2, 1

4, − 1

8, . . .(cid:1)T = ai1 −

1
2

ai2 +

1
4

ai3 −

1
8

ai4 + · · · > 0.

However, the margin in this example can be exponentially small. Indeed, if for an example
a, the ﬁrst d/10 coordinates are all zero, then the margin is O(2−d/10).

Maximizing the Margin

In this section, we present an algorithm to ﬁnd the maximum margin separator. The
li(wT ai)
.
|w|

margin of a solution w to (wT ai)li > 0, 1 ≤ i ≤ n, where |ai| = 1 is δ = min
Since this is not a concave function of w, it is diﬃcult to deal with computationally.

i

Convex optimization techniques in general can only handle the maximization of con-
cave functions or the minimization of convex functions over convex sets. However, by

206

Smaller Margin Separator

Max Margin Separator

Figure 6.3: Separators with Diﬀerent Margins

modifying the weight vector, one can convert the optimization problem to one with a
concave objective function. Note that

(cid:19)

(cid:18) wT ai
|w|δ

li

≥ 1

for all ai. Let v = w
vector w
|v|. So the optimization problem is

δ|w| be the modiﬁed weight vector. Dividing the normalized weight
|w| by δ normalizes the margin to one. Maximizing δ is equivalent to minimizing

minimize |v| subject to li(vT ai) > 1, ∀i.

Although |v| is a convex function of the coordinates of v, a better convex function to
minimize is |v|2 since |v|2 is diﬀerentiable. So we reformulate the problem as:

Maximum Margin Problem:

minimize |v|2 subject to li(vT ai) ≥ 1.

This convex optimization problem has been much studied and algorithms that use the
special structure of this problem solve it more eﬃciently than general convex optimiza-
tion methods. We do not discuss these improvements here. An optimal solution v to
this problem has the following property. Let V be the space spanned by the examples
ai for which there is equality, namely for which li(vT ai) = 1. We claim that v lies in
V . If not, v has a component orthogonal to V . Reducing this component inﬁnitesimally
does not violate any inequality, since, we are moving orthogonally to the exactly satisﬁed
constraints; but it does decrease |v| contradicting the optimality. If V is full dimensional,

207

a1

a2

a4

a3

Figure 6.4: The vectors a1, a2, a3, and a4 are all support vectors.

then there are d independent examples for which the equality li(vT ai) = 1 holds. These d
equations then have a unique solution and v must be that solution. These examples are
then called the support vectors. The d support vectors determine uniquely the maximum
margin separator.

Example: In the example of Figure 6.4 where

a1 = [0, 2, 1] a2 = [1, 2, 1] a3 = [−1, 0, 1] a4 − [−2, 0, 1]
l1 = +1

l3 = −1

l2 = −1

l4 = +1

all four vectors are support vectors but a1, a2 and a3 are an independent set and determine
[v1, v2, v3] uniquely. The solution for v is v = [−2, 2, −3].

Linear Separators that classify most examples correctly

It may happen that there are linear separators for which almost all but a small fraction
of examples are on the correct side. Going back to (6.2), ask if there is a w for which at
least (1 − ε)n of the n inequalities in (6.2) are satisﬁed. Unfortunately, such problems are
NP-hard and there are no good algorithms to solve them. A good way to think about this
is that we suﬀer a “loss” of one for each misclassiﬁed point and would like to minimize the
loss. But this loss function is discontinuous, it goes from 0 to 1 abruptly. However, with a
nicer loss function it is possible to solve the problem. One possibility is to introduce slack
variables yi, i = 1, 2, . . . , n, where yi measures how badly the example ai is classiﬁed. We
then include the slack variables in the objective function to be minimized:

minimize |v|2 + c

n
(cid:88)

i=1

yi

subject to

(vT ai)li ≥ 1 − yi
yi ≥ 0.

(cid:27)

i = 1, 2, . . . , n

(6.3)

If for some i, li(vT ai) ≥ 1, then set yi to its lowest value, namely zero, since each yi has a
positive coeﬃcient in the cost function. If, however, li(vT ai) < 1, then set yi = 1−li(vT ai),

208

-1

+1

-1

+1

+1

-1

+1

-1

-1

+1

-1

+1

+1

-1

+1

-1

Figure 6.5: The checker board pattern.

so yi is just the amount of violation of this inequality. Thus, the objective function is
trying to minimize a combination of the total violation as well as 1/margin. It is easy to
see that this is the same as minimizing

|v|2 + c

(cid:88)

i

(cid:0)1 − li(vTai)(cid:1)+

, 7

subject to the constraints. The second term is the sum of the violations.

6.3 Nonlinear Separators, Support Vector Machines, and Ker-

nels

There are problems where no linear separator exists but where there are nonlinear
separators. For example, there may be a polynomial p(·) such that p(ai) > 1 for all +1
labeled examples and p(ai) < 1 for all -1 labeled examples. A simple instance of this is
the unit square centered at the origin partitioned into four pieces where the top right and
the bottom left pieces are the +1 region and the bottom right and the top left are the
-1 region. For this, x1x2 > 0 for all +1 examples and x1x2 < 0 for all -1 examples. So,
the polynomial p(·) = x1x2 separates the regions. A more complicated instance is the
checker-board pattern in Figure 6.5 with alternate +1 and -1 squares.

If we know that there is a polynomial p of degree8 at most D such that an example
a has label +1 if and only if p(a) > 0, then the question arises as to how to ﬁnd such a
polynomial. Note that each d-tuple of integers (i1, i2, . . . , id) with i1 + i2 + · · · + id ≤ D
leads to a distinct monomial, xi1
d . So, the number of monomials in the polyno-
mial p is at most the number of ways of inserting d-1 dividers into a sequence of D + d−1
(cid:1) ≤ (D + d − 1)d−1. Let m = (D + d − 1)d−1 be the upper bound
positions which is (cid:0)D+d−1

2 · · · xid

1 xi2

d−1

7x+ =

(cid:26) 0
x

x ≤ 0
otherwise

8The degree is the total degree. The degree of a monomial is the sum of the powers of each variable

in the monomial and the degree of the polynomial is the maximum degree of its monomials.

209

on the number of monomials.

By letting the coeﬃcients of the monomials be unknowns, we can formulate a linear
program in m variables whose solution gives the required polynomial. Indeed, suppose
the polynomial p is

p(x1, x2, . . . , xd) =

(cid:88)

wi1,i2,...,idxi1

1 xi2

2 · · · xid
d .

i1,i2,...,id
i1+i2+···+id≤D

Then the statement p(ai) > 0 (recall ai is a d-vector) is just a linear inequality in the
wi1,i2,...,id. However the exponential number of variables for even moderate values of D
makes this approach infeasible. Nevertheless, this theoretical approach is useful. First,
we clarify the discussion above with an example. Suppose d = 2 and D = 2. Then the
possible (i1, i2) form the set {(1, 0) , (0, 1) , (2, 0) , (1, 1) , (0, 2)}. We ought to include the
pair (0, 0); but it is convenient to have a separate constant term called b. So we write

p(x1, x2) = b + w10x1 + w01x2 + w11x1x2 + w20x2

1 + w02x2
2.

Each example, ai, is a 2-vector, (ai1, ai2). The linear program is

b + w1,0ai1 + w01ai2 + w11ai1ai2 + w20a2
b + w10ai1 + w01ai2 + w11ai1ai2 + w20a2

i1 + w02a2
i1 + w02a2

i2 > 0
i2 < 0

if label of i = +1
if label of i = −1.

Note that we “pre-compute” ai1ai2, so this does not cause a nonlinearity. The linear
inequalities have unknowns that are the w’s and b.

The approach above can be thought of as embedding the examples ai that are in
d-space into a m-dimensional space where there is one coordinate for each i1, i2, . . . , id
summing to at most D, except for (0, 0, . . . , 0), and if ai = (x1, x2, . . . , xd), the coordinate
2 · · · xid
is xi1
d . Call this embedding ϕ(x). When d = D = 2, as in the above example,
ϕ(x) = (x1, x2, x2

2). If d = 3 and D = 2,

1, x1x2, x2

1 xi2

ϕ(x) = (x1, x2, x3, x1x2, x1x3, x2x3, x2

1, x2

2, x2

3),

and so on. We then try to ﬁnd a m-dimensional vector w such that the dot product of
w and ϕ(ai) is positive if the label is +1 and negative otherwise. Note that this w is not
necessarily the ϕ of some vector in d space.

Instead of ﬁnding any w, we want to ﬁnd the w maximizing the margin. As earlier,

write this program as

min |w|2 subject to (wT ϕ(ai))li ≥ 1 for all i.

The major question is whether we can avoid having to explicitly compute the embedding
ϕ and the vector w. Indeed, we only need to have ϕ and w implicitly. This is based on
the simple, but crucial observation that any optimal solution w to the convex program
yiϕ (ai), then wT ϕ (aj) can be
above is a linear combination of the ϕ(ai).

If w = (cid:80)

computed without actually knowing the ϕ(ai) but only the products ϕ(ai)T ϕ(aj).

i

210

Lemma 6.2 Any optimal solution w to the convex program above is a linear combination
of the ϕ(ai).

Proof: If w has a component perpendicular to all the ϕ(ai), simply zero out that com-
ponent. This preserves all the inequalities since the wT ϕ(ai) do not change and decreases
|w|2 contradicting the assumption that w is an optimal solution.

Assume that w is a linear combination of the ϕ(ai). Say w = (cid:80)

yiϕ(ai), where the

yi are real variables. Note that

|w|2 =

(cid:32)

(cid:88)

i

(cid:33)T (cid:32)

yiϕ(ai)

i

(cid:33)

yjϕ(aj)

=

(cid:88)

i,j

yiyjϕ(ai)T ϕ(aj).

(cid:88)

j

Reformulate the convex program as

minimize

(cid:88)

yiyjϕ(ai)T ϕ(aj)

i,j

(cid:32)

subject to li

(cid:88)

j

(cid:33)

yjϕ(aj)T ϕ(ai)

≥ 1 ∀i.

(6.4)

(6.5)

It is important to notice that ϕ itself is not needed, only the dot products of ϕ(ai) and
ϕ(aj) for all i and j including i = j. The Kernel matrix K, deﬁned as

suﬃces since we can rewrite the convex program as

kij = ϕ(ai)T ϕ(aj),

minimize

(cid:88)

ij

yiyjkij

subject to

(cid:88)

li

j

kijyj ≥ 1.

(6.6)

This convex program is called a support vector machine (SVM) though it is really not a
machine. The advantage is that K has only n2 entries instead of the O(dD) entries in each
ϕ(ai). Instead of specifying ϕ(ai), we specify how to get K from the ai. The speciﬁcation
is usually in closed form. For example, the “Gaussian kernel” is given by:

kij = ϕ(ai)T ϕ(aj) = e−c|ai−aj|2.

We prove shortly that this is indeed a kernel function.

First, an important question arises. Given a matrix K, such as the above matrix for
the Gaussian kernel, how do we know that it arises from an embedding ϕ as the pairwise
dot products of the ϕ(ai)? This is answered in the next lemma but ﬁrst we need to deﬁne
positive semi deﬁnite.

211

Deﬁnition 6.2 A symmetric matrix A is positive semi deﬁnite if xAxT ≥ 0 for all x.

If A is positive semi deﬁnite, then its eigenvalues values are nonnegative and A can be
2 V T = BBT where B = V D 1
written A = V DV T = V D 1
2 .

2 D 1

Lemma 6.3 A matrix K is a kernel matrix, i.e., there is an embedding ϕ such that
kij = ϕ(ai)T ϕ(aj), if and only if K is positive semi deﬁnite.

Proof: If K is positive semi deﬁnite, then it can be expressed as K = BBT . Deﬁne
ϕ(ai)T to be the ith row of B. Then kij = ϕ(ai)T ϕ(aj). Conversely, if there is an embed-
ding ϕ such that kij = ϕ(ai)T ϕ(aj), then using the ϕ(ai)T for the rows of a matrix B,
we have that K = BBT and so K is positive semi deﬁnite.

Recall that a function of the form (cid:80)

yiyjkij = yT Ky is convex if and only if K is

ij

positive semi deﬁnite. So the support vector machine problem is a convex program. We
may use any positive semi deﬁnite matrix as our kernel matrix.

We now give an important example of a kernel matrix. Consider a set of vectors,
T aj)p, where p is a positive integer. We prove that the
a1, a2, . . . , an, and let kij = (ai
matrix K with elements kij is positive semi deﬁnite. Suppose u is any n-vector. We must
show that uT Ku = (cid:80)

kijuiuj ≥ 0.

(cid:88)

ij

kijuiuj =

ij

(cid:88)

ij

uiuj(ai

T aj)p

(cid:88)

=

uiuj

ij

(cid:33)p

aikajk

(cid:32)

(cid:88)

k



(cid:88)

=

uiuj



(cid:88)

ij

k1,k2,...,kp

aik1aik2 · · · aikpajk1 · · · ajkp


 by expansion9.

Note that k1, k2, . . . , kp need not be distinct. Exchanging the summations and simplifying



uiuj



(cid:88)

k1,k2,...,kp

(cid:88)

ij

aik1aik2 · · · aikpajk1 · · · ajkp

 =

(cid:88)

(cid:88)

uiujaik1aik2 · · · aikpajk1 · · · ajkp



k1,k2,...,kp

(cid:88)

=

ij
(cid:32)

(cid:88)

k1,k2,...,kp

i

(cid:33)2

uiaik1aik2 · · · aikp

.

9Here aik denotes the kth coordinate of the vector ai

212

Figure 6.6: Two curves

The last term is a sum of squares and thus nonnegative proving that K is positive semi
deﬁnite.

From this, it is easy to see that for any set of vectors, a1, a2, . . . , an, and any c1, c2, . . .
greater than or equal to zero, the matrix K where kij has an absolutely convergent power

series expansion kij =

cp(ai

T aj)p is positive semi deﬁnite. For any u,

∞
(cid:80)
p=0

uT Ku =

(cid:88)

ij

uikijuj =

(cid:88)

ui

(cid:32) ∞
(cid:88)

ij

p=0

(cid:33)

cp(ai

T aj)p

uj =

∞
(cid:88)

(cid:88)

cp

p=0

i,j

uiuj(ai

T aj)p ≥ 0.

Lemma 6.4 For any set of vectors, a1, a2, . . . , an, the matrix K given by kij = e−|ai−aj|2/(2σ2)
is positive semi deﬁnite for any value of σ.

Proof:

e−|ai−aj|2/2σ2 = e−|ai|2/2σ2e−|aj|2/2σ2eai

T aj/σ2 =

(cid:16)

e−|ai|2/2σ2e−|aj|2/2σ2(cid:17) ∞
(cid:88)

t=0

(cid:18) (ai

T aj)t
t!σ2t

(cid:19)
.

The matrix L given by lij =

(cid:16) (ai

T aj)t
t!σ2t

(cid:17)

FF is positive semi-deﬁnite. Now K can be

∞
(cid:80)
t=0

written as DLDT , where D is the diagonal matrix with e−|ai|2/2σ2 as its (i, i)th entry. So
K is positive semi-deﬁnite.

Example: (Use of the Gaussian Kernel) Consider a situation where examples are
points in the plane on two juxtaposed curves, the solid curve and the dotted curve shown
in Figure 6.6, where points on the ﬁrst curve are labeled +1 and points on the second
curve are labeled -1. Suppose examples are spaced δ apart on each curve and the minimum
distance between the two curves is ∆ >> δ. Clearly, there is no half-space in the plane
that classiﬁes the examples correctly. Since the curves intertwine a lot, intuitively, any
polynomial which classiﬁes them correctly must be of high degree. Consider the Gaussian
kernel e−|ai−aj|2/δ2. For this kernel, the K has kij ≈ 1 for adjacent points on the same
curve and kij ≈ 0 for all other pairs of points. Reorder the examples, ﬁrst listing in
order all examples on the solid curve, then on the dotted curve. K has the block form:

213

K =

(cid:18) K1 0
0 K2

(cid:19)

, where K1 and K2 are both roughly the same size and are both block

matrices with 1’s on the diagonal and slightly smaller constants on the diagonals one oﬀ
from the main diagonal and then exponentially falling oﬀ with distance from the diagonal.

The SVM is easily seen to be essentially of the form:
T K2y2

T K1y1 + y2
minimize
subject to K1y1 ≥ 1 and K2y2 ≤ −1.

y1

This separates into two programs, one for y1 and the other for y2. From the fact that
K1 = K2, the solution will have y2 = −y1. Further by the structure which is essentially
the same everywhere except at the ends of the curves, the entries in y1 will all be essentially
the same as will the entries in y2. Thus, the entries in y1 will be 1 everywhere and the
entries in y2 will be -1 everywhere. Let li be the ±1 labels for the points. The yi values
provide a nice simple classiﬁer, namely liyi > 1.

6.4 Strong and Weak Learning - Boosting

A strong learner is an algorithm that takes n labeled examples and produces a clas-
siﬁer that correctly labels each of the given examples. Since the learner is given the n
examples with their labels and is responsible only for the given training examples, it seems
a trivial task. Just store the examples and labels in a table and each time we are asked
for the label of one of the examples, do a table look-up. By Occam’s razor principle,
the classiﬁer produced by the learner should be considerably more concise than a table
of the given examples. The time taken by the learner, and the length/complexity of the
classiﬁer output are both parameters by which we measure the learner. For now we focus
on a diﬀerent aspect. The word strong refers to the fact that the output classiﬁer must
label all the given examples correctly; no errors are allowed.

A weak learner is allowed to make mistakes. It is only required to get a strict majority,
namely, a ( 1
2 + γ) fraction of the examples correct where γ is a positive real number. This
seems very weak. But with a slight generalization of weak learning and using a technique
called boosting, strong learning can be accomplished with a weak learner.

Deﬁnition 6.3 (Weak learner) Suppose U = {a1, a2, . . . , an} are n labeled examples.
A weak learner is an algorithm that given the examples, their labels, and a nonnegative
real weight wi on each example ai as input, produces a classiﬁer that correctly labels a
subset of examples with total weight at least ( 1

wi.

2 + γ)

n
(cid:80)
i=1

A strong learner can be built by making O(log n) calls to a weak learner by a method
called boosting. Boosting makes use of the intuitive notion that if an example was mis-
classiﬁed, one needs to pay more attention to it.

214

Example: Illustration of boosting

x x x
0 0 x
0 0 x

x x x
0 0 x
0 0 x

x x x
0 0 x
0 0 x

x x x
0 0 x
0 0 x

x x x
0 0 x
0 0 x

Learn x’s from 0’s. Items above or to the right of a line are classiﬁed as x’s.

1 1 1
1 1 1
1 1 1

1

1 1
1 1 1+(cid:15)
1 1 1+(cid:15)

1+(cid:15) 1+(cid:15) 1

1+(cid:15) 1+(cid:15)

1

(1+(cid:15))2 1+(cid:15)

1

1
1

1 1+(cid:15)
1 1+(cid:15)

1
1

1+(cid:15) 1+(cid:15)
1+(cid:15)

1

1
1

1+(cid:15) 1+(cid:15)
1+(cid:15)

1

Weight of each example over time

0 0 0
0 0 1
0 0 1

1 1 0
0 0 1
0 0 1

1 1 0
0 1 1
0 0 1

2 1 0
0 1 1
0 0 1

2 1 0
0 1 1
0 0 1

Number of times misclassiﬁed

The top row indicates the results of the weak learner and the middle row indi-
In the ﬁrst application, the weak learner
cates the weight applied to each example.
misclassiﬁed the bottom two elements of the rightmost column. Thus,
in the next
application the weights of these two items were increased from 1 to 1 + (cid:15). The bottom
row of matrices indicates how often each element was misclassiﬁed. Since no element was
misclassiﬁed more than two out of ﬁve times, the results of labeling each example by the
way it was classiﬁed a majority of times give the correct labeling of all elements.

Boosting algorithm

Make the ﬁrst call to the weak learner with all wi set equal to 1.

At time t + 1 multiply the weight of each example that was mis-
classiﬁed the previous time by 1 + ε. Leave the other weights as
they are. Make a call to the weak learner.

After T steps, stop and output the following classiﬁer:

Label each of the examples {a1, a2, . . . , an} by the label
given to it by a majority of calls to the weak learner. Assume
T is odd, so there is no tie for the majority.

215

...

majority gate

Figure 6.7: Learner produced by boosting algorithm

Suppose m is the number of examples the ﬁnal classiﬁer gets wrong. Each of these
m examples was misclassiﬁed at least T /2 times so each has weight at least (1 + ε)T /2.
This says the total weight is at least m(1 + ε)T /2. On the other hand, at time t + 1, only
the weight of examples misclassiﬁed at time t were increased. By the property of weak
learning, the total weight of misclassiﬁed examples is at most f = ( 1
2 − γ) of the total
weight at time t. Let weight(t) be the total weight at time t. Then

weight(t + 1) ≤ (cid:0)(1 + ε)f + 1 − f (cid:1) × weight(t)

= (1 + εf ) × weight(t)

(cid:16)

≤

1 +

(cid:17)

− γε

ε
2

× weight(t).

Thus, since weight(0) = n,

m(1 + ε)T /2 ≤ Total weight at end ≤ n(1 +

ε
2

− γε)T .

Taking logarithms

ln m +

T
2

ln(1 + ε) ≤ ln n + T ln(1 +

ε
2

− γε).

To a ﬁrst order approximation, ln(1 + δ) ≈ δ for δ small. Make ε, the amount the
weights of misclassiﬁed examples are increased by, a small constant, say ε = 0.01. Then
ln m ≤ ln n − T γε. Let T = (1 + ln n)/γε. Then ln m ≤ −1 and m ≤ 1
e . Thus, the number
of misclassiﬁed items, m, is less than one and hence must be zero.

6.5 Number of Examples Needed for Prediction: VC-Dimension

Training and Prediction

216

Up to this point, we dealt only with training examples and focused on building a clas-
siﬁer that works correctly on them. Of course, the ultimate purpose is prediction of labels
on future examples. In the car verses non-car example, we want our classiﬁer to classify
future feature vectors as car or non-car without human input. Clearly, we cannot expect
the classiﬁer to predict every example correctly. To measure how good the classiﬁer is, we
attach a probability distribution on the space of examples and measure the probability of
misclassiﬁcation. The reason for attaching a probability distribution is that we want the
classiﬁer to correctly classify likely examples but are not so concerned about examples
that almost never arise.

A second question is how many training examples suﬃce so that as long as a classiﬁer
gets all the training examples correct (strong learner), the probability that it makes a
prediction error (measured with the same probability distribution as used to select train-
ing examples) of more than ε is less than δ? Ideally, we would like this number to be
suﬃcient whatever the unknown probability distribution is. The theory of VC-dimension
will provide an answer to this.

A Sampling Motivation

The concept of VC-dimension is fundamental and is the backbone of learning theory.
It is also useful in many other contexts. Our ﬁrst motivation will be from a database
example. Consider a database consisting of the salary and age of each employee in a
company and a set of queries of the form: how many individuals between ages 35 and
45 have a salary between $60,000 and $70,000? Each employee is represented by a point
in the plane where the coordinates are age and salary. The query asks how many data
points fall within an axis-parallel rectangle. One might want to select a ﬁxed sample of
the data before queries arrive and estimate the number of points in a query rectangle
based on the number of sample points in the rectangle. For one rectangle the probability
that the estimate is oﬀ by more than an (cid:15)-fraction can be made less than δ by making the
sample large enough. However, we want the sample to work for all rectangles. At ﬁrst,
such an estimate would not seem to work. Applying a union bound, the probability that
there exists a rectangle that the sample fails to work for is at most the product of the
probability that the sample fails for one particular rectangle times the number of possible
rectangles. But, there are an inﬁnite number of possible rectangles. So such a simple
union bound argument does not give a ﬁnite upper bound on the probability that the
sample fails to work for rectangles.

Deﬁne two axis-parallel rectangles to be equivalent if they contain the same data
points. If there are n data points, only O(n4) of the 2n subsets can correspond to the set
of points in a rectangle. To see this, consider any rectangle R. If one of its sides does not
pass through one of the n points that is inside the rectangle, then move the side parallel
to itself until for the ﬁrst time it passes through one of the n points inside the rectangle.
Clearly, the set of points in R and the new rectangle are the same since the edge did not

217

“cross” any point. By a similar process, modify all four sides, so that there is at least
one point on each side of the rectangle. Now, the number of rectangles with at least one
point on each side is at most O(n4). The exponent four plays an important role; it will
turn out to be the VC-dimension of axis-parallel rectangles.

Let U be a set of n points in the plane where each point corresponds to one employee’s
age and salary. Let ε > 0 be a given error parameter. Pick a random sample S of size s
from U . Given a query rectangle R, estimate |R ∩ U | by the quantity n
s |R ∩ S|. This is the
number of employees in the sample within the ranges scaled up by n
s , since we picked a
sample of size s out of n. We wish to assert that the fractional error for a random sample
of size s is at most ε for every rectangle R, i.e., that

(cid:12)
(cid:12)
(cid:12)|R ∩ U | −

(cid:12)
(cid:12)
|R ∩ S|
(cid:12) ≤ εn

n
s

for every R. Of course, the assertion is not absolute, there is a small probability that the
sample is atypical, for example picking no points from a rectangle R which has a lot of
points. We can only assert the above with high probability or that its negation holds with
very low probability. That is,

(cid:16)

Prob

∃ an R

(cid:12)
(cid:12)
(cid:12)|R ∩ U | −

(cid:12)
(cid:17)
(cid:12)
(cid:12) > εn
|R ∩ S|

n
s

≤ δ,

(6.7)

where δ > 0 is another error parameter. Note that it is very important that our sample S
be good for every possible query, since we do not know beforehand which queries will arise.

How many samples are necessary to ensure that (6.7) holds? Pick s samples uniformly
at random from the n points in U . For one ﬁxed R, the number of samples in R is
a random variable that is the sum of s independent 0-1 random variables, each with
probability q = |R∩U |
of having value one. The distribution of |R ∩ S| is Binomial(s, q).
n
Using Chernoﬀ bounds, for 0 ≤ ε ≤ 1,

Prob

(cid:16)(cid:12)
(cid:12)
(cid:12)|R ∩ U | −

(cid:12)
(cid:12)
(cid:12) > εn
|R ∩ S|

n
s

(cid:17)

≤ 2e−ε2s/(3q) ≤ 2e−ε2s/3.

Using the union bound and noting that there are only O(n4) possible sets R ∩ U yields

(cid:16)

Prob

∃ an R

(cid:12)
(cid:12)
(cid:12)|R ∩ U | −

(cid:12)
(cid:17)
(cid:12)
(cid:12) > εn
|R ∩ S|

n
s

≤ cn4e−ε2s/3

for some suﬃciently large c. Setting

s ≥

(cid:18)

3
ε2

5 ln n + ln

(cid:19)

1
δ

ensures (6.7) when n is suﬃciently large. In fact, we will see later that even the logarith-
mic dependence on n can be avoided. As long as s is at least a certain number depending
only upon the error ε and the VC-dimension of the set of shapes, (6.7) will hold.

218

In another situation, suppose we have an unknown probability distribution p over the
plane and ask what is the probability mass p(R) of a query rectangle R? We might esti-
mate the probability mass by ﬁrst drawing a sample S of size s in s independent trials,
each draw according to p, and wish to know how far the sample estimate |S ∩ R|/s is
from the probability mass p(R). Again, we would like the estimate to be good for every
rectangle. This is a more general problem than the ﬁrst problem of estimating |R ∩ U |.
The ﬁrst problem is the particular case where U consists of n points in the plane and the
probability distribution p has value 1

n at each of n points. Then 1

n |R ∩ U | = p(R).

There is no simple argument bounding the number of rectangles to O(n4) for the gen-
eral problem. Moving the sides of the rectangle is no longer valid, since it could change
the enclosed probability mass. Further, p could be a continuous distribution, where the
analog of n would be inﬁnite. So the argument above using the union bound would not
solve the problem. The VC-dimension argument will yield the desired result for the more
general situation.

The question is also of interest for shapes other than rectangles. Indeed, half-spaces in
d-dimensions is an important class of “shapes”, since they correspond to threshold gates.
A class of regions such as halfspaces or rectangles has a parameter called VC-dimension
and we can bound the probability of the discrepancy between the sample estimate and
the probability mass in terms of the VC-dimension of the shapes allowed. That is,

with probability 1 − δ where δ depends on ε and the VC-dimension.

|prob mass - estimate| < ε

In summary, we would like to create a sample of the data base without knowing which
query we will face, knowing only the family of possible queries such as rectangles. We
would like our sample to work well for every possible query from the class. With this
motivation, we introduce VC-dimension and later relate it to learning.

6.6 Vapnik-Chervonenkis or VC-Dimension

A set system (U, S) consists of a set U along with a collection S of subsets of U . The
set U may be ﬁnite or inﬁnite. An example of a set system is the set U = R2 of points
in the plane, with S being the collection of all axis-parallel rectangles. Each rectangle is
viewed as the set of points in it.

Let (U, S) be a set system. A subset A ⊆ U is shattered by S if each subset of A can
be expressed as the intersection of an element of S with A. The VC-dimension of the set
system (U, S) is the maximum size of any subset of U shattered by S.

219

B

A

D

(b)

C

(a)

Figure 6.8: (a) shows a set of four points that can be shattered by rectangles along with
some of the rectangles that shatter the set. Not every set of four points can be shattered
as seen in (b). Any rectangle containing points A, B, and C must contain D. No set of ﬁve
points can be shattered by rectangles with axis-parallel edges. No set of three collinear
points can be shattered, since any rectangle that contains the two end points must also
contain the middle point. More generally, since rectangles are convex, a set with one point
inside the convex hull of the others cannot be shattered.

6.6.1 Examples of Set Systems and Their VC-Dimension

Rectangles with axis-parallel edges

There exist sets of four points that can be shattered by rectangles with axis-parallel
edges. For example, four points at the vertices of a diamond. However, rectangles with
axis-parallel edges cannot shatter any set of ﬁve points. To see this, assume for contra-
diction that there is a set of ﬁve points shattered by the family of axis-parallel rectangles.
Find the minimum enclosing rectangle for the ﬁve points. For each edge there is at least
one point that has stopped its movement. Identify one such point for each edge. The
same point maybe identiﬁed as stopping two edges if it is at a corner of the minimum
enclosing rectangle. If two or more points have stopped an edge, designate only one as
having stopped the edge. Now, at most four points have been designated. Any rectangle
enclosing the designated points must include the undesignated points. Thus, the subset
of designated points cannot be expressed as the intersection of a rectangle with the ﬁve
points. Therefore, the VC-dimension of axis-parallel rectangles is four.

Intervals of the reals

Intervals on the real line can shatter any set of two points but no set of three points
since the subset of the ﬁrst and last points cannot be isolated. Thus, the VC-dimension
of intervals is two.

Pairs of intervals of the reals

220

Consider the family of pairs of intervals, where a pair of intervals is viewed as the set
of points that are in at least one of the intervals, in other words, their set union. There
exists a set of size four that can be shattered but no set of size ﬁve since the subset of ﬁrst,
third, and last point cannot be isolated. Thus, the VC-dimension of pairs of intervals is
four.

Convex polygons

Consider the set system of all convex polygons in the plane. For any positive integer
n, place n points on the unit circle. Any subset of the points are the vertices of a convex
polygon. Clearly that polygon will not contain any of the points not in the subset. This
shows that convex polygons can shatter arbitrarily large sets, so the VC-dimension is
inﬁnite.

Half spaces in d-dimensions

Deﬁne a half space to be the set of all points on one side of a hyper plane, i.e., a set

of the form {x|aT x ≥ a0}. The VC-dimension of half spaces in d-dimensions is d + 1.

There exists a set of size d + 1 that can be shattered by half spaces. Select the d
unit-coordinate vectors plus the origin to be the d + 1 points. Suppose A is any subset
of these d + 1 points. Without loss of generality assume that the origin is in A. Take a
0-1 vector a which has 1’s precisely in the coordinates corresponding to vectors not in A.
Clearly A lies in the half-space aT x ≤ 0 and the complement of A lies in the complemen-
tary half-space.

We now show that no set of d + 2 points can be shattered by half spaces. To this end,
we ﬁrst show that any set of d + 2 points can be partitioned into two disjoint subsets A
and B of points whose convex hulls intersect. Let convex (A) and convex(B) denote the
convex hull of the sets of points in A and B. First consider four points in 2-dimensions. If
any three of the points lie on a straight line, then the mid point lies in the convex hull of
the other two. Thus, assume that no three of the points lie on a straight line. Select three
of the points. The three points must form a triangle. Extend the edges of the triangle
to inﬁnity. The three lines divide the plane into seven regions, one ﬁnite and six inﬁnite.
Place the fourth point in the plane. If the point is placed in the triangle, then it and the
convex hull of the triangle intersect. If the fourth point lies in a two sided inﬁnite region,
the convex hull of the point plus the two opposite points of the triangle contains the third
vertex of the triangle. If the fourth point is in a three sided region, the convex hull of the
point plus the opposite vertex of the triangle intersects the convex hull of the other two
points of the triangle.

Consider d + 2 points in d-dimensions and assume we have established the claim for
dimensions less than d. Thus, if d+1 points lie on a d−1-dimensional hyper plane, then we

221

are done. Assume that d+1 points are in general position and form a hyper tetrahedron in
d-space. Extend the d − 1 dimensional faces to hyper planes. The hyper planes partition
d-space into a ﬁnite region, the tetrahedron, and a number of inﬁnite regions. Each inﬁnite
region contain a vertex, edge, face, etc. of the ﬁnite region. Refer to the component of
the ﬁnite region that meets an inﬁnite region as a face of the tetrahedron. Let the points
of the face be one subset and the remaining vertices of the tetrahedron plus a point in
the inﬁnite region be the other subset. The convex hulls of these two subsets intersect.
The reader is encouraged to develop these ideas into a geometric proof. Here, instead, we
present an algebraic proof.

Theorem 6.5 (Radon): Any set S ⊆ Rd with |S| ≥ d + 2, can be partitioned into two
disjoint subsets A and B such that convex(A) ∩ convex(B) (cid:54)= φ.

Proof: Without loss of generality, assume |S| = d + 2. Form a d × (d + 2) matrix
with one column for each point of S. Call the matrix A. Add an extra row of all
1’s to construct a (d + 1) × (d + 2) matrix B. Clearly, since the rank of this matrix
is at most d + 1, the columns are linearly dependent. Say x = (x1, x2, . . . , xd+2) is
a nonzero vector with Bx = 0. Reorder the columns so that x1, x2, . . . , xs ≥ 0 and
s
(cid:80)
|xi| = 1. Let bi (respectively ai) be the ith
xs+1, xs+2, . . . , xd+2 < 0. Normalize x so
i=1

column of B (respectively A). Then,

s
(cid:80)
i=1

|xi|ai =

d+2
(cid:80)
i=s+1

|xi|ai and

s
(cid:80)
i=1

|xi| =

s
(cid:80)
i=1
d+2
(cid:80)
i=s+1

d+2
(cid:80)
i=s+1
s
(cid:80)
i=1

|xi|bi =

|xi|bi from which it follows that

|xi|. Since

|xi| = 1 and

d+2
(cid:80)
i=s+1

|xi| = 1 each

side of

s
(cid:80)
i=1

|xi|ai =

d+2
(cid:80)
i=s+1

|xi|ai is a convex combination of columns of A which proves the

theorem. Thus, S can be partitioned into two sets, the ﬁrst consisting of the ﬁrst s points
after the rearrangement and the second consisting of points s + 1 through d + 2 . Their
convex hulls intersect as required.

Radon’s theorem immediately implies that half-spaces in d-dimensions do not shat-
ter any set of d + 2 points. Divide the set of d + 2 points into sets A and B where
convex(A) ∩ convex(B) (cid:54)= φ. Suppose that some half space separates A from B. Then
the half space separates the convex hulls of A and B. Thus, convex(A) ∩ convex(B) = ∅
a contradiction. Therefore, no set of d + 2 points can be shattered by half planes in
d-dimensions.

Spheres in d-dimensions

A sphere in d-dimensions is a set of points of the form {x| |x − x0| ≤ r}. The VC-
dimension of spheres is d + 1. It is the same as that of half spaces. First, we prove that
no set of d + 2 points can be shattered by spheres. Suppose some set S with d + 2 points
can be shattered. Then for any partition A1 and A2 of S, there are spheres B1 and B2
such that B1 ∩ S = A1 and B2 ∩ S = A2. Now B1 and B2 may intersect, but there is no

222

point of S in their intersection. It is easy to see that there is a hyperplane perpendicular
to the line joining the centers of the two spheres with all of A1 on one side and all of A2
on the other and this implies that half spaces shatter S, a contradiction. Therefore no
d + 2 points can be shattered by hyperspheres.

It is also not diﬃcult to see that the set of d+1 points consisting of the unit-coordinate
vectors and the origin can be shattered by spheres. Suppose A is a subset of the d + 1
points. Let a be the number of unit vectors in A. The center a0 of our sphere will be
the sum of the vectors in A. For every unit vector in A, its distance to this center will
a + 1.
be
The distance of the origin to the center is
a. Thus, we can choose the radius so that
precisely the points in A are in the hypersphere.

a − 1 and for every unit vector outside A, its distance to this center will be

√

√

√

Finite sets

The system of ﬁnite sets of real numbers can shatter any ﬁnite set of real numbers

and thus the VC-dimension of ﬁnite sets is inﬁnite.

6.6.2 The Shatter Function

Consider a set system (U, S) of ﬁnite VC-dimension d. For n ≤ d there exists a subset
A ⊆ U , |A| = n, such that A can be shattered into 2n pieces. This raises the question for
|A| = n, n > d, as to what is the maximum number of subsets of A expressible as S ∩A for
S ∈ S. We shall see that this maximum number is at most a polynomial in n with degree d.

The shatter function πS(n) of a set system (U, S) is the maximum number of subsets
that can be deﬁned by the intersection of sets in S with some n element subset A of U .
Thus

πS(n) = max
A⊆U
|A|=n

|{A ∩ S|S ∈ S}|

For small values of n, πS(n) will grow as 2n. Once n equals the VC-dimension of S,
it grows more slowly. The deﬁnition of VC-dimension can clearly be reformulated as
dim(S) = max{n|πS(n) = 2n}. Curiously, the growth of πS (n) must be either polynomial
or exponential in n. If the growth is exponential, then the VC-dimension of S is inﬁnite.

Examples of set systems and their shatter function.

Example: Half spaces and circles in the plane have VC-dimension three. So, their
shatter function is 2n for n=1, 2, and 3. For n > 3, their shatter function grows as a
polynomial of degree three in n. Axis-parallel rectangles have VC-dimension four and
thus their shatter function is 2n for n=1,2, 3, and 4. For n >4, their shatter function
grows as a polynomial of degree four in n.

223

Maximum
number of
subsets
deﬁned
by sets in S

d

n

Figure 6.9: The shatter function for a set system of VC-dimension d

We already saw that for axis-parallel rectangles in the plane, there are at most O(n4)
possible subsets of an n element set that arise as intersections with rectangles. The
argument was that one can move the sides of the rectangle until each side is “blocked” by
one point. We also saw that the VC-dimension of axis-parallel rectangles is four. We will
see here that the two fours, one in the exponent of n and the other the VC-dimension,
being equal is no accident. There is another four related to rectangles, that is, it takes
four parameters to specify an axis-parallel rectangle. Although the VC-dimension of a
collection of sets is often closely related to the number of free parameters, this latter four
is a coincidence.

6.6.3 Shatter Function for Set Systems of Bounded VC-Dimension

For any set system (U, S) of VC-dimension d, the quantity

d
(cid:88)

i=0

(cid:19)

(cid:18)n
i

=

(cid:19)

(cid:18)n
0

+

(cid:19)

(cid:18)n
1

+ · · · +

(cid:19)

(cid:18)n
d

≤ 2nd

(cid:1) bounds the number of subsets of any
bounds the shatter function πS (n). That is,
n point subset of U that can be expressed as the intersection with a set of S. Thus, the
shatter function πS (n) is either 2n if d is inﬁnite or it is bounded by a polynomial of
degree d.

(cid:0)n
i

d
(cid:80)
i=0

Lemma 6.6 For any set system (U, S) of VC-dimension at most d, πS (n) ≤

all n.

d
(cid:80)
i=0

(cid:0)n
i

(cid:1) for

Proof: The proof is by induction on d and n. The base case will handle all pairs (d, n)
with either n ≤ d or d = 0. The general case (d, n) will use the inductive assumption on
the cases (d − 1, n − 1) and (d, n − 1).

d
(cid:80)
i=0

n
(cid:80)
i=0

(cid:0)n
i

(cid:1) =

For n ≤ d,

(cid:1) = 2n and πS (n) = 2n. For d = 0, a set system (U, S) can
have at most one set in S since if there were two sets in S there would exist a set A consist-
ing of a single element that was contained in one of the sets but not in the other that could

(cid:0)n
i

224

be shattered. If S contains only one set, then πS(n) = 1 for all n and for d = 0,

d
(cid:80)
i=0

(cid:0)n
i

(cid:1) = 1.

Consider the case for general d and n. Select a subset A of U of size n such that πS(n)
subsets of A can be expressed as A ∩ S for S in S. Without loss of generality, we may
assume that U = A and replace each set S ∈ S by S ∩ A removing duplicate sets; i.e., if
S1 ∩ A = S2 ∩ A for S1 and S2 in S, keep only one of them. Now each set in S corresponds
(cid:1), we only need to show
to a subset of A and πS(n) = |S|. Thus, to show πS(n) ≤

d
(cid:80)
i=0

(cid:0)n
i

|S| ≤

d
(cid:80)
i=0

(cid:0)n
i

(cid:1).

Remove some element u from the set A and from each set in S. Consider the set system
S1 = (A − {u} , {S − {u}|S ∈ S}). For S ⊆ A − {u}, if exactly one of S and S ∪ {u} is in
S, then the set S contributes one set to both S and S1, whereas, if both S and S ∪ {u}
are in S, then they together contribute two sets to S, but only one to S1. Thus |S1| is less
than |S| by the number of pairs of sets in S that diﬀer only in the element u. To account
for this diﬀerence, deﬁne another set system

S2 = (A − {u}, {S|both S and S ∪ {u} are in S}) .

Then

or

|S| = |S1| + |S2| = πS1(n − 1) + πS2(n − 1)

πS (n) = πS1(n − 1) + πS2(n − 1).

We make use of two facts

(1) S1 has dimension at most d, and

(2) S2 has dimension at most d − 1.

(1) follows because if S1 shatters a set of cardinality d + 1, then S also would shatter
that set producing a contradiction. (2) follows because if S2 shattered a set B ⊆ A − {u}
with |B| ≥ d, then B ∪ {u} would be shattered by S where |B ∪ {u}| ≥ d + 1, again
producing a contradiction.

By the induction hypothesis applied to S1, we have |S1| = πS1 (n − 1) ≤

d
(cid:80)
i=0

(cid:0)n−1
i

(cid:1). By

the induction hypotheses applied to S2, we have |S2| = πS2 (n − 1) ≤

d−1
(cid:80)
i=0

(cid:0)n−1
i

(cid:1).

225

Since (cid:0)n−1

(cid:1) + (cid:0)n−1

(cid:1) = (cid:0)n

(cid:1) and (cid:0)n−1

d−1

d

(cid:1)
(cid:1) = (cid:0)n

0

0

d

πS(n) ≤ πS1 (n − 1) + πS2 (n − 1)
(cid:1) + (cid:0)n−1
(cid:1) + (cid:2)(cid:0)n−1

0

1

d

(cid:1) + · · · + (cid:0)n−1
(cid:1) + (cid:0)n−1
(cid:1).

0

≤ (cid:0)n−1
≤ (cid:0)n−1
≤ (cid:0)n

0

(cid:1) + · · · + (cid:0)n

(cid:1) + (cid:0)n

1

0

1

d

(cid:1) + (cid:0)n−1
(cid:1)(cid:3) + · · · + (cid:2)(cid:0)n−1

0

(cid:1) + (cid:0)n−1

(cid:1)
(cid:1) + · · · + (cid:0)n−1

d−1

1

(cid:1) + (cid:0)n−1

d−1

(cid:1)(cid:3)

d

6.6.4

Intersection Systems

Let (U, S1) and (U, S2) be two set systems on the same underlying set U . Deﬁne another
set system, called the intersection system, (U, S1∩S2), where S1∩S2 = {A∩B|A ∈ S1; B ∈
S2}. In words, take the intersections of every set in S1 with every set in S2. A simple
example is U = Rd and S1 and S2 are both the set of all half spaces. Then S1 ∩ S2 consists
of all sets deﬁned by the intersection of two half spaces. This corresponds to taking the
Boolean AND of the output of two threshold gates and is the most basic neural net besides
a single gate. We can repeat this process and take the intersection of k half spaces. The
following simple lemma helps us bound the growth of the shatter function as we do this.

Lemma 6.7 Suppose (U, S1) and (U, S2) are two set systems on the same set U . Then

πS1∩S2(n) ≤ πS1(n)πS2(n).

Proof: First observe that for B ⊆ A if A∩S1 and A∩S2 are the same sets, then B∩S1 and
B ∩ S2 must also be the same sets. Thus for B ⊆ A, |{B ∩ S|S ∈ S}| ≤ |{A ∩ S|S ∈ S}|
The proof then follows from the fact that for any A ⊆ U , the number of sets of the form
A ∩ (S1 ∩ S2) with S1 ∈ S1 and S2 ∈ S2 is at most the number of sets of the form A ∩ S1
times the number of sets of the form A ∩ S2 since for ﬁxed S1, |(A ∩ S1) ∩ S2| ≤ |A ∩ S2| .

6.7 The VC Theorem

The VC theorem estimates the number of labeled training examples needed to train a
good predictor of unlabeled test examples. Assume the examples are vectors and let U be
the set of all vectors in the relevant space. Let (U, H) be a set system. We assume that
there is a subset H ∈ H according to which examples are labeled. Each x ∈ H gets the
label +1 and each x /∈ H gets the label −1. Our task is to learn a representation of H
from a set of labeled training examples, so as to be able to predict labels of future exam-
ples. In learning theory, H is called a concept and in statistics it is called an hypothesis.
Here, we will call it an hypothesis.

We are given a set S of points in U , each labeled according to an unknown hypothesis
H ∈ H. Our task is to learn H. In the case of half spaces, learning H exactly with a

226

ﬁnite number of training examples may not be possible. So we modify the task to learn a
hypothesis H (cid:48) which is approximately the same as H. How do we measure the diﬀerence
between H and H (cid:48)? For half spaces, there is a natural notion of angle. For general (U, H),
there may not be such a notion. Even in the case of half spaces, if some regions of space
are more important than others, angles and distances, which are the same everywhere in
space, may not be the correct measure of approximation.

Valiant formulated the theoretical model of learning that gives an elegant answer to
these issues. In Valiant’s model, there is a probability distribution p, which the learning
algorithm may not know. Training examples are picked in independent identical trials,
each according to p. Each training example is labeled ±1 as per an unknown hypothesis
H ∈ H. The purpose of learning is to come up with a hypothesis H (cid:48) ∈ H that is used to
predict labels of future test examples which are also picked in independent trials accord-
ing to the same probability distribution p on U . The key insight here is to use the same
probability to pick the training examples as the test examples.

Deﬁne the prediction error to be the probability that the label of a test example is
predicted wrongly. Prediction error for a predictor H (cid:48) is p(H(cid:52)H (cid:48)) since the symmetric
diﬀerence H(cid:52)H (cid:48) 10 is the set of examples on which the true hypothesis H and our pre-
dictor H (cid:48) disagree. Since the learning algorithm only sees the set of training examples,
the algorithm can come up with any hypothesis consistent with all the training examples.
The central question is: How many training examples are suﬃcient so that any hypothesis
consistent with all training examples makes prediction error of at most ε? The training
examples should rule out all possible H (cid:48) with p(H(cid:52)H (cid:48)) > ε. For this, it is suﬃcient
that at least one training example land in H(cid:52)H (cid:48) for every such H (cid:48). The H label of the
example will be the opposite of its H (cid:48) label ruling out H (cid:48).

The VC theorem below bounds the number of training examples needed in terms of
the VC-dimension of the set system (U, H). First a technical lemma needed in the proof.

Lemma 6.8 If y ≥ x ln x, then

provided x >4.

2y
ln y

≥ x

Proof: First consider the situation where y = x ln x. Then ln y = ln x + ln ln x ≤ 2 ln x.
2 ln x ≥ x. It is easy to see by diﬀerentiation that 2y
Thus 2y
ln y is a monotonically
increasing function of y in the range y ≥ x ln x and x > 4. Thus, the lemma follows.

ln y ≥ 2x ln x

Theorem 6.9 (Vapnik-Chervonenkis Theorem) Let (U, H) be a set system with VC-
dimension d ≥ 2 and let p be a probability distribution on U . Let S be a set of m

10For two sets H and H (cid:48), we denote their symmetric diﬀerence by H(cid:52)H (cid:48), namely, the set of elements

belonging to precisely one of the sets H or H (cid:48).

227

(cid:1) , the probability
independent samples picked from U according to p. For m ≥ 1000d
that there exist sets H and H (cid:48) in H with p(H(cid:52)H (cid:48)) ≥ ε for which S ∩ (H(cid:52)H (cid:48)) = ∅ is at
most e−εm/8.

ln (cid:0) d

ε

ε

Proof: The theorem asserts that a suﬃciently large sample set S with high probability
intersects every H(cid:52)H (cid:48) with p(H(cid:52)H (cid:48)) ≥ ε. It is easy to prove that for a particular H and
H (cid:48) in H, the probability that S misses H(cid:52)H (cid:48) is small. But H potentially has inﬁnitely
many sets. So, a union bound is not suﬃcient to prove the theorem.

We begin with an intuitive explanation of the proof. Let S1 be a set of m samples
and suppose for one pair H and H (cid:48) in H with p(H(cid:52)H (cid:48)) ≥ ε, the symmetric diﬀerence
H(cid:52)H (cid:48) is missed by S1. According to p pick a second set S2 of m samples independent
of S1. With high probability, S2 will have at least εm/2 samples from the set H(cid:52)H (cid:48).
Thus, if there is some H and H (cid:48) in H with p(H(cid:52)H (cid:48)) ≥ ε, which is missed by S1, then
there is some H and H (cid:48) in H with p(H(cid:52)H) ≥ ε whose symmetric diﬀerence is missed by
S1, while S2 has εm/2 of its elements. The proof of the theorem lies in showing that this
latter situation occurs with very low probability.

Instead of picking S1 and then S2, pick a set W of 2m independent samples from U.
Pick one of the (cid:0)2m
(cid:1) subsets of W of cardinality m uniformly at random for S1 and let the
remainder be S2. We claim that these two processes give the same distribution on S1 and
so we may use either process in our arguments. The proof uses each process at diﬀerent
places. Hence the technique is called double sampling.

m

Consider the second process of picking W and then S1 and S2 from W . Let H and
H (cid:48) be generic elements of H. If |W ∩ (H(cid:52)H (cid:48))| ≥ εm/2, then it is highly unlikely that a
random m-subset of W will completely miss H(cid:52)H (cid:48), so the probability of the event that
H(cid:52)H (cid:48) is missed by S1, but H(cid:52)H (cid:48) has intersection at least εm/2 with S2 is very small.
By a Chernoﬀ bound, this probability falls oﬀ exponentially in m. Since this only works
for a single pair of H and H (cid:48), We are still faced with the problem of the union bound over
possibly inﬁnitely many sets.

Once W is picked, we only need to worry about the (H(cid:52)H (cid:48)) ∩ W for all the H and
H (cid:48) in H. Even though there may be inﬁnitely many H and H (cid:48), the number of possible
H ∩ W with H ∈ H is at most the shatter function of 2m, which grows with 2m as a
polynomial of degree equal to the VC dimension d of the set system. The number of
possible (H(cid:52)H (cid:48)) ∩ W is at most the square of the number of possible H ∩ W , since
(H(cid:52)H (cid:48)) ∩ W = (H ∩ W )(cid:52)(H (cid:48) ∩ W ). So, we only need to ensure that the failure prob-
ability for each H and H (cid:48) multiplied by a polynomial in 2m of degree 2d is o(1). By a
simple calculation m ∈ Ω((d/ε) log(d/ε)) suﬃces.

More formally, deﬁne two events E1 and E2. Let E1 be the event that there exist H

228

and H (cid:48) and T = H(cid:52)H (cid:48), with |T | ≥ ε|U | and all points in S1 miss T .

E1

∃ H and H (cid:48) in H with |T | ≥ ε|U | and |T ∩ S1| = ∅

Let E2 be the event that there exists an H and H (cid:48) with |T | ≥ ε|U |, all points in S1 miss
T , and S2 intersects T in at least εm/2 points. That is,

E2

∃ H and H (cid:48) in H with |T | ≥ ε|U |, |T ∩ S1| = ∅ and |T ∩ S2| ≥

ε
2

m.

We wish to show that Prob(E1) is very low. First we show that Prob(E2|E1) ≥ 1/2. Then
the bulk of the proof goes to show that Prob(E2) is very low. Since

Prob(E2) ≥ Prob(E2|E1)Prob(E1)

this implies that Prob(E1) is very low.

We now show that Prob(E2|E1) ≥ 1/2. Given E1 there is a pair of sets H and H (cid:48) such
that T ∩ S1 = ∅. For this one pair H and H (cid:48), the probability that S2 ∩ T ≤ εm/2 is at
most 1/2 giving us Prob(E2|E1) ≥ 1/2.

Prob(E2) is bounded by the double sampling technique. Instead of picking S1 and
then S2, pick a set W of 2m samples. Then pick a subset of size m out of W without
replacement to be S1 and let S2 = W \ S1. The distribution of S1 and S2 obtained this
way is the same as picking S1 and S2 directly.

Now if E2 occurs, then for some H and H (cid:48) in H, with p(T ) ≥ ε, we have both
|T ∩ S1| = 0 and |T ∩ S2| ≥ ε
2m and S2 ⊆ W , it follows that
|T ∩ W | ≥ ε
2m and S1 is a random subset of cardinality m out of
W , the probability that |T ∩S1| = 0 is at most the probability of selecting m elements from
the 2m − ε
2m elements known to be in T . This probability is
at most

2m elements other than the ε

2m. Since |T ∩ S2| ≥ ε

2m. But if |T ∩ W | ≥ ε

(cid:1)
(cid:0)2m−(ε/2)m
m
(cid:1)
(cid:0)2m
m

≤

m(m − 1) · · · (m − ε
(2m)(2m − 1) · · · (2m − ε

2m + 1)

2m + 1)

≤ 2− εm
2 .

This is the failure probability for just one pair H and H (cid:48). The number of possible W ∩ H
is at most πS(2m) which from Lemma 6.6 is at most 2(2m)d ≤ m2d for m ≥ 4. So the
number of possible (H(cid:52)H (cid:48)) ∩ W is at most m4d. By the union bound, the probability is
at most m4d2−εm/2 ≤ m4de−εm/4. So we need to prove that m4de−εm/4 ≤ e−εm/8 or after
some manipulation that m
ε . Apply Lemma 6.8 with y = m and x = 64d/ε to get
the conclusion of the theorem.

ln m ≥ 32d

6.8 Simple Learning

Given the large amount of data available today, learning algorithms are becoming very
important. However, one can learn from very little data, even possibly learn to recognize

229

a category of objects from a single object. An example of this is a father with a book of
pictures and a three year old daughter. The parent goes through the book pointing at
pictures of cars, trucks, houses, dogs, etc. and mentions the name of each. He points to
a single picture of a ﬁre engine and says ”ﬁre engine”. Later that day while walking with
his daughter they see a ﬁre engine and the child points at it and says ”ﬁre engine”. How
did she learn from a single instance?

Suppose our brain gets signals that are binary and when we see an object we get a
0-1 100-dimensional vector with approximately 50 ones and 50 zeros. Thus, a category
of objects is associate with a vector have 50 speciﬁc coordinates one and the rest zero.
Of curse, individual objects in the category may have ﬁve or so extra ones and lack some
small number of ones. This is okay provided no two categories over lap by more than 25
ones.

When one sees an object a1, they could associate a weight vector w = a1 with that
category and will be able to correctly identify future objects in that category. As one sees
more and more objects in the category, their weight vector is modiﬁed and gradually gets
closer to the actual weight vector for the category.

An interesting direction of research is whether there are functions other than the linear
threshold that can be learned quickly. Suppose a category was deﬁned by the parity of
a certain set of 50 coordinates. Could one from a few labeled vectors of objects in the
category in linear time determine the 50 coordinates?

6.9 Bibliographic Notes

Leslie Valiant formulated the theory of learning in a foundational paper- “A Theory of the
learnable” [Val84]; this paper stipulates that the learning algorithm be measured on test
examples drawn from the same probability distribution from which the training examples
were drawn. The connection between Valiant’s learning model and the more classical no-
tion of Vapnik-Chervonekis dimension [VC71] was struck by Blumer, Ehrenfrucht, Hausler
and Warmuth [BEHW]. Boosting was ﬁrst introduced by Schapire [Sch90]. A general ref-
erence on machine learning is the book [Mit97] and a more theoretical introduction is
given in [KV95]. [SS01] is a reference on support vector machines and learning with ker-
nels. The basic idea in boosting of taking a weighted majority of several decisions, where
the weights get updated based on past experience has been used in economics as well
as other areas. A survey of many applications of this general method can be found in
[Aro11].

230

6.10 Exercises

Exercise 6.1 (Boolean OR has a linear separator ) Take as examples all the 2d
elements of {0, 1}d. Label the example by +1 if there is at least one coordinate with a +1
and label it by -1 if all its coordinates are 0. This is like taking the Boolean OR, except
that the coordinates are the real numbers 0 and 1 rather than true or false. Show that
there is a linear separator for the labeled examples. Show that we can achieve a margin
of Ω(1/d) for this problem.

Exercise 6.2 Repeat Exercise 6.1 for the AND function.

Exercise 6.3 Repeat Exercise 6.1 for majority and minority functions. [You may assume
d is odd for this problem.]

Exercise 6.4 Show that the parity function, the Boolean function that is 1 if and only if
an odd number of inputs is 1, cannot be represented as a threshold function.

Exercise 6.5 Apply the perceptron learning algorithm to the following data.

a1 = [1, 2] a2 = [−2, −1] a3 = [−1, 1] a4 = [−1, −1]
l1 = +1

l2 = −1

l3 = −1

l4 = +1

To simplify computation do not normalize the ai to be unit vectors. Run the algorithm until
(wT ai)lI > 0 for all i. Plot the successive weight vectors without the threshold component.

Exercise 6.6 Suppose the starting w in the perceptron learning algorithm made an angle
of 45◦ with the solution w∗ whose margin is δ. Show that the number of iterations satisﬁes
a smaller upper bound than 1
δ2 − 1 by a small modiﬁcation to the proof of Theorem 6.1?

Exercise 6.7 The proof of Theorem 6.1 shows that for every w∗, with li(w∗T ai) ≥ δ
for i = 1, 2, . . . , n, the cosine of the angle between w and w∗ is at least
t + 1 δ after t
√
iterations. (So, the angle is at most cos−1(
t + 1 δ).) What happens if there are multiple
w∗, all satisfying li(w∗T ai) ≥ δ for i = 1, 2, . . . , n? Then, how can our one w make a
small angle with all of these w∗?

√

Exercise 6.8 Suppose the examples are points in d-space with 0,1 coordinates and the
label of x ∈ {0, 1}d is +1 if and only if x (cid:54)= 0 and the least i for which xi = 1 is odd.
Otherwise the example’s label is -1. Show that the rule can be represented by the linear
threshold function

(x1, x2, . . . , xn) (cid:0)1, − 1

2, 1

4, − 1

8, . . .(cid:1)T = x1 −

1
2

x2 +

1
4

x3 −

1
8

x4 + · · · ≥ 0

Exercise 6.9 (Hard) Prove that for the problem of Exercise 6.8, we cannot have a
linear separator with margin at least 1/f (d) where f (d) is bounded above by a polynomial
function of d.

231

Exercise 6.10 (Hard) Recall the deﬁnition of margin where the linear separator is re-
quired to correctly classify all examples with a margin of at least δ. Suppose this condition
is relaxed to say that the linear separator classiﬁes all examples correctly and has a mar-
gin of at least δ on all but an (cid:15) fraction of the examples. Consider the following modiﬁed
version of the perceptron learning algorithm:

Start with w = (1, 0, 0, . . . , 0)
Repeat until (wai)T li > 0 for all but at most 2(cid:15) fraction of the examples

Add to w the average of all aili with (wai)T li ≤ 0

Show that this is a “noise-tolerant” version of the algorithm. Namely, show that with
the relaxed margin assumption, it correctly ﬁnds a linear separator that classiﬁes all but
at most a 2(cid:15) fraction correctly. Prove a bound on the number of steps the algorithm takes.
What goes wrong if we use the old unmodiﬁed algorithm with the relaxed assumption?

Hint: Go over the proof of theorem 6.1 (convergence of perceptron learning algorithm)
and adapt it. You need to modify the argument that the numerator increases in every step.

Exercise 6.11

1. Show that (6.3) can be reformulated as the unconstrained minimization of

|v|2 + c

(cid:88)

(cid:16)

1 − li(vai)T (cid:17)+

.

i

2. Show that x+ is a convex function.

The function x+ does not have a derivative at 0. The function (x+)2 is smoother (its ﬁrst
derivative at 0 exists) and it is better to minimize

|v|2 + c

(cid:88)

(cid:18)(cid:16)

1 − li(vai)T (cid:17)+(cid:19)2

.

i

Exercise 6.12 Assume that the center of Figure 6.5 is (0,0) and the side of each small
square is of length 1. Show that a point has label +1 if and only if

(x1 + 1)x1(x1 − 1)(x2 + 1)x2(x2 − 1) ≥ 0.

Consider only examples which are interior to a small square.

Exercise 6.13 Consider a set of examples in 2-dimensions where any example inside the
circle x2
2 = 1 is labeled +1 and any example outside the circle is labeled -1. Construct
a function ϕ so that the examples are linearly separable in the space ϕ (x).

1 + x2

Exercise 6.14 Find a function ϕ that maps each of the regions below to a space where
the regions are linearly separable.

232

1. {(x, y)| − 1 ≤ x ≤ 1}

2. {(x, y)| − 1 ≤ x ≤ 1, −1 ≤ y ≤ 1}

Exercise 6.15 (Hard) Label the points in the plane that are within the circle of radius
one as +1. Label the points in the annulus of inner radius one and outer radius two as
-1 and the points in an annulus of inner radius two and outer radius three as +1. Find
a function ϕ mapping the points to a higher dimensional space where the two sets are
linearly separable.

Exercise 6.16 Suppose examples are just real numbers in the interval [0, 1] and suppose
there are reals 0 < a1 < a2 < a3 < . . . < ak, 1 an example is labeled +1 iﬀ it is from
(0, a1) ∪ (a2, a3) ∪ (a4, a5) ∪ . . .. [So alternate intervals are labeled +1.] Show that there
is an embedding of the interval into an O(k) dimensional space where we have a linear
separator.

Exercise 6.17

1. Consider 2-dimensional points and let K be the kernel matrix where the entry for a =
(a1, a2) and b = (b1, b2) is (aT b)2. What is the mapping ϕ(a) such that K(a, b) =
ϕ(a) · ϕ(b)?

2. What mapping gives rise to the kernel e−|a−b|2?

Exercise 6.18 Let p be a polynomial of degree D with d variables. Prove the the number
of monomials in the polynomial p is at most

D
(cid:88)

i=0

(cid:19)

(cid:18)d + i − 1
d − 1

.

Then prove that

D
(cid:80)
i=0

(cid:0)d+i−1
d−1

(cid:1) ≤ D(d + D)min(d−1,D).

Exercise 6.19 Produce a polynomial p(x, y) whose arguments x and y are real numbers
and a set of real real numbers a1, a2, . . . so that the matrix Kij = p(ai, aj) is not positive
semi deﬁnite.

Exercise 6.20 Are social networks suﬃciently diﬀerent so that a network can be identi-
ﬁed by looking at a small region? One might try to answer this question by ﬁnding 100
regions in each of a number of social networks and training a support vector machine on
50 regions from each network labeled by the network they came from. The remaining 50
regions are then tested to see if the support vector machine can correctly classify must of
them. If it can, then the networks must be diﬀerent. To carry out this experiment, say
that a region (subgraph) is formed by selecting a vertex at random along with all vertices
within distance two of the selected vertex. The subgraph is then converted to a vector by
deﬁning a set of features such as the average degree of vertices in the subgraph. Create a
list of 10 possible features.

233

Figure 6.10: Data for exercise on boosting

Exercise 6.21 An n×n symmetric matrix A is positive semi-deﬁnite if for all x, xT Ax ≥
0. Prove that a positive semi-deﬁnite matrix A can be expressed as A = BBT .

Exercise 6.22 Using boosting with threshold logic units ﬁnd a solution to the data in
Figure 6.10. The shaded area is data labeled +1 and the unshaded area is data labeled -1.

Exercise 6.23 Make the proof that the majority of enough weak-learners in the boosting
section is a strong learner rigorous by using inequalities instead of ﬁrst order approxima-
tion. Prove that T = 3+ln n

ε2 will do for ε < γ/8

γε + 1

Exercise 6.24 (Experts picking stocks) Suppose there are n experts who are predict-
ing whether one particular stock will go up or down at each of t time periods. There are
only two outcomes at each time; up or down. You also have to make a prediction each
time and after you do so, the actual outcome for that time period will be revealed to you.
You may not assume any stochastic model of the experts (so past performance is no indi-
cation of the future). You are charged one for each wrong prediction. Can you pick nearly
as well as the best expert where the best expert is the one who made the least number of
wrong predictions overall? Show that boosting can help.

Exercise 6.25 Let f (x) = ax2 + bx + c and assume you measure f (x) for a number of
values of x. The measurements you make are corrupted by noise. You do not know f but
would like to ﬁt your data with some g(x) so that you could predict f (x) for additional
values of x. If you use a high degree polynomial you will have more parameters than you
need to ﬁt the real data and will ﬁt the noise. This is called over ﬁtting. What should
happen is as you go from degree 0 to 1 to 2 the predictive power should get better. As
you increase the degree of g beyond 2 the predictive power should decrease. See if you can
design an experiment to illustrate this eﬀect of over ﬁtting.

Exercise 6.26 What happens if in Section 6.5, instead of requiring

Prob

(cid:16)(cid:12)
(cid:12)
(cid:12)|R ∩ U | −

n
s

(cid:12)
(cid:12)
(cid:12) ≤ εn for every R
|R ∩ S|

(cid:17)

≥ 1 − δ,

one requires only:

234

Prob (cid:0)(cid:12)

(cid:12)|R ∩ U | − n

s |R ∩ S|(cid:12)

(cid:12) ≤ εn (cid:1) ≥ 1 − δ, for every R ?

Exercise 6.27 Given n points in the plane and a circle C1 containing at least three points,
i.e., at least three points lie on or inside it, show that there exists a circle C2 with at least
two of the points on its circumference containing the same set of points as C1.

Exercise 6.28 Is the following statement true or false? Suppose we have n points in the
plane and C1 is a circle containing at least three points. There exists a circle C2 with at
least three points lying on the circle C2 or two points lying on a diameter of C2 and the
set of points in C2 is the same as the set of points in C1. Either give a counter example
or a proof.

Exercise 6.29 Given n points in the plane deﬁne two circles as equivalent if they enclose
the same set of points. Prove that there are only O (n3) equivalence classes of points deﬁned
by circles and thus only O(n3) subsets out of the 2n subsets can be enclosed by circles.

Exercise 6.30 Prove that the VC-dimension of circles is three.

Exercise 6.31

1. What is the VC-dimension of axis aligned ellipses?

2. What is the VC-dimension of arbitrary ellipses?

Exercise 6.32 Consider a 3-dimensional space.

1. What is the VC-dimension of rectangular boxes with axis-parallel sides?

2. What is the VC-dimension of d-dimensional rectangular boxes with axis-parallel

sides?

3. What is the VC-dimension of spheres?

Exercise 6.33 Consider d + 1 points in general position that form a tetrahedron in d-
the hyper planes partition
space. Extend the d − 1 dimensional faces to hyper planes.
d-space into a ﬁnite region and a number of inﬁnite regions.

1. Select a point x in an inﬁnite region that intersects the tetrahedron in a d − 1
dimensional face. Let v be the vertex not on the d − 1 dimensional selected face.
Prove that the line from x to v intersects the d − 1 dimensional face.

2. Consider the 3-dimensional case. Select a point x in an inﬁnite region that intersects
the tetrahedron in an edge e. Let v1 and v2 be the two vertices not on the edge. Prove
that the convex hull of {x, v1, v2} intersects the edge. That is, one can draw a line
from x to the edge (v1, v2) that intersects the edge e of the tetrahedron.

3. Prove that the convex hull of a point in an inﬁnite region plus the vertices not on
the face of the tetrahedron that meets the inﬁnite region intersects the convex hull
of the face.

235

Exercise 6.34 (Squares) Show that there is a set of three points which can be shattered
by axis-parallel squares. Show that the system of axis-parallel squares cannot shatter any
set of four points.

Exercise 6.35 Show that the VC-dimension of axis-aligned right triangles with the right
angle in the lower left corner is four.

Exercise 6.36 Prove that the VC-dimension of 45◦, 45◦, 90◦ triangles with right angle
in the lower left is four.

Exercise 6.37 Show that the VC-dimension of arbitrary right triangles is seven.

Exercise 6.38 What is the VC-dimension of triangles?

Exercise 6.39 Prove that the VC dimension of convex polygons is inﬁnite.

Exercise 6.40 If a class contains only convex sets prove that it cannot shatter any set
in which some point is in the convex hull of other points in the set.

Exercise 6.41

1. Show that there exists a set of six points that can be shattered by squares in arbitrary

position (rotation allowed).

2. Find an upper bound on the VC-dimension of squares in arbitrary position.

Exercise 6.42

1. Show that the set of seven vertices of a regular heptagon can be shattered by rotated

rectangles.

2. Prove that no set of eight points can be shattered by rotated rectangles there by

showing that the VC-dimension of rectangles in arbitrary position is 7.

Exercise 6.43 What is the VC-dimension of the family of quadrants? A quadrant Q is
a set of points of one of the four types below:

1. Q = {(x, y) : (x − x0, y − y0) ≥ (0, 0)},

2. Q = {(x, y) : (x0 − x, y − y0) ≥ (0, 0)},

3. Q = {(x, y) : (x0 − x, y0 − y) ≥ (0, 0)}, or

4. Q = {(x, y) : (x − x0, y0 − y) ≥ (0, 0)}.

Exercise 6.44 Create a list of simple shapes for which we can calculate the VC-dimension
and indicate the VC-dimension for each shape on your list.

236

Exercise 6.45 For large n, how should you place n points on the plane so that the max-
imum number of subsets of the n points are deﬁned by rectangles? Can you achieve 4n
subsets of size 2? Can you do better? What about size 3? What about size 10?

Exercise 6.46 For large n, how should you place n points on the plane so that the max-
imum number of subsets of the n points are deﬁned by

1. half spaces?

2. circles?

3. axis-parallel rectangles?

4. some other simple shape of your choosing?

For each of the shapes how many subsets of size two, three, etc can you achieve?

Exercise 6.47 What is the shatter function for 2-dimensional half spaces? That is, given
n points in the plane, how many subsets can be deﬁned by half spaces?

Exercise 6.48 What does it mean to shatter the empty set? How many subsets does one
get?

Exercise 6.49 Intuitively deﬁne the most general form of a set system of VC-dimension
one. Give an example of such a set system that can generate n subsets of an n element
set. What is the form of the most general set system of dimension two.

Exercise 6.50 (Hard) We proved that if the VC-dimension is small, then the shatter
function is small as well. Can you prove some sort of converse to this?
Exercise 6.51 If (U, S1), (U, S2), . . . , (U, Sk) are k set systems on the same ground set U
show that πS1∩S2∩···Sk(n) ≤ πS1(n)πS2(n) · · · πSk(n).
Exercise 6.52 Show that in the “double sampling” procedure, the probability of picking
a pair of multi-sets T and T (cid:48), each of cardinality m, by ﬁrst picking T and then T (cid:48) is the
same as picking a W of cardinality 2m and then picking uniformly at random a subset T
out of W of cardinality m and letting T (cid:48) be W − T . For this exercise, assume that p, the
underlying probability distribution is discrete.

Exercise 6.53 Randomly select n integers from the set {1, 2, . . . , 2n} without replace-
ment. In the limit as n goes to inﬁnity, what is the probability of not selecting any integer
in the set {1, 2, . . . , k} for k a constant independent of n? For k = ln n?

Exercise 6.54 Write a short paragraph about what you learned in this chapter.

Exercise 6.55 What is the maximum number of 100-dimensional 0-1 vectors with ﬁfty
coordinates one such that no two vectors overlap by more than 25 ones?

Exercise 6.56 How many n-dimensional 0-1 vectors

1. with two ones?

2. with three ones with no two vectors over lapping by more than one?

237

7 Algorithms for Massive Data Problems

Massive Data, Sampling

This chapter deals with massive data problems where the input data, a graph, a ma-
trix or some other object, is too large to be stored in random access memory. One model
for such problems is the streaming model, where the data can be seen only once. In the
streaming model, the natural technique to deal with the massive data is sampling. Sam-
pling is done “on the ﬂy”. As each piece of data is seen, based on a coin toss, one decides
whether to include the data in the sample. Typically, the probability of including the data
point in the sample may depend on its value. Models allowing multiple passes through
the data are also useful; but the number of passes needs to be small. We always assume
that random access memory, RAM, is limited, so the entire data cannot be stored in RAM.

To introduce the basic ﬂavor of sampling on the ﬂy, consider the following primitive.
From a stream of n positive real numbers, a1, a2, . . . , an, draw a sample element ai so that
the probability of picking an element is proportional to its value. It is easy to see that
the following sampling method works. Upon seeing a1, a2, . . . , ai, keep track of the sum
a = a1 + a2 + · · · + ai and a sample aj, j ≤ i, drawn with probability proportional to
its value. On seeing ai+1, replace the current sample by ai+1 with probability ai+1
and
a+ai+1
update a. If the current element is replaced by ai+1, then clearly ai+1 is selected with
probability proportional to its value. If the current element is not replaced, then aj is the
selected element and its probability of having been selected is

aj
a1 + a2 + · · · ai

(cid:18)

1 −

ai+1
a1 + a2 + · · · + ai+1

(cid:19)

=

aj
a1 + a2 + · · · ai+1

.

7.1 Frequency Moments of Data Streams

An important class of problems concerns the frequency moments of data streams.
Here a data stream a1, a2, . . . , an of length n consists of symbols ai from an alphabet of
m possible symbols, which for convenience we denote as {1, 2, . . . , m}. Throughout this
section, n, m, and ai will have these meanings and s, for symbol, will denote a generic
element of {1, 2, . . . , m}. The frequency fs of the symbol s is the number of occurrences
of s in the stream. For a nonnegative integer p, the pth frequency moment of the stream
is

m
(cid:88)

f p
s .

Note that the p = 0 frequency moment corresponds to the number of distinct symbols
occurring in the stream. The ﬁrst frequency moment is just n, the length of the string.
The second frequency moment, (cid:80)
f 2
s , is useful in computing the variance of the stream.

s

s=1

1
m

m
(cid:88)

(cid:16)

s=1

fs −

(cid:17)2

n
m

=

1
m

m
(cid:88)

s=1

(cid:18)

f 2
s − 2

n
m

fs +

(cid:16) n
m

(cid:17)2(cid:19)

=

1
m

m
(cid:88)

s=1

f 2
s −

n2
m2

238

In the limit as p becomes large,

ment(s).

(cid:19)1/p

(cid:18) m
(cid:80)
s=1

f p
s

is the frequency of the most frequent ele-

We will describe sampling based algorithms to compute these quantities for streaming
data shortly. But ﬁrst a note on the motivation for these various problems. The identity
and frequency of the the most frequent item or more generally, items whose frequency
exceeds a fraction of n, is clearly important in many applications. If the items are packets
on a network with source destination addresses, the high frequency items identify the
heavy bandwidth users. If the data is purchase records in a supermarket, the high fre-
quency items are the best-selling items. Determining the number of distinct symbols is
the abstract version of determining such things as the number of accounts, web users, or
credit card holders. The second moment and variance are useful in networking as well as
in database and other applications. Large amounts of network log data are generated by
routers that can record for all the messages passing through them, the source address,
destination address, and the number of packets. This massive data cannot be easily sorted
or aggregated into totals for each source/destination. But it is important to know if a few
popular source-destination pairs generate a lot of the traﬃc for which the second moment
is the natural measure.

7.1.1 Number of Distinct Elements in a Data Stream

Consider a sequence a1, a2, . . . , an of n elements, each ai an integer in the range 1 to m
where n and m are very large. Suppose we wish to determine the number of distinct ai in
the sequence. Each ai might represent a credit card number extracted from a sequence of
credit card transactions and we wish to determine how many distinct credit card accounts
there are. The model is a data stream where symbols are seen one at a time. We ﬁrst
show that any deterministic algorithm that determines the number of distinct elements
exactly must use at least m bits of memory.

Lower bound on memory for exact deterministic algorithm

Suppose we have seen the ﬁrst k ≥ m symbols of the stream. The set of distinct
symbols seen so far could be any of the 2m subsets of {1, 2, . . . , m}. Each subset must
result in a diﬀerent state for our algorithm and hence m bits of memory are required. To
see this, suppose ﬁrst that two diﬀerent size subsets of distinct symbols lead to the same
internal state. Then our algorithm would produce the same count of distinct symbols
for both inputs, clearly an error for one of the input sequences. If two sequences with
the same number of distinct elements but diﬀerent subsets lead to the same state, then
seeing a symbol that appeared in one sequence but not the other would result in subsets
of diﬀerent sizes and thus require diﬀerent states.

Algorithm for the Number of distinct elements

239

|S| + 1 subsets

(cid:125)(cid:124)

(cid:123)

(cid:122)

m
|S|+1

Figure 7.1: Estimating the size of S from the minimum element in S which has value
approximately m
|S|+1. The elements of S partition the set {1, 2, . . . , m} into |S| + 1 subsets
each of size approximately m

|S|+1.

In estimating a quantity such as the number of distinct elements, we are interested in
the relative error not the absolute error. For example, we may want to estimate a quantity
so that our estimate is within a multiplicative factor of 1 ± (cid:15) of the correct value. Thus,
the variance of our estimate may be as large as the square of the quantity itself. We can
reduce the variance by multiple independent estimates. With 1
(cid:15)2 independent estimates,
the variance is reduced by a multiplicative factor of (cid:15)2 and the standard deviation is re-
duced by a multiplicative factor of (cid:15). Thus with 1
(cid:15) independent estimates, the estimate is
highly likely to be within a multiplicative constant of 1 + c(cid:15) of the correct value for some
small constant c.

Let a1, a2, . . . , an be a sequence of elements where each ai ∈ {1, 2, . . . , m}. The number
of distinct elements can be estimated with O(log m) space. Let S ⊆ {1, 2, . . . , m} be the
set of elements that appear in the sequence. Suppose that the elements of S were selected
uniformly at random from {1, 2, . . . , m}. Let min denote the minimum element of S.
Knowing the minimum element of S allows us to estimate the size of S. The elements of
S partition the set {1, 2, . . . , m} into |S| + 1 subsets each of size approximately m
|S|+1. See
Figure 7.1. Thus, the minimum element of S should have value close to m
|S|+1. Solving
min = m
min − 1. Since we can determine min, this gives us an estimate
of |S|.

|S|+1 yields |S| = m

The above analysis required that the elements of S were picked uniformly at random
from {1, 2, . . . , m}. This is generally not the case when we have a sequence a1, a2, . . . , an
of elements from {1, 2, . . . , m}. Clearly if the elements of S were obtained by selecting the
|S| smallest elements of {1, 2, . . . , m}, the above technique would give the wrong answer.
If the elements are not picked uniformly at random, can we estimate the number of distinct
elements? The way to solve this problem is to use a hash function h where

h : {1, 2, . . . , m} → {0, 1, 2, . . . , M − 1}

To count the number of distinct elements in the input, count the number of elements
in the mapped set {h (a1) , h (a2) , . . .}. The point being that {h (a1) , h (a2) , . . .} behaves

240

like a random subset and so the above heuristic argument using the minimum to estimate
the number of elements may apply. If we needed h (a1) , h (a2) , . . . to be completely inde-
pendent, the space needed to store the hash function would too high. Fortunately, only
2-way independence is needed. We recall the formal deﬁnition of 2-way independence
below. But ﬁrst recall that a hash function is always chosen at random from a family of
hash functions and phrases like “probability of collision” refer to the probability in the
choice of hash function.

Universal Hash Functions

A set of hash functions

H = {h | h : {1, 2, . . . , m} → {0, 1, 2, . . . , M − 1}}

is 2-universal if for all x and y in {1, 2, . . . , m}, x (cid:54)= y, and for all z and w in {0, 1, 2, . . . , M − 1}

Prob (cid:0)h (x) = z and h (y) = w(cid:1) = 1
M 2

for a randomly chosen h. The concept of a 2-universal family of hash functions is that
given x, h (x) is equally likely to be any element of {0, 1, 2, . . . , M − 1} and for x (cid:54)= y,
h (x) and h (y) are independent.

We now give an example of a 2-universal family of hash functions. For simplicity let M
be a prime. For each pair of integers a and b in the range [0,M -1], deﬁne a hash function

hab (x) = ax + b mod (M )

To store the hash function hab, store the two integers a and b. This requires only O(log M )
space. To see that the family is 2-universal note that h(x) = z and h(y) = w if and only
if

(cid:19) (cid:18) a
b

(cid:19)

(cid:18) z
w

=

(cid:19)

mod (M )

(cid:18) x 1
y 1
(cid:19)

(cid:18) x 1
y 1

If x (cid:54)= y, the matrix

is invertible modulo M and there is only one solution for

a and b. Hence, for a and b chosen uniformly at random, the probability of the equation
holding is exactly 1

M 2 . Thus,

Prob (cid:0)hab(x) = z and hab(y) = w(cid:1) = Prob (cid:0)hab(x) = z(cid:1) Prob (cid:0)hab(y) = w(cid:1)

and hab(x) and hab(y) are statistically independent.

Analysis of distinct element counting algorithm

Let b1, b2, . . . , bd be the distinct values that appear in the input. Then

S = {h (b1) , h (b2) , . . . , h (bd)} is a set of d random and 2-way independent values from
the set {0, 1, 2, . . . , M − 1}. We now show that M
min is a good estimate for d, the number
of distinct elements in the input, where min is the minimum value in the set S.

241

Lemma 7.1 Assume M >100d. With probability at least 2
the smallest element of S.

3, d

6 ≤ M

min ≤ 6d, where min is

Proof: First, we show that Prob (cid:2) M

min > 6d(cid:3) < 1
6.
(cid:21)

(cid:20)

Prob

(cid:20) M
min

(cid:21)

> 6d

= Prob

min <

M
6d

(cid:20)

= Prob

∃k, h (bk) <

(cid:21)

M
6d

For i = 1, 2, . . . , d, deﬁne the indicator variable

zi =

(cid:26) 1 if h (bi) < M
0 otherwise

6d

and let z =

zi. If h (bi) is chosen randomly from {0, 1, 2, . . . , M − 1}, then Prob (zi = 1) <

d
(cid:80)
i=1

1

6d . Thus, E (zi) < 1

6d and E (z) < 1

6. Now
(cid:21)

Prob

(cid:20) M
min

> 6d

= Prob

min <

(cid:20)

(cid:21)

M
6d

(cid:20)

= Prob

∃k h (bk) <

(cid:21)

M
6d

≤ Prob (z ≥ 1)
≤ Prob (cid:0)z ≥ 6E (z)(cid:1) .

By Markov’s inequality Prob (cid:0)z ≥ 6E (z)(cid:1) ≤ 1
6.

Finally, we show that Prob (cid:0) M

min < d

6

(cid:1) < 1
6.

Prob

(cid:20) M
min

(cid:21)

< d
6

= Prob (cid:0)min > 6M

d

(cid:1) = Prob (cid:0)∀k, h (bk) > 6M

d

(cid:1)

For i = 1, 2, . . . , d deﬁne the indicator variable

yi =

(cid:26) 0 if h (bi) > 6M
1 otherwise

d

d
(cid:80)
i=1

and let y =

yi. Now Prob (yi = 1) > 6

d, and E (y) > 6. For 2-way
independent random variables, the variance of their sum is the sum of their variances. So
Var (y) = dVar (y1). Further, since y1 is 0 or 1

d , E (yi) > 6

Var(y1) = E (cid:2)(y1 − E(y1))2(cid:3) = E(y2

1) − E2(y1) = E(y1) − E2(y1) ≤ E (y1) .

242

Thus, Var(y) ≤ E (y). Now by the Chebychev inequality,

Prob

(cid:20) M
min

<

(cid:21)

d
6

d

(cid:20)
∀k h (bk) >

(cid:3) = Prob

= Prob (cid:2)min > 6M

6M
d
= Prob (y = 0) ≤ Prob [|y − E (y)| ≥ E (y)]
1
6

Var(y)
E2 (y)

1
E (y)

≤

≤

≤

.

(cid:21)

min > 6d with probability at most 1

6 and M

min < d

6 with probability at most 1
6,

Since M
6 ≤ M
d

min ≤ 6d with probability at least 2
3.

7.1.2 Counting the Number of Occurrences of a Given Element.

To count the number of occurrences of an element in a stream requires at most log n
space where n is the length of the stream. Clearly, for any length stream that occurs in
practice, we can aﬀord log n space. For this reason, the following material may never be
used in practice, but the technique is interesting and may give insight into how to solve
some other problems.

Consider a string of 0’s and 1’s of length n in which we wish to count the number
of occurrences of 1’s. Clearly if we had log n bits of memory we could keep track of the
exact number of 1’s. However, we can approximate the number with only log log n bits.

Let m be the number of 1’s that occur in the sequence. Keep a value k such that 2k
is approximately the number of occurrences m. Storing k requires only log log n bits of
memory. The algorithm works as follows. Start with k=0. For each occurrence of a 1,
add one to k with probability 1/2k. At the end of the string, the quantity 2k − 1 is the
estimate of m. To obtain a coin that comes down heads with probability 1/2k, ﬂip a fair
coin, one that comes down heads with probability 1/2, k times and report heads if the fair
coin comes down heads in all k ﬂips.

Given k, on average it will take 2k ones before k is incremented. Thus, the expected

number of 1’s to produce the current value of k is 1 + 2 + 4 + · · · + 2k−1 = 2k − 1.

7.1.3 Counting Frequent Elements

The Majority and Frequent Algorithms

First consider the very simple problem of n people voting where there are m candi-
dates, {1, 2, . . . , m}. We want to determine if one candidate gets a majority vote and if
so who. Formally, we are given a stream of integers a1, a2, . . . , an, each ai belonging to
{1, 2, . . . , m}. We want to determine whether there is some s in {1, 2, . . . , m} which occurs
more than n/2 times and if so which s. To solve the problem exactly with a deterministic
algorithm on streaming read only once data where m > n, requires Ω(n) space. Suppose

243

n is even and the ﬁrst n/2 items are all distinct and the last n/2 items are identical. After
reading the ﬁrst n/2 items, we need to remember exactly which elements of {1, 2, . . . , m}
have occurred. If for two diﬀerent sets of elements occurring in the ﬁrst half of the stream,
the contents of the memory are the same, then a mistake would occur if the second half
(cid:1)
(cid:0) m
of the stream consists solely of an element in one set, but not the other. Thus, log2
n/2
bits of memory, which if m > n is Ω(n), are needed.

The following is a simple low-space algorithm that always ﬁnds the majority vote if
there is one. If there is no majority vote, the output may be arbitrary. That is, there
may be “false positives”, but no “false negatives”.

Majority Algorithm

Store a1 and initialize a counter to one. For each subsequent ai, if ai is the same as
the currently stored item, increment the counter by one. If it diﬀers, decrement the
counter by one provided the counter is nonzero. If the counter is zero, then store ai
and set the counter to one.

If s is not the stored element at the end, each copy of s either incremented or decre-
If s
mented the counter. Associate with each copy of s another symbol as follows.
incremented the counter, associate with s the symbol that deleted that increment from
the counter. If s decremented the counter, then associate with s the symbol responsible
for that element of the count. If s is not the stored element at the end, then each copy of
s is associated with another symbol in the sequence and thus the number of copies of s is
at most n
2 . Thus, if there is a majority element, it must be stored on the counter at the end.

Next we modify the above algorithm so that not just the majority, but also items
with frequency above some threshold are detected. We will also ensure (approximately)
that there are no false positives as well as no false negatives. Indeed the algorithm below
will ﬁnd the frequency (number of occurrences) of each element of {1, 2, . . . , m} to within
n
k+1 using O(k log n) space by keeping k counters instead of just one
an additive term of
counter.

Algorithm Frequent

Maintain a list of items being counted. Initially the list is empty. For each item, if
it is the same as some item on the list, increment its counter by one. If it diﬀers
from all the items on the list, then if there are less than k items on the list, add the
item to the list with its counter set to one. If there are already k items on the list
decrement each of the current counters by one. Delete an element from the list if its
count becomes zero.

Theorem 7.2 At the end of Algorithm Frequent, for each s in {1, 2, . . . , m}, its counter
on the list is at least the number of occurrences of s in the stream minus n/(k+1). In

244

particular, if some s does not occur on the list, its counter is zero and the theorem asserts
that it occurs fewer than n/(k+1) times in the stream.

Proof: View each decrement counter step as eliminating some items. An item is elimi-
nated if it is the current ai being read and there are already k symbols diﬀerent from it on
the list in which case it and k other items are simultaneously eliminated. At the end of
the stream any element not eliminated contributes to one of the counts, The elimination
of each occurrence of an s in {1, 2, . . . , m} is really the elimination of k + 1 items. Thus,
no more than n/(k + 1) occurrences of any symbol can be eliminated. If an item is not
eliminated, then it must still be on the list at the end. This proves the theorem.

Theorem 7.2 implies that we can compute the true relative frequency, the number of
occurrences divided by n, of every s in {1, 2, . . . , m} to within an additive term of n

k+1.

7.1.4 The Second Moment

m
(cid:80)
s=1

This section focuses on computing the second moment of a stream with symbols from
{1, 2, . . . , m}. Let fs denote the number of occurrences of symbol s in the stream. The
m
(cid:80)
n. Each sum could
s=1

second moment of the stream is given by

2 + · · · + f 2

s = f 2
f 2

1 + f 2

be computed separately using m counters. We would like to compute

f 2
s with log m
space using only one counter. For each symbol s, 1 ≤ s ≤ m, independently set a random
variable xs to ±1 with probability 1/2. Maintain a single sum by adding xs to the sum
each time the symbol s occurs in the stream. At the end of the stream, the sum will equal
m
(cid:80)
s=1
choice of the ±1 values for the xs.

xsfs. The expected value of the sum will be zero where the expectation is over the

(cid:32) m
(cid:88)

E

s=1

(cid:33)

xsfs

= 0

Although the expected value of the sum is zero, its actual value is a random variable and
the expected value of the square of the sum is given by

(cid:32) m
(cid:88)

E

s=1

(cid:33)2

xsfs

= E

(cid:32) m
(cid:88)

s=1

(cid:33)

(cid:32)

sf 2
x2
s

+ 2E

(cid:88)

s(cid:54)=t

(cid:33)

xsxtfsft

=

m
(cid:88)

s=1

f 2
s .

The last equality follows since E (xsxt) = 0 for s (cid:54)= t. Thus

a =

(cid:33)2

xsfs

(cid:32) m
(cid:88)

s=1

f 2
s . One diﬃculty which we will come back to is that to store all the

is an estimator of

m
(cid:80)
s=1

xi requires space m and we want to do the calculation in log m space.

245

How good this estimator is depends on its variance, which we now compute.

Var (a) ≤ E

(cid:32) m
(cid:88)

s=1

(cid:33)4

(cid:32)

xsfs

= E

(cid:88)

(cid:33)

xsxtxuxvfsftfufv

1≤s,t,u,v≤m

The ﬁrst inequality is because the variance is at most the second moment and the second
equality is by expansion. In the second sum, since the xs are independent, if any one of
s, u, t, or v is distinct from the others, then the expectation of the whole term is zero.
Thus, we need to deal only with terms of the form x2
t for t (cid:54)= s and terms of the form
x4
s. Note that this does not need the full power of mutual independence of all the xs, it
only needs 4-way independence, that any four of the x(cid:48)
ss are mutually independent. In
the above sum, there are four indices s, t, u, and v and there are (cid:0)4
(cid:1) ways of choosing two
of them that have the same x value. Thus,

sx2

2

Var (a) ≤

(cid:19)

(cid:18)4
2

E

(cid:32) m
(cid:88)

m
(cid:88)

s=1

t=s+1

sx2
x2

t f 2

s f 2
t

(cid:33)

+ E

(cid:33)

sf 4
x4
s

(cid:32) m
(cid:88)

s=1

m
(cid:88)

s=1

f 4
s

m
(cid:88)

m
(cid:88)

= 6

s f 2
f 2

t +

t=s+1

s=1
(cid:32) m
(cid:88)

(cid:33)2

f 2
s

.

s=1

≤ 3

The variance can be reduced by a factor of r, which reduces the standard deviation by
√
r, by taking the average of r independent trials. With r independent trials the variance
s , O(1/ε2)
r E2 (a), so to achieve relative error ε in the estimate of
f 2

would be at most 3

m
(cid:80)
s=1

independent trials suﬃce.

The only drawback with the algorithm described here is the space needed to store the
r vectors x(1), x(2), . . . , x(r). We need to solve the problem in space proportional to log m
not m itself. In the next section, we will see that the vectors x(1), x(2), . . . , x(r) can be
stored using only O(log m) space by using pseudo-random vectors instead of truly random
ones.

Storing limited independent variables

Consider the problem of generating a random m-dimensional vector x of ±1’s so that
any four coordinates are mutually independent. Such an m-dimensional vector may be
generated from a random seed of only O(log m) mutually independent bits. Thus, we
need only store the log m bits and can generate any of the m coordinates when needed.
This allows us to store the 4-way independent random m-vectors using only order log m
bits.

246

For any k, there exists a ﬁnite ﬁeld F with exactly 2k elements whose elements can
be represented with k bits and arithmetic operations in the ﬁeld can be carried out in
O(k2) time. Here, k will be the ceiling of log2 m. We also need that a polynomial
over any ﬁeld F of degree at most three is uniquely determined by its values at any
four points. More precisely, for any four distinct points a1, a2, a3, and a4 in F and any
four possibly not distinct values b1, b2, b3, and b4 in F , there is a unique polynomial
f (x) = f0 + f1x + f2x2 + f3x3 of degree at most three, so that with computations done
over F , f (a1) = b1, f (a2) = b2, f (a3) = b3, and f (a4) = b4.

Our selection of a pseudo-random ±1 vector x with 4-way independence is simple.
Choose four elements f0, f1, f2, and f3 at random from F and form the polynomial
f (s) = f0 + f1s + f2s2 + f3s3. This polynomial represents x as follows. Order the
elements of F and let yi be the ith element of F. For s = 1, 2, . . . , m, xs is the leading bit
of the k-bit representation of f (ys). Thus, the m-dimensional vector x requires only O(k)
bits where k = (cid:100)log m(cid:101).

Lemma 7.3 The x deﬁned above has 4-way independence.

Proof: Assume that the elements of F are represented in binary using ±1 instead of the
traditional 0 and 1. Exactly half the elements of F have leading bit 1 so the probability
that any coordinate of x is +1 is exactly 1/2. Thus, four way independence requires that
any four coordinates of x be equally likely to have any one of the 16 possible sets of values.
Let s, t, u, and v be any four coordinates of x and let α, β, γ, and δ be any four elements
from {−1, 1}. There are exactly 2k−1 elements of F whose leading bit is α and similarly
for β, γ, and δ. So, there are exactly 24(k−1) 4-tuples of elements b1, b2, b3, b4 ∈ F so
that the leading bit of b1 is α, the leading bit of b2 is β, the leading bit of b3 is γ, and the
leading bit of b4 is δ. For each such b1, b2, b3, and b4, there is precisely one polynomial f
so that

f (s) = b1, f (t) = b2, f (u) = b3, and f (v) = b4.

Thus, the probability that the four coordinates xs, xt, xu, and xv of x are

xs = α, xt = β, xu = γ, and xv = δ

is precisely

24(k−1)
total number of f

= 24(k−1)

24k = 1

16 as asserted.

The lemma describes how to get one vector x with 4-way independence. However, we
need r = O(1/ε2) vectors. Also the vectors must be mutually independent. But this is
easy, just choose r polynomials at the outset.

To implement the algorithm with low space, store only the polynomials in memory.
This requires 4k = O(log m) bits per polynomial for a total of O(log m/ε2) bits for r = 1
(cid:15)2
trials. When a symbol s in the stream is read, compute x(1)
s and update the

s , . . . , x(r)

s , x(2)

247

running sums. Note that x(i)
s
requires O(log m) time to calculate from the coeﬃcients of the ith polynomial.

is the leading bit of the ith polynomial evaluated at ys and

This idea of polynomial interpolation is also used in other contexts. Error-correcting
codes is an important example. Say we wish to transmit n bits over a channel that may
introduce noise. One can introduce redundancy into the transmission so that some chan-
nel errors can be corrected. A simple way to do this is to view the n bits to be transmitted
as coeﬃcients of a polynomial f (x) of degree n − 1. Now transmit f evaluated at points
1, 2, 3, . . . , n + m. At the receiving end, any n correct values will suﬃce to reconstruct the
polynomial and the true message. So up to m errors can be tolerated. But even if the
number of errors is at most m, it is not a simple matter to know which values are corrupted.

7.2 Matrix Algorithms Using Sampling

How does one deal with a large matrix? An obvious suggestion is to take a sample of the
matrix. Uniform sampling does not work in general. For example, if a small fraction of
the entries are the big/signiﬁcant ones in the matrix, uniform sampling may miss them
all. So the sampling probabilities need to take into account the size or magnitude of the
entries. It turns out that sampling the rows and columns of a matrix with probabilities
dependent on their length is a good idea in many contexts. We present two examples
here, matrix multiplication and the sketch of a matrix. The sketch of a matrix A is a
rank r matrix that closely approximates A in the Frobenius norm.

7.2.1 Matrix Multiplication Using Sampling

Suppose A is an m × n matrix and B is an n × p matrix and the product AB is desired.
We show how to use sampling to get an approximate product faster than traditional matrix
multiplication. Let A (:, k) denote the kth column of A. A (:, k) is a m × 1 matrix. Let
B (k, :) be the kth row of B. B (k, :) is a 1 × n matrix. It is easy to see that

AB =

n
(cid:88)

k=1

A (:, k)B (k, :) .

Note that for each value of k, A(:, k)B(k, :) is an m × p matrix each element of which
is a single product of elements of A and B. An obvious use of sampling suggests itself.
Compute the sum of A (:, k) B (k, :) for some sampled k’s and suitably scale the sum for
the estimate of AB.

It turns out that nonuniform sampling probabilities are useful. Deﬁne a random vari-
able z that takes on values in {1, 2, . . . , n}. Let pk denote the probability that z assumes
the value k. The pk are nonnegative and sum to one. Deﬁne an associated random matrix

248

variable that has value

with probability

X =





1
p1
1
p2

1
pn

A (:, 1) B (1, :)
A (:, 2) B (2, :)
...
A (:, n) B (n, :)

p1
p2

pn

(7.1)

with probability pk. The matrix X approximates the product AB using only one column
of A and one row of B. Let E (X) denote the entry-wise expectation.

E (X) =

n
(cid:88)

k=1

Prob(z = k)

1
pk

A (:, k) B (k, :) =

n
(cid:88)

k=1

A (:, k)B (k, :) = AB.

This explains the scaling by 1
pk

in X.

Deﬁne the variance of X as the sum of the variances of all its entries.

Var(X) =

=

m
(cid:88)

p
(cid:88)

i=1
(cid:88)

j=1
(cid:88)

ij

k

Var (xij) =

(cid:88)

E (cid:0)x2

ij

(cid:1) −

(cid:88)

E2(xij)

ij
(cid:88)

a2
ikb2

kj −

ij

(AB)2
ij.

ij

pk

1
p2
k

Exchanging the order of summations

Var(X) =

=

(cid:88)

k
(cid:88)

k

1
pk

1
pk

(cid:88)

a2
ik

(cid:88)

b2
kj −

(cid:88)

(AB)2
ij

i

j

ij

|A (:, k) |2|B (k, :) |2 −

(AB)2
ij.

(cid:88)

ij

ij(AB)2

ij equals ||AB||2

What is the best choice of pk? It is the one which minimizes the variance. The term
F . So we should choose pk to minimize (cid:80)
(cid:80)
|A(:, k)|2|B(k, :)|2.
It can be seen by calculus that the minimizing pk are proportional to |A(:, k)||B(k, :)|. In
the important special case when B = AT , one should pick columns of A with probabilities
proportional to the squared length of the columns.

1
pk

k

In the general case when B is not AT , length squared sampling simpliﬁes bounds. If

pk is proportional to |A (:, k) |2, i.e, pk = |A(:,k)|2
||A||2
F

, we can bound Var(X) by

Var(X) ≤ ||A||2
F

(cid:80)
k

|B (k, :) |2 = ||A||2

F ||B||2
F .

To reduce the variance, do s independent trials. Each trial i, i = 1, 2, . . . , s yields a
i=1 Xi as our estimate of AB. Since the variance of a

matrix Xi as in (7.1). Take 1
s

(cid:80)s

249















A





























B

m × n

n × p















≈

































Sampled
columns
of
A

m × s

Corresponding
scaled rows of B
s × p





Figure 7.2: Approximate Matrix Multiplication using sampling

sum of independent random variables is the sum of variances, the variance of 1
s
is 1
F ||B||2
F .

s Var(X) and is at most 1

s ||A||2

(cid:80)s

i=1 Xi

To implement this, suppose k1, k2, . . . , ks are the k ’s chosen in each trial. It is easy

to see that

1
s

s
(cid:88)

i=1

Xi =

1
s

(cid:18) A (:, k1) B (k1, :)
pk1

+

A (:, k2) B (k2, :)
pk2

+ · · · +

A (:, ks) B (ks, :)
pks

(cid:19)

= C ˜B,

where, C is the m × s matrix of the chosen columns of A and ˜B is an s × p matrix
with the corresponding rows of B scaled, namely, ˜B has rows B(k1, :)/(spk1) , B(k2, :
)/(spk2) , . . . , B(ks, :)/(spks). See Figure (7.2).

We summarize our discussion in a lemma.

Lemma 7.4 Suppose A is an m × n matrix and B is an n × p matrix. The product AB
can be estimated by C ˜B, where, C is an m × s matrix consisting of s columns of A picked
in independent trials, each according to length-squared distribution and ˜B is the s × p
matrix consisting of the corresponding rows of B scaled as above. The error is bounded
by:

(cid:16)
||AB − C ˜B||2
F

(cid:17)

E

≤

||A||2

F ||B||2
F
s

.

7.2.2 Sketch of a Large Matrix

The main result of this section will be that for any matrix, a sample of columns and
rows, each picked in independent trials according to length squared distribution is a good
sketch of the matrix.

Let A be an m × n matrix. Pick s columns of A in independent trials, in each picking
a column according to length squared distribution on the columns. Let C be the m × s
matrix containing the picked columns. Similarly, pick r rows of A in r independent trials,

250

each according to length squared distribution on the rows of A. Let R be the r × n matrix
of the picked rows. From C and R, we can compute a matrix U so that A ≈ CU R. The
schematic diagram is given in Figure 7.3.

The proof makes crucial use of the fact that the sampling of rows and columns is with
probability proportional to the squared length. One may recall that the top k singular
vectors of the SVD of A, give a similar picture; but the SVD takes more time to compute,
requires all of A to be stored in RAM, and does not have the property that the rows and
columns are directly from A. The last property, that the approximation involves actual
rows and columns of the matrix rather than linear combinations, is called an interpolative
approximation and is useful in many contexts. However, the SVD does yield the best
2-norm approximation. Error bounds for the approximation CU R are weaker.

We brieﬂy touch upon two motivations for such a sketch. Suppose A is the document-
term matrix of a large collection of documents. We are to “read” the collection at the
outset and store a sketch so that later, when a query represented by a vector with one
entry per term arrives, we can ﬁnd its similarity to each document in the collection. Simi-
larity is deﬁned by the dot product. In Figure 7.3 it is clear that the matrix-vector product
of a query with the right hand side can be done in time O(ns + sr + rm) which would
be linear in n and m if s and r are O(1). The error bound for this process, requires that
the diﬀerence between A and the sketch of A has small 2-norm. Recall that the 2-norm
|Ax|. The fact that the sketch is an interpolative approxi-
||A||2 of a matrix A is max
|x|=1

mation means that our approximation essentially consists of a subset of documents and
a subset of terms, which may be thought of as a representative set of documents and terms.

A second motivation comes from recommendation systems. Here A would be a
customer-product matrix whose (i, j)th entry is the preference of customer i for prod-
uct j. The objective is to collect a few sample entries of A and based on them, get an
approximation to A so that we can make future recommendations. A few sampled rows
of A (all preferences of a few customers) and a few sampled columns (all customers’ pref-
erences for a few products) give a good approximation to A provided that the samples
are drawn according to the length-squared distribution.

It remains to describe how to ﬁnd U from C and R. Through the rest of this section,
we make the assumption that RRT is invertible. This case will convey the essential ideas.
Also, note that since r in general will be much smaller than n and m, unless the matrix
A is degenerate, it is likely that the r rows in the sample R will be linearly independent
giving us invertibility of RRT .

Before stating precisely what U is, we give some intuition. Write A as AI, where,
I is the n × n identity matrix. Pretend for the moment that we approximate the prod-
uct AI by sampling s columns of A according to length-squared. Then, as in the last
section, write AI ≈ CW where, W consists of a scaled version of the s rows of I cor-

251















A





























≈

Sample
columns















n × m

n × s

(cid:21)(cid:20) Sample rows

(cid:21)

r × m

(cid:20) Multi
plier

s × r

Figure 7.3: Schematic diagram of the approximation of A by a sample of s columns and
r rows.

F ||I||2

responding to the s picked columns of A. Lemma 7.4 bounds the error ||A − CW ||2
F by
||A||2
s . But clearly, we would like the error to be a fraction of ||A||2
F
which would require s ≥ n, which is of no use since this would pick as many or more
columns than the whole of A.

F /s = ||A||2
F

n

We modify the intuition. Assume that RRT is invertible. Then it is easy to see (Lemma
7.8) that P = RT (RRT )−1R acts as the identity matrix on the space V spanned by the
rows of R. Lets use this identity-like matrix P instead of I in the above discussion. We
will show later, using the fact that R is picked according to length squared, the following
proposition.

Proposition 7.5 A ≈ AP and the error E (||A − AP ||2

2) is at most ||A||2

F /r.

We then use Lemma 7.4 to argue that instead of doing the multiplication AP , we can use
the sampled columns of A and the corresponding rows of P . The sampled s columns of
A form C. We have to take the corresponding s rows of P = RT (RRT )−1R, which is the
same as taking the corresponding s rows of RT , and multiplying this by (RRT )−1R. It is
easy to check that this leads to an expression of the form CU R. Further, by Lemma 7.4,
the error is bounded by

E (cid:0)||AP − CU R||2

2

(cid:1) ≤ E (cid:0)||AP − CU R||2

F

(cid:1) ≤

||A||2

F ||P ||2
F
s

≤

r
s

||A||2
F ,

(7.2)

since we will show later the following proposition.

Proposition 7.6 ||P ||2

F ≤ r.

Putting (7.2) and Proposition 7.5 together and using ||A−CU R||2 ≤ ||A−AP ||2 +||AP −
CU R||2 which implies that ||A − CU R||2
2, we establish
the main result.

2 + 2||AP − CU R||2

2 ≤ 2||A − AP ||2

Theorem 7.7 Suppose A is any m × n matrix and r, s are positive integers. Suppose C
is a m × s matrix of s columns of A picked in i.i.d. trials, each according to length squared

252

sampling and similarly R is a matrix of r rows of A picked according to length squared
sampling. Then, we can ﬁnd from C, R an s × r matrix U so that

E (cid:0)||A − CU R||2

2

(cid:1) ≤ ||A||2

F

(cid:18) 2
r

+

(cid:19)

.

2r
s

Choosing s = r2, the bound becomes O(1/r)||A||2
ε||A||2

F for some small ε > 0, it suﬃces to choose r ∈ Ω(1/ε).

F and if want the bound to be at most

We now brieﬂy look at the time needed to compute U . The only involved step in
computing U is to ﬁnd (RRT )−1. But note that RRT is an s × s matrix and since s is
to much smaller than n and m, this is fast. Now we prove all the claims used in the
discussion above.

Lemma 7.8 If RRT is invertible, then RT (RRT )−1R acts as the identity matrix on the
row space of R. I.e., for every vector x of the form x = RT y (this deﬁnes the row space
of R), we have RT (RRT )−1Rx = x.

Proof: For x = RT y, since RRT is invertible

RT (RRT )−1Rx = RT (RRT )−1RRT y = RT y = x

Now we prove Proposition 7.5. First suppose x ∈ V . Then we can write x = RT y and
so P x = RT (RRT )−1RRT y = RT y = x, so for x ∈ V , we have (A − AP )x = 0. So, it
suﬃces to consider x ∈ V ⊥. For such x, (A − AP )x = Ax and

|(A − AP )x|2 = |Ax|2 = xT AT Ax = xT (AT A − RT R)x ≤ ||AT A − RT R||2|x|2,

2 ≤ ||AT A − RT R||2, so it suﬃces to prove that ||AT A − RT R||2 ≤
so we get ||A − AP ||2
F /r which follows directly from Lemma 7.4 since we can think of RT R as a way of
||A||2
estimating AT A by picking (according to length-squared distribution) columns of AT , i.e.,
rows of A. This proves Proposition 7.5.

Proposition 7.6 is easy to see: Since by Lemma 7.8, P is the identity on the space V
F is the sum of its singular values squared

spanned by the rows of R, we have that ||P ||2
which is at most r as claimed.

7.3 Sketches of Documents

Suppose one wished to store all the web pages from the WWW. Since there are billions
of web pages, one might store just a sketch of each page where a sketch is a few hundred
bits that capture suﬃcient information to do whatever task one had in mind. A web page

253

or a document is a string. We ﬁrst show how to sample a set and then how to convert
the problem of sampling a string into the problem of sampling a set.

Consider subsets of size 1000 of the integers from 1 to 106. Suppose one wished to

compute the resemblance of two subsets A and B by the formula

resemblance (A, B) = |A∩B|
|A∪B|

Suppose that instead of using the sets A and B, one sampled the sets and compared ran-
dom subsets of size ten. How accurate would the estimate be? One way to sample would
be to select ten elements uniformly at random from A and B. However, this method is
unlikely to produce overlapping samples. Another way would be to select the ten smallest
elements from each of A and B. If the sets A and B overlapped signiﬁcantly one might
expect the sets of ten smallest elements from each of A and B to also overlap. One dif-
ﬁculty that might arise is that the small integers might be used for some special purpose
and appear in essentially all sets and thus distort the results. To overcome this potential
problem, rename all elements using a random permutation.

Suppose two subsets of size 1000 overlapped by 900 elements. What would the over-
lap be of the 10 smallest elements from each subset assuming that the elements have
been renamed using a random permutation? One would expect the nine smallest ele-
ments from the 900 common elements to be in each of the two subsets for an overlap of
90%. The expected resemblance for the size ten sample would be 9/11=0.81, which is the
resemblance(A, B).

Another method would be to select the elements equal to zero mod m for some inte-
ger m. If one samples mod m, the size of the sample becomes a function of n and thus
sampling mod m allows us to also handle containment.

In another version of the problem, one has a string rather than a set. Here one con-
verts the string into a set by replacing the string by the set of all short substrings of some
length k. Corresponding to each string is a set of length k substrings. If k is suﬃciently
large, then two strings are highly unlikely to give rise to the same set of substrings. Thus,
we have converted the problem of sampling a string to that of sampling a set. Instead
of storing all the substrings, one stores only a small subset of the set of length k substrings.

Suppose you wish to be able to determine if two web pages are minor modiﬁcations of
one another or to determine if one is a fragment of the other. Deﬁne the set of substrings
of k consecutive words from the string of words on the page. Let S(D) be the set of all
substrings of length k occurring in document D. Deﬁne resemblance of A and B by

And deﬁne containment as

resemblance (A, B) = |S(A)∩S(B)|
|S(A)∪S(B)|

containment (A, B) = |S(A)∩S(B)|

|S(A)|

254

Let W be a set of substrings. Deﬁne min (W ) to be the s smallest elements in W and
deﬁne mod (W ) as the set of elements of w that are zero mod m.

Let π be a random permutation of all length k substrings. Deﬁne F (A) to be the s
smallest elements of A and V (A) to be the set mod m in the ordering deﬁned by the
permutation.

Then

and

F (A)∩F (B)
F (A)∪F (B)

|V (A)∩V (B)|
|V (A)∪V (B)|

are unbiased estimates of the resemblance of A and B. The value

is an unbiased estimate of the containment of A in B.

|V (A)∩V (B)|
|V (A)|

255

7.4 Exercises

Exercise 7.1 Given a stream of symbols a1, a2, . . . , an, give an algorithm that will select
one symbol uniformly at random from the stream. How much memory does your algorithm
require?

Exercise 7.2 Give an algorithm to select an ai from a stream of symbols a1, a2, . . . , an
with probability proportional to a2
i .

Exercise 7.3 How would one pick a random word from a very large book with probability
of picking a word being proportional to the number of occurrences of the word in the book?

Exercise 7.4 For the streaming model give an algorithm to draw s independent samples
each with the probability proportional to its value. Justify that your algorithm works
correctly.

Exercise 7.5 Show that for a 2-universal hash family Prob (h(x) = z) = 1
x ∈ {1, 2, . . . , m} and z ∈ {0, 1, 2, . . . , M }.

M +1 for all

Exercise 7.6 Let p be a prime. A set of hash functions

H = {h| {0, 1, . . . , p − 1} → {0, 1, . . . , p − 1}}

is 3-universal if for all u,v,w,x,y, and z in {0, 1, . . . , p − 1}

Prob (h (x) = u, h (y) = v, h (z) = w) =

1
p3 .

(a) Is the set {hab(x) = ax + b mod p|0 ≤ a, b < p} of hash functions 3-universal?

(b) Give a 3-universal set of hash functions.

Exercise 7.7 Give an example of a set of hash functions that is not 2-universal.

Exercise 7.8

(a) What is the variance of the method in Section 7.1.2 of counting the number of occur-

rences of a 1 with log log n memory?

(b) Can the algorithm be iterated to use only log log log n memory? What happens to the

variance?

Exercise 7.9 Prove that for independent x and y, Var(x + y) =Var(x)+Var(y). Hint:
Shifting a probability distribution so that it has expected value does not change the Var of
the distribution.

Exercise 7.10 Consider a coin that comes down heads with probability p. Prove that the
expected number of ﬂips before a head occurs is 1/p.

256

Exercise 7.11 Randomly generate a string x1x2 · · · xn of 106 0’s and 1’s with probability
1/2 of xi being a 1. Count the number of ones in the string and also estimate the number
of ones by the approximate counting algorithm. Repeat the process for p=1/4, 1/8, and
1/16. How close is the approximation?

Exercise 7.12 Construct an example in which the majority algorithm gives a false posi-
tive, i.e., stores a non majority element at the end.

Exercise 7.13 Construct examples where the frequent algorithm in fact does as badly as
in the theorem, i.e., it “under counts” some item by n/(k+1).

Exercise 7.14 Let F be the ﬁnite ﬁeld with 2k elements and let s be an element of F.
Choose a polynomial of degree 3 uniformly at random. Prove that f (s) is equally likely to
be any element of F.

Exercise 7.15 Recall basic statistics on how an average of independent trials cuts down

variance and complete the argument for relative error ε estimate of

m
(cid:80)
s=1

f 2
s .

Exercise 7.16 What are the groups GF(2), GF(4), and GF(8)? Specify the elements
and the operations of addition and multiplication.

Exercise 7.17 Let F be a ﬁeld. Prove that for any four distinct points a1, a2, a3, and a4
in F and any four (possibly not distinct) values b1, b2, b3, and b4 in F , there is a unique
polynomial f (x) = f0+f1x+f2x2+f3x3 of degree at most three so that f (a1) = b1, f (a2) =
b2, f (a3) = b3 f (a4) = b4 with all computations done over F .

Exercise 7.18 Suppose we want to pick a row of a matrix at random where the probability
of picking row i is proportional to the sum of squares of the entries of that row. How would
we do this in the streaming model? Do not assume that the elements of the matrix are
given in row order.

(a) Do the problem when the matrix is given in column order.

(b) Do the problem when the matrix is represented in sparse notation: it is just presented

as a list of triples (i, j, aij), in arbitrary order.

Exercise 7.19 Suppose A and B are two matrices. Show that AB =

n
(cid:80)
k=1

A (:, k)B (k, :).

Exercise 7.20 Generate two 100 by 100 matrices A and B with integer values between
1 and 100. Compute the product AB both directly and by sampling. Use the Frobenius
norm to measure the error. Plot the relative error as a function of the number of samples.
In generating the matrices make sure that they are skewed. One method would be the
following. First generate two 100 dimensional vectors a and b with integer values between
1 and 100. Next generate the ith row of A with integer values between 1 and ai and the
ith column of B with integer values between 1 and bi.

257

Exercise 7.21 Show that ADDT B is exactly

1
s

(cid:18) A (:, k1) B (k1, :)
pk1

+

A (:, k2) B (k2, :)
pk2

+ · · · +

A (:, ks) B (ks, :)
pks

(cid:19)

Exercise 7.22 Suppose a1, a2, . . . , an are nonnegative reals. Show that the minimum of
s =
xk = 1 is attained when the xk are

subject to the constraints xk ≥ 0 and

n
(cid:80)
k=1

n
(cid:80)
k=1

a2
k
xk
proportional to ak.

Exercise 7.23 Consider random strings of length n composed of the integers 0 through
9. Represent a string by its set of length k-substrings. What is the resemblance of the sets
of length k-substrings from two random strings of length n for various values of k as n
goes to inﬁnity?

Exercise 7.24 What if the strings in the Exercise 7.23 were not random? Suppose the
strings consisted of letters and that there was some nonzero probability of a given letter
of the alphabet following another. Would the result get better or worse?

Exercise 7.25 Consider a random string of length 10,000 over an alphabet of size 100.

1. For k = 3 what is probability that two possible successor substrings for a given

substring are in the set of substrings of the string?

2. For k = 5 what is the probability?

Exercise 7.26 How would you go about detecting plagiarism in term papers?

Exercise 7.27 Suppose you had one billion web pages and you wished to remove dupli-
cates. How would you do this?

Exercise 7.28 Construct two strings of 0’s and 1’s having the same set of substrings of
width w.

Exercise 7.29 Consider the following lyrics:

When you walk through the storm hold your head up high and don’t be afraid of the
dark. At the end of the storm there’s a golden sky and the sweet silver song of the
lark.
Walk on, through the wind, walk on through the rain though your dreams be tossed
and blown. Walk on, walk on, with hope in your heart and you’ll never walk alone,
you’ll never walk alone.

How large must k be to uniquely recover the lyric from the set of all substrings of symbols
of length k? Treat the blank as a symbol.

258

Exercise 7.30 Blast: Given a long string a, say 109 and a shorter string b, say 105,
how do we ﬁnd a position in a which is the start of a substring b(cid:48) of a that is close to b?
This problem can be solved by dynamic programming but not in reasonable time. Find a
time eﬃcient algorithm to solve this problem.
Hint: (Shingling approach) One possible approach would be to ﬁx a small length, say
seven, and consider the shingles of a and b of length seven. A shingle is a continuous
subsequence of a sequence. For a string, a shingle is simply a substring.
If a close
approximation to b is a substring of a, then a number of shingles of b must be shingles of
a. This should allows us to ﬁnd the approximate location in a of the approximation of b.
Some ﬁnal algorithm should then be able to ﬁnd the best match.

259

8 Clustering

8.1 Some Clustering Examples

Clustering refers to the process of partitioning a set of objects into subsets consisting
of similar objects. Clustering comes up in many contexts. For example, one might want
to cluster journal articles into clusters of articles on related topics. In doing this, one
ﬁrst represents a document by a vector. This can be done using the vector space model
introduced in Chapter 2. Each document is represented as a vector with one component
for each term giving the frequency of the term in the document. Alternatively, a docu-
ment may be represented by a vector whose components correspond to documents in the
collection and the jth component of the ith vector is a 0 or 1 depending on whether the
ith document referenced the jth document. Once one has represented the documents as
vectors, the problem becomes one of clustering vectors.

Another context where clustering is important is the study of the evolution and growth
of communities in social networks. Here one constructs a graph where nodes represent
individuals and there is an edge from one node to another if the person corresponding to
the ﬁrst node sent an email or instant message to the person corresponding to the second
node. A community is deﬁned as a set of nodes where the frequency of messages within
the set is higher than what one would expect if the set of nodes in the community were a
random set. Clustering partitions the set of nodes of the graph into sets of nodes where
the sets consist of nodes that send more messages to one another than one would expect
by chance. Note that clustering generally asks for a strict partition into subsets, although
in reality a node may belong to several communities.

In these clustering problems, one deﬁnes either a similarity measure between pairs of
objects or a distance measure, a notion of dissimilarity. One measure of similarity between
two vectors a and b is the cosine of the angle between them:

cos(a, b) =

aT b
|a| |b| .

To get a distance measure, subtract the cosine similarity from one.

dist(a, b) = 1 − cos(a, b)

Another distance measure is the Euclidean distance. There is an obvious relationship
between cosine similarity and Euclidean distance. If a and b are unit vectors, then

|a − b|2 = (a − b)T (a − b) = |a|2 + |b|2 − 2aT b = 2 (1 − cos (a, b)) .

In determining the distance function to use, it is useful to know something about the
origin of the data. In clustering the nodes of a graph, we may represent each node as
a vector, namely, as the row of the adjacency matrix corresponding to the node. One

260

notion of dissimilarity here is the square of the Euclidean distance. For 0-1 vectors, this
measure is just the number of “uncommon” 1’s, whereas, the dot product is the number
of common 1’s.

In many situations one has a stochastic model of how the data was generated. An
example is customer behavior. Suppose there are d products and n customers. A rea-
sonable assumption is that each customer generates from a probability distribution, the
basket of goods he or she buys. A basket speciﬁes the amount of each good bought. One
hypothesis is that there are only k types of customers, k << n. Each customer type
is characterized by a probability density used by all customers of that type to generate
their baskets of goods. The densities may all be Gaussians with diﬀerent centers and
covariance matrices. We are not given the probability densities, only the basket bought
by each customer, which is observable. Our task is to cluster the customers into the k
types. We may identify the customer with his or her basket which is a vector. One way to
formulate the problem mathematically is by a clustering criterion that is then optimized.
Some potential criteria are to partition the customers into k clusters so as to minimize

1. the sum of distances between all pairs of customers in the same cluster,

2. the sum of distances of all customers to their “cluster center” (any point in space

may be designated as the cluster center), or

3. the sum of squared distances to the cluster center.

The last criterion is called the k-means criterion and is widely used. The variant (2)
above called the k-median criterion minimizes the sum of distances (not squared) to the
cluster center. Another possibility, called the k-center criterion, is to minimize the max-
imum distance of any point to its cluster center.

The chosen criterion can aﬀect the results. To illustrate, suppose that the data was
generated according to an equal weight mixture of k spherical Gaussian densities centered
at µ1, µ2, . . . , µk, each with variance one in every direction. Then the density of the
mixture is

F (x) = Prob(x) =

1
k

1
(2π)d/2

k
(cid:88)

i=1

e−|x−µi|2.

Denote by µ(x) the center nearest to x. Since the exponential function falls oﬀ fast, we
can approximate (cid:80)k

i=1 e−|x−µi|2 by e−|x−µ(x)|2. Thus

F (x) ≈

1
k

1

(2π)d/2 e−|x−µ(x)|2.

The likelihood of drawing the sample of points x(1), x(2), . . . , x(n) from the mixture, if the
centers were µ1, µ2, . . . , µk, is approximately

1
kn

1
(2π)nd/2

n
(cid:89)

i=1

e−|x(i)−µ(x(i))|2 = ce− (cid:80)n

i=1 |x(i)−µ(x(i))|2.

261

Minimizing the sum of squared distances to cluster centers ﬁnds the maximum likelihood
µ1, µ2, . . . , µk. This suggests using the sum of distance squared to the cluster centers.

On the other hand, if the generating process had an exponential probability distribu-

tion, with the probability law

Prob [(x1, x2, . . . , xd)] =

1
2d

d
(cid:89)

i=1

e− |xi−µi| =

−

d
(cid:80)
i=1

1
2d e

|xi−µi|

=

1

2d e− |x−µ |1,

one would use the L1 norm, not the L2 or the square of the L1, since the probability den-
sity decreases as the L1 distance from the center. The intuition here is that the distance
used to cluster data should be related to the actual distribution of the data.

The choice of whether to use a distance measure and cluster together points that are
close or use a similarity measure and cluster together points with high similarity, and
what particular distance or similarity measure to use, can be crucial to the application.
However, there is not much theory on these choices; they are determined by empirical
domain-speciﬁc knowledge. One general observation is worth making. Using distance
squared instead of distance, favors outliers since the square function magniﬁes large val-
ues, which means a small number of outliers may make a clustering look bad. On the
other hand, distance squared has some mathematical advantages; see for example Corol-
lary 8.2 that asserts that with the distance squared criterion, the centroid is the correct
cluster center. The widely used k-means criterion is based on sum of squared distances.

There are in general two variations of the clustering problem for each of the criteria.
We could require that each cluster center be a data point or allow a cluster center to be
any point in space. If we require each cluster center to be a data point, the optical clus-
tering of n data points into k clusters can be solved in time (cid:0)n
(cid:1) times a polynomial in the
length of the data. First, exhaustively enumerate all sets of k data points as the possible
sets of k cluster centers, then associate each point to its nearest center and select the best
clustering. No such naive enumeration procedure is available when cluster centers can be
any point in space. But, for the k-means problem, Corollary 8.2 shows that once we have
identiﬁed the data points that belong to a cluster, the best choice of cluster center is the
centroid. Note that the centroid might not be a data point.

k

In the formulations discussed so far, we have one number (e.g. sum of distances squared
to the cluster center) as the measure of goodness of a clustering and we try to optimize
that number to ﬁnd the best clustering according to the measure. This approach does not
always yield desired results, since it can be hard to ﬁnd the optimum exactly. Although
most clustering problems are NP-hard, often there are polynomial time algorithms to ﬁnd
an approximately optimal solution. But such a solution may be far from the optimal or
desired clustering. We will see in Section 8.4 how to formalize some realistic conditions
under which an approximate optimal solution gives us a desired clustering as well. But

262

ﬁrst we see some simple algorithms for getting a good clustering according to some natural
measures.

8.2 A k-means Clustering Algorithm

There are many algorithms for clustering high dimensional data. We start with a
widely used algorithm that uses the k-means criterion. In the k-means criterion, a set A =
{a1, a2, . . . , an} of n points in d-dimensions is partitioned into k-clusters, S1, S2, . . . , Sk,
so as to minimize the sum of squared distances of each point to its cluster center. That
is, A is partitioned into clusters, S1, S2, . . . , Sk, and a center is assigned to each cluster so
as to minimize

d (S1, S2, . . . , Sk) =

k
(cid:88)

(cid:88)

(cj − ai)2

where cj is the center of cluster j.

j=1

ai∈Sj

Suppose we have already determined the clustering or the partitioning into S1, S2, . . . , Sk.

What are the best centers for the clusters? The following lemma shows that the answer
is the centroids, the coordinate means, of the clusters.

Lemma 8.1 Let {a1, a2, . . . , an} be a set of points. The sum of the squared distances
of the ai to any point x equals the sum of the squared distances to the centroid plus the
number of points times the squared distance from the point x to the centroid. That is,

|ai − x|2 =

(cid:88)

i

(cid:88)

i

|ai − c|2 + n |c − x|2

ai is the centroid of the set of points.

where c = 1
n

n
(cid:80)
i=1

Proof:

|ai − x|2 =

(cid:88)

i

=

(cid:88)

i
(cid:88)

i

|ai − c + c − x|2

|ai − c|2 + 2(c − x) ·

(ai − c) + n |c − x|2

(cid:88)

i

Since c is the centroid, (cid:80)

(ai − c) = 0. Thus, (cid:80)

|ai − x|2 = (cid:80)

|ai − c|2 + n |c − x|2

i

i

i

A corollary of Lemma 8.1 is that the centroid minimizes the sum of squared distances

since the second term, n (cid:107)c − x(cid:107)2, is always non-negative.

Corollary 8.2 Let {a1, a2, . . . , an} be a set of points. The sum of squared distances of
the ai to a point x is minimized when x is the centroid, namely x = 1
n

ai.

(cid:80)
i

263

Another expression for the sum of squared distances of a set of n points to their centroid
is the sum of all pairwise distances squared divided by n. First, a simple observation. For
|ai − aj|2 counts the quantity |ai − aj|2 once for

a set of points {a1, a2, . . . , an},
each ordered pair (i, j), j > i. However, (cid:80)

later sum is twice the ﬁrst sum.

i,j

n
(cid:80)
i=1

n
(cid:80)
j=i+1

|ai − aj|2 counts each |ai − aj|2 twice, so the

Lemma 8.3 Let {a1, a2, . . . , an} be a set of points. The sum of the squared distances
between all pairs of points equals the number of points times the sum of the squared dis-
tances of the points to the centroid of the points. That is, (cid:80)
|ai − c|2

|ai − aj|2 = n (cid:80)

(cid:80)
j>i

i

where c is the centroid of the set of points.

i

Proof: Lemma 8.1 states that for every x,
(cid:88)

(cid:88)

|ai − x|2 =

|ai − c|2 + n |c − x|2 .

Letting x range over all aj and summing the n equations yields

i

i

(cid:80)
i,j

|ai − aj|2 = n (cid:80)

|ai − c|2 + n (cid:80)
|ai − c|2.

j

i

= 2n (cid:80)

|c − aj|2

Observing that

yields the result that

i

(cid:88)

i,j

|ai − aj|2 = 2

(cid:88)

(cid:88)

|ai − aj|2

i

j>i

(cid:88)

(cid:88)

i

j>i

|ai − aj|2 = n

|ai − c|2 .

(cid:88)

i

The k-means clustering algorithm

A natural algorithm for k-means clustering is given below. There are three unspeciﬁed
aspects of the algorithm. One is k, the number of clusters, a second is the actual set of
starting centers and the third is the stopping condition.

The k-means algorithm

Start with k centers.

Cluster each point with the center nearest to it.

Find the centroid of each cluster and replace the set of old centers with the
centroids.

Repeat the above two steps until the centers converge (according to some
criterion).

264

The k-means algorithm always converges but often to a local minimum. To show con-
vergence, we argue that the sum of the squares of the distances of each point to its cluster
center, always improves. Each iteration consists of two steps. First, consider the step
that ﬁnds the centroid of each cluster and replaces the old centers with the new centers.
By Corollary 8.2, this step improves the sum of internal cluster distances squared. The
second step reclusters by assigning each point to its nearest cluster center, which also
improves the internal cluster distances.

One way to determine a good value of k is to run the algorithm for each value of k and
plot the sum of squared distances to the cluster centers as a function of k. If the value of
the sum drops sharply going from some value of k to k + 1, then this suggests that k + 1
corresponds to the number of clusters in a natural partition of the data.

A problem that arises with some implementations of the k-means clustering algorithm
is that one or more of the clusters becomes empty and there is no center from which to
measure distance. A simple case where this occurs is illustrated in the following example.
You might think how you would modify the code to resolve this issue.

Example: Consider running the k-means clustering algorithm to ﬁnd three clusters on
the following 1-dimension data set: 2,3,7,8 starting with center 0,5,10.

0

0

0

1

1

1

2

2

2

3

3

3

4

4

4

5

5

5

6

6

6

7

7

7

8

8

8

9

9

9

10

10

10

The center at 5 ends up with no items and there are only two clusters instead of the
desired three.

Another issue that arises is whether the clusters have any real signiﬁcance. The k-
means algorithm will ﬁnd k clusters even in G(n, p). But note that since the graph
G(n, p) should look uniform everywhere, there aren’t really k meaningful clusters where a
clustering is meaningful if any close to optimal clustering is almost identical to it. In fact,
there are many ways of clustering the vertices of this graph all of which will be nearly
optimal with respect to the k-means or k-median criteria.

8.3 A Greedy Algorithm for k-Center Criterion Clustering

In this section, instead of using the k-means clustering criterion, we use the k-center
criterion. The k-center criterion partitions the points into k clusters so as to minimize the

265

maximum distance of any point to its cluster center. Call the maximum distance of any
point to its cluster center the radius of the clustering. There is a k-clustering of radius
r if and only if there are k spheres, each of radius r, which together cover all the points.
Below, we give a simple algorithm to ﬁnd k spheres covering a set of points. The following
lemma shows that this algorithm only needs to use a radius that is “oﬀ by a factor of at
most two” from the optimal k-center solution.

The Greedy k-clustering Algorithm

Pick any data point to be the ﬁrst cluster center. At time t, for t = 2, 3, . . . , k, pick
any data point that is not within distance r of an existing cluster center; make it the
tth cluster center.

Lemma 8.4 If there is a k-clustering of radius r
clustering with radius at most r.

2, then the above algorithm ﬁnds a k-

Proof: Suppose for contradiction that the algorithm using radius r fails to ﬁnd a k-
clustering. This means that after the algorithm chooses k centers, there is still at least
one data point that is not in any sphere of radius r around a picked center. This is the
only possible mode of failure. But then there are k + 1 data points, with each pair more
than distance r apart. Clearly, no two such points can belong to the same cluster in any
k-clustering of radius r

2 contradicting the hypothesis.

8.4 Spectral Clustering

In this section we give two contexts where spectral clustering is used. The ﬁrst is
used for ﬁnding communities in graphs and the second for clustering a general set of data
points. We begin with a simple explanation as to how spectral clustering works when
applied to the adjacency matrix of a graph.

Spectral clustering applied to graphs

In spectral clustering of the vertices of a graph, one ﬁrst creates a new matrix V whose
columns correspond to the ﬁrst k singular vectors of the adjacency matrix. Each row of V
is the projection of a row of the adjacency matrix to the space spanned by the k singular
vectors. In the example below, the graph has ﬁve vertices divided into two cliques, one
consisting of the ﬁrst three vertices and the other the last two vertices. The top two right
singular vectors of the adjacency matrix, not normalized to length one, are (1, 1, 1, 0, 0)T
and (0, 0, 0, 1, 1)T . The ﬁve rows of the adjacency matrix projected to these vectors form
the 5 × 2 matrix in Figure 8.1. Here, in fact there are two ideal clusters with all edges
inside a cluster being present including all self-loops and all edges between clusters being
absent. The ﬁve rows project to just two points, depending on which cluster the rows are
in. If the clusters were not so ideal and instead of the graph consisting of two disconnected

266

A =









1 1 1 0 0
1 1 1 0 0
1 1 1 0 0
0 0 0 1 1
0 0 0 1 1









V =









1 0
1 0
1 0
0 1
0 1









Figure 8.1: Illustration of spectral clustering.

cliques, the graph consisted of two dense subsets of vertices where the two sets were con-
nected by only a few edges, then the singular vectors would not be indicator vectors for
the clusters but close to indicator vectors. The rows would be mapped to two clusters of
points instead of two points. A k-means clustering algorithm would ﬁnd the clusters.

If the clusters were overlapping, then instead of two clusters of points, there would be
three clusters of points where the third cluster corresponds to the overlapping vertices of
the two clusters. Instead of using k-means clustering, we might instead ﬁnd the minimum
1-norm vector in the space spanned by the two singular vectors. The minimum 1-norm
vector will not be an indicator vector, so we would threshold its values to create an
indicator vector for a cluster. Instead of ﬁnding the minimum 1-norm vector in the space
spanned by the singular vectors in V, we might actually look for a small 1-norm vector
close to the subspace.

min
x

(1 − |x|1 + α cos(θ))

Here θ is the cosine of the angle between x and the space spanned by the two singular
vectors. α is a control parameter that determines how close we want the vector to be to
the subspace. When α is large, x must be close to the subspace. When α is zero, x can
be anywhere.

Finding the minimum 1-norm vector in the space spanned by a set of vectors can be
formulated as a linear programming problem. To ﬁnd the minimum 1-norm vector in V,
write V x = y where we want to solve for both x and y. Note that the format is diﬀerent
from the usual format for a set of linear equations Ax = b where b is a known vector.

Finding the minimum 1-norm vector looks like a nonlinear problem.

min |y|1 subject to V x = y

267

To remove the absolute value sign, write y = y1 − y2 with y1 ≥ 0 and y2 ≥ 0. Then solve

min

(cid:32) n

(cid:88)

i=1

y1i +

n
(cid:88)

i=1

(cid:33)

y2i

subject to V x = y, y1 ≥ 0, and y2 ≥ 0.

Write V x = y1 − y2 as V x − y1 + y2 = 0. then we have the linear equations in a format
we are accustomed to.

[V, −I, I]



 =





x
y1
y2















0
0
...
0

This is a linear programming problem. The solution, however, happens to be x = 0,
y1 = 0, and y2 = 0. To resolve this, add the equation y1i = 1 to get a community con-
taining the vertex i.

Often we are looking for communities of 50 or 100 vertices in graphs with hundreds of
million of vertices. We want a method to ﬁnd such communities in time proportional to
the size of the community and not the size of the entire graph. Here spectral clustering
can be used but instead of calculating singular vectors of the entire graph, we do some-
thing else. Consider a random walk on a graph. If we walk long enough the probability
distribution converges to the ﬁrst eigenvector. However, if we take only a few steps from a
start vertex or small group of vertices that we believe deﬁne a cluster, the probability will
distribute over the cluster with some of the probability leaking out to the remainder of the
graph. To get the early convergence of several vectors which would ultimately converge
to the ﬁrst few singular vectors, we take a subspace [x, Ax, A2x, A3x] and propagate the
subspace. At each iteration we ﬁnd an orthonormal basis and then multiply each basis
vector by A. We then take the resulting basis vectors after a few steps, say ﬁve, and ﬁnd
a minimum 1-norm vector in the subspace.

Spectral clustering applied to data

Consider n data points arranged as the rows of an n × d matrix A. These are to be
partitioned into k clusters where k is much smaller than n or d. Finding the best k-means
clustering of the points is known to be NP-hard. However, there are eﬃcient algorithms
that ﬁnd a k-clustering within a factor of two of the best. We will see that singular value
decomposition together with this type of approximate k-means clustering is very useful.

Spectral Clustering of the data into k clusters. The method consists of the following

steps:

1. Find the top k right singular vectors of the data matrix A.

2. Project each row of A into the space spanned by these singular vectors to obtain a

n × d matrix ¯A.

268

3. Apply an algorithm to ﬁnd an approximately optimal k-clustering of ¯A.

It is important to note that the projected points are being clustered, i.e., the rows of
¯A and not A itself. Projection oﬀers the obvious advantage of decreasing the dimension
of the problem from d to k, making it easier to cluster. The more important advantage
of projecting is that it yields cluster centers closer to the true centers than clustering A.
This is not so obvious and we demonstrate it here. The formal statement is contained in
Theorem 8.7.

We will see how to use the fact that spectral clustering ﬁnds centers close to the true
centers to get an actual clustering close to the true clustering. But this makes sense only
if there is no ambiguity about what the true clustering is. We will develop a notion of a
proper clustering that says the clusters are distinct enough so as not to be confused with
each other. We will then show that if there is a proper clustering, spectral clustering will
ﬁnd a clustering close to the proper clustering. This is proved in Theorem 8.9.

Consider a spherical Gaussian F in Rd with mean µ and variance one in every direc-
tion. As we saw in Chapter 2, for a point x picked according to F , |x − µ|2 is likely to
be about d. Now suppose we apply an approximate k-means clustering algorithm, which
ﬁnds a clustering with sum of distances squared at most (1 + ε) times the optimal. With
this amount of error, a center µ(cid:48) found may have |µ(cid:48) − µ|2 ≈ εd.

Consider a mixture of two spherical Gaussians in Rd, for large d, each of variance
one in every direction. If the inter-center separation between them is say six, which is
six standard deviations, then the error of εd would result in confusing the two. So, even
in this simple case, approximate optimization does not do a good job. Now consider
a mixture of k spherical Gaussians, each of variance one in every direction, We saw in
Chapter 4 that the space spanned by the top k singular vectors contains the means of
the k Gaussians. Project all data points on to this space. The densities are still Gaus-
sian in the projection with variance again one in every direction. The mean squared
distance of projected data points to the projected mean of the respective densities is O(k)
and in an approximately best k-means clustering, the cluster centers will be at distance
squared at most O(k) from the true means, not O(d). In this example, we assumed that
the data points were stochastically generated from a mixture of Gaussians. We show in
what follows that this is not necessary. Indeed, we show that the intuitive argument here
also holds for any arbitrary set of data points. But ﬁrst, we have to deﬁne an analog of
variance for a general set of data points. This is simple. It is just the average squared
distance from the cluster center instead of the average distance squared to the mean of the
probability density. Now, for spherical Gaussians, the squared distance in every direction
is the same, but in general, they are not and we will take the maximum over all directions.

Represent a k-clustering by a n × d matrix C with each row of C being the cluster
center of the cluster the corresponding row of A belongs to. Note that C has only k

269

distinct rows. Deﬁne the variance of C, denoted σ2(C), by

σ2(C) = max
v
|v|=1

1
n

|(A − C)v|2,

which is simply the maximum, in any direction v, of the mean-squared distance of a data
point from its cluster center. It is easy to see that σ2(C) = 1

n||A − C||2
2.

If we had a stochastic model of data, as for example a mixture of Gaussians generating
the data, then there is a true clustering and it is desirable that our algorithm ﬁnd this
clustering or at least come close. In general, we do not assume that there is a stochas-
tic model and so there is no true clustering. Nevertheless, we will be able to show that
spectral clustering does nearly as well as any clustering C. Namely, for most data points,
(cid:17)
the cluster centers found by spectral clustering will be at distance at most O
of the cluster centers in C. The reader should think about the question: How is it that
the one clustering found by the algorithm can do this for every possible clustering? The
answer is that if C is a very bad clustering, σ(C) is large and the requirement of being
kσ(C)) is very weak. For the theorem below, recall the notation that
within distance O(
ai, ci, and c(cid:48)

i are respectively the ith row of A, C, and C (cid:48).

k σ(C)

(cid:16)√

√

First, we need two technical lemmas.

Lemma 8.5 For any two vectors u and v,

|u + v|2 ≥

1
2

|u|2 − |v|2.

Proof:

|u + v|2 = (u + v) · (u + v) = |u|2 + |v|2 + 2u · v

≥ |u|2 + |v|2 − 2|u||v| = (|u| − |v|)2 .

From this and the fact that for any two real numbers a and b,

(a − b)2 ≥ (a − b)2 −

(cid:19)2

√

2b

=

a −

(cid:18) 1
√
2

1
2

a2 − b2,

the claim follows.

Lemma 8.6 Suppose A is an n × d matrix and ¯A is the projection of the rows of A onto
the subspace spanned by the top k singular vectors of A. Then for any matrix C of rank
at most k,

|| ¯A − C||2

F ≤ 8k||A − C||2
2.

270

Proof: Since the rank of ¯A − C is at most the sum of the ranks of ¯A and C, which is
most 2k,

|| ¯A − C||2

F ≤ 2k|| ¯A − C||2

2

(8.1)

by Lemma 4.2. Now

|| ¯A − C||2 ≤ || ¯A − A||2 + ||A − C||2 ≤ 2||A − C||2,

the last inequality since ¯A is the best rank k approximation for the spectral norm and C
has rank at most k. Combining this with (8.1), the lemma follows.

Theorem 8.7 Suppose A is a n×d data matrix and C is any clustering of A and suppose
C (cid:48) (also a n × d matrix with k distinct rows) is the clustering of ¯A found by the spectral
clustering algorithm. For all but εn of the data points, we have |ci − c(cid:48)

i|2 < 48k

ε σ2(C).

Proof: Let ∆ = 48k
that B has at most εn elements.

ε σ2(C) and B = {i||ci − c(cid:48)

i|2 ≥ ∆} be the bad set of i. We must show

|¯ai − c(cid:48)

i|2 =

(cid:88)

|(ci − c(cid:48)

i) + ( ¯ai − ci)|2

(cid:88)

i∈B

i∈B
1
2

(cid:88)

i∈B

|ci − c(cid:48)

i|2 −

|¯ai − ci|2

(cid:88)

i∈B

by the Lemma 8.5

1
2

|B|∆ −

n
(cid:88)

i=1

|¯ai − ci|2 =

1
2

|B|∆ − || ¯A − C||2
F .

≥

≥

On the other hand,

(cid:88)

i∈B

|¯ai − c(cid:48)

i|2 ≤

n
(cid:88)

i=1

|¯ai − c(cid:48)

i|2 ≤ 2

n
(cid:88)

i=1

|¯ai − ci|2 = 2|| ¯A − C||2
F ,

since, C (cid:48) is within a factor of two of being the best k-means clustering of the projected
data matrix ¯A implies that if we took C as a clustering of ¯A, then, it is at most a factor
of two better than C (cid:48). Combining,

3|| ¯A − C||2

F ≥

1
2

|B|∆

which implies

|B| ≤

From Lemma 8.6, || ¯A − C||2
follows.

F ≤ 8k||A − C||2

6ε|| ¯A − C||2
F
48kσ2(C)
2 = 8knσ2(C). Plugging this in, the theorem

.

We need the following lemma which asserts another property of spectral clustering,
k of the best

namely that the clustering it ﬁnds has σ which is within a factor of 5
possible σ for any clustering.

√

271

Lemma 8.8 Let C ∗ be the k-clustering with the minimum σ among all k-clusterings of
the data. For the clustering C (cid:48) found by spectral clustering, we have

√

σ(C (cid:48)) ≤ 5

kσ(C ∗).

Proof:

||A − C (cid:48)||2 ≤ ||A − ¯A||2 + || ¯A − C (cid:48)||2 ≤ ||A − C ∗||2 + || ¯A − C (cid:48)||F

√

√

√

√

≤

nσ(C ∗) +

2|| ¯A − C ∗||F ≤

nσ(C ∗) + 4

knσ(C ∗), by Lemma 8.6.

For the second inequality, we used the fact that since ¯A is the best rank k approximation
to A in spectral norm, ||A − C ∗||2 ≥ ||A − ¯A||2 and for the third inequality, we used
the fact that C (cid:48) is within a factor of two of the optimal k-means clustering of ¯A and in
particular, the clustering C ∗ is not better by a factor of more than two. Now the lemma
follows.

Now we show that we can use the fact that spectral clustering ﬁnds cluster centers
close to the true centers to ﬁnd approximately the true clustering. This makes sense
only if there is no ambiguity about what the true clustering is. A necessary condition
for a clustering to be unambiguous is that the clusters must be distinct or spatially well-
separated. Otherwise, points could be put into either of two nearby clusters without
changing the k-means objective function much. We make this more precise with the
following deﬁnition:

Deﬁnition 8.1 A clustering C ∗ is said to be proper if

1. σ(C ∗) is least among all k-clustering of the data, and

2. the centers of any two clusters in C ∗ are separated by a distance of at least 70k2σ(C ∗)/

√

ε.

Here, ε is any positive real number. Why do we choose this deﬁnition of a proper clus-
tering? For the case of spherical Gaussians, the separation required here corresponds to
the means of diﬀerent Gaussians being a constant number of standard deviations apart.
A diﬀerent deﬁnition might have insisted on the clusters being distinct enough so that
even an approximately best k-means clustering in Rd, would give approximately the true
clustering. Since for a spherical Gaussian with variance one in every direction, data
points are about
d away from the center, this would intuitively require the means of
two such Gaussians involved in a mixture to be at least Ω(
d) apart, which is a stronger
requirement than that of being proper. To be proper, a separation of only Ω(1) is required.

√

√

We modify the spectral clustering algorithm by adding a merge step at the end.

Merge Step Let C (cid:48) be the clustering found by spectral clustering. Repeatedly merge
ε.

any two clusters with cluster centers separated by a distance of at most 14

kσ(C (cid:48))/

√

√

272

Theorem 8.9 Suppose there is a proper clustering C ∗ of data points. Then, spectral
clustering followed by merge-step produces a clustering C (0) with the property that by
reclustering at most εn points, we can get from C (0) to C ∗.

Proof: Let C (cid:48) be the clustering produced by spectral clustering before the merge step is
i |2 > ∆}. Let S be one particular
executed. Let ∆ = 49kσ2(C (cid:48))/ε. Deﬁne B = {i : |c(cid:48)
j − c∗
cluster in C ∗. For any i, j ∈ S \ B, we have |c(cid:48)
∆. Since
c∗
i = c∗
j , i and j will be in one cluster after the merge step. Now if S and T are two
diﬀerent clusters in C ∗, by the deﬁnition of proper, for i ∈ S \ B and j ∈ T \ B, we have

i − c∗
i | ≤

∆ and |c(cid:48)

i − c∗

j | ≤

√

√

|c∗

i − c∗

j | ≥ 70k2σ(C ∗)/
√

√

ε ≥ 14k3/2σ(C (cid:48))/

√

ε ≥ 2k

√

∆,

i − c(cid:48)

j| ≥ 2(k − 1)

by Lemma 8.8. So |c(cid:48)
∆ by the deﬁnition of B and the merge step (even
when repeated k − 1 times) will not merge i and j into one cluster. Thus, for all i, j /∈ B,
we have that i and j belong to the same cluster in C ∗ if and only if they belong to the
same cluster in C (0). Thus, by reclustering at most |B| points, we can get from C (0) to
C ∗.

8.5 Recursive Clustering Based on Sparse Cuts

Suppose we are given an undirected, connected graph G(V, E) in which an edge in-
dicates the end point vertices are similar. Recursive clustering starts with all vertices
in one cluster and recursively splits a cluster into two parts whenever there are not too
many edges from one part to the other part of the cluster. For this technique to be ef-
fective it is important that the data has an hierarchical clustering. Consider what would
happen if one used recursive clustering to ﬁnd communities of students at an institution
hoping that one of the clusters might be computer science students. At the ﬁrst level one
might get four clusters corresponding to freshman, sophomores, juniors, and seniors. At
the next level one might get clusters that were majors partitioned into year rather than
majors. Another problem would occur if the real top level clusters were overlapping. If
one is clustering journals articles, the top level might be mathematics, physics, chem-
istry, etc. However, there are papers that are related to both mathematics and physics.
Such a paper would be put in one cluster or the other and the community that the pa-
per really belonged in would be split and thus never found at lower levels in the clustering.

Formally, for two disjoint sets S and T of vertices, deﬁne

Φ(S, T ) =

number of edges from S to T
total number of edges incident to S in G

.

Φ(S, T ) measures the relative strength of similarities between S and T . Let d(i) be the
degree of vertex i and for d(S) = (cid:80)
i∈S d(i). Let m be the total number of edges. The
following algorithm cuts only a small fraction of the edges, yet ensures that each cluster
is consistent, namely no subset of it has low similarity to the rest of the cluster.

273

Recursive Clustering Algorithm

If a current cluster W has a subset S with d(S) ≤ 1

2d(W ) and Φ(S, T ) ≤ ε, then split

W into two clusters: S and W -S. Repeat until no such split is possible.

Theorem 8.10 At termination of the above algorithm, the total number of edges between
vertices in diﬀerent clusters is at most O(εm ln n).

Proof: Each edge between two diﬀerent clusters at the end was “cut up” at some stage by
the algorithm. We will “charge” edge cuts to vertices and bound the total charge. When
the algorithm partitions a cluster W into S and W -S with d(S) ≤ (1/2)d(W ), each k ∈ S
is charged d(k)
d(W ) times the number of edges being cut. Since Φ(S, W -S) ≤ ε, the charge
added to each k ∈ W is a most εd(k). A vertex is charged only when it is in the smaller
part (d(S) ≤ d(W )/2) of the cut. So between any two times it is charged, d(W ) is reduced
by a factor of at least two and so a vertex can be charged at most log2 m ≤ O(ln n) times,
proving the theorem.

To implement the algorithm, we have to compute MinS⊆W Φ(S, W -S), an NP-hard
problem. So the theorem cannot be implemented right away. Luckily, eigenvalues and
eigenvectors, which can be computed fast, give an approximate answer. The connection
between eigenvalues and sparsity, known as Cheeger’s inequality, is deep with applications
to Markov chains among others. We do not discuss this here.

8.6 Kernel Methods

The clustering methods discussed so far work well only when the data satisfy certain
conditions. For example, in any distance-based measure like k-means or k-center, once
the cluster centers are ﬁxed, the Vornoi diagram of the cluster centers determines which
cluster each data point belongs to. Cells of the Vornoi diagram are determined by hy-
perplane bisectors of line segments joining pairs of centers. This implies that clusters are
linearly separable.

Such criteria cannot separate clusters that are not linearly separable in the input
space. The chapter on learning had many examples that were not linearly separable in
the original space, but were linearly separable when mapped to a higher dimensional space
using a nonlinear function called a kernel. An analogous technique can be used in the
case of clustering, but with two diﬀerences.

1. There may be any number k of clusters, whereas in learning, there were just two

classes, the positive and negative examples.

2. There is unlabelled data, i.e., we are not given which cluster each data point belongs
to, whereas in the case of learning each data point was labeled. The clustering
situation is sometimes called unsupervised whereas the labeled learning situation is
called supervised, the reason being, one imagines a supervisor, human judgement,
supplying the labels.

274

B

A

Figure 8.2: Example where 2-median clustering B is not natural.

These two diﬀerences do not prevent the application of kernel methods to clustering.
Indeed, here too, one could ﬁrst embed the data in a diﬀerent space using the Gaussian
or other kernel and then run k-means in the embedded space. Again, one need not write
down the whole embedding explicitly. In the learning setting, since there were only two
classes with a linear separator, we were able to write a convex program to ﬁnd the normal
of the separator. When there are k classes, there could be as many as (cid:0)k
(cid:1) hyperplanes
separating pairs of classes, so the computational problem is harder and there is no simple
convex program to solve the problem. However, we can still run the k-means algorithm
in the embedded space. The centroid of a cluster is kept as the average of the data points
in the cluster. Recall that we only know dot products, not distances in the higher dimen-
sional space, but we can use the relation |x − y|2 = x · x + y · y + 2x · y to go from dot
products to distances.

2

There are situations in which high-dimensional data points lie in a lower dimensional
manifold. In such situations, a Gaussian kernel is useful. Say we are given a set of n points
S = {s1, s2, . . . , sn} in Rd that we wish to cluster into k subsets. The Gaussian kernel
uses an aﬃnity measure that emphasizes closeness of points and drops oﬀ exponentially
as the points get farther apart. We deﬁne the aﬃnity between points i and j by

aij =

(cid:40)

e−
0

1

2σ2 (cid:107)si − sj(cid:107)2

i (cid:54)= j
i = j.

The aﬃnity matrix gives a closeness measure for points. The measure drops oﬀ expo-
nentially fast with distance and thus favors close points. Points farther apart have their
closeness shrink to zero. We give two examples to illustrate brieﬂy the use of Gaussian
kernels. The ﬁrst example is similar to Figure 8.2 of points on two concentric annuli. Sup-
pose the annuli are close together, i.e., the distance between them is δ << 1. Even if we
used similarity between objects, rather than say the k-median criterion, it is not clear that
we will get the right clusters; namely two separate circles. Instead, suppose the circles are
sampled at a rate so that adjacent samples are separated by a distance ε << δ. Deﬁne a
Gaussian kernel with variance ε2. Then, if sample s1 is on Circle 1 and sample s2 is on

275

Circle 2, e−|s1−s2|2/2ε2 << 1, so they are very likely to be put in separate clusters as desired.

Our second example has three curves. Suppose two points from two diﬀerent curves
are never closer than δ. If we sample at a high enough rate, every sample will have many
other samples from the same curve close to it giving high similarity according to the
Gaussian kernel, but no two samples from diﬀerent curves will have high similarity. This
example can be generalized to a situation where the points lie on diﬀerent “sheets” or low
dimensional manifolds.

Two points near each other on the same circle will have a high aﬃnity value, i.e., they
will be close together in this metric. For the right sigma value, the two closest points, one
from each circle, will be inﬁnitely far apart. Thus, the aﬃnity matrix is a band matrix,
consisting of two blocks of data.

8.7 Agglomerative Clustering

Agglomerative clustering is the opposite of recursive clustering. It starts with each
point in a separate cluster and then repeatedly merges the two closest clusters into one.
There are various criteria to determine which two clusters are merged at any point. They
are based on ﬁrst deﬁning a distance between two clusters in terms of the distance between
points. Four of these possibilities are listed below.

1. Nearest neighbor - the distance between clusters Ci and Cj is the distance between

the points in Ci and Cj that are closest.

dmin (Ci, Cj) = min
x∈Ci
y∈Cj

|x − y|

This measure basically builds the minimal cost spanning tree.

2. Farthest neighbor - the distance between clusters Ci and Cj is the distance between

the points in Ci and Cj that are farthest apart.

dmax (Ci, Cj) = max
x∈Ci
y∈Cj

|x − y|

3. Mean - the distance between two clusters is the distance between the centroids of

the clusters.

4. Average - the distance between two clusters is the average distance between points

in the two clusters.

Agglomerative clustering in moderate and high dimensions often gives rise to a very
unbalanced tree. This section gives some insight into the cause of this phenomenon. We
begin by considering agglomerative clustering of 1-dimensional data. The 1-dimensional

276

dmin

dmean

dmax

Figure 8.3: Illustration of minimum, maximum and mean distances for a set of points.

case gives rise to a balanced tree.

Consider agglomerative clustering using nearest neighbor of n points on a line. Assume
the distances between adjacent points are independent random variables and measure the
distance between clusters by the distance of the nearest neighbors. Here it is easy to see
that each cluster is always an interval. In this case, any two adjacent intervals are equally
likely to be merged. The last merge will occur when the largest distance between two
adjacent points is encountered. This is equally likely to be the distance between point i
and point i + 1 for any i, 1 ≤ i < n. The height of the ﬁnal merge tree will be one more
than the maximum of the heights of the two subtrees. Let h(n) be the expected height
of a merge tree with n leaves. Then

h (n) = 1 + 1
n

max {h (i) , h (n − i)}

n
(cid:80)
i=1
n
(cid:80)
n
2+1
3
4n
(cid:80)
n
2+1

= 1 + 2
n
i=

h (i)

= 1 + 2
n
i=

h (i) + 2
n
i=

h (i)

n
(cid:80)
3
4n+1

Since h(i) is monotonic, for n

2 < i ≤ 3

4n, bound h (i) by h (cid:0) 3

4n(cid:1) and for 3

4n < i ≤ n,

bound h (i) by h (n). Thus,

h (n) ≤ 1 + 2
n
≤ 1 + 1

n

4 h (cid:0) 3n
2h (cid:0) 3n

4

4

(cid:1) + 2

n
4 h (n)

(cid:1) + 1

n
2h (n) .

This recurrence has a solution h (n) ≤ b log n for suﬃciently large b. Thus, the merge tree
has no long path and is bushy.

277

If the n points are in high dimension rather than constrained to a line, then the
distance between any two points, rather than two adjacent points, can be the smallest
distance. One can think of edges being added one at a time to the data to form a spanning
tree. Only now we have an arbitrary tree rather than a straight line. The order in which
the edges are added corresponds to the order in which the connected components are
merged by the agglomerative algorithm. Two extreme cases of the spanning tree for the
set of points are the straight line which gives a bushy agglomerative tree or a star which
gives a skinny agglomerative tree of height n. Note there are two trees involved here, the
spanning tree and the agglomerative tree.

The question is what is the shape of the spanning tree? If distance between components
is nearest neighbor, the probability of an edge between two components is proportional to
the size of the components. Thus, once a large component forms it will swallow up small
components giving a more star like spanning tree and hence a tall skinny agglomerative
tree. Notice the similarity to the G(n, p) problem.

If we deﬁned distance between two clusters to be the maximum distance between any
two points in the clusters and merge the two clusters that are the smallest distance apart,
then we are more likely to get a bushy spanning tree and a skinny agglomerative tree.
If all distances between points are independent and we have two clusters of size k and a
singleton, the maximum distance between the points in the two clusters of size k is likely
to give a larger distance than the maximum between the singleton and the k points in
a cluster. Thus, the singleton will likely merge into one of the clusters before the two
clusters will merge and in general small clusters will combine before larger ones, resulting
in a bushy spanning tree and a bushy agglomerative tree.

8.8 Dense Submatrices and Communities

Represent n data points in d-space by the rows of an n × d matrix A. Assume that A
has all nonnegative entries. Examples to keep in mind for this section are the document-
term matrix and the customer-product matrix. We address the question of how to deﬁne
and ﬁnd eﬃciently a coherent large subset of rows. To this end, the matrix A can be
represented by a bipartite graph. One side has a vertex for each row and the other side a
vertex for each column. Between the vertex for row i and the vertex for column j, there
is an edge with weight aij.

We want a subset S of row vertices and a subset T of column vertices so that

A(S, T ) =

(cid:88)

aij

i∈S,j∈T

is high. This simple deﬁnition is not good since A(S, T ) will be maximized by taking
all rows and columns. We need a balancing criterion that ensures that A(S, T ) is high
relative to the sizes of S and T . One possibility is to maximize A(S,T )
|S||T | . This is not a good

278

Figure 8.4: Example of a bipartite graph.

measure either, since it is maximized by the single edge of highest weight. The deﬁnition
we use is the following. Let A be a matrix with nonnegative entries. For a subset S of
rows and a subset T of columns, the density d(S, T ) of S and T is d(S, T ) = A(S,T )√
. The
|S||T |

density d(A) of A is deﬁned as the maximum value of d(S, T ) over all subsets of rows and
columns. This deﬁnition applies to bipartite as well as non bipartite graphs.

One important case is when A’s rows and columns both represent the same set and aij
is the similarity between object i and object j. Here d(S, S) = A(S,S)
. If A is an n × n 0-1
matrix, it can be thought of as the adjacency matrix of an undirected graph, and d(S, S) is
the average degree of a vertex in S. The subgraph of maximum average degree in a graph
can be found exactly by network ﬂow techniques, as we will show in the next section. We
do not know an eﬃcient (polynomial-time) algorithm for ﬁnding d(A) exactly in general.
However, we show that d(A) is within a O(log2 n) factor of the top singular value of A
assuming |aij| ≤ 1 for all i and j. This is a theoretical result. The gap may be much less
than O(log2 n) for many problems, making the singular value and singular vector quite
useful. Also, S and T with d(S, T ) ≥ Ω(d(A)/ log2 n) can be found algorithmically.

|S|

Theorem 8.11 Let A be an n × d matrix with entries between 0 and 1. Then

σ1(A) ≥ d(A) ≥

σ1(A)
4 log n log d

.

Furthermore, subsets S and T satisfying d(S, T ) ≥ σ1(A)
singular vector of A.

4 log n log d may be found from the top

Proof: Let S and T be the subsets of rows and columns that achieve d(A) = d(S, T ).
Consider an n-vector u which is

on S and 0 elsewhere and a d-vector v which is

1√

1√

|S|

|T |

on T and 0 elsewhere. Then,

σ1 (A) ≥ uT Av = (cid:80)

uivjaij = d(S, T ) = d(A)

ij

establishing the ﬁrst inequality.

279

To prove the second inequality, express σ1 (A) in terms of the ﬁrst left and right

singular vectors x and y.

σ1(A) = xT Ay =

(cid:88)

i,j

xiaijyj,

|x| = |y| = 1.

Since the entries of A are nonnegative, the components of the ﬁrst left and right singular
vectors must all be nonnegative, that is, xi ≥ 0 and yj ≥ 0 for all i and j. To bound
(cid:80)
xiaijyj, break the summation into O (log n log d) parts. Each part corresponds to a
i,j
given α and β and consists of all i such that α ≤ xi < 2α and all j such that β ≤ yi < 2β.
The log n log d parts are deﬁned by breaking the rows into log n blocks with α equal to
1√
1
n , 4 1√
n , 2 1√
1√
n ,
n , . . . , 1 and by breaking the columns into log d blocks with β equal
2
, . . . , 1. The i such that xi < 1
to 1
4√
2√
1√
1√
will
,
,
√
2
2
d
d
d
d
be ignored at a loss of at most 1
[Exercise (8.28) proves the loss is at most this
4σ1(A).
amount.]

n and the j such that yj < 1

√

,

d

2

Since (cid:80)

i

i = 1, the set S = {i|α ≤ xi < 2α} has |S| ≤ 1
x2

α2 and similarly,

T = {j|β ≤ yj ≤ 2β} has |T | ≤ 1

β2 . Thus

(cid:88)

(cid:88)

xiyjaij ≤ 4αβA(S, T )

i
α≤xi≤2α

j
β≤yj ≤2β

≤ 4αβd(S, T )(cid:112)|S||T |
≤ 4d(S, T )
≤ 4d(A).

From this it follows that

or

proving the second inequality.

σ1 (A) ≤ 4d (A) log n log d

d (A) ≥ σ1(A)

4 log n log d

It is also clear that for each of the values of (α, β), we can compute A(S, T ) and d(S, T )
as above and taking the best of these d(S, T ) ’s gives us an algorithm as claimed in the
Theorem.

Note that in many cases, the nonzero values of xi and yj (after zeroing out the low
entries) will only go from 1
for yj, since the singular vectors
2
are likely to be balanced given that aij are all between 0 and 1. In this case, there will
be O(1) groups only and the log factors disappear.

n for xi and 1

n to c√
1√

to c√
d

1√
d

2

280

Another measure of density is based on similarities. Recall that the similarity between
objects represented by vectors (rows of A) is deﬁned by their dot products. Thus, simi-
larities are entries of the matrix AAT . Deﬁne the average cohesion f (S) of a set S of rows
of A to be the sum of all pairwise dot products of rows in S divided by |S|. The average
cohesion of A is the maximum over all subsets of rows of the average cohesion of the subset.

Since the singular values of AAT are squares of singular values of A, we expect f (A)

to be related to σ1(A)2 and d(A)2. Indeed it is. We state the following without proof.

Lemma 8.12 d(A)2 ≤ f (A) ≤ d(A) log n. Also, σ1(A)2 ≥ f (A) ≥ cσ1(A)2
log n .

f (A) can be found exactly using ﬂow techniques as we will see later.

In this section, we described how to ﬁnd a large global community. There is another
question, that of ﬁnding a small local community including a given vertex. We will visit
this question in Section 8.10.

8.9 Flow Methods

Here we consider dense induced subgraphs of a graph. An induced subgraph of a
graph consisting of a subset of the vertices of the graph along with all edges of the graph
that connect pairs of vertices in the subset of vertices. We show that ﬁnding an induced
subgraph with maximum average degree can be done by network ﬂow techniques. This
is simply maximizing density d(S, S) of Section 8.8 over all subsets S of the graph. First
consider the problem of ﬁnding a subset of vertices such that the induced subgraph has
average degree at least λ for some parameter λ. Then do a binary search on the value of
λ until the maximum λ for which there exists a subgraph with average degree at least λ
is found.

Given a graph G in which one wants to ﬁnd a dense subgraph, construct a directed
graph H from the given graph and then carry out a ﬂow computation on H. H has a
node for each edge of the original graph, a node for each vertex of the original graph,
plus two additional nodes s and t. There is a directed edge with capacity one from s to
each node corresponding to an edge of the original graph and a directed edge with inﬁnite
capacity from each node corresponding to an edge of the original graph to the two nodes
corresponding to the vertices the edge connects. Finally, there is a directed edge with
capacity λ from each node corresponding to a vertex of the original graph to t.

Notice there are three types of cut sets of the directed graph that have ﬁnite capacity.
It has capacity e, the number of edges of the
The ﬁrst cuts all arcs from the source.
original graph. The second cuts all edges into the sink. It has capacity λv, where v is the
number of vertices of the original graph. The third cuts some arcs from s and some arcs
into t. It partitions the set of vertices and the set of edges of the original graph into two

281

s

[u, v]

[v, w]

[w, x]

edges

u

v

w

x

vertices

t

Figure 8.5: The directed graph H used by the ﬂow technique to ﬁnd a dense subgraph

blocks. The ﬁrst block contains the source node s, a subset of the edges es, and a subset
of the vertices vs deﬁned by the subset of edges. The ﬁrst block must contain both end
points of each edge in es; otherwise an inﬁnite arc will be in the cut. The second block
contains t and the remaining edges and vertices. The edges in this second block either
connect vertices in the second block or have one endpoint in each block. The cut set will
cut some inﬁnite arcs from edges not in es coming into vertices in vs. However, these
arcs are directed from nodes in the block containing t to nodes in the block containing s.
Note that any ﬁnite capacity cut that leaves an edge node connected to s must cut the
two related vertex nodes from t. Thus, there is a cut of capacity e − es + λvs where vs
and es are the vertices and edges of a subgraph. For this cut to be the minimal cut, the
quantity e − es + λvs must be minimal over all subsets of vertices of the original graph
and the capcity must be less than e and also less than λv.

> e

If there is a subgraph with vs vertices and es edges where the ratio es
vs

is suﬃciently
v , then for λ such that eS
large so that eS
v , es − λvs > 0 and e − es + λvs < e.
vS
vS
Similarly e < λv and thus e − es + λvs < λv. This implies that the cut e − es + λvs is less
than either e or λv and the ﬂow algorithm will ﬁnd a nontrivial cut and hence a proper
subset. For diﬀerent values of λ in the above range there maybe diﬀerent nontrivial cuts.

> λ > e

282

s

1

∞

∞

∞

λ

t

cut

edges and vertices
in the community

Figure 8.6: Cut in ﬂow graph

Note that for a given density of edges, the number of edges grows as the square of the
v if vS is small. Thus, the ﬂow method
. To ﬁnd small communities one

number of vertices and es
vs
works well in ﬁnding large subsets since it works with eS
vS
would need to use a method that worked with eS
v2
S

as the following example illustrates.

is less likely to exceed e

Example: Consider ﬁnding a dense subgraph of 1,000 vertices and 2,000 internal edges in
a graph of 106 vertices and 6×106 edges. For concreteness, assume the graph was generated
by the following process. First, a 1,000-vertex graph with 2,000 edges was generated as a
random regular degree four graph. The 1,000-vertex graph was then augmented to have
106 vertices and edges were added at random until all vertices were of degree 12. Note
that each vertex among the ﬁrst 1,000 has four edges to other vertices among the ﬁrst
1,000 and eight edges to other vertices. The graph on the 1,000 vertices is much denser
than the whole graph in some sense. Although the subgraph induced by the 1,000 vertices
has four edges per vertex and the full graph has twelve edges per vertex, the probability
of two vertices of the 1,000 being connected by an edge is much higher than for the graph
as a whole. The probability is given by the ratio of the actual number of edges connecting
vertices among the 1,000 to the number of possible edges if the vertices formed a complete
graph. A(S,S)

|S|2 ?]

p =

e
(cid:1)(cid:1) =
(cid:0)(cid:0)v
2

2e
v(v − 1)

For the 1,000 vertices, this number is p = 2×2,000
1,000×999

∼= 4 × 10−3. For the entire graph this

283

number is p = 2×6×106
connected should allow us to ﬁnd the dense subgraph.

106×106 = 12 × 10−6. This diﬀerence in probability of two vertices being

In our example, the cut of all arcs out of s is of capacity 6 × 106, the total number
of edges in the graph, and the cut of all arcs into t is of capacity λ times the number
of vertices or λ × 106. A cut separating the 1,000 vertices and 2,000 edges would have
capacity 6 × 106 − 2, 000 + λ × 1, 000. This cut cannot be the minimum cut for any value
of λ since es
v . The point is that to ﬁnd the 1,000 vertices, we
vs
have to maximize A(S, S)/|S|2 rather than A(S, S)/|S|. Note that A(S, S)/|S|2 penalizes
large |S| much more and therefore can ﬁnd the 1,000 node “dense” subgraph.

v = 6, hence es
vs

= 2 and e

< e

8.10 Finding a Local Cluster Without Examining the Whole

Graph

If one wishes to ﬁnd the community containing a vertex v in a large graph with say a
billion vertices, one would like to ﬁnd the community in time proportional to the size of
the community and independent of the size of the graph. Thus, we would like local meth-
ods that do not inspect the entire graph but only the neighborhood around the vertex v.
We now give several such algorithms. Throughout this section, we assume the graph is
undirected.

Breadth-First Search

The simplest method is to do a breadth ﬁrst search starting at v. Clearly if there is
a small connected component containing v, we will ﬁnd it in time depending only on the
size (number of edges) of the component. In a more subtle situation, each edge may have
a weight that is the similarity between the two end points. If there is a small cluster C
containing v, with each outgoing edge from C to ¯C having weight less than some ε, C
could clearly also be found by breadth-ﬁrst search in time proportional to the size of C.
However, in general, it is unlikely that the cluster will have such obvious telltale signs of
its boundary and one needs more complex techniques, some of which we describe now.

By max ﬂow

Given a vertex v in a directed graph, we want to ﬁnd a small set S of vertices whose
boundary (set of a few outgoing edges) is very small. Suppose we are looking for a set
S whose boundary is of size at most b and whose cardinality is at most k. Clearly, if
deg (v) < b then the problem is trivial, so assume deg (v) ≥ b.

Think of a ﬂow problem where v is the source. Put a capacity of one on each edge
of the graph. Create a new vertex that is the sink and add an edge of capacity α from
each vertex of the original graph to the new sink vertex, where α = b/k. If a community
of size at most k with boundary at most b containing v exists, then there will be a cut

284

separating v from the sink of size at most kα + b = 2b, since the cut will have k edges
from the community to the sink and b edges from the community to the remainder of the
graph. Conversely, if there is a cut of size at most 2b, then the community containing v
has a boundary of size at most 2b and has at most 2k vertices since each vertex has an
edge to the sink with capacity b
k . Thus, to come within a factor of two of the answer, all
one needs to do is determine whether there is a cut of size at most 2b. Since we know that
the minimum size of any cut equals the maximum ﬂow, it suﬃces to ﬁnd the maximum
ﬂow. If the ﬂow algorithm can do more than 2k ﬂow augmentations, then the maximum
ﬂow and hence the minimum cut is of size more than 2b. If not, the minimum cut is of
size at most 2b.

In executing the ﬂow algorithm one ﬁnds an augmenting path from source to sink and
augments the ﬂow. Each time a new vertex not seen before is reached, there is an edge
to the sink and the ﬂow can be augmented by α directly on the path from v to the new
vertex to the sink. So the amount of work done is a function of b and k, not the total
number of vertices in the graph.

Sparsity and Local communities

In this part, we consider another deﬁnition of a local community. A local community
in an undirected graph G(V, E) is a subset of vertices with strong internal similarities and
weak similarities to the outside. Using the same notation as in Section 8.5, we formalize
this as follows:

Deﬁnition 8.2 A subset S of vertices is a local community with parameter ε > 0 if it
satisﬁes the following conditions:

Φ(S, ¯S) ≤ ε3

∀T ⊆ S, d(T ) ≤

1
2

d(S), Φ(T, S \ T ) ≥ ε.

(8.2)

(8.3)

The ﬁrst condition says that the connections of S to the outside ¯S are weak. The second
condition requires subsets of S of size as measured by d(·) less than 1/2 of the size of S to
be strongly connected to the rest of S. Otherwise, S would not be one community, rather
it would split into at least two. Note that for ε << 1, we have ε3 << ε and so the internal
connections are required to be much stronger than the external ones. This is intuitively
consistent with what we think of as a strong community. However, as opposed to Section
8.5, where, we spent time that grows as a function of |V | since recursive clustering starts
with the whole of V as one cluster, here, we will assume that |S| << |U | and would like
to ﬁnd S in time which grows as a function of |S|, not |V |.

To accomplish this, we do a random walk on the graph starting with a vertex in S

285

Figure 8.7: Example of a highly connected, low sparsity community.

with transition probability matrix P (See Chapter 5) given by:

pij =

1
di

for j adjacent to i.

Recall from Chapter 5 that the Fundamental Theorem of Markov Chains proved that the
long-term average probability vector converges to a stationary probability π given by

πi =

d(i)
j∈V d(j)

(cid:80)

,

assuming G is connected.

If the Markov Chain is run for long enough, the probabilities will “spread” throughout
V in proportion to the degrees. This is not desirable in this context. We would rather
have it be essentially conﬁned to S, our local community. Intuitively, since S ’s connection
to ¯S is at most ε3, if we run the Markov Chain for O(1/ε2) steps, we hope to have only
ε probability of stepping into ¯S. Unfortunately, this is not valid. There may be a few
boundary vertices in S that have strong connections to ¯S and if we happen to start in
one of them, we might step into ¯S right away. All we can assert is that for most starting
points in S, we do not step into ¯S in O(1/ε2) steps. We now show this.

Lemma 8.13 Suppose condition (8.2) is satisﬁed. Then there is a subset S0 of S with
π(S0) ≥ 3
4π(S) such that starting the Markov Chain at any i in S0 and running it for
t0 ∈ O(1/ε2) steps, the probability that we ever step into ¯S is at most O(ε).

Proof: For i ∈ S and t ∈ O(1/ε2), let f (i, t) be the probability that the Markov chain
started at vertex i at time 0, walks from S to a vertex in ¯S at time t. We would like
to upper bound f (i, t). While this is diﬃcult, observe that had the walk started in the

286

stationary distribution π, then it would remain in the stationary distribution and so the
probability that it would step from a vertex in S to a vertex in ¯S at time t is precisely
(cid:80)
j∈S

πjpjk = Φ(S)π(S). By linearity, this probability is (cid:80)

πif (i, t), so

i∈S

(cid:80)
k∈ ¯S

πif (i, t) = Φ(S)π(S) ≤ ε3π(S)

(cid:88)

i∈S

Let fi be the probability that when started at time 0 at i, we step at least once into ¯S in
the ﬁrst O(1/ε2) steps of the Markov Chain. We get from above that:

(cid:88)

i∈S

πi
π(S)

fi ≤ O(ε).

i∈S

But (cid:80)
πi
π(S) fi is the weighted average of fi over i ∈ S with weights πi/π(S) and so by
Markov inequality, it follows that the weight of the set of i for which fi > cε for a large
constant c cannot exceed 1/4 proving the lemma.

To discover S, besides not going out of S, we also need that the walk spreads through all,
or at least most, of S which we now show.

Lemma 8.14 Suppose conditions (8.2) and (8.3) are satisﬁed. Start the markov Chain
in S0 and run it for t0 steps. Let S1 be the set of all i ∈ S for which the expected number
of visits is at least (3/4)πi/π(S)t0. Then, π(S1) ≥ (3/4)π(S).

Proof: For i ∈ S and t ≤ t0, let

git = Prob(Walk remains in S and is at i at time t)

hi =

1
t0

t0−1
(cid:88)

t=0

git.

From Lemma 8.13, we have

(cid:88)

i∈S

git = Prob(Walk remains in S) ≥ 1 − O(ε) =⇒

(cid:88)

i∈S

hi ≥ 1 − O(ε).

(8.4)

Let ˜P be the transition probability matrix of a Markov chain with states S obtained from
P by redirecting each transition (i, j) from a vertex i ∈ S to a vertex j ∈ ¯S to be a
self-loop at i. More formally, ˜pjk = pjk, for j, k ∈ S and for all i ∈ S, ˜pii = 1 − (cid:80)
pij. We

j(cid:54)=i

still have πj ˜pjk = πk ˜pkj and so (from Chapter 5), we know that the stationary probability
of the chain ˜P is

1
π(S) π.

Further, the conductance of ˜P is at least ε by (8.3). Let p(t) denote the probabilities

of the chain ˜P at time t and let a denote the long term average, i.e.,

a =

1
t0

t0−1
(cid:88)

t=0

p(t).

287

From Theorem 5.12 of Chapter 5,

(cid:12)
(cid:12)
(cid:12)a − 1

π(S)π

(cid:12)
(cid:12)
(cid:12) ≤ 1

100, Thus

a(S1) ≤

π(S1)
π(S)

+

1
100

.

(8.5)

Now, for each i ∈ S, git ≤ p(t)
, since every run of the walk that never steps out of S has
i
a corresponding run in ˜P . This is an inequality rather than an equation because, walks
which would have stepped out of S are now redirected via the self-loop we created; they
are counted in p(t)
, but not in git. So, hi ≤ ai and hence, h(S1) ≤ a(S1). Using (8.5) and
i
(8.4):

h(S \ S1) = h(S) − h(S1) ≥ h(S) − a(S1) ≥ 1 − O(ε) −

π(S1)
π(S)

−

1
100

≥

π(S \ S1)
π(S)

−

1
50

.

But, h(S \ S1) ≤ 3
4

π(S\S1)
π(S)

. Thus, π(S \ S1) ≤ 4

50 proving the lemma.

Modularity clustering

Another way to partition a graph into communities is based on the concept of modu-
larity. The method is popular for small graphs. Consider the partition of the vertices of
a graph into communities. The modularity of the partition is deﬁned to be the fraction
of edges that lie within communities minus the expected number of edges that lie within
communities in a random graph with the same degree distribution. Let A be the adja-
cency matrix of a graph, m the total number of edges, dv the degree of vertex v, and let
i index the communities deﬁned by a partition of the vertices. Then, the modularity is
given by

Q = 1
2m

(cid:80)
i

(cid:80)
v,w∈i

avw − (cid:80)

(cid:80)
v,w∈i

i

dv
2m

dw
2m

Let eij denote the fraction of the total set of edges that connect communities i and j and
let ai denote the fraction of edges with ends in community i. Then

and

Write

eij = 1
2m

avw

(cid:80)

v∈i
w∈j

ai = 1
2m

(cid:80)
v∈i

dv

(cid:88)

(cid:88)

Q =

(cid:0) 1
2m avw − dv

2m

dw
2m

(cid:1)

v,w∈i

(cid:0)eij − a2

i

(cid:1)

=

i
(cid:88)

i

288

The algorithm for ﬁnding communities works as follows. Start with each vertex in a
community. Repeatedly merge the pair of communities that maximizes the change in Q.
This can be done in time O (cid:0)m log2 n(cid:1) where n is the number of vertices in the graph and
m is the number of edges where m ≥ n. The algorithm works well on small graphs but is
ineﬃcient for graphs with even a few thousand vertices.

Percolation clustering

Another clustering method that is useful in clustering nodes of a graph is called per-
colation clustering. Here one selects a value k and creates a new graph whose vertices
correspond to k-cliques in the original graph. Edges in this new graph correspond to k-1
cliques connecting the k-cliques in the original graph. The connected components of this
new graph are the clusters for the original graph.

8.11 Axioms for Clustering

Each clustering algorithm tries to optimize some criterion, like the sum of squared
distances to the nearest cluster center, over all possible clusterings. We have seen many
diﬀerent optimization criteria in this chapter and many more are used. Now, we take a
step back and ask what are the desirable properties of a clustering criterion and if there are
criteria satisfying these properties. Our ﬁrst result is negative. We present three seemingly
desirable properties of a measure, and then show that no measure satisﬁes them. Next we
argue that these requirements are too stringent and under more reasonable requirements,
a slightly modiﬁed form of the sum of Euclidean distance squared between all pairs of
points inside the same cluster is indeed a measure satisfying the desired properties.

8.11.1 An Impossibility Result

Let A(d) denote the optimal clustering found by the clustering algorithm A using dis-
tance function d on a set S. The clusters of the clustering A(d) form a partition Γ of S.

The ﬁrst desirable property of a clustering algorithm is scale invariance. A clustering
algorithm A is scale invariant if for any α > 0, A(d) = A(αd). That is, multiplying all
distances by some scale factor does not change the optimal clustering. In general, there
could be ties for what the algorithm returns; in that case, we adopt the convention that
A(d) = A(αd) really means for any clustering returned by A on distance d, it can also be
returned by A on distance αd.

A clustering algorithm A is rich (full/complete) if for every partitioning Γ there ex-
ists a distance function d such that A(d) = Γ. That is, for any desired partitioning, we
can ﬁnd a set of distances so that the clustering algorithm returns the desired partitioning.

A clustering algorithm is consistent if increasing the distance between points in diﬀer-
ent clusters and reducing the distance between points in the same cluster does not change

289

the clusters produced by the clustering algorithm.

If a clustering algorithm is consistent and A(d) = Γ, one can ﬁnd a new distance
function d(cid:48) such that A(d(cid:48)) = Γ where there are only two distances a and b. Here a
is the distance between points within a cluster and b is the distance between points in
diﬀerent clusters. By consistency, we can reduce all distances within clusters and increase
all distances between clusters there by getting two distances a and b with a < b where
a is the distance between points within a cluster and b is the distance between points in
diﬀerent clusters.

There exist natural clustering algorithms satisfying any two of the three axioms. The
single link clustering algorithm starts with each point in a cluster by itself and then merges
the two clusters that are closest. The process continues until some stopping condition is
reached. One can view the process as the points being vertices of a graph and edges being
labeled by the distances between vertices. One merges the two vertices that are closest
and merges parallel edges taking the distance of the merged edge to be the minimum of
the two distances.

Theorem 8.15

1. The single link clustering algorithm with the k-cluster stopping condition, stop when
there are k clusters, satisﬁes scale-invariance and consistency. We do not get rich-
ness since we only get clustering’s with k clusters.

2. The single link clustering algorithm with scale α stopping condition satisﬁes scale
invariance and richness. The scale α stopping condition is to stop when the closest
pair of clusters is of distance greater than or equal to αdmax where dmax is the max-
imum pair wise distance. Here we do not get consistency. If we select one distance
between clusters and increase it signiﬁcantly until it becomes dmax and in addition
αdmax exceeds all other distances, the resulting clustering has just one cluster con-
taining all of the points.

3. The single link clustering algorithm with the distance r stopping condition, stop when
the inter-cluster distances are all at least r, satisﬁes richness and consistency; but
not scale invariance.

Proof: (1) Scale-invariance is easy to see. If one scales up all distances by a factor, then
at each point in the algorithm, the same pair of clusters will be closest. The argument for
consistency is more subtle. Since edges inside clusters of the optimal (ﬁnal) clustering can
only be decreased and since edges between clusters can only be increased, the edges that
led to merges between any two clusters are less than any edge between the ﬁnal clusters.
Since the ﬁnal number of clusters is ﬁxed, these same edges will cause the same merges
unless the merge has already occurred due to some other edge that was inside a ﬁnal
cluster having been shortened even more. No edge between two ﬁnal clusters can cause a
merge before all the above edges have been considered. At this time the ﬁnal number of

290

clusters has been reached and the process of merging has stopped.

(2) and (3) are straight forward.

Next, we show that no clustering algorithm can satisfy all three axioms. A distance
function d, (a-b)-conforms to a partition Γ if all points in a cluster are within distance
a of each other and all points in distinct clusters are at least distance b apart. For a
clustering algorithm A, the pair of numbers (a, b) is said to force the partition Γ if all
distances functions d that (a-b) conform to Γ have A(d) = Γ.

Associated with a clustering algorithm is a collection of allowable clustering’s it can
produce using diﬀerent distance functions. We begin with a theorem stating that scale
invariance and consistency imply that no allowable clustering can be a reﬁnement of
another allowable clustering.

Theorem 8.16 If a clustering algorithm satisﬁes scale-invariance and consistency, then
no two clustering’s, one of which is a reﬁnement of the other, can both be optimal clus-
tering’s returned by the algorithm.

Proof: Suppose that the range of the clustering algorithm A contains two clustering’s,
Γ0 and Γ1 where Γ0 is a reﬁnement of Γ1. Modify the distance functions giving rise to Γ0
and Γ1 so that there are only two distinct distances a0 and b0 for Γ0 and a1 and b1 for Γ1.
Points within a cluster of Γ0 are distance a0 apart and points between clusters of Γ0 are
distance b0 apart. The distances a1 and b1 play similar roles for Γ1.

Let a2 be any number less than a1 and choose ε such that 0 < ε < a0a2b−1

0 . Let d be

a new distance function where



d (i, j) =

ε if i and j are in the same cluster of Γ0
a2 if i and j are in diﬀernt clusers of Γ0 but the same cluster of Γ1
b1 if i and j are in diﬀerent clusters of Γ1



From a0 < b0 it follows that a0b−1
and a2 are less than a1, it follows by consistency that A (d) = Γ1. Let α = b0a−1
ε < a0a2b−1

0 and a2 < a1 < b1, which implies a−1

0 < a2 < a1. Since both ε
2 . Since

0 < 1. Thus ε < a0a2b−1

1 , it follows that

2 > a−1

1 > b−1

αd (i, j) =






b0a−1

2 ε < b0a−1

2 a0a2b−1

0 = a0

b0a−1

2 a2 = b0

b0a−1

2 b1 > b0b−1

1 b1 = b0

if i and j are in the same cluster of Γ0

if i and j are in diﬀernt clusers of Γ0
but the same cluster of Γ1

if i and j are in diﬀerent clusters of Γ1

Thus, by consistency A(αd) = Γ0. But by scale invariance A (αd) = A (d) = Γ1, a
contradiction.

291

Γ1

Γ0

New
distance
function d

a1

b0

a2 < a1

a0

(cid:15)

a0

(cid:15)

b1

b0

b1

a1

a0

(cid:15)

Figure 8.8: Illustration of the sets Γ0, Γ1, and those for the distance function d.

Corollary 8.17 For n ≥ 2 there is no clustering function f that satisﬁes scale-invariance,
richness, and consistency.

It turns out that any collection of clustering’s in which no clustering is a reﬁnement
of any other clustering in the collection is the range of a clustering algorithm satisfying
scale invariance and consistency. To demonstrate this, we use the sum of pairs clustering
algorithm. Given a collection of clustering’s, the sum of pairs clustering algorithm ﬁnds
the clustering that minimizes the sum of all distances between points in the same cluster
over all clustering’s in the collection.

Theorem 8.18 Every collection of clustering’s in which no clustering is the reﬁnement
of another is the range of a clustering algorithm A satisfying scale invariance and consis-
tency.

Proof: We ﬁrst show that the sum of pairs clustering algorithm satisﬁes scale invariance
and consistency. Then we show that every collection of clustering’s in which no cluster is
a reﬁnement of another can be achieved by a sum of pairs clustering algorithm.

Let A be the sum of pairs clustering algorithm. It is clear that A satisﬁes scale invari-
ance since multiplying all distances by a constant, multiplies the total cost of each cluster
by a constant and hence the minimum cost clustering is not changed.

To demonstrate that A satisﬁes consistency let d be a distance function and Γ the
resulting clustering. Increasing the distance between pairs of points in diﬀerent clusters
of Γ does not aﬀect the cost of Γ. If we reduce distances only between pairs of points in
clusters of Γ then the cost of Γ is reduced as much or more than the cost of any other
clustering. Hence Γ remains the lowest cost clustering.

Consider a collection of clustering’s in which no cluster is a reﬁnement of another. It
remains to show that every clustering in the collection is in the range of A. In sum of

292

A

B

A

B

Figure 8.9: Illustration of the objection to the consistency axiom. Reducing distances
between points in a cluster may suggest that the cluster be split into two.

pairs clustering, the minimum is over all clustering’s in the collection. We now show for
any clustering Γ how to assign distances between pairs of points so that A returns the
desired clustering. For pairs of points in the same cluster assign a distance of 1/n3. For
pairs of points in diﬀerent clusters assign distance one. The cost of the clustering Γ is less
than one. Any clustering that is not a reﬁnement of Γ has cost at least one. Since there
are no reﬁnements of Γ in the collection it follows that Γ is the minimum cost clustering.

Note that one may question both the consistency axiom and the richness axiom. The
following are two possible objections to the consistency axiom. Consider the two clusters
in Figure 8.9. If one reduces the distance between points in cluster B, they might get an
arrangement that should be three clusters instead of two.

The other objection, which applies to both the consistency and the richness axioms,
is that they force many unrealizable distances to exist. For example, suppose the points
were in Euclidean d space and distances were Euclidean. Then, there are only nd degrees
of freedom. But the abstract distances used here have O(n2) degrees of freedom since the
distances between the O(n2) pairs of points can be speciﬁed arbitrarily. Unless d is about
n, the abstract distances are too general. The objection to richness is similar. If for n
points in Euclidean d space, the clusters are formed by hyper planes each cluster may be
a Voronoi cell or some other polytope, then as we saw in the theory of VC dimensions
Section ?? there are only (cid:0)n
(cid:1) interesting hyper planes each deﬁned by d of the n points.
If k clusters are deﬁned by bisecting hyper planes of pairs of points, there are only ndk2
possible clustering’s rather than the 2n demanded by richness. If d and k are signiﬁcantly
less than n, then richness is not reasonable to demand. In the next section, we will see a
possibility result to contrast with this impossibility theorem.

d

The k-means clustering algorithm is one of the most widely used clustering algorithms.
We now show that any centroid based algorithm such as k-means does not satisfy the
consistency axiom.

Theorem 8.19 A centroid based clustering such as k-means does not satisfy the consis-
tency axiom.

Proof: The cost of a cluster is (cid:80)

(xi − u)2, where u is the centroid. An alternative way
to compute the cost of the cluster if the distances between pairs of points in the cluster are

i

293

√
5

y

√
2

All interpoint distances of

√
5

Figure 8.10: Example illustrating k-means does not satisfy the consistency axiom.

known is to compute 1
n

(cid:80)
i(cid:54)=j

(xi − xj)2 where n is the number of points in the cluster. For a

proof see Lemma 8.2. Consider seven points, a point y and two sets of three points each,
called X0 and X1. Let the distance from y to each point in X0 ∪X1 be
5 and let all other
2. These distances are achieved by placing each
distances between pairs of points be
point of X0 and X1 a distance one from the origin along a unique coordinate and placing
y at distance two from the origin along another coordinate. Consider a clustering with
two clusters (see Figure 8.9). The cost depends only on how many points are grouped
with y. Let that number be m. The cost is

√

√

1
m + 1

(cid:19)

(cid:20)

(cid:18)m
2
2

(cid:21)

+ 5m

+

2
6 − m

(cid:19)

(cid:18)6 − m
2

=

8m + 5
m + 1

which has its minimum at m = 0. That is, the point y is in a cluster by itself and all
other points are in a second cluster.

If we now shrink the distances between points in X0 and points in X1 to zero, the
optimal clustering changes. If the clusters were X0 ∪ X1 and y, then the distance would
be 9 × 2 = 18 whereas if the clusters are X0 ∪ {y} and X1, the distance would be only
3 × 5 = 15. Thus, the optimal clustering is X0 ∪ {y} and X1. Hence k-means does
not satisfy the consistency axiom since shrinking distances within clusters changes the
optimal clustering.

5 Relaxing the axioms

Given that no clustering algorithm can satisfy scale invariance, richness, and consis-
tency, one might want to relax the axioms in some way. Then one gets the following results.

294

1. Single linkage with a distance stopping condition satisﬁes a relaxed scale-invariance

property that states that for α > 1, then f (αd) is a reﬁnement of f (d).

2. Deﬁne reﬁnement consistency to be that shrinking distances within a cluster or
expanding distances between clusters gives a reﬁnement of the clustering. Single linkage
with α stopping condition satisﬁes scale invariance, reﬁnement consistency and richness
except for the trivial clustering of all singletons.

8.11.2 A Satisﬁable Set of Axioms

In this section, we propose a diﬀerent set of axioms that are reasonable for distances
between points in Euclidean space and show that the clustering measure, the sum of
squared distances between all pairs of points in the same cluster, slightly modiﬁed, is con-
sistent with the new axioms. We assume through the section that points are in Euclidean
d-space. Our three new axioms follow.

We say that a clustering algorithm satisﬁes the consistency condition if, for the clus-
tering produced by the algorithm on a set of points, moving a point so that its distance
to any point in its own cluster is not increased and its distance to any point in a diﬀer-
ent cluster is not decreased, then the algorithm returns the same clustering after the move.

Remark: Although it is not needed in the sequel, it is easy to see that for an inﬁnitesimal
perturbation dx of x, the perturbation is consistent if and only if each point in the cluster
containing x lies in the half space through x with dx as the normal and each point in a
diﬀerent cluster lies in the other half space.

An algorithm is scale-invariant if multiplying all distances by a positive constant does

not change the clustering returned.

An algorithm has the richness property if for any set K of k distinct points in the
ambient space, there is some placement of a set S of n points to be clustered so that the
algorithm returns a clustering with the points in K as centers. So there are k clusters,
each cluster consisting of all points of S closest to one particular point of K.

We will show that the following algorithm satisﬁes these three axioms.

Balanced k-means algorithm

Among all partitions of the input set of n points into k sets, each of size n/k, return
the one that minimizes the sum of squared distances between all pairs of points in
the same cluster.

295

Theorem 8.20 The balanced k-means algorithm satisﬁes the consistency condition, scale
invariance, and the richness property.

Proof: Scale invariance is obvious. Richness is also easy to see. Just place n/k points of
S to coincide with each point of K. To prove consistency, deﬁne the cost of a cluster T
to be the sum of squared distances of all pairs of points in T .

Suppose S1, S2, . . . , Sk is an optimal clustering of S according to the balanced k-
means algorithm. Move a point x ∈ S1 to z so that its distance to each point in S1 is
non increasing and its distance to each point in S2, S3, . . . , Sk is non decreasing. Suppose
T1, T2, . . . , Tk is an optimal clustering after the move. Without loss of generality assume
z ∈ T1. Deﬁne ˜T1 = (T1 \ {z}) ∪ {x} and ˜S1 = (S1 \ {x}) ∪ {z}. Note that ˜T1, T2, . . . , Tk
is a clustering before the move, although not necessarily an optimal clustering. Thus

cost

(cid:17)

(cid:16) ˜T1

+ cost (T2) + · · · + cost (Tk) ≥ cost (S1) + cost (S2) + · · · + cost (Sk) .

If cost (T1) − cost

(cid:17)

(cid:16) ˜T1

≥ cost

(cid:17)

(cid:16) ˜S1

− cost (S1) then

cost (T1) + cost (T2) + · · · + cost (Tk) ≥ cost

(cid:17)

(cid:16) ˜S1

+ cost (S2) + · · · + cost (Sk) .

Since T1, T2, . . . , Tk is an optimal clustering after the move, so also must be ˜S1, S2, . . . , Sk
proving the theorem.

It remains to show that cost (T1) − cos t

− cost (S1). Let u and v
stand for elements other than x and z in S1 and T1. The terms |u − v|2 are common to T1
and ˜T1 on the left hand side and cancel out. So too on the right hand side. So we need
only prove

≥ cost

(cid:17)

(cid:16) ˜T1

(cid:17)

(cid:16) ˜S1

(cid:88)

(|z − u|2 − |x − u|2) ≥

(|z − u|2 − |x − u|2).

(cid:88)

u∈T1

u∈S1

For u ∈ S1 ∩ T1, the terms appear on both sides, and we may cancel them, so we are left
to prove

(cid:88)

(|z − u|2 − |x − u|2) ≥

(|z − u|2 − |x − u|2)

(cid:88)

u∈T1\S1

u∈S1\T1

which is true because by the movement of x to z, each term on the left hand side is non
negative and each term on the right hand side is non positive.

296

8.12 Exercises

Exercise 8.1 Construct examples where using distances instead of distance squared gives
bad results for Gaussian densities. For example, pick samples from two 1-dimensional
unit variance Gaussians, with their centers 10 units apart. Cluster these samples by trial
and error into two clusters, ﬁrst according to k-means and then according to the k-median
criteria. The k-means clustering should essentially yield the centers of the Gaussians as
cluster centers. What cluster centers do you get when you use the k-median criterion?

Exercise 8.2 Let v = (1, 3). What is the L1 norm of v? The L2 norm? The square of
the L1 norm?

Exercise 8.3 Show that in 1-dimension, the center of a cluster that minimizes the sum
of distances of data points to the center is in general not unique. Suppose we now require
the center also to be a data point; then show that it is the median element (not the mean).
Further in 1-dimension, show that if the center minimizes the sum of squared distances
to the data points, then it is unique.

Exercise 8.4 Construct a block diagonal matrix A with three blocks of size 50. Each
matrix element in a block has value p = 0.7 and each matrix element not in a block has
value q = 0.3. generate a 150 × 150 matrix B of random numbers in the range [0,1]. If
bij ≥ aij replace aij with the value one. Otherwise replace aij with value zero. The rows of
A have three natural clusters. Permute the rows and columns of A so the ﬁrst 50 rows do
not form the ﬁrst cluster, the next 50 the second cluster, and the last 50 the third cluster.

1. Apply the k-mean algorithm to A with k = 3. Do you ﬁnd the correct clusters?

2. Apply the k-means algorithm to A for 1 ≤ k ≤ 10. Plot the value of the sum of

squares to the cluster centers versus k. Was three the correct value for k?

Exercise 8.5 Let M be a k × k matrix whose elements are numbers in the range [0,1].
A matrix entry close to one indicates that the row and column of the entry correspond to
closely related items and an entry close to zero indicates unrelated entities. Develop an
algorithm to match each row with a closely related column where a column can be matched
with only one row.

Exercise 8.6 The simple greedy algorithm of Section 8.3 assumes that we know the clus-
tering radius r. Suppose we do not. Describe how we might arrive at the correct r?

Exercise 8.7 For the k-median problem, show that there is at most a factor of two ratio
between the optimal value when we either require all cluster centers to be data points or
allow arbitrary points to be centers.

Exercise 8.8 For the k-means problem, show that there is at most a factor of four ratio
between the optimal value when we either require all cluster centers to be data points or
allow arbitrary points to be centers.

297

Exercise 8.9 Consider clustering points in the plane according to the k-median criterion,
where cluster centers are required to be data points. Enumerate all possible clustering’s
and select the one with the minimum cost. The number of possible ways of labeling n
points, each with a label from {1, 2, . . . , k} is kn which is prohibitive. Show that we can
ﬁnd the optimal clustering in time at most a constant times (cid:0)n
(cid:1) ≤ nk
which is much smaller than kn when k << n.

(cid:1) + k2. Note that (cid:0)n

k

k

Exercise 8.10 Suppose in the previous exercise, we allow any point in space (not neces-
sarily data points) to be cluster centers. Show that the optimal clustering may be found
in time at most a constant times n2k2.

Exercise 8.11 Corollary 8.3 shows that for a set of points {a1, a2, . . . , an}, there is a
|ai − x|2. Show examples

unique point x, namely their centroid, which minimizes

n
(cid:80)
i=1

where the x minimizing

|ai − x| is not unique. (Consider just points on the real line.)

n
(cid:80)
i=1

Show examples where the x deﬁned as above are far apart from each other.

n
(cid:80)
i=1

ai

Exercise 8.12 Let {a1, a2, . . . , an} be a set of unit vectors in a cluster. Let c = 1
n

be the cluster centroid. The centroid c is not in general a unit vector. Deﬁne the similarity
between two points ai and aj as their dot product. Show that the average cluster similarity
1
T is the same whether it is computed by averaging all pairs or computing the
n2

aiaj

(cid:80)
i,j

average similarity of each point with the centroid of the cluster.

Exercise 8.13 For some synthetic data estimate the number of local minima for k-means
by using the birthday estimate. Is your estimate an unbaised estimate of the number? an
upper bound? a lower bound? Why?

Exercise 8.14 Examine the example in Figure and discuss how to ﬁx it. Optimizing
according to the k-center or k-median criteria would seem to produce clustering B while
clustering A seems more desirable.

Exercise 8.15 Prove that for any two vectors a and b, |a − b|2 ≥ 1

2|a|2 − |b|2.

Exercise 8.16 Let A be an n×d data matrix, B its best rank k approximation, and C the
optimal centers for k-means clustering of rows of A. How is it possible that (cid:107)A − B(cid:107)2
F <
(cid:107)A − C(cid:107)2

F ?

Exercise 8.17 Suppose S is a ﬁnite set of points in space with centroid µ(S). If a set T
of points is added to S, show that the centroid µ(S ∪ T ) of S ∪ T is at distance at most
|S|+|T | |µ(T ) − µ(S)| from µ.

|T |

298

A

B

Figure 8.11: insert caption

Exercise 8.18 What happens if we relax this restriction, for example, if we allow for S,
the entire set?

Exercise 8.19 Given the graph G = (V, E) of a social network where vertices represent
individuals and edges represent relationships of some kind, one would like to deﬁne the
concept of a community. A number of deferent deﬁnitions are possible.

1. A subgraph S = (VS, ES) whose density ES
V 2
S

is greater than that of the graph E
V 2 .

2. A subgraph S with a low conductance like property such as the number of graph edges
leaving the subgraph normalized by the minimum size of S or V − S where size is
measured by the sum of degrees of vertices in S or in V − S.

3. A subgraph that has more internal edges than in a random graph with the same

degree distribution.

Which would you use and why?

Exercise 8.20 A stochastic matrix is a matrix with non negative entries in which each
row sums to one. Show that for a stochastic matrix, the largest eigenvalue is one. Show
that the eigenvalue has multiplicity one if and only if the corresponding Markov Chain is
connected.

Exercise 8.21 Show that if P is a stochastic matrix and π satisﬁes πipij = πjpji, then
for any left eigenvector v of P , the vector u with components ui = vi
is a right eigenvector
πi
with the same eigenvalue.

Exercise 8.22 In Theorem (??), how can one clustering C (0) be close to any proper
clustering? What if there are several proper clusterings?

Exercise 8.23 Give an example of a clustering problem where the clusters are not linearly
separable in the original space, but are separable in a higher dimensional space.
Hint: Look at the example for Gaussian kernels in the chapter on learning.

299

Exercise 8.24 The Gaussian kernel maps points to a higher dimensional space. What is
this mapping?

Exercise 8.25 Agglomerative clustering requires that one calculate the distances between
all pairs of points. If the number of points is a million or more, then this is impractical.
One might try speeding up the agglomerative clustering algorithm by maintaining a 100
clusters at each unit of time. Start by randomly selecting a hundred points and place each
point in a cluster by itself. Each time a pair of clusters is merged randomly select one of
the remaining data points and create a new cluster containing that point. Suggest some
other alternatives.

Exercise 8.26 Let A be the adjacency matrix of an undirected graph. Let d(S, S) = A(S,S)
be the density of the subgraph induced by the set of vertices S. Prove that d (S, S) is the
average degree of a vertex in S.

|S|

Exercise 8.27 Suppose A is a matrix with non negative entries. Show that A(S, T )/(|S||T |)
is maximized by the single edge with highest aij.

Exercise 8.28 Suppose A is a matrix with non negative entries and

σ1(A) = xT Ay =

(cid:88)

i,j

xiaijyj,

|x| = |y| = 1.

Zero out all xi less than 1/2
th of σ1(A).
than 1/4

√

n and all yj less than 1/2

d. Show that the loss is no more

√

Exercise 8.29 Consider other measures of density such as A(S,T )
ρ. Discuss the signiﬁcance of the densest subgraph according to these measures.

|S|ρ|T |ρ for diﬀerent values of

Exercise 8.30 Let A be the adjacency matrix of an undirected graph. Let M be the
2m . Partition the vertices into two groups S and ¯S.
matrix whose ijth element is aij − didj
Let s be the indicator vector for the set S and let ¯s be the indicator variable for ¯S. Then
sT M s is the number of edges in S above the expected number given the degree distribution
and sT M ¯s is the number of edges from S to ¯S above the expected number given the degree
distribution. Prove that if sT M s is positive sT M ¯s must be negative.

Exercise 8.31 Which of the three axioms, scale invariance, richness, and consistency
are satisﬁed by the following clustering algorithms.

1. k−means

2. Spectral Clustering.

Exercise 8.32 (Research Problem): What are good measures of density that are also
eﬀectively computable? Is there empirical/theoretical evidence that some are better than
others?

300

9 Topic Models, Hidden Markov Process, Graphical

Models, and Belief Propagation

In the chapter on learning and VC dimension, we saw many model-ﬁtting problems.
There we were given labeled data and simple classes of functions: half-spaces, support
vector machines, etc. The problem was to ﬁt the best model from a class of functions
to the data. Model ﬁtting is of course more general and in this chapter we discuss some
useful models. These general models are often computationally infeasible, in the sense
that they do not admit provably eﬃcient algorithms. Nevertheless, data often falls into
special cases of these models that can be solved eﬃciently.

9.1 Topic Models

A topic model is a model for representing a large collection of documents. Each docu-
ment is viewed as a combination of topics and each topic has a set of word frequencies. For
a collection of news articles over a period, the topics may be politics, sports, science, etc.
For the topic politics, the words like “president” and “election” may have high frequencies
and for the topic sports, words like “batter” and “goal” may have high frequencies. A
news item document may be 60% on politics and 40% on sports. The word frequencies
in the document will be convex combinations of word frequencies for the topics, politics
and sports, with weights 0.6 and 0.4 respectively. We describe this more formally with
vectors and matrices.

Each document is viewed as a “bag of words”. We disregard the order and context in
which each word occurs in the document and instead only list the frequency of occurrences
of each term. Frequency is the number of occurrences of the term divided by the total
number of all terms in the document. Discarding context information may seem wasteful,
but this approach works well in practice and is widely used. Each document is an n-
dimensional vector where n is the total number of diﬀerent terms in all the documents in
the collection. Each component of the vector is the frequency of a particular term in the
document. Terms are words or phrases. Not all words are chosen as terms; articles, simple
verbs, and pronouns like “a”, “is”, and “it” may be ignored. Represent the collection of
documents by a n × m matrix A, called the term-document matrix, with one column per
document in the collection. The topic model hypothesizes that there are r topics and
each of the m documents is a combination of topics. The number of topics r is usually
much smaller than the number of terms n. So corresponding to each document, there is
a vector with r components telling us the fraction of the document that is on each of the
topics. In the example above, this vector will have 0.6 in the component for politics and
0.4 in the component for sports. Arrange these vectors as the columns of a r × m matrix
C, called the topic-document matrix. There is a third matrix B which is n × r. Each
column of B corresponds to a topic; each component of the column gives the frequency of
a term in that topic. In the simplest model, the term frequencies in documents are exact
combinations of term frequencies in the various topics that make up the document. So,

301

aij, the frequency of the ith term in the jth document is the sum over all topics l of the
fraction of document j which is on topic l times the frequency of term i in topic l. In
matrix notation,

Pictorially, we can represent this as:

DOCUMENT

TOPIC

A = BC.















T
E
R
M

A
n × m















=















T
E
R
M

B
n × r























T
O
P
I
C

DOCUMENT

C
r × m









This model is too simple to be realistic since the frequency of each term in the doc-
ument is unlikely to be exactly what is given by the equation A = BC. So, a more
sophisticated stochastic model is used in practice.

From the document collection we observe the n × m matrix A. Can we ﬁnd B and
C such that A = BC? The top r singular vectors from a singular value decomposition
of A give a factorization BC. But there are additional constraints stemming from the
fact that frequencies of terms in one particular topic are nonnegative reals summing to
one and from the fact that the fraction of each topic a particular document is on are also
nonnegative reals summing to one. Altogether the constraints are:

1. A = BC and (cid:80)

aij = 1.

i

2. The entries of B and C are all non-negative.

3. Each column of B and each column of C sums to one.

Given the ﬁrst two conditions, we can achieve the third by multiplying the ith column
of B by a positive real number and dividing the ith row of C by the same real number
without violating A = BC. By doing this, one may assume that each column of B sums
to one. Since (cid:80)
i aij is the total frequency of all terms in document j, (cid:80)
i aij = 1. Now
aij = (cid:80)
k ckj = 1. Thus, the columns of C also
sum to one.

k bikckj implies (cid:80)

i,k bikckj = (cid:80)

i aij = (cid:80)

The problem can be posed as one of factoring the given matrix A into the product of

two matrices with nonnegative entries called nonnegative matrix factorization.

302

Nonnegative matrix factorization (NMF) Given an n × m matrix A and an in-
teger r, determine whether there is a factorization of A into XY where, X is an n × r
matrix with nonnegative entries and Y is r × m matrix with nonnegative entries and if
so, ﬁnd such a factorization.

Nonnegative matrix factorization is a more general problem than topic modeling and
there are many heuristic algorithms to solve the problem. But in general, they suﬀer
from one of two problems, they can get stuck at local optima that are not solutions
In practice,
or take exponential time.
often r is much smaller than n and m. We ﬁrst show that while the NMF problem as
formulated above is a nonlinear problem in r(n + m) unknown entries of X and Y , it
can be reformulated as a nonlinear problem with just 2r2 unknowns under the simple
nondegeneracy assumption that A has rank r. Think of r as say, 25, while n and m are
in the tens of thousands to see why this is useful.

In fact, the general NMF problem is NP-hard.

Lemma 9.1 If A has rank r, then the NMF problem can be formulated as a problem with
2r2 unknowns.

Proof: If A = XY , then each row of A is a linear combination of the rows of Y . So the
space spanned by the rows of A must be contained in the space spanned by the rows of Y .
The latter space has dimension at most r, while the former has dimension r. So they must
be equal. Thus, every row of Y must be a linear combination of the rows of A. Choose
any set of r independent rows of A to form a r × m matrix A1. Then Y = SA1 for some
r × r matrix S. By analogous reasoning, if A2 is a n × r matrix of r independent columns
of A, there is a r × r matrix T such that X = A2T . Now we can easily cast NMF in terms
of the unknowns S and T.

A = A2T SA1

(SA1)ij ≥ 0

(A2T )kl ≥ 0

∀i, j, k, l.

It remains to solve the nonlinear problem in the 2r2 variables. There is a classical al-
gorithm that solves such problems in time exponential in r2 and polynomial in the other
parameters. In fact, there is a logical theory, called the theory of reals of which this is
a special case and any problem in the theory of reals can be solved in time exponential
only in the number of variables. We do not give details here.

Besides the special case when r is small, there is another important case of NMF in
the topic modeling application that can be solved. This is the case when there are anchor
terms. An anchor term for a topic is a term that occurs in the topic and does not occur
in any other topic. For example, the term “batter” may an anchor term for the topic
baseball and “election” for the topic politics. Consider the case when each topic has an
anchor term. In matrix notation, this assumes that for each column of the term-topic
matrix B, there is a row whose sole nonzero entry is in that column. In this case, it is

303

easy to see that each row of the topic-document matrix C has a scaled copy of it occurring
as a row of the given term-document matrix A. Here is an illustrative diagram:

0.3 × c4

A
0.2 × c2





























election 0

0

0

0.3

=

batter

0 0.2

B
0

0















































.

c1
c2
c3
...
cn

If we knew which rows of A were copies of rows of C, called special rows of A, we could
ﬁnd C. Once C is known, we could solve the linear equations and inequalities, A = BC
and bij ≥ 0, to get B. The following lemma shows that after making one modiﬁcation,
we can ﬁnd the rows of A that are special. Suppose a row of C is a nonnegative linear
combination of the other rows of C. Eliminate that row of C as well as the corresponding
column of B, suitably modifying the other columns of B, maintaining A = BC. For
example, if row 5 of C equals 4 times row 3 of C plus 3 times row 6 of C, then we can
delete row 5 of C, then add 4 times column 5 of B to column 3 of B and add 3 times
column 5 of B to column 6 of B and delete column 5 of B.

Repeating this until each row of C is positively independent of the other rows of C,
i.e., it cannot be expressed as a nonnegative linear combination of the other rows. We still
have a scaled copy of each row of C in A. Further, the other rows of A are all nonnegative
linear combinations of rows of C and thus are nonnegative linear combinations of the
special rows of A.

Lemma 9.2 Suppose A has a factorization A = BC, where the rows of C are positively
independent and for each column of B, there is a row that has its sole nonzero entry in
that column. Then there is a scaled copy of each row of C in A and furthermore, the rows
of A that are scaled copies of rows of C are precisely the rows of A that are positively
independent of other rows of A. These rows can be identiﬁed by solving a linear program,
one program per row.

Proof: The set of special rows of A can be identiﬁed by solving n linear programming
problems. Check each row of A to see if it is positively independent of all other rows.
Denote by ai the i th row of A. Then, the ith row is positively dependent upon the others
if and only if there are real numbers x1, x2, . . . xi−1, xi+1, . . . xn such that

This is a linear program.

(cid:88)

j(cid:54)=i

xjaj = ai,

xj ≥ 0.

304

As we remarked earlier, the equation A = BC will not hold exactly. A more practical
model views A as a matrix of probabilities rather than exact frequencies. In this model,
each document is generated by picking its terms in independent trials. Each trial for
document j picks term 1 with probability a1j; term 2 with probability a2j, etc. We are
not given entire documents; instead we are given s independent trials for each document.
Our job is to ﬁnd B and C. We do not discuss the details of either the model or the
algorithms. In this new situation, algorithms are known to ﬁnd B and C when there exist
anchor terms, even with a small number s of trials.

At the heart of such an algorithm is the following problem:

Approximate NMF Given a n×m matrix A and the promise that there is a n×r matrix
B and a r × m matrix C, both with nonnegative entries, such that ||A − BC||F ≤ ∆, ﬁnd
B(cid:48) and C (cid:48) of the same dimensions, with nonnegative entries such that ||A − B(cid:48)C (cid:48)||F ≤ ∆(cid:48).

Here, ∆(cid:48) is related to ∆ and if the promise does not hold, the algorithm is allowed to

return any answer.

Now for the case when anchor words exist, this reduces to the problem of ﬁnding which
rows of A have the property that no point close to the row is positively dependent on
other rows. It is easy to write the statement that there is a vector y close to ai which is
positively dependent on the other rows as a convex program:

∃x1, x2, . . . , xi−1, xi+1, . . . , xn such that

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:88)

j(cid:54)=i

xjaj − ai

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

≤ ε.

| (cid:80)

j(cid:54)=i xjaj − ai| is convex function of xj and hence this problem can be solved eﬃciently.

9.2 Hidden Markov Model

A hidden Markov model , HMM, consists of a ﬁnite set of states with a transition
between each pair of states. There is an initial probability distribution α on the states
and a transition probability aij associated with the transition from state i to state j. Each
state has a probability distribution p(O, i) giving the probability of outputting the symbol
O in state i. A transition consists of two components. A state transition to a new state
followed by the output of a symbol. The HMM starts by selecting a start state according
to the distribution α and outputting a symbol.

Example: An example of a HMM is the graph with two states q and p illustrated below.

305

1
2

q
2h 1
2t

1

3
4

1
2

p
3h 1
3t

2

1
4

The initial distribution is α(q) = 1 and α(p) = 0. At each step a change of state occurs
followed by the output of heads or tails with probability determined by the new state.

We consider three problems in increasing order of diﬃculty. First, given a HMM what
is the probability of a given output sequence? Second, given a HMM and an output
sequence, what is the most likely sequence of states? And third, knowing that the HMM
has at most n states and given an output sequence, what is the most likely HMM? Only
the third problem concerns a ”hidden” Markov model. In the other two problems, the
model is known and the questions can be answered in polynomial time using dynamic
programming. There is no known polynomial time algorithm for the third question.

How probable is an output sequence

Given a HMM, how probable is the output sequence O = O0O1O2 · · · OT of length
T +1? To determine this, calculate for each state i and each initial segment of the sequence
of observations, O0O1O2 · · · Ot of length t + 1, the probability of observing O0O1O2 · · · Ot
ending in state i. This is done by a dynamic programming algorithm starting with t = 0
and increasing t. For t = 0 there have been no transitions. Thus, the probability of
observing O0 ending in state i is the initial probability of starting in state i times the
probability of observing O0 in state i. The probability of observing O0O1O2 · · · Ot ending
in state i is the sum of the probabilities over all states j of observing O0O1O2 · · · Ot−1
ending in state j times the probability of going from state j to state i and observing Ot.
The time to compute the probability of a sequence of length T when there are n states is
O(n2T ). The factor n2 comes from the calculation for each time unit of the contribution
from each possible previous state to the probability of each possible current state. The
space complexity is O(n) since one only needs to remember the probability of reaching
each state for the most recent value of t.

Algorithm to calculate the probability of the output sequence

The probability, Prob(O0O1 · · · OT , i) of the output sequence O0O1 · · · OT ending in

state i is given by

Prob(O0, i) = α(i)p(O0, i)

306

for t = 1 to T

Prob(O0O1 · · · Ot, i) = (cid:80)

Prob(O0O1 · · · Ot−1, j)aijp(Ot+1, i)

j

Example: What is the probability of the sequence hhht by the HMM in the above ex-
ample?

1
2

72

1

1

2 + 5
2 + 1
2 = 1

3
4

1

8

6

t = 3

t = 2

t = 1

t = 0

3
32

1
2

1
2

1
8

1
2

1
2

3
4

1

2 = 19

384

3
32

1
2

1

2 = 3

32

1
8

1
2

1
2

1
2

0

72

1

2

3 + 5
3 + 1
3 = 1

1
4

6

6

2

1
4

1

3 = 37

64×27

2

3 = 5

72

q

p

For t = 0, the q entry is 1/2 since the probability of being in state q is one and the proba-
bility of outputting heads is 1
2. The entry for p is zero since the probability of starting in
8 since for t = 0 the q entry is 1
state p is zero. For t = 1, the q entry is 1
2 and in state q
the HMM goes to state q with probability 1
2. The
p entry is 1
2 and in state q the HMM goes to state p with
probability 1
3. For t = 2, the q entry is 3
32 which
consists of two terms. The ﬁrst term is the probability of ending in state q at t = 1 times
the probability of staying in q and outputting h. The second is the probability of ending
in state p at t = 1 times the probability of going from state p to state q and outputting h.

6 since for t = 0 the q entry is 1
2 and outputs heads with probability 2

2 and outputs heads with probability 1

From the table, the probability of producing the sequence hhht is 19

384 + 37

1728 = 0.0709.

The most likely sequence of states - the Viterbi algorithm

Given a HMM and an observation O = O0O1 · · · OT , what is the most likely sequence of
states? The solution is given by the Viterbi algorithm, which is a slight modiﬁcation to the
dynamic programming algorithm just given for determining the probability of an output
sequence. For t = 0, 1, 2, . . . , T and for each state i, calculate the probability of the most
likely sequence of states to produce the output O0O1O2 · · · Ot ending in state i. For each
value of t, calculate the most likely sequence of states by selecting over all states j the most
likely sequence producing O0O1O2 · · · Ot and ending in state i consisting of the most likely
sequence producing O0O1O2 · · · Ot−1 ending in state j followed by the transition from j
to i producing Ot. Note that in the previous example, we added the probabilities of each
possibility together. Now we take the maximum and also record where the maximum
came from. The time complexity is O(n2T ) and the space complexity is O(nT ). The
space complexity bound is argued as follows. In calculating the probability of the most
likely sequence of states that produces O0O1 . . . Ot ending in state i, we remember the

307

previous state j by putting an arrow with edge label t from i to j. At the end, can ﬁnd
the most likely sequence by tracing backwards as is standard for dynamic programming
algorithms.

Example: For the earlier example what is the most likely sequence of states to produce
the output hhht?

t = 3

t = 2

t = 1

t = 0

1
2

24

1

1

2, 1
2, 1
q

3
4

6

max{ 1
48
max{ 1
8

1
2

1
2

1
2

1
2

1

8

2 = 1
q

3
4

1

2} = 1

64

1

2} = 3

48

q or p

p

max{ 3
48
max{ 1
8

1
2

1
4

1

3} = 1

96

2

3} = 1

24

q

q

1
2

24

2

1

3, 1
3, 1
q

1
4

6

1
2

1
2

2

3 = 1

6

0 p

Note that the two sequences of states, qqpq and qpqq, are tied for the most likely se-
quences of states.

Determining the underlying hidden Markov model

Given an n-state HMM, how do we adjust the transition probabilities and output
probabilities to maximize the probability of an output sequence O1O2 · · · OT ? The as-
sumption is that T is much larger than n. There is no known computationally eﬃcient
method for solving this problem. However, there are iterative techniques that converge
to a local optimum.

Let aij be the transition probability from state i to state j and let bj(Ok) be the
probability of output Ok given that the HMM is in state j. Given estimates for the HMM
parameters, aij and bj, and the output sequence O, we can improve the estimates by
calculating for each unit of time the probability that the HMM goes from state i to state
j and outputs the symbol Ok.

308

aij

transition probability from state i to state j

bj(Ot+1) probability of Ot+1 given that the HMM is in state j at time t + 1

αt(i)

probability of seeing O0O1 · · · Ot and ending in state i at time t

βt+1(j)

probability of seeing the tail of the sequence Ot+2Ot+3 · · · OT given state j
at time t + 1

δ(i, j)

probability of going from state i to state j at time t given the sequence
of outputs O

st(i)

probability of being in state i at time t given the sequence of outputs O

p(O)

probability of output sequence O

Given estimates for the HMM parameters, aij and bj, and the output sequence O, the
probability δt(i, j) of going from state i to state j at time t is given by the probability of
producing the output sequence O and going from state i to state j at time t divided by
the probability of producing the output sequence O.

δt(i, j) =

at(i)aijbj(Ot+1)βt+1(j)
p(O)

The probability p(O) is the sum over all pairs of states i and j of the numerator in the
above formula for δt(i, j). That is,

p(O) =

(cid:88)

(cid:88)

i

j

αt(j)aijbj(Ot+1)βt+1(j).

The probability of being in state i at time t is given by

st(i) =

n
(cid:88)

j=1

δt(i, j).

Note that δt(i, j) is the probability of being in state i at time t given O0O1O2 · · · Ot but
it is not the probability of being in state i at time t given O since it does not take into
account the remainder of the sequence O. Summing st(i) over all time periods gives the
expected number of times state i is visited and the sum of δt(i, j) over all time periods
gives the expected number of times edge i to j is traversed.

Given estimates of the HMM parameters ai,j and bj(Ok), we can calculate by the above

formulas estimates for

309

1. (cid:80)T −1

i=1 st(i), the expected number of times state i is visited and departed from

2. (cid:80)T −1

i=1 δt(i, j), the expected number of transitions from state i to state j

Using these estimates we can obtain new estimates of the HMM parameters

aij =

expected number of transitions from state i to state j
expected number of transitions out of state i

=

(cid:80)T −1

t=1 δt(i, j)
t=1 st(i)

(cid:80)T −1

bj(Ok) =

expected number of times in state j observing symbol Ok
expected number of times in state j

=

st(j)

T −1
(cid:80)
t=1
subject to
Ot=Ok
(cid:80)T −1

t=1 st(j)

By iterating the above formulas we can arrive at a local optimum for the HMM parameters
ai,j and bj(Ok).

9.3 Graphical Models, and Belief Propagation

A graphical model is a compact representation of a function of n variables x1, x2, . . . , xn.
It consists of a graph, directed or undirected, whose vertices correspond to variables that
take on values from some set. In this chapter, we consider the case where the function
is a probability distribution and the set of values the variables take on is ﬁnite, although
graphical models are often used to represent probability distributions with continuous vari-
ables. The edges of the graph represent relationships or constraints between the variables.

The directed model represents a joint probability distribution that factors into a prod-

uct of conditional probabilities.

p (x1, x2, . . . , xn) =

n
(cid:89)

i=1

p (xi|parents of xi)

It is assumed that the directed graph is acyclic. The directed graphical model is called
a Bayesian or belief network and appears frequently in the artiﬁcial intelligence and the
statistics literature.

The undirected graph model, called a Markov random ﬁeld, can also represent a joint
probability distribution of the random variables at its vertices. In many applications the
Markov random ﬁeld represents a function of the variables at the vertices which is to be
optimized by choosing values for the variables.

A third model called the factor model is akin to the Markov random ﬁeld, but here
the dependency sets have a diﬀerent structure. In the following sections we describe all
these models in more detail.

310

C1

D1

S1

C2

causes

D2

diseases

S2

symptoms

Figure 9.1: A Bayesian network

9.4 Bayesian or Belief Networks

A Bayesian network is a directed acyclic graph where vertices correspond to variables
and a directed edge from y to x represents a conditional probability p(x|y). If a vertex x
has edges into it from y1, y2, . . . , yk, then the conditional probability is p (x | y1, y2, . . . , yk).
The variable at a vertex with no in edges has an unconditional probability distribution.
If the value of a variable at some vertex is known, then the variable is called evidence.
An important property of a Bayesian network is that the joint probability is given by the
product over all nodes of the conditional probability of the node conditioned on all its
immediate predecessors.

In the example of Fig. 9.1, a patient is ill and sees a doctor. The doctor ascertains
the symptoms of the patient and the possible causes such as whether the patient was in
contact with farm animals, whether he had eaten certain foods, or whether the patient
has an hereditary predisposition to any diseases. Using the above Bayesian network where
the variables are true or false, the doctor may wish to determine one of two things. What
is the marginal probability of a given disease or what is the most likely set of diseases. In
determining the most likely set of diseases, we are given a T or F assignment to the causes
and symptoms and ask what assignment of T or F to the diseases maximizes the joint
probability. This latter problem is called the maximum a posteriori probability (MAP).

Given the conditional probabilities and the probabilities p (C1) and p (C2) in Example
9.1, the joint probability p (C1, C2, D1, . . .) can be computed easily for any combination
of values of C1, C2, D1, . . .. However, we might wish to ﬁnd that value of the variables
of highest probability (MAP) or we might want one of the marginal probabilities p (D1)
or p (D2). The obvious algorithms for these two problems require evaluating the proba-
bility p (C1, C2, D1, . . .) over exponentially many input values or summing the probability
p (C1, C2, D1, . . .) over exponentially many values of the variables other than those for

311

which we want the marginal probability. In certain situations, when the joint probability
distribution can be expressed as a product of factors, a belief propagation algorithm can
solve the maximum a posteriori problem or compute all marginal probabilities quickly.

9.5 Markov Random Fields

The Markov random ﬁeld model arose ﬁrst in statistical mechanics where it was called
the Ising model. It is instructive to start with a description of it. The simplest version
n grid. Each
of the Ising model consists of n particles arranged in a rectangular
particle can have a spin that is denoted ±1. The energy of the whole system depends
on interactions between pairs of neighboring particles. Let xi be the spin, ±1, of the ith
particle. Denote by i ∼ j the relation that i and j are adjacent in the grid. In the Ising
model, the energy of the system is given by

n ×

√

√

f (x1, x2, . . . , xn) = exp

c

(cid:32)

(cid:33)

|xi − xj|

.

(cid:88)

i∼j

c is a constant that can be positive or negative. If c < 0, then energy is lower if many
adjacent pairs have opposite spins and if c > 0 the reverse holds. The model was ﬁrst
used to model probabilities of spin conﬁgurations. The hypothesis was that for each
{x1, x2, . . . , xn} in {−1, +1}n, the energy of the conﬁguration with these spins is propor-
tional to f (x1, x2, . . . , xn).

In most computer science settings, such functions are mainly used as objective func-
tions that are to be optimized subject to some constraints. The problem is to ﬁnd the
minimum energy set of spins under some constraints on the spins. Usually the constraints
just specify the spins of some particles. Note that when c > 0, this is the problem of
minimizing (cid:80)
l imitsi∼j|xi − xj| subject to the constraints. The objective function is con-
vex and so this can be done eﬃciently. If c < 0, however, we need to minimize a concave
function for which there is no known eﬃcient algorithm. The minimization of a concave
function in general is NP-hard.

A second important motivation comes from the area of vision. It has to to do with
reconstructing images. Suppose we are given observations of the intensity of light at
individual pixels, x1, x2, . . . , xn and wish to compute the true values, the true intensities,
of these variables y1, y2, . . . , yn. There may be two sets of constraints, the ﬁrst stipulating
that the yi must be close to the corresponding xi and the second, a term correcting possible
observation errors, stipulating that yi must be close to the values of yj for j ∼ i. This
can be formulated as

Minimize

|xi − yi| +

|yi − yj|,

(cid:88)

(cid:88)

where the values of xi are constrained to be the observed values. The objective function
is convex and polynomial time minimization algorithms exist. Other objective functions

i

i∼j

312

x1 + x2 + x3

x1 + x2

x1 + x3

x2 + x3

x1

x2

x3

Figure 9.2: The factor graph for the function f (x1, x2, x3) = (x1 + x2 + x3) (x1 + x2) (x1 + x3) (x2 + x3) .

using say sum of squares instead of sum of absolute values can be used and thee are
polynomial time algorithms as long as the function to be minimized is convex.

More generally, the correction term may depend on all grid points within distance two
of each point rather than just immediate neighbors. Even more generally, we may have n
variables y1, y2, . . . yn with the value of some already speciﬁed and subsets S1, S2, . . . Sm of
these variables constrained in some way. The constraints are accumulated into one objec-
tive function which is a product of functions f1, f2, . . . , fm, where function fi is evaluated
on the variables in subset Si. The problem is to minimize (cid:81)m
i=1 fi(yj, j ∈ Si) subject to
constrained values. Note that the vision example had a sum instead of a product, but by
taking exponentials we can turn the sum into a product as in the Ising model.

In general, the fi are not convex; indeed they may be discrete. So the minimization
cannot be carried out by a known polynomial time algorithm. The most used forms of the
Markov random ﬁeld involve Si which are cliques of a graph. So we make the following
deﬁnition.

A Markov Random Field consists of an undirected graph and an associated function
that factorizes into functions associated with the cliques of the graph. The special case
when all the factors correspond to cliques of size one or two is of interest.

9.6 Factor Graphs

Factor graphs arise when we have a function f of a variables x = (x1, x2, . . . , xn) that
fα (xα) where each factor depends only on some small

can be expressed as f (x) = (cid:81)

α

number of variables xα. The diﬀerence from Markov random ﬁelds is that the variables
corresponding to factors do not necessarily form a clique. Associate a bipartite graph
where one set of vertices correspond to the factors and the other set to the variables.
Place an edge between a variable and a factor if the factor contains that variable. See

313

Figure 9.2

9.7 Tree Algorithms

Let f (x) be a function that is a product of factors. When the factor graph is a tree
there are eﬃcient algorithms for solving certain problems. With slight modiﬁcations, the
algorithms presented can also solve problems where the function is the sum of terms rather
than a product of factors.

The ﬁrst problem is called marginalization and involves evaluating the sum of f over
all variables except one. In the case where f is a probability distribution the algorithm
computes the marginal probabilities and thus the word marginalization. The second prob-
lem involves computing the assignment to the variables that maximizes the function f .
When f is a probability distribution, this problem is the maximum a posteriori probabil-
ity or MAP problem.

If the factor graph is a tree, then there exists an eﬃcient algorithm for solving these
problems. Note that there are four problems: the function f is either a product or a sum
and we are either marginalizing or ﬁnding the maximizing assignment to the variables. All
four problems are solved by essentially the same algorithm and we present the algorithm
for the marginalization problem when f is a product. Assume we want to “sum out” all
the variables except x1, so we will be left with a function of x1.

We call the variable node associated with the variable xi node xi. First, make the
node x1 the root of the tree. It will be useful to think of the algorithm ﬁrst as a recursive
algorithm and then unravel the recursion. We want to compute the product of all factors
occurring in the sub-tree rooted at the root with all variables except the root-variable
summed out. Let gi be the product of all factors occurring in the sub-tree rooted at
node xi with all variables occurring in the subtree except xi summed out. Since this is a
tree, x1 will not reoccur anywhere except the root. Now, the grandchildren of the root
are variable nodes and suppose for recursion, each grandchild xi of the root, has already
computed its gi. It is easy to see that we can compute g1 by the following.

Each grandchild xi of the root passes its gi to its parent, which is a factor node. Each
child of x1 collects all its children’s gi, multiplies them together with its own factor and
sends the product to the root. The root multiplies all the products it gets from its children
and sums out all variables except its own variable, namely here x1.

Unraveling the recursion is also simple, with the convention that a leaf node just re-
ceives 1, product of an empty set of factors, from its children. Each node waits until it
receives a message from each of its children. After that, if the node is a variable node,
it computes the product of all incoming messages, and sums this product function over
all assignments to the variables except for the variable of the node. Then, it sends the

314

x1

x1

x1 + x2 + x3

x3 + x4 + x5

x2

x3

x4

x4

x5

x5

Figure 9.3: The factor graph for the function f = x1 (x1 + x2 + x3) (x3 + x4 + x5) x4x5.

resulting function of one variable out along the edge to its parent. If the node is a factor
node, it computes the product of its factor function along with incoming messages from
all the children and sends the resulting function out along the edge to its parent.

The reader should prove that the following invariant holds assuming the graph is a tree:

Invariant The message passed by each variable node to its parent is the product of
all factors in the subtree under the node with all variables in the subtree except its own
summed out.

Consider the following example where

f = x1 (x1 + x2 + x3) (x3 + x4 + x5) x4x5

and the variables take on values 0 or 1. Consider marginalizing f by computing

f (x1) =

(cid:88)

x2x3x4x5

x1 (x1 + x2 + x3) (x3 + x4 + x5) x4x5,

In this case the factor graph is a tree as shown in Figure 9.3. The factor graph as a
rooted tree and the messages passed by each node to its parent are shown in Figure 9.4.
If instead of computing marginal’s, one wanted the variable assignment that maximizes
the function f , one would modify the above procedure by replacing the summation by a
maximization operation. Obvious modiﬁcations handle the situation where f (x) is a sum
of products.

f (x) =

g (x)

(cid:88)

x1,...,xn

9.8 Message Passing in general Graphs

The simple message passing algorithm in the last section gives us the one variable
function of x1 when we sum out all the other variables. For a general graph that is not
a tree, we formulate an extension of that algorithm. But unlike the case of trees, there
is no proof that the algorithm will converge and even if it does, there is no guarantee

315

(cid:80)

x2,x3

x1(x1 + x2 + x3)(2 + x3) = 10x2

1 + 11x1

x1

x1 ↑

x1

x1 + x2 + x3

1 ↑

x2

x3

(x1 + x2 + x3)(2 + x3) ↑

(cid:80)

x4,x5

(x3 + x4 + x5)x4x5

= 2 + x3 ↑

(x3 + x4 + x5)x4x5 ↑

x3 + x4 + x5

x4 ↑

x4 ↑

x4

x4

x5 ↑

x5 ↑

x5

x5

Figure 9.4: Messages.

that the limit is the marginal probability. This has not prevented its usefulness in some
applications.

First, lets ask a more general question, just for trees. Suppose we want to compute for
each i the one variable function of xi when we sum out all variables xj, j (cid:54)= i. Do we have
to repeat what we did for x1 once for each xi? Luckily, the answer is no. It will suﬃce
to do a second pass from the root to the leaves of essentially the same message passing
algorithm to get all the answers. Recall that in the ﬁrst pass, each edge of the tree has
sent a message “up”, from the child to the parent. In the second pass, each edge will send
a message from the parent to the child. We start with the root and work downwards for
this pass. Each node waits until its parent has sent it a message before sending messages
to each of its children. The rules for messages are:

Rule 1 The message from a factor node v to a child xi, which is the variable node xi,
is the product of all messages received by v in both passes from all nodes other than xi

316

times the factor at v itself.

Rule 2 The message from a variable node xi to a child, a factor node, v is the product
of all messages received by xi in both passes from all nodes except v, with all variables
except xi summed out. The message is a function of xi alone.

At termination, one can show when the graph is a tree that if we take the product
of all messages received in both passes by a variable node xi and sum out all variables
except xi in this product, what we get is precisely the entire function marginalized to xi.
We do not give the proof here. But the idea is simple. We know from the ﬁrst pass that
the product of the messages coming to a variable node xi from its children is the product
of all factors in the sub-tree rooted at xi. In the second pass, we claim that the message
from the parent v to xi is the product of all factors which are not in the sub-tree rooted
at xi which one can show either directly or by induction working from the root downwards.

We can apply the same rules 1 and 2 to any general graph. We do not have child and
parent relationships and it is not possible to have the two synchronous passes as before.
The messages keep ﬂowing and one hopes that after some time, the messages will stabilize,
but nothing like that is proven. We state the algorithm for general graphs now:

Rule 1 At each time, each factor node v sends a message to each adjacent node xi.
The message is the product of all messages received by v at the previous step except for
the one from xi multiplied by the factor at v itself.

Rule 2 At each time, each variable node xi sends a message to each adjacent node v.
The message is the product of all messages received by xi at the previous step except the
one from v, with all variables except xi summed out.

9.9 Graphs with a Single Cycle

The message passing algorithm gives the correct answers on trees and on certain other
graphs. One such situation is graphs with a single cycle which we treat here. We switch
from the marginalization problem to the MAP problem as the proof of correctness is sim-
pler for the MAP problem. Consider the network in the Figure 9.5a below with a single
cycle. The message passing scheme will multiply count some evidence. The local evidence
at A will get passed around the loop and will come back to A. Thus, A will count the local
evidence multiple times. If all evidence is multiply counted in equal amounts, then there
is a possibility that all though the numerical values of the marginal probabilities (beliefs)
are wrong, the algorithm still converges to the correct maximum a posteriori assignment.

Consider the unwrapped version of the graph in Figure 9.5b. The messages that the
loopy version will eventually converge to, assuming convergence, are the same messages
that occur in the unwrapped version provided that the nodes are suﬃciently far in from

317

A

B

C

(a) A graph with a single cycle

A

B

C

A

B

C

A

B

C

(b) Segment of unrolled graph

Figure 9.5: Unwrapping a graph with a single cycle

the ends. The beliefs in the unwrapped version are correct for the unwrapped graph since
it is a tree. The only question is, how similar are they to the true beliefs in the original
network.

Write p (A, B, C) = elog p(A,B,C) = eJ(A,B,C) where J (A, B, C) = log p (A, B, C). Then
the probability for the unwrapped network is of the form ekJ(A,B,C)+J (cid:48) where the J (cid:48) is
associated with vertices at the ends of the network where the beliefs have not yet stabi-
lized and the kJ (A, B, C) comes from k inner copies of the cycle where the beliefs have
stabilized. Note that the last copy of J in the unwrapped network shares an edge with J (cid:48)
and that edge has an associated Ψ. Thus, changing a variable in J has an impact on the
value of J (cid:48) through that Ψ. Since the algorithm maximizes Jk = kJ (A, B, C) + J (cid:48) in the
unwrapped network for all k, it must maximize J (A, B, C). To see this, set the variables
A, B, C, so that Jk is maximized. If J (A, B, C) is not maximized, then change A, B, and
C to maximize J (A, B, C). This increases Jk by some quantity that is proportional to
k. However, two of the variables that appear in copies of J (A, B, C) also appear in J (cid:48)
and thus J (cid:48) might decrease in value. As long as J (cid:48) decreases by some ﬁnite amount, we
can increase Jk by increasing k suﬃciently. As long as all Ψ’s are nonzero, J (cid:48) which is

318

y2

x2

y3

x3

x4

y4

y1

yn

x1

xn

Figure 9.6: A Markov random ﬁeld with a single loop.

proportional to log Ψ, can change by at most some ﬁnite amount. Hence, for a network
with a single loop, assuming that the message passing algorithm converges, it converges
to the maximum a posteriori assignment.

9.10 Belief Update in Networks with a Single Loop

In the previous section, we showed that when the message passing algorithm converges,
it correctly solves the MAP problem for graphs with a single loop. The message passing
algorithm can also be used to obtain the correct answer for the marginalization problem.
Consider a network consisting of a single loop with variables x1, x2, . . . , xn and evidence
y1, y2, . . . , yn as shown in Figure 9.6. The xi and yi can be represented by vectors having
a component for each value xi can take on. To simplify the discussion assume the xi take
on values 1, 2, . . . , m.

Let mi be the message sent from vertex i to vertex i + 1 mod n. At vertex i + 1
each component of the message mi is multiplied by the evidence yi+1 and the constraint
function Ψ. This is done by forming a diagonal matrix Di+1 where the diagonal elements
are the evidence and then forming a matrix Mi whose rsth element is Ψ (xi+1 = r, xi = s).
The message mi+1 is MiDi+1mi. Multiplication by the diagonal matrix Di+1 multiplies
the components of the message mi by the associated evidence. Multiplication by the
matrix Mi multiplies each component of the vector by the appropriate value of Ψ and
sums over the values producing the vector which is the message mi+1. Once the message
has travelled around the loop, the new message m(cid:48)

1 is given by

m(cid:48)

1 = MnD1Mn−1Dn · · · M2D3M1D2m1

319

Let M = MnD1Mn−1Dn · · · M2D3M1D2m1. Assuming that M ’s principle eigenvalue is
unique, the message passing will converge to the principle vector of M . The rate of con-
vergences depends on the ratio of the ﬁrst and second eigenvalues.

An argument analogous to the above concerning the messages gong clockwise around
the loop applies to messages moving counter clockwise around the loop. To obtain the es-
timate of the marginal probability p (x1), one multiples component wise the two messages
arriving at x1 along with the evidence y1. This estimate does not give the true marginal
probability but the true marginal probability can be computed from the estimate and the
rate of convergences by linear algebra.

9.11 Maximum Weight Matching

We have seen that the belief propagation algorithm converges to the correct solution
in trees and graphs with a single cycle. It also correctly converges for a number of prob-
lems. Here we give one example, the maximum weight matching problem where there is
a unique solution.

We apply the belief propagation algorithm to ﬁnd the maximal weight matching
(MWM) in a complete bipartite graph. If the MWM in the bipartite graph is unique,
then the belief propagation algorithm will converge to it.

Let G = (V1, V2, E) be a complete bipartite graph where V1 = {a1, . . . , an} , V2 =
1 ≤ i, j ≤ n. Let π = {π (1) , . . . , π (n)} be a per-
{b1, . . . , bn} , and (ai, bj) ∈ E,
mutation of {1, . . . , n}. The collection of edges (cid:8)(cid:0)a1, bπ(1)
(cid:1)(cid:9)is called a
matching which is denoted by π. Let wij be the weight associated with the edge (ai, bj).
wiπ(i). The maximum weight matching π∗ is

(cid:1) , . . . , (cid:0)an, bπ(n)

The weight of the matching π is wπ =
π∗ = arg max

wπ

π

n
(cid:80)
i=1

The ﬁrst step is to create a factor graph corresponding to the MWM problem. Each
edge of the bipartite graph is represented by a variable cij which takes on the values
zero or one. The value one means that the edge is present in the matching, the value
zero means that the edge is not present in the matching. A set of constraints is used to
force the set of edges to be a matching. The constraints are of the form (cid:80)
cij = 1 and
(cid:80)
i
deﬁnes a matching. In addition, we have constraints for the weights of the edges.

cij = 1. Any assignment of 0,1 to the variables cij that satisﬁes all of the constraints

j

We now construct a factor graph, a portion of which is shown in Fig. 9.10. Associated
with the factor graph is a function f (c11, c12, . . .) consisting of a set of terms for each cij
enforcing the constraints and summing the weights of the edges of the matching. The

320

terms for c12 are

−λ

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:32)

(cid:88)

(cid:33)

ci2

i

(cid:12)
(cid:12)
(cid:12)
− 1
(cid:12)
(cid:12)

− λ

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:32)

(cid:88)

j

c1j

(cid:33)

(cid:12)
(cid:12)
(cid:12)
− 1
(cid:12)
(cid:12)

+ w12c12

where λ is a large positive number used to enforce the constraints when we maximize the
function. Finding the values of c11, c12, . . . that maximize f ﬁnds the maximum weighted
matching for the bipartite graph.

If the factor graph was a tree, then the message from a variable node x to its parent
is a message g(x) that gives the maximum value for the sub tree for each value of x. To
compute g(x), one sums all messages into the node x. For a constraint node, one sums
all messages from sub trees and maximizes the sum over all variables except the variable
of the parent node subject to the constraint. The message from a variable x consists of
two pieces of information, the value p (x = 0) and the value p (x = 1). This information
can be encoded into a linear function of x.

[p (x = 1) − p (x = 0)] x + p (x = 0)

Thus, the messages are of the form ax + b. To determine the MAP value of x once the
algorithm converges, sum all messages into x and take the maximum over x=1 and x=0
to determine the value for x. Since the arg maximum of a linear form ax +b depends
only on whether a is positive or negative and since maximizing the output of a constraint
depends only on the coeﬃcient of the variable, we can send messages consisting of just
the variable coeﬃcient.

To calculate the message to c12 from the constraint that node b2 has exactly one
neighbor, add all the messages that ﬂow into the constraint node from the ci2, i (cid:54)= 1
nodes and maximize subject to the constraint that exactly one variable has value one. If
α (i, 2). If
c12 = 0, then one of ci2, i (cid:54)= 1, will have value one and the message is max
i(cid:54)=1

c12 = 1, then the message is zero. Thus, we get

− max
i(cid:54)=1

α (i, 2) x + max
i(cid:54)=1

α (i, 2)

and send the coeﬃcient − max

i(cid:54)=1

α (i, 2). This means that the message from c12 to the other

constraint node is β(1, 2) = w12 − max
i(cid:54)=1

α (i, 2).

The alpha message is calculated in a similar fashion. If c12 = 0, then one of c1j will
β (1, j). If c12 = 1, then the message is zero. Thus,

have value one and the message is max
j(cid:54)=1

the coeﬃcient − max

j(cid:54)=1

α (1, j) is sent. This means that α(1, 2) = w12 − max
j(cid:54)=1

α (1, j).

To prove convergence, we enroll the constraint graph to form a tree with a constraint
node as the root. In the enrolled graph a variable node such as c12 will appear a number
of times which depends on how deep a tree is built. Each occurrence of a variable such
as c12 is deemed to be a distinct variable.

321

w12c12

(cid:80)

j c1j = 1

c12

(cid:80)

i ci2 = 1

←
β(1, 2)

→
α(1, 2)

Constraint forcing
b2 to have exactly
one neighbor

Constraint forcing
a1to have exactly
one neighbor

c32

c42

cn2

Figure 9.7: Portion of factor graph for the maximum weight matching problem.

(cid:80)

j c1j = 1

c11

c13

c1n

(cid:80)

j ci2 = 1

(cid:80)

i ci2 = 1

c12

c22

c32

cn2

Figure 9.8: Tree for MWM problem.

322

Lemma 9.3 If the tree obtained by unrolling the graph is of depth k, then the messages
to the root are the same as the messages in the constraint graph after k-iterations.

Proof: Straight forward.

Deﬁne a matching in the tree to be a set of vertices so that there is exactly one variable
node of the match adjacent to each constraint. Let Λ denote the vertices of the matching.
Heavy circles represent the nodes of the above tree that are in the matching Λ.

Let Π be the vertices corresponding to maximum weight matching edges in the bi-
partite graph. Recall that vertices in the above tree correspond to edges in the bipartite
graph. The vertices of Π are denoted by dotted circles in the above tree.

Consider a set of trees where each tree has a root that corresponds to one of the con-
straints. If the constraint at each root is satisﬁed by the edge of the MWM, then we have
found the MWM. Suppose that the matching at the root in one of the trees disagrees
with the MWM. Then there is an alternating path of vertices of length 2k consisting of
vertices corresponding to edges in Π and edges in Λ. Map this path onto the bipartite
graph. In the bipartite graph the path will consist of a number of cycles plus a simple
path. If k is large enough there will be a large number of cycles since no cycle can be of
length more than 2n. Let m be the number of cycles. Then m ≥ 2k

2n = k
n .

Let π∗ be the MWM in the bipartite graph. Take one of the cycles and use it as an
alternating path to convert the MWM to another matching. Assuming that the MWM
is unique and that the next closest matching is ε less, Wπ∗ − Wπ > ε where π is the new
matching.

Consider the tree matching. Modify the tree matching by using the alternating path
of all cycles and the left over simple path. The simple path is converted to a cycle by
adding two edges. The cost of the two edges is at most 2w* where w* is the weight of the
maximum weight edge. Each time we modify Λ by an alternating cycle, we increase the
cost of the matching by at least ε. When we modify Λ by the left over simple path, we
increase the cost of the tree matching by ε − 2w∗ since the two edges that were used to
create a cycle in the bipartite graph are not used. Thus

weight of Λ - weight of Λ(cid:48) ≥ k

n ε − 2w∗

which must be negative since Λ(cid:48) is optimal for the tree. However, if k is large enough
this becomes positive, an impossibility since Λ(cid:48) is the best possible. Since we have a
tree, there can be no cycles, as messages are passed up the tree, each sub tree is optimal
and hence the total tree is optimal. Thus the message passing algorithm must ﬁnd the
maximum weight matching in the weighted complete bipartite graph assuming that the
maximum weight matching is unique. Note that applying one of the cycles that makes
up the alternating path decreased the bipartite graph match but increases the value of

323

a

b

c

i

j

Figure 9.9: warning propagation

the tree. However, it does not give a higher tree matching, which is not possible since
we already have the maximum tree matching. The reason for this is that the application
of a single cycle does not result in a valid tree matching. One must apply the entire
alternating path to go from one matching to another.

9.12 Warning Propagation

Signiﬁcant progress has been made using methods similar to belief propagation in
ﬁnding satisfying assignments for 3-CNF formulas. Thus, we include a section on a
version of belief propagation, called warning propagation, that is quite eﬀective in ﬁnding
assignments. Consider a factor graph for a SAT problem. Index the variables by i, j, and
k and the factors by a, b, and c. Factor a sends a message mai to each variable i that
appears in the factor a called a warning. The warning is 0 or 1 depending on whether
or not factor a believes that the value assigned to i is required for a to be satisﬁed. A
factor a determines the warning to send to variable i by examining all warnings received
by other variables in factor a from factors containing them.

For each variable j, sum the warnings from factors containing j that warn j to take
value T and subtract the warnings that warn j to take value F. If the diﬀerence says that
j should take value T or F and this value for variable j does not satisfy a, and this is
true for all j, then a sends a warning to i that the value of variable i is critical for factor a.

Start the warning propagation algorithm by assigning 1 to a warning with probability
1/2. Iteratively update the warnings. If the warning propagation algorithm converges,
then compute for each variable i the local ﬁeld hi and the contradiction number ci. The
local ﬁeld hi is the number of clauses containing the variable i that sent messages that
i should take value T minus the number that sent messages that i should take value F.
The contradiction number ci is 1 if variable i gets conﬂicting warnings and 0 otherwise.
If the factor graph is a tree, the warning propagation algorithm converges. If one of the
warning messages is one, the problem is unsatisﬁable; otherwise it is satisﬁable.

324

9.13 Correlation Between Variables

In many situations one is interested in how the correlation between variables drops oﬀ
with some measure of distance. Consider a factor graph for a 3-CNF formula. Measure
the distance between two variables by the shortest path in the factor graph. One might
ask if one variable is assigned the value true, what is the percentage of satisfying assign-
ments in which the second variable also is true. If the percentage is the same as when the
ﬁrst variable is assigned false, then we say that the two variables are uncorrelated. How
diﬃcult it is to solve a problem is likely to be related to how fast the correlation decreases
with distance.

Another illustration of this concept is in counting the number of perfect matchings
in a graph. One might ask what is the percentage of matching in which some edge is
present and ask how correlated this percentage is with the presences or absence of edges
at some distance d. One is interested in whether the correlation drops oﬀ with distance.
To explore this concept we consider the Ising model studied in physics.

The Ising or ferromagnetic model is a pairwise random Markov ﬁeld. The underlying
graph, usually a lattice, assigns a value of ±1, called spin, to the variable at each ver-
tex. The probability (Gibbs measure) of a given conﬁguration of spins is proportional
to exp(β (cid:80)
eβxixj where xi = ±1 is the value associated with vertex i.

xixj) = (cid:81)

(i,j)∈E

(i,j)∈E

Thus

p (x1, x2, . . . , xn) = 1
Z

(cid:81)

(i,j)∈E

exp(βxixj) = 1

Z e

where Z is a normalization constant.

β (cid:80)
(i,j)∈E

xixj

The value of the summation is simply the diﬀerence in the number of edges whose
vertices have the same spin minus the number of edges whose vertices have opposite spin.
The constant β is viewed as inverse temperature. High temperature corresponds to a low
value of β and low temperature corresponds to a high value of β. At high temperature,
low β, the spins of adjacent vertices are uncorrelated whereas at low temperature adjacent
vertices have identical spins. The reason for this is that the probability of a conﬁgura-

β (cid:80)
i∼j

xixj

β (cid:80)
i∼j

xixj

. As β is increased, e

for conﬁgurations with a large
tion is proportional to e
number of edges whose vertices have identical spins increases more than for conﬁgurations
whose edges have vertices with non identical spins. When the normalization constant 1
Z
is adjusted for the new value of β, the highest probability conﬁgurations are those where
adjacent vertices have identical spins.

Given the above probability distribution, what is the correlation between two variables
xi and xj. To answer this question, consider the probability that xi equals plus one as a
function of the probability that xj equals plus one. If the probability that xi equals plus
one is 1
2 independent of the value of the probability that xj equals plus one, we say the

325

values are uncorrelated.

2 ln d+1

Consider the special case where the graph G is a tree. In this case a phase transition
occurs at β0 = 1
d−1 where d is the degree of the tree. For a suﬃciently tall tree and for
β > β0, the probability that the root has value +1 is bounded away from 1/2 and depends
on whether the majority of leaves have value +1 or -1. For β < β0 the probability that
the root has value +1 is 1/2 independent of the values at the leaves of the tree.

Consider a height one tree of degree d. If i of the leaves have spin +1 and d − i have

spin -1, then the probability of the root having spin +1 is proportional to

eiβ−(d−i)β = e(2i−d)β.

If the probability of a leaf being +1 is p, then the probability of i leaves being +1 and
d − i being -1 is

(cid:19)

(cid:18)d
i

pi (1 − p)d−i

Thus, the probability of the root being +1 is proportional to

A =

d
(cid:88)

i=1

(cid:18)d
i

(cid:19)

pi(1 − p)d−ie(2i−d)β = e−dβ

d
(cid:88)

i=1

(cid:19)

(cid:18)d
i

(cid:0)pe2β(cid:1)i

(1 − p)d−i = e−dβ (cid:2)pe2β + 1 − p(cid:3)d

and the probability of the root being –1 is proportional to

B =

d
(cid:88)

i=1

(cid:18)d
i

(cid:19)

pi(1 − p)d−ie−(2i−d)β

d
(cid:88)

= e−dβ

(cid:19)

(cid:18)d
i

pi (cid:2)(1 − p)e−2(i−d)β(cid:3)

i=1
d
(cid:88)

(cid:19)

= e−dβ

(cid:18)d
i
= e−dβ (cid:2)p + (1 − p)e2β(cid:3)d

i=1

.

pi (cid:2)(1 − p)e2β(cid:3)d−i

The probability of the root being +1 is

q = A

A+B =

[pe2β +1−p]d

[pe2β +1−p]d

+[p+(1−p)e2β]d = C

D

where

and

C = (cid:2)pe2β + 1 − p(cid:3)d

D = (cid:2)pe2β + 1 − p(cid:3)d + (cid:2)p + (1 − p) e2β(cid:3)d.

326

At high temperature, low β, the probability q of the root of the height one tree being

+1 in the limit as β goes to zero is

q =

p + 1 − p
[p + 1 − p] + [p + 1 − p]

=

1
2

independent of p. At low temperature, high β,

q ≈

pde2βd
pde2βd + (1 − p)de2βd =

pd
pd + (1 − p)d =

(cid:26) 0 p = 0
1 p = 1

.

q goes from a low probability of +1 for p below 1/2 to high probability of +1 for p above
1/2.

Now consider a very tall tree. If the p is the probability that a root has value +1,
we can iterate the formula for the height one tree and observe that at low temperature
the probability of the root being one converges to some value. At high temperature, the
probability of the root being one is 1/2 independent of p. See Figure 9.10. At the phase
transition, the slope of q at p=1/2 is one.

Now the slope of the probability of the root being 1 with respect to the probability of

a leaf being 1 in this height one tree is

∂q
∂p

=

D ∂C

∂p − C ∂D
D2

∂p

Since the slope of the function q(p) at p=1/2 when the phase transition occurs is one, we
can solve ∂q
∂p = 1 for the value of β where the phase transition occurs. First, we show that
∂D
= 0.
∂p

(cid:12)
(cid:12)
(cid:12)p=

1
2

∂D
∂p

Then

∂q
∂p

(cid:12)
(cid:12)
(cid:12)
(cid:12)p=

1
2

D = (cid:2)pe2β + 1 − p(cid:3)d
∂p = d (cid:2)pe2β + 1 − p(cid:3)d−1 (cid:0)e2β − 1(cid:1) + d (cid:2)p + (1 − p) e2β(cid:3)d−1 (cid:0)1 − e2β(cid:1)

+ (cid:2)p + (1 − p) e2β(cid:3)d

∂D

(cid:12)
(cid:12)
(cid:12)p=

= d
2d−1

(cid:2)e2β + 1(cid:3)d−1 (cid:0)e2β − 1(cid:1) + d
2d−1

(cid:2)1 + e2β(cid:3)d−1 (cid:0)1 − e2β(cid:1) = 0

1
2

=

=

D ∂C

∂p − C ∂D
D2

∂p

2e2β + 1

d (cid:2) 1
(cid:2) 1
2e2β + 1

2

2

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)p=

1
2

=

∂C
∂p
D

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)p=
(cid:3)d−1 (cid:0)e2β − 1(cid:1)
2 + 1

2e2β(cid:3)d =

(cid:3)d + (cid:2) 1

d (cid:2)pe2β + 1 − p(cid:3)d−1 (cid:0)e2β − 1(cid:1)
[pe2β + 1 − p]d + [p + (1 − p) e2β]d

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)p=

1
2

=

1
2

d (cid:0)e2β − 1(cid:1)
1 + e2β

327

1

high
temperature

Probability q(p) of
the root being 1
as a function of p

1/2

at phase transition
slope of q(p) equals 1
at p = 1/2

low
temperature

1/2

1

0

0

Probability p of a leaf being 1

Figure 9.10: Shape of q as a function of p for the height one tree and three values of β cor-
responding to low temperature, the phase transition temperature, and high temperature.
.

Setting

And solving for β yields

d (cid:0)e2β − 1(cid:1)
1 + e2β = 1

d (cid:0)e2β − 1(cid:1) = 1 + e2β

e2β = d+1
d−1

β = 1

2 ln d+1

d−1

To complete the argument, we need to show that q is a monotonic function of p. To see
this, write q = 1
. A is a monotonically increasing function of p and B is monotonically
1+

B
A

decreasing. From this it follows that q is monotonically increasing.

In the iteration going from p to q, we do not get the true marginal probabilities at
each level since we ignored the eﬀect of the portion of the tree above. However, when we
get to the root, we do get the true marginal for the root. To get the true marginal’s for
the interior nodes we need to send messages down from the root.

Note: The joint probability distribution for the tree is of the form e

β (cid:80)
(ij)∈E)

xixj

= (cid:81)

eβxixj .

(i,j)∈E

Suppose x1 has value 1 with probability p. Then deﬁne a function ϕ, called evidence, such
that

ϕ (x1) =

(cid:26) p

for x1 = 1
1 − p for x1 = −1

= (cid:0)p − 1

2

(cid:1) x1 + 1

2

328

and multiply the joint probability function by ϕ. Note, however, that the marginal prob-
ability of x1 is not p. In fact, it may be further from p after multiplying the conditional
probability function by the function ϕ.

329

9.14 Exercises

Exercise 9.1 Find a nonnegative factorization of the matrix









A =









5
6
4
3
1
2
7
7 10
6
4
8
6 10 11

Indicate the steps in your method and show the intermediate results.

Exercise 9.2 Find a nonnegative factorization of each of the following matrices.

(1)

(3)













3

10 9 15 14 13
1
2
1
3
7 13 11 11
8
7
5 11 10
7
11
6
5 11
5
3
3
1
1
1
2
2
2
2

























1

3

4

4

3

3

4
3
13 16 13 10 5 13 14 10
15 24 21 12 9 21 18 12
6
7
1
1
4
5
3
3

7 15 10
2
4
2
6
7
3
6
6 12

16 15
4
4
7
8
12 12

6
1
4
3

























(2)

5 5 10 14 17
6
4
2 2
4
2
1 1
3
2
1 1
3 3
10
6
5 5 10 16 18
7
4
2 2

4
4
2
8

6



















(4)



3
9

4
9

1
4
1 1
3
9 9
12


6 6 12 16 15 15 4

1
4
3 3

4
9

3

3

3

Exercise 9.3 Consider the matrix A that is the product of nonnegative matrices B and
C.







12 22 41 35
19 20 13 48
11 14 16 29
14 16 14 36







=









10 1
9
1
4
3
6
2

(cid:18)1 2 4 3
2 2 1 5

(cid:19)





Which rows of A are approximate positive linear combinations of other rows of A?
Find an approxiamte nonnegative factorization of A

Exercise 9.4 What is the probability of heads occurring after a suﬃciently long sequence
of transitions in Viterbi algorithm example of the most likely sequence of states?

Exercise 9.5 Find optimum parameters for a three state HMM and given output se-
quence. Note the HMM must a strong signature in the output sequence or we probably will
not be able to ﬁnd it. The following example may not be good for that reason.

330

1
1
2

1
4

1
3

2
1
4

1
4

1
3

3
1
4

1
2

1
3

1

2

3

A B
1
3
4
4

1
4

1
3

3
4

2
3

1

2

3

Exercise 9.6 In the Ising model for a tree of degree one, a chain of vertices, is there a
phase transition where the correlation between the value at the root and the value at the
leaves becomes independent? Work out mathematical what happens.

Exercise 9.7 For a Boolean function in CNF the marginal probability gives the number
of satisﬁable assignments with x1.

How does one obtain the number of satisfying assignments for a 2-CNF formula? Not

completely related to ﬁrst sentence.

331

10 Other Topics

10.1 Rankings

Ranking is important. We rank movies, restaurants, students, web pages, and many
other items. Ranking has become a multi-billion dollar industry as organizations try to
raise the position of their web pages in the display of web pages returned by search en-
gines to relevant queries. Developing a method of ranking that is not manipulative is an
important task.

A ranking is a complete ordering in the sense that for every pair of items a and b,
either a is preferred to b or b is preferred to a. Furthermore, a ranking is transitive in
that a > b and b > c implies a > c.

One problem of interest in ranking is that of combining many individual rankings into
one global ranking. However, merging ranked lists is nontrivial as the following example
illustrates.

Example: Suppose there are three individuals who rank items a, b, and c as illustrated
in the following table.

individual ﬁrst item second item third item

1
2
3

a
b
c

b
c
a

c
a
b

Suppose our algorithm tried to rank the items by ﬁrst comparing a to b and then
comparing b to c. In comparing a to b, two of the three individuals prefer a to b and thus
we conclude a is preferable to b. In comparing b to c, again two of the three individuals
prefer b to c and we conclude that b is preferable to c. Now by transitivity one would
expect that the individuals would prefer a to c, but such is not the case, only one of the
individuals prefers a to c and thus c is preferable to a. We come to the illogical conclusion
that a is preferable to b, b is preferable to c, and c is preferable to a.

Suppose there are a number of individuals or voters and a set of candidates to be
ranked. Each voter produces a ranked list of the candidates. From the set of ranked lists
can one construct a single ranking of the candidates? Assume the method of producing a
global ranking is required to satisfy the following three axioms.

Nondictatorship – The algorithm cannot always simply select one individual’s ranking.

Unanimity – If every individual prefers a to b, then the global ranking must prefer a to

b.

332

Independent of irrelevant alternatives – If individuals modify their rankings but
keep the order of a and b unchanged, then the global order of a and b should
not change.

Arrow showed that no ranking algorithm exists satisfying the above axioms.

Theorem 10.1 (Arrow) Any algorithm for creating a global ranking from individual
rankings of three or more elements in which the global ranking satisﬁes unanimity and
independence of irrelevant alternatives is a dictatorship.

Proof: Let a, b, and c be distinct items. Consider a set of rankings in which each indi-
vidual ranks b either ﬁrst or last. Some individuals may rank b ﬁrst and others may rank
b last. For this set of rankings, the global ranking must put b ﬁrst or last. Suppose to the
contrary that b is not ﬁrst or last in the global ranking. Then there exist a and c where the
global ranking puts a > b and b > c. By transitivity, the global ranking puts a > c. Note
that all individuals can move c above a without aﬀecting the order of b and a or the order
of b and c since b was ﬁrst or last on each list. Thus, by independence of irrelevant alter-
natives, the global ranking would continue to rank a > b and b > c even if all individuals
moved c above a since that would not change the individuals relative order of a and b or
the individuals relative order of b and c. But then by unanimity, the global ranking would
need to put c > a, a contradiction. We conclude that the global ranking puts b ﬁrst or last.

Consider a set of rankings in which every individual ranks b last. By unanimity, the
global ranking must also rank b last. Let the individuals, one by one, move b from bot-
tom to top leaving the other rankings in place. By unanimity, the global ranking must
eventually move b from the bottom all the way to the top. When b ﬁrst moves, it must
move all the way to the top by the previous argument. Let v be the ﬁrst individual whose
change causes the global ranking of b to change.

We now argue that v is a dictator. First, we argue that v is a dictator for any pair ac
not involving b. We will refer to three rankings of v (see Figure 10.1). The ﬁrst ranking
of v is the ranking prior to v moving b from the bottom to the top and the second is the
ranking just after v has moved b to the top. Choose any pair ac where a is above c in v’s
ranking. The third ranking of v is obtained by moving a above b in the second ranking
so that a > b > c in v’s ranking. By independence of irrelevant alternatives, the global
ranking after v has switched to the third ranking puts a > b since all individual ab votes
are the same as just before v moved b to the top of his ranking. At that time the global
ranking placed a > b. Similarly b > c in the global ranking since all individual bc votes
are the same as just after v moved b to the top causing b to move to the top in the global
ranking. By transitivity the global ranking must put a > c and thus the global ranking
of a and c agrees with v.

Now all individuals except v can modify their rankings arbitrarily while leaving b in its
extreme position and by independence of irrelevant alternatives, this does not aﬀect the

333

b

b

...
a
...
c
...
b
v

...
a
...
...
...
b
global

b

b

b

b

b
...
a
...
c
...
v

b

b

b
...
...
...
c
...
global

b

b a
b
...
c
...
...
v

b

b

a
b
...
c
...
...
global

ﬁrst ranking

second ranking

third ranking

Figure 10.1: The three rankings that are used in the proof of Theorem 10.1.

global ranking of a > b or of b > c. Thus, by transitivity this does not aﬀect the global
ranking of a and c. Next, all individuals except v can move b to any position without
aﬀecting the global ranking of a and c.

At this point we have argued that independent of other individuals’ rankings, the
global ranking of a and c will agree with v’s ranking. Now v can change its ranking
arbitrarily, provided it maintains the order of a and c, and by independence of irrelevant
alternatives the global ranking of a and c will not change and hence will agree with v.
Thus, we conclude that for all a and c, the global ranking agrees with v independent of
the other rankings except for the placement of b. But other rankings can move b without
changing the global order of other elements. Thus, v is a dictator for the ranking of any
pair of elements not involving b.

Note that v changed the relative order of a and b in the global ranking when it moved

b from the bottom to the top in the previous argument. We will use this in a moment.

The individual v is also a dictator over every pair ab. Repeat the construction showing
that v is a dictator for every pair ac not involving b only this time place c at the bottom.
There must be an individual vc who is a dictator for any pair such as ab not involving c.
Since both v and vc can aﬀect the global ranking of a and b independent of each other, it
must be that vc is actually v. Thus, the global ranking agrees with v no matter how the
other voters modify their rankings.

10.2 Hare System for Voting

One voting system would be to have everyone vote for their favorite candidate. If some
candidate receives a majority of votes, he or she is declared the winner. If no candidate
receives a majority of votes, the candidate with the fewest votes is dropped from the slate
and the process is repeated.

334

The Hare system implements this method by asking each voter to rank all the can-
didates. Then one counts how many voters ranked each candidate as number one. If no
candidate receives a majority, the candidate with the fewest number one votes is dropped
from each voters ranking. If the dropped candidate was number one on some voters list,
then the number two candidate becomes that voter’s number one choice. The process of
counting the number one rankings is then repeated.

Although the Hare system is widely used it fails to satisfy Arrow’ axioms as all voting
systems must. Consider the following situation in which there are 21 voters that fall into
four categories. Voters within a category rank individuals in the same order.

Category

Number of voters
in category

Preference order

1
2
3
4

7
6
5
3

abcd
bacd
cbad
dcba

The Hare system would ﬁrst eliminate d since d gets only three rank one votes. Then
it would eliminate b since b gets only six rank one votes whereas a gets seven and c gets
eight. At this point a is declared the winner since a has thirteen votes to c’s eight votes.

Now assume that Category 4 voters who prefer b to a move a up to ﬁrst place. Then
the election proceeds as follows. In round one, d is eliminated since it gets no rank one
votes. Then c with ﬁve votes is eliminated and b is declared the winner with 11 votes.
Note that by moving a up, category 4 voters were able to deny a the election and get b
to win, whom they prefer over a.

10.3 Compressed Sensing and Sparse Vectors

Given a function x(t), one can represent the function by the composition of sinusoidal
functions. Basically one is representing the time function by its frequency components.
The transformation from the time representation of a function to it frequency represen-
tation is accomplished by a Fourier transform. The Fourier transform of a function x(t)
is given by

(cid:90)

f (ω) =

x(t)e−2πωtdt

Converting the frequency representation back to the time representation is done by the
inverse Fourier transformation

(cid:90)

x(t) =

f (ω)e−2πωtdω

335

In the discrete case, x = [x0, x1, . . . , xn−1] and f = [f0, f1, . . . , fn−1]. The Fourier trans-
form and its inverse are f = Ax with aij = ωij where ω is the principle nth root of unity.

There are many other transforms such as the Laplace, wavelets, chirplets, etc. In fact,

any nonsingular n × n matrix can be used as a transform.

If one has a discrete time sequence x of length n, the Nyquist theorem states that n
coeﬃcients in the frequency domain are needed to represent the signal x. However, if the
signal x has only s nonzero elements, even though one does not know which elements they
are, one can recover the signal by randomly selecting a small subset of the coeﬃcients in
the frequency domain. It turns out that one can reconstruct sparse signals with far fewer
samples than one might suspect and an area called compressed sampling has emerged
with important applications.

Motivation

Let A be an n × d matrix with n much smaller than d whose elements are generated
by independent Gaussian processes. Let x be a sparse d-dimensional vector with at most
s nonzero coordinates, s << d. x is called the signal and A is the “measurement” matrix.
What we measure are the components of the n dimensional vector Ax. We ask if we
can recover the signal x from measurements Ax, where the number n of measurements
is much smaller than the dimension d? We have two advantages over an arbitrary system
of linear equations. First, the solution x is known to be sparse and second we have the
choice of the measurement matrix A.

In many applications, the signal is sparse in either the time domain or the frequency
domain. For images, it is often the case that in the frequency domain very few frequencies
have signiﬁcant amplitude. If we zero out small frequency amplitudes, we get a sparse
frequency representation of the signal. It is wasteful to measure each of the d components
of the signal x, most of which are zero. Instead, we measure n linear combinations of
components, the linear combinations form A. In applications, we choose the matrix A. A
usual choice is a matrix whose entries are independent zero mean, unit variance Gaussian
random variables. Since we have no control over the signal, our system needs to recover
any signal. We will show that n needs to depend essentially only on s, not on d.

10.3.1 Unique Reconstruction of a Sparse Vector

A vector is said to be s-sparse if it has at most s nonzero elements. Let x be a d-
dimensional, s-sparse vector with s << d. Consider solving Ax = b for x where A is an
n × d matrix with n < d. The set of solutions to Ax = b is a subspace. However, if we
restrict ourselves to sparse solutions, under certain conditions on A there is a unique s-
sparse solution. Suppose that there were two s-sparse solutions, x1 and x2. Then x1 − x2

336

d

A

n

=

b

x

Figure 10.2: Ax = b has a vector space of solutions but possibly only one sparse solution.

would be a 2s-sparse solution to the homogeneous system Ax = 0. A 2s-sparse solution to
the homogeneous equation Ax = 0 requires that some 2s columns of A be linearly depen-
dent. Unless A has 2s linearly dependent columns there can be only one s-sparse solution.

Now suppose n is Ω(s2) and we pick an n × d matrix A with random independent
zero mean, unit variance Gaussian entries. Take any subset of 2s columns of A. Since
we have already seen in Chapter 2 that each of these 2s vectors is likely to be essentially
orthogonal to the space spanned by the previous vectors, the sub-matrix is unlikely to be
singular. This intuition can be made rigorous.

To ﬁnd a sparse solution to Ax = b, one would like to minimize the zero norm (cid:107)x(cid:107)0
over {x|Ax = b} . This is a computationally hard problem. There are techniques to min-
imize a convex function over a convex set. But ||x||0 is not a convex function. With no
further hypotheses, it is NP-hard. With this in mind, we use the one norm as a proxy for
the zero norm and minimize the one norm (cid:107)x(cid:107)1 over {x|Ax = b}. Although this problem
appears to be nonlinear, it can be solved by linear programming by writing x = u − v,
u ≥ 0, and v ≥ 0, and then minimizing the linear function (cid:80)
vi subject to Au-

ui + (cid:80)

Av=b, u ≥ 0, and v ≥ 0.

i

i

Under what conditions will minimizing (cid:107)x(cid:107)1 over {x|Ax = b} recover the s-sparse
solution to Ax=b? If g(x) is a convex function, then any local minimum of g is a global
minimum. If g(x) is diﬀerentiable at its minimum, the gradient ∇g must be zero there.
However, the 1-norm is not diﬀerentiable at its minimum. Thus, we introduce the concept
of a subgradient of a convex function. Where the function is diﬀerentiable the subgradient
is just the gradient. Where the function is not diﬀerentiable, the sub gradient is any line
touching the function at the point that lies totally below the function. See Figure 10.3.

Subgradients are deﬁned as follows. A subgradient of a function g at a point x0, is a

337

Figure 10.3: Some subgradients for a function that is not everywhere diﬀerentiable.

vector ∇g(x0) satisfying g (x0 + ∆x) ≥ g (x0) + (∇g)T ∆x for any vector ∆x . A point is
a minimum for a convex function if there is a subgradient at that point with slope zero.

Consider the function (cid:107)x(cid:107)1, where x is a real variable. For x < 0, the subgradient
equals the gradient and has value -1. For x > 0, the subgradient equals the gradient and
has value 1. At x = 0, the subgradient can be any value in the range [-1,1]. The following
proposition generalizes this example to the 1-norm function in d-space.

Proposition 10.2 A vector v is a subgradient of the 1-norm function ||x||1 at x if and
only if it satisﬁes the three conditions below:

1. vi = −1 for all i in I1 where, I1 = {i|xi < 0},

2. vi = 1 for all i in I2 where, I2 = {i|xi > 0},

3. and vi in [−1, 1] for all i in I3 where, I3 = {i|xi = 0}.

Proof: It is easy to see that for any vector y,
(cid:88)

||x + y||1 − ||x||1 ≥ −

i∈I1

yi +

yi +

(cid:88)

i∈I2

|yi|.

(cid:88)

i∈I3

If yi is also negative,

If i is in I1, xi is negative.
then ||xi + yi||1 = ||xi||1 + ||yi||1
and thus ||xi + yi||1 − ||xi||1 = ||yi||1 = −yi. If yi is positive and less than ||xi||1, then
||xi +yi||1 = ||xi||−yi and thus ||xi +yi||1 −||xi|| = −yi. If yi is positive and greater than or
equal to ||xi||1, then ||xi+yi||1 = yi−||xi||1 and thus ||xi+yi||1−||xi||1 = yi−2||xi||1 ≥ −yi.
Similar reasoning establishes the case for i in I2 or I3.

If v satisﬁes the conditions in the proposition, then ||x+y||1 ≥ ||x||1+vT y as required.
Now for the converse, suppose that v is a subgradient. Consider a vector y that is zero
in all components except the ﬁrst and y1 is nonzero with y1 = ±ε for a small ε > 0. If
1 ∈ I1, then ||x + y||1 − ||x||1 = −y1 which implies that −y1 ≥ v1y1. Choosing y1 = ε,
gives −1 ≥ v1 and choosing y1 = −ε, gives −1 ≤ v1. So v1 = −1. Similar reasoning gives
the second condition. For the third condition, choose i in I3 and set yi = ±ε and argue
similarly.

338

A sub gradient

Figure 10.4: Illustration of a subgradient for |x|1 at x = 0

To characterize the value of x that minimizes (cid:107)x(cid:107)1 subject to Ax=b, note that at the
minimum x0, there can be no downhill direction consistent with the constraint Ax=b.
Thus, if the direction ∆x at x0 is consistent with the constraint Ax=b, that is A∆x=0
so that A (x0 + ∆x) = b, any subgradient ∇ for (cid:107)x(cid:107)1 at x0 must satisfy ∇T ∆x = 0.

A suﬃcient but not necessary condition for x0 to be a minimum is that there exists
some w such that the sub gradient at x0 is given by ∇ = AT w. Then for any ∆x such
that A∆x = 0, ∇T ∆x = wT A∆x = wT · 0 = 0. That is, for any direction consistent with
the constraint Ax = b, the subgradient is zero and hence x0 is a minimum.

10.3.2 The Exact Reconstruction Property

Theorem 10.3 below gives a condition that guarantees that a solution x0 to Ax = b is
the unique minimum 1-norm solution to Ax = b. This is a suﬃcient condition, but not
necessary condition.

Theorem 10.3 Suppose x0 satisﬁes Ax0 = b. If there is a subgradient ∇ to the 1-norm
function at x0 for which there exists a w where ∇ = AT w and the columns of A corre-
sponding to nonzero components of x0 are linearly independent, then x0 minimizes (cid:107)x(cid:107)1
subject to Ax=b. Furthermore, these conditions imply that x0 is the unique minimum.

Proof: We ﬁrst show that x0 minimizes (cid:107)x(cid:107)1. Suppose y is another solution to Ax = b.
We need to show that ||y||1 ≥ ||x0||1. Let z = y − x0. Then Az = Ay − Ax0 = 0. Hence,
∇T z = (AT w)T z = wT Az = 0. Now, since ∇ is a subgradient of the 1-norm function at
x0,

||y||1 = ||x0 + z||1 ≥ ||x0||1 + ∇T · z = ||x0||1

and so we have that ||x0||1 minimizes ||x||1 over all solutions to Ax = b.

Suppose ˜x0 were another minimum. Then ∇ is also a subgradient at ˜x0 as it is at x0.

To see this, for ∆x such that A∆x = 0,

(cid:107)˜x0 + ∆x(cid:107)1 =

x0 + ˜x0 − x0 + ∆x
(cid:125)

(cid:124)

(cid:123)(cid:122)
α

≥ (cid:107)x0(cid:107)1 + ∇T (˜x0 − x0 + ∆x) .

(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)

(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)1

339

The above equation follows from the deﬁnition of ∇ being a subgradient for the one norm
function, (cid:107)(cid:107)1, at x0. Thus,

(cid:107)˜x0 + ∆x(cid:107)1 ≥ (cid:107)x0(cid:107)1 + ∇T (˜x0 − x0) + ∇T ∆x.

But

∇T (˜x0 − x0) = wT A (˜x0 − x0) = wT (b − b) = 0.

Hence, since ˜x0 being a minimum means || ˜x0||1 = ||x0||1,

(cid:107)˜x0 + ∆x(cid:107)1 ≥ (cid:107)x0(cid:107)1 + ∇T ∆x = || ˜x0||1 + ∇T ∆x.

This implies that ∇ is a sub gradient at ˜x0.

Now, ∇ is a subgradient at both x0 and ˜x0. By Proposition 10.2, we must have that
(∇)i = sgn((x0)i) = sgn((˜x0)i), whenever either is nonzero and |(∇)i| < 1, whenever either
is 0. It follows that x0 and ˜x0 have the same sparseness pattern. Since Ax0 = b and
A˜x0 = b and x0 and ˜x0 are both nonzero on the same coordinates, and by the assumption
that the columns of A corresponding to the nonzeros of x0 and ˜x0 are independent, it
must be that x0 = ˜x0.

10.3.3 Restricted Isometry Property

Next we introduce the restricted isometry property that plays a key role in exact
reconstruction of sparse vectors. A matrix A satisﬁes the restricted isometry property,
RIP, if for any s-sparse x there exists a δs such that

(1 − δs) |x|2 ≤ |Ax|2 ≤ (1 + δs) |x|2 .

(10.1)

Isometry is a mathematical concept; it refers to linear transformations that exactly pre-
serve length such as rotations. If A is an n × n isometry, all its eigenvalues are ±1 and
it represents a coordinate system. Since a pair of orthogonal vectors are orthogonal in all
coordinate system, for an isometry A and two orthogonal vectors x and y, xT AT Ay = 0.
We will prove approximate versions of these properties for matrices A satisfying the re-
stricted isometry property. The approximate versions will be used in the sequel.

A piece of notation will be useful. For a subset S of columns of A, let AS denote the

submatrix of A consisting of the columns of S.

Lemma 10.4 If A satisﬁes the restricted isometry property, then

1. For any subset S of columns with |S| = s, the singular values of AS are all between

1 − δs and 1 + δs.

2. For any two orthogonal vectors x and y, with supports of size s1 and s2 respectively,

|xT AT Ay| ≤ 5|x||y|(δs1 + δs2).

340

Proof: Item 1 follows from the deﬁnition. To prove the second item, assume without loss
of generality that |x| = |y| = 1. Since x and y are orthogonal, |x + y|2 = 2. Consider
|A(x+y)|2. This is between 2(1−δs1 +δs2)2 and 2(1+δs1 +δs2)2 by the restricted isometry
property. Also |Ax|2 is between (1 − δs1)2 and (1 + δs1)2 and |Ay|2 is between (1 − δs2)2
and (1 + δs2)2. Since

2xT AT Ay = (x + y)T AT A(x + y) − xT AT Ax − yT AT Ay

= |A(x + y)|2 − |Ax|2 − |Ay|2,

it follows that

|2xT AT Ay| ≤ 2(1 + δs1 + δs2)2 − (1 − δs1)2 − (1 − δs2)2

6(δs1 + δs2) + (δ2

s1 + δ2

s2 + 4δs1 + 4δs2) ≤ 9(δs1 + δs2).

Thus, for arbitrary x and y |xT AT Ay| ≤ (9/2)|x||y|(δs1 + δs2).

Theorem 10.5 Suppose A satisﬁes the restricted isometry property with

δs+1 ≤

1
√
10

s

.

Suppose x0 has at most s nonzero coordinates and satisﬁes Ax = b. Then a subgradient
∇||(x0)||1 for the 1-norm function exists at x0 which satisﬁes the conditions of Theorem
10.3 and so x0 is the unique minimum 1-norm solution to Ax = b.

Proof: Let

S = {i|(x0)i (cid:54)= 0}
be the support of x0 and let ¯S = {i|(x0)i = 0} be the complement set of coordinates. To
ﬁnd a subgradient u at x0 satisfying Theorem 10.3, search for a w such that u = AT w
where for coordinates in which x0 (cid:54)= 0, u = sgn (x0) and for the remaining coordinates
the 2-norm of u is minimized. Solving for w is a least squares problem. Let z be the
vector with support S, with zi = sgn(x0) on S. Consider the vector w deﬁned by

w = AS

(cid:0)AT

S AS

(cid:1)−1

z.

This happens to be the solution of the least squares problem, but we do not need this
fact. We only state it to tell the reader how we came up with this expression. Note that
AS has independent columns from the restricted isometry property assumption, and so
AT
S AS is invertible. We will prove that this w satisﬁes the conditions of Theorem 10.3.
First, for coordinates in S,

(AT w)S = (AS)T AS(AT

S AS)−1z = z

as required.

341

For coordinates in ¯S, we have

(AT w) ¯S = (A ¯S)T AS(AT

S AS)−1z.

Now, the eigenvalues of AT
between (1 − δs)2 and (1 + δs)2. So ||(AT
have |p| ≤
for j ∈ ¯S

S AS, which are the squares of the singular values of AS, are
S AS)−1|| ≤ 1
S AS)−1z, we
(1−δS )2 . Write Asp as Aq, where q has all coordinates in ¯S equal to zero. Now,

(1−δS )2 . Letting p = (AT

√

s

j AT Aq
√
and part (2) of Lemma 10.4 gives |(AT w)j| ≤ 9δs+1
Theorem 10.3 holds.

(AT w)j = eT

s/(1 − δ2

s ) ≤ 1/2 establishing the

A Gaussian matrix is a matrix where each element is an independent Gaussian variable.

Gaussian matrices satisfy the restricted isometry property. (Exercise ??)

10.4 Applications

10.4.1 Sparse Vector in Some Coordinate Basis

Consider Ax = b where A is a square n×n matrix. The vectors x and b can be consid-
ered as two representations of the same quantity. For example, x might be a discrete time
sequence with b the frequency spectrum of x and the matrix A the Fourier transform. The
quantity x can be represented in the time domain by x and in the frequency domain by its
Fourier transform b. In fact, any orthonormal matrix can be thought of as a transforma-
tion and there are many important transformations other than the Fourier transformation.

Consider a transformation A and a signal x in some standard representation. Then
y = Ax transforms the signal x to another representation y. If A spreads any sparse
signal x out so that the information contained in each coordinate in the standard basis is
spread out to all coordinates in the second basis, then the two representations are said to
be incoherent. A signal and its Fourier transform are one example of incoherent vectors.
This suggests that if x is sparse, only a few randomly selected coordinates of its Fourier
transform are needed to reconstruct x. In the next section we show that a signal cannot
be too sparse in both its time domain and its frequency domain.

10.4.2 A Representation Cannot be Sparse in Both Time and Frequency

Domains

We now show that there is an uncertainty principle that states that a time signal
cannot be sparse in both the time domain and the frequency domain. If the signal is of
length n, then the product of the number of nonzero coordinates in the time domain and
the number of nonzero coordinates in the frequency domain must be at least n. We ﬁrst
prove two technical lemmas.

342

In dealing with the Fourier transform it is convenient for indices to run from 0 to n − 1
rather than from 1 to n. Let x0, x1, . . . , xn−1 be a sequence and let f0, f1, . . . , fn−1 be its

discrete Fourier transform. Let i =

In matrix form f = Zx where zjk = e−

2πi

n jk.

√

−1. Then fj = 1√
n

xke−

2πi

n jk,

n−1
(cid:80)
k=0

j = 0, . . . , n − 1.








f0
f1
...
fn−1








=

1
√
n









1

1
...
1 e−

1
2πi
e−
n
...

1
2πi
n 2

e−

2πi

n (n − 1) e−

2πi
n 2 (n − 1)

· · ·

· · ·
...
· · ·

1

2πi
n (n − 1)

e−

2πi

n (n − 1)2

e−























x0
x1
...
xn−1

If some of the elements of x are zero, delete the zero elements of x and the corresponding
columns of the matrix. To maintain a square matrix, let nx be the number of nonzero
elements in x and select nx consecutive rows of the matrix. Normalize the columns of the
resulting submatrix by dividing each element in a column by the column element in the
ﬁrst row. The resulting submatrix is a Vandermonde matrix that looks like







1
a
a2
a3

1
b
b2
b3

1
1
c
d
c2 d2
c3 d3







and is nonsingular.

Lemma 10.6 If x0, x1, . . . , xn−1 has nx nonzero elements, then f0, f1, . . . , fn−1 cannot
have nx consecutive zeros.

Proof: Let i1, i2, . . . , inx be the indices of the nonzero elements of x. Then the elements
of the Fourier transform in the range k = m + 1, m + 2, . . . , m + nx are

fk = 1√
n

−2πi
n kij

xij e

nx(cid:80)

j=1

√

−1 and the multiplication of the exponent by ij to account for the
Note the use of i as
actual location of the element in the sequence. Normally, if every element in the sequence
was included, we would just multiply by the index of summation.

Convert the equation to matrix form by deﬁning zkj = 1√

n kij) and write
f = Zx. Actually instead of x, write the vector consisting of the nonzero elements of x.
By its deﬁnition, x (cid:54)= 0. To prove the lemma we need to show that f is nonzero. This will
be true provided Z is nonsingular. If we rescale Z by dividing each column by its leading
entry we get the Vandermonde determinant which is nonsingular.

n exp(− 2πi

343

1

1

1

1

z3 z6 1

1
1
1
1 1
z2 z3 z4 z5 z6 z7 z8
1 z
z3 z5 z7
1 z2 z4 z6 z8 z
z3 z6
1 z3 z6 1
z5
1 z4 z8 z3 z7 z2 z6 z
z6 z2 z7 z3 z8 z4
1 z5 z
z6 z3
1 z6 z3 1
1 z7 z5 z3 z
z8 z6 z4 z2
1 z8 z7 z6 z5 z4 z3 z2 z

z6 z3 1

Figure 10.5: The matrix Z for n=9.

Theorem 10.7 Let nx be the number of nonzero elements in x and let nf be the number
of nonzero elements in the Fourier transform of x. Let nx divide n. Then nxnf ≥ n.

Proof: If x has nx nonzero elements, f cannot have a consecutive block of nx zeros. Since
nx divides n there are n
blocks each containing at least one nonzero element. Thus, the
nx
product of nonzero elements in x and f is at least n.

Fourier transform of spikes prove that above bound is tight

To show that the bound in Theorem 10.7 is tight we show that the Fourier transform
n − 1 zeros,
of the sequence of length n consisting of
is the sequence itself. For example, the Fourier transform of the sequence 100100100 is
100100100. Thus, for this class of sequences, nxnf = n.

n ones, each one separated by

√

√

Theorem 10.8 Let S (
apart. The Fourier transform of S (

n,

√

√

n,

n) is itself.

n) be the sequence of 1’s and 0’s with

√

√

√

n 1’s spaced

√

n

√

√

√

√

√

√

Proof : Consider the columns 0,
which S (
k
and the 1/

n,
n, 0 ≤ k <

√
√

√

n, . . . , (
n) has value 1. The element of the matrix Z in the row j
n is znkj = 1. Thus, for these rows Z times the vector S (

n. These are the columns for
n of column
n
n) =
n,

n − 1)

√
√

n, 2

√

√

√

n normalization yields fj

n = 1.
√
For rows whose index is not of the form j
√
n, 2
n−1)b(cid:17)

the elements in row b in the columns 0,
(cid:16)
and thus fb = 1√
n

√
1 + zb + z2b · · · + z(√

n, the row b, b (cid:54)= j
√
√
n, . . . , (
z
= 1√
n

n − 1)
nb−1
z−1 = 0 since zb

√

√

√
√
√
n, j ∈ {0,
n are 1, zb, z2b, . . . , z(√

n, . . . ,

n − 1},
n−1)b

n = 1 and z (cid:54)= 1.

Uniqueness of l1 optimization
Consider a redundant representation for a sequence. One such representation would be
representing a sequence as the concatenation of two sequences, one speciﬁed by its coordi-
nates and the other by its Fourier transform. Suppose some sequence could be represented
as a sequence of coordinates and Fourier coeﬃcients sparsely in two diﬀerent ways. Then

344

by subtraction, the zero sequence could be represented by a sparse sequence. The rep-
If
resentation of the zero sequence cannot be solely coordinates or Fourier coeﬃcients.
y is the coordinate sequence in the representation of the zero sequence, then the Fourier
portion of the representation must represent −y. Thus y and its Fourier transform would
have sparse representations contradicting nxnf ≥ n. Notice that a factor of two comes in
when we subtract the two representations.

Suppose two sparse signals had Fourier transforms that agreed in almost all of their
coordinates. Then the diﬀerence would be a sparse signal with a sparse transform. This is
not possible. Thus, if one selects log n elements of their transform these elements should
distinguish between these two signals.

10.4.3 Biological

There are many areas where linear systems arise in which a sparse solution is unique.
One is in plant breading. Consider a breeder who has a number of apple trees and for
each tree observes the strength of some desirable feature. He wishes to determine which
genes are responsible for the feature so he can cross bread to obtain a tree that better
expresses the desirable feature. This gives rise to a set of equations Ax = b where each
row of the matrix A corresponds to a tree and each column to a position on the genone.
See Figure 10.6. The vector b corresponds to the strength of the desired feature in each
tree. The solution x tells us the position on the genone corresponding to the genes that
account for the feature. It would be surprising if there were two small independent sets
of genes that accounted for the desired feature. Thus, the matrix must have a property
that allows only one sparse solution.

10.4.4 Finding Overlapping Cliques or Communities

Consider a graph that consists of several cliques. Suppose we can observe only low
level information such as edges and we wish to identify the cliques. An instance of this
problem is the task of identifying which of ten players belongs to which of two teams
of ﬁve players each when one can only observe interactions between pairs of individuals.
There is an interaction between two players if and only if they are on the same team.
(cid:1) rows. The columns
In this situation we have a matrix A with (cid:0)10
represent possible teams and the rows represent pairs of individuals. Let b be the (cid:0)10
(cid:1)
dimensional vector of observed interactions. Let x be a solution to Ax = b. There is a
sparse solution x where x is all zeros except for the two 1’s for 12345 and 678910 where
the two teams are {1,2,3,4,5} and {6,7,8,9,10}. The question is can we recover x from
b. If the matrix A had satisﬁed the restricted isometry condition, then we could surely
do this. Although A does not satisfy the restricted isometry condition which guarantees
recover of all sparse vectors, we can recover the sparse vector in the case where the teams
are non overlapping or almost non overlapping.
If A satisﬁed the restricted isometry
property we would minimize (cid:107)x(cid:107)1 subject to Ax = b. Instead, we minimize (cid:107)x(cid:107)1 subject
to (cid:107)Ax − b(cid:107)∞ ≤ ε where we bound the largest error.

(cid:1) columns and (cid:0)10

2

2

5

345

position on genome

trees

=

Phenotype; outward
manifestation, observables

Genotype:
internal code

Figure 10.6: The system of linear equations used to ﬁnd the internal code for some
observable phenomenon.

10.4.5 Low Rank Matrices

Suppose L is a low rank matrix that has been corrupted by noise. That is, M = L+R.
If the R is Gaussian, then principle component analysis will recover L from M . However,
if L has been corrupted by several missing entries or several entries have a large noise
added to them and they become outliers, then principle component analysis may be far
oﬀ. However, if L is low rank and R is sparse, then L can be recovered eﬀectively from
L + R. To do this, ﬁnd the L and R that minimize (cid:107)L(cid:107)∗ + λ (cid:107)R(cid:107)1. Here (cid:107)L(cid:107)∗ is the sum
of the singular values of L. A small value of (cid:107)L(cid:107)∗ indicates a low rank matrix. Notice
that we do not need to know the rank of L or the elements that were corrupted. All we
need is that the low rank matrix L is not sparse and that the sparse matrix R is not low
rank. We leave the proof as an exercise.

An example where low rank matrices that have been corrupted might occur is aerial
photographs of an intersection. Given a long sequence of such photographs, they will be
the same except for cars and people. If each photo is converted to a vector and the vector
used to make a column of a matrix, then the matrix will be low rank corrupted by the
traﬃc. Finding the original low rank matrix will separate the cars and people from the
back ground.

346

10.5 Gradient

(x0), ∂f
∂x2

(x0), . . . ∂f
∂xd

The gradient of a function f (x) of d variables, x = (x1, x2, . . . , xd), at a point x0 is de-
noted (cid:53)f (x0). It is a d-dimensional vector with components ∂f
(x0),
∂x1
where ∂f
are partial derivatives. Without explicitly stating we assume that the deriva-
∂xi
tives referred to exist. The rate of increase of the function f as we move from x0 in
a direction u is easily seen to be (cid:53)f (x0) · u. So the direction of steepest descent is
−(cid:53)f (x0); this is a natural direction to move in if we wish to minimize f . But by how
[See ﬁgure (10.7).]
much should we move? A large move may overshoot the minimum.
A simple ﬁx is to minimize f on the line from x0 in the direction of steepest descent by
solving a one dimensional minimization problem. This gets us the next iterate x1 and
we may repeat. Here, we will not discuss the issue of step-size any further. Instead, we
focus on “inﬁnitesimal” gradient descent, where, the algorithm makes inﬁnitesimal moves
in the −(cid:53)f (x0) direction. Whenever (cid:53)f is not the zero vector, we strictly decrease the
function in the direction −(cid:53)f , so the current point is not a minimum of the function
In
f . Conversely, a point x where (cid:53)f = 0 is called a ﬁrst-order local optimum of f .
general, local minima do not have to be global minima (see (10.7)) and gradient descent
may converge to a local minimum which is not a global minimum. In the special case
when the function f is convex, this is not the case. A function f of a single variable x is
said to be convex if for any two points x and y, the line joining f (x) and f (y) is above the
curve f (·). A function of many variables is convex if on any line segment in its domain,
it acts as a convex function of one variable on the line segment.

Deﬁnition 10.1 A function f over a convex domain is a convex function if for any two
points x, y in the domain, and any λ in [0, 1] we have

f (λx + (1 − λ)y) ≤ λf (x) + (1 − λ)f (y).

The function is concave if the inequality is satisﬁed with ≥ instead of ≤.

Theorem 10.9 Suppose f is a convex, diﬀerentiable, function deﬁned on a closed bounded
convex domain. Then any ﬁrst-order local minimum is also a global minimum. Thus, in-
ﬁnitesimal gradient descent always reaches the global minimum.

Proof: We will prove that if at a point x, is a local minimum, then it must be a global
minimum. If not, consider a global minimum point y (cid:54)= x. But on the line joining x
and y, the function must not go above the line joining f (x) and f (y). This means for an
inﬁnitesimal ε > 0 , if we move distance ε from x towards y, the function must decrease,
so we cannot have (cid:53)f (x) = 0, contradicting the assumption that x is a local minimum.

The second derivatives

∂2
∂xi∂xj

form a matrix, called the Hessian, denoted H(f (x)).

The Hessian of f at x is a symmetric d × d matrix with (i, j) th entry ∂2f
∂xi∂xj

(x). The

347

second derivative of f at x in the direction u is the rate of change of the ﬁrst derivative
as we move along u from x. It is easy to see that it equals

To see this, note that the second derivative of f along u is

uT H(f (x))u.

(cid:88)

uj

∂
∂xj

((cid:53)f (x) · u) =

(cid:88)

uj

(cid:88)

j

i

(cid:19)

∂
∂xj

(cid:18)

ui

∂f
∂xi

j

=

ujui

∂2f
∂xj∂xi

(cid:88)

j,i

(x).

Theorem 10.10 Suppose f is a function from a closed convex domain D in Rd to the
reals and the Hessian of f exists everywhere in D. Then f is convex (concave) on D if
and only if the Hessian of f is positive (negative) semi-deﬁnite everywhere on D.

Gradient descent requires the gradient to exist. But, even if the gradient is not always
deﬁned, one can minimize a convex function over a convex domain eﬃciently, i.e., in
polynomial time. Here, the quote is added because of the lack of rigor in the statement,
one can only ﬁnd an approximate minimum and the time really depends on the error
parameter as well as the presentation of the convex set. We do not go into these details
here. But, in principle we can minimize a convex function over a convex domain. We can
also maximize a concave function over a convex domain. However, in general, we do not
have eﬃcient procedures to maximize a convex function over a convex set. It is easy to
see that at a ﬁrst-order local minimum of a possibly non-convex function, the gradient
vanishes. But second-order local decrease of the function may be possible. The steepest
second-order decrease is in the direction of ±v, where, v is the eigenvector of the Hessian
corresponding to the largest absolute valued eigenvalue.

10.6 Linear Programming

An optimization problem which has been carefully studied and is immensely useful
is linear programming. We consider linear programming problem in the following form
where A is an m × n matrix of rank m , c is 1 × n, b is m × 1 and x is n × 1) :

max c · x

:

Ax = b

;

x ≥ 0.

Inequality constraints can be converted to this form by adding slack variables. Also, we
can do Gaussian elimination on A and if it does not have rank m, we either ﬁnd that
the system of equations has no solution, whence we may stop or we can ﬁnd and discard
redundant equations. After this preprocessing, we may assume that A ’s rows are inde-
pendent.

The simplex algorithm is a classical method to solve linear programming problems. It
is a vast subject and is well discussed in many texts. Here, we will discuss the ellipsoid
algorithm which is in a sense based more on continuous mathematics and is closer to the
spirit of this book.

348

Figure 10.7

349

10.6.1 The Ellipsoid Algorithm

The ﬁrst polynomial time algorithm for Linear Programming was developed by Khachian

based on work of Iudin, Nemirovsky and Shor and is called the ellipsoid algorithm. The
algorithm is best stated for the seemingly simpler problem of determining whether there
is a solution to Ax ≤ b and if so ﬁnding one. The ellipsoid algorithm starts with a large
ball in d-space which is guaranteed to contain the polyhedron Ax ≤ b. Even though we do
not yet know if the polyhedron is empty or non-empty, such a ball can be found. It checks
if the center of the ball is in the polyhedron, if it is, we have achieved our objective. If
not, we know from convex geometry (in particular, the Separating Hyperplane Theorem)
that there is a hyperplane called the separating hyperplane through the center of the ball
such that the whole polytope lies in one half space.

We then ﬁnd an ellipsoid which contains the ball intersected with this half-space See
Figure (10.8. The ellipsoid is guaranteed to contain Ax ≤ b as was the ball earlier. We
now check if the center of the ellipsoid satisﬁes the inequalities. If not, there is a separating
hyper plane again and we may repeat the process. After a suitable number of steps, either
we ﬁnd a solution to the original Ax ≤ b or, we end up with a very small ellipsoid. Now if
the original A and b had integer entries, one can ensure that the set Ax ≤ b, after a slight
perturbation which preserves its emptiness/non-emptiness, has a volume of at least some
(cid:15) > 0 and if our ellipsoid has shrunk to a volume of less than this (cid:15), then we know there
is no solution and we can stop. Clearly this must happen within logρ V0/(cid:15) = O((V0d)/(cid:15)),
where V0 is an upper bound on the initial volume and ρ is the factor by which the volume
shrinks in each step. We do not go into details of how to get a value for V0 here, but the
important points are that (i) V0 only occurs under the logarithm and (ii) the dependence
on d is linear. These features ensure a polynomial time algorithm.

The main diﬃculty in proving fast convergence is to show that the volume of the
ellipsoid shrinks by a certain factor in each step. Thus, the question can be phrased as
suppose E is an ellipsoid with center x0 and consider the half-ellipsoid E(cid:48) deﬁned by

E(cid:48) = {x : x ∈ E ; a · (x − x0) ≥ 0},

where, a is some unit length vector. Let ˆE be the smallest volume ellipsoid containing
E(cid:48). Show that

Vol( ˆE)
Vol(E)

≤ 1 − ρ

for some ρ > 0. A sequence of geometric reductions transforms this into a simple prob-
lem. First, observe that we can translate the entire picture and assume that x0 = 0.
Next, rotate the coordinate axes so that a is replaced by (1, 0, 0, . . . , 0). Finally, make a
nonsingular linear transformation τ so that τ E = B = {x : |x| = 1}, the unit sphere.
The important point is that a nonsingular linear transformation τ multiplies the volumes
of all sets by |det(τ )|, so that Vol( ˆE)
Vol(τ (E)). Now, the following lemma answers the
question raised.

Vol(E) = Vol(τ ( ˆE))

350

Figure 10.8: Ellipsoid Algorithm

Lemma 10.11 Consider the half-sphere B(cid:48) = {x : x1 ≥ 0 ;
ellipsoid ˆE contains B(cid:48):

|x| ≤ 1}. The following

(cid:40)

ˆE =

x

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)

(cid:18) d + 1
d

(cid:19)2 (cid:18)

x1 −

1
d + 1

(cid:19)2

+

(cid:18) d2 − 1
d2

(cid:19) (cid:18)

2 + x2
x2

3 + . . . + x2
d

(cid:19)

(cid:41)

≤ 1

.

Further,

Vol( ˆE)
Vol(B)

=

(cid:18) d

(cid:19) (cid:18) d2

(cid:19)(d−1)/2

d + 1

d2 − 1

≤ 1 −

1
4d

.

Proof: See Exercise (10.3).

10.7 Integer Optimization

The problem of maximizing a linear function subject to linear inequality constraints,

but with the variables constrained to be integers is called integer programming:

Max c · x subject to Ax ≤ b xi integers .

This problem is NP-hard. One way to handle the hardness is to relax the integer con-
straints, solve the linear program in polynomial time and round the fractional values to
integers. The simplest rounding, round each variable which is 1/2 or more to 1, the rest
to 0, yields sensible results in some cases. The vertex cover problem is one of them. The

351

Ellipsoid containing half-sphereSeparating hyperplanepolytopeproblem is to choose a subset of vertices so that each edge is covered, at least one of its
end points is in the subset. The integer program is:

(cid:88)

Min

i

xi subject to xi + xj ≥ 1 ∀ edges (i, j) ; xi integers .

Solve the Linear program. At least one variable for each edge must be at least 1/2 and
the simple rounding rounds it up to 1. So the integer solution we get is still feasible. It
clearly at most doubles the objective function from the Linear Programming solution and
since the LP solution value is at most the optimal integer programming solution value,
we get within a factor of 2 of the optimal.

10.8 Semi-Deﬁnite Programming

Semi-deﬁnite programs are special cases of convex programs. Recall that a n × n
matrix A is positive semi-deﬁnite if and only if (i) A is symmetric and (ii) for all x ∈ Rn,
xT Ax ≥ 0. There are many equivalent characterizations of positive semi-deﬁnite matri-
ces. We mention one. A symmetric matrix A is positive semi-deﬁnite if and only if it can
be expressed as A = BBT for a possibly rectangular matrix B.

An semi-deﬁnite program (SDP) is the problem of minimizing a linear function cT x
subject to a constraint that F = F0 + F1x1 + F2x2 + · · · + Fdxd is positive semi-deﬁnite.
Here F0, F1, . . . , Fd are given symmetric matrices.

This is a convex program since the set of x satisfying the constraint is a convex
set: To see this, just note that if F (x) = F0 + F1x1 + F2x2 + · · · + Fdxd and F (y) =
F0 + F1y1 + F2y2 + · · · + Fdyd are positive semi-deﬁnite, then so is F (αx + (1 − α)y) for
all α ∈ [0, 1]. So SDP’s can be solved in polynomial time in principle. It turns out that
there are more eﬃcient algorithms for SDP’s than general convex programs and also that
many interesting problems can be formulated as SDP’s. We discuss the latter aspect here.

First note that linear programs are special cases of SDP’s. For any vector v, let
diag(v) denote a diagonal matrix with the components of v on the diagonal. Then it is
easy to see that the constraints v ≥ 0 are equivalent to the constraint diag(v) is positive
semi-deﬁnite. Consider now the linear rogram:

Minimize cT x subject to Ax = b; x ≥ 0. Rewrite Ax = b as Ax − b ≥ 0 ; b − Ax ≥ 0

and use the idea of diagonal matrices above to formulate this as an SDP.

A second interesting example is that of quadratic programs of the form:

Minimize

(cT x)2
dT x

subject to Ax + b ≥ 0.

First, this is equivalent to : Minimize t subject to Ax + b ≥ 0 and t ≥
is in turn equivalent to the SDP:

(cT x)2
dT x . Now this

352

Minimize t subject to the following matrix being positive semi-deﬁnite:





diag(Ax + b)
0
0

0
t

0
cT x
cT x dT x



 .

An exciting area of application of SDP is to solve some integer problems. The central
idea is best illustrated by its early application in a breakthrough due to Goemans and
Williamson ([?]) for the maximum cut problem which given a graph G(V, E) asks for the
cut S, ¯S maximizing the number of edges going across the cut from S to ¯S. For each
i ∈ V , let xi be an integer variable assuming values ±1 depending on whether i ∈ S or
i ∈ ¯S respectively. Then the max-cut problem can be posed as

Maximize (cid:80)

(i,j)∈E(1 − xixj) subject to the constraints xi ∈ {−1, +1}.

The integrality constraint on the xi makes the problem NP-hard. Instead replace the
integer constraints by allowing the xi to be unit length vectors. This enlarges the set of
feasible solutions since ±1 are just 1-dimensional vectors of length 1. The relaxed problem
is an SDP and can be solved in polynomial time. To see that it is an SDP, consider xi as
the rows of a matrix X. The variables of our SDP are not X, but actually Y = XX T ,
which is a positive deﬁnite matrix. The SDP is

Maximize (cid:80)

(i,j)∈E(1 − yij) subject to Y positive semi deﬁnte.

This can be solved in polynomial time. From the solution Y , ﬁnd X satisfying Y =
XX T . Now, instead of a ±1 label on each vertex, we have vector labels, namely the rows
of X. We need to round the vectors to ±1 to get an S. One natural way to do this is to
pick a random vector v and if for vertex i, xi · v is positive, put i in S, otherwise put it in
¯S. Goemans and Wiiliamson showed that this method produces a cut guaranteed to be
at least 0.878 times the maximum. The .878 factor is a big improvement on the previous
best factor of 0.5 which is easy to get by putting each vertex into S with probability 1/2.

Exercise 10.1

1. Suppose for a univariate convex function f and a ﬁnite interval D, |f (cid:48)(cid:48)(x)| ≤ δ|f (cid:48)(x)|
for every x. Then, what is a good step size to choose for gradient descent? Derive a
bound on the number of steps needed to get an approximate minimum of f in terms
of as few parameters as possible.

2. Generalize the statement and proof to convex functions of d variables.

Exercise 10.2 Prove that the maximum of a convex function over a polytope is attained
at one of its vertices.

Exercise 10.3 Prove Lemma 10.11.

353

10.9 Exercises

Exercise 10.4 Select a method that you believe is good for combining individual rankings
into a global ranking. Consider a set of rankings where each individual ranks b last. One
by one move b from the bottom to the top leaving the other rankings in place. Does there
exist a vb as in Theorem 10.1 where vb is the ranking that causes b to move from the
bottom to the top in the global ranking. If not, does your method of combing individual
rankings satisfy the axioms of unanimity and independence of irrelevant alternatives.

Exercise 10.5 Show that the three axioms: non dictator, unanimity, and independence
of irrelevant alternatives are independent.

Exercise 10.6 Does the axiom of independence of irrelevant alternatives make sense?
What if there were three rankings of ﬁve items. In the ﬁrst two rankings, A is number one
and B is number two. In the third ranking, B is number one and A is number ﬁve. One
might compute an average score where a low score is good. A gets a score of 1+1+5=7
and B gets a score of 2+2+1=5 and B is ranked number one in the global raking. Now if
the third ranker moves A up to the second position, A’s score becomes 1+1+2=4 and the
global ranking of A and B changes even though no individual ranking of A and B changed.
Is there some alternative axiom to replace independence of irrelevant alternatives? Write
a paragraph on your thoughts on this issue.

Exercise 10.7 Prove that the global ranking agrees with column vb even if b is moved
down through the column.

Exercise 10.8 Create a random 100 by 100 orthonormal matrix A and a sparse 100-
dimensional vector x. Compute Ax = b. Randomly select a few coordinates of b and
reconstruct x from the samples of b using the minimization of 1-norm technique of Section
10.3.1. Did you get x back?

Exercise 10.9 Let A be a low rank n × m matrix. Let r be the rank of A. Let ˜A be A
corrupted by Gaussian noise. Prove that the rank r SVD approximation to ˜A minimizes
(cid:12)
(cid:12)
(cid:12)A − ˜A
(cid:12)
(cid:12)
(cid:12)

.

2

F

Exercise 10.10 Prove that minimizing ||x||0 subject to Ax = b is NP-complete.

Exercise 10.11 Let A be a Gaussian matrix where each element is a random Gauussian
variable with zero mean and variance one. Prove that A has the restricted isometry
property.

Exercise 10.12 Generate 100 × 100 matrices of rank 20, 40, 60 80, and 100. In each
matrix randomly delete 50, 100, 200, or 400 entries.
In each case try to recover the
original matrix. How well do you do?

354

Exercise 10.13 Repeat the previous exercise but instead of deleting elements, corrupt the
elements by adding a reasonable size corruption to the randomly selected matrix entires.

Exercise 10.14 Compute the Fourier transform of the sequence 1000010000.

Exercise 10.15 What is the Fourier transform of a cyclic shift?

Exercise 10.16 Let S(i, j) be the sequence of i blocks each of length j where each block
of symbols is a 1 followed by i − 1 0’s. The number n=6 is factorable but not a perfect
square. What is Fourier transform of S (2, 3)= 100100?

Exercise 10.17 Let Z be the n root of unity. Prove that (cid:8)zbi|0 ≤ i < n(cid:9) = {zi|0 ≤ i < n}
provide that b does not divide n.










1
a
a2
...
ad

1
b
b2
...
bd

· · ·
· · ·
· · ·

· · ·










1
c
c2
...
cd

Show that if the elements in the second row of the Vandermonde matrix are distinct, then
the Vandermonde matrix is nonsingular by using the fact that specifying the value of an
nth degree polynomial at n + 1 points uniquely determines the polynomial.

Exercise 10.18 Many problems can be formulated as ﬁnding x satisfying Ax = b + r
where r is some residual error. Discuss the advantages and disadvantages of each of the
following three versions of the problem.

1. Set r=0 and ﬁnd x= argmin (cid:107)x(cid:107)1 satisfying Ax = b
2. Lasso: ﬁnd x= argmin (cid:0)(cid:107)x(cid:107)1 + α (cid:107)r(cid:107)2
=argmin (cid:107)x(cid:107)1 such that (cid:107)r(cid:107)2 < ε
3. ﬁnd x
¯

2

(cid:1) satisfying Ax = b

Exercise 10.19 Create a graph of overlapping communities as follows. Let n=1,000.
Partition the integers into ten blocks each of size 100. The ﬁrst block is {1, 2, . . . , 100}.
The second is {100, 101, . . . , 200} , and so on. Add edges to the graph so that the vertices
in each block form a clique. Now randomly permute the indices and partition the sequence
into ten blocks of 100 vertices each. Again add edges so that these new blocks are cliques.
Randomly permute the indices a second time and repeat the process of adding edges. The
result is a graph in which each vertex is in three cliques. Explain how to ﬁnd the cliques
given the graph.

Exercise 10.20 Repeat the above exercise but instead of adding edges to form cliques,
use each block to form a G(100,p) graph. For how small a p can you recover the blocks?
What if you add G(1,000,q) to the graph for some small value of q.

355

Exercise 10.21 Construct an n × m matrix A where each of the m columns is a 0-1
indicator vector with approximately 1/4 entries being 1. Then B = AAT is a symmetric
matrix that can be viewed as the adjacency matrix of an n vertex graph. Some edges will
have weight greater than one. The graph consists of a number of possibly over lapping
cliques. Your task given B is to ﬁnd the cliques by the following technique of ﬁnding a
0-1 vector in the column space of B by the following linear program for ﬁnding b and x.

subject to

b = argmin||b||1

Bx = b
b1 = 1
0 ≤ bi ≤ 1

2 ≤ i ≤ n

Then subtract bbT from B and repeat.

Exercise 10.22 Construct an example of a matrix A satisfying the following conditions

1. The columns of A are 0-1 vectors where the support of no two columns overlap by

50% or more.

2. No column’s support is totally within the support of another column.

3. The minimum 1-norm vector in the column space of A is not a 0-1 vector.

Exercise 10.23 Let M = L+R where L is a low rank matrix corrupted by a sparse noise
matrix R. Why can we not recover L from M if R is low rank or if L is sparse?

356

11 Appendix

11.1 Asymptotic Notation

We introduce the big O notation here. The motivating example is the analysis of the
running time of an algorithm. The running time may be a complicated function of the
input length n such as 5n3 +25n2 ln n−6n+22. Asymptotic analysis is concerned with the
behavior as n → ∞ where the higher order term 5n3 dominates. Further, the coeﬃcient
5 of 5n3 is not of interest since its value varies depending on the machine model. So we
say that the function is O(n3). The big O notation applies to functions on the positive
integers taking on positive real values.

Deﬁnition 11.1 For functions f and g from the natural numbers to the positive reals,
f (n) is O(g(n)) if there exists a constant c >0 such that for all n, f (n) ≤ cg(n).

Thus, f (n) = 5n3 + 25n2 ln n − 6n + 22 is O(n3). The upper bound need not be tight.
Not only is f (n), O(n3), it is also O(n4). Note g(n) must be strictly greater than 0 for all n.

To say that the function f (n) grows at least as fast as g(n), one uses a notation called
omega of n. For positive real valued f and g, f (n) is Ω(g(n)) if there exists a constant
c > 0 such that for all n, f (n) ≥ cg(n). If f (n) is both O(g(n)) and Ω(g(n)), then f (n) is
Θ(g(n)). Theta of n is used when the two functions have the same asymptotic growth rate.

little o of n is used. We say f (n) is o(g(n)) if

Many times one wishes to bound the low order terms. To do this, a notation called
f (n)
g(n) = 0. Note that f (n) being
O(g(n)) means that asymptotically f (n) does not grow faster than g(n), whereas f (n)
n, then
being o(g(n)) means that asymptotically f (n)/g(n) goes to zero. If f (n) = 2n +

lim
n→∞

√

asymptotic upper bound
f (n) is O(g(n)) if for all n, f (n) ≤ cg(n) for some constant c > 0.

asymptotic lower bound
f (n) is Ω(g(n)) if for all n, f (n) ≥ cg(n) for some constant c > 0.

asymptotic equality
f (n) is Θ(g(n)) if it is both O(g(n)) and Ω(g(n)).

f (n) is o(g(n)) if lim
n→∞

f (n)
g(n) = 0 .

f (n) ∼ g(n) if lim
n→∞

f (n)
g(n) = 1.

f (n) is ω (g (n)) if

lim
n→∞

f (n)
g(n) = ∞.

357

≤

≥

=

<

=

>

f (n) is O(n) but in bounding the lower order term, we write f (n) = 2n + o(n). Finally,
f (n)
we write f (n) ∼ g(n) if
g(n) = ∞. The
diﬀerence between f (n) being Θ(g(n)) and f (n) ∼ g(n) is that in the ﬁrst case f (n) and
g(n) may diﬀer by a multiplicative constant factor.

f (n)
g(n) = 1 and say f (n) is ω(g(n)) if

lim
n→∞

lim
n→∞

11.2 Useful relations

Summations

n
(cid:88)

i=0
∞
(cid:88)

i=0
∞
(cid:88)

i=0
∞
(cid:88)

i=0
n
(cid:88)

i=1
n
(cid:88)

i=1
∞
(cid:88)

i=1

ai = 1 + a + a2 + · · · =

ai = 1 + a + a2 + · · · =

1 − an+1
1 − a

,

a (cid:54)= 1

1
1 − a

,

|a| < 1

iai = a + 2a2 + 3a3 · · · =

a
(1 − a)2 ,

|a| < 1

i2ai = a + 4a2 + 9a3 · · · =

a(1 + a)
(1 − a)3 ,

|a| < 1

i =

n(n + 1)
2

i2 =

n(n + 1)(2n + 1)
6

1
i2 =

π2
6

We prove one equality.

∞
(cid:88)

i=0

iai = a + 2a2 + 3a3 · · · =

a

(1 − a)2 , provided |a| < 1.

Write S =

∞
(cid:80)
i=0

iai.

Thus,

aS =

∞
(cid:88)

i=0

iai+1 =

∞
(cid:88)

i=1

(i − 1)ai.

S − aS =

∞
(cid:88)

i=1

iai −

∞
(cid:88)

i=1

(i − 1)ai =

∞
(cid:88)

i=1

ai =

a
1 − a

,

from which the equality follows. The sum (cid:80)

i2ai can also be done by an extension of this

i
method (left to the reader). Using generating functions, we will see another proof of both

358

these equalities by derivatives.

∞
(cid:88)

i=1

1
i

= 1 + 1

2 + (cid:0) 1

3 + 1

4

(cid:1) + (cid:0) 1

5 + 1

6 + 1

7 + 1

8

The summation

n
(cid:80)
i=1

1
i grows as ln n since

n
(cid:80)
i=1

γ where γ ∼= 0.5772 is Euler’s constant. Thus,

(cid:1) + · · · ≥ 1 + 1

2 + 1

2 + · · · and thus diverges.

1
x dx. In fact, lim
i→∞

(cid:18) n
(cid:80)
i=1
∼= ln(n) + γ for large n.

x=1

1

i ≈ (cid:82) n
n
(cid:80)
i=1

1
i

(cid:19)

1
i − ln(n)

=

Truncated Taylor series

If all the derivatives of a function f (x) exist, then we can write

f (x) = f (0) + f (cid:48)(0)x + f (cid:48)(cid:48)(0)

x2
2

+ · · · .

The series can be truncated. In fact, there exists some y between 0 and x such that

Also, there exists some z between 0 and x such that

f (x) = f (0) + f (cid:48)(y)x.

f (x) = f (0) + f (cid:48)(0)x + f (cid:48)(cid:48)(z)

x2
2

and so on for higher derivatives. This can be used to derive inequalities. For example, if
f (x) = ln(1 + x), then its derivatives are

f (cid:48)(x) =

1
1 + x

; f (cid:48)(cid:48)(x) = −

1

(1 + x)2 ; f (cid:48)(cid:48)(cid:48)(x) =

2
(1 + x)3 .

For any z, f (cid:48)(cid:48)(z) < 0 and thus for any x, f (x) ≤ f (0) + f (cid:48)(0)x hence, ln(1 + x) ≤ x, which
also follows from the inequality 1 + x ≤ ex. Also using

f (x) = f (0) + f (cid:48)(0)x + f (cid:48)(cid:48)(0)

x2
2

+ f (cid:48)(cid:48)(cid:48)(z)

x3
3!

for z > −1, f (cid:48)(cid:48)(cid:48)(z) > 0, and so for x > −1,

Exponentials and logs

ln(1 + x) > x −

x2
2

.

ex = 1 + x +

x2
2!

+

x3
3!

alog b = blog a

+ · · ·

e = 2.7182

Setting x = 1 in the equation ex = 1 + x + x2

2! + x3

3! + · · · yields e =

1
e = 0.3679
∞
(cid:80)
i=0

1
i! .

359

(cid:0)1 + a

n

(cid:1)n = ea

lim
n→∞
1
2

ln(1 + x) = x −

x2 +

1
3

x3 −

1
4

x4 · · ·

|x| < 1

The above expression with −x substituted for x gives rise to the approximations

ln(1 − x) < −x

which also follows from 1 − x ≤ e−x, since ln(1 − x) is a monotone function for x ∈ (0, 1).

For 0 < x < 0.69, ln(1 − x) > −x − x2.

Trigonometric identities

eix = cos(x) + i sin(x)
cos(x) = 1
2 (eix + e−ix)
sin(x) = 1
2i (eix − e−ix)
sin(x ± y) = sin(x) cos(y) ± cos(x) sin(y)
cos(x ± y) = cos(x) cos(y) ∓ sin(x) sin(y)
cos (2θ) = cos2 θ − sin2 θ = 1 − 2 sin2 θ
sin (2θ) = 2 sin θ cos θ
sin2 θ
2 (1 − cos θ)
cos2 θ
2 (1 + cos θ)

2 = 1
2 = 1

360

Gaussian and related integrals

(cid:90)

(cid:90)

xeax2dx =

1
2a

eax2

1

a2+x2 dx = 1

a tan−1 x

a thus

∞
(cid:90)

1

a2+x2 dx = π

a

∞
(cid:90)

e− a2x2

2 dx =

√

2π
a

thus

−∞

a
√
2π

∞
(cid:90)

−∞

a2x2

2 dx = 1

e−

x2e−ax2dx =

(cid:114) π
a

1
4a

x2ne− x2

a2 dx =

√

π

1 · 3 · 5 · · · (2n − 1)
2n+1

a2n−1 =

√

π

(2n)!
n!

(cid:16) a
2

(cid:17)2n+1

−∞
∞
(cid:90)

0
∞
(cid:90)

0
(cid:90) ∞

0
∞
(cid:90)

x2n+1e− x2

a2 dx =

n!
2

a2n+2

e−x2dx =

√

π

To verify

∞
(cid:82)

−∞

e−x2dx =

−∞
√

π, consider

(cid:19)2

e−x2dx

(cid:18) ∞
(cid:82)

−∞

=

∞
(cid:82)

∞
(cid:82)

−∞

−∞

e−(x2+y2)dxdy. Let x =

r cos θ and y = r sin θ. The Jacobian of this transformation of variables is

J (r, θ) =

(cid:12)
(cid:12)
(cid:12)
(cid:12)

∂x
∂r
∂y
∂r

∂x
∂θ
∂y
∂θ

(cid:12)
(cid:12)
(cid:12)
(cid:12)

=

(cid:12)
(cid:12)
(cid:12)
(cid:12)

cos θ − r sin θ
sin θ

r cos θ

(cid:12)
(cid:12)
(cid:12)
(cid:12)

= r

Thus,



2

e−x2dx



=

∞
(cid:90)





−∞

∞
(cid:90)

∞
(cid:90)

−∞

−∞

e−(x2+y2)dxdy =

∞
(cid:90)

2π
(cid:90)

0

0

e−r2J (r, θ) drdθ

= −2π

Thus,

∞
(cid:82)

−∞

e−x2dx =

√

π.

e−r2rdr

2π
(cid:90)

dθ

=

∞
(cid:90)

0

(cid:104) e−r2
2

0
(cid:105)∞

0

= π

361

Miscellaneous integrals

(cid:90) 1

x=0

xα−1(1 − α)β−1dx =

Γ(α)Γ(β)
Γ(α + β)

For deﬁnition of the gamma function see Section 11.3 Binomial coeﬃcients

The binomial coeﬃcient (cid:0)n
(n−k)!k! is the number of ways of choosing k items from n.
The number of ways of choosing d + 1 items from n + 1 items equals the number of ways
of choosing the d + 1 items from the ﬁrst n items plus the number of ways of choosing d
of the items from the ﬁrst n items with the other item being the last of the n + 1 items.

(cid:1) = n!

k

(cid:19)

(cid:18)n
d

+

(cid:18) n

(cid:19)

d + 1

=

(cid:18)n + 1
d + 1

(cid:19)
.

The observation that the number of ways of choosing k items from 2n equals the
number of ways of choosing i items from the ﬁrst n and choosing k − i items from the
second n summed over all i, 0 ≤ i ≤ k yields the identity

k
(cid:88)

i=0

(cid:18)n
i

(cid:19)(cid:18) n

(cid:19)

k − i

=

(cid:19)
.

(cid:18)2n
k

Setting k = n in the above formula and observing that (cid:0)n

(cid:1) = (cid:0) n

(cid:1) yields

i

n−i

(cid:19)2

n
(cid:88)

i=0

(cid:18)n
i

=

(cid:19)
.

(cid:18)2n
n

More generally

k
(cid:80)
i=0

(cid:0)n
i

(cid:1)(cid:0) m
k−i

(cid:1) = (cid:0)n+m

(cid:1) by a similar derivation.

k

11.3 Useful Inequalities

1 + x ≤ ex for all real x.

One often establishes an inequality such as 1 + x ≤ ex by showing that the dif-
ference of the two sides, namely ex − (1 + x), is always positive. This can be done
by taking derivatives. The ﬁrst and second derivatives are ex − 1 and ex. Since ex
is always positive, ex − 1 is monotonic and ex − (1 + x) is convex. Since ex − 1 is
monotonic, it can be zero only once and is zero at x = 0. Thus, ex − (1 + x) takes
on its minimum at x = 0 where it is zero establishing the inequality.

(1 − x)n ≥ 1 − nx for 0 ≤ x ≤ 1

362

1 + x ≤ ex for all real x

(1 − x)n ≥ 1 − nx for 0 ≤ x ≤ 1

(x + y)2 ≤ 2x2 + 2y2

Triangle Inequality

|x + y| ≤ |x| + |y|.

Cauchy-Schwartz Inequality

|x||y| ≥ xT y

Young’s Inequality For positive real numbers p and q where 1
positive reals x and y,

p + 1

q = 1 and

1
p
H¨older’s inequalityH¨older’s inequality For positive real numbers p and q with 1
1
q = 1,

xp +

xy ≤

yq.

1
q

p +

n
(cid:88)

|xiyi| ≤

(cid:32) n

(cid:88)

(cid:33)1/p (cid:32) n

(cid:88)

|yi|q

(cid:33)1/q
.

|xi|p

i=1
Jensen’s inequality For a convex function f ,

i=1

i=1

(cid:32) n

(cid:88)

f

i=1

(cid:33)

αixi

≤

n
(cid:88)

i=1

αif (xi),

Let g(x) = (1 − x)n − (1 − nx). We establish g(x) ≥ 0 for x in [0, 1] by taking
the derivative.

g(cid:48)(x) = −n(1 − x)n−1 + n = n(cid:0)1 − (1 − x)n−1(cid:1) ≥ 0

for 0 ≤ x ≤ 1. Thus, g takes on its minimum for x in [0, 1] at x = 0 where g(0) = 0
proving the inequality.

(x + y)2 ≤ 2x2 + 2y2

The inequality follows from (x + y)2 + (x − y)2 = 2x2 + 2y2.

Lemma 11.1 For any nonnegative reals a1, a2, . . . , an and any ρ ∈ [0, 1], (cid:0) (cid:80)n
(cid:80)n

i=1 ai

i=1 aρ
i .

(cid:1)ρ ≤

363

Proof: We will see that we can reduce the proof of the lemma to the case when only one
of the ai is nonzero and the rest are zero. To this end, suppose a1 and a2 are both positive
and without loss of generality, assume a1 ≥ a2. Add an inﬁnitesimal positive amount (cid:15)
to a1 and subtract the same amount from a2. This does not alter the left hand side. We
claim it does not increase the right hand side. To see this, note that

1 − aρ−1

2 = ρ(aρ−1

(a1 + (cid:15))ρ + (a2 − (cid:15))ρ − aρ
1 − aρ−1

1 − aρ
and since ρ − 1 ≤ 0, we have aρ−1
2 ≤ 0, proving the claim. Now by repeating this
process, we can make a2 = 0 (at that time a1 will equal the sum of the original a1 and
a2). Now repeating on all pairs of ai, we can make all but one of them zero and in the
process, we have left the left hand side the same, but have not increased the right hand
side. So it suﬃces to prove the inequality at the end which clearly holds. This method of
proof is called the variational method.

)(cid:15) + O((cid:15)2),

2

The Triangle Inequality

For any two vectors x and y, |x + y| ≤ |x| + |y|. Since x · y ≤ |x||y|,

|x + y|2 = (x + y)T · (x + y) = |x|2 + |y|2 + 2xT · y ≤ |x|2 + |y|2 + 2|x||y| = (|x| + |y|)2.
The inequality follows by taking square roots.

Stirling approximation
(cid:16)n
e

n! ∼=

(cid:17)n √

2πn

(cid:19)

(cid:18)2n
n

∼=

√

2πn

nn
en < n! <

√

2πn

nn
en

(cid:18)

1 +

1
12n − 1

22n

1
√
πn
(cid:19)

We prove the inequalities, except for constant factors. Namely, we prove that
(cid:17)n √

(cid:17)n √

1.4

(cid:16)n
e

n ≤ n! ≤ e

n.

(cid:16)n
e

Write ln(n!) = ln 1 + ln 2 + · · · + ln n. This sum is approximately (cid:82) n
x=1 ln x dx. The
indeﬁnite integral (cid:82) ln x dx = (x ln x − x) gives an approximation, but without the
√
n, diﬀerentiate twice and note that ln x is a concave function.

n term. To get the

√

This means that for any positive x0,

ln x0 + ln(x0 + 1)
2

≤

(cid:90) x0+1

x=x0

ln x dx,

since for x ∈ [x0, x0 + 1], the curve ln x is always above the spline joining (x0, ln x0)
and (x0 + 1, ln(x0 + 1)). Thus,

ln(n!) =

≤

ln 1
2
(cid:90) n

x=1

+

ln 1 + ln 2
2

+

ln 2 + ln 3
2

+ · · · +

ln(n − 1) + ln n
2

+

ln n
2

ln x dx +

= [x ln x − x]n

1 +

ln n
2

= n ln n − n + 1 +

ln n
2
ln n
2

.

364

Thus, n! ≤ nne−n√
x0 ≥ 1/2 and any real ρ

ne. For the lower bound on n!, start with the fact that for any

ln x0 ≥

1
2

Thus,

(ln(x0 + ρ) + ln(x0 − ρ))

implies

ln x0 ≥

(cid:90) x0+.5

x=x0−0.5

ln x dx.

ln(n!) = ln 2 + ln 3 + · · · + ln n ≥

(cid:90) n+.5

x=1.5

ln x dx,

from which one can derive a lower bound with a calculation.

Stirling approximation for the binomial coeﬃcient

(cid:19)

(cid:18)n
k

≤

(cid:17)k

(cid:16) en
k

Using the Stirling approximation for k!,

(cid:19)

(cid:18)n
k

=

n!
(n − k)!k!

≤

nk
k!

∼=

(cid:17)k

.

(cid:16) en
k

The gamma function

For a > 0

∞
(cid:90)

Γ (a) =

xa−1e−xdx

0
√

Γ (cid:0) 1

2

(cid:1) =

π, Γ (1) = Γ (2) = 1, and for n ≥ 2, Γ (n) = (n − 1)Γ (n − 1) .

The last statement is proved by induction on n. It is easy to see that Γ(1) = 1. For n ≥ 2,
we use integration by parts.

(cid:90)

f (x) g(cid:48) (x) dx = f (x) g (x) −

(cid:90)

f (cid:48) (x) g (x) dx

Write Γ(n) = (cid:82) ∞

x=0 f (x)g(cid:48)(x) dx, where, f (x) = xn−1 and g(cid:48)(x) = e−x. Thus,

Γ(n) = [f (x)g(x)]∞

x=0 +

(cid:90) ∞

x=0

(n − 1)xn−2e−x dx = (n − 1)Γ(n − 1),

as claimed.

Cauchy-Schwartz Inequality

(cid:32) n

(cid:88)

(cid:33) (cid:32) n

(cid:88)

(cid:33)

y2
i

≥

(cid:32) n

(cid:88)

xiyi

(cid:33)2

x2
i

i=1

i=1

i=1

365

In vector form, |x||y| ≥ xT y, the inequality states that the dot product of two vectors
is at most the product of their lengths. The Cauchy-Schwartz inequality is a special case
of H¨older’s inequality with p = q = 2.

Young’s inequality

For positive real numbers p and q where 1

p + 1

q = 1 and positive reals x and y,

1
p

xp +

1
q

yq ≥ xy.

The left hand side of Young’s inequality, 1
q yq, is a convex combination of xp and yq
since 1
q sum to 1. ln(x) is a concave function for x > 0 and so the ln of the convex
combination of the two elements is greater than or equal to the convex combination of
the ln of the two elements

p and 1

p xp + 1

ln(

1
p

xp +

1
q

yp) ≥

1
p

ln(xp) +

1
q

ln(yq) = ln(xy).

Since for x ≥ 0, ln x is a monotone increasing function, 1

p xp + 1

q yq ≥ xy..

H¨older’s inequalityH¨older’s inequality

For positive real numbers p and q with 1

p + 1

q = 1,

n
(cid:88)

i=1

|xiyi| ≤

(cid:32) n

(cid:88)

i=1

(cid:33)1/p (cid:32) n

(cid:88)

(cid:33)1/q
.

|yi|q

|xi|p

i=1

i = xi / ((cid:80)n

i=1 |xi|p)1/p and y(cid:48)

Let x(cid:48)
i does not change the inequality. Now (cid:80)n
y(cid:48)
(cid:80)n
i=1 |x(cid:48)

i| ≤ 1. Apply Young’s inequality to get |x(cid:48)

i = yi / ((cid:80)n
i=1 |x(cid:48)

i=1 |yi|q)1/q. Replacing xi by x(cid:48)
i and yi by
i|p = (cid:80)n
i|q = 1, so it suﬃces to prove
i=1 |y(cid:48)
i| ≤ |x(cid:48)
i|p
p + |y(cid:48)
i|q
iy(cid:48)
q . Summing over i, the
q = 1 ﬁnishing the proof.

right hand side sums to 1

p + 1

iy(cid:48)

For a1, a2, . . . , an real and k a positive integer,

(a1 + a2 + · · · + an)k ≤ nk−1(|a1|k + |a2|k + · · · + |an|k).

Using H¨older’s inequality with p = k and q = k/(k − 1),

|a1 + a2 + · · · + an| ≤ |a1 · 1| + |a2 · 1| + · · · + |an · 1|

(1 + 1 + · · · + 1)(k−1)/k ,

(cid:32) n

(cid:88)

≤

|ai|k

(cid:33)1/k

i=1

366

from which the current inequality follows.

Arithmetic and geometric means

The arithmetic mean of a set of nonnegative reals is at least their geometric mean.

For a1, a2, . . . , an > 0,

1
n

n
(cid:88)

i=1

√
ai ≥ n

a1a2 · · · an.

Assume that a1 ≥ a2 ≥ . . . ≥ an. We reduce the proof to the case when all the ai
are equal using the variational method; in this case the inequality holds with equality.
Suppose a1 > a2. Let ε be a positive inﬁnitesimal. Add ε to a2 and subtract ε from a1 to
get closer to the case when they are equal. The left hand side 1
i=1 ai does not change.
n

(cid:80)n

(a1 − ε)(a2 + ε)a3a4 · · · an = a1a2 · · · an + ε(a1 − a2)a3a4 · · · an + O(ε2)

> a1a2 · · · an

√
for small enough ε > 0. Thus, the change has increased n
a1a2 · · · an. So if the inequality
holds after the change, it must hold before. By continuing this process, one can make all
the ai equal.

Approximating sums by integrals

For monotonic decreasing f (x),

n+1
(cid:90)

x=m

f (x)dx ≤

n
(cid:88)

i=m

f (i) ≤

n
(cid:90)

x=m−1

f (x)dx.

See Fig. 11.1. Thus,

n+1
(cid:90)

x=2

1
x2 dx ≤

n
(cid:88)

i=2

and hence 3

2 − 1

n+1 ≤

n
(cid:80)
i=1

1

i2 ≤ 2 − 1
n .

1

i2 = 1

4 + 1

9 + · · · + 1

n2 ≤

n
(cid:82)

x=1

1
x2 dx

Jensen’s Inequality

For a convex function f ,

(cid:18) 1
2

f

(cid:19)

(x1 + x2)

≤

1
2

(f (x1) + f (x2)) .

367

n+1
(cid:82)

x=m

f (x)dx ≤

n
(cid:80)
i=m

f (i) ≤

n
(cid:82)

x=m−1

f (x)dx

m − 1 m

n n + 1

Figure 11.1: Approximating sums by integrals

More generally for any convex function f ,

(cid:32) n

(cid:88)

f

i=1

(cid:33)

αixi

≤

n
(cid:88)

i=1

αif (xi),

where 0 ≤ αi ≤ 1 and

random variable x,

n
(cid:80)
i=1

αi = 1. From this, it follows that for any convex function f and

E (f (x)) ≥ f (E (x)) .

We prove this for a discrete random variable x taking on values a1, a2, . . . with Prob(x =
ai) = αi:

E(f (x)) =

(cid:88)

i

αif (ai) ≥ f

(cid:33)

(cid:32)

(cid:88)

i

αiai

= f (E(x)).

f (x1)

f (x2)

x1

x2

Figure 11.2: For a convex function f , f (cid:0) x1+x2

2

(cid:1) ≤ 1

2 (f (x1) + f (x2)) .

368

Example: Let f (x) = xk for k an even positive integer. Then, f (cid:48)(cid:48)(x) = k(k − 1)xk−2
which since k − 2 is even is nonnegative for all x implying that f is convex. Thus,

E (x) ≤ k(cid:112)E (xk),

k is a monotone function of t, t > 0. It is easy to see that this inequality does not

since t 1
necessarily hold when k is odd; indeed for odd k, xk is not a convex function.

Tails of Gaussian

For bounding the tails of Gaussian densities, the following inequality is useful. The

proof uses a technique useful in many contexts. For t > 0,

(cid:90) ∞

x=t

e−x2 dx ≤

e−t2
2t

.

In proof, ﬁrst write: (cid:82) ∞
t e−x2 dx, using the fact that x ≥ t in the range of
integration. The latter expression is integrable in closed form since d(e−x2) = (−2x)e−x2
yielding the claimed bound.

x=t e−x2 dx ≤ (cid:82) ∞

x=t

x

A similar technique yields an upper bound on

(cid:90) 1

x=β

(1 − x2)α dx,

for β ∈ [0, 1] and α > 0. Just use (1 − x2)α ≤ x
closed form the last expression.

β (1 − x2)α over the range and integrate in

(cid:90) 1

x=β

(1 − x2)αdx ≤

=

(1 − x2)αdx =

(cid:90) 1

x
β
x=β
(1 − β2)α+1
2β(α + 1)

−1
2β(α + 1)

(1 − x2)α+1

(cid:12)
(cid:12)
(cid:12)
(cid:12)

1

x=β

11.4 Probability

Consider an experiment such as ﬂipping a coin whose outcome is determined by chance.
To talk about the outcome of a particular experiment, we introduce the notion of a ran-
dom variable whose value is the outcome of the experiment. The set of possible outcomes
is called the sample space. If the sample space is ﬁnite, we can assign a probability of
occurrence to each outcome. In some situations where the sample space is inﬁnite, we can
assign a probability of occurrence. The probability p (i) = 6
1
i2 for i an integer greater
π2
than or equal to one is such an example. The function assigning the probabilities is called

369

a probability distribution function.

In many situations, a probability distribution function does not exist. For example,
for the uniform probability on the interval [0,1], the probability of any speciﬁc value is
zero. What we can do is deﬁne a probability density function p(x) such that

Prob(a < x < b) =

b

(cid:90)

a

p(x)dx

If x is a continuous random variable for which a density function exists, then the cumu-
lative distribution function f (a) is deﬁned by
(cid:90) a

f (a) =

p(x)dx

which gives the probability that x ≤ a.

−∞

11.4.1 Sample Space, Events, Independence

There may be more than one relevant random variable in a situation. For example, if
one tosses n coins, there are n random variables, x1, x2, . . . , xn, taking on values 0 and 1,
a 1 for heads and a 0 for tails. The set of possible outcomes, the sample space, is {0, 1}n.
An event is a subset of the sample space. The event of an odd number of heads, consists
of all elements of {0, 1}n with an odd number of 1’s.

Let A and B be two events. The joint occurrence of the two events is denoted by
(A∧B). The conditional probability of event A given that event B has occurred is denoted
by Prob(A|B)and is given by

Prob(A|B) =

Prob(A ∧ B)
Prob(B)

.

Events A and B are independent if the occurrence of one event has no inﬂuence on the
probability of the other. That is, Prob(A|B) = Prob(A) or equivalently, Prob(A ∧ B) =
Prob(A)Prob(B). Two random variables x and y are independent if for every possible set
A of values for x and every possible set B of values for y, the events x in A and y in B
are independent.

A collection of n random variables x1, x2, . . . , xn is mutually independent if for all

possible sets A1, A2, . . . , An of values of x1, x2, . . . , xn,

Prob(x1 ∈ A1, x2 ∈ A2, . . . , xn ∈ An) = Prob(x1 ∈ A1)Prob(x2 ∈ A2) · · · Prob(xn ∈ An).

If the random variables are discrete, it would suﬃce to say that for any real numbers
a1, a2, . . . , an

Prob(x1 = a1, x2 = a2, . . . , xn = an) = Prob(x1 = a1)Prob(x2 = a2) · · · Prob(xn = an).

370

Random variables x1, x2, . . . , xn are pairwise independent if for any ai and aj, i (cid:54)= j,
Prob(xi = ai, xj = aj) = Prob(xi = ai)Prob(xj = aj). Mutual independence is much
stronger than requiring that the variables are pairwise independent. Consider the exam-
ple of 2-universal hash functions discussed in Chapter 7.

If (x, y) is a random vector and one normalizes it to a unit vector

(cid:18)

x√

x2+y2

,

y√

x2+y2

(cid:19)

the coordinates are no longer independent since knowing the value of one coordinate
uniquely determines the value of the other.

11.4.2 Linearity of Expectation

An important concept is that of the expectation of a random variable. The expected
xp(x) in the discrete case and E(x) =

value, E(x), of a random variable x is E(x) = (cid:80)

∞
(cid:82)

xp(x)dx in the continuous case. The expectation of a sum of random variables is equal

x

−∞
to the sum of their expectations. The linearity of expectation follows directly from the
deﬁnition and does not require independence.

11.4.3 Union Bound

Let A1, A2, . . . , An be events. The actual probability of the union of events is given

by Boole’s formula.

Prob(A1 ∪ A2 ∪ · · · An) =

n
(cid:88)

i=1

Prob(Ai) −

(cid:88)

ij

Prob(Ai ∧ Aj) +

(cid:88)

ijk

Prob(Ai ∧ Aj ∧ Ak) − · · ·

Often we only need an upper bound on the probability of the union and use

Prob(A1 ∪ A2 ∪ · · · An) ≤

n
(cid:88)

i=1

Prob(Ai)

This upper bound is called the union bound.

11.4.4 Indicator Variables

A useful tool is that of an indicator variable that takes on value 0 or 1 to indicate
whether some quantity is present or not. The indicator variable is useful in determining
the expected size of a subset. Given a random subset of the integers {1, 2, . . . , n}, the
expected size of the subset is the expected value of x1 + x2 + · · · + xn where xi is the
indicator variable that takes on value 1 if i is in the subset.

Example: Consider a random permutation of n integers. Deﬁne the indicator function
xi = 1 if the ith integer in the permutation is i. The expected number of ﬁxed points is
given by

371

(cid:32) n

(cid:88)

E

(cid:33)

xi

=

i=1

n
(cid:88)

i=1

E(xi) = n

1
n

= 1.

Note that the xi are not independent. But, linearity of expectation still applies.

Example: Consider the expected number of vertices of degree d in a random graph
G(n, p). The number of vertices of degree d is the sum of n indicator random variables, one
for each vertex, with value one if the vertex has degree d. The expectation is the sum of the
expectations of the n indicator random variables and this is just n times the expectation
of one of them. Thus, the expected number of degree d vertices is n(cid:0)n

(cid:1)pd(1 − p)n−d.

d

11.4.5 Variance

In addition to the expected value of a random variable, another important parameter
is the variance. The variance of a random variable x, denoted var(x) or often σ2(x) is
E (x − E (x))2 and measures how close to the expected value the random variable is likely
to be. The standard deviation σ is the square root of the variance. The units of σ are the
same as those of x.

By linearity of expectation

σ2 = E (x − E (x))2 = E(x2) − 2E(x)E(x) + E2(x) = E (cid:0)x2(cid:1) − E2 (x) .

11.4.6 Variance of the Sum of Independent Random Variables

In general, the variance of the sum is not equal to the sum of the variances. However,

if x and y are independent, then E (xy) = E (x) E (y) and

var(x + y) = var (x) + var (y) .

To see this

var(x + y) = E (cid:0)(x + y)2(cid:1) − E2(x + y)

= E(x2) + 2E(xy) + E(y2) − E2(x) − 2E(x)E(y) − E2(y).

From independence, 2E(xy) − 2E(x)E(y) = 0 and

var(x + y) = E(x2) − E2(x) + E(y2) − E2(y)

= var(x) + var(y).

More generally, if x1, x2, . . . , xn are pairwise independent random variables, then

var(x1 + x2 + · · · + xn) = var(x1) + var(x2) + · · · + var(xn).

For the variance of the sum to be the sum of the variances only requires pairwise inde-
pendence not full independence.

372

11.4.7 Median

One often calculates the average value of a random variable to get a feeling for the
magnitude of the variable. This is reasonable when the probability distribution of the
variable is Gaussian, or has a small variance. However, if there are outliers, then the
average may be distorted by outliers. An alternative to calculating the expected value is
to calculate the median, the value for which half of the probability is above and half is
below.

11.4.8 The Central Limit Theorem

Let s = x1 + x2 + · · · + xn be a sum of n independent random variables where each xi

has probability distribution

xi =

(cid:26) 0
1

1
2
1
2

.

The expected value of each xi is 1/2 with variance

σ2
i =

(cid:18) 1
2

− 0

(cid:19)2 1
2

+

(cid:18) 1
2

− 1

(cid:19)2 1
2

=

1
4

.

The expected value of s is n/2 and since the variables are independent, the variance of
the sum is the sum of the variances and hence is n/4. How concentrated s is around its
√
n
mean depends on the standard deviation of s which is
2 . For n equal 100 the expected
value of s is 50 with a standard deviation of 5 which is 10% of the mean. For n = 10, 000
the expected value of s is 5,000 with a standard deviation of 50 which is 1% of the
mean. Note that as n increases, the standard deviation increases, but the ratio of the
standard deviation to the mean goes to zero. More generally, if xi are independent and
identically distributed, each with standard deviation σ, then the standard deviation of
has standard deviation σ. The central limit
x1 + x2 + · · · + xn is
theorem makes a stronger assertion that in fact x1+x2+···+xn
has Gaussian distribution
with standard deviation σ.

nσ. So, x1+x2+···+xn

√

√

√

n

n

Theorem 11.2 Suppose x1, x2, . . . , xn is a sequence of identically distributed independent
random variables, each with mean µ and variance σ2. The distribution of the random
variable

1
√
n

(x1 + x2 + · · · + xn − nµ)

converges to the distribution of the Gaussian with mean 0 and variance σ2.

11.4.9 Probability Distributions

The Gaussian or normal distribution

373

The normal distribution is

√

1
2πσ

e− 1

2

(x−m)2
σ2

where m is the mean and σ2 is the variance. The coeﬃcient
makes the integral of
the distribution be one. If we measure distance in units of the standard deviation σ from
the mean, then

2πσ

1√

Standard tables give values of the integral

φ(x) =

1
√
2π

e− 1

2 x2

t

(cid:90)

0

φ(x)dx

and from these values one can compute probability integrals for a normal distribution
with mean m and variance σ2.

General Gaussians

So far we have seen spherical Gaussian densities in Rd. The word spherical indicates
that the level curves of the density are spheres. If a random vector y in Rd has a spherical
Gaussian density with zero mean, then yi and yj, i (cid:54)= j, are independent. However, in
many situations the variables are correlated. To model these Gaussians, level curves that
are ellipsoids rather than spheres are used.

For a random vector x, the covariance of xi and xj is E((xi − µi)(xj − µj)). We list
the covariances in a matrix called the covariance matrix, denoted Σ.11 Since x and µ are
column vectors, (x − µ)(x − µ)T is a d × d matrix. Expectation of a matrix or vector
means componentwise expectation.

Σ = E(cid:0)(x − µ)(x − µ)T (cid:1).

The general Gaussian density with mean µ and positive deﬁnite covariance matrix Σ is

f (x) =

1
(cid:112)(2π)d det(Σ)

(cid:18)

exp

−

1
2

(x − µ)T Σ−1(x − µ)

(cid:19)

.

To compute the covariance matrix of the Gaussian, substitute y = Σ−1/2(x − µ). Noting
that a positive deﬁnite symmetric matrix has a square root:

E((x − µ)(x − µ)T = E(Σ1/2yyT Σ1/2)

= Σ1/2 (cid:0)E(yyT )(cid:1) Σ1/2 = Σ.

11Σ is the standard notation for the covariance matrix. We will use it sparingly so as not to confuse

with the summation sign.

374

The density of y is the unit variance, zero mean Gaussian, thus E(yyT ) = I.

Bernoulli trials and the binomial distribution

A Bernoulli trial has two possible outcomes, called success or failure, with probabilities
p and 1 − p, respectively. If there are n independent Bernoulli trials, the probability of
exactly k successes is given by the binomial distribution

B (n, p) =

(cid:19)

(cid:18)n
k

pk(1 − p)n−k

The mean and variance of the binomial distribution B(n, p) are np and np(1 − p), respec-
tively. The mean of the binomial distribution is np, by linearity of expectations. The
variance is np(1 − p) since the variance of a sum of independent random variables is the
sum of their variances.

Let x1 be the number of successes in n1 trials and let x2 be the number of successes
in n2 trials. The probability distribution of the sum of the successes, x1 + x2, is the same
as the distribution of x1 + x2 successes in n1 + n2 trials. Thus, B (n1, p) + B (n2, p) =
B (n1 + n2, p).

Poisson distribution

The Poisson distribution describes the probability of k events happening in a unit of
time when the average rate per unit of time is λ. Divide the unit of time into n segments.
When n is large enough, each segment is suﬃciently small so that the probability of two
events happening in the same segment is negligible. The Poisson distribution gives the
probability of k events happening in a unit of time and can be derived from the binomial
distribution by taking the limit as n → ∞.

Let p = λ

n . Then

Prob(k successes in a unit of time) = lim
n→∞

= lim
n→∞

n (n − 1) · · · (n − k + 1)
k!

= lim
n→∞

λk
k!

e−λ

(cid:19)k (cid:18)

(cid:19)n−k

(cid:18)n
(cid:19) (cid:18) λ
n
k
(cid:19)k (cid:18)
(cid:18) λ
n

1 −

λ
n

1 −

λ
n
(cid:19)n (cid:18)

1 −

(cid:19)−k

λ
n

In the limit as n goes to inﬁnity the binomial distribution p (k) = (cid:0)n

(cid:1)pk (1 − p)n−k be-
comes the Poisson distribution p (k) = e−λ λk
k! . The mean and the variance of the Poisson
distribution have value λ. If x and y are both Poisson random variables from distributions

k

375

with means λ1 and λ2 respectively, then x + y is Poisson with mean m1 + m2. For large
n and small p the binomial distribution can be approximated with the Poisson distribution.

The binomial distribution with mean np and variance np(1 − p) can be approximated
by the normal distribution with mean np and variance np(1−p). The central limit theorem
tells us that there is such an approximation in the limit. The approximation is good if
both np and n(1 − p) are greater than 10 provided k is not extreme. Thus,

(cid:18)n
k

(cid:19) (cid:18)1
2

(cid:19)k (cid:18) 1
2

(cid:19)n−k

∼=

1
(cid:112)πn/2

e

− (n/2−k)2
1
2 n

.

This approximation is excellent provided k is Θ(n). The Poisson approximation

(cid:19)

(cid:18)n
k

pk (1 − p)k ∼= e−np (np)k
k!

is oﬀ for central values and tail values even for p = 1/2. The approximation

(cid:19)

(cid:18) n
k

pk (1 − p)n−k ∼=

√

e− (pn−k)2

pn

1
πpn

is good for p = 1/2 but is oﬀ for other values of p.

Generation of random numbers according to a given probability distribution

Suppose one wanted to generate a random variable with probability density p(x) where
p(x) is continuous. Let P (x) be the cumulative distribution function for x and let u be
a random variable with uniform probability density over the interval [0,1]. Then the ran-
dom variable x = P −1 (u) has probability density p(x).

Example: For a Cauchy density function the cumulative distribution function is

P (x) =

x
(cid:90)

t=−∞

1
π

1

1 + t2 dt =

1
2

+

1
π

tan−1 (x) .

Setting u = P (x) and solving for x yields x = tan (cid:0)π (cid:0)u − 1
(cid:1)(cid:1). Thus, to generate a
random number x ≥ 0 using the Cauchy distribution, generate u, 0 ≤ u ≤ 1, uniformly
(cid:1)(cid:1) . The value of x varies from −∞ to ∞ with x = 0 for
and calculate x = tan (cid:0)π (cid:0)u − 1
u = 1/2.

2

2

11.4.10 Bayes Rule and Estimators

Bayes rule

376

Bayes rule relates the conditional probability of A given B to the conditional proba-

bility of B given A.

Prob (A|B) =

Prob (B|A) Prob (A)
Prob (B)

Suppose one knows the probability of A and wants to know how this probability changes
if we know that B has occurred. Prob(A) is called the prior probability. The conditional
probability Prob(A|B) is called the posterior probability because it is the probability of
A after we know that B has occurred.

The example below illustrates that if a situation is rare, a highly accurate test will

often give the wrong answer.

Example: Let A be the event that a product is defective and let B be the event that a
test says a product is defective. Let Prob(B|A) be the probability that the test says a
product is defective assuming the product is defective and let Prob (cid:0)B| ¯A(cid:1) be the proba-
bility that the test says a product is defective if it is not actually defective.

What is the probability Prob(A|B) that the product is defective if the test say it is
defective? Suppose Prob(A) = 0.001, Prob(B|A) = 0.99, and Prob (cid:0)B| ¯A(cid:1) = 0.02. Then

Prob (B) = Prob (B|A) Prob (A) + Prob (cid:0)B| ¯A(cid:1) Prob (cid:0) ¯A(cid:1)

= 0.99 × 0.001 + 0.02 × 0.999
= 0.02087

and

Prob (A|B) =

Prob (B|A) Prob (A)
Prob (B)

≈

0.99 × 0.001
0.0210

= 0.0471

Even though the test fails to detect a defective product only 1% of the time when it
is defective and claims that it is defective when it is not only 2% of the time, the test
is correct only 4.7% of the time when it says a product is defective. This comes about
because of the low frequencies of defective products.

The words prior, a posteriori, and likelihood come from Bayes theorem.

a posteriori =

likelihood × prior
normalizing constant

Prob (A|B) =

Prob (B|A) Prob (A)
Prob (B)

The a posteriori probability is the conditional probability of A given B. The likelihood
is the conditional probability Prob(B|A).

Unbiased Estimators

377

σ2. For this distribution, m = x1+x2+···+xn

Consider n samples x1, x2, . . . , xn from a Gaussian distribution of mean µ and variance
is an unbiased estimator of µ, which means
(xi − µ)2 is an unbiased estimator of σ2. However, if µ is not

that E(m) = µ and 1
n

n

n
(cid:80)
i=1

known and is approximated by m, then 1
n−1

n
(cid:80)
i=1

(xi − m)2 is an unbiased estimator of σ2.

Maximum Likelihood Estimation MLE

Suppose the probability distribution of a random variable x depends on a parameter
r. With slight abuse of notation, since r is a parameter rather than a random variable, we
denote the probability distribution of x as p (x|r) . This is the likelihood of observing x if
r was in fact the parameter value. The job of the maximum likelihood estimator, MLE,
is to ﬁnd the best r after observing values of the random variable x. The likelihood of r
being the parameter value given that we have observed x is denoted L(r|x). This is again
not a probability since r is a parameter, not a random variable. However, if we were to
apply Bayes’ rule as if this was a conditional probability, we get

L(r|x) =

Prob(x|r)Prob(r)
Prob(x)

.

Now, assume Prob(r) is the same for all r. The denominator Prob(x) is the absolute
probability of observing x and is independent of r. So to maximize L(r|x), we just maxi-
mize Prob(x|r). In some situations, one has a prior guess as to the distribution Prob(r).
This is then called the “prior” and in that case, we call Prob(x|r) the posterior which we
try to maximize.

Example: Consider ﬂipping a coin 100 times. Suppose 62 heads and 38 tails occur.
What is the most likely value of the probability of the coin to come down heads when the
coin is ﬂipped? In this case, it is r = 0.62. The probability that we get 62 heads if the
unknown probability of heads in one trial is r is

Prob (62 heads|r) =

(cid:19)

(cid:18)100
62

r62(1 − r)38.

This quantity is maximized when r = 0.62. To see this take the logarithm, which as a
function of r is ln (cid:0)100
(cid:1) + 62 ln r + 38 ln(1 − r). The derivative with respect to r is zero at
r = 0.62 and the second derivative is negative indicating a maximum. Thus, r = 0.62 is
the maximum likelihood estimator of the probability of heads in a trial.

62

11.4.11 Tail Bounds and Chernoﬀ inequalities

Markov’s inequality bounds the probability that a nonnegative random variable exceeds
a value a.

E(x)
a

.

p(x ≥ a) ≤

378

or

p (cid:0)x ≥ aE(x)(cid:1) ≤

1
a

If one also knows the variance, σ2, then using Chebyshev’s inequality one can bound the
probability that a random variable diﬀers from its expected value by more than a standard
deviations.

p(|x − m| ≥ aσ) ≤

1
a2

If a random variable s is the sum of n independent random variables x1, x2, . . . , xn of
ﬁnite variance, then better bounds are possible. For any δ > 0,

Prob(s > (1 + δ)m) <

(cid:20)

eδ
(1 + δ)(1+δ)

(cid:21)m

and for 0 < γ ≤ 1,

Prob (cid:0)s < (1 − γ)m(cid:1) <

(cid:20)

e−γ
(1 + γ)(1+γ)

(cid:21)m

< e− γ2m

2

Chernoﬀ inequalities

Chebyshev’s inequality bounds the probability that a random variable will deviate
from its mean by more than a given amount. Chebyshev’s inequality holds for any proba-
bility distribution. For some distributions we can get much tighter bounds. For example,
the probability that a Gaussian random variable deviates from its mean falls oﬀ exponen-
tially with the distance from the mean. Here we shall be concerned with the situation
where we have a random variable that is the sum of n independent random variables. This
is another situation in which we can derive a tighter bound than that given by the Cheby-
shev inequality. We consider the case where the n independent variables are binomial but
similar results can be shown for independent random variables from any distribution that
has a ﬁnite variance.

Let x1, x2, . . . , xn be independent random variables where

xi =

(cid:26) 0 Prob 1 − p
1 Prob

p

.

Consider the sum s =

xi. Here the expected value of each xi is p and by linearity of

expectation, the expected value of the sum is m=np. Theorem 2.10 bounds the probability
that the sum s exceeds (1 + δ) m.

n
(cid:80)
i=1

Theorem 11.3 For any δ > 0, Prob (cid:0)s > (1 + δ)m(cid:1) <

(cid:16)

eδ
(1+δ)(1+δ)

(cid:17)m

379

Proof: For any λ > 0, the function eλx is monotone. Thus,

Prob (cid:0)s > (1 + δ)m(cid:1) = Prob (cid:0)eλs > eλ(1+δ)m(cid:1) .

eλx is nonnegative for all x, so we can apply Markov’s inequality to get

Prob (cid:0)eλs > eλ(1+δ)m(cid:1) ≤ e−λ(1+δ)mE (cid:0)eλs(cid:1) .

Since the xi are independent,

E (cid:0)eλs(cid:1) = E

(cid:33)

(cid:32)
e

λ

n
(cid:80)
i=1

xi

= E

(cid:32) n
(cid:89)

(cid:33)

eλxi

=

E (cid:0)eλxi(cid:1)

n
(cid:89)

i=1

=

n
(cid:89)

i=1

(cid:0)eλp + 1 − p(cid:1) =

i=1
n
(cid:89)

i=1

(cid:0)p(eλ − 1) + 1(cid:1).

Using the inequality 1 + x < ex with x = p(eλ − 1) yields

E (cid:0)eλs(cid:1) <

n
(cid:89)

i=1

ep(eλ−1).

Thus, for all λ > 0

Prob (cid:0)s > (1 + δ)m(cid:1) ≤ Prob (cid:0)eλs > eλ(1+δ)m(cid:1)

≤ e−λ(1+δ)mE (cid:0)eλs(cid:1)

≤ e−λ(1+δ)m

n
(cid:89)

i=1

ep(eλ−1).

Setting λ = ln(1 + δ)

Prob (cid:0)s > (1 + δ)m(cid:1) ≤ (cid:0)e− ln(1+δ)(cid:1)(1+δ)m

n
(cid:89)

i=1

ep(eln(1+δ)−1)

≤

≤

≤

(cid:18) 1

(cid:19)(1+δ)m n
(cid:89)

epδ

1 + δ
(cid:18) 1

(1 + δ)

i=1

(cid:19)(1+δ)m

enpδ

(cid:32)

eδ
(1 + δ)(1+δ)

(cid:33)m

.

380

To simplify the bound of Theorem 11.3, observe that

(1 + δ) ln (1 + δ) = δ +

δ2
2

−

δ3
6

+

δ4
12

− · · · .

Therefore

and hence

Thus, the bound simpliﬁes to

(1 + δ)(1+δ) = eδ+ δ2

2 − δ3

6 + δ4

12 −···

eδ

(1+δ)(1+δ) = e− δ2

2 + δ3

6 −···.

Prob (cid:0)s < (1 + δ) m(cid:1) ≤ e− δ2

2 m+ δ3

6 m−···.

For small δ the probability drops exponentially with δ2.

When δ is large another simpliﬁcation is possible. First

Prob (cid:0)s > (1 + δ) m(cid:1) ≤

(cid:32)

eδ
(1 + δ)(1+δ)

(cid:33)m

≤

(cid:18) e

(cid:19)(1+δ)m

1 + δ

If δ > 2e − 1, substituting 2e − 1 for δ in the denominator yields

Prob(s > (1 + δ) m) ≤ 2−(1+δ)m.

Theorem 11.3 gives a bound on the probability of the sum being greater than the

mean. We now bound the probability that the sum will be less than its mean.

Theorem 11.4 Let 0 < γ ≤ 1, then Pr ob (cid:0)s < (1 − γ)m(cid:1) <

(cid:16)

e−γ
(1+γ)(1+γ)

(cid:17)m

< e− γ2m

2

.

Proof: For any λ > 0

Prob (cid:0)s < (1 − γ)m(cid:1) = Prob (cid:0) − s > −(1 − γ)m(cid:1) = Prob (cid:0)e−λs > e−λ(1−γ)m(cid:1) .

Applying Markov’s inequality

Now

Prob (cid:0)s < (1 − γ)m(cid:1) <

E(e−λx)
e−λ(1−γ)m <

n
(cid:81)
E(e−λXi)
i=1
e−λ(1−γ)m .

E(e−λxi) = pe−λ + 1 − p = 1 + p(e−λ − 1) + 1.

381

Thus,

Since 1 + x < ex

Setting λ = ln 1
1−γ

Prob(s < (1 − γ)m) <

n
(cid:81)
i=1

[1 + p(e−λ − 1)]

e−λ(1−γ)m

.

Prob (cid:0)s < (1 − γ)m(cid:1) <

enp(e−λ−1)
e−λ(1−γ)m .

Prob (cid:0)s < (1 − γ)m(cid:1) <

<

enp(1−γ−1)
(1 − γ)(1−γ)m
(cid:18)
e−γ
(1 − γ)(1−γ)

(cid:19)m

.

But for 0 < γ ≤ 1, (1 − γ)(1−γ) > e−γ+ γ2

2 . To see this note that

(1 − γ) ln (1 − γ) = (1 − γ)

−γ −

(cid:18)

γ2
2

−

γ3
3

(cid:19)

− · · ·

− · · · + γ2 +
(cid:19)
(cid:18) γ3
2

−

+

+
(cid:19)

γ3
2
γ3
3

γ4
3

+ · · ·

+ · · ·

= −γ −

= −γ +

= −γ +

≥ −γ +

γ3
3
γ2
2
γ3
6

−

γ2
2
(cid:18)

γ2 −

γ2
2
γ2
2

+

.

+ · · ·

It then follows that

Prob (cid:0)s < (1 − γ)m(cid:1) <

(cid:18)

e−γ
(1 − γ)(1−γ)

(cid:19)m

< e− mγ2

2

.

11.5 Eigenvalues and Eigenvectors

11.5.1 Eigenvalues and Eigenvectors

Let A be an n×n real matrix. The scalar λ is called an eigenvalue of A if there exists a
nonzero vector x satisfying the equation Ax = λx. The vector x is called the eigenvector
of A associated with λ. The set of all eigenvectors associated with a given eigenvalue form
a subspace as seen from the fact that if Ax = λx and Ay = λy, then for any scalers c
and d, A(cx + dy) = λ(cx + dy). The equation Ax = λx has a nontrivial solution only if

382

det(A − λI) = 0. The equation det(A − λI) = 0 is called the characteristic equation and
has n not necessarily distinct roots.

Matrices A and B are similar if there is an invertible matrix P such that A = P −1BP .

Theorem 11.5 If A and B are similar, then they have the same eigenvalues.

Proof: Let A and B be similar matrices. Then there exists an invertible matrix P
such that A = P −1BP . For an eigenvector x of A with eigenvalue λ, Ax = λx, which
implies P −1BP x = λx or B(P x) = λ(P x). So, P x is an eigenvector of B with the same
eigenvalue λ. Since the reverse also holds, the theorem follows.

Even though two similar matrices, A and B, have the same eigenvalues, their eigen-

vectors are in general diﬀerent.

The matrix A is diagonalizable if A is similar to a diagonal matrix.

Theorem 11.6 A is diagonalizable if and only if A has n linearly independent eigenvec-
tors.

Proof:

(only if ) Assume A is diagonalizable. Then there exists an invertible matrix P
and a diagonal matrix D such that D = P −1AP . Thus, P D = AP . Let the diago-
nal elements of D be λ1, λ2, . . . , λn and let p1, p2, . . . , pn be the columns of P . Then
AP = [Ap1, Ap2, . . . , Apn] and P D = [λ1p1, λ2p2, . . . , λnpn] . Hence Api = λipi. That
is, the λi are the eigenvalues of A and the pi are the corresponding eigenvectors. Since P
is invertible, the pi are linearly independent.

(if ) Assume that A has n linearly independent eigenvectors p1, p2, . . . , pn with cor-

responding eigenvalues λ1, λ2, . . . , λn. Then Api = λipi and reversing the above steps

AP = [Ap1, Ap2, . . . , Apn] = [λ1p1, λ2p2, . . . λnpn] = P D.

Thus, AP = DP . Since the pi are linearly independent, P is invertible and hence A =
P −1DP . Thus, A is diagonalizable.

It follows from the proof of the theorem that if A is diagonalizable and has eigenvalue
λ with multiplicity k, then there are k linearly independent eigenvectors associated with λ.

A matrix P is orthogonal if it is invertible and P −1 = P T . A matrix A is orthogonally
diagonalizable if there exists an orthogonal matrix P such that P −1AP = D is diagonal.
If A is orthogonally diagonalizable, then A = P DP T and AP = P D. Thus, the columns
of P are the eigenvectors of A and the diagonal elements of D are the corresponding

383

eigenvalues.

If P is an orthogonal matrix, then P T AP and A are both representations of the same
linear transformation with respect to diﬀerent bases. To see this, note that if e1, e2, . . . , en
is the standard basis, then aij is the component of Aej along the direction ei, namely,
T Aej. Thus, A deﬁnes a linear transformation by specifying the image under the
aij = ei
transformation of each basis vector. Denote by pj the jth column of P . It is easy to see that
(P T AP )ij is the component of Apj along the direction pi, namely, (P T AP )ij = pi
T Apj.
Since P is orthogonal, the pj form a basis of the space and so P T AP represents the same
linear transformation as A, but in the basis p1, p2, . . . , pn.

Another remark is in order. Check that

A = P DP T =

n
(cid:88)

i=1

diipipi

T .

Compare this with the singular value decomposition where

A =

n
(cid:88)

i=1

σiuivi

T ,

the only diﬀerence being that ui and vi can be diﬀerent and indeed if A is not square,
they will certainly be.

11.5.2 Symmetric Matrices

For an arbitrary matrix, some of the eigenvalues may be complex. However, for a
symmetric matrix with real entries, all eigenvalues are real. The number of eigenvalues
of a symmetric matrix, counting multiplicities, equals the dimension of the matrix. The
set of eigenvectors associated with a given eigenvalue form a vector space. For a non-
symmetric matrix, the dimension of this space may be less than the multiplicity of the
eigenvalue. Thus, a nonsymmetric matrix may not be diagonalizable. However, for a
symmetric matrix the eigenvectors associated with a given eigenvalue form a vector space
of dimension equal to the multiplicity of the eigenvalue. Thus, all symmetric matrices are
diagonalizable. The above facts for symmetric matrices are summarized in the following
theorem.

Theorem 11.7 (Real Spectral Theorem) Let A be a real symmetric matrix. Then

1. The eigenvalues, λ1, λ2, . . . , λn, are real, as are the components of the corresponding

eigenvectors, v1, v2, . . . , vn.

2. (Spectral Decomposition) A is orthogonally diagonalizable and indeed

A = V DV T =

n
(cid:88)

i=1

λivivi

T ,

384

where V is the matrix with columns v1, v2, . . . , vn, |vi| = 1 and D is a diagonal
matrix with entries λ1, λ2, . . . , λn.

Proof: Avi = λivi and vi
pose. Then

cAvi = λivi

cvi. Here the c superscript means conjugate trans-

λi = vi

cAvi = (vi

cAvi)cc = (vi

cAcvi)c = (vi

cAvi)c = λc
i

and hence λi is real.

Since λi is real, a nontrivial solution to (A − λiI) x = 0 has real components.

Let P be a real symmetric matrix such that P v1 = e1 where e1 = (1, 0, 0, . . . , 0)T and

P −1 = P T . We will construct such a P shortly. Since Av1 = λ1v1,

P AP T e1 = P Av1 = λP v1 = λ1e1.

The condition P AP T e1 = λ1e1 plus symmetry implies that P AP T =

(cid:19)

(cid:18) λ1 0
0 A(cid:48)

where

A(cid:48) is n − 1 by n − 1 and symmetric. By induction, A(cid:48) is orthogonally diagonalizable. Let
Q be the orthogonal matrix with QA(cid:48)QT = D(cid:48), a diagonal matrix. Q is (n − 1) × (n − 1).
Augment Q to an n × n matrix by putting 1 in the (1, 1) position and 0 elsewhere in the
ﬁrst row and column. Call the resulting matrix R. R is orthogonal too.

(cid:18) λ1 0
0 A(cid:48)

R

(cid:19)

RT =

(cid:19)

(cid:18) λ1 0
0 D(cid:48)

=⇒ RP AP T RT =

(cid:18) λ1 0
0 D(cid:48)

(cid:19)

.

Since the product of two orthogonal matrices is orthogonal, this ﬁnishes the proof of (2)
except it remains to construct P . For this, take an orthonormal basis of space containing
v1. Suppose the basis is {v1, w2, w3, . . .} and V is the matrix with these basis vectors as
its columns. Then P = V T will do.

Theorem 11.8 (The fundamental theorem of symmetric matrices) A real matrix
A is orthogonally diagonalizable if and only if A is symmetric.

Proof: (if ) Assume A is orthogonally diagonalizable. Then there exists P such that
D = P −1AP . Since P −1 = P T , we get

A = P DP −1 = P DP T

AT = (P DP T )T = P DP T = A

which implies

and hence A is symmetric.
(only if ) Already roved.

385

Note that a nonsymmetric matrix may not be diagonalizable, it may have eigenvalues
that are not real, and the number of linearly independent eigenvectors corresponding to
an eigenvalue may be less than its multiplicity. For example, the matrix









1 1 0
0 1 1
1 0 1

has eigenvalues 2, 1

√
3
2 . The matrix
(1 − λ)2 = 0 and thus has eigenvalue 1 with multiplicity 2 but has only one linearly

has characteristic equation

2 , and 1

2 − i

2 + i

√

3

(cid:19)

(cid:18) 1 2
0 1

independent eigenvector associated with the eigenvalue 1, namely x = c

Neither of these situations is possible for a symmetric matrix.

(cid:19)

(cid:18) 1
0

c (cid:54)= 0.

11.5.3 Relationship between SVD and Eigen Decomposition

The singular value decomposition exists for any n × d matrix whereas the eigenvalue
decomposition exists only for certain square matrices. For symmetric matrices the de-
compositions are essentially the same.

E and singular value decomposition A = USDSV T

The singular values of a matrix are always positive since they are the sum of squares
of the projection of a row of a matrix onto a singular vector. Given a symmetric matrix,
the eigenvalues can be positive or negative. If A is a symmetric matrix with eigenvalue
decomposition A = VEDEV T
S , what is
the relationship between DE and DS, and between VE and VS, and between US and VE?
Observe that if A can be expressed as QDQT where Q is orthonormal and D is diagonal,
then AQ = QD. That is, each column of Q is an eigenvector and the elements of D
are the eigenvalues. Thus, if the eigenvalues of A are distinct, then Q is unique up to
a permutation of columns. If an eigenvalue has multiplicity k, then the space spanned
In the following we will use the term essentially unique to
the k columns is unique.
capture this situation. Now AAT = USD2
SU T
S . By an argument
similar to the one above, US and VS are essentially unique and are the eigenvectors or
negatives of the eigenvectors of A and AT . The eigenvalues of AAT or AT A are the squares
of the eigenvalues of A. If A is not positive semi deﬁnite and has negative eigenvalues,
then in the singular value decomposition A = USDSVS, some of the left singular vectors
are the negatives of the eigenvectors. Let S be a diagonal matrix with ±1(cid:48)s on the
diagonal depending on whether the corresponding eigenvalue is positive or negative. Then
A = (USS)(SDS)VS where USS = VE and SDS = DE.

S and AT A = VSD2

SV T

11.5.4 Extremal Properties of Eigenvalues

In this section we derive a min max characterization of eigenvalues that implies that
the largest eigenvalue of a symmetric matrix A has a value equal to the maximum of

386

xT Ax over all vectors x of unit length. That is, the largest eigenvalue of A equals the
2-norm of A. If A is a real symmetric matrix there exists an orthogonal matrix P that
diagonalizes A. Thus

P T AP = D
where D is a diagonal matrix with the eigenvalues of A, λ1 ≥ λ2 ≥ · · · ≥ λn, on its
diagonal. Rather than working with A, it is easier to work with the diagonal matrix D.
This will be an important technique that will simplify many proofs.

Consider maximizing xT Ax subject to the conditions

1.

n
(cid:80)
i=1

x2
i = 1

2. rT

i x = 0,

1 ≤ i ≤ s

where the ri are any set of nonzero vectors. We ask over all possible sets {ri|1 ≤ i ≤ s}
of s vectors, what is the minimum value assumed by this maximum.

Theorem 11.9 (Min max theorem) For a symmetric matrix A, min
r1,...,rs

(xtAx) =

max
x
ri⊥x

λs+1 where the minimum is over all sets {r1, r2, . . . , rs} of s nonzero vectors and the
maximum is over all unit vectors x orthogonal to the s nonzero vectors.

Proof: A is orthogonally diagonalizable. Let P satisfy P T P = I and P T AP = D, D
diagonal. Let y = P T x. Then x = P y and

xT Ax = yT P T AP y = yT Dy =

n
(cid:88)

i=1

λiy2
i

i = 1 is equivalent to maximizing

Since there is a one-to-one correspondence between unit vectors x and y, maximizing
xT Ax subject to (cid:80) x2

n
(cid:80)
i=1
λiy2
i at λ1. Then x = P y is the ﬁrst
column of P and is the ﬁrst eigenvector of A. Similarly λn is the minimum value of xT Ax
subject to the same conditions.

λ1 ≥ λi, 2 ≤ i ≤ n, y = (1, 0, . . . , 0) maximizes

i subject to (cid:80) y2

i = 1. Since

n
(cid:80)
i=1

λiy2

Now consider maximizing xT Ax subject to the conditions
1. (cid:80) x2

i = 1

2. rT

i x = 0

where the ri are any set of nonzero vectors. We ask over all possible choices of s vectors
what is the minimum value assumed by this maximum.

As above, we may work with y. The conditions are

min
r1,...,rs

max
x
rT
i x=0

xT Ax

387

1. (cid:80) y2

i = 1

2. qT

i y = 0 where, qT

i = rT

i P

Consider any choice for the vectors r1, r2, . . . , rs. This gives a corresponding set of qi. The
yi therefore satisfy s linear homogeneous equations. If we add ys+2 = ys+3 = · · · yn = 0
we have n − 1 homogeneous equations in n unknowns y1, . . . , yn. There is at least one
solution that can be normalized so that (cid:80) y2

i = 1. With this choice of y

yT Dy =

(cid:88)

λiy2

i ≥λs+1

since coeﬃcients greater than or equal to s + 1 are zero. Thus, for any choice of ri there
will be a y such that

and hence

(yT P T AP y) ≥ λs+1

max
y
rT
i y=0

min
r1,r2,...,rs

(yT P T AP y) ≥ λs+1.

max
y
rT
i y=0

However, there is a set of s constraints for which the minimum is less than or equal to
λs+1. Fix the relations to be yi = 0, 1 ≤ i ≤ s. There are s equations in n unknowns
and for any y subject to these relations

yT Dy =

n
(cid:88)

s+1

λiy2

i ≤ λs+1.

Combining the two inequalities, min max yT Dy = λs+1.

The above theorem tells us that the maximum of xT Ax subject to the constraint that
|x|2 = 1 is λ1. Consider the problem of maximizing xT Ax subject to the additional re-
striction that x is orthogonal to the ﬁrst eigenvector. This is equivalent to maximizing
ytP tAP y subject to y being orthogonal to (1,0,. . . ,0), i.e. the ﬁrst component of y being
0. This maximum is clearly λ2 and occurs for y = (0, 1, 0, . . . , 0). The corresponding x is
the second column of P or the second eigenvector of A.

Similarly the maximum of xT Ax for p1

T x = p2

T x = · · · ps

T x = 0 is λs+1 and is

obtained for x = ps+1.

11.5.5 Eigenvalues of the Sum of Two Symmetric Matrices

The min max theorem is useful in proving many other results. The following theorem
shows how adding a matrix B to a matrix A changes the eigenvalues of A. The theorem
is useful for determining the eﬀect of a small perturbation on the eigenvalues of A.

388

Theorem 11.10 Let A and B be n × n symmetric matrices. Let C=A+B. Let αi, βi,
and γi denote the eigenvalues of A, B, and C respectively, where α1 ≥ α2 ≥ . . . αn and
similarly for βi, γi. Then αs + β1 ≥ γs ≥ αs + βn.

Proof: By the min max theorem we have

αs = min

r1,...,rs−1

(xT Ax).

max
x
ri⊥x

Suppose r1, r2, . . . , rs−1 attain the minimum in the expression. Then using the min max
theorem on C,

(cid:0)xT (A + B)x(cid:1)

γs ≤

≤

max
x⊥r1,r2,...rs−1
max
x⊥r1,r2,...rs−1

(xT Ax) +

max
x⊥r1,r2,...rs−1

(xT Bx)

≤ αs + max

x

(xT Bx) ≤ αs + β1.

Therefore, γs ≤ αs + β1.

An application of the result to A = C + (−B), gives αs ≤ γs − βn. The eigenvalues
of -B are minus the eigenvalues of B and thus −βn is the largest eigenvalue. Hence
γs ≥ αs + βn and combining inequalities yields αs + β1 ≥ γs ≥ αs + βn.

Lemma 11.11 Let A and B be n × n symmetric matrices. Let C=A+B. Let αi, βi,
and γi denote the eigenvalues of A, B, and C respectively, where α1 ≥ α2 ≥ . . . αn and
similarly for βi, γi. Then γr+s−1 ≤ αr + βs.

Proof: There is a set of r−1 relations such that over all x satisfying the r−1 relationships

And a set of s − 1 relations such that over all x satisfying the s − 1 relationships

max(xT Ax) = αr.

max(xT Bx) = βs.

Consider x satisfying all these r + s − 2 relations. For any such x

xT Cx = xT Ax + xT Bxx ≤ αr + βs

and hence over all the x

max(xT Cx) ≤ αs + βr

Taking the minimum over all sets of r + s − 2 relations

γr+s−1 = min max(xT Cx) ≤ αr + βs

389

11.5.6 Norms

T xj = 0 for i (cid:54)= j and is orthonormal if
A set of vectors {x1, . . . , xn} is orthogonal if xi
in addition |xi| = 1 for all i. A matrix A is orthonormal if AT A = I. If A is a square
orthonormal matrix, then rows as well as columns are orthogonal. In other words, if A
is square orthonormal, then AT is also. In the case of matrices over the complexes, the
concept of an orthonormal matrix is replaced by that of a unitary matrix. A∗ is the con-
jugate transpose of A if a∗
ij is the complex
conjugate of the ijth element of A. A matrix A over the ﬁeld of complex numbers is
unitary if AA∗ = I.

ij is the ijth entry of A∗ and ¯a∗

ij = ¯aji where a∗

Norms

A norm on Rn is a function f : Rn → R satisfying the following three axioms:

1. f (x) ≥ 0,

2. f (x + y) ≤ f (x) + f (y), and

3. f (αx) = |α|f (x).

A norm on a vector space provides a distance function where

distance(x, y) = norm(x − y).

An important class of norms for vectors is the p-norms deﬁned for p > 0 by

|x|p = (|x1|p + · · · + |xn|p)

1
p .

Important special cases are

|x|0 the number of non zero entries
|x|1 = |x1| + · · · + |xn|
|x|2 = (cid:112)|x1|2 + · · · + |xn|2
|x|∞ = max |xi|.

Lemma 11.12 For any 1 ≤ p < q, |x|q ≤ |x|p.

Proof:

|x|q

q =

(cid:88)

|xi|q.

i

Let ai = |xi|q and ρ = p/q. Using Jensen’s inequality (see Section 11.3) that for any
nonnegative reals a1, a2, . . . , an and any ρ ∈ (0, 1), we have ((cid:80)n
i , the
lemma is proved.

i=1 ai)ρ ≤ (cid:80)n

i=1 aρ

390

There are two important matrix norms, the matrix p-norm

and the Frobenius norm

||A||p = max
|x|=1

(cid:107)Ax(cid:107)p

||A||F =

(cid:115)(cid:88)

a2
ij.

ij

Let ai be the ith column of A. Then (cid:107)A(cid:107)2

F = (cid:80)
F = tr (cid:0)AAT (cid:1). Thus, (cid:107)A(cid:107)2

i

T ai = tr (cid:0)AT A(cid:1). A similar argument

ai
F = tr (cid:0)AT A(cid:1) = tr (cid:0)AAT (cid:1).

on the rows yields (cid:107)A(cid:107)2
If A is symmetric and rank k

||A||2

2 ≤ ||A||2

F ≤ k ||A||2
2 .

11.5.7 Important Norms and Their Properties

Lemma 11.13 ||AB||2 ≤ ||A||2 ||B||2

Proof: ||AB||2 = max
|x|=1
let z = By. Then

|ABx|. Let y be the value of x that achieves the maximum and

||AB||2 = |ABy| = |Az| =

(cid:12)
(cid:12)
(cid:12)
(cid:12)

A

z
|z|

(cid:12)
(cid:12)
(cid:12)
(cid:12)

|z|

But

(cid:12)
(cid:12)
(cid:12)A z

|z|

(cid:12)
(cid:12)
(cid:12) ≤ max

|x|=1

|Ax| = ||A||2 and |z| ≤ max
|x|=1

|Bx| = ||B||2. Thus ||AB||2 ≤ ||A||2 ||B||2.

Let Q be an orthonormal matrix.

Lemma 11.14 For all x,

|Qx| = |x|.

Proof: |Qx|2

2 = xT QT Qx = xT x = |x|2
2.

Lemma 11.15 ||QA||2 = ||A||2

Proof: For all x,

|Qx| = |x|. Replacing x by Ax, |QAx| = |Ax| and thus max
|x|=1

|QAx| =

max
|x|=1

|Ax|

Lemma 11.16 ||AB||2

F ≤ ||A||2

F ||B||2

F

Proof: Let ai be the ith column of A and let bj be the jth column of B. By the
Cauchy-Schwartz inequality (cid:13)
2 ≤

(cid:13)
(cid:13) ≤ (cid:107)ai(cid:107) (cid:107)bj(cid:107). Thus ||AB||2

F = (cid:80)

(cid:12)
(cid:12)ai

T bj

T bj

(cid:13)ai

(cid:12)
(cid:12)

(cid:80)
j

i

(cid:80)
i

(cid:80)
j

(cid:107)ai(cid:107)2 (cid:107)bj(cid:107)2 = (cid:80)

(cid:107)ai(cid:107)2 (cid:80)

i

j

(cid:107)bj(cid:107)2 = ||A||2

F ||B||2

F

391

Lemma 11.17 ||QA||F = ||A||F
Proof: ||QA||2

F = Tr(AT QT QA) = Tr(AT A) = ||A||2
F .

Lemma 11.18 For real, symmetric matrix A with eigenvalues λ1 ≥ λ2 ≥ . . ., (cid:107)A(cid:107)2
2 + · · · + λ2
max(λ2
n

n) and (cid:107)A(cid:107)2

1 + λ2

1, λ2

F = λ2

2 =

Proof: Suppose the spectral decomposition of A is P DP T , where P is an orthogo-
nal matrix and D is diagonal. We saw that ||P T A||2 = ||A||2. Applying this again,
||P T AP ||2 = ||A||2. But, P T AP = D and clearly for a diagonal matrix D, ||D||2 is the
largest absolute value diagonal entry from which the ﬁrst equation follows. The proof of
the second is analogous.

If A is real and symmetric and of rank k then ||A||2

2 ≤ ||A||2

F ≤ k ||A||2

2

Theorem 11.19 ||A||2

2 ≤ ||A||2
Proof: It is obvious for diagonal matrices that ||D||2
2. Let D =
QtAQ where Q is orthonormal. The result follows immediately since for Q orthonormal,
||QA||2 = ||A||2 and ||QA||F = ||A||F .

F ≤ k ||D||2

F ≤ k ||A||2

2 ≤ ||D||2

2

Real and symmetric are necessary for some of these theorems. This condition was
needed to express Σ = QT AQ. For example, in Theorem 11.19 suppose A is the n × n
matrix



A =






1 1
1 1
...
...
1 1



0

.






||A||2 = 2 and ||A||F =

2n. But A is rank 2 and ||A||F > 2 ||A||2 for n > 8.

√

Lemma 11.20 Let A be a symmetric matrix. Then (cid:107)A(cid:107)2 = max
|x|=1

(cid:12)xT Ax(cid:12)
(cid:12)
(cid:12).

Proof: By deﬁnition, the 2-norm of A is (cid:107)A(cid:107)2 = max
|x|=1

|Ax|. Thus,

(cid:107)A(cid:107)2 = max
|x|=1

|Ax| = max
|x|=1

√

xT AT Ax = (cid:112)λ2

1 = λ1 = max
|x|=1

(cid:12)xT Ax(cid:12)
(cid:12)
(cid:12)

The two norm of a matrix A is greater than or equal to the 2-norm of any of its

columns. Let au be a column of A.

Lemma 11.21 |au| ≤ (cid:107)A(cid:107)2

Proof: Let eu be the unit vector with a 1 in position u and all other entries zero. Note
λ = max
|x|=1

|Ax|. Let x = eu where au is row u. Then |au| = |Aeu| ≤ max
|x|=1

|Ax| = λ

392

11.5.8 Linear Algebra

Lemma 11.22 Let A be an n × n symmetric matrix. Then det(A) = λ1λ2 · · · λn.

Proof: The det (A − λI) is a polynomial in λ of degree n. The coeﬃcient of λn will be ±1
depending on whether n is odd or even. Let the roots of this polynomial be λ1, λ2, . . . , λn.
Then det(A − λI) = (−1)n

(λ − λi). Thus

n
(cid:81)
i=1

det(A) = det(A − λI)|λ=0 = (−1)n

n
(cid:89)

i=1

(cid:12)
(cid:12)
(cid:12)
(λ − λi)
(cid:12)
(cid:12)λ=0

= λ1λ2 · · · λn

The trace of a matrix is deﬁned to be the sum of its diagonal elements. That is,

tr (A) = a11 + a22 + · · · + ann.

Lemma 11.23 tr(A) = λ1 + λ2 + · · · + λn.

Proof: Consider the coeﬃcient of λn−1 in det(A − λI) = (−1)n

n
(cid:81)
i=1

(λ − λi). Write

A − λI =






a11 − λ a12
a21
...

· · ·
a22 − λ · · ·
...

...




 .

Calculate det(A − λI) by expanding along the ﬁrst row. Each term in the expansion
involves a determinant of size n − 1 which is a polynomial in λ of deg n − 2 except for
the principal minor which is of deg n − 1. Thus the term of deg n − 1 comes from

and has coeﬃcient (−1)n−1 (a11 + a22 + · · · + ann). Now

(a11 − λ) (a22 − λ) · · · (ann − λ)

(−1)n

n
(cid:89)

i=1

(λ − λi) = (−1)n (λ − λ1)(λ − λ2) · · · (λ − λn)

= (−1)n (cid:16)

λn − (λ1 + λ2 + · · · + λn)λn−1 + · · ·

(cid:17)

Therefore equating coeﬃcients λ1 + λ2 + · · · + λn = a11 + a22 + · · · + ann = tr(A)

Note that (tr(A))2 (cid:54)= tr(A2). For example A =

(cid:18) 1 0
0 2
has trace 5 (cid:54)=9. However tr(A2) = λ2
n. To see this, observe that A2 =
(V T DV )2 = V T D2V . Thus, the eigenvalues of A2 are the squares of the eigenvalues for
A.

(cid:18) 1 0
0 4

has trace 3, A2 =

2 + · · · + λ2

1 + λ2

(cid:19)

(cid:19)

393

Alternative proof that tr(A) = λ1 + λ2 + · · ·+ λn. Suppose the spectral decomposition

of A is A = P DP T . We have

tr (A) = tr (cid:0)P DP T (cid:1) = tr (cid:0)DP T P (cid:1) = tr (D) = λ1 + λ2 + · · · + λn.

Lemma 11.24 If A is n × m and B is a m × n matrix, then tr(AB)=tr(BA).

tr(AB) =

n
(cid:88)

n
(cid:88)

aijbji =

n
(cid:88)

n
(cid:88)

i=1

j=1

j=1

i=1

bjiaij = tr (BA)

Pseudo inverse

Let A be an n × m rank r matrix and let A = U ΣV T be the singular value decompo-
(cid:17)
where σ1, . . . , σr are the nonzero singular
It is the unique X that

sition of A. Let Σ(cid:48) = diag
values of A. Then A(cid:48) = V Σ(cid:48)U T is the pseudo inverse of A.
minimizes (cid:107)AX − I(cid:107)F .
Second eigenvector

, . . . , 1
σr

, 0, . . . , 0

(cid:16) 1
σ1

Suppose the eigenvalues of a matrix are λ1 ≥ λ2 ≥ · · · . The second eigenvalue,
λ2, plays an important role for matrices representing graphs. It may be the case that
|λn| > |λ2|.

Why is the second eigenvalue so important? Consider partitioning the vertices of a
regular degree d graph G = (V, E) into two blocks of equal size so as to minimize the
number of edges between the two blocks. Assign value +1 to the vertices in one block and
-1 to the vertices in the other block. Let x be the vector whose components are the ±1
values assigned to the vertices. If two vertices, i and j, are in the same block, then xi and
xj are both +1 or both –1 and (xi −xj)2 = 0. If vertices i and j are in diﬀerent blocks then
(xi − xj)2 = 4. Thus, partitioning the vertices into two blocks so as to minimize the edges
between vertices in diﬀerent blocks is equivalent to ﬁnding a vector x with coordinates
±1 of which half of its coordinates are +1 and half of which are –1 that minimizes

Ecut =

1
4

(cid:88)

(i,j)∈E

(xi − xj)2

Let A be the adjacency matrix of G. Then

xT Ax = (cid:80)

aijxixj = 2 (cid:80)
(cid:18) number of edges

ij

edges

xixj
(cid:19)

= 2 ×

= 2 ×

within components

(cid:18) total number
of edges

(cid:19)

− 4 ×

(cid:18) number of edges

(cid:19)

− 2 ×
(cid:18) number of edges

between components

(cid:19)

between components

394

Maximizing xT Ax over all x whose coordinates are ±1 and half of whose coordinates are
+1 is equivalent to minimizing the number of edges between components.

Since ﬁnding such an x is computational diﬃcult, replace the integer condition on the
components of x and the condition that half of the components are positive and half of the

components are negative with the conditions

x2
i = 1 and

xi = 0. Then ﬁnding the

n
(cid:80)
i=1

n
(cid:80)
i=1

optimal x gives us the second eigenvalue since it is easy to see that the ﬁrst eigenvector
Is along 1

λ2 = max
x⊥v1

xT Ax
(cid:80) x2

i

Actually we should use
(cid:18) total number
of edges

2 ×

(cid:19)

n
(cid:80)
i=1

− 4 ×

n
(cid:80)
i=1

x2
x2
i = 1. Thus nλ2 must be greater than
i = n not
(cid:18) number of edges

(cid:19)

since the maximum is taken over

between components

a larger set of x. The fact that λ2 gives us a bound on the minimum number of cross
edges is what makes it so important.

11.5.9 Distance between subspaces

Suppose S1 and S2 are two subspaces. Choose a basis of S1 and arrange the basis
vectors as the columns of a matrix X1; similarly choose a basis of S2 and arrange the
basis vectors as the columns of a matrix X2. Note that S1 and S2 can have diﬀerent
dimensions. Deﬁne the square of the distance between two subspaces by

dist2(S1, S2) = dist2(X1, X2) = ||X1 − X2X T

2 X1||2
F

Since X1 − X2X T

2 X1 and X2X T
F = (cid:13)

(cid:107)X1(cid:107)2

2 X1 are orthogonal
(cid:13)
F + (cid:13)
2
(cid:13)

(cid:13)X1 − X2X T

2 X1

(cid:13)X2X T

2 X1

(cid:13)
2
(cid:13)
F

and hence

dist2 (X1, X2) = (cid:107)X1(cid:107)2

F − (cid:13)

(cid:13)X2X T

2 X1

(cid:13)
2
F .
(cid:13)

Intuitively, the distance between X1 and X2 is the Frobenius norm of the component of
X1 not in the space spanned by the columns of X2.

If X1 and X2 are 1-dimensional unit length vectors, dist2 (X1, X2) is the sin squared

of the angle between the spaces.

Example: Consider two subspaces in four dimensions








X1 =

1√
2

0
1√
2

0

X2 =







1 0
0 1
0 0
0 0














0
1√
3
1√
3
1√
3

395

Here

dist2 (X1, X2) =

=














(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)

1√
2

0
1√
2

0

0
0
1√
2

0

1√
2

0
1√
2

0

0
1√
3
1√
3
1√
3








(cid:13)
2
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
F







1 0
0 1
0 0
0 0







(cid:18) 1 0 0 0
0 1 0 0

(cid:19)








=

7
6

0
1√
3
1√
3
1√
3

0
0
1√
3
1√
3














−

2
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
(cid:13)
F

In essence, we projected each column vector of X1 onto X2 and computed the Frobenius
norm of X1 minus the projection. The Frobenius norm of each column is the sin squared
of the angle between the original column of X1 and the space spanned by the columns of
X2.

11.6 Generating Functions

A sequence a0, a1, . . ., can be represented by a generating function g(x) =

∞
(cid:80)
i=0

aixi. The

advantage of the generating function is that it captures the entire sequence in a closed
form that can be manipulated as an entity. For example, if g(x) is the generating func-
tion for the sequence a0, a1, . . ., then x d
dx g(x) is the generating function for the sequence
0, a1, 2a2, 3a3, . . . and x2g(cid:48)(cid:48)(x) + xg(cid:48)(x) is the generating function for the sequence for
0, a1, 4a2, 9a3, . . .

Example: The generating function for the sequence 1, 1, . . . is

ating function for the sequence 0, 1, 2, 3, . . . is

∞
(cid:80)
i=0

xi = 1

1−x . The gener-

∞
(cid:80)
i=0

ixi =

∞
(cid:80)
i=0

dx xi = x d
x d

dx

∞
(cid:80)
i=0

xi = x d
dx

1

1−x = x

(1−x)2 .

Example: If A can be selected 0 or 1 times and B can be selected 0, 1, or 2 times and C
can be selected 0, 1, 2, or 3 times, in how many ways can ﬁve objects be selected. Consider
the generating function for the number of ways to select objects. The generating function
for the number of ways of selecting objects, selecting only A’s is 1+x, only B’s is 1+x+x2,
and only C’s is 1 + x + x2 + x3. The generating function when selecting A’s, B’s, and C’s
is the product.

(1 + x)(1 + x + x2)(1 + x + x2 + x3) = 1 + 3x + 5x2 + 6x3 + 5x4 + 3x5 + x6

The coeﬃcient of x5 is 3 and hence we can select ﬁve objects in three ways: ABBCC,
ABCCC, or BBCCC.

396

The generating functions for the sum of random variables

Let f (x) =

∞
(cid:80)
i=0

pixi be the generating function for an integer valued random variable

where pi is the probability that the random variable takes on value i. Let g(x) =

be the generating function of an independent integer valued random variable where qi
is the probability that the random variable takes on the value i. The sum of these two
random variables has the generating function f (x)g(x). This is because the coeﬃcient of
xi in the product f (x)g(x) is (cid:80)i
k=0 pkqk−i and this is also the probability that the sum of
the random variables is i. Repeating this, the generating function of a sum of independent
nonnegative integer valued random variables is the product of their generating functions.

∞
(cid:80)
i=0

qixi

11.6.1 Generating Functions for Sequences Deﬁned by Recurrence Relation-

ships

Consider the Fibonacci sequence

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, . . .

deﬁned by the recurrence relationship

f0 = 0

f1 = 1

fi = fi−1 + fi−2

i ≥ 2

Multiply each side of the recurrence by xi and sum from i equals two to inﬁnity.

∞
(cid:88)

i=2

fixi =

∞
(cid:88)

i=2

fi−1xi +

∞
(cid:88)

i=2

fi−2xi

f2x2 + f3x3 + · · · = f1x2 + f2x3 + · · · + f0x2 + f1x3 + · · ·

= x (cid:0)f1x + f2x2 + · · ·(cid:1) + x2 (f0 + f1x + · · ·)

(11.1)

Let

f (x) =

∞
(cid:88)

i=0

fixi.

(11.2)

Substituting (11.2) into (11.1) yields

f (x) − f0 − f1x = x (f (x) − f0) + x2f (x)
f (x) − x = xf (x) + x2f (x)
f (x)(1 − x − x2) = x

Thus, f (x) = x

1−x−x2 is the generating function for the Fibonacci sequence.

397

Note that generating functions are formal manipulations and do not necessarily con-
verge outside some region of convergence. Consider the generating function f (x) =
∞
(cid:80)
i=0

1−x−x2 for the Fibonacci sequence. Using

fixi = x

∞
(cid:80)
i=0

fixi,

and using f (x) = x

1−x−x2

Asymptotic behavior

f (1) = f0 + f1 + f2 + · · · = ∞

f (1) =

1
1 − 1 − 1

= −1.

To determine the asymptotic behavior of the Fibonacci sequence write

f (x) =

x
1 − x − x2 =

√

5
5
1 − φ1x

+

√

−

5
5
1 − φ2x

√
where φ1 = 1+
2
1 − x − x2 = 0.

5

√
and φ1 = 1−
2

5

are the reciprocals of the two roots of the quadratic

Then

Thus,

f (x) =

√

5
5

1 + φ1x + (φ1x)2 + · · · − (cid:0)1 + φ2x + (φ2x)2 + · · ·(cid:1)(cid:17)
(cid:16)

.

fn =

1 − φn

2 ) .

(φn
√

√

5
5
∼=

5 φn
Since φ2 < 1 and φ1 > 1, for large n, fn
integer and φ2 < 1, it must be the case that fn =
all n.
Means and standard deviations of sequences

5

√

1 . In fact, since fn =
√
5
2 φn

5 (φn
. Hence fn =

(cid:106)
fn +

1 − φn
2 ) is an
(cid:107)
(cid:106) √
5
5 φn
for

(cid:107)

2

1

5

Generating functions are useful for calculating the mean and standard deviation of a
sequence. Let z be an integral valued random variable where pi is the probability that
pixi be the
z equals i. The expected value of z is given by m =

ipi. Let p(x) =

∞
(cid:80)
i=0

∞
(cid:80)
i=0

generating function for the sequence p1, p2, . . .. The generating function for the sequence
p1, 2p2, 3p3, . . . is

x

d
dx

p(x) =

∞
(cid:88)

i=0

ipixi.

Thus, the expected value of the random variable z is m = xp(cid:48)(x)|x=1 = p(cid:48)(1). If p was not
a probability function, its average value would be p(cid:48)(1)
p(1) since we would need to normalize
the area under p to one.

398

The second moment of z, is E(z2) − E2(z) and can be obtained as follows.

x2 d
dx

(cid:12)
(cid:12)
p(x)
(cid:12)
(cid:12)x=1

=

=

∞
(cid:88)

i=0
∞
(cid:88)

i=0

(cid:12)
(cid:12)
i(i − 1)xip(x)
(cid:12)
(cid:12)
(cid:12)x=1
∞
(cid:88)

i2xip(x)

−

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)x=1

i=0

ixip(x)

(cid:12)
(cid:12)
(cid:12)
(cid:12)
(cid:12)x=1

= E(z2) − E(z).

Thus, σ2 = E(z2) − E2(z) = E(z2) − E(z) + E(z) − E2(z) = p”(1) + p(cid:48)(1) − (cid:0)p(cid:48)(1)(cid:1)2.

11.6.2 The Exponential Generating Function and the Moment Generating

Function

Besides the ordinary generating function there are a number of other types of gener-
ating functions. One of these is the exponential generating function. Given a sequence

a0, a1, . . . , the associated exponential generating function is g(x) =

Moment generating functions

∞
(cid:80)
i=0

ai

xi
i! .

The kth moment of a random variable x around the point b is given by E((x − b)k).
Usually the word moment is used to denote the moment around the value 0 or around
the mean. In the following, we use moment to mean the moment about the origin.

The moment generating function of a random variable x is deﬁned by

Ψ(t) = E(etx) =

∞
(cid:90)

−∞

etxp(x)dx

Replacing etx by its power series expansion 1 + tx + (tx)2

2!

· · · gives

Ψ(t) =

∞
(cid:90)

(cid:32)

−∞

1 + tx +

(tx)2
2!

(cid:33)

+ · · ·

p(x)dx

Thus, the kth moment of x about the origin is k! times the coeﬃcient of tk in the power
series expansion of the moment generating function. Hence, the moment generating func-
tion is the exponential generating function for the sequence of moments about the origin.

The moment generating function transforms the probability distribution p(x) into a
function Ψ (t) of t. Note Ψ(0) = 1 and is the area or integral of p(x). The moment
generating function is closely related to the characteristic function which is obtained by
replacing etx by eitx in the above integral where i =
−1 and is related to the Fourier

√

399

transform which is obtained by replacing etx by e−itx.

Ψ(t) is closely related to the Fourier transform and its properties are essentially the
same. In particular, p(x) can be uniquely recovered by an inverse transform from Ψ(t).
mi
i! ti converges abso-

More speciﬁcally, if all the moments mi are ﬁnite and the sum

∞
(cid:80)
i=0

lutely in a region around the origin, then p(x) is uniquely determined.

The Gaussian probability distribution with zero mean and unit variance is given by

p (x) = 1√
2π

e− x2

2 . Its moments are given by

∞
(cid:90)

xne− x2

2 dx

un =

=

1
√
2π

−∞
(cid:40) n!
n
2 ( n
2
0

2 )!

n even

n odd

To derive the above, use integration by parts to get un = (n − 1) un−2 and combine
2 and v = xn−1. Then

this with u0 = 1 and u1 = 0. The steps are as follows. Let u = e− x2
u(cid:48) = −xe− x2

2 and v(cid:48) = (n − 1) xn−2. Now uv = (cid:82) u(cid:48)v+ (cid:82) uv(cid:48) or

e− x2

2 xn−1 =

(cid:90)

xne− x2

2 dx +

(cid:90)

(n − 1) xn−2e− x2

2 dx.

From which

−∞
Thus, un = (n − 1) un−2.

(cid:82) xne− x2
∞
xne− x2
(cid:82)

2 dx = (n − 1) (cid:82) xn−2e− x2

2 dx − e− x2

2 xn−1

2 dx = (n − 1)

xn−2e− x2

2 dx

∞
(cid:82)

−∞

The moment generating function is given by

g (s) =

∞
(cid:88)

n=0

unsn
n!

∞
(cid:88)

=

n=0
n even

n!
2 n
n
2 !

2

sn
n!

=

∞
(cid:88)

i=0

s2i
2ii!

=

∞
(cid:88)

i=0

(cid:18) s2
2

1
i!

(cid:19)i

= e

s2
2 .

For the general Gaussian, the moment generating function is

g (s) = esu+

(cid:16) σ2
2

(cid:17)

s2

Thus, given two independent Gaussians with mean u1 and u2 and variances σ2
the product of their moment generating functions is

1 and σ2
2,

es(u1+u2)+(σ2

1+σ2

2)s2

,

400

1 + σ2
the moment generating function for a Gaussian with mean u1 + u2 and variance σ2
2.
Thus, the convolution of two Gaussians is a Gaussian and the sum of two random vari-
ables that are both Gaussian is a Gaussian random variable.

11.7 Miscellaneous

11.7.1 Lagrange multipliers

Lagrange multipliers are used to convert a constrained optimization problem into an un-
constrained optimization. Suppose we wished to maximize a function f (x) subject to a
constraint g(x) = c. The value of f (x) along the constraint g(x) = c might increase for
a while and then start to decrease. At the point where f (x) stops increasing and starts
to decrease, the contour line for f (x) is tangent to the curve of the constraint g(x) = c.
Stated another way the gradient of f (x) and the gradient of g(x) are parallel.

By introducing a new variable λ we can express the condition by ∇xf = λ∇xg and

g = c. These two conditions hold if and only if

∇xλ

(cid:0)f (x) + λ (g (x) − c)(cid:1) = 0

The partial with respect to λ establishes that g(x) = c. We have converted the constrained
optimization problem in x to an unconstrained problem with variables x and λ.

11.7.2 Finite Fields

For a prime p and integer n there is a unique ﬁnite ﬁeld with pn elements. In Section
7.1.4 we used the ﬁeld GF(2n), which consists of polynomials of degree less than n with
coeﬃcients over the ﬁeld GF(2). In GF(28)

(x7 + x5 + x) + (x6 + x5 + x4) = x7 + x6 = x4 = x

Multiplication is modulo an irreducible polynomial. Thus

(x7 + x5 + x)(x6 + x5 + x4) = x13 + x12 + x11 + x11 + x10 + x9 + x7 + x6 + x5

= x13 + x12 + x10 + x9 + x7 + x6 + x5
= x6 + x4 + x3 + x2

mod x8 + x4 + x3 + x + 1

Division of x13 + x12 + x10 + x9 + x7 + x6 + x5 by x6 + x4 + x3 + x2 is illustrated below.

−x5(x8 + x4 + x3 + x2 + 1) = x13

x13 +x12 +x10 +x9
+x9

−x4(x8 + x4 + x3 + x2 + 1) =

−x2(x8 + x4 + x3 + x2 + 1) =

x12 +x10
x12

x10
x10

401

+x7 +x6 +x5
+x6 +x5

+x8
+x8 +x7
+x8 +x7

+x5 +x4
+x5
x4
x6 +x5
x6

x3
x2
+x4 +x3 +x2

11.7.3 Hash Functions

Universal Hash Families

ADD PARAGRAPH ON MOTIVATION integrate material with Chapter

Let M = {1, 2, . . . , m} and N = {1, 2, . . . , n} where m ≥ n. A family of hash functions
H = {h|h : M → N } is said to be 2-universal if for all x and y, x (cid:54)= y, and for h chosen
uniformly at random from H,

P rob [h (x) = h (y)] ≤

1
n

Note that if H is the set of all possible mappings from M to N , then H is 2-universal. In
fact P rob [h (x) = h (y)] = 1
n. The diﬃculty in letting H consist of all possible functions
is that a random h from H has no short representation. What we want is a small set H
where each h ∈ H has a short representation and is easy to compute.

Note that for a 2-universal H, for any two elements x and y, h(x) and h(y) behave as
independent random variables. For a random f and any set X the set {f (x) |x ∈ X} is
a set of independent random variables.

11.7.4 Application of Mean Value Theorem

The mean value theorem states that if f (x) is continuous and diﬀerentiable on the
interval [a, b], then there exists c, a ≤ c ≤ b such that f (cid:48)(c) = f (b)−f (a)
. That is, at some
point between a and b the derivative of f equals the slope of the line from f (a) to f (b).
See Figure 11.7.4.

b−a

f (x)

a

c

b

Figure 11.3: Illustration of the mean value theorem.

402

One application of the mean value theorem is with the Taylor expansion of a function.

The Taylor expansion about the origin of f (x) is

f (x) = f (0) + f (cid:48)(0)x +

1
2!
By the mean value theorem there exists c, 0 ≤ c ≤ x, such that f (cid:48)(c) = f (x)−f (0)
f (x) − f (0) = xf (cid:48)(c). Thus

f (cid:48)(cid:48)(cid:48)(0)x3 + · · ·

f (cid:48)(cid:48)(0)x2 +

1
3!

x

(11.3)

or

xf (cid:48)(c) = f (cid:48)(0)x +

1
2!

f (cid:48)(cid:48)(0)x2 +

1
3!

f (cid:48)(cid:48)(cid:48)(0)x3 + · · ·

and

f (x) = f (0) + xf (cid:48)(c).

One could apply the mean value theorem to f (cid:48)(x) in

f (cid:48)(x) = f (cid:48)(0) + f (cid:48)(cid:48)(0)x +

1
2!

f (cid:48)(cid:48)(cid:48)(0)x2 + · · ·

Then there exists d, 0 ≤ d ≤ x such that

xf (cid:48)(cid:48)(d) = f (cid:48)(cid:48)(0)x +

1
2!

f (cid:48)(cid:48)(cid:48)(0)x2 + · · ·

Integrating

1
2
Substituting into Eq(11.3)

x2f (cid:48)(cid:48)(d) =

1
2!

f (cid:48)(cid:48)(0)x +

1
3!

f (cid:48)(cid:48)(cid:48)(0)x3 + · · ·

f (x) = f (0) + f (cid:48)(0)x +

1
2

x2f (cid:48)(cid:48)(d).

11.7.5 Sperner’s Lemma

Consider a triangulation of a 2-dimensional simplex. Let the vertices of the simplex
be colored R, B, and G. If the vertices on each edge of the simplex are colored only with
the two colors at the endpoints then the triangulation must have a triangle whose ver-
tices are three diﬀerent colors. In fact, it must have an odd number of such vertices. A
generalization of the lemma to higher dimensions also holds.

Create a graph whose vertices correspond to the triangles of the triangulation plus an
additional vertex corresponding to the outside region. Connect two vertices of the graph
by an edge if the triangles corresponding to the two vertices share a common edge that
is color R and B. The edge of the original simplex must have an odd number of such
triangular edges. Thus, the outside vertex of the graph must be of odd degree. The graph
must have an even number of odd degree vertices. Each odd vertex is of degree 0, 1, or 2.
The vertices of odd degree, i.e. degree one, correspond to triangles which have all three
colors.

403

11.7.6 Pr¨ufer

Here we prove that the number of labeled trees with n vertices is nn−2. By a labeled
tree we mean a tree with n vertices and n distinct labels, each label assigned to one vertex.

Theorem 11.25 The number of labeled trees with n vertices is nn−2.

Proof: (Pr¨ufer sequence) There is a one-to-one correspondence between labeled trees
and sequences of length n − 2 of integers between 1 and n. An integer may repeat in the
sequence. The number of such sequences is clearly nn−2. Although each vertex of the tree
has a unique integer label the corresponding sequence has repeating labels. The reason for
this is that the labels in the sequence refer to interior vertices of the tree and the number
of times the integer corresponding to an interior vertex occurs in the sequence is related
to the degree of the vertex. Integers corresponding to leaves do not appear in the sequence.

To see the one-to-one correspondence, ﬁrst convert a tree to a sequence by deleting
the lowest numbered leaf. If the lowest numbered leaf is i and its parent is j, append j to
the tail of the sequence. Repeating the process until only two vertices remain yields the
sequence. Clearly a labeled tree gives rise to only one sequence.

It remains to show how to construct a unique tree from a sequence. The proof is
by induction on n. For n = 1 or 2 the induction hypothesis is trivially true. Assume
the induction hypothesis true for n − 1. Certain numbers from 1 to n do not appear
in the sequence and these numbers correspond to vertices that are leaves. Let i be
the lowest number not appearing in the sequence and let j be the ﬁrst integer in the
sequence. Then i corresponds to a leaf connected to vertex j. Delete the integer j from
the sequence. By the induction hypothesis there is a unique labeled tree with integer
labels 1, . . . , i − 1, i + 1, . . . , n. Add the leaf i by connecting the leaf to vertex j. We
need to argue that no other sequence can give rise to the same tree. Suppose some other
sequence did. Then the ith integer in the sequence must be j. By the induction hypothesis
the sequence with j removed is unique.

Algorithm

Create leaf list - the list of labels not appearing in the Pr¨ufer sequence. n is the

length of the Pr¨ufer list plus two.
while Pr¨ufer sequence is non empty do
begin

p =ﬁrst integer in Pr¨ufer sequence
e =smallest label in leaf list
Add edge (p, e)
Delete e from leaf list
Delete p from Pr¨ufer sequence
If p no longer appears in Pr¨ufer sequence add p to leaf list

end
There are two vertices e and f on leaf list, add edge (e, f )

404

11.8 Exercises

Exercise 11.1 What is the diﬀerence between saying f (n) is O (n3) and f (n) is o (n3)?

Exercise 11.2 If f (n) ∼ g (n) what can we say about f (n) + g(n) and f (n) − g(n)?

Exercise 11.3 What is the diﬀerence between ∼ and Θ?

Exercise 11.4 If f (n) is O (g (n)) does this imply that g (n) is Ω (f (n))?

Exercise 11.5 What is lim
k→∞

(cid:0) k−1
k−2

(cid:1)k−2.

Exercise 11.6 Select a, b, and c uniformly at random from [0, 1]. The probability that
b < a is 1/2. The probability that c<a is 1/2. However, the probability that both b and c are
less than a is 1
3 not 1/4. Why is this? Note that the six possible permutations abc, acb,
bac, cab, bca, and cba, are all equally likely. Assume that a, b, and c are drawn from the
interval (0,1]. Given that b < a, what is the probability that c < a?

Exercise 11.7 Let A1, A2, . . . , An be events. Prove that Prob(A1∪A2∪· · · An) ≤

n
(cid:80)
i=1

Prob(Ai)

Exercise 11.8 Give an example of three random variables that are pairwise independent
but not fully independent.

Exercise 11.9 Give examples of nonnegative valued random variables with median >>
mean. Can we have median << mean?

Exercise 11.10 Consider n samples x1, x2, . . . , xn from a Gaussian distribution of mean
µ and variance σ. For this distribution m = x1+x2+···+xn
is an unbiased estimator of
(xi − µ)2 is an unbiased estimator of σ2. Prove that if we

n

µ. If µ is known then 1
n

n
(cid:80)
i=1
approximate µ by m, then 1
n−1

n
(cid:80)
i=1

(xi − m)2 is an unbiased estimator of σ2.

Exercise 11.11 Given the distribution

1√

2π3

2 ( x

3 )2

e− 1

what is the probability that x >1?

Exercise 11.12 e−
we wished to approximate e−

x2
2 has value 1 at x = 0 and drops oﬀ very fast as x increases. Suppose

x2
2 by a function f (x) where
(cid:26) 1
0

|x| ≤ a
|x| > a

f (x) =

.

What value of a should we use? What is the integral of the error between f (x) and e−

x2
2 ?

405

Exercise 11.13 Given two sets of red and black balls with the number of red and black
balls in each set shown in the table below.

Set 1
Set 2

red black
40
50

60
50

Randomly draw a ball from one of the sets. Suppose that it turns out to be red. What is
the probability that it was drawn from Set 1?

Exercise 11.14 Why cannot one prove an analogous type of theorem that states p (x ≤ a) ≤
E(x)
a ?

Exercise 11.15 Compare the Markov and Chebyshev bounds for the following probability
distributions

1. p(x) =

(cid:26) 1 x = 1

0 otherwise

2. p(x) =

(cid:26) 1/2
0

0 ≤ x ≤ 2
otherwise

Exercise 11.16 Let s be the sum of n independent random variables x1, x2, . . . , xn where
for each i

xi =

(cid:26) 0 Prob
1 Prob

p
1 − p

1. How large must δ be if we wish to have P rob (cid:0)s < (1 − δ) m(cid:1) < ε?

2. If we wish to have P rob (cid:0)s > (1 + δ) m(cid:1) < ε?

Exercise 11.17 What is the expected number of ﬂips of a coin until a head is reached?
Assume p is probability of a head on an individual ﬂip. What is value if p=1/2?

Exercise 11.18 Given the joint probability

P(A,B)
B=0
B=1

A=0
1/16
1/4

A=1
1/8
9/16

1. What is the marginal probability of A? of B?

2. What is the conditional probability of B given A?

406

Exercise 11.19 Consider independent random variables x1, x2, and x3, each equal to
zero with probability 1
2. Let S = x1 + x2 + x3 and let F be event that S ∈ {1, 2}. Condi-
tioning on F , the variables x1, x2, and x3 are still each zero with probability 1
2. Are they
still independent?

Exercise 11.20 Consider rolling two dice A and B. What is the probability that the sum
S will add to nine? What is the probability that the sum will be 9 if the roll of A is 3?

Exercise 11.21 Write the generating function for the number of ways of producing chains
using only pennies, nickels, and dines. In how many ways can you produce 23 cents?

Exercise 11.22 A dice has six faces, each face of the dice having one of the numbers 1
though 6. The result of a role of the dice is the integer on the top face. Consider two roles
of the dice. In how many ways can an integer be the sum of two roles of the dice.

Exercise 11.23 If a(x) is the generating function for the sequence a0, a1, a2, . . ., for what
sequence is a(x)(1-x) the generating function.

Exercise 11.24 How many ways can one draw n a(cid:48)s and b(cid:48)s with an even number of a(cid:48)s.

Exercise 11.25 Find the generating function for the recurrence ai = 2ai−1 + i where
a0 = 1.

Exercise 11.26 Find a closed form for the generating function for the inﬁnite sequence
of prefect squares 1, 4, 9, 16, 25, . . .

Exercise 11.27 Given that
what sequence is

1

1−2x the generating function?

1
1−x is the generating function for the sequence 1, 1, . . ., for

Exercise 11.28 Find a closed form for the exponential generating function for the inﬁnite
sequence of prefect squares 1, 4, 9, 16, 25, . . .

Exercise 11.29 Prove that the L2 norm of (a1, a2, . . . , an) is less than or equal to the L1
norm of (a1, a2, . . . , an).

Exercise 11.30 Prove that there exists a y, 0 ≤ y ≤ x, such that f (x) = f (0) + f (cid:48)(y)x.

Exercise 11.31 Show that the eigenvectors of a matrix A are not a continuous function
of changes to the matrix.

Exercise 11.32 What are the eigenvalues of the two graphs shown below? What does
this say about using eigenvalues to determine if two graphs are isomorphic.

407

Exercise 11.33 Let A be the adjacency matrix of an undirected graph G. Prove that
eigenvalue λ1 of A is at least the average degree of G.

Exercise 11.34 Show that if A is a symmetric matrix and λ1 and λ2 are distinct eigen-
values then their corresponding eigenvectors x1 and x2 are orthogonal.
Hint:

Exercise 11.35 Show that a matrix is rank k if and only if it has k nonzero eigenvalues
and eigenvalue 0 of rank n-k.

Exercise 11.36 Prove that maximizing xT Ax
to the condition that x be of unit length.

xT x is equivalent to maximizing xT Ax subject

Exercise 11.37 Let A be a symmetric matrix with smallest eigenvalue λmin. Give a
bound on the largest element of A−1.

Exercise 11.38 Let A be the adjacency matrix of an n vertex clique with no self loops.
Thus, each row of A is all ones except for the diagonal entry which is zero. What is the
spectrum of A.

Exercise 11.39 Let A be the adjacency matrix of an undirect graph G. Prove that the
eigenvalue λ1 of A is at least the average degree of G.

Exercise 11.40 We are given the probability distribution for two random vectors x and
y and we wish to stretch space to maximize the expected distance between them. Thus,

we will multiply each coordinate by some quantity ai. We restrict

a2
i = d. Thus, if we
increase some coordinate by ai > 1, some other coordinate must shrink. Given random
vectors x = (x1, x2, . . . , xd) and y = (y1, y2, . . . , yd) how should we select ai to maximize
E (cid:0)|x − y|2(cid:1)? The ai stretch diﬀerent coordinates. Assume

d
(cid:80)
i=1

yi =

(cid:26) 0
1

1
2
1
2

and that xi has some arbitrary distribution.

E (cid:0)|x − y|2(cid:1) = E

d
(cid:80)
i=1

(cid:2)a2

i (xi − yi)2(cid:3) =

i E (x2
a2

i − 2xiyi + y2
i )

d
(cid:80)
i=1
i − xi + 1
2

(cid:1)

=

d
(cid:80)
i=1

i E (cid:0)x2
a2

i ) = E (xi) we get . Thus, weighting the coordinates has no eﬀect assuming

Since E (x2
d
(cid:80)
i=1

i = 1. Why is this? Since E (yi) = 1
a2
2.
E (cid:0)|x − y|2(cid:1) is independent of the value of xi hence its distribution.

408

What if yi =

(cid:26) 0
1

3
4
1
4

and E (yi) = 1

4. Then

E (cid:0)|x − y|2(cid:1) =

d
(cid:80)
i=1

i ) =

i − 2xiyi + y2
i E (x2
a2
d
(cid:80)
i=1

(cid:0) 1
2E (xi) + 1

a2
i

=

4

d
(cid:80)
i=1
(cid:1)

i E (cid:0)xi − 1
a2

2xi + 1

4

(cid:1)

.

To maximize put all weight on the coordinate of x with highest probability of one. What
if we used 1-norm instead of the two norm?

E (|x − y|) = E

d
(cid:88)

i=1

ai |xi − yi| =

d
(cid:88)

i=1

aiE |xi − yi| =

d
(cid:88)

i=1

aibi

where bi = E (xi − yi). If

i = 1, then to maximize let ai = bi
a2

b . Taking the dot product

of a and b is maximized when both are in the same direction.

d
(cid:80)
i=1

Exercise 11.41 Maximize x+y subject to the constraint that x2 + y2 = 1.

Exercise 11.42 Draw a tree with 10 vertices and label each vertex with a unique integer
from 1 to 10. Construct the Prfer sequence for the tree. Given the Prfer sequence recreate
the tree.

Exercise 11.43 Construct the tree corresponding to the following Prfer sequences

1. 113663

2. 552833226

409

Index

2-norm, 59
2-universal, 241
4-way independence, 247

Aﬃnity matrix, 275
Algorithm

greedy k-clustering, 265
k-means, 263
singular value decomposition, 62

Almost surely, 93
Anchor term, 303
Annulus, 16
Aperiodic, 192
Arithmetic mean, 367
Axioms

consistent, 289
for clustering, 289
rich, 289
scale invariant, 289

Bad pair, 96
Balanced k-means algorithm, 295
Bayes rule, 376
Bernoulli trials, 375
Best ﬁt, 10
Bigoh, 357
Binomial distribution, 88

approximated by normal density, 88
approximated by Poisson, 90

Boosting, 214
Branching Process, 105
Branching process, 109
Breadth-ﬁrst search, 102

Cartesian coordinates, 17
Cauchy-Schwartz inequality, 363, 365
Central Limit Theorem, 373
Characteristic equation, 383
Characteristic function, 399
Chebyshev’s inequality, 14
Chernoﬀ inequalities, 378

Clustering, 260

k-center criterion, 265
axioms, 289
balanced k-means algorithm, 295
k-means, 263
proper, 272
single link, 290
sparse cuts, 273
sum of pairs, 292

CNF

CNF-sat, 121

Cohesion, 281
Commute time, 165
Conditional probability, 370
Conductance, 158
Coordinates

Cartesian, 17
polar, 17

Coupon collector problem, 168
Cumulative distribution function, 370
Current

probabilistic interpretation, 161

Cycles, 116

emergence, 115
number of, 115

Data streams

counting frequent elements, 243
frequency moments, 238
frequent element, 244
majority element, 244
number of distinct elements, 239
number of occurrences of an element,

243

second moment, 245

Degree distribution, 88
power law, 89
Diagonalizable, 383
Diameter of a graph, 95, 118
Diameter two, 116
Dimension reduction, 269

410

Disappearance of isolated vertices, 116
Discovery time, 163
Distance

total variation, 178

Distribution

vertex degree, 86

Document ranking, 71

Eﬀective resistance, 165
Eigenvalue, 382
Eigenvector, 71, 382
Electrical network, 158
Equator

of sphere, 13, 20

Erd¨os R´enyi, 85
Escape probability, 162
Euler’s constant, 169
Event, 370
Expected degree
vertex, 85

Expected value, 371
Exponential generating function, 399
Extinct families
size, 113

Extinction probability, 109, 111

Finite ﬁelds, 401
First moment method, 93
Fourier transform, 342, 400
Frequency domain, 342

G(n,p), 85
Gamma function, 19
Gamma function , 365
Gaussian, 27, 373, 400

annulus

width of, 28, 35
ﬁtting to data, 30
tail, 369

Gaussians

sparating, 29

Generating function, 109
component size, 130
for sum of two variables, 109

Generating functions, 396
Generating points on sphere, 27
Geometric mean, 367
Giant component, 86, 93, 98, 101, 116
Gibbs sampling, 180
Graph

connecntivity, 115
resistance, 168
Graphical model, 310
Greedy

k-clustering, 265
Growth models, 126
nonuniform, 126
with preferential attachment, 135
without preferential attachment, 128

Harmonic function, 158
Hash function, 402

universal, 241

Heavy tail, 89
Hidden Markov model, 305
Hitting time, 163, 175

Immortality probability, 111
Incoherent, 342
Increasing property, 93, 119
unsatisﬁability, 122

Independence

limited way, 246

Independent, 370
Indicator random variable, 96

of triangle, 91
Indicator variable, 371
Intersection systems, 226
Isolated vertices, 98, 116

number of, 98

Isometry

restricted isometry property, 340

Jensen’s inequality, 367
Johnson-Lindenstrauss theorem, 38, 40

k-center, 261
k-clustering, 265
k-means, 261

411

k-means clustering algorithm, 263
k-median, 261
Kernel methods, 274
Kirchhoﬀ’s law, 160
Kleinberg, 137

Lagrange, 401
Law of large numbers, 13, 15
Learning, 202

supervised, 274
unsupervised, 274
Linear separator, 204
Linearity of expectation, 91, 371
Lloyd’s algorithm, 263
Local algorithm, 137
Long-term probabilities, 156

m-fold, 120
Manifold

low dimensional, 275

Margin, 204

maximum margin separator, 206

Markov chain, 154
state, 177

Markov Chain Monte Carlo, 155
Markov random ﬁeld, 313
Markov’s inequality, 14
Matrix

multiplication

by sampling, 248
diagonalizable, 383
similar, 383

Maximum cut problem, 73
Maximum likelihood estimation, 378
Maximum likelihood estimator, 31
Maximum principle, 159
MCMC, 155
Mean value theorem, 402
Median, 373
Metropolis-Hastings algorithm, 178
Mixing time, 156
Model

random graph, 85

Molloy Reed, 127

Moment generating function, 399
Mutually independent, 370

Nearest neighbor, 276
Nearest neighbor problem, 38, 40
NMF, 303
Nonnegative matrix factorization, 303
Normal distribution

standard deviation, 88

Normalized conductance, 156, 184
Number of triangles in G(n, p), 91

Ohm’s law, 160
Orthonormal, 390

Page rank, 173

personalized , 176

Parallelepiped, 26
Perceptron, 204
Persistent, 154
Phase transition, 93
CNF-sat, 121
nonﬁnite components, 132

Poisson distribution, 375
Polar coordinates, 17
Positive semi deﬁnite, 212
Power iteration, 71
Power law distribution, 89
Power method, 62
Power-law distribution, 126
Pr¨ufer, 404
Principle component analysis, 64
Probability density function, 370
Probability distribution function, 370
Psuedo random, 247
Pure-literal heuristic, 123

Queue, 123

arrival rate, 123

Radon, 222
Random graph, 85
Random projection, 38

theorem, 38
Random variable, 369

412

Random walk

Eucleadean space, 169
in three dimensions, 170
in two dimensions, 170
on lattice, 169
undirected graph, 162
web, 173
Rapid Mixing, 177
Real spectral theorem, 384
Recommendation system, 251
Replication, 120
Resistance, 158, 168
eﬀfective, 162

Restart, 173

value, 173
Return time, 173

Sample space, 369
Sampling

length squared, 249
Satisfying assignments

expected number of, 122

Scale invariant, 289
Second moment method, 91, 95
Set system, 219, 223
Sharp threshold, 93
Shatter function, 223
Shattered, 219
Shingle, 259
Similar matrices, 383
Similarity measure
cosine, 260

Simplex, 26
Single link, 290
Singular value decomposition, 52
Singular vector, 53

ﬁrst, 53
left, 56
right, 56
second, 54

Six-degrees separation, 136
Sketch

matrix, 250

Sketches

documents, 253

Small world, 136
Smallest-clause heuristic, 122
Spam, 175
Spectral clustering, 266
spectral norm, 59
Sperner’s lemma, 403
Sphere

volume

narrow annulus, 23
near equator, 20

Standard deviation

normal distribution, 88

Stanley Milgram, 136
State, 177
Stationary distribution, 156
Stirling approximation, 364
Streaming model, 238
Subgradient, 338
Subgraph, 143
Support vector, 208
Support vector machine, 211
Surface area

of sphere, 17

near equator, 24

Symmetric matrices, 384

Tail bounds, 378
Tail of Gaussian, 369
Taylor series, 359
Threshold, 93

CNF-sat, 121
diameter O(ln n), 119
disappearance of isolated vertices, 98
emergence of cycles, 115
emergence of diameter two, 95
giant component plus isolated vertices,

117
Time domain, 342
Total variation distance, 178
Trace, 393
Triangle inequality, 363

413

Triangles, 91

Union bound, 371
Unit-clause heuristic, 123
Unitary matrix, 390
Unsatisﬁability, 122

Vapnik-Chervonenkis, 219
Variance, 372
variational method, 364
VC theorem, 226
VC-dimension, 216

convex polygons, 221
ﬁnite sets, 223
half spaces, 221
intervals, 220
pairs of intervals, 220
rectangles, 220
spheres, 222

Vector space model, 10
Vector space representation, 10
Viterbi algorithm, 307
Voltage

probabilistic interpretation, 160

Volume

parallelepiped, 26
simplex, 26
sphere, 15

in narrow annulus, 23
near equator, 20

Weak learner, 214
World Wide Web, 173

Young’s inequality, 363, 366

414

References

[ABC+08] Reid Andersen, Christian Borgs, Jennifer T. Chayes, John E. Hopcroft, Va-
hab S. Mirrokni, and Shang-Hua Teng. Local computation of pagerank con-
tributions. Internet Mathematics, 5(1):23–45, 2008.

[AF]

[AK]

David Aldous and James Fill. Reversible Markov Chains and Random Walks
on Graphs. http://www.stat.berkeley.edu/ aldous/RWG/book.html.

Sanjeev Arora and Ravindran Kannan. Learning mixtures of separated non-
spherical gaussians. Annals of Applied Probability, 15(1A):6992.

[Alo86]

Noga Alon. Eigenvalues and expanders. Combinatorica, 6:83–96, 1986.

[AM05]

[AN72]

[AP03]

[Aro11]

[AS08]

Dimitris Achlioptas and Frank McSherry. On spectral learning of mixtures
of distributions. In COLT, pages 458–469, 2005.

Krishna Athreya and P. E. Ney. Branching Processes, volume 107. Springer,
Berlin, 1972.

Dimitris Achlioptas and Yuval Peres. The threshold for random k-sat is 2k
(ln 2 - o(k)). In STOC, pages 223–231, 2003.

Multiplicative weights method: a meta-algorithm and its applications. Theory
of Computing journal - to appear, 2011.

Noga Alon and Joel H. Spencer. The probabilistic method. Wiley-Interscience
Series in Discrete Mathematics and Optimization. John Wiley & Sons Inc.,
Hoboken, NJ, third edition, 2008. With an appendix on the life and work of
Paul Erd˝os.

[BA]

Albert-Lszl Barabsi and Rka Albert. Emergence of scaling in random net-
works. Science, 286(5439).

[BEHW]

A. Blumer, A. Ehrenfeucht, D. Haussler, and M. K. Warmuth. Learnabil-
ity and the vapnik-chervonenkis dimension. Journal of the Association for
Computing Machinary.

[BGG97]

C Sidney Burrus, Ramesh A Gopinath, and Haitao Guo.
wavelets and wavelet transforms: a primer. 1997.

Introduction to

[Ble12]

David M. Blei. Probabilistic topic models. Commun. ACM, 55(4):77–84,
2012.

[BMPW98] Sergey Brin, Rajeev Motwani, Lawrence Page, and Terry Winograd. What
can you do with a web in your pocket? Data Engineering Bulletin, 21:37–47,
1998.

415

[Bol01]

B´ela Bollob´as. Random Graphs. Cambridge University Press, 2001.

[BT87]

[CF86]

B´ela Bollob´as and Andrew Thomason. Threshold functions. Combinatorica,
7(1):35–38, 1987.

Ming-Te Chao and John V. Franco. Probabilistic analysis of two heuristics
for the 3-satisﬁability problem. SIAM J. Comput., 15(4):1106–1118, 1986.

[CGTS99] Moses Charikar, Sudipto Guha, ´Eva Tardos, and David B. Shmoys. A
constant-factor approximation algorithm for the k-median problem (extended
abstract). In Proceedings of the thirty-ﬁrst annual ACM symposium on The-
ory of computing, STOC ’99, pages 1–10, New York, NY, USA, 1999. ACM.

[CHK+]

[Chv92]

Duncan S. Callaway, John E. Hopcroft, Jon M. Kleinberg, M. E. J. Newman,
and Steven H. Strogatz. Are randomly grown graphs really random?

33rd Annual Symposium on Foundations of Computer Science, 24-27 October
1992, Pittsburgh, Pennsylvania, USA. IEEE, 1992.

[CLMW11] Emmanuel J. Cand`es, Xiaodong Li, Yi Ma, and John Wright. Robust prin-

cipal component analysis? J. ACM, 58(3):11, 2011.

[DFK91] Martin Dyer, Alan Frieze, and Ravindran Kannan. A random polynomial
time algorithm for approximating the volume of convex bodies. Journal of
the Association for Computing Machinary, 1991.

[DFK+99] Petros Drineas, Alan M. Frieze, Ravi Kannan, Santosh Vempala, and
V. Vinay. Clustering in large graphs and matrices. In SODA, pages 291–
299, 1999.

[DG99]

[DS84]

[DS07]

[ER60]

Sanjoy Dasgupta and Anupam Gupta. An elementary proof of the johnson-
lindenstrauss lemma. 99(006), 1999.

Peter G. Doyle and J. Laurie Snell. Random walks and electric networks,
volume 22 of Carus Mathematical Monographs. Mathematical Association of
America, Washington, DC, 1984.

Sanjoy Dasgupta and Leonard J. Schulman. A probabilistic analysis of em
for mixtures of separated, spherical gaussians. Journal of Machine Learning
Research, 8:203–226, 2007.

Paul Erd¨os and Alfred R´enyi. On the evolution of random graphs. Publication
of the Mathematical Institute of the Hungarian Academy of Sciences, 5:17–61,
1960.

[Fel68]

William Feller. An Introduction to Probability Theory and Its Applications,
volume 1. Wiley, January 1968.

416

[FK99]

[Fri99]

[FS96]

Alan M. Frieze and Ravindan Kannan. Quick approximation to matrices and
applications. Combinatorica, 19(2):175–220, 1999.

Friedgut. Sharp thresholds of graph properties and the k-sat problem. Journal
of the American Math. Soc., 12, no 4:1017–1054, 1999.

Alan M. Frieze and Stephen Suen. Analysis of two simple heuristics on a
random instance of k-sat. J. Algorithms, 20(2):312–355, 1996.

[GKP94]

Ronald L. Graham, Donald E. Knuth, and Oren Patashnik. Concrete math-
ematics - a foundation for computer science (2. ed.). Addison-Wesley, 1994.

[GvL96]

Gene H. Golub and Charles F. van Loan. Matrix computations (3. ed.). Johns
Hopkins University Press, 1996.

[HBB10] Matthew D. Hoﬀman, David M. Blei, and Francis R. Bach. Online learning

for latent dirichlet allocation. In NIPS, pages 856–864, 2010.

[Jer98]

Mark Jerrum. Mathematical foundations of the markov chain monte carlo
method. In Dorit Hochbaum, editor, Approximation Algorithms for NP-hard
Problems, 1998.

[JKLP93]

Svante Janson, Donald E. Knuth, Tomasz Luczak, and Boris Pittel. The birth
of the giant component. Random Struct. Algorithms, 4(3):233–359, 1993.

[JLR00]

[Kan09]

[Kar90]

[Kle99]

[Kle00]

[Kle02]

[KV95]

[KV09]

Svante Janson, Tomasz ´Luczak, and Andrzej Ruci´nski. Random Graphs. John
Wiley and Sons, Inc, 2000.

Ravindran Kannan. A new probability inequality using typical moments and
concentration results. In FOCS, pages 211–220, 2009.

Richard M. Karp. The transitive closure of a random digraph. Random
Structures and Algorithms, 1(1):73–94, 1990.

Jon M. Kleinberg. Authoritative sources in a hyperlinked environment.
JOURNAL OF THE ACM, 46(5):604–632, 1999.

Jon M. Kleinberg. The small-world phenomenon: an algorithm perspective.
In STOC, pages 163–170, 2000.

Jon M. Kleinberg. An impossibility theorem for clustering. In NIPS, pages
446–453, 2002.

Michael Kearns and Umesh Vazirani. An introduction to Computational
Learning Theory. MIT Press, 1995.

Ravi Kannan and Santosh Vempala. Spectral algorithms. Foundations and
Trends in Theoretical Computer Science, 4(3-4):157–288, 2009.

417

[Liu01]

Jun Liu. Monte Carlo Strategies in Scientiﬁc Computing. Springer, 2001.

[Mat10]

Jiˇr´ı Matouˇsek. Geometric discrepancy, volume 18 of Algorithms and Combina-
torics. Springer-Verlag, Berlin, 2010. An illustrated guide, Revised paperback
reprint of the 1999 original.

[Mit97]

Tom M. Mitchell. Machine Learning. McGraw-Hill, New York, 1997.

[MR95a] Michael Molloy and Bruce A. Reed. A critical point for random graphs with
a given degree sequence. Random Struct. Algorithms, 6(2/3):161–180, 1995.

[MR95b]

Rajeev Motwani and Prabhakar Raghavan. Randomized Algorithms. Cam-
bridge University Press, 1995.

[MR99]

[MU05]

[MV10]

[Pal85]

[Par98]

Rajeev Motwani and Prabhakar Raghavan. Randomized algorithms. In Al-
gorithms and theory of computation handbook, pages 15–1–15–23. CRC, Boca
Raton, FL, 1999.

Michael Mitzenmacher and Eli Upfal. Probability and computing - randomized
algorithms and probabilistic analysis. Cambridge University Press, 2005.

Ankur Moitra and Gregory Valiant. Settling the polynomial learnability of
mixtures of gaussians. In FOCS, pages 93–102, 2010.

Edgar M. Palmer. Graphical evolution. Wiley-Interscience Series in Discrete
Mathematics. John Wiley & Sons Ltd., Chichester, 1985. An introduction to
the theory of random graphs, A Wiley-Interscience Publication.

Beresford N. Parlett. The symmetric eigenvalue problem, volume 20 of Clas-
sics in Applied Mathematics. Society for Industrial and Applied Mathematics
(SIAM), Philadelphia, PA, 1998. Corrected reprint of the 1980 original.

[per10]

Markov Chains and Mixing Times. American Mathematical Society, 2010.

[Sch90]

[SJ]

[Sly10]

[SS01]

Rob Schapire. Strength of weak learnability. Machine Learning, 5:197–227,
1990.

Alistair Sinclair and Mark Jerrum. Approximate counting, uniform genera-
tion and rapidly mixing markov chains. Information and Computation.

Allan Sly. Computational transition at the uniqueness threshold. In FOCS,
pages 287–296, 2010.

Bernhard Scholkopf and Alexander J. Smola. Learning with Kernels: Support
Vector Machines, Regularization, Optimization, and Beyond. MIT Press,
Cambridge, MA, USA, 2001.

[SWY75] G. Salton, A. Wong, and C. S. Yang. A vector space model for automatic

indexing. Commun. ACM, 18:613–620, November 1975.

418

[Val84]

Leslie G. Valiant. A theory of the learnable. In STOC, pages 436–445, 1984.

[Val13]

[VC71]

L. Valiant. Probably Approximately Correct: Nature’s Algorithms for Learn-
ing and Prospering in a Complex World. Basic Books, 2013.

V. Vapnik and A. Chervonenkis. On the uniform convergence of relative
frequencies of events to their probabilities. Theory of Probability and its
Applications, 16(2):264–280, 1971.

[Vem04]

Santosh Vempala. The Random Projection Method. DIMACS, 2004.

[VW02]

Santosh Vempala and Grant Wang. A spectral algorithm for learning mixtures
of distributions. Journal of Computer and System Sciences, pages 113–123,
2002.

[Wil06]

H.S. Wilf. Generatingfunctionology. Ak Peters Series. A K Peters, 2006.

[WS98a]

D. J. Watts and S. H. Strogatz. Collective dynamics of ’small-world’ networks.
Nature, 393 (6684), 1998.

[WS98b]

Duncan J. Watts and Steven H. Strogatz. Collective dynamics of ’small-world’
networks. Nature, 393, 1998.

[WW96]

E. T. Whittaker and G. N. Watson. A course of modern analysis. Cambridge
Mathematical Library. Cambridge University Press, Cambridge, 1996. An
introduction to the general theory of inﬁnite processes and of analytic func-
tions; with an account of the principal transcendental functions, Reprint of
the fourth (1927) edition.

419

