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

Dive Into Algorithms: A Pythonic Adventure For The Intrepid Beginner 1st Edition Bradford Tuckfield

Uploaded by

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

Dive Into Algorithms: A Pythonic Adventure For The Intrepid Beginner 1st Edition Bradford Tuckfield

Uploaded by

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

Full download textbook at textbookfull.

com

Dive Into Algorithms: A Pythonic Adventure for the


Intrepid Beginner 1st Edition Bradford Tuckfield

https://textbookfull.com/product/dive-into-algorithms-a-
pythonic-adventure-for-the-intrepid-beginner-1st-edition-
bradford-tuckfield-2/

OR CLICK BUTTON

DOWLOAD EBOOK

Download more textbookfull from https://textbookfull.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Dive Into Algorithms: A Pythonic Adventure for the


Intrepid Beginner 1st Edition Bradford Tuckfield

https://textbookfull.com/product/dive-into-algorithms-a-pythonic-
adventure-for-the-intrepid-beginner-1st-edition-bradford-
tuckfield-2/

A deep dive into NoSQL databases the use cases and


applications First Edition Raj

https://textbookfull.com/product/a-deep-dive-into-nosql-
databases-the-use-cases-and-applications-first-edition-raj/

Deep Dive into Power Automate: Learn by Example 1st


Edition Mishra

https://textbookfull.com/product/deep-dive-into-power-automate-
learn-by-example-1st-edition-mishra/

Windows Security Internals - A Deep Dive into Windows


Authentication, Authorization, and Auditing (for True
Epub) 1st Edition James Forshaw

https://textbookfull.com/product/windows-security-internals-a-
deep-dive-into-windows-authentication-authorization-and-auditing-
for-true-epub-1st-edition-james-forshaw/
Kubernetes Up and Running Dive into the Future of
Infrastructure 1st Edition Kelsey Hightower

https://textbookfull.com/product/kubernetes-up-and-running-dive-
into-the-future-of-infrastructure-1st-edition-kelsey-hightower/

Database Internals A Deep Dive into How Distributed


Data Systems Work Alex Petrov

https://textbookfull.com/product/database-internals-a-deep-dive-
into-how-distributed-data-systems-work-alex-petrov/

Practical Modern JavaScript Dive into ES6 and the


Future of JavaScript Nicolás Bevacqua

https://textbookfull.com/product/practical-modern-javascript-
dive-into-es6-and-the-future-of-javascript-nicolas-bevacqua/

Windows Security Internals: A Deep Dive into Windows


Authentication, Authorization, and Auditing 1 /
converted Edition James Forshaw

https://textbookfull.com/product/windows-security-internals-a-
deep-dive-into-windows-authentication-authorization-and-
auditing-1-converted-edition-james-forshaw/

Programming IOS 12 Dive Deep Into Views View


Controllers and Frameworks 1st Edition Matt Neuburg

https://textbookfull.com/product/programming-ios-12-dive-deep-
into-views-view-controllers-and-frameworks-1st-edition-matt-
neuburg/
DIVE INTO
ALGORITHMS
A P Y T H O N I C A D V E N T U R E
F O R T H E I N T R E P I D B E G I N N E R

BRADFORD TUCKFIELD
DIVE INTO
ALGORITHMS
A Pythonic Adventure for
the Intrepid Beginner

Br a d for d Tu c kf i e ld
DIVE INTO ALGORITHMS. Copyright © 2021 by Bradford Tuckfield

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.

ISBN-13: 978-1-71850-068-6 (print)


ISBN-13: 978-1-71850-069-3 (ebook)

Publisher: William Pollock


Execuitve Editor: Barbara Yien
Production Editors: Maureen Forys, Happenstance Type-O-Rama and Laurel Chun
Developmental Editor: Alex Freed
Cover Design: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Alok Malik
Copyeditor: Scout Festa
Compositor: Jeff Lytle, Happenstance Type-O-Rama
Proofreader: Rachel Monaghan
Illustrator: Jeff Wilson, Happenstance Type-O-Rama
Indexer: Valerie Perry

For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; [email protected]
www.nostarch.com

Library of Congress Cataloging-in-Publication Data

Names: Tuckfield, Bradford, author.


Title: Dive into algorithms / Bradford Tuckfield.
Description: San Francisco : No Starch Press, [2020] | Includes index.
Identifiers: LCCN 2020026327 (print) | LCCN 2020026328 (ebook) | ISBN
9781718500686 (paperback) | ISBN 1718500688 (paperback) | ISBN
9781718500693 (ebook)
Subjects: LCSH: Computer algorithms. | Computer programming.
Classification: LCC QA76.9.A43 T83 2020 (print) | LCC QA76.9.A43 (ebook)
| DDC 005.13--dc23
LC record available at https://lccn.loc.gov/2020026327
LC ebook record available at https://lccn.loc.gov/2020026328

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other
product and company names mentioned herein may be the trademarks of their respective owners. Rather
than use a trademark symbol with every occurrence of a trademarked name, we are using the names only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of
the trademark.

