100% found this document useful (4 votes)
50 views

[FREE PDF sample] Algorithms Illuminated Part 3 Greedy Algorithms and Dynamic Programming 1st Edition Tim Roughgarden ebooks

Programming

Uploaded by

arrieschoubh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
50 views

[FREE PDF sample] Algorithms Illuminated Part 3 Greedy Algorithms and Dynamic Programming 1st Edition Tim Roughgarden ebooks

Programming

Uploaded by

arrieschoubh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Algorithms Illuminated Part 3 Greedy Algorithms


and Dynamic Programming 1st Edition Tim
Roughgarden

https://textbookfull.com/product/algorithms-illuminated-
part-3-greedy-algorithms-and-dynamic-programming-1st-
edition-tim-roughgarden/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Algorithms Illuminated Part 3 Greedy Algorithms and


Dynamic Programming 1st Edition Tim Roughgarden

https://textbookfull.com/product/algorithms-illuminated-part-3-greedy-
algorithms-and-dynamic-programming-1st-edition-tim-roughgarden/

textboxfull.com

Beyond the Worst-Case Analysis of Algorithms 1st Edition


Tim Roughgarden

https://textbookfull.com/product/beyond-the-worst-case-analysis-of-
algorithms-1st-edition-tim-roughgarden/

textboxfull.com

Algorithms For Competitive Programming 1st Edition David


Esparza Alba

https://textbookfull.com/product/algorithms-for-competitive-
programming-1st-edition-david-esparza-alba/

textboxfull.com

Twenty Lectures on Algorithmic Game Theory 1st Edition Tim


Roughgarden

https://textbookfull.com/product/twenty-lectures-on-algorithmic-game-
theory-1st-edition-tim-roughgarden/

textboxfull.com
Programming Quantum Computers Essential Algorithms and
Code Samples 1st Edition Eric R. Johnston

https://textbookfull.com/product/programming-quantum-computers-
essential-algorithms-and-code-samples-1st-edition-eric-r-johnston/

textboxfull.com

Options and Derivatives Programming in C Algorithms and


Programming Techniques for the Financial Industry 1st
Edition Carlos Oliveira (Auth.)
https://textbookfull.com/product/options-and-derivatives-programming-
in-c-algorithms-and-programming-techniques-for-the-financial-
industry-1st-edition-carlos-oliveira-auth/
textboxfull.com

Art of Computer Programming The Combinatorial Algorithms


Volume 4B 1st Edition Donald Knuth

https://textbookfull.com/product/art-of-computer-programming-the-
combinatorial-algorithms-volume-4b-1st-edition-donald-knuth/

textboxfull.com

Algorithms and Programs of Dynamic Mixture Estimation


Unified Approach to Different Types of Components Ivan
Nagy
https://textbookfull.com/product/algorithms-and-programs-of-dynamic-
mixture-estimation-unified-approach-to-different-types-of-components-
ivan-nagy/
textboxfull.com

Algorithms 1st Edition Jeff Erickson

https://textbookfull.com/product/algorithms-1st-edition-jeff-erickson/

textboxfull.com
Algorithms Illuminated
Part 3: Greedy Algorithms and Dynamic
Programming

Tim Roughgarden
c 2019 by Tim Roughgarden

All rights reserved. No portion of this book may be reproduced in any form
without permission from the publisher, except as permitted by U. S. copyright
law.

First Edition

Cover image: Untitled, by Johanna Dickson

ISBN: 978-0-9992829-4-6 (Paperback)


ISBN: 978-0-9992829-5-3 (ebook)

Library of Congress Control Number: 2017914282

Soundlikeyourself Publishing, LLC


New York, NY
[email protected]
www.algorithmsilluminated.org
In memory of
Stephen H. Schneider
Contents

Preface vii

13 Introduction to Greedy Algorithms 1


13.1 The Greedy Algorithm Design Paradigm 1
13.2 A Scheduling Problem 4
13.3 Developing a Greedy Algorithm 6
13.4 Proof of Correctness 12
Problems 21

14 Huffman Codes 23
14.1 Codes 23
14.2 Codes as Trees 28
14.3 Huffman’s Greedy Algorithm 32
*14.4 Proof of Correctness 41
Problems 49

15 Minimum Spanning Trees 52


15.1 Problem Definition 52
15.2 Prim’s Algorithm 57
*15.3 Speeding Up Prim’s Algorithm via Heaps 62
*15.4 Prim’s Algorithm: Proof of Correctness 69
15.5 Kruskal’s Algorithm 76
*15.6 Speeding Up Kruskal’s Algorithm via Union-Find 81
*15.7 Kruskal’s Algorithm: Proof of Correctness 91
15.8 Application: Single-Link Clustering 94
Problems 99

16 Introduction to Dynamic Programming 103


16.1 The Weighted Independent Set Problem 104
16.2 A Linear-Time Algorithm for WIS in Paths 108

v
vi Contents

16.3 A Reconstruction Algorithm 116


16.4 The Principles of Dynamic Programming 118
16.5 The Knapsack Problem 123
Problems 133

17 Advanced Dynamic Programming 137


17.1 Sequence Alignment 137
*17.2 Optimal Binary Search Trees 148
Problems 163

18 Shortest Paths Revisited 167


18.1 Shortest Paths with Negative Edge Lengths 167
18.2 The Bellman-Ford Algorithm 172
18.3 The All-Pairs Shortest Path Problem 185
18.4 The Floyd-Warshall Algorithm 187
Problems 198

Epilogue: A Field Guide to Algorithm Design 201

Hints and Solutions to Selected Problems 203

Index 211
Preface

This book is the third of a four-part series based on my online algo-


rithms courses that have been running regularly since 2012, which in
turn are based on an undergraduate course that I taught many times
at Stanford University. The first two parts of the series are not strict
prerequisites for this one, though portions of this book do assume
at least a vague recollection of big-O notation (covered in Chapter 2
of Part 1 or Appendix C of Part 2), divide-and-conquer algorithms
(Chapter 3 of Part 1), and graphs (Chapter 7 of Part 2).

What We’ll Cover

Algorithms Illuminated, Part 3 provides an introduction to and nu-


merous case studies of two fundamental algorithm design paradigms.

Greedy algorithms and applications. Greedy algorithms solve


problems by making a sequence of myopic and irrevocable decisions.
For many problems, they are easy to devise and often blazingly
fast. Most greedy algorithms are not guaranteed to be correct, but
we’ll cover several killer applications that are exceptions to this rule.
Examples include scheduling problems, optimal compression, and
minimum spanning trees of graphs.

Dynamic programming and applications. Few benefits of a se-


rious study of algorithms rival the empowerment that comes from
mastering dynamic programming. This design paradigm takes a lot of
practice to perfect, but it has countless applications to problems that
appear unsolvable using any simpler method. Our dynamic program-
ming boot camp will double as a tour of some of the paradigm’s killer
applications, including the knapsack problem, the Needleman-Wunsch
genome sequence alignment algorithm, Knuth’s algorithm for opti-

vii
viii Preface

mal binary search trees, and the Bellman-Ford and Floyd-Warshall


shortest-path algorithms.
For a more detailed look into the book’s contents, check out the
“Upshot” sections that conclude each chapter and highlight the most
important points. The “Field Guide to Algorithm Design” on page 201
provides a bird’s-eye view of how greedy algorithms and dynamic
programming fit into the bigger algorithmic picture.
The starred sections of the book are the most advanced ones. The
time-constrained reader can skip these sections on a first reading
without any loss of continuity.
Topics covered in the other three parts. Algorithms Illumi-
nated, Part 1 covers asymptotic notation (big-O notation and its
close cousins), divide-and-conquer algorithms and the master method,
randomized QuickSort and its analysis, and linear-time selection algo-
rithms. Part 2 covers data structures (heaps, balanced search trees,
hash tables, bloom filters), graph primitives (breadth- and depth-first
search, connectivity, shortest paths), and their applications (ranging
from deduplication to social network analysis). Part 4 is all about N P -
completeness, what it means for the algorithm designer, and strategies
for coping with computationally intractable problems, including the
analysis of heuristics and local search.

Skills You’ll Learn


Mastering algorithms takes time and effort. Why bother?
Become a better programmer. You’ll learn several blazingly
fast subroutines for processing data as well as several useful data
structures for organizing data that you can deploy directly in your own
programs. Implementing and using these algorithms will stretch and
improve your programming skills. You’ll also learn general algorithm
design paradigms that are relevant to many different problems across
different domains, as well as tools for predicting the performance of
such algorithms. These “algorithmic design patterns” can help you
come up with new algorithms for problems that arise in your own
work.
Sharpen your analytical skills. You’ll get lots of practice describ-
ing and reasoning about algorithms. Through mathematical analysis,
Preface ix

you’ll gain a deep understanding of the specific algorithms and data


structures that these books cover. You’ll acquire facility with sev-
eral mathematical techniques that are broadly useful for analyzing
algorithms.

Think algorithmically. After you learn about algorithms, you’ll


start seeing them everywhere, whether you’re riding an elevator,
watching a flock of birds, managing your investment portfolio, or even
watching an infant learn. Algorithmic thinking is increasingly useful
and prevalent in disciplines outside of computer science, including
biology, statistics, and economics.

Literacy with computer science’s greatest hits. Studying al-


gorithms can feel like watching a highlight reel of many of the greatest
hits from the last sixty years of computer science. No longer will you
feel excluded at that computer science cocktail party when someone
cracks a joke about Dijkstra’s algorithm. After reading these books,
you’ll know exactly what they mean.

Ace your technical interviews. Over the years, countless stu-


dents have regaled me with stories about how mastering the concepts
in these books enabled them to ace every technical interview question
they were ever asked.

How These Books Are Different

This series of books has only one goal: to teach the basics of algorithms
in the most accessible way possible. Think of them as a transcript
of what an expert algorithms tutor would say to you over a series of
one-on-one lessons.
There are a number of excellent more traditional and encyclopedic
textbooks about algorithms, any of which usefully complement this
book series with additional details, problems, and topics. I encourage
you to explore and find your own favorites. There are also several
books that, unlike these books, cater to programmers looking for
ready-made algorithm implementations in a specific programming
language. Many such implementations are freely available on the Web
as well.
x Preface

Who Are You?


The whole point of these books and the online courses upon which
they are based is to be as widely and easily accessible as possible.
People of all ages, backgrounds, and walks of life are well represented
in my online courses, and there are large numbers of students (high-
school, college, etc.), software engineers (both current and aspiring),
scientists, and professionals hailing from all corners of the world.
This book is not an introduction to programming, and ideally
you’ve acquired basic programming skills in a standard language (like
Java, Python, C, Scala, Haskell, etc.). If you need to beef up your
programming skills, there are several outstanding free online courses
that teach basic programming.
We also use mathematical analysis as needed to understand how
and why algorithms really work. The freely available book Mathe-
matics for Computer Science, by Eric Lehman, F. Thomson Leighton,
and Albert R. Meyer, is anP excellent and entertaining refresher on
mathematical notation (like and 8), the basics of proofs (induction,
contradiction, etc.), discrete probability, and much more.

Additional Resources
These books are based on online courses that are currently running
on the Coursera and Stanford Lagunita platforms. I’ve made several
resources available to help you replicate as much of the online course
experience as you like.
Videos. If you’re more in the mood to watch and listen than
to read, check out the YouTube video playlists available from
www.algorithmsilluminated.org. These videos cover all the topics
in this book series, as well as additional advanced topics. I hope they
exude a contagious enthusiasm for algorithms that, alas, is impossible
to replicate fully on the printed page.
Quizzes. How can you know if you’re truly absorbing the concepts
in this book? Quizzes with solutions and explanations are scattered
throughout the text; when you encounter one, I encourage you to
pause and think about the answer before reading on.
End-of-chapter problems. At the end of each chapter you’ll find
several relatively straightforward questions for testing your under-
Preface xi

standing, followed by harder and more open-ended challenge problems.


Hints or solutions to all of these problems (as indicated by an “(H)” or
“(S),” respectively) are included at the end of the book. Readers can
interact with me and each other about the end-of-chapter problems
through the book’s discussion forum (see below).
Programming problems. Each of the chapters concludes with a
suggested programming project whose goal is to help you develop a
detailed understanding of an algorithm by creating your own working
implementation of it. Data sets, along with test cases and their
solutions, can be found at www.algorithmsilluminated.org.
Discussion forums. A big reason for the success of online courses
is the opportunities they provide for participants to help each other
understand the course material and debug programs through discus-
sion forums. Readers of these books have the same opportunity, via
the forums available at www.algorithmsilluminated.org.

Acknowledgments
These books would not exist without the passion and hunger supplied
by the hundreds of thousands of participants in my algorithms courses
over the years. I am particularly grateful to those who supplied
detailed feedback on an earlier draft of this book: Tonya Blust, Yuan
Cao, Carlos Guia, Jim Humelsine, Vladimir Kokshenev, Bayram
Kuliyev, and Daniel Zingaro.
I always appreciate suggestions and corrections from readers.
These are best communicated through the discussion forums men-
tioned above.

Tim Roughgarden
New York, NY
April 2019
Chapter 13

Introduction to Greedy Algorithms

Much of the beauty in the design and analysis of algorithms stems


from the interplay between general algorithm design principles and
the instantiation of these principles to solve concrete computational
problems. There’s no silver bullet in algorithm design—no universal
technique that can solve every computational problem you’ll encounter.
But there are several general design paradigms that can help you
solve problems from many different application domains. Teaching
you these paradigms and their most famous instantiations is one of
the major goals of this book series.

13.1 The Greedy Algorithm Design Paradigm

13.1.1 Algorithm Paradigms


What’s an “algorithm design paradigm?” Readers of Part 1 have
already seen a canonical example, the divide-and-conquer paradigm.
That paradigm went like this:

The Divide-and-Conquer Paradigm


1. Divide the input into smaller subproblems.

2. Conquer the subproblems recursively.

3. Combine the solutions for the subproblems into a


solution for the original problem.

In Part 1 we saw numerous instantiations of this paradigm: the


MergeSort and QuickSort algorithms, Karatsuba’s O(n1.59 )-time al-
gorithm for multiplying two n-digit integers, Strassen’s O(n2.71 )-time
algorithm for multiplying two n ⇥ n matrices, and more.

1
2 Introduction to Greedy Algorithms

The first half of this book is about the greedy algorithm design
paradigm. What is a greedy algorithm, exactly? Much blood and ink
have been spilled over this question, so we’ll content ourselves with
an informal definition.1

The Greedy Paradigm


Construct a solution iteratively, via a sequence of myopic
decisions, and hope that everything works out in the end.

The best way to get a feel for greedy algorithms is through exam-
ples. We’ll see several over the next few chapters.2

13.1.2 Themes of the Greedy Paradigm


Here are a few themes to watch for in our examples. (You might want
to re-read this section after going through one or more examples, so
that it’s less abstract.) First, for many problems, it’s surprisingly
easy to come up with one or even multiple greedy algorithms that
might plausibly work. This is both a bug and a feature—greedy
algorithms can be a great cure for writer’s block when you’re stuck
on a problem, but it can be hard to assess which greedy approach
is the most promising. Second, the running time analysis is often a
one-liner. For example, many greedy algorithms boil down to sorting
plus a linear amount of extra processing, in which case the running
time of a good implementation would be O(n log n), where n is the
number of objects to be sorted.3 (Big-O notation suppresses constant
1
To investigate formal definitions of greedy algorithms, start with the paper
“(Incremental) Priority Algorithms,” by Allan Borodin, Morten N. Nielsen, and
Charles Rackoff (Algorithmica, 2003).
2
Readers of Part 2 have already seen a greedy algorithm, namely Dijkstra’s
shortest-path algorithm. That algorithm iteratively computes the shortest-path
distances from a starting vertex s to every other vertex of a graph. In each
iteration, the algorithm irrevocably and myopically commits to an estimate of the
shortest-path distance to one additional vertex, never revisiting the decision. In
graphs with only nonnegative edge lengths, everything works out in the end and
all the shortest-path distance estimates are correct.
3
For example, two O(n log n)-time sorting algorithms are MergeSort (see
Chapter 1 in Part 1) and HeapSort (see Chapter 10 in Part 2). Alternatively,
randomized QuickSort (see Chapter 5 of Part 1) has an average running time of
O(n log n).
13.1 The Greedy Algorithm Design Paradigm 3

factors and different logarithmic functions differ by a constant factor,


so there is no need to specify the base of the logarithm.) Finally,
it’s often difficult to figure out whether a proposed greedy algorithm
actually returns the correct output for every possible input. The fear
is that one of the algorithm’s irrevocable myopic decisions will come
back to haunt you and, with full hindsight, be revealed as a terrible
idea. And even when a greedy algorithm is correct, proving it can be
difficult.4

Features and Bugs of the Greedy Paradigm


1. Easy to come up with one or more greedy algorithms.

2. Easy to analyze the running time.

3. Hard to establish correctness.

One of the reasons why it can be hard to prove the correctness


of greedy algorithms is that most such algorithms are not correct,
meaning there exist inputs for which the algorithm fails to produce
the desired output. If you remember only one thing about greedy
algorithms, it should be this.

Warning
Most greedy algorithms are not always correct.

This point is especially difficult to accept for clever greedy algorithms