The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in it.
Dedicated to my parents, David and Becky
Tuckfield, for believing in me and for
teaching me la pipopipette.
About the Author
Bradford Tuckfield is a data scientist and writer. He runs a data science con-
sulting firm called Kmbara (https://kmbara.com/) and a fiction website called
Dreamtigers (http://thedreamtigers.com/).

About the Technical Reviewer


Alok Malik is a data scientist based in New Delhi, India. He works on devel-
oping deep learning models in both natural language processing and com-
puter vision with Python. He has developed and deployed solutions such as
language models, image and text classifiers, language translators, speech-
to-text models, named entity recognizers, and object detectors. He has also
co-authored a book on machine learning. In his free time he likes to read
about finance, do MOOCs, and play video games on his console.
BRIEF CONTENTS

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Chapter 1: Problem-Solving With Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Chapter 2: Algorithms in History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Chapter 3: Maximizing and Minimizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Chapter 4: Sorting and Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Chapter 5: Pure Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

Chapter 6: Advanced Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Chapter 7: Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

Chapter 8: Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Chapter 9: Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

Chapter 10: Artificial Intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

Chapter 11: Forging Ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
CONTE NT S IN DE TA IL

ACKNOWLEDGMENTS xiii

INTRODUCTION xv
Who Is This Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
Setting Up the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Install Python on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Install Python on macOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Install Python on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Installing Third-Party Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

1
PROBLEM-SOLVING WITH ALGORITHMS 1
The Analytic Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Galilean Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Solve-for-x Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Inner Physicist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Algorithmic Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Thinking with Your Neck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Applying Chapman’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Solving Problems with Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2
ALGORITHMS IN HISTORY 13
Russian Peasant Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Doing RPM by Hand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Implementing RPM in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Euclid’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Doing Euclid’s Algorithm by Hand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Implementing Euclid’s Algorithm in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Japanese Magic Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Creating the Luo Shu Square in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Implementing Kurushima’s Algorithm in Python . . . . . . . . . . . . . . . . . . . . . . . . 24
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

3
MAXIMIZING AND MINIMIZING 35
Setting Tax Rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Steps in the Right Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Turning the Steps into an Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Objections to Gradient Ascent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
The Problem of Local Extrema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Education and Lifetime Income . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Climbing the Education Hill—the Right Way . . . . . . . . . . . . . . . . . . . . . . . . . 44
From Maximization to Minimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Hill Climbing in General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
When Not to Use an Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4
SORTING AND SEARCHING 51
Insertion Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Putting the Insertion in Insertion Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Sorting via Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Measuring Algorithm Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Why Aim for Efficiency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Measuring Time Precisely . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Counting Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Comparing to Well-Known Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Adding Even More Theoretical Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Using Big O Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Merge Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
From Merging to Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Sleep Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
From Sorting to Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Applications of Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

5
PURE MATH 77
Continued Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Compressing and Communicating Phi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
More about Continued Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
An Algorithm for Generating Continued Fractions . . . . . . . . . . . . . . . . . . . . . 82
From Decimals to Continued Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
From Fractions to Radicals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Square Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The Babylonian Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Square Roots in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Random Number Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
The Possibility of Randomness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Linear Congruential Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Judging a PRNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Diehard Tests for Randomness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Linear Feedback Shift Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

x Contents in Detail
6
ADVANCED OPTIMIZATION 101
Life of a Salesman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Setting Up the Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Brains vs. Brawn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
The Nearest Neighbor Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Implementing Nearest Neighbor Search . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Checking for Further Improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Algorithms for the Avaricious . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Introducing the Temperature Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Simulated Annealing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Tuning Our Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Avoiding Major Setbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Allowing Resets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Testing Our Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

7
GEOMETRY 125
The Postmaster Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Triangles 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Advanced Graduate-Level Triangle Studies . . . . . . . . . . . . . . . . . . . . . . . . . 130
Finding the Circumcenter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Increasing Our Plotting Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Delaunay Triangulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Incrementally Generating Delaunay Triangulations . . . . . . . . . . . . . . . . . . . . 136
Implementing Delaunay Triangulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
From Delaunay to Voronoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

8
LANGUAGE 149
Why Language Algorithms Are Hard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Space Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Defining a Word List and Finding Words . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Dealing with Compound Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Checking Between Existing Spaces for Potential Words . . . . . . . . . . . . . . . . . 153
Using an Imported Corpus to Check for Valid Words . . . . . . . . . . . . . . . . . . 154
Finding First and Second Halves of Potential Words . . . . . . . . . . . . . . . . . . . 156
Phrase Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Tokenizing and Getting N-grams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Our Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Finding Candidate n + 1-grams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Selecting a Phrase Based on Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Contents in Detail xi
9
MACHINE LEARNING 165
Decision Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Building a Decision Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Downloading Our Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Looking at the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Splitting Our Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Smarter Splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Choosing Splitting Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Adding Depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Evaluating Our Decision Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
The Problem of Overfitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Improvements and Refinements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Random Forests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

10
ARTIFICIAL INTELLIGENCE 185
La Pipopipette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Drawing the Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Representing Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Scoring Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Game Trees and How to Win a Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Building Our Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Winning a Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Adding Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

11
FORGING AHEAD 201
Doing More with Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Building a Chatbot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Text Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Vector Similarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Becoming Better and Faster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Algorithms for the Ambitious . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Solving the Deepest Mysteries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

INDEX 215

xii Contents in Detail


ACKNOWLEDGMENTS

“A word is not the same with one writer as it is with another. One tears it
from his guts. The other pulls it out of his overcoat pocket.” This is how
Charles Peguy described writing individual words. The same thing is true
of chapters and whole books. At times, it felt like I was pulling this book
out of my overcoat pocket. At other times, it felt like I was tearing it from
my guts. It seems appropriate to acknowledge everyone who contributed to
the long process, either by loaning me an overcoat or by helping me clean
up my spilled guts.
Many kind people helped me on the long path I took to gain the expe-
rience and skills required to write this book. My parents, David and Becky
Tuckfield, gave me so many gifts, starting with life and education, and con-
tinued to believe in me, encourage me, and help me in many other ways too
numerous to list here. Scott Robertson gave me my first job writing code,
even though I was unqualified and not very good. Randy Jenson gave me my
first data science job, again despite my inexperience and limitations. Kumar
Kashyap gave me my first chance to lead a development team to implement
algorithms. David Zou was the first person to pay me for writing an article
($10 minus PayPal fees for 10 short movie reviews), and that felt so good, it
put me on a path to writing more. Aditya Date was the first person to sug-
gest that I write a book and gave me my first chance to do so.
I also received encouragement from many teachers and mentors. David
Cardon gave me my first chance to collaborate on academic research,
and taught me many things during that process. Bryan Skelton and
Leonard Woo showed me examples of what I wanted to grow up to be. Wes
Hutchinson taught me crucial algorithms, like k-means clustering, and
helped me better understand how algorithms work. Chad Emmett taught
me how to think about history and culture, and Chapter 2 is dedicated to
him. Uri Simonsohn showed me how to think about data.
Some people helped to make the process of writing this book a joy.
Seshu Edala helped me adjust my work schedule to be able to write, and
provided constant encouragement. Alex Freed was a joy to work with dur-
ing the editing process. Jennifer Eagar, via Venmo transfer months before
initial publication, unofficially became the first person to buy a copy of the
book; that was appreciated during a difficult time. Hlaing Hlaing Tun was
supportive, helpful, sweet, and encouraging at every step.
I cannot repay all of these debts of gratitude, but at least I can say thank
you. Thank you!

xiv Acknowledgments
Another random document with
no related content on Scribd:
fierce bark; but Juliet being absolutely fearless of animals,
spoke soothingly to him and patted his broad head,
whereupon his bark subsided into a whine, and he wagged
his stump of a tail.

"Why, Sykes has quickly made friends with you,"


exclaimed Flossie, in surprise; "he is most suspicious of
strangers, as a rule."

With that Flossie used the knocker vigorously, and, after


some delay, the door was opened by a very untidy maid-of-
all-work.

"Come in," said Flossie cheerfully.

And Juliet followed her across the threshold, not without


an uneasy thought of how her mother would feel if she
could see her.

CHAPTER III
A PEEP INTO BOHEMIA

FLOSSIE CHALCOMBE led Juliet into a square, lofty


room, which was the dining-room of the house.

It was not an ill-furnished room, but it looked dingy,


and had, even to Juliet's unobservant eyes, a most untidy
appearance, whilst her sensitive nostrils were at once aware
of the disagreeable odour of stale tobacco.
The ceiling was darkened by smoke; the curtains, once
white, had, under the strain of smoke and dust from within,
and damp and smuts from without, developed a greyish
hue; the carpet, once handsome, was discoloured and
threadbare, rather, perhaps, from the effects of careless
usage than as the result of long service; a pipe-rack and a
tobacco jar appeared amongst other odd ornaments on the
mantelpiece, and the pier-glass above it presented a curious
effect, being bordered on each side as high as hands could
reach with papers, play-bills, photographs, etc., stuck for
security within its rim. The chairs were of oak, curiously
carved, with crimson leather seats. A handsome sideboard
with a plate-glass back stood on one side, presenting an
array of flagons and decanters flanked by a black bottle or
two. A plated spirit-stand was in the centre. The cut-glass
decanter labelled "whisky" had been drawn out and stood
on the table beside two empty glasses. Near the door a
cottage piano stood open, the top littered with sheets of
music, and on the music-stand a piece bearing on its cover
a marvellous representation of a gentleman in extravagantly
fashionable attire making his bow to an imaginary audience.

As Juliet glanced round her, the misgivings with which


she had entered the house increased.

"Is father at home?" Flossie asked of the servant, as her


eyes fell on the empty glasses.

The maid answered in the affirmative.

Flossie slightly shrugged her shoulders, and Juliet


fancied she was not best pleased.

"Make us some tea, Maria, as quickly as you can," said


Flossie, "and let it be strong, mind. And stay, you had better
run to the nearest shop for a cake; I don't suppose there is
any in the house."

"Oh, Flossie, please don't," began Juliet.

"Nonsense, Juliet!" Flossie checked her laughingly. "I


may surely order cake if I like. I want some, it you do not."

"But I really ought not to stay," faltered Juliet.

"You are not going till you have had some tea, so
there," said Flossie imperiously. "Excuse me one moment."
And she disappeared.

Juliet heartily wished that she had not entered the


house. She foresaw that the maid's getting tea would be a
long business; but it seemed impossible to hurry away now
without hurting Flossie's feelings.

"What would Hannah say if she could see me!" she


thought. "How shocked Salome, who always wears the blue
ribbon, would be if she saw that sideboard!"

In fact, Juliet was slightly shocked herself. Decidedly the


people who dwelt in this house were of a different set from
her own. What a strange, disorderly room it was! She
glanced at the pier-glass, and saw the likeness of a ballet-
girl taken in such extreme attire, that, though she was
alone, Juliet instinctively lowered her eyes with a sense of
shame. But ere she had time to observe more there was a
sound of voices in the hall, and Flossie entered followed by
her brother.

"Juliet, this is Algernon, who has been wishing so much


to make your acquaintance. I hardly thought he would be at
home, but—"
"Fortune has been kind to me," added her brother, in a
low, rich voice, as she hesitated.

The colour flew into Juliet's cheeks and deepened as she


met the frankly admiring glance of Flossie's brother. She
hardly knew how she acknowledged the introduction, so
conscious was she of those tiresome blushes and the timid
fluttering of her heart.

But there was nothing formidable in the appearance of


Algernon Chalcombe, unless it were his extreme
handsomeness. Juliet saw before her a well-formed,
graceful man of middle height, whose dark beauty was well
set off by the crimson and black "blazer" which he wore. His
black hair was rather long and inclined to curl; he had fine
dark lustrous eyes and regular features. The mouth was
rather large in proportion to the rest of the face, with full
lips, the chin large, full, and rounded. He had been told that
he resembled the portraits of Lord Byron, and the
suggestion flattered his vanity. He was amply endowed with
that commodity, and his countenance revealed its presence,
and betrayed tokens too of luxurious, self-indulgent habits.

But Juliet had not the experience that could discern


these. She was struck with the graceful bearing and
polished ease of the young man. Although his eyes plainly
expressed admiration for her, there was no insolence in
their gaze. On the contrary, he contrived to infuse into his
manner a subtle suggestion of self-depreciation and
humility inspired by her presence, and his tone in
addressing her was charmingly deferential.

"He is a perfect gentleman," thought Juliet, with a sense


of agreeable surprise.
And certainly Algernon Chalcombe lacked none of the
externals of a gentleman. It had been his father's ambition
to make him such, and his education had been expensive,
and therefore presumably good. It had even comprised a
sojourn at Oxford, but his career at the University had come
to an abrupt termination, and he had reasons for preferring
not to speak of that period of his life. At Oxford and
elsewhere he had courted the society of men of a higher
social standing than his own, and had been quick to catch
their tone and learn their habits.

Thus it was that Juliet discerned in him what she took to


be tokens of high breeding and superior personal
refinement. Having no brother, and belonging to a wholly
feminine household, her ideas as to what constitutes a
gentleman were perhaps more crude than are those of most
girls. Certain it is that Algernon Chalcombe's ready
courtesy, his pleasant accent, the well-made garments
which he wore with such careless grace, his white hands
and polished nails, all combined to produce on her the
impression of a personal distinction and innate chivalry
befitting a hero of romance. Juliet had read few romances—
Hannah had seen to that—but perhaps just because they
were so few, those she had read had made the more
impression on her vivid imagination.

Flossie was quick to see how Juliet was struck by


Algernon's appearance and bearing. She was delighted, for
she was very fond of this brother seven years older than
herself. She was able to make a hero of him in her way,
though she saw him under other aspects than that which he
was so studiously presenting to Juliet.

"This is not the first time that I have had the pleasure of
seeing you, Miss Tracy," remarked Algernon Chalcombe.
"Flossie pointed you out to me at your school concert."
"Yes, so she told me," said Juliet hurriedly, blushing
deeply the next moment, as she remembered all Flossie had
said when she told her.

He did not appear conscious of her confusion, though in


reality, he thought how pretty she looked when she
blushed, and what a fresh, naïve, charming little girl she
was.

"It was rather a slow affair that school concert, was it


not?" he said, in his full, deep tones, with the fine drawl he
affected.

"Oh yes—at least I do not know that I found it so,"


Juliet corrected herself; "but then I knew beforehand what
it would be like. One cannot expect anything very startling
at a school concert, when only the pupils perform. Of course
it must have seemed a dull affair to you."

"Oh no; I liked it very much. I do not mean to say that I


enjoyed the music particularly, but I liked being there. I was
disappointed, though, to find that you were not amongst
the performers. I had hoped to hear you play or sing."

"Flossie could have told you that was impossible. I do


not learn music at school. I do not learn at all now, in fact."

"Do you really mean it? And yet I am sure you are
musical."

Juliet shook her head. "I am afraid not. I am very fond


of music, but I cannot play much. Salome used to teach
me, but she gave me up in despair; and, indeed, I could
never learn of her. We used to quarrel at every lesson."

"I don't wonder, if she taught you," said Flossie.


"Mother wanted me to have lessons of someone else,
but Hannah said that would be an extravagance, when
Salome is so well qualified to teach me. She gives lessons in
music, you know, and is said to have an admirable method
of training young strummers. I know her playing is quite
correct, and all that, but can never feel that there is any
music in it, somehow."

"I know the kind of playing you mean," said Algernon;


"this is it, is it not?" He turned quickly to the piano, sat
down and played a little air of Beethoven's; played it
correctly, coldly, the time strictly accented, but without the
least expression.

"That's it—that's it exactly!" exclaimed Juliet, delighted.


"Salome always plays in that hard, woodeny manner."

"Do you know anyone who plays like this?" he asked.


His hands now wandered over the keys in uncertain,
fluttering movements, one hand always a little behind the
other, as in staccato fashion, he struck out "Ye Banks and
Braes."

"Oh yes, yes," said Juliet; "I have heard people play like
that."

"What do you think of this?" he asked next. His hands


descended with a crash upon the piano, tore at the notes,
flew up and down the keyboard. Crash followed crash, run
pursued run, there was a tumult in which hammer and
tongs, tin-whistle and wooden drum might have been taking
part, assisted by an enraged cat. The piano rocked beneath
the violent onslaught, the room seemed to shake with it;
then, suddenly, the din ceased, and the performer leaned
back from the stool, laughing.

Flossie and Juliet were laughing too.


"Whatever is that remarkable composition?" asked his
sister.

"'Battle, Murder, and Sudden Death,' an impromptu, by


Algernon Chalcombe," he answered gravely.

"Won't you sing something to Juliet, now she is here?"


suggested his sister. "She wants so much to hear you sing."

The colour rose in Juliet's face. She looked half-


ashamed of hearing such a thing said. But the suggestion
was very agreeable to Algernon Chalcombe.

"With pleasure, if she wishes it," he said, in his low,


musical tones. "Her wish is a command to me."

He sang a song which was comic without being vulgar.


His singing was very spirited, and his full, rich baritone was
delightful to listen to. But when Juliet asked for another
song, he chose one of a very different description. It was
Blumenthal's "My Queen," and he sang it with great power
and feeling.

The song is familiar enough to most persons now, but


Juliet had not heard it before, and she was thrilled by the
beauty of the words and the music. Still more was she
thrilled when Algernon at its conclusion suddenly lifted his
dark eyes to hers, and looked at her with a glance that
seemed charged with unutterable meanings. Juliet trembled
under the magnetism of that glance. She rose and looked
about for her gloves, feeling a sudden desire to get away.
But the tea had not yet appeared, and till now she had been
unconscious how time was passing.

"You must not think of going yet," said Algernon, in his


low, deep voice, as he came to her side. "Won't you sing
something to me now? I am sure that you sing."
"Yes, indeed; she sings beautifully," exclaimed Flossie;
"her voice is as clear as a bird's. Do sing, Juliet."

"Oh, I cannot! I never sing, except sometimes with


mother some of the old songs that she used to sing when
she was a girl."

"Won't you let me hear one of them?" said Algernon


persuasively. "I love those good old songs."

"Oh no, indeed! I cannot sing, really," protested Juliet.

"Oh, but you must, you shall!" exclaimed Flossie. "I


won't let you off, Juliet."

But her brother gravely interposed.

"Stay, Flossie. Miss Tracy shall not be urged to sing if


the idea is really disagreeable to her. Of course it would
have given me great pleasure; but it shall be just as she
likes."

Juliet immediately felt convicted of ingratitude. He had


been so kind in singing to her, it seemed horrid of her to
refuse to gratify him in her turn.

"I will try, if you like," she faltered; "but you must
please go to the other end of the room and promise not to
listen."

"I cannot promise that," he said, with a gleam of


amusement in his eyes, "but I assure you I will not listen
critically."

He moved away as he spoke, and Juliet, sitting down at


the piano, struck a few notes in uncertain fashion, and then
trilled forth the sweet old song, "Where the bee sucks, there
lurk I."

She loved singing, and in a few moments, she had


forgotten her nervousness. Her voice was untrained, but it
was singularly sweet and clear. Algernon, as he stood
carelessly with his hands in his pockets looking out of the
window, expected only to be amused by some school-girlish
warbling. He was amazed at the strength and purity of the
full, clear notes.

But Algernon Chalcombe was not the only listener who


was surprised and delighted by the sweet, bird-like notes.
As Juliet sang the last verse, a shuffling tread was heard
crossing the hall towards the half-open door, and the next
moment, Mr. Chalcombe senior entered the room.

He was a short, stoutish man, with a highly coloured


complexion and a round bullet head, but scantily covered
with greyish hair. Late though it was in the afternoon, he
wore what he was wont to describe as his "dishabilles," a
gay, much-beflowered dressing-gown, considerably the
worse for wear, whilst on his feet were a pair of old carpet
slippers, the easiness of which was an advantage
counterbalanced by the difficulty of keeping on the loose,
downtrodden things.

Flossie's face flushed as her father entered, and an


impatient frown appeared on that of Algernon; but Mr.
Chalcombe's face beamed with good-nature. He had no
misgivings as to his welcome as he joined the little party.

"Bravo! Bravo!" he cried heartily as Juliet finished her


song. "I congratulate you, young lady, whoever you are, on
having such a voice as that."
"Father, this is Miss Tracy," said Flossie, in a tone
suggestive of remonstrance.

"To be sure. Juliet Tracy, your chum at the 'igh school.


I've often 'eard of you, my dear. You two are in the same
class, ar'n't you? It's a mighty fine thing, that 'igh school.
You young people nowadays 'ave great advantages. My
hedjucation was all crowded into three years, which left
little time for putting on the polish. Ha, ha! But there, I've
done very well without it." And Mr. Chalcombe struck the
table sharply with his hand, by way of giving emphasis to
his words.

His son looked much annoyed. He moved quickly to


Juliet's side, saying in a low voice, with an evident desire to
cover his father's want of taste—

"Thank you so much, Miss Tracy. Your voice is indeed


beautiful. One does not often have the chance of hearing
such."

"Oh, but my singing is not good," said Juliet, looking


much pleased, however. "You see, I have had no proper
training."

"Yes, yes, I can tell that," said Mr. Chalcombe, taking


the remark as addressed to him; "but it's not too late for it
to be cultivated, and it's a lovely voice. You might make
your fortune on the stage with such a voice as that."

Juliet looked at the speaker with a startled air. At the


first moment she saw him and heard him speak, she had
been conscious of a sensation of strong repulsion from one
who was obviously such a vulgar member of society. But
now his words were so agreeably suggestive and flattering
to her self-love that she was disposed to view him more
favourably.
"The stage!" she exclaimed. "Oh, I should never think of
going on the stage!"

"And why not?" he demanded. "It's my belief you'd be a


grand success as an opera singer. Patti, Neilson, Trebelli,
and all the rest of them would 'ave to look to their laurels
when you made your début. Oh, you need not laugh, my
dear; I'm not joking."

"I think you must be, when you prophesy such things as
that for me," said Juliet, with a merry laugh.

"Nonsense!" he exclaimed excitedly. "I tell you, there's


many a one sings at 'er Majesty's opera whose voice is a
less musical one than yours. You've 'eard Orféo?"

"I have heard nothing," said Juliet. "I have never been
to the theatre or the opera in my life."

"You don't mean that?"

"Indeed I do. My mother and sisters do not approve of


the theatre. They would never let me go."

Mr. Chalcombe muttered something that it was well


Juliet did not catch, since it was not complimentary to the
intelligence of her family. Flossie was listening rather
nervously to the talk going on between her father and her
friend. It was a relief to her that at this moment the maid
appeared bearing the tea-tray, which she placed with some
clatter on the table.

"Here's the tea at last!" Flossie exclaimed. "You must


have thought, Juliet, that it was never coming."

Thus reminded of the flight of time, Juliet glanced at the


clock, and was dismayed to see how late it was.
She rose from the piano. Algernon drew forward a chair
for her, brought her some tea, and waited on her
assiduously.

"Will you have some tea, father?" Flossie asked.

"No, thank you, my dear, no, thank you. Tea is all very
well for women-folks, but I like something stronger. Oh
dear, I am forgetting my letters! I must bid you good-day,
Miss Tracy. Now think over what I've said, and when you've
made up your mind, you come to me, and I'll put you in the
way of things. It's my belief that with proper training you
might soon be earning your thirty guineas a night, and
that's not a sum to be sniffed at, let me tell you."

"No, indeed!" exclaimed Flossie. "Only think, Juliet,


thirty guineas a night!"

"Juliet!" exclaimed Mr. Chalcombe. "There you are! The


very name for an opera singer. She might play Juliet to your
Romeo, eh, Algie? That would be the best use you could
make of your good looks, as I often tell you. Ha, ha, ha!"

And laughing at his own joke, Mr. Chalcombe shuffled


out of the room.

Juliet's cheeks were crimson as she sipped her tea,


trying to look unconscious. Presently, glancing at Algernon
Chalcombe, she perceived that he was gnawing his
moustache savagely, and appeared much put out.
Whereupon she reflected, not without sympathy, how trying
a person of his refinement must find it to be saddled with
such a parent.

"Have you really never been to a theatre, Juliet?" asked


Flossie.
"Never," said Juliet, "and I do not suppose I ever shall."

"Oh, do not say that!" exclaimed Flossie. "How I wish


you could go with us one, night! Father gets tickets for
everything, you know."

And Algernon's expressive eyes said that he wished it


too. But Juliet would not entertain such an idea for a
moment. She rose to take her leave, and was not to be
persuaded to stay longer.

As she hastened homewards at her quickest pace, her


mind was in a strangely excited state. She knew that she
might prepare to face a storm when she reached home, but
she did not quail at the prospect. Her knowledge of the
world seemed to have increased, and the horizon of her life
to have widened with the experience of the afternoon. Her
imagination played delightedly with words and looks which
had been full of pleasant insinuation, as well as with the
practical suggestions of Mr. Chalcombe senior. Her future
seemed to be quite bewilderingly full of wonderful
possibilities.

CHAPTER IV
CONTRITION

SALOME GRANT seated herself at the tea-table behind


the steaming urn. The clock on the mantelpiece had just
struck six, and six was the hour at which they took their
evening meal. The fact that Juliet had not yet come in was
no reason for delaying it. Salome prided herself on her
punctuality. Juliet could hardly be said to know what
punctuality meant.

It was always Salome who made the tea, and her tea
was excellent. She, indeed, attended generally to the
housekeeping. Carefully trained by the Scotch cousin in
whose home she had passed so many years, Salome had
developed into as notable a housekeeper as her teacher.
She was well versed in the niceties belonging to every
department of domestic management. Her jams were
always clear, her cakes light; her store cupboard never
seemed to get out of order, and it was a pleasure to look
into the linen-press, for Salome was a first-rate
needlewoman also, and prided herself on the way she
marked and kept the household linen.

Mrs. Tracy was well pleased, on the whole, to leave the


care of the household in her daughter's capable hands. She
was conscious that she was herself by no means a model
housekeeper. As she moved with Captain Tracy from station
to station, she had kept house in a careless, happy-go-lucky
fashion, and the captain had never grumbled, though he
seldom found it convenient to dine with his wife. But their
expenses, though there was little to show for them, had
mounted up wonderfully, and Mrs. Tracy had always an
uneasy sense that she was being cheated, without being
able to discover where the fraud originated.

Ere long they went to India, and there, as everyone


knows, housekeeping differs considerably from the prosaic
ordering of an English home. So Mrs. Tracy, on her return
from abroad, had been thankful to find Salome such a
clever manager, with quite an old head on her young
shoulders. The mother, with her delicate health and languid
dislike to exertion, had gradually fallen into the position of a
merely nominal ruler, content to perform only such
functions as her powerful prime minister would permit.

It had been necessary for Salome to leave school very


early, though for some years afterwards she had pursued
the study of music, with the result that she was now able,
by giving lessons, to earn a sum which more than covered
her modest personal expenses. There were times when
Salome felt keenly the deficiencies in her education and the
poverty of her mental attainments, compared with those of
Hannah. But her sister never assumed airs of superiority.
She was always ready to assure Salome that she had a
special gift for domestic economy, and served the family
interests as truly by her clever thrift and practical industry
as she herself did by means of the good salary she earned.

A close bond united the sisters, though their affection


was not demonstrative. Salome had the greatest admiration
for Hannah's intellectual ability, and gladly set her free to
devote her time to study, by undertaking Hannah's mending
and making in addition to her own. She held Hannah's
opinions in high esteem, and echoed them with a firm belief
that they were her own. The two held together in most
things, and on no matter were they more in accord than in
their criticism of Juliet, and their mother's mistaken
treatment of her.

Salome was pre-eminently a worker. Despite her many


home duties, her music lessons, her sewing, she yet found
time to take up outside work. She was a most exemplary
Sunday-school teacher, and Mr. Hayes, the Vicar of St.
Jude's, a church near The Poplars, counted on her help in
various branches of his parish work.
Mrs. Hayes, herself a woman of considerable energy,
which had to divide itself between the claims of her
husband's parish and those of her rather numerous family,
thought Miss Salome Grant a most excellent person, who
would prove just the wife that Mr. Ainger, their single
curate, needed; one who would make the very most of his
slender stipend, and be capable of superintending any
amount of cutting out and sewing for the poor of his parish,
to say nothing of the management of soup-kitchens and
blanket-clubs. Mr. Hayes was quite of the same opinion,
though he made a mental note of the fact that Miss Grant
was rather plain in appearance. But he himself had chosen
his wife on the same principle that he chose his boots and
broadcloth, for good wearing rather than showy qualities,
with the additional advantage, which Salome lacked, that
the lady had a few hundreds a year of her own.

Mr. Ainger, however, though ready to echo the praise


which the vicar's wife bestowed on Miss Grant, evinced no
desire to make her excellences his own. He remained
obtuse to every hint, and Mrs. Hayes could only sigh over
the perversity of men.

"Tea is ready, mother," said Salome, when she had filled


all the cups, and Mrs. Tracy still remained at a distance
bending over her needlework.

"In one moment, dear," said her mother; "I must finish
this, now it is so nearly done."

Salome looked annoyed as she watched her mother's


movements. Hannah had already taken her place at the
table.

"There!" exclaimed Mrs. Tracy, holding up to view a


tastefully made blue cotton blouse into which she had just
set the last stitch. "How will that suit the child? She wants
something cool to wear, now the weather has turned so
warm."

"It is pretty," said Salome, in a tone which seemed to


suggest that prettiness was a doubtful advantage.

"I do wonder, mother, when you will cease to think of


Juliet as a child," said Hannah.

"Oh, not yet, I hope," said Mrs. Tracy cheerfully,


pausing, to Salome's vexation, at the window to look up
and down the road ere taking her place at the table. "After
all, what is she but a child?" she added, as she turned
towards the table.

"She was nineteen last February," said Hannah, in her


most matter-of-fact tone. "I began to teach when I was
nineteen."

"Ah, yes, my dear; but you were always so different


from Juliet. And the youngest is usually more of a child than
the others. Besides, you two are so much older. Why, you,
Hannah, will be thirty on your next birthday."

"Yes, I shall be thirty," said Hannah calmly, with an air


which said she was above being sensitive on the score of
her age.

"Dear me, how old it makes me feel to think of having a


daughter who is thirty!" observed Mrs. Tracy. "That is the
worst of marrying young. You know, I was not twenty when
I married your father. Why, how strange it seems! I was
only a few months older than Juliet is now!"

"It is to be hoped that no one will be wanting to marry


Juliet yet," said Salome, with a short laugh. "I should pity
the man over whose household she presided."

"Oh, she would soon learn how to manage," said Mrs.


Tracy, in her easy way; "that sort of thing comes to girls
when they are married."

"I am not so sure of that," said Salome.

"Nor I," said Hannah. "It would certainly take Juliet a


long time to learn to be such a housekeeper as you are,
Salome. But Juliet must be taught to make herself useful
when she leaves school."

"And she must find some employment," said Salome,


"though I hardly know what she is fit for."

"Oh, there is time enough to consider that," said Mrs.


Tracy, with an air of uneasiness. "There she is!" she added
in a tone of relief, as Juliet's peculiar knock resounded
through the house.

"So you're having tea?" said Juliet, thrusting her pretty,


flushed face inside the door without entering. "I don't want
any; I've had mine."

And she was off ere any questions could be asked,


bounding upstairs three steps at a time.

"Where can she have had tea?" asked Salome


wonderingly of her sister. "Do you think she went home with
Frances Hayes?"

"Hardly. She and Frances have not seemed at all


friendly of late."

"With Dora Felgate, perhaps," suggested Mrs. Tracy.


"I do not think so," said Hannah; "Juliet is by no means
fond of Dora. I heard her call her a sneak only yesterday.
No, if you ask me, I should say that most probably Juliet
has been taking tea with her friend, Flossie Chalcombe."

"Oh no, Hannah," said Mrs. Tracy quickly; "Juliet would


not go there."

Hannah made no reply, but smiled in a peculiar and


exasperating manner. The subject was allowed to drop, but
all three were feeling intensely curious as to how Juliet had
passed the afternoon. That young lady did not appear to
satisfy their curiosity.

As soon as tea was over, Salome went upstairs to get


ready to go out. There was a committee meeting at the
vestry that evening which she had promised to attend. On
the first landing she paused, and, after a moment's
hesitation, tapped on the closed door of the room Juliet
shared with her mother.

"Come in!" rang out Juliet's voice, and Salome entered.

Juliet was seated on her little bed. She had not removed
her hat, but it was thrust far back from the flossy curly
mass of sunny hair above her forehead. Dusty shoes still
covered the little feet, which she was swinging to and fro in
undesirable proximity to the spotless counterpane.

Salome felt the natural irritation of an immaculate


housewife who had recently sustained the burdens of a
spring cleaning.

"Juliet, I wish you would not sit on your bed. It


impossible to keep the counterpane clean if you do so."
"Oh, did you only come to say that?" Juliet's accents
were provokingly cool.

Salome looked with angry disapproval at her flushed,


excited face and saucy eyes.

"Of course not. How could I know that you were sitting
on the bed till I opened the door? I came to ask if you really
would have nothing to eat. There are some nice fresh
scones downstairs."

"No, thank you, I am not hungry."

Juliet's tone expressed no gratitude. Already she divined


that Salome had come mainly from a desire to find out how
she had spent the afternoon.

"Where did you have tea?" asked Salome.

"With a friend," replied Juliet laconically, still retaining


her position on the bed, and swinging her feet faster than
before.

"Of course," replied Salome, with mild sarcasm; "I did


not suppose it was with an enemy. That is no answer to my
question."

"It is near enough," said Juliet. "I do not see that it


matters to you with whom I took tea."

"Really, Juliet, it is hard if a sister cannot ask so simple


a thing as that!"

"You may ask, of course,—as many questions as you


like,—but I do not feel bound to answer them."

"I must say, Juliet, you are very polite."


"And I must say you are very inquisitive."

"Pray do not let us quarrel about such a thing," said


Salome coldly. "You are welcome to make a mystery of it, if
you please, only I must say it does not look well that you
are ashamed to say with whom you have been taking tea."

And Salome quitted the room.

"I am not ashamed!" exclaimed Juliet, suddenly


springing from the bed and darting after her. "And you know
it is not my way to make mysteries of things. Since you are
so consumed by curiosity, I will inform you that I went
home with Flossie Chalcombe and had tea with her. There,
now; are you satisfied?" And Juliet went back to her room
flushed and triumphant.

A few minutes later, Salome, in her close-fitting,


deaconess-like bonnet, with her waterproof cloak neatly
folded on her arm, one or two dark clouds being apparent in
the evening sky, came into the room where Hannah and her
mother were sitting. Her face was rather more highly
coloured than usual; but it was in a quiet, composed
manner that she said—

"You were right about Juliet, Hannah. She has been


taking tea with the Chalcombes."

"You do not mean that?" exclaimed Hannah. "But I am


not surprised," she added the next moment.

Mrs. Tracy turned round with a startled air.

"Are you sure of what you are saying, Salome?" she


asked, with unusual incisiveness.

"Quite sure, mother. Juliet told me so herself."


"She was perhaps joking," suggested Mrs. Tracy.

"Oh no; I am sure she was not joking," said Salome


demurely. "But I must go now, or I shall be late." She
passed quickly from the room, and the next moment they
heard the hall door close behind her.

At the same instant, Mr. Ainger might have been seen


crossing the road from his lodgings on the opposite side.

There was silence in the room for some minutes after


she had gone. Mrs. Tracy was feeling intensely hurt and
mortified.

"I should think, mother," Hannah said at last, "you must


now see that it is desirable Juliet should take a situation as
soon as she leaves school."

"Not at a distance," replied Mrs. Tracy, in quick, agitated


tones. "I will not have my child sent away from me."

"It would be a very good thing for her to leave home for
a time," said Hannah quietly. "It seems the only way of
withdrawing her from undesirable connections."

"I will never give my consent to it!" said Mrs. Tracy, in


an excited manner. And she rose and went hurriedly from
the room, as if resolved not to listen further to Hannah's
views on the subject.

Juliet was standing before the dressing-table when her


mother entered their bedroom. She had removed her hat,
and was engaged in arranging, somewhat fastidiously, her
golden locks; but, careless as was her attitude, she was not
so much at ease as she appeared. For the last ten minutes
she had been hearing with the ears of her imagination the
discussion of her conduct that was probably taking place
below. Her reflections on the consequences of her
confession to Salome were not agreeable.

"Juliet," said Mrs. Tracy, when she had closed the door,
"I think you will break my heart."

Juliet had been hardening herself in anticipation of


reproof, but she had not expected such words as these. As
she heard her mother's faltering tones, and saw that there
were tears in her eyes, her own face fell, and she said in
tones that expressed unfeigned regret—

"Oh, mother! I am so sorry. I did not think you would


mind so very much."

"My dear, after what I said to you only the other day,
you must have known that I should very much dislike the
idea of your entering the Chalcombes' house."

"Well, yes, I suppose I did know it," Juliet acknowledged


ruefully; "but Flossie persuaded me so, and she taunted me
with being afraid of Hannah. I could not stand that. But I
am sorry if you are vexed with me. Oh dear! I am always
doing the wrong thing."

"It is because you are so thoughtless, dear. You always


act upon impulse. If only you would give yourself time to
reflect."

"Oh, mother, don't preach to me!" exclaimed Juliet


impatiently. "It is done now; and, after all, I am not entirely
sorry, for, do you know, I was singing to Flossie, and Mr.
Chalcombe heard me—"

"Oh, did you see him?" interrupted Mrs. Tracy, in a tone


of vexation.
"Yes, he came into the room when I was singing. He is a
vulgar little man, mother; but he knows about things, and
he said my voice was beautiful, and that if it were properly
trained I should be a great success as a public singer, and
earn lots of money. Only think, mother, how much better
that would be than teaching brats, as Hannah wants me to
do!"

"I don't agree with you, dear. The idea is not at all to
my mind."

"But, mother, would you not like to have a daughter


who could sing like Antoinette Sterling? Fancy, he said I
might earn thirty guineas a night! Only think! We should
soon be as rich as Crœsus!"

"I daresay," said Mrs. Tracy, with a faint smile; "but you
are a long way from that at present, my child. I expect he
only said it to flatter you. You must not dream of being a
public singer, Juliet. I hate the idea of a public career for a
woman. The quieter and simpler her life, the happier she is,
as a rule."

"I don't think so," said Juliet, vexed that her mother did
not share her elation. "I know I am sick to death of the
quietness and simplicity of my life. Oh! what is the matter,
mother?"

Her mother had sunk on to a chair, and was pressing


both hands to her temples. Her face was very pale.

"My head!" she moaned. "It has been aching all day, but
now the pain has grown almost unendurable. I believe I
shall have to go to bed."

"Oh dear it is all my fault!" exclaimed Juliet, greatly


distressed. "You must go to bed, mother dear, and I will
bathe your head with toilet vinegar, and give you the
medicine which always sends you to sleep."

And, contrite and remorseful, Juliet waited on her


mother in the deftest and tenderest manner. When, some
time later, she lay down in her own little bed, her mind was
still so uneasy that sleep did not come readily. She turned
from side to side, though cautiously, that she might not
disturb her mother, many times ere she fell asleep.

Mrs. Tracy, when once her dose began to take effect,


slept soundly. She woke in the early morning to find that
Juliet was already up and kneeling in her nightdress by the
fender, engaged in some mysterious operation.

"What are you doing, dear?" her mother asked.

"I am getting you a cup of tea," Juliet replied, as she


anxiously watched the little kettle she had placed to boil on
a spirit-lamp; "it will soon be ready now."

"You are very good, darling," Mrs. Tracy said, as Juliet


brought the cup of fragrant tea to her bedside. She liked
the refreshment of an early cup of tea, though it was an
indulgence she rarely allowed herself, since Salome
regarded it as an extravagance, and Hannah condemned
the habit as pernicious.

"How did you manage to get all the things?" Mrs. Tracy
asked, with pleased curiosity.

"I brought them up last night," Juliet said exultantly.

"I do believe you love me a little, Juliet," her mother


said.

"A little, mother! I love you a very great deal."


"Then, darling," said her mother, eager to embrace the
favourable opportunity, "you will not mind giving me a
promise that will be a great comfort to me."

"What is it?" Juliet asked reluctantly.

"Promise me you will not enter the Chalcombes' house


again."

Juliet was silent for a few moments, and her colour


deepened. She was not one to give a promise lightly, and
she did not want to bind herself thus. But when she met her
mother's tender, pleading glance, and noted how white and
weary-looking was the face which pressed the pillow, it
seemed impossible to refuse.

"I promise, mother," she said, in a low voice; and then


her mother drew the girl's face down to hers, and kissed
her with passionate warmth.

After all, the mother told herself with a throbbing heart,


she was a good and loving child, this wayward, spoilt Juliet.

CHAPTER V
A DISAGREEABLE PROSPECT

"AT last I have heard of the very thing for Juliet," said
Hannah, in tones of extreme satisfaction.
Mrs. Tracy looked up quickly from her needlework, her
face expressing some anxiety. Hannah had just returned
from an afternoon visit to the high school. It was a busy
time with the teachers, for the school year was drawing to
its close and the examinations were being held.

Already the beauty of the summer was past in London.


The suburban trees looked dim and dusty; the grass was
baked brown; the air was oppressively close and the sun's
heat torrid. Everyone was talking or thinking of the seaside.

"Miss Tucker invited me into her room for a little talk,"


continued Hannah, in response to her mother's questioning
glance. "She said she had heard of a situation which she
thought Juliet might take. It is at Hampstead—just to teach
two little girls. The elder, I believe, is only eight. Miss Tucker
thinks Juliet might do well there if she chose."

"If she chose!" The proviso was an important one. Mrs.


Tracy felt its significance.

"Miss Tucker says that she would have no hesitation in


recommending Juliet for the situation. She thinks she might
teach such little ones very nicely; but she is not fit to
undertake older ones, for she is not taking at all a high
place in the examinations."

Mrs. Tracy's countenance fell.

"Oh dear!" she said, with a sigh. "I am sorry to hear


that."

"It is the result of idleness rather than lack of ability,"


said Hannah severely. "If Juliet were really stupid, one could
forgive her. She trifles away her time with that horrid
Chalcombe girl instead of working. I don't know whether
you are aware, mother, that they are constantly together."
"Yes," said Salome, looking up from the accounts she
was carefully auditing. "I asked Frances Hayes yesterday
why she never came to see us now, and she said she
fancied that Juliet had ceased to care for her visits since she
had been so taken up with her new friend. Frances would
have nothing to say to such a girl. Her mother is too careful
of her."

Mrs. Tracy's colour rose. She looked annoyed—rather, it


is to be feared, with her elder daughters than with the
culprit they denounced.

"Perhaps Mrs. Hayes has cause to be distrustful of her


daughter," she said proudly. "I am not afraid for Juliet. She
is kind to that Chalcombe girl because she knows her to be
lonely and friendless in the school. The intimacy will
naturally cease when Juliet leaves school."

"I hope it will," said Hannah. "It is on that account that


I am anxious to lose no time in getting an engagement for
Juliet. This lady will want her from ten till five every day,
which will leave her little time to herself."

"I wonder what Juliet will say to it!" said Mrs. Tracy,
thinking aloud.

"It does not much natter what she says," returned


Hannah decisively. "She must be shown what is her duty.
The salary will be forty pounds. We cannot afford to throw
away such a chance. It is time Juliet helped to maintain
herself. Her clothes cost a good deal."

"Not very much," said Mrs. Tracy deprecatingly, "since I


make most of her things myself. Of course I see that it is a
good chance; but it will be hard for the dear child to get
into harness at once. She has been counting on a little extra
leisure, and meant to practise up her music. I had almost
promised her that she should have singing lessons."

"Surely, mother, you are not going to encourage, Juliet


in her absurd notion of becoming a public singer!" Salome
exclaimed.

"By no means, dear; but the child has certainly a


beautiful voice, and it is a pity that it should not be
cultivated."

"Of course, if you have money to throw away on such


lessons, there is no reason why you should not indulge her
whim," said Hannah coldly.

Mrs. Tracy flushed. The words stung her, coming as they


did from the one who contributed most largely to the
support of the household. But ere she could defend herself
against the insinuation they conveyed, the door opened,
and Juliet walked into the room.

Mrs. Tracy made a quick movement, which expressed to


her elder daughters her wish that no more should be said
on the subject at present. But Juliet saw the signal, and she
noted, too, her mother's flushed face and the excited air
worn by all three. Little escaped the keen observation of
that young lady. She felt sure that she had been under
discussion when her entrance broke off the conversation.

"Dear me! How very warm you all look!" she remarked
with the utmost sang-froid. "What agitating topic has
excited you so? You should really, from sanitary
considerations, avoid such discussions when the
thermometer stands at eighty degrees in the shade. I am
not surprised at you, mother darling; but I do wonder to
find Hannah and Salome showing so little good sense."

You might also like