that you invented yourself. You might believe, in your heart of hearts,
that your natural greedy algorithm must always solve the problem
correctly. More often than not, this belief is unfounded.5
4
Veterans of Part 1 know that all three themes are a big contrast to the divide-
and-conquer paradigm. It’s often tricky to come up with a good divide-and-conquer
algorithm for a problem, and when you do, there’s usually a “Eureka!” moment
when you know that you’ve cracked the problem. Analyzing the running times of
divide-and-conquer algorithms can be difficult, due to the tug-of-war between the
forces of proliferating subproblems and shrinking work-per-subproblem. (All of
Chapter 4 of Part 1 is devoted to this topic.) Finally, proofs of correctness for
divide-and-conquer algorithms are usually straightforward inductions.
5
A not-always-correct greedy algorithm can still serve as a super-fast heuristic
for a problem, a point we’ll return to in Part 4.
4 Introduction to Greedy Algorithms

Now that my conscience is clear, let’s look at some cherry-picked


examples of problems that can be solved correctly with a judiciously
designed greedy algorithm.

13.2 A Scheduling Problem

Our first case study concerns scheduling, in which the goal is to sched-
ule tasks on one or more shared resources to optimize some objective.
For example, a resource could represent a computer processor (with
tasks corresponding to jobs), a classroom (with tasks corresponding
to lectures), or your calendar for the day (with tasks corresponding
to meetings).

13.2.1 The Setup


In scheduling, the tasks to be completed are usually called jobs, and
jobs can have different characteristics. Suppose that each job j has a
known length `j , which is the amount of time required to process the
job (for example, the length of a lecture or meeting). Also, each job
has a weight wj , with higher weights corresponding to higher-priority
jobs.

13.2.2 Completion Times


A schedule specifies an order in which to process the jobs. In a problem
instance with n jobs, there are n! = n · (n 1) · (n 2) · · · 2 · 1 different
schedules. That’s a lot of schedules! Which one should we prefer?
Next, we need to define an objective function that assigns a nu-
merical score to every schedule and quantifies what we want. First, a
preliminary definition:

Completion Times

The completion time Cj ( ) of a job j in a schedule is the


sum of the lengths of the jobs preceding j in , plus the
length of j itself.

In other words, a job’s completion time in a schedule is the total time


that elapses before the job has been fully processed.
13.2 A Scheduling Problem 5

Quiz 13.1
Consider a problem instance that has three jobs with `1 = 1,
`2 = 2, and `3 = 3, and suppose they are scheduled in this
order (with job 1 first). What are the completion times
of the three jobs in this schedule? (The job weights are
irrelevant for this question, so we have not specified them.)

a) 1, 2, and 3

b) 3, 5, and 6

c) 1, 3, and 6

d) 1, 4, and 6

(See Section 13.2.4 for the solution and discussion.)

13.2.3 Objective Function


What makes for a good schedule? We’d like jobs’ completion times to
be small, but trade-offs between jobs are inevitable—in any schedule,
jobs scheduled early will have short completion times while those
scheduled toward the end will have long completion times.
One way to make trade-offs between the jobs is to minimize the
sum of weighted completion times. In math, this objective function
translates to
Xn
min wj Cj ( ), (13.1)
j=1

where the minimization is over all n! possible schedules , and Cj ( )


denotes job j’s completion time in the schedule . This is equivalent
to minimizing the weighted average of the jobs’ completion times,
with the averaging weights proportional to the wj ’s.
For example, consider the three jobs in Quiz 13.1 and suppose
their weights are w1 = 3, w2 = 2, and w3 = 1. If we schedule the first
job first, the second job second, and the third job third, the sum of
the weighted completion times is

3 · 1 + |{z}
|{z} 2 · 3 + |{z}
1 · 6 = 15.
job #1 job #2 job #3
6 Introduction to Greedy Algorithms

By checking all 3! = 6 possible schedules, you can verify that this is


the schedule that minimizes the sum of weighted completion times.
How can we solve this problem in general, given as input an arbitrary
set of job lengths and weights?

Problem: Minimizing the Sum of Weighted


Completion Times
Input: A set of n jobs with positive lengths `1 , `2 , . . . , `n
and positive weights w1 , w2 , . . . , wn .

Output: A job sequence that minimizes the sum of


weighted completion times (13.1).

With n! different schedules, computing the best one by exhaustive


search is out of the question for all but the tiniest instances. We need
a smarter algorithm.6

13.2.4 Solution to Quiz 13.1


Correct answer: (c). We can visualize a schedule by stacking the
jobs on top of one another, with time increasing from bottom to top
(Figure 13.1). The completion time of a job is the time corresponding
to its topmost edge. For the first job, its completion time is just
its length, which is 1. The second job must wait for the first job to
complete, so its completion time is the sum of the lengths of the first
two jobs, which is 3. The third job doesn’t even start until time 3,
and then it takes 3 more time units to complete, so its completion
time is 6.

13.3 Developing a Greedy Algorithm

Greedy algorithms seem like a good fit for the problem of scheduling
jobs to minimize the weighted sum of completion times. The output
has an iterative structure, with jobs processed one by one. Why not
6
For example, n! is bigger than 3.6 million when n = 10, bigger than 2.4
quintillion when n = 20, and bigger than the estimated number of atoms in the
known universe when n 60. Thus no conceivable improvement in computer
technology would transmute exhaustive search into a useful algorithm.
13.3 Developing a Greedy Algorithm 7

job #3

time
3
job #2
1
job #1
0

Figure 13.1: The completion times of the three jobs are 1, 3, and 6.

use a greedy algorithm that iteratively decides which job should go


next?
The first step of our plan is to solve two special cases of the
general problem. Our solutions to these will suggest what a greedy
algorithm might look like in the general case. We’ll then narrow the
field to a single candidate algorithm and prove that this candidate
correctly solves the problem. The process by which we arrive at this
algorithm is more important to remember than the algorithm itself;
it’s a repeatable process that you can use in your own applications.

13.3.1 Two Special Cases


Let’s think positive and posit that there actually is a correct greedy
algorithm for the problem of minimizing the weighted sum of comple-
tion times. What would it look like? For starters, what if you knew
that all the jobs had the same length (but possibly different weights)?
What if they all had the same weight (but possibly different lengths)?

Quiz 13.2

(1) If all job lengths are identical, should we schedule


smaller- or larger-weight jobs earlier?

(2) If all job weights are identical, should we schedule


shorter or longer jobs earlier?
8 Introduction to Greedy Algorithms

a) larger/shorter

b) smaller/shorter

c) larger/longer

d) smaller/longer

(See Section 13.3.3 for the solution and discussion.)

13.3.2 Dueling Greedy Algorithms

In the general case, jobs can have different weights and different
lengths. Whenever our two rules-of-thumb—to prefer shorter jobs
and higher-weight jobs—luckily coincide for a pair of jobs, we know
which one to schedule first (the shorter, higher-weight one). But what
if the two rules give conflicting advice? What should we do with one
short low-weight job and one long high-weight job?
What’s the simplest greedy algorithm that might work? Each
job has two parameters, and the algorithm must look at both. The
best-case scenario would be to come up with a formula that compiles
each job’s length and weight into a single score, so that scheduling
jobs from highest to lowest score is guaranteed to minimize the sum of
weighted completion times. If such a formula exists, our two special
cases imply that it must have two properties: (i) holding the length
fixed, it should be increasing in the job’s weight; and (ii) holding the
weight fixed, it should be decreasing in the job’s length. (Remember,
higher scores are better.) Take a minute to brainstorm some formulas
that have both of these properties.

* * * * * * * * * * *

Perhaps the simplest function that is increasing in weight and


decreasing in length is the difference between the two:

proposal #1 for score of job j: wj `j .

This score might be negative, but that poses no obstacle to sequencing


the jobs from highest to lowest score.
13.3 Developing a Greedy Algorithm 9

There are plenty of other options. For example, the ratio of the
two parameters is another candidate:
wj
proposal #2 for score of job j: .
`j
These two scoring functions lead to two different greedy algo-
rithms.
GreedyDiff
Schedule the jobs in decreasing order of wj `j
(breaking ties arbitrarily).

GreedyRatio
wj
Schedule the jobs in decreasing order of `j
(breaking ties arbitrarily).

Thus, already, our first case study illustrates the first theme of the
greedy paradigm (Section 13.1.2): It is often easy to propose multiple
competing greedy algorithms for a problem.
Which of the two algorithms, if any, is correct? A quick way to
rule out one of them is to find an instance in which the two algorithms
output different schedules, with different objective function values.
For whichever algorithm fares worse in this example, we can conclude
that it is not always optimal.
Both algorithms do the right thing in our two special cases, with
equal-weight or equal-length jobs. The simplest possible example for
ruling out one of them would be a problem instance with two jobs,
having different weights and lengths, such that the two algorithms
schedule the jobs in opposite orders. That is, we seek two jobs whose
ordering by difference is the opposite of their ordering by ratio. One
simple example is:
Job #1 Job #2
Length `1 = 5 `2 = 2
Weight w1 = 3 w2 = 1.
The first job has the larger ratio ( 35 vs. 12 ) but the smaller (more
negative) difference ( 2 vs. 1). Thus the GreedyDiff algorithm
schedules the second job first, while GreedyRatio does the opposite.
10 Introduction to Greedy Algorithms

Quiz 13.3
What is the sum of weighted completion times in the sched-
ules output by the GreedyDiff and GreedyRatio algorithms,
respectively?

a) 22 and 23

b) 23 and 22

c) 17 and 17

d) 17 and 11

(See Section 13.3.3 for the solution and discussion.)

We’ve made progress by ruling out the GreedyDiff algorithm


from further consideration. However, the outcome of Quiz 13.3 does
not immediately imply that the GreedyRatio algorithm is always
optimal. For all we know, there are other cases in which the algorithm
outputs a suboptimal schedule. You should always be skeptical about
an algorithm that does not come with a proof of correctness, even
if the algorithm does the right thing in some toy examples, and
extra-skeptical of greedy algorithms.
In our case, the GreedyRatio algorithm is, in fact, guaranteed to
minimize the sum of weighted completion times.

Theorem 13.1 (Correctness of GreedyRatio) For every set of


positive job weights w1 , w2 , . . . , wn and positive job lengths
`1 , `2 , . . . , `n , the GreedyRatio algorithm outputs a schedule with the
minimum-possible sum of weighted completion times.
This assertion is not obvious and you should not trust it until I supply
you with a proof. Consistent with the third theme of the greedy
paradigm (Section 13.1.2), this proof occupies the entire next section.

On Lemmas, Theorems, and the Like

In mathematical writing, the most important tech-


nical statements are labeled theorems. A lemma is
a technical statement that assists with the proof of
13.3 Developing a Greedy Algorithm 11

a theorem (much as a subroutine assists with the


implementation of a larger program). A corollary is a
statement that follows immediately from an already-
proven result, such as a special case of a theorem.
We use the term proposition for stand-alone techni-
cal statements that are not particularly important in
their own right.

The remaining theme of the greedy paradigm is the ease of running


time analyses (Section 13.1.2). That’s certainly the case here. All the
GreedyRatio algorithm does is sort the jobs by ratio, which requires
O(n log n) time, where n is the number of jobs in the input (see
footnote 3).

13.3.3 Solutions to Quiz 13.2–13.3

Solution to Quiz 13.2

Correct answer: (a). First suppose that all n jobs have the same
length, say length 1. Then, every schedule has exactly the same
set of completion times—{1, 2, 3, . . . , n}—and the only question is
which job gets which completion time. Our semantics for job weights
certainly suggests that the higher-weight jobs should receive the
smaller completion times, and this is in fact the case. For example,
you wouldn’t want to schedule a job with weight 10 third (with
completion time 3) and one with weight 20 fifth (with completion
time 5); you’d be better off exchanging the positions of these two jobs,
which would decrease the sum of weighted completion times by 20 (as
you should check).
The second case, in which all jobs have equal weights, is a little
more subtle. Here, you want to favor shorter jobs. For example,
consider two unit-weight jobs with lengths 1 and 2. If you schedule
the shorter job first, the completion times are 1 and 3, for a total
of 4. In the opposite order, the completion times are 2 and 3, for
an inferior total of 5. In general, the job scheduled first contributes
to the completion times of all the jobs, as all jobs must wait for
the first one to finish. All else being equal, scheduling the shortest
job first minimizes this negative impact. The second job contributes
12 Introduction to Greedy Algorithms

to all the completion times other than that of the first job, so the
second-shortest job should be scheduled next, and so on.

Solution to Quiz 13.3

Correct answer: (b). The GreedyDiff algorithm schedules the


second job first. The completion time of this job is C2 = `2 = 2
while that of the other job is C1 = `2 + `1 = 7. The sum of weighted
completion times is then

w1 · C1 + w2 · C2 = 3 · 7 + 1 · 2 = 23.

The GreedyRatio algorithm schedules the first job first, resulting in


completion times C1 = `1 = 5 and C2 = `1 + `2 = 7 and a sum of
weighted completion times of

3 · 5 + 1 · 7 = 22.

We conclude that the GreedyDiff algorithm fails to compute an


optimal schedule for this example and therefore is not always correct.

13.4 Proof of Correctness

Divide-and-conquer algorithms usually have formulaic correctness


proofs, consisting of a straightforward induction. Not so with greedy
algorithms, for which correctness proofs are more art than science—be
prepared to throw in the kitchen sink. To the extent that there are
recurring themes in correctness proofs of greedy algorithms, we will
emphasize them as we go along.
The proof of Theorem 13.1 includes a vivid example of one such
theme: exchange arguments. The key idea is to prove that every
feasible solution can be improved by modifying it to look more like
the output of the greedy algorithm. We’ll see two variants in this
section. In the first, we’ll proceed by contradiction and use an exchange
argument to exhibit a “too-good-to-be-true” solution. In the second,
we’ll use an exchange argument to show that every feasible solution
can be iteratively massaged into the output of the greedy algorithm,
13.4 Proof of Correctness 13

while only improving the solution along the way.7

13.4.1 The No-Ties Case: High-Level Plan

We proceed to the proof of Theorem 13.1. Fix a set of jobs, with


positive weights w1 , w2 , . . . , wn and lengths `1 , `2 . . . , `n . We must
show that the GreedyRatio algorithm produces a schedule that min-
imizes the sum of weighted completion times (13.1). We start with
two assumptions.

Two Assumptions

(1) The jobs are indexed in nonincreasing order of weight-


length ratio:
w1 w2 wn
··· . (13.2)
`1 `2 `n

wi wj
(2) There are no ties between ratios: `i 6= `j whenever
i 6= j.

The first assumption is without loss of generality, merely an agreement


among friends to minimize our notational burden. Reordering the
jobs in the input has no effect on the problem to be solved. We can
therefore always reorder and reindex the jobs so that (13.2) holds.
The second assumption imposes a non-trivial restriction on the input;
we will do some extra work to remove it in Section 13.4.4. Together,
the two assumptions imply that jobs are indexed in strictly decreasing
order of weight-length ratio.
The high-level plan is to proceed by contradiction. Recall that
in this type of proof, you assume the opposite of what you want to
prove, and then build on this assumption with a sequence of logically
correct steps that culminates in a patently false statement. Such a
7
Exchange arguments are only one way among many to prove that a greedy
algorithm is correct. For example, in Chapter 9 of Part 2, our correctness
proof for Dijkstra’s algorithm used induction rather than an exchange argument.
Both induction and exchange arguments play a role in our correctness proofs for
Huffman’s greedy coding algorithm (Chapter 14) and for Prim’s and Kruskal’s
minimum spanning tree algorithms (Chapter 15).
14 Introduction to Greedy Algorithms

contradiction implies that the assumption can’t be true, which proves


the desired statement.
To begin, we assume that the GreedyRatio algorithm produces
a schedule of the given jobs that is not optimal. Thus, there is
an optimal schedule ⇤ of these jobs with a strictly smaller sum of
weighted completion times. The inspired idea is to use the differences
between and ⇤ to explicitly construct a schedule that is even better
than ⇤ ; this will contradict our assumption that ⇤ is an optimal
schedule.

13.4.2 Exchanging Jobs in a Consecutive Inversion


Suppose, for contradiction, that the GreedyRatio algorithm produces
the schedule and that there is an optimal schedule ⇤ with a strictly
smaller sum of weighted completion times. By assumption (1), the
greedy schedule schedules the jobs in order of index (with job 1
first, then job 2, all the way up to job n); see Figure 13.2.

job #n
..........

job #3
time

job #2

job #1
σ

Figure 13.2: The greedy schedule , with jobs scheduled in order of


nonincreasing weight-length ratio.

Going from bottom to top in the greedy schedule, the indices


of the jobs always go up. This is not true for any other schedule.
To make this assertion precise, define a consecutive inversion in a
13.4 Proof of Correctness 15

schedule as a pair i, j of jobs such that i > j and job i is processed


immediately before job j. For example, in Figure 13.2, if jobs 2
and 3 were processed in the opposite order they would constitute a
consecutive inversion (with i = 3 and j = 2).

Lemma 13.2 (Non-Greedy Schedules Have Inversions)


Every schedule ˆ different from the greedy schedule has at least one
consecutive inversion.
Proof: We prove the contrapositive.8 If ˆ has no consecutive inversions,
the index of each job is at least 1 larger than the job that came before
it. There are n jobs and the maximum-possible index is n, so there
cannot be any jumps of 2 or more between the indices of consecutive
jobs. This means that ˆ is the same as the schedule computed by the
greedy algorithm. QE D 9

Returning to the proof of Theorem 13.1, we are assuming that


there is an optimal schedule ⇤ of the given jobs with a strictly
smaller sum of weighted completion times than the greedy schedule .
Because ⇤ 6= , Lemma 13.2 applies to ⇤ , and there are consecutive
jobs i, j in ⇤ with i > j (Figure 13.3(a)). How can we use this fact
to exhibit another schedule 0 that is even better than ⇤ , thereby
furnishing a contradiction?
The key idea is to perform an exchange. We define a new sched-
ule 0 that is identical to ⇤ except that the jobs i and j are processed
in the opposite order, with j now processed immediately before i.
The jobs before both i and j (“stuff” in Figure 13.3) are the same in
both ⇤ and 0 (and in the same order), and likewise for the jobs that
follow both i and j (“more stuff”).

13.4.3 Cost-Benefit Analysis


What are the ramifications of the exchange illustrated below in
Figure 13.3?
8
The contrapositive of a statement “if A is true, then B is true” is the logically
equivalent statement “if B is not true, then A is not true.” For example, the
contrapositive of Lemma 13.2 is: If ˆ has no consecutive inversions, then ˆ is the
same as the greedy schedule .
9
“Q.e.d.” is an abbreviation for quod erat demonstrandum and means “that
which was to be demonstrated.” In mathematical writing, it is used at the end of
a proof to mark its completion.
16 Introduction to Greedy Algorithms

more more
stuff stuff

j i
exchange!
i j
time

time
stuff stuff

σ* σ’
(a) Before exchange (b) After exchange

Figure 13.3: Obtaining the new schedule 0 from the allegedly optimal
schedule ⇤ by exchanging the jobs in a consecutive inversion (with i > j).

Quiz 13.4
What effect does the exchange have on the completion time
of: (i) a job other than i or j; (ii) the job i; and (iii) the
job j?

a) (i) Not enough information to answer; (ii) goes up;


(iii) goes down.

b) (i) Not enough information to answer; (ii) goes down;


(iii) goes up.

c) (i) Unaffected; (ii) goes up; (iii) goes down.

d) (i) Unaffected; (ii) goes down; (iii) goes up.

(See Section 13.4.5 for the solution and discussion.)


Other documents randomly have
different content
several other places, just as if she were some common burgher's wench with
a none too spotless reputation, had not ended with a song or two: no! the
malapert had actually been impudent enough last night to scale the
courtyard wall and to stand for over half an hour just below Madame's
window (how he knew which was Madame's window Satan, his
accomplice, alone could tell!) singing away to the accompaniment of a
twangy lute, which she—Nicolle—for one, could never abide.

Fortunately, on that occasion Madame Jacqueline had been both modest


and discreet. She had kept well within the room and even retired into the
alcove, well out of sight of that abominable rascal; but she would not allow
Colle to close the window and had been very angry indeed when the old
woman with a few gruff and peremptory words had presently sent the
malapert away.

That was yesterday. And now this outburst of rage! It was unbelievable!
Madame Jacqueline of a truth was hot-tempered and passionate—how
could she help being otherwise, seeing that she had been indulged and
adulated ever since, poor mite of three, she had lost both father and mother
and had been under the guardianship of Monseigneur d'Inchy and of half a
dozen other gentlemen. Never, however, had Colle seen her quite like this,
and for such a worthless cause! Colle could scarce credit her eyes and ears.
And alas! there was no mistaking the flood of heartrending weeping which
followed. Jacqueline sat huddled up in her chair, her face buried in her
hands, sobbing and weeping as if her heart would break.

II

All the obstinacy in the worthy old soul melted away in an instant,
giving place to heartrending remorse. She fell on her knees, she took the
small feet of her adored mistress in her hands and kissed them and wept
over them and cried and lamented tearfully.

'Lord God, what have I done?' she called out from the depths of her
misery. 'My dove, my cabbage! Look at me—look at thy old Colle! Dost
not know that I would far sooner bite my tongue out than say one word that
would offend thee? My lamb, wilt not look at Colle?—I vow—I swear that
I'll die here on the spot at thy feet, if thou'lt not smile on me!'

Gradually as the old woman wept and pleaded, Jacqueline became more
calm. The sobs no longer shook her shoulders, but she still kept her face
hidden in her hands. A few minutes went by. Colle had buried her old head
in the young girl's lap, and after a while Jacqueline, regally condescending
to forgive, allowed her hand to fall on the bowed head of the repentant
sinner.

'I'll only forgive thee, Colle,' she said with solemn earnestness, 'if Pierre
doth not lay a finger upon that heavenly singer—but, if he does——'

Colle struggled to her feet as quickly as her stiff joints would allow.

'I'll go and find the varlet myself,' she said fiercely, ready to betray with
cowardly baseness the confederate of awhile ago, now that she had
propitiated the mistress whom she adored. 'M. de Landas hath not yet left
the Palace, and if Pierre dares but raise his hand against that mal—hem!—
against the noble singer whom thou dost honour with thine attention, well!
he'll have to reckon with old Colle; that is all!'

With Jacqueline de Broyart—who in herself appeared the very


embodiment of spring, so full of youth, of grace and of vitality was she—
sunshine and storm came in rapid succession over her moods, just as they
do over the skies when the year is young. Already her eyes, bathed in tears
of rage awhile ago, were glistening with pleasure, and her lips, which had
pouted and stormed, were parted in a smile.

'Go, Colle!' she said eagerly. 'Go at once, ere it be too late and that fool
Pierre——'

The words died upon her lips. The next instant she had jumped down
from her chair and run to the window. From some distance down the street
there had come, suddenly wafted upon the wings of the wind, the sound of a
voice singing the well-known verses of Messire de Ronsard:
'Mignonne, allons voir si la rose
Qui ce matin avait desclose
Sa robe de pourpre au soleil
A point perdu cette vesprée
Les plis de sa robe pourprée
Et son teint au vostre pareil.'[1]

[1] 'Mignonne, come see if the rose


That this morning did unclose
Her purple robe to the sun
Hath not ere this evening lost
Of those purple petals most
And the tint with your tint one.'

(Translation by Mr. Percy Allen. Songs of Old France.)

Jacqueline knelt upon the window-seat, but she could see nothing, so she
turned back piteously to murmur to old Colle: 'Oh! if I could only see him!'

The old woman, after the experience of the past few minutes, was ready
to do anything, however abject, to further her mistress' desire.

'Put on thy mask, my pigeon,' she said, 'and then lean well out of the
window; but not too far, for fear M. de Landas should happen to be passing
in the courtyard and should see thee with thy hair down. No, no!' added the
old hypocrite obsequiously, 'there is no harm in listening to so sweet a
singer. I'll get thy purse, too, and thou canst throw him a coin or two. No
doubt the poor fellow is down-at-heels and only sings to earn his supper.'

And humble, fussy, still snivelling, Nicolle shuffled across the room,
found the satin mask and brought it to her mistress. Jacqueline fixed it over
her face; then she leaned as far out of the window as she dared to do
without fear of falling out. And, if M. de Landas saw her, why! he would be
so gladdened at the sight that he would have no ear for a mere street
musician, whilst she—Jacqueline—was just now in so soft a mood that if
M. de Landas happened to scale the wall to her casement-window—as he
had more than once threatened to do—she would return his kisses in a way
that she had never done before.

For she was deeply in love with M. de Landas, had been for years. She
had plighted her troth to him when she was a mere child, and she loved him
—oh yes! she loved him very, very much, only...

III

There was the width of the courtyard and the tall wall between
Jacqueline and the street where stood the singer whom she so longed to see.
She had caught sight of him yesterday when, to Nicolle's horror, he had
boldly scaled the wall and then had lingered for nigh on half an hour
beneath her window, singing one merry song after another, till her young
heart had been filled with a new joy, the cause of which she herself could
not quite comprehend.

She had watched him unseen, fearful lest some of the serving-men
should see him and drive him away. Fortunately Chance had been all in
favour of her new romance. M. de Landas was on duty at the Forts that
night; her guardian was still closeted with some other grave seigneurs, and
the serving-men were no doubt too busy to trouble about a harmless
minstrel. As for the wenches about the place, they had stood about in the
doorways, listening with delight at the impassioned songs and gaping in
admiration at the splendid bearing of the unknown cavalier.

Thus the singer had stood in the courtyard for some considerable time,
his martial figure silhouetted against the clear, moonlit sky, his voice rising
and falling in perfect cadence to the accompaniment of a soft-toned lute,
whilst Jacqueline, hidden within the shadow of the window-embrasure,
listened spellbound, her whole youth, her ardent, loving soul exultant at this
romance which was taking birth at her feet.
And now he had come back, and the very night seemed to bid him
welcome. It was still quite early in March, yet the air was soft as spring. All
day the birds had been twittering under the eaves, and on the west wind had
come wafted gently the scent of budding almond blossom and of the life-
giving sap in the branches of the trees.

The stately city with its towers and steeples and cupolas lay bathed in the
light of the honey-coloured moon. Far away on the right, the elegant church
of Saint Géry up on the Mont-des-Boeufs seemed like a bar of silver which
attached old Cambray to the star-studded firmament above, and around it
were grouped the tall steeples of St. Martin, St. Waast and St. Aubert, with
the fine hexagon of Martin et Martine which crowned the Town Hall;
whilst, dominating this forest of perfect and rich architecture, was the mass
of the cathedral close by, with its tall pointed steeple, its flying buttresses,
its numberless delicate pinnacles picked out as by a fairy hand against the
background of deep azure.

But Jacqueline de Broyart had for the nonce no eyes for all that beauty.
What cared she if the wintry moon outlined all these lovely heights with
delicate lines of silver? What cared she if the shadows of stately edifices
appeared full of a golden glow by contrast with the cold blue of the lights?
Her eyes were fixed, not on the tower of St. Géry nor on the steeple of
Notre Dame: they rested upon that high and cruel wall which hid the
unknown singer from her sight.

'Mignonne!' he sang out gaily. 'Allons voir la rose——'

'Oh!' sighed Jacqueline with passionate longing. 'If I only could——!'

And her fancy went soaring into a world of romance—a world far away
from the sordid strifes, the political intrigues, the quarrels of to-day; a world
wherein men were all handsome and brave and women were all free to
grant them their hand to kiss, to listen to their songs, to reward their
prowess, to receive their homage unfettered by convention—a world, in
fact, such as Messire de Froissart had chronicled and of which Messire
Villon had sung so exquisitely.
Then suddenly Jacqueline's dreams were rudely interrupted, as was also
the song of the unseen minstrel. Loud voices were raised and there was a
clash which made Jacqueline's very heart turn cold in her bosom.

'Colle!' she cried excitedly.

But Colle had shuffled out of the room some little while ago, in search of
Pierre, no doubt, whom evidently she had failed to find. And out there
behind that cruel wall the rough hands of that abominable varlet were being
laid on the precious person of the unsuspecting minstrel. Jacqueline felt
literally paralysed both with terror and with wrath. Colle had spoken of
Pierre's stout arm and still stouter stick, but there was also the possibility of
M. de Landas himself being about, and then—oh, then! ... Ye heavens
above! anything might happen! ... Oh! the wicked, wicked old woman and
that execrable Pierre! ... and ... and of course M. de Landas' jealousy was
sometimes terrifying!

'God in Heaven!' sighed Jacqueline. 'I entreat Thee to protect him!'

The noise of the scuffle in the street became louder and louder. There
were cries of rage as well as of pain. Blows were evidently raining freely—
on whom? My God, on whom? Then, from further up the street, came the
sound of running footsteps as well as the stern voice of the night watchmen
hurrying to the scene. Jacqueline would have bartered some years of her life
to see what was going on the other side of the wall. Only a minute or two
had gone by: to the young girl it had seemed like hours of suspense. And
now these people all rushing along, no doubt in order to give a hand to
Pierre—to fall on the unarmed minstrel—to lay hands upon him—to
belabour him with sticks—to wound or hurt him—to——

Jacqueline uttered a loud cry of horror. It was the echo of one of terror,
of pain and of rage which came from the other side of the wall. The next
moment a dark mass appeared over the top of the wall, silhouetted against
the moonlit sky. To Jacqueline's straining eyes it seemed like the body of a
man which, for the space of a brief second, seemed to hover in mid air and
then fell with a dull thud upon the paving-stones of the courtyard below.
Jacqueline closed her eyes. She felt sick and faint. To her ears now came
the sound of loud groans and vigorous curses. And then—oh, then!—loud
laughter and the last bar of the interrupted song—a sound indeed which
caused her at once to open her eyes again; whereupon she, too, could have
laughed and sung for joy. The inert mass still lay in a heap at the foot of the
wall; Jacqueline could vaguely discern its outline in the gloom, whilst up on
the top of the wall, astride, hatless, lute in hand, sat the masked minstrel
with his head turned gazing toward her window.

She clapped her hands with glee, and he, with a loud cry of 'Mignonne!'
swung himself down from the wall and ran across the courtyard until he
came to a halt just beneath her window, and even in the dim light of this
wintry moon Jacqueline thought that she could see his eyes glowing
through the holes in the mask.

It was all so joyous, so gay, so romantic; so different—ah! so very, very


different—to the dreary monotony of Jacqueline's daily existence! This
masked and unknown minstrel! His daring, his prowess, aye! his very
impudence, which laughed at high walls and defied an army of varlets!
There was Pierre moaning and groaning, disarmed and helpless, having
been tossed over the wall just as if he were a bale of cumbersome goods!
Serve him right well, too, for having dared to measure his valour against
that of so proud a cavalier! Pierre was not hurt—oh, Jacqueline was quite
sure that he was not hurt! Nothing, nothing whatever, was going to be
wrong on this lovely, glorious evening! No! Pierre would soon be healed of
his wounds; but it was ludicrous to see him stretched out just there, where
he thought he could lay the noble singer low!

'Mignonne, allons voir si la rose,' sang the mysterious minstrel; and


Jacqueline's young heart, which was filled with the joy of romance, the
exquisite rapture of ideals, suddenly ached with a passionate longing for—
for what? She did not know. She had had so many things in life: riches,
beauty, adulation, aye! and the love of a man whom she loved in return. But
now it seemed to her as if, in spite of all that, in spite of M. de Landas and
his love, she had really lacked something all the time—something that was
both undefinable and mystic and yet was intensely and vividly real,
something that would fill her life, that would satisfy her soul and gladden
her heart, in a way that M. de Landas' love, his passionate kisses, had never
succeeded in doing hitherto.

And somehow all this longing, all this thirst for a still-unknown
happiness, seemed personified in the singer with the tall, broad stature and
the mellow voice; it was embodied in the honey-coloured moon, in the
glints of silver and gold upon the steeples of Cambray, in the scent of the
spring and the murmurs of the breeze. Jacqueline pressed her hands against
her heart. She was so happy that she could have cried.

Beside her on the window-sill stood a tall vase fashioned of Dutch clay.
It was filled with tall-stemmed Madonna lilies, which had been produced at
great cost in the hot-houses belonging to her own estate in Hainault. Their
powerful scent had filled the room with its fragrance. Without thought or
hesitation, Jacqueline suddenly pulled the sheaf out of the vase and
gathered the flowers in her arms. The tender, juicy stems were wet and she
took her embroidered handkerchief out of her pocket and wrapped it round
them; then she flung the whole sheaf of lilies out of the window and
watched to see them fall, bruised and sweet-smelling, at the minstrel's feet.

Then, half-ashamed, laughing a little hysterically, but thoroughly happy


and excited, she drew quickly back into the room and hastily closed the
casement.

IV

When, ten minutes or so later, Nicolle came back, shame-faced,


remorseful and not a little frightened, she was surprised and delighted to
find her young mistress sitting quite composedly in a high-backed chair in
the centre of the room, the window closed, and the lady herself quite eager
to go to bed.

'Thou hast been gone a long time, Colle,' said the young girl carelessly.
'Where hast thou been?'
Old Colle sighed with relief. The Lord be praised! Madame had
evidently seen and heard nothing of that vulgar scuffle which had ended in
such disaster for poor Pierre, and in such a triumph for the impudent rascal
who had since disappeared just as quickly as he came.

'I just went round to see that those wenches were all abed and that their
lights were safely out,' replied the old woman with brazen hypocrisy.

'And didst speak to Pierre on the way?' queried Jacqueline, who had
assumed the quaintest possible air of simple ingenuousness.

'Aye!' replied the old woman dryly. 'I spoke to Pierre.'

'What did he say?'

'Nothing of importance. We talked of to-morrow's banquet.'

'To-morrow's banquet?'

'Do not feign surprise, my pigeon,' rejoined old Colle, who was
decidedly out of humour. 'I even asked thee to-night, before taking off thy
gown, if thou wouldst wear that one or another on the morrow.'

'I remember,' replied Jacqueline with a yawn, 'I said that I did not care
what I wore, as I hated banquets, and company and bowings and——'

'But Monseigneur said that the banquet to-morrow would be for a special
occasion.'

'When did he say that?'

'A moment or two ago—to Pierre.'

'And what will the special occasion be to-morrow?'

Nicolle looked mysterious.

'Maybe,' she said, 'that it is not altogether unconnected with


Monseigneur de Landas.'
'Why with him?' asked Jacqueline eagerly.

'Oh! I am only putting two and two together, my cabbage,' replied old
Colle with a sly wink. 'There is talk of distinguished guests in Cambray, of
betrothals, and ... and ...

'Betrothals?'

'Why, yes. Thou art nearly twenty, my pigeon, and Monseigneur, thy
guardian, will have to make up his mind that thou wilt marry sooner or
later. I always thought that he did favour Monseigneur de Landas, until
——'

'Until what?' queried Jacqueline impatiently.

'There are so many rumours in the air,' replied Colle sententiously. 'Some
talk of the Duc d'Anjou, who is own brother to the King of France.'

Jacqueline made a little moue of disdain.

'Oh! Monsieur!' she said carelessly.

'A very great and noble prince, my pigeon.'

'I am tired of great and noble princes.'

'But Monseigneur, the Duc d'Anjou...'

'Is one of the many, I suppose, who want my fortune, my family


connexions, the Sovereignty of the Netherlands. Bah!' she added with an
impatient sigh. 'They sicken me!'

'A great lady, my cabbage,' said Nicolle solemnly, 'cannot follow the
dictates of her heart like a common wench.'

'Why!' exclaimed Jacqueline. 'Methought thou wast all for M. de


Landas!'
'So I am, my pigeon, so I am!' rejoined the old woman. 'He is a very
distinguished gentleman, who loves thee ardently. But if there's one who is
own brother to the King of France....' And old Colle gave an unctuous sigh
when she spoke the exalted name.

'Bah!' retorted Jacqueline with a careless shrug of the shoulders. 'There


are others too! And no one can force me into a marriage whilst my heart is
pledged to M. de Landas.'

'No, no! Thank God for that!' assented Colle piously. 'As for the others ...
well! their name is legion ... some of them will be at the banquet to-
morrow.... There is the Marquis de Hancourt, a fine-looking youth, and that
horrid German prince whom I cannot abide! The English lord hath gone
away, so they say, broken-hearted at thy refusal; but there's the Spanish
duke, whose name I cannot remember, and Don José, own son to the
Emperor.... As for that stranger——' she added with a contemptuous shrug
of the shoulders.

'The stranger?' queried Jacqueline lazily. 'What stranger?

'Well, I don't know much about him. But Pierre, feeling crestfallen, did
admit that Monseigneur chided him severely for having shown a want of
respect to a gentleman who ought to have known better than to pretend to
be a street musician.'

But Jacqueline appeared all of a sudden to have lost interest in the


conversation. 'Ah!' she said with well-assumed indifference, 'then the street
musician of awhile ago was a gentleman in disguise?'

'Aye! so Pierre said—the fool!' quoth old Colle unblushingly.


'Monseigneur was very angry with him when he heard of the altercation
with the singer, threatened to speak of the matter to M. de Landas and have
Pierre flogged or dismissed for his interference. Then he hinted that the
stranger, far from being a street musician, was a foreign seigneur of high
degree, even if of scanty fortune.'

'Oh!' commented Jacqueline carelessly.


'And he e'en ordered Pierre to go and apologize most humbly to the
stranger, who it seems is lodging in a very poor hostelry known as "Les
Trois Rois," just close to the Porte Notre Dame.'

Jacqueline ostentatiously smothered a yawn.

'I think I'll go to bed now, Colle,' she said.

But Colle's tongue, once loosened, could not so easily be checked.

'Town gossip,' she went on with great volubility, 'has been busy with that
stranger for the past two days. 'Tis said that he is styled Monseigneur le
Prince de Froidmont; though what a prince should be doing in a shabby
hostel in that squalid quarter of the city I, for one, do not know—nor why
he should be going about masked and cloaked through the city in the guise
of a vagabond.'

'Perhaps the vagabond is no prince after all,' suggested Jacqueline.

'That's what I say,' asserted Colle triumphantly. 'And that's what Pierre
thought until Monseigneur told him that if he did not go at once and offer
his humble apologies he surely would get a flogging, seeing that the Prince
de Froidmont would actually be a guest at the banquet to-morrow, and
would of a certainty complain to M. de Landas.'

'A guest at the banquet!' exclaimed Jacqueline involuntarily.'

'Aye!' assented Colle. 'Didst ever hear the like! But he must be a
distinguished seigneur for all that, or Monseigneur would not bid him
come.'

'No, I suppose not,' said Jacqueline with perfect indifference. 'The Prince
de Froidmont?' she added with a little yawn. 'Is that his name?'

'So the town gossips say,' replied Colle, who was busy just then in
wrapping the bed-gown round her young mistress's shoulders.
'And he comes to the banquet to-morrow?'

'So Monseigneur said to Pierre.'

Jacqueline said nothing more for the moment, appeared to have lost all
interest in the masked musician and in Pierre's misdeeds. She stretched out
her arms lazily while vigorous old Colle picked her up as if she were a baby
and carried her—as she was wont to do every night—to her bed.

She laid her down upon the soft feather mattress and spread the fine
coverlets over her. The alcove wherein stood the monumental bedstead was
in semi-darkness, for the light from the wax candles in the sconces about
the room failed to penetrate into the recess. But that semi-darkness was
restful, and for awhile Jacqueline lay back against the pillows, with eyes
closed, in a state of that complete well-being which is one of the
monopolies of youth. Nicolle, thinking that Madame would be dropping off
to sleep, made a movement to go; but Jacqueline's small white hand had
hold of the old woman's bony fingers, and old Colle, abjectly happy at
feeling the pressure, remained quite still, waiting and watching, gazing with
doglike devotion on the lovely face—lovely in repose as it was when the
light of gaiety and roguishness danced in the blue eyes.

After a few minutes of this silent beatitude, Jacqueline opened her eyes
and said in a dreamy voice, half-asleep:

'Tell me, Colle, which is my prettiest gown?'

And Nicolle—herself more than half-way to the land of Nod—roused


herself in order to reply: 'The white one with the pearls, my pigeon.'

She was sufficiently awake to feel quite happy at the thought that
Madame was suddenly taking an interest in her clothes, and continued
eagerly: 'It hath an underdress of that lovely new green colour which hath
become the mode of late, and all embroidered with silver. Nothing more
beautiful hath ever been fashioned by tailors' art, and in it Madame looks
just like an exquisite white lily, with the delicate green stem below.'
'Well then, Colle,' rejoined Jacqueline dreamily, 'to-morrow evening I
will wear my white satin gown with the pearls and the underdress of green
and silver, and Mathurine must study a new way of doing my hair with the
pointed coif which they say is so modish now in France. I will wear my
stockings of crimson silk and my velvet shoes, and round my neck I'll wear
the ropes of pearls which my dear mother did bequeath to me; in my ears I'll
have the emerald earrings, and I'll wear the emerald ring upon my finger. I
wish I had not that ugly mole upon my left cheek-bone, for then I could
have had one of those tiny patches of black taffeta which are said to be so
becoming to the complexion....'

She paused, and added with quaint wistfulness: 'Think you, Colle, that I
shall look handsome?'

'As lovely as a picture, my dear one,' said Nicolle with enthusiasm. 'As
exquisite as a lily; fit only to be the bride of a King.'

Jacqueline gave a quick sigh of satisfaction, after which she allowed


Colle to give her a kiss and to bid her a final 'good night.'

And even as she fell gradually into the delicious and dreamless sleep of
youth, her lips murmured softly: 'I wonder!'

CHAPTER VIII

WHAT BECAME OF THE LILIES

I
Gilles had spent four days at the hostelry of 'Les Trois Rois,' and here he
would have liked to remain indefinitely and to continue the sentimental
romance so happily begun beneath the casement-windows of the
Archiepiscopal Palace. With the light-heartedness peculiar to most soldiers
of fortune, he had during those four days succeeded in putting his rôle out
of his mind. Though he had not yet caught sight of Madame's face at her
window, he quite thought that he would do so in time, and already he had
received more than one indication that his singing was not unwelcome. The
casement had been deliberately thrown open when he had scaled the
courtyard wall, and had resumed his song immediately beneath the window
which he had ascertained belonged to Madame's private apartment. He had
felt, even though he did not actually see, that some one was listening to him
from up there, for once he had perceived a shadow upon the casement
curtain, and once a hand, small and delicate, had rested upon the window-
sill. Gilles would have continued this wooing—aye! perhaps have brought it
to a happy conclusion, he thought—without being forced to assume another
personality than his own: a thing which became more and more abhorrent to
Messire Gilles' temper, now that the time for starting the masquerade in
earnest was drawing nigh.

'We could make ourselves very happy here, honest Jehan,' he had said to
the faithful companion of his many adventures. 'Waited on by that silent and
zealous youth, who of a truth looks like the very ghost of silence and
discretion. With judicious economy, the money which a gracious Queen
hath placed in our hands would last us a year. It seems a pity to fritter it all
away in a few weeks by playing a rôle which is detestable and unworthy.'

'B-b-b-but——' stammered old Jehan.

'You are quite right,' broke in Gilles gravely. 'Your argument is very
sound. The money, my friend, was given unto us in order to play a certain
rôle, and that rôle we must now play whether we like it or not, on pain of
being branded as vagabonds and thieves.'

'V-v-v-very——' stammered poor Jehan.

'As you say,' remarked Gilles dryly, 'I have always found you of good
counsel, my friend. Very likely—that is what you would say, is it not?—
very likely, unless we played our parts as Madame la Reyne de Navarre did
direct, Monseigneur le Baron d'Inchy would discover the fraud and have us
both hanged for our pains. And if the hangman did happen to miss us,
Madame Marguerite would certainly see to it that a gibbet was ready for us
somewhere in France. So for this once, I think, mine honest Jehan, we must
take it that honesty will be the best policy.'

'O-o-o-only th-th-th-that——'

'Quite so!' assented Gilles, 'only that in this case we cannot contrive to
remain honest without being dishonest, which is a proposition that doth
gravely disturb my mind.'

'Th-th-th-the o-o-o-only——'

'Hold your tongue, friend Jehan,' broke in Gilles impatiently. 'Verily, you
talk a great deal too much!'

II

And now, at the very close of the fourth day, Messire Gilles made noisy
irruption into the tiny room which he occupied in the hostelry of 'Les Trois
Rois.' Maître Jehan—after the stormy episode outside the postern gate
wherein he had taken part—was in the room, waiting for his master.

Gilles was in the rarest of good humour. As soon as he had closed the
door behind him, he threw his plumed toque and the lute upon the table and,
sitting down on the narrow paillasse which was his bed, he fell to
contemplating a bunch of white lilies which he had in his hand. The stems
of these lilies were carefully wrapped in an embroidered handkerchief, but
they hung their bruised, if still fragrant, heads in a very doleful manner.

Gilles laughed softly to himself. Then he held the flowers out at arm's
length and called out gaily to Jehan:
'Congratulate me, honest Jehan!' he said. 'The first act of our
adventurous comedy is over. The curtain has rung down on a veritable
triumph! I have received a token! ... I have captured the first bastion in the
citadel of the fair one's heart! Give me a week, and I hold the entire fortress
for and on behalf of Monsieur Duc d'Anjou, our august master!'

'Th-th-th-then you h-h-h-have——'

'No, I have not seen her, my good man. All that fine fight outside the
walls, the complete discomfiture of our assailants, my perilous position
inside the courtyard, from whence a reinforcement of varlets might easily
have put me to flight, did not win for me even a glimpse of the lady. But her
window was wide open this time, and I could see her shadow flitting past
the casement. Then suddenly these lilies were flung at me. They were
crushed and bruised against the pavement as they fell; but they are a token,
friend Jehan, and you cannot deny it! Madame Jacqueline's heart is already
touched by the song of the unknown troubadour, and he hath but to present
himself before her to be graciously received.'

'B-b-b-b-but——' said Jehan with grave solemnity.

'That's just it!' broke in Gilles with a laugh. 'You have a way, my friend,
of hitting the right nail on the head. As you say, the four days' respite which
have been granted to us have now expired, and we have not yet seen the
future Duchesse d'Anjou face to face.'

'N-n-n-not yet! Th-th-th-that——'

'That is the trouble, I grant you. There is that infernal masquerade; and of
a truth, I am more convinced than ever that the reason why those noble
mynheers are so determined that Madame shall not show her face ere I have
irrevocably committed myself—I—that is, the Duc d'Anjou—that is——
Oh, my God!' he exclaimed. 'What a tangle!! Well, as I was saying.... By the
way, what was I saying just now?'

'Th-th-th-that——'
'Of course! You incorrigible chatterbox! I would have explained my
meaning before now if you had not talked nineteen to the dozen all the
time! I mean that I have completely changed my mind, and that I have
become convinced that Madame Jacqueline is as ugly as sin, else those wily
Dutchmen would not be so anxious to cover up her face.'

'Th-th-th-therefore——' asserted Jehan stoutly.

'Therefore, my good man, good fortune is in our debt. She did not favour
me with a sight of the lady ere I meet her in my official capacity. But
Madame Jacqueline hath given me a token: she is prepared to love me, and
I am still in the dark as to whether she squints or is pitted with pock-marks.
A terrible position for any man to be in!' he sighed dolefully, 'even though
he is out a-courting for a friend.'

'B-b-b-but——'

'You mean well, my friend,' quoth Gilles, who fell to contemplating the
bunch of faded lilies with a rueful expression of face. 'You mean well, but
you talk too much, and thus I am thrown on mine own resources for counsel
in an emergency. As for arguments! Why, you would argue the devil's horns
from off his head! Still,' he added, as he finally flung the lilies away from
him with a careless gesture of indifference, 'still, in spite of what you say, I
must stick to my bargain. Those mulish mynheers will not grant us any
further delay, and to-morrow I am pledged to appear at the governor's
banquet—yes, even I!—Monsieur Duc d'Anjou et d'Alençon, own brother
to the King of France, and you as my faithful servitor.'

'N-n-n-not a m-m-minute t-t-too soon,' Maître Jehan managed to blurt


out quickly whilst Gilles had paused for breath.

'Ah! there you are wrong, my friend,' retorted Gilles. 'For my taste, the
dénouement is coming along at far too rapid a pace. To-morrow, already our
troubles will begin—peace will know us no more. I for one will never
rightly know who I am; nor will I know who it is who will know who I am
not. Oh, my Lord!' he added in mock despair, as he rested his elbows on his
knees and buried his head in his hands. 'My head will split ere I have done!
Tell me, Jehan, who I shall be to-morrow.'
'T-t-t-to-morrow,' stammered Jehan with painful earnestness, 'you—you
—you——you will b-b-b-b-be——'

'Own brother to His Majesty the King of France,' said Gilles, 'and as
great blackguard as ever disgraced a Royal house. To Monseigneur the
governor, and maybe also to some of his friends, I shall be a Royal prince.
To others, and notably to Madame Jacqueline de Broyart, I shall be the
Prince de Froidmont—an insignificant and penniless seigneur who only
dares approach the far-famed heiress under cover of a mask, having fallen
desperately in love with her. Ah, Jehan! Jehan!' he added with mock
solemnity, 'thou art of a truth a lucky devil! Thou canst keep thine own
name, thine own rank, even thine own ludicrous stutter: whereas I,—what
shall I be? A mime! A buffoon! And what's more, a fraudulent varlet,
pledged to deceive an innocent wench into the belief that her future lord is
both sentimental and amorous and can sing the love ditties writ by Messire
de Ronsard with passable tunefulness.... Ye gods, Jehan, hast ever heard
Monsieur Duc d'Anjou—the real one, I mean—sing?'

'N-n-n-no!' objected Jehan in pious horror, for he did not like to hear so
exalted a personage derided.

'Then hast ever heard the barn-door rooster calling to his favourite hen?'

'S-s-s-s-sometimes!'

'Well!' quoth Gilles lightly, 'so have I. And I prefer the barn-door rooster!
And now to bed, friend Jehan,' he added as he jumped to his feet. 'To-
morrow is the great day! Didst take my letter to the governor's palace?'

'I d-d-d-did.'

'And didst see Monseigneur the governor himself?'

Jehan nodded affirmatively.

'Gave him my letter?'

Another nod from Jehan.


'Did he look pleased?'

A shrug of the shoulders this time.

'Said he would be honoured to see Monseigneur le Duc d'Alençon et


d'Anjou at the banquet to-morrow?'

Once again a nod.

'Then to bed, chatterbox!' concluded Gilles gaily, 'for to-morrow I begin


my career as a low, deceitful hound, fit only for the gibbet, which I dare
swear is already prepared for me!'

III

Jehan helped his master to undress. He pulled off the heavy boots and
laid aside the cloth jerkin, the kerseymere trunks and worsted hose. Then,
when Messire Gilles lay stretched out upon the hard paillasse, honest Jehan
bade him a quiet good night and went off carrying the guttering candle. For
one candle had to do duty for two customers, or even at times for three, at
the hostel of 'Les Trois Rois.' These were not days of luxurious
caravanserai: eight square feet of floor space, a tiny leaded window, a straw
paillasse, perhaps a table and a rickety chair, made up the sum total of a
furnished bedroom, if destined for a person of quality. Men like Maître
Jehan had to be content with the bare boards and a horse-blanket outside
their master's door, or behind a wooden partition set up inside the latter's
room.

Jehan went off, then, with the candle, and Gilles de Crohin remained in
almost total darkness, for the light of the moon failed to penetrate through
the narrow aperture which went by the name of window. For a long time
Messire Gilles lay motionless, staring into the gloom. Vague pictures
seemed to flit before his gaze: the unknown girl whom he was pledged to
woo appeared and disappeared before him, now walking across his line of
vision with stately dignity, now dancing a wild rigadoon like some unruly
country wench; but always, and with irritating persistence, wearing a mask
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like