100% found this document useful (2 votes)
92 views

Full Data Structures & Algorithm Analysis in C++ 4th Edition (Ebook PDF) Ebook All Chapters

ebook

Uploaded by

guminaktv
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
100% found this document useful (2 votes)
92 views

Full Data Structures & Algorithm Analysis in C++ 4th Edition (Ebook PDF) Ebook All Chapters

ebook

Uploaded by

guminaktv
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 ebook at ebooksecure.

com

Data Structures & Algorithm Analysis in C++


4th Edition (eBook PDF)

https://ebooksecure.com/product/data-structures-
algorithm-analysis-in-c-4th-edition-ebook-pdf/

Download more ebook from https://ebooksecure.com


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

Data Structures & Algorithm Analysis in C++ 4th Edition


(eBook PDF)

http://ebooksecure.com/product/data-structures-algorithm-
analysis-in-c-4th-edition-ebook-pdf/

(eBook PDF) Starting Out with Java: From Control


Structures through Data Structures 4th Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-data-structures-4th-edition/

Data Structures - eBook PDF

https://ebooksecure.com/download/data-structures-ebook-pdf/

C++ Programming. Program Design including Data


Structures 8th Edition D.S. Malik - eBook PDF

https://ebooksecure.com/download/c-programming-program-design-
including-data-structures-ebook-pdf/
(eBook PDF) Data Structures and Abstractions with Java
4th Edition

http://ebooksecure.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/

(eBook PDF) Data Structures and Abstractions with Java


4th Global Edition

http://ebooksecure.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-global-edition/

(eBook PDF) Data Structures and Other Objects Using


Java 4th Edition

http://ebooksecure.com/product/ebook-pdf-data-structures-and-
other-objects-using-java-4th-edition/

(eBook PDF) Data Structures and Problem Solving Using


Java 4th Edition

http://ebooksecure.com/product/ebook-pdf-data-structures-and-
problem-solving-using-java-4th-edition/

Data Structures & Algorithms in Python 1st Edition John


Canning - eBook PDF

https://ebooksecure.com/download/data-structures-algorithms-in-
python-ebook-pdf-2/
CO NTE NTS

Preface xv

Chapter 1 Programming: A General Overview 1


1.1 What’s This Book About? 1
1.2 Mathematics Review 2
1.2.1 Exponents 3
1.2.2 Logarithms 3
1.2.3 Series 4
1.2.4 Modular Arithmetic 5
1.2.5 The P Word 6
1.3 A Brief Introduction to Recursion 8
1.4 C++ Classes 12
1.4.1 Basic class Syntax 12
1.4.2 Extra Constructor Syntax and Accessors 13
1.4.3 Separation of Interface and Implementation 16
1.4.4 vector and string 19
1.5 C++ Details 21
1.5.1 Pointers 21
1.5.2 Lvalues, Rvalues, and References 23
1.5.3 Parameter Passing 25
1.5.4 Return Passing 27
1.5.5 std::swap and std::move 29
1.5.6 The Big-Five: Destructor, Copy Constructor, Move Constructor, Copy
Assignment operator=, Move Assignment operator= 30
1.5.7 C-style Arrays and Strings 35
1.6 Templates 36
1.6.1 Function Templates 37
1.6.2 Class Templates 38
1.6.3 Object, Comparable, and an Example 39
1.6.4 Function Objects 41
1.6.5 Separate Compilation of Class Templates 44
1.7 Using Matrices 44
1.7.1 The Data Members, Constructor, and Basic Accessors 44
1.7.2 operator[] 45
vii
viii Contents

1.7.3 Big-Five 46
Summary 46
Exercises 46
References 48

Chapter 2 Algorithm Analysis 51


2.1 Mathematical Background 51
2.2 Model 54
2.3 What to Analyze 54
2.4 Running-Time Calculations 57
2.4.1 A Simple Example 58
2.4.2 General Rules 58
2.4.3 Solutions for the Maximum Subsequence
Sum Problem 60
2.4.4 Logarithms in the Running Time 66
2.4.5 Limitations of Worst-Case Analysis 70
Summary 70
Exercises 71
References 76

Chapter 3 Lists, Stacks, and Queues 77


3.1 Abstract Data Types (ADTs) 77
3.2 The List ADT 78
3.2.1 Simple Array Implementation of Lists 78
3.2.2 Simple Linked Lists 79
3.3 vector and list in the STL 80
3.3.1 Iterators 82
3.3.2 Example: Using erase on a List 83
3.3.3 const_iterators 84
3.4 Implementation of vector 86
3.5 Implementation of list 91
3.6 The Stack ADT 103
3.6.1 Stack Model 103
3.6.2 Implementation of Stacks 104
3.6.3 Applications 104
3.7 The Queue ADT 112
3.7.1 Queue Model 113
3.7.2 Array Implementation of Queues 113
3.7.3 Applications of Queues 115
Summary 116
Exercises 116
Contents ix

Chapter 4 Trees 121


4.1 Preliminaries 121
4.1.1 Implementation of Trees 122
4.1.2 Tree Traversals with an Application 123
4.2 Binary Trees 126
4.2.1 Implementation 128
4.2.2 An Example: Expression Trees 128
4.3 The Search Tree ADT—Binary Search Trees 132
4.3.1 contains 134
4.3.2 findMin and findMax 135
4.3.3 insert 136
4.3.4 remove 139
4.3.5 Destructor and Copy Constructor 141
4.3.6 Average-Case Analysis 141
4.4 AVL Trees 144
4.4.1 Single Rotation 147
4.4.2 Double Rotation 149
4.5 Splay Trees 158
4.5.1 A Simple Idea (That Does Not Work) 158
4.5.2 Splaying 160
4.6 Tree Traversals (Revisited) 166
4.7 B-Trees 168
4.8 Sets and Maps in the Standard Library 173
4.8.1 Sets 173
4.8.2 Maps 174
4.8.3 Implementation of set and map 175
4.8.4 An Example That Uses Several Maps 176
Summary 181
Exercises 182
References 189

Chapter 5 Hashing 193


5.1 General Idea 193
5.2 Hash Function 194
5.3 Separate Chaining 196
5.4 Hash Tables without Linked Lists 201
5.4.1 Linear Probing 201
5.4.2 Quadratic Probing 202
5.4.3 Double Hashing 207
5.5 Rehashing 208
5.6 Hash Tables in the Standard Library 210
x Contents

5.7 Hash Tables with Worst-Case O(1) Access 212


5.7.1 Perfect Hashing 213
5.7.2 Cuckoo Hashing 215
5.7.3 Hopscotch Hashing 227
5.8 Universal Hashing 230
5.9 Extendible Hashing 233
Summary 236
Exercises 237
References 241

Chapter 6 Priority Queues (Heaps) 245


6.1 Model 245
6.2 Simple Implementations 246
6.3 Binary Heap 247
6.3.1 Structure Property 247
6.3.2 Heap-Order Property 248
6.3.3 Basic Heap Operations 249
6.3.4 Other Heap Operations 252
6.4 Applications of Priority Queues 257
6.4.1 The Selection Problem 258
6.4.2 Event Simulation 259
6.5 d-Heaps 260
6.6 Leftist Heaps 261
6.6.1 Leftist Heap Property 261
6.6.2 Leftist Heap Operations 262
6.7 Skew Heaps 269
6.8 Binomial Queues 271
6.8.1 Binomial Queue Structure 271
6.8.2 Binomial Queue Operations 271
6.8.3 Implementation of Binomial Queues 276
6.9 Priority Queues in the Standard Library 282
Summary 283
Exercises 283
References 288

Chapter 7 Sorting 291


7.1 Preliminaries 291
7.2 Insertion Sort 292
7.2.1 The Algorithm 292
7.2.2 STL Implementation of Insertion Sort 293
7.2.3 Analysis of Insertion Sort 294
7.3 A Lower Bound for Simple Sorting Algorithms 295
Contents xi

7.4 Shellsort 296


7.4.1 Worst-Case Analysis of Shellsort 297
7.5 Heapsort 300
7.5.1 Analysis of Heapsort 301
7.6 Mergesort 304
7.6.1 Analysis of Mergesort 306
7.7 Quicksort 309
7.7.1 Picking the Pivot 311
7.7.2 Partitioning Strategy 313
7.7.3 Small Arrays 315
7.7.4 Actual Quicksort Routines 315
7.7.5 Analysis of Quicksort 318
7.7.6 A Linear-Expected-Time Algorithm for Selection 321
7.8 A General Lower Bound for Sorting 323
7.8.1 Decision Trees 323
7.9 Decision-Tree Lower Bounds for Selection Problems 325
7.10 Adversary Lower Bounds 328
7.11 Linear-Time Sorts: Bucket Sort and Radix Sort 331
7.12 External Sorting 336
7.12.1 Why We Need New Algorithms 336
7.12.2 Model for External Sorting 336
7.12.3 The Simple Algorithm 337
7.12.4 Multiway Merge 338
7.12.5 Polyphase Merge 339
7.12.6 Replacement Selection 340
Summary 341
Exercises 341
References 347

Chapter 8 The Disjoint Sets Class 351


8.1 Equivalence Relations 351
8.2 The Dynamic Equivalence Problem 352
8.3 Basic Data Structure 353
8.4 Smart Union Algorithms 357
8.5 Path Compression 360
8.6 Worst Case for Union-by-Rank and Path Compression 361
8.6.1 Slowly Growing Functions 362
8.6.2 An Analysis by Recursive Decomposition 362
8.6.3 An O( M log * N ) Bound 369
8.6.4 An O( M α(M, N) ) Bound 370
8.7 An Application 372
xii Contents

Summary 374
Exercises 375
References 376

Chapter 9 Graph Algorithms 379


9.1 Definitions 379
9.1.1 Representation of Graphs 380
9.2 Topological Sort 382
9.3 Shortest-Path Algorithms 386
9.3.1 Unweighted Shortest Paths 387
9.3.2 Dijkstra’s Algorithm 391
9.3.3 Graphs with Negative Edge Costs 400
9.3.4 Acyclic Graphs 400
9.3.5 All-Pairs Shortest Path 404
9.3.6 Shortest Path Example 404
9.4 Network Flow Problems 406
9.4.1 A Simple Maximum-Flow Algorithm 408
9.5 Minimum Spanning Tree 413
9.5.1 Prim’s Algorithm 414
9.5.2 Kruskal’s Algorithm 417
9.6 Applications of Depth-First Search 419
9.6.1 Undirected Graphs 420
9.6.2 Biconnectivity 421
9.6.3 Euler Circuits 425
9.6.4 Directed Graphs 429
9.6.5 Finding Strong Components 431
9.7 Introduction to NP-Completeness 432
9.7.1 Easy vs. Hard 433
9.7.2 The Class NP 434
9.7.3 NP-Complete Problems 434
Summary 437
Exercises 437
References 445

Chapter 10 Algorithm Design Techniques 449


10.1 Greedy Algorithms 449
10.1.1 A Simple Scheduling Problem 450
10.1.2 Huffman Codes 453
10.1.3 Approximate Bin Packing 459
10.2 Divide and Conquer 467
10.2.1 Running Time of Divide-and-Conquer Algorithms 468
10.2.2 Closest-Points Problem 470
Contents xiii

10.2.3 The Selection Problem 475


10.2.4 Theoretical Improvements for Arithmetic Problems 478
10.3 Dynamic Programming 482
10.3.1 Using a Table Instead of Recursion 483
10.3.2 Ordering Matrix Multiplications 485
10.3.3 Optimal Binary Search Tree 487
10.3.4 All-Pairs Shortest Path 491
10.4 Randomized Algorithms 494
10.4.1 Random-Number Generators 495
10.4.2 Skip Lists 500
10.4.3 Primality Testing 503
10.5 Backtracking Algorithms 506
10.5.1 The Turnpike Reconstruction Problem 506
10.5.2 Games 511
Summary 518
Exercises 518
References 527

Chapter 11 Amortized Analysis 533


11.1 An Unrelated Puzzle 534
11.2 Binomial Queues 534
11.3 Skew Heaps 539
11.4 Fibonacci Heaps 541
11.4.1 Cutting Nodes in Leftist Heaps 542
11.4.2 Lazy Merging for Binomial Queues 544
11.4.3 The Fibonacci Heap Operations 548
11.4.4 Proof of the Time Bound 549
11.5 Splay Trees 551
Summary 555
Exercises 556
References 557

Chapter 12 Advanced Data Structures


and Implementation 559
12.1 Top-Down Splay Trees 559
12.2 Red-Black Trees 566
12.2.1 Bottom-Up Insertion 567
12.2.2 Top-Down Red-Black Trees 568
12.2.3 Top-Down Deletion 570
12.3 Treaps 576
xiv Contents

12.4 Suffix Arrays and Suffix Trees 579


12.4.1 Suffix Arrays 580
12.4.2 Suffix Trees 583
12.4.3 Linear-Time Construction of Suffix Arrays and Suffix Trees 586
12.5 k-d Trees 596
12.6 Pairing Heaps 602
Summary 606
Exercises 608
References 612

Appendix A Separate Compilation of


Class Templates 615
A.1 Everything in the Header 616
A.2 Explicit Instantiation 616

Index 619
P R E FAC E

Purpose/Goals
The fourth edition of Data Structures and Algorithm Analysis in C++ describes data structures,
methods of organizing large amounts of data, and algorithm analysis, the estimation of the
running time of algorithms. As computers become faster and faster, the need for programs
that can handle large amounts of input becomes more acute. Paradoxically, this requires
more careful attention to efficiency, since inefficiencies in programs become most obvious
when input sizes are large. By analyzing an algorithm before it is actually coded, students
can decide if a particular solution will be feasible. For example, in this text students look at
specific problems and see how careful implementations can reduce the time constraint for
large amounts of data from centuries to less than a second. Therefore, no algorithm or data
structure is presented without an explanation of its running time. In some cases, minute
details that affect the running time of the implementation are explored.
Once a solution method is determined, a program must still be written. As computers
have become more powerful, the problems they must solve have become larger and more
complex, requiring development of more intricate programs. The goal of this text is to teach
students good programming and algorithm analysis skills simultaneously so that they can
develop such programs with the maximum amount of efficiency.
This book is suitable for either an advanced data structures course or a first-year
graduate course in algorithm analysis. Students should have some knowledge of inter-
mediate programming, including such topics as pointers, recursion, and object-based
programming, as well as some background in discrete math.

Approach
Although the material in this text is largely language-independent, programming requires
the use of a specific language. As the title implies, we have chosen C++ for this book.
C++ has become a leading systems programming language. In addition to fixing many
of the syntactic flaws of C, C++ provides direct constructs (the class and template) to
implement generic data structures as abstract data types.
The most difficult part of writing this book was deciding on the amount of C++ to
include. Use too many features of C++ and one gets an incomprehensible text; use too few
and you have little more than a C text that supports classes.
The approach we take is to present the material in an object-based approach. As such,
there is almost no use of inheritance in the text. We use class templates to describe generic
data structures. We generally avoid esoteric C++ features and use the vector and string
classes that are now part of the C++ standard. Previous editions have implemented class
templates by separating the class template interface from its implementation. Although
this is arguably the preferred approach, it exposes compiler problems that have made it xv
xvi Preface

difficult for readers to actually use the code. As a result, in this edition the online code
represents class templates as a single unit, with no separation of interface and implementa-
tion. Chapter 1 provides a review of the C++ features that are used throughout the text and
describes our approach to class templates. Appendix A describes how the class templates
could be rewritten to use separate compilation.
Complete versions of the data structures, in both C++ and Java, are available on
the Internet. We use similar coding conventions to make the parallels between the two
languages more evident.

Summary of the Most Significant Changes in the Fourth Edition


The fourth edition incorporates numerous bug fixes, and many parts of the book have
undergone revision to increase the clarity of presentation. In addition,

r Chapter 4 includes implementation of the AVL tree deletion algorithm—a topic often
requested by readers.
r Chapter 5 has been extensively revised and enlarged and now contains material on
two newer algorithms: cuckoo hashing and hopscotch hashing. Additionally, a new
section on universal hashing has been added. Also new is a brief discussion of the
unordered_set and unordered_map class templates introduced in C++11.
r Chapter 6 is mostly unchanged; however, the implementation of the binary heap makes
use of move operations that were introduced in C++11.
r Chapter 7 now contains material on radix sort, and a new section on lower-bound
proofs has been added. Sorting code makes use of move operations that were
introduced in C++11.
r Chapter 8 uses the new union/find analysis by Seidel and Sharir and shows the
O( M α(M, N) ) bound instead of the weaker O( M log∗ N ) bound in prior editions.
r Chapter 12 adds material on suffix trees and suffix arrays, including the linear-time
suffix array construction algorithm by Karkkainen and Sanders (with implementation).
The sections covering deterministic skip lists and AA-trees have been removed.
r Throughout the text, the code has been updated to use C++11. Notably, this means
use of the new C++11 features, including the auto keyword, the range for loop, move
construction and assignment, and uniform initialization.

Overview
Chapter 1 contains review material on discrete math and recursion. I believe the only way
to be comfortable with recursion is to see good uses over and over. Therefore, recursion
is prevalent in this text, with examples in every chapter except Chapter 5. Chapter 1 also
includes material that serves as a review of basic C++. Included is a discussion of templates
and important constructs in C++ class design.
Chapter 2 deals with algorithm analysis. This chapter explains asymptotic analysis
and its major weaknesses. Many examples are provided, including an in-depth explana-
tion of logarithmic running time. Simple recursive programs are analyzed by intuitively
converting them into iterative programs. More complicated divide-and-conquer programs
are introduced, but some of the analysis (solving recurrence relations) is implicitly delayed
until Chapter 7, where it is performed in detail.
Preface xvii

Chapter 3 covers lists, stacks, and queues. This chapter includes a discussion of the STL
vector and list classes, including material on iterators, and it provides implementations
of a significant subset of the STL vector and list classes.
Chapter 4 covers trees, with an emphasis on search trees, including external search
trees (B-trees). The UNIX file system and expression trees are used as examples. AVL trees
and splay trees are introduced. More careful treatment of search tree implementation details
is found in Chapter 12. Additional coverage of trees, such as file compression and game
trees, is deferred until Chapter 10. Data structures for an external medium are considered
as the final topic in several chapters. Included is a discussion of the STL set and map classes,
including a significant example that illustrates the use of three separate maps to efficiently
solve a problem.
Chapter 5 discusses hash tables, including the classic algorithms such as sepa-
rate chaining and linear and quadratic probing, as well as several newer algorithms,
namely cuckoo hashing and hopscotch hashing. Universal hashing is also discussed, and
extendible hashing is covered at the end of the chapter.
Chapter 6 is about priority queues. Binary heaps are covered, and there is additional
material on some of the theoretically interesting implementations of priority queues. The
Fibonacci heap is discussed in Chapter 11, and the pairing heap is discussed in Chapter 12.
Chapter 7 covers sorting. It is very specific with respect to coding details and analysis.
All the important general-purpose sorting algorithms are covered and compared. Four
algorithms are analyzed in detail: insertion sort, Shellsort, heapsort, and quicksort. New to
this edition is radix sort and lower bound proofs for selection-related problems. External
sorting is covered at the end of the chapter.
Chapter 8 discusses the disjoint set algorithm with proof of the running time. This is a
short and specific chapter that can be skipped if Kruskal’s algorithm is not discussed.
Chapter 9 covers graph algorithms. Algorithms on graphs are interesting, not only
because they frequently occur in practice but also because their running time is so heavily
dependent on the proper use of data structures. Virtually all of the standard algorithms
are presented along with appropriate data structures, pseudocode, and analysis of running
time. To place these problems in a proper context, a short discussion on complexity theory
(including NP-completeness and undecidability) is provided.
Chapter 10 covers algorithm design by examining common problem-solving tech-
niques. This chapter is heavily fortified with examples. Pseudocode is used in these later
chapters so that the student’s appreciation of an example algorithm is not obscured by
implementation details.
Chapter 11 deals with amortized analysis. Three data structures from Chapters 4 and
6 and the Fibonacci heap, introduced in this chapter, are analyzed.
Chapter 12 covers search tree algorithms, the suffix tree and array, the k-d tree, and
the pairing heap. This chapter departs from the rest of the text by providing complete and
careful implementations for the search trees and pairing heap. The material is structured so
that the instructor can integrate sections into discussions from other chapters. For example,
the top-down red-black tree in Chapter 12 can be discussed along with AVL trees (in
Chapter 4).
Chapters 1 to 9 provide enough material for most one-semester data structures courses.
If time permits, then Chapter 10 can be covered. A graduate course on algorithm analysis
could cover chapters 7 to 11. The advanced data structures analyzed in Chapter 11 can
easily be referred to in the earlier chapters. The discussion of NP-completeness in Chapter 9
xviii Preface

is far too brief to be used in such a course. You might find it useful to use an additional
work on NP-completeness to augment this text.

Exercises
Exercises, provided at the end of each chapter, match the order in which material is pre-
sented. The last exercises may address the chapter as a whole rather than a specific section.
Difficult exercises are marked with an asterisk, and more challenging exercises have two
asterisks.

References
References are placed at the end of each chapter. Generally the references either are his-
torical, representing the original source of the material, or they represent extensions and
improvements to the results given in the text. Some references represent solutions to
exercises.

Supplements
The following supplements are available to all readers at http://cssupport.pearsoncmg.com/

r Source code for example programs


r Errata

In addition, the following material is available only to qualified instructors at Pearson


Instructor Resource Center (www.pearsonhighered.com/irc). Visit the IRC or contact your
Pearson Education sales representative for access.

r Solutions to selected exercises


r Figures from the book
r Errata

Acknowledgments
Many, many people have helped me in the preparation of books in this series. Some are
listed in other versions of the book; thanks to all.
As usual, the writing process was made easier by the professionals at Pearson. I’d like
to thank my editor, Tracy Johnson, and production editor, Marilyn Lloyd. My wonderful
wife Jill deserves extra special thanks for everything she does.
Finally, I’d like to thank the numerous readers who have sent e-mail messages and
pointed out errors or inconsistencies in earlier versions. My website www.cis.fiu.edu/~weiss
will also contain updated source code (in C++ and Java), an errata list, and a link to submit
bug reports.
M.A.W.
Miami, Florida
C H A P T E R 1

Programming: A General
Overview

In this chapter, we discuss the aims and goals of this text and briefly review programming
concepts and discrete mathematics. We will . . .

r See that how a program performs for reasonably large input is just as important as its
performance on moderate amounts of input.
r Summarize the basic mathematical background needed for the rest of the book.
r Briefly review recursion.
r Summarize some important features of C++ that are used throughout the text.

1.1 What’s This Book About?


Suppose you have a group of N numbers and would like to determine the kth largest. This
is known as the selection problem. Most students who have had a programming course
or two would have no difficulty writing a program to solve this problem. There are quite a
few “obvious” solutions.
One way to solve this problem would be to read the N numbers into an array, sort the
array in decreasing order by some simple algorithm such as bubble sort, and then return
the element in position k.
A somewhat better algorithm might be to read the first k elements into an array and
sort them (in decreasing order). Next, each remaining element is read one by one. As a new
element arrives, it is ignored if it is smaller than the kth element in the array. Otherwise, it
is placed in its correct spot in the array, bumping one element out of the array. When the
algorithm ends, the element in the kth position is returned as the answer.
Both algorithms are simple to code, and you are encouraged to do so. The natural ques-
tions, then, are: Which algorithm is better? And, more important, Is either algorithm good
enough? A simulation using a random file of 30 million elements and k = 15,000,000
will show that neither algorithm finishes in a reasonable amount of time; each requires
several days of computer processing to terminate (albeit eventually with a correct answer).
An alternative method, discussed in Chapter 7, gives a solution in about a second. Thus,
although our proposed algorithms work, they cannot be considered good algorithms, 1
2 Chapter 1 Programming: A General Overview

1 2 3 4

1 t h i s
2 w a t s
3 o a h g
4 f g d t

Figure 1.1 Sample word puzzle

because they are entirely impractical for input sizes that a third algorithm can handle in a
reasonable amount of time.
A second problem is to solve a popular word puzzle. The input consists of a two-
dimensional array of letters and a list of words. The object is to find the words in the puzzle.
These words may be horizontal, vertical, or diagonal in any direction. As an example, the
puzzle shown in Figure 1.1 contains the words this, two, fat, and that. The word this begins
at row 1, column 1, or (1,1), and extends to (1,4); two goes from (1,1) to (3,1); fat goes
from (4,1) to (2,3); and that goes from (4,4) to (1,1).
Again, there are at least two straightforward algorithms that solve the problem. For each
word in the word list, we check each ordered triple (row, column, orientation) for the pres-
ence of the word. This amounts to lots of nested for loops but is basically straightforward.
Alternatively, for each ordered quadruple (row, column, orientation, number of characters)
that doesn’t run off an end of the puzzle, we can test whether the word indicated is in the
word list. Again, this amounts to lots of nested for loops. It is possible to save some time
if the maximum number of characters in any word is known.
It is relatively easy to code up either method of solution and solve many of the real-life
puzzles commonly published in magazines. These typically have 16 rows, 16 columns, and
40 or so words. Suppose, however, we consider the variation where only the puzzle board is
given and the word list is essentially an English dictionary. Both of the solutions proposed
require considerable time to solve this problem and therefore might not be acceptable.
However, it is possible, even with a large word list, to solve the problem very quickly.
An important concept is that, in many problems, writing a working program is not
good enough. If the program is to be run on a large data set, then the running time becomes
an issue. Throughout this book we will see how to estimate the running time of a program
for large inputs and, more important, how to compare the running times of two programs
without actually coding them. We will see techniques for drastically improving the speed
of a program and for determining program bottlenecks. These techniques will enable us to
find the section of the code on which to concentrate our optimization efforts.

1.2 Mathematics Review


This section lists some of the basic formulas you need to memorize, or be able to derive,
and reviews basic proof techniques.
Another random document with
no related content on Scribd:
pound pound calories of
of of material
protein energy
Oat
preparations:
Oatmeal,
3 0.24 1.7 3.33 0.42 0.22 2.18 5884
raw
” 4 0.32 2.3 2.50 0.31 0.16 1.64 4418
Rolled oats,
6 0.48 3.4 1.67 0.21 0.11 1.08 2938
steam cooked
Wheat
preparations:
Flour,
4 0.40 2.6 2.50 0.25 0.01 1.61 3790
Graham
Flour,
5 0.46 3.1 2.00 0.22 0.03 1.36 3188
entire-wheat
Flour,
3.5 0.35 2.1 2.86 0.29 0.03 2.10 4700
patent
Farina 10 1.12 6.2 1.00 0.09 0.01 0.73 1609
Flaked 15 1.69 9.3 0.67 0.06 0.01 0.46 1005
Shredded 12.5 1.62 8.2 0.80 0.06 0.01 0.57 1217
Parched &
7.5 0.88 4.9 1.33 0.11 0.02 0.94 2050
ground
Malted,
cooked and 13 1.43 8.5 0.77 0.07 0.01 0.53 1175
crushed
Flaked and
11 1.21 7.2 0.91 0.08 0.01 0.62 1389
malted
Barley
preparations:
Pearled
7 1.06 4.6 1.43 0.09 0.01 1.04 2165
barley
Flaked,
15 1.83 9.6 0.67 0.05 ... 0.50 1051
steam cooked
Corn
preparations:
Corn meal,
3 0.44 1.8 3.33 0.23 0.06 2.48 5534
granular
Hominy 4 0.62 2.4 2.50 0.16 0.01 1.97 4178
Samp 5 0.78 3.0 2.00 0.13 0.01 1.57 3342
Flaked &
13 1.73 7.5 0.77 0.06 0.01 0.60 1335
parched
Rice
preparations:
Rice,
8 1.48 4.7 1.25 0.07 ... 0.94 1855
polished
Flaked,
15 2.31 9.8 0.67 0.04 ... 0.51 1026
steam cooked
Miscellaneous
foods for
comparison:
Bread,
6 0.74 5.0 1.67 0.14 0.02 0.87 2009
white
” 5 0.62 4.2 2.00 0.16 0.02 1.04 2406
Crackers 10 1.10 5.3 1.00 0.09 0.08 0.71 1905
Macaroni 12.5 1.08 7.5 0.80 0.09 0.01 0.58 1328
Beans,
5 0.28 3.5 2.00 0.35 0.03 1.16 2868
dried
Peas, dried 5 0.26 3.4 2.00 0.38 0.02 1.20 2974
Milk 3 0.94 9.7 3.33 0.11 0.13 0.17 1030
” 3.5 1.09 11.3 2.86 0.09 0.11 0.14 885
Sugar 5 ... 2.8 2.00 ... ... 2.00 3515
” 6 ... 3.4 1.67 ... ... 1.67 2940

The less expensive breakfast foods, such as oatmeal and corn


meal, are as economical as flour, and, as they supply heat and
energy in abundance, as shown by Table VI, they should be supplied
in the diet in proportion to the energy required. They are easily
prepared for porridge, requiring simply to be boiled in water, with a
little salt.
For invalids, children, and old people, breakfast foods prepared in
gruels and porridges are valuable as they are easily digested. All
should be thoroughly cooked so as to break the cell-walls inclosing
the starch granules.
Oatmeal is the most nutritious cereal. The oat contains more fat
than other grains and a larger proportion of protein. It, therefore,
contains the proportion of nutrient elements best adapted to sustain
life.
On account of the fat, oats are especially well adapted for a
breakfast food in winter. Another advantage oatmeal, or rolled oats,
have as a breakfast food is in their laxative tendency, due to the
coarse shell of the kernel.
Oat breakfast foods keep longer than the foods made from wheat
and rice.
There are no malts, or any mixtures in the oat preparations.
The difference between the various oatmeal breakfast foods is in
their manner of preparation. They all contain the entire grain, with
the exception of the husk. They are simply the ground or crushed
oat. In preparing the oats before grinding, the outer hull is removed,
the fuzzy coating of the berry itself is scoured off, the ends of the
berry, particularly the end containing the germ, which is usually the
place of deposit for insect eggs, is scoured, and the bitter tip end of
the oat berry is likewise removed.
Rolled oats consist of the whole berry of the oat, ground into a
coarse meal, either between millstones, or, in the case of the so-
called “steel cut” oatmeal, cut with sharp steel knives across the
sections of the whole oat groat.
Quaker Oats consist of the whole groats, which, after steaming in
order to soften, have been passed between hot steel rolls,
somewhat like a mangle in a laundry, and crushed into large, thin,
partially cooked flakes. The oats are then further cooked by an open
pan-drying process. This roasting process insures that all germ life is
exterminated, renders the product capable of quicker preparation for
the table, and causes the oil cells to release their contents, thereby
producing what is termed the “nut flavor,” which is not present in the
old-fashioned type of oat product.
Both Rolled Oats and Quaker Oats are now partially cooked in
their preparation, but the starch cells must be thoroughly broken
and they should be cooked at least forty-five minutes in a double
boiler; or, a good way to prepare the porridge is to bring it to the
boiling point at night, let it stand covered over night and then cook it
from twenty to thirty minutes in the morning. Another method of
cooking is to bring the porridge to the boiling point and then place it
in a fireless cooker over night.
The great fault in the preparation of any breakfast food is in not
cooking it sufficiently to break the starch cells.
Puffed Rice is made from a good quality of finished rice. The
process is a peculiar one, the outer covering or bran, is removed and
then the product is literally “shot from guns”; that is, a quantity of
the rice is placed in metal retorts, revolved slowly in an oven, at high
temperature, until the pressure of steam, as shown by a gauge on
the gun, indicates that the steam, generated slowly by the moisture
within the grain itself, has thoroughly softened the starch cells. The
gun retort is pointed into a wire cage and the cap which closes one
end is removed, permitting an inrush of cold air. This cold air, on
striking the hot steam, causes expansion, which amounts practically
to an explosion. The expansion of steam within each starch cell
completely shatters the cell, causing the grain to expand to eight
times its original size. It rushes out of the gun and into the cage
with great force, after which it is screened to remove all scorched or
imperfectly puffed grains.
This process dextrinizes a portion of the starch and also very
materially increases the amount of soluble material as against the
original proportion in the grain.
Puffed Wheat is manufactured from Durum, or macaroni wheat, of
the very highest grade. This is a very hard, glutinous grain. It is
pearled in order to thoroughly clean and take off the outer covering
of bran. It then goes through a puffing process, identical with that of
Puffed Rice. The chemical changes are very similar to those of
puffed rice.
Both Puffed Rice and Puffed Wheat are more digestible than in the
original grain state. They are valuable foods for invalids.
Stale Bread. A food which tastes much like a prepared breakfast
food, but is cheaper, may be made by dipping stale bread into
molasses and water, drying it in the oven for several hours, and then
crushing it. It is then ready to serve with cream. This is a palatable
way to use up stale bread.
Crackers and Milk or Bread and Milk. As noted by Table VI,
crackers are similar to breakfast food in nutrient elements, and with
milk make a good food for breakfast, or a good luncheon. Business
men, and others who eat hurriedly and return immediately to work,
will do well to substitute crackers and milk, or bread and milk, for
the piece of pie which often constitutes a busy man’s lunch.
Cracked Wheat. In America wheat is seldom used whole. In
England the whole grain, with the bran left on, is slightly crushed
and served as cracked wheat or wheat grits.
Wheat is also rolled, or flaked, or shredded. The majority of wheat
breakfast foods contain a part of the middlings and many of them
bran. Farina and gluten preparations do not contain these, however.
The preparations of the various breakfast foods are a secret of the
manufacturers. The ready-to-eat brands are cooked, then they are
either rolled or shredded, the shredding requiring special machinery
to tear the steamed kernels; later they are dried, and, finally packed,
sometimes in small biscuits. Many preparations are baked after being
steamed, which turns them darker and makes them more crisp.
Some preparations are steamed, then run through rollers, while still
wet, and pressed into flakes or crackers.
Predigested Foods. It is claimed that some foods are “partly
digested and thus valuable for those with weak stomachs,” but
breakfast foods are largely starch and the starch is not digested by
the gastric juice. It is digested by saliva and the ferments in the
small intestine. These change the starch into dextrin and maltose.
Experiments with “predigested” foods do not show a larger
proportion of dextrin (digested starch), however, than would
naturally be produced by the heating of the starch when these foods
are cooked at home. The natural cooking makes starch more or less
soluble, or at least gelatinized. As a result of these experiments
therefore, the “predigested” argument is not of much weight.
Predigested foods, except in cases in which the patient is so weak
as to be under the direction of a physician, are not desirable. Nature
requires every organ to do the work intended for it, in order to keep
up its strength, just as she requires exercise for the arms or legs to
keep them strong. If an organ is weak, the cause must be found and
corrected—perhaps the stomach or intestines need more blood,
which should be supplied through exercise; or perhaps the nerves
need relaxation; or the stomach less food; or food at more regular
intervals.
Another argument against predigested foods lies in the fact that
the chewing of coarse food is necessary to keep the teeth strong.
For this strengthening of the teeth, children should be given dry
crackers or dry toast each day.
Dogs and wild animals which chew bones and hard substances do
not have pyorrhea, but lap-dogs and animals in the zoos, fed on
bread and meat without bones, suffer from this disease.
In the so-called “predigested” or “malted” preparations, malt is
added while they are being cooked.
Malt is a ferment made from some grain, usually from barley, the
grain being allowed to germinate until the ferment diastase is
developed.
There is no doubt that a number of foods containing malt are
valuable to assist in converting starch into dextrin or sugar, just as
pepsin is an aid in the digestion of protein; but eaten
indiscriminately, there can be no question that it is more important
for the teeth, stomach, and intestines to perform their natural work
and thus keep their strength through normal exercise.
While they are not “predigested,” as claimed, these foods are, as a
rule, wholesome and nutritious. They are cleanly, and made from
good, sound grain, and they contain no harmful ingredients. Some
contain “middlings,” molasses, glucose, and similar materials, but
these are in no way injurious and have value as foods.
The dry, crisp, ready-to-eat foods are especially advantageous
because of the mastication they require. This insures plenty of saliva
being mixed with them to aid in digestion. A dish of such dry
breakfast food, well masticated, together with an egg, to furnish a
larger proportion of protein, makes a wholesome breakfast.

According to investigations made by the United


Cereal Coffees States Agriculture Experiment Station, cereal
coffees are made of parched grains. A few contain
a little true coffee, but for the most part they are made of parched
wheat, barley, etc., or of grain mixed with wheat middlings, pea
hulls, or corn cobs. There is no objection to any of these mixtures
providing they are clean. The cereal coffees, as seen by Table VII,
contain no more nourishment than the true coffee, but they are
probably more easily digested; only a very little of the soluble starch
passes into the water unless the kernel is ground. Coffee and tea are
not taken for their nutrition, but for their stimulating effect on the
nerves; and, if stimulation is desired, the cereal coffees fall short.

TABLE VII
Composition of Cereal-Coffee Infusion and Other Beverages

Fuel Value
KIND OF BEVERAGE Water Protein Fat Carbohydrates
per pound
Commercial cereal coffee (0.5
98.2 0.2 .... 1.4 30
ounce to 1 pint water)
Parched corn coffee (1.6 ounces
99.5 0.2 .... 0.5 13
to 1 pint water)
Oatmeal water (1 ounce to 1 pint
99.7 0.3 .... 0.3 11
water)
Coffee (1 ounce to 1 pint water) 98.9 0.2 .... 0.7 16
Tea (0.5 ounce to 1 pint water) 99.5 0.2 .... 0.6 15
Chocolate (0.5 ounce to 1 pint
84.5 3.8 4.7 6.0 365
milk)
Cocoa (0.5 ounce to 1 pint
97.1 0.6 0.9 1.1 65
water)
Skimmed milk 88.8 4.0 1.8 5.4 170

By reference to Table VII it will be seen that cocoa and skimmed


milk contain much more nutrition than any of the coffees. The chief
value of cereal coffees is that they furnish a warm drink with the
meal. They should not be too hot.
Barley or wheat, mixed with a little molasses, parched in the oven,
and then ground, makes a mixture similar to the cereal coffee.
The old-fashioned crust coffee is just as nutritious as any of the
coffees and has the advantage of being cheaper.
Barley water and oat water, made by boiling the ground kernel
thoroughly and then straining, are nourishing foods for invalids and
children. They are often used as drinks by athletes and manual
laborers, as they have the advantage of both quenching thirst and
supplying energy.
Gruels are made in the same way, only strained through a sieve.
This process allows more of the starch to pass with the water.

The legumes are the seeds of peas, beans,


Legumes lentils, and peanuts.

TABLE VIII
Legumes
Water Ash Fuel Value
FOOD Protein Fat per Carbohydrates
per per per pound
MATERIALS per cent. cent. per cent.
cent. cent. Calories
Dried
Legumes:
Navy beans 12.6 22.5 1.8 59.6 3.5 1605
Dried peas 9.5 24.6 1.0 62.0 2.9 1655
Lentils 8.4 25.7 1.0 59.2 5.7 1620
Lima beans 10.4 18.1 1.5 65.9 4.1 1625
Peanuts 9.2 25.8 38.6 24.4 2.0 2560
Peanut
2.1 29.3 46.5 17.1 5.0 2825
butter
Fresh
Legumes:
Canned
85.3 3.6 0.2 9.8 1.1 255
peas
Canned
79.5 4.0 0.3 14.6 1.6 360
lima beans
Canned
93.7 1.1 0.1 3.8 1.3 95
string beans
Canned
68.9 6.9 2.5 19.6 2.1 600
baked beans
String
89.2 2.3 0.3 7.4 0.8 195
beans
Shelled
74.6 7.0 0.5 16.9 1.0 465
peas

Like the cereals, they are seeds, yet they contain a very much
larger proportion of protein and may be substituted for meat or eggs
in a diet. In all vegetarian diets, under normal conditions, the
legumes should be used freely to replace meats.
All legumes must be thoroughly cooked and thoroughly
masticated. Because the protein in these foods is less digestible than
that in meat or eggs, particularly if they are not thoroughly
masticated, they are better adapted for the use of those who do
manual labor. Soldiers in battle, day laborers, and others whose work
calls for hard physical exercise, can digest legumes more easily than
can those whose occupation is more sedentary.
If not thoroughly masticated legumes usually produce intestinal
fermentation with consequent production of gas. For this reason
they occasion distress in those who partake of them too freely and
with insufficient preparation by cooking.
The protein of the legumes is of the same nature as the casein of
milk. It has been called vegetable casein.
Peanuts. While an underground vegetable, grown like potatoes,
peanuts resemble nuts, inasmuch as they contain so much fat. The
extracted oil is used in several commercial products.
Like other legumes, they require cooking. They are roasted
because this develops the flavor.
Because they contain a more balanced proportion of proteins,
carbohydrates, and fats, they will sustain life for some time without
other food, as they provide rebuilding material, energy, and heat.
Used alone, however, there is no counteracting acid, and it is better
to add some fruit, such as apples, or apples and dates. For this
reason lemon juice is mixed with peanut butter.
In eating peanuts it is imperative that they be masticated until
they are a pulp, otherwise they are very difficult of digestion. The
pain which many people experience after eating peanuts is probably
due to eating too large a quantity and not fully masticating them,
forgetting that they are a very rich, highly concentrated food.
The habit of eating peanuts between meals and then eating a
hearty meal is likely to overload the digestive organs.
Both peanuts and peanut butter contain over twenty-five per cent.
of protein and about thirty-nine per cent. of fat; therefore they yield
much heat and energy.
Peanuts have been made into a flour; they are also to be had in
the form of grits which are cooked like oatmeal. When nuts or
peanuts are used as an after-dinner relish the quantity of meat
should be cut down.
Their popularity is evidenced by the fact that between 4,000,000
and 5,000,000 bushels are raised annually in America.
Peanut Butter. While peanut butter contains 46.5 per cent. fat, it
contains only seventeen per cent. carbohydrates. Since sugars and
starches are protections to fat, being used for energy before the fats
are consumed, if these sugars and starches are not supplied in other
food, the fats in the peanut butter are consumed for energy. If
starches are consumed in other foods, it is clear that one who
wishes to reduce in flesh should avoid peanut butter, as well as other
fats.
Peanut butter is more easily digested than the roasted peanut,
unless the latter is chewed to a pulp. It can be made at home by
grinding the peanuts in a meat grinder, and then further mashing
with a rolling pin or a wooden potato masher. A little lemon juice
mixed with the peanut butter makes it not only more palatable, but
more easily digested. A peanut butter sandwich is quite as
nourishing as a meat sandwich.
Shelled Peas. Shelled peas were used in Europe as far back as in
the Middle Ages, and there, to-day, the dried or “split” pea is used
quite as extensively as the dried bean. In America, peas are used
almost entirely in the green stage, fresh, or canned.
As seen by Table VIII, the green, shelled pea contains seven per
cent. of protein and sixteen per cent. of sugar and starch, while the
dry or “split” pea contains over 24.5 per cent. of protein and sixty-
two per cent. of sugar and starch, the difference being in the
amount of water contained in the shelled peas. Canned peas contain
even a larger percentage of water.
A variety of the pea is now being cultivated, in which, like the
string bean, the pod is used as a food. They are sweet and delicious.
Dried peas are used in this country mostly in purées.
Beans. Baked navy beans may well be substituted on a menu for
meat, containing, as they do, 22.5 per cent. of protein. It is needless
to state that beans and lean meat or eggs should not be served at
the same meal. Beans have the advantage of being cheaper than
meat, yet, as stated above, the protein in the legumes is less easily
digested than the protein of meat or eggs. They must be thoroughly
cooked and thoroughly masticated.
There is but a small percentage of fat in dried beans; for this
reason they are usually baked with a piece of pork. They make a
very complete, perhaps the most complete food, containing nutrient
elements in about the proper proportions.
A bean biscuit is used for the sustenance of soldiers on a march; it
gives a complete food in condensed form.
In baking dried beans or peas, soft or distilled water should be
used, as the lime of hard water makes the shell almost indigestible.
Parboiling the beans for fifteen minutes in two quarts of water with a
quarter of a teaspoon of baking soda softens the shell, making them
easier to digest.
String Beans. The string bean contains very little nutrition, as
shown by Table VIII. The pod and the bean, at this unripe stage,
contain nearly ninety per cent. water. Their chief value as a food
consists in their appetizing quality to those who are fond of them,
thus stimulating the flow of gastric juice.
Like all green vegetables they stimulate the action of the kidneys.
All green vegetables are particularly valuable to those who drink little
water.
The dried Lima bean, used during the winter, may be boiled or
baked. If old, they are practically indigestible.
Kidney Beans contain much water but are more nutritious than the
string bean.
Soy Bean. In China and Japan this bean is used extensively. Being
rich in protein, used with rice it makes a well-balanced diet.
The soy bean is made into various preparations, one of the most
important being shoyo, which has been introduced into other
countries. To make it, the soy bean is cooked and mixed with
roasted wheat flour and salt; into this is put a special ferment. It is
then allowed to stand for an extended time in casks. The result is a
thick, brown liquid with a pungent, agreeable taste. It is very
nourishing.
A kind of cheese is also made by boiling the soy bean for several
hours, wrapping the hot mass in bundles of straw, and putting it in a
tightly closed cellar for twenty-four hours.
Lentils are not commonly used in this country, but they were one
of the earliest vegetables to be cultivated in Asia and the
Mediterranean countries. They are usually imported and may be
obtained in the markets. They are used like dried peas and are fully
as nourishing, but the flavor of the lentil is pronounced and they are
not so agreeable to the average person as peas or beans.

Nuts are classed with the carbo-nitrogenous


foods, because of the more nearly equal Nuts
proportion of proteins and carbonaceous
substances.

TABLE IX
Nuts

Water Ash Fuel Value per


FOOD Protein Fat per Carbohydrates
per per pound
MATERIALS per cent. cent. per cent.
cent. cent. Calories.
Almonds 4.8 21.0 54.90 17.3 2.0 3030
Brazil nuts 5.3 17.0 66.80 7.0 3.9 3329
Filberts 3.7 15.6 65.30 13.0 2.4 3342
Hickory nuts 3.7 15.4 67.40 11.4 2.1 3495
Pecans 3.0 16.7 71.20 13.3 1.5 3633
English
2.8 16.7 64.40 14.8 1.3 3305
walnuts
Chestnuts,
45.0 6.2 5.40 42.1 1.3 1125
fresh
Walnuts,
2.5 27.6 56.30 11.7 1.9 3105
black
Cocoanut,
3.5 6.3 57.30 31.6 1.3 3125
shredded
Peanuts,
1.6 30.5 49.20 16.2 2.5 3177
roasted

It will be noted, by reference to Table IX that nuts contain a much


larger proportion of fats and less starch than the legumes. Chestnuts
contain the largest amount of starch, and pecans the most fat.
Peanuts are classed here with nuts because of their similar use in
the diet. Their comparative richness in protein will be noted.
Nuts are a valuable food, but they should be made a part of a
meal and may well take the place of meat rather than eaten as a
dessert, because of the large percentage of protein. They are too
rich to be eaten as a relish at the end of a meal, if one has eaten as
much other food as the system requires.
In planning a meal, if the dietary is rich in starches and lacking in
protein, a side dish of nuts may be served.
Too great stress cannot be laid on the importance of the thorough
mastication of nuts; otherwise they are difficult of digestion. When
thoroughly chewed, however, they are as easily digested as cereals
or legumes. If ground fine in a meat grinder or rubbed through a
sieve, they digest more readily, but this grinding does not take the
place of the grinding with the teeth and the mixture with the saliva.
They are best chopped for salads, cake, or croquettes. When ground
the oil extracted makes them pasty and not appetizing in appearance
for use in salads or cake.
Milk is a perfect food for the infant because it
Milk contains the elements in proper proportions to
sustain life and growth, though, alone, it is
insufficient for the nourishment of healthy adults. The adult, in order
to get sufficient nutriment, would be compelled to take a larger
proportion of water than necessary, the proportion of water required
by the system being about sixty-seven per cent., while milk contains
eighty-seven per cent.
In many diseases, however, a whole or partial milk diet is
desirable, especially in any inflammatory condition of the gastro-
intestinal tract.

TABLE X
Milk and Milk Products

FOOD MATERIALS Water Protein Fats Sugar Salts Lactic Acid


Milk 86.8 4.0 3.7 4.8 0.7 ....
Skimmed milk 88.0 4.0 1.8 5.4 0.8 ....
Buttermilk 90.6 3.8 1.2 3.3 0.6 0.3
Cream 66.0 2.7 26.7 2.8 1.8 ....
Cheese 36.8 33.5 24.3 .... 5.4 ....
Butter 6.0 0.3 91.0 .... 2.7 ....

The milk of the cow is not perfectly adapted for the young child—
it is lacking in the proper proportion of sugar, and when fed to the
infant it must be modified. Mother’s milk is not only richer in sugar
than cow’s milk, but it contains about half as much casein. The calf
needs more albumin than the baby does because it grows faster.
Human milk is also richer in fat.
An all-milk diet may be followed when it is desirable to gain in
weight. Such a diet should be accompanied by exercises for the vital
organs and by deep breathing, but experiments have shown that
healthy digestive organs do their work better when a part of the
food is solid.
A milk and cream diet of about three quarts milk and one quart
cream with the addition of one to two eggs a day will keep up the
strength of one in bed, but is not sufficient for one who is active.
In order for an adult to obtain the proper quantity of
carbohydrates and fat, from an all-milk diet, it is necessary for him
to drink from four to five quarts of milk a day (sixteen to twenty
glasses). It is usually said that on an all-milk diet an active person
requires as many quarts as he is feet tall.
Young babies on mother’s milk are almost always fat, because of
the larger proportion of sugar and fat in the mother’s milk.
Reference to Table X shows that the thirteen per cent. of solids
are about equally divided between fat, sugar, and protein. The sugar
is lactose. It supplies heat to the infant before it can exercise its
muscles vigorously. The protein is casein.
There is no starch in milk. The digestive ferment, which acts on
starch, has not developed in the young babe and it cannot digest
starch.
The salts promote the growth of bone.
The fat in milk is in small emulsified droplets within a thin
albuminous sheath. When allowed to stand in a cool place it rises to
the top.
Besides casein, milk contains a certain amount of albumin—about
one-seventh of the total amount—called lactalbumin. It maintains
the fat in milk in emulsified form.
In young babes the milk is curdled in the stomach, or the casein
separated from the water and sugar, not by hydrochloric acid, but by
a ferment in the gastric juice, known as rennin. Rennin, or rennet,
from the stomachs of calves, is used in cheese and butter factories
to coagulate the casein. This with other chemicals so hardens the
casein that it is used in the manufacture of buttons.
Preserving milk. If milk could be kept free from bacteria, it would
keep sweet almost indefinitely. At the Paris Exposition, milk from
several American dairies was kept sweet for two weeks, without any
preservative except cleanliness and a temperature of about forty
degrees. The United States Bureau of Animal Industry states that
milk may be kept sweet for seven weeks without the use of
chemicals.
The importance of absolute cleanliness in the preparation and
marketing of this important article of food is being recognized both
by the producer and the consumer, and careful inspection has done
away with many abuses. In the absence of an efficient health
department, the consumer should ascertain in every case how the
milk he uses is handled at every stage before it reaches him. Care in
this regard may safeguard his family from disease and save him
many dollars.
The best method for the housewife to follow is to keep the milk
clean, cool, and away from other foods, as milk will absorb a bad
odor or flavor from any stale food or odorous vegetables, from fresh
paint, or other substances.
Milk must never be left exposed in a sick room or in a refrigerator
unless the waste pipe and the ice chamber are kept scrupulously
clean.
Milk Tests. In testing the value of milk, or the value of a cow,
butter makers and farmers gauge it by the amount of butter fat in
the milk, while the cheese maker tests the milk for the proportion of
protein (casein). The amount of butter fat depends on the feed and
water, and on the breed. If the total nutrient elements fall below
twelve per cent., it is safe to assume that the milk has been
watered.
In cheese and butter there is no sugar; it remains in the
buttermilk and the whey, both of which the farmer takes home from
the factories to fatten his hogs.
Pasteurized Milk. In pasteurizing milk the aim is to destroy as
many of the bacteria as possible without causing any chemical
changes or without changing the flavor. One can pasteurize milk at
home by placing it in an air-tight bottle, immersing the bottle to the
neck in hot water, heating the water to 167 F. for twenty minutes,
and then quickly cooling the milk to 50 F. by immersing the bottle in
cold water. The rapid cooling lessens the cooked taste. The best
dairies pasteurize the milk before it is marketed.
Sterilized Milk. Milk is sterilized to destroy all bacteria, by heating
it to 212 F. Sterilized milk remains sweet longer than pasteurized
milk, but more chemical changes are produced and the flavor is
changed, resembling that of boiled milk.
Formerly borax, boric acid, salicylic acid, formalin, and saltpeter
were used to keep the milk sweet, but this adulteration is now
forbidden by the pure-food laws.
Malted milk is a dry, soluble food product in powder form, derived
from malted barley, wheat flour (dextrin), and cow’s milk, containing
the full amount of cream.
The process of the extraction from the cereals is conducted at
elevated temperatures so as to allow the active agents (enzymes) of
the barley malt to effect the conversion of the vegetable protein and
starches. The filtered extract, containing the derivatives of the malt,
wheat, and the full-cream cow’s milk, is then evaporated to dryness
in vacuo, the temperature being controlled so as to obviate any
alteration of the natural constituents of the ingredients and so as to
preserve their full physiological values. The strictest precautions are
observed to insure the purity of the product. It contains:
Fats 8.75
Proteins 16.35
Dextrin 18.80
Lactose and Maltose 49.15
(Total Soluble Carbohydrates) 67.95
Inorganic Salts 3.86
Moisture 3.06

Malted milk is free from germs. The starches and sugars are
converted in the process of manufacture into maltose, dextrin, and
lactose. The fats are in an absorbable condition, and it contains a
high percentage of proteins derived from both the milk and the
grains, as well as a marked percentage of mineral salts. It is readily
soluble in water and is easily digested.
The hydrochloric acid of the stomach coagulates or curds milk
much as it is curded by many fruit and vegetable acids, such as
those in lemons or tomatoes. Thus the milk forms into curds
immediately on entering the stomach, the casein being at once
precipitated by the rennin. This is the chief reason why it should be
drunk slowly, otherwise too large curds will form, causing distress
from pressure.

A part of the digestion of the casein is


performed by pepsin in the stomach and a part by Digestion of Milk
the trypsin of the pancreatic juice.
The larger part of the digestion of the milk sugar or lactose, is
performed by the pancreatic juice; although it is partly acted on by
the saliva. Usually, however, the saliva is given little chance to
become mixed with the milk, unless it is taken slowly and mixed with
saliva by chewing movements. This is one reason why children
should be given milk in which bread has been broken, rather than a
piece of bread and a glass of milk. By swallowing the milk slowly,
smaller curds are formed in the stomach and the milk is more
thoroughly digested.
The salts of milk, to a large extent, the water, and perhaps a
portion of the sugar are absorbed in the stomach.
When the fat (cream) is removed milk digests more readily, so
that in cases in which the stomach is delicate, skimmed milk,
clabbered milk, or buttermilk are often prescribed instead of sweet
milk.
Boiled milk is also more readily digested by some; the lactalbumin
is separated and rises to the top in a crinkly scum. The casein of
boiled milk is also more readily digested, forming in small flakes in
the stomach instead of in curds.
Sterilizing the milk by boiling will prevent the action of bacteria in
producing fermentation and disordered digestion, and, if relished,
milk can thus be treated. Pasteurized milk is more palatable than
boiled milk.
Milk is often better assimilated if other food is not too suddenly
cut off. When the diet is radically changed the digestive system is
apt to show derangement. Therefore when for any cause an all-milk
diet is desired, it is unwise to begin it at once, by feeding from
eighteen to twenty glasses of milk a day. This amount may be
approximated within a week’s time. The change in diet should be
begun by cutting down all meats and legumes and gradually
eliminating starches. In changing from a milk diet to a diet including
more hearty foods, the transition should also be gradual.
If a milk diet is to be followed and the milk seems to disturb the
stomach when taken in quantities, one may begin by taking it in very
small quantities every fifteen minutes for the first hour. If one’s
purpose is to gain in flesh the quantity may be increased to a glass,
and time intervals be lengthened to every hour as the stomach
becomes accustomed to caring for the milk. It should be sipped
slowly and thoroughly mixed with saliva before being swallowed. The
mouth should be carefully rinsed with equal parts of peroxide of
hydrogen and water, or listerine and hot sterile water, each time milk
is taken.
Milk, in whatever form it is taken, leaves a coating on the tongue
and teeth. The heat of the mouth, especially if the patient is
feverish, quickly causes changes which give a disagreeable taste and
a chance for bacterial action. These bacterial products are carried
into the stomach and excite digestive changes through which
fermentation and gas formation appear and biliousness may result.
This may be avoided if, after taking the milk, the mouth is carefully
washed and, in feverish conditions, the tongue gently scraped or
swabbed with absorbent cotton dipped in listerine or peroxide of
hydrogen. Without such cleansing of the mouth milk may disagree.
When from two to three glasses of milk at a meal are taken, less
solid food is needed, because the required nutriment is partially
supplied by the milk. One reason why milk seems to disagree with
many people, is because they lose sight of the fact that milk is an
actual food, as well as a beverage, and they eat the usual quantity
of food in addition to the milk. As one pint, or two glasses of milk,
contains approximately the same amount of nutrition as one-third of
a pound of beef, the amount of food to be taken in addition may be
readily calculated.
The chief reason for the lessened activity of the bowels on a milk
diet is because the nourishment in milk is practically all absorbed—
there is very little residue and milk gives little rough surface to excite
peristaltic action and stimulate the walls of the intestine to activity.
The calcium, one of the constituents of milk, tends to lessen the
peristaltic action of the intestines and this is one of the causes of
constipation. Fruit and coarse bread containing much bran, should
be used with a milk diet.
Constipation may also be occasioned by drinking milk rapidly.
When the hydrochloric acid is very active coagulation may take place
so quickly as to cause hard tough curds to form; these enter the
intestine undissolved because the gastric juice can act only on the
exterior portion; the stomach retains the curds in its effort to
dissolve them and fermentation may occur, with irritation and
constipation from irregular action. In this case the constipating effect
may be overcome by taking the milk in small sips or by the addition
of one part of limewater to six parts milk. The limewater causes the
curds to be precipitated in small flakes.
Limewater may be prepared by putting a heaping teaspoon of
unslaked lime with a quart of boiled or distilled water into a corked
bottle or Mason jar. Shake thoroughly two or three times during the
first hour; then allow the lime to settle, and after twenty-four hours
pour or siphon off the clear fluid. Be careful not to allow the lime to
be poured off with the water.
Barley water or oatmeal water added to milk also prevents the
formation of large curds.
Milk may also be taken with any variety of gruel—oatmeal, sago,
arrowroot, or tapioca.
If there is much mucus in the stomach, mucous fermentation may
occur in milk because of the lack of hydrochloric acid. The partially
digested curds are tough, stringy, and slimy and the intestinal walls
find no resistance in the mass. In this case constipation may be
followed by diarrhea.
If the stomach is deficient in hydrochloric acid the juice of half an
orange or a little lemon juice may be taken a half hour before the
glass of milk.
Constipation and, later, diarrhea may also result when stomach
digestion is weak, the curds passing through the stomach and
intestines undissolved.
When there is any tendency to torpidity of the liver, daily exercise
should be directed to the liver, stomach, and intestines or milk may
cause biliousness, because the excess of fat and protein taken
overstimulates the liver, causing an excess of bile. The bile may
enter the stomach and cause nausea and vomiting. Constipation
results from the disordered digestion. This will not often occur if one
exercises daily and cuts down the quantity of solid food as the
amount of liquid is increased.
A glass of hot Vichy or Hunyadi water taken the first thing on
rising, and followed by a glass of cool water will help to relieve any
engorgement of the liver.
In case of biliousness resulting from a milk diet, abstain from all
food for twenty-four hours, cleanse the mouth as indicated above,
and drink freely of water.
When the liver is a little inactive, milk may be diluted with an
aërated water or even plain water. Daily exercise directed toward
securing a greater activity of the liver and gall-bladder should be
followed. Four tablespoonfuls of soda water, Apollinaris, or carbonic-
acid water to the glass may be used.
As noted in the preceding pages, orange and lemon juice will
encourage greater activity of the stomach and bowels.
One-third of a glass of hot Vichy water to each glass of milk
renders it easily digested and most people relish it. Unless the liver
is very inactive milk taken in this way will not constipate and
exercise directed to the liver, as previously mentioned, will help to
obviate this condition.
Skimmed milk, Kumyss, or buttermilk are easily digested and are
valuable when the digestive system is weak.
The monotony of a milk diet tends to create a distaste for milk
and the mental revolt may upset digestion and result in constipation.
This should be kept in mind and various ways of modifying the milk
be used to create variety; mental aversion and antagonism should
be corrected.
When its taste is not relished milk may be made acceptable and
the stomach induced to retain it by using a variety of flavors. A drop
or two of vanilla, a trifle of cinnamon, nutmeg, salt and pepper,
chocolate, or any other flavor that is liked may be used, varying
them so as to keep from monotony.
If milk seems to produce gas in the stomach with distress and the
milk is retained too long in the stomach from the interference with
its movements caused by the gas, a teaspoonful of malt extract may
be added to each glass of milk. If the malt extract is not at hand,
four teaspoonfuls of malted milk to each glass may be used.
Equal parts of cream and hot water to which has been added a
third of a teaspoon of soda may be used, for the same purpose.
If milk disagrees because of an excess of hydrochloric acid and the
formation of hard curds, a saltspoon of salt or bicarbonate of soda
may be used, or one part of limewater to six parts of milk.
When milk seems to disagree because digestion is somewhat slow
and the milk does not offer enough bulk to excite peristaltic action, it
remains too long in the stomach and fermentation occurs. A slice of
bread, a couple of crackers, a piece of zweiback, a tablespoonful of
Nestle’s or Mellin’s food or of arrowroot gruel added to each glass, or
eaten with the milk, will give it more body and prevent the formation
of large curds.
When the stomach is excessively weak because of a lack of the
digestive juices and a consequent incomplete action of the stomach,
only predigested milk should be taken until the stomach has been
brought to a normal tone. Pepsin or pancreatin may be used for the
partial digestion. Milk so predigested must be freshly prepared each
time it is used or must be kept on ice until used. The stomach will
find practically no difficulty in assimilating milk thus prepared, and
constipation will be avoided.
It must be remembered that milk must be sipped slowly and be
well mixed with saliva before it is swallowed.
Milk can be soured and taken separated as a variation, the curds
and whey being relished by many when properly prepared. A little
sugar and cinnamon or nutmeg sprinkled on curds or mixed with the
whey make a palatable mixture. Buttermilk or kumyss offer still other
variations.
With all these means of varying the taste, appearance, or
condition of milk it is hardly possible that some way cannot be found
whereby milk may be taken and be well borne by the stomach and
the full benefits from its use be derived.
This is the casein (protein) which has been
Cheese separated from milk by the action of rennet. It is
highly nutritious and many varieties are on the
market. In Europe it is largely used to take the place of meat.
Cheese contains almost as much again protein as is contained in the
same quantity of meat.
In this country more highly flavored cheeses are in demand, and
when eaten in moderate quantities they aid digestion. They are
highly concentrated food and but a small quantity should be eaten at
a meal, particularly if meat has constituted a part of the meal.
The cheeses poor in fat are more difficult to digest as they are
harder and not so easily masticated.
Contrary to the prevalent idea, a properly made Welsh rarebit is
more easily digested than uncooked cheese.
One should use judgment, in eating any highly concentrated food,
not to eat too large a quantity.
Smierkase, or cottage cheese, is coagulated casein. It contains
thirty-three per cent. of protein, twenty-four per cent. of fat, and five
per cent. of salts.
The thickening of the milk, or the coagulation of the casein, is like
that produced by lactic acid.
Skimmed milk, as shown by the table, contains the same amount
of protein as fresh milk, but more sugar and more ash, the
difference consisting almost entirely of less fat, which has been
removed in the cream.
Buttermilk. There is less fat, protein, sugar, or ash in buttermilk
than in skimmed milk; it is therefore less nourishing, but it requires
less digestive effort. The sugar has partially fermented and the lactic
acid is freed. It is the free lactic acid which gives the pungent taste.
Buttermilk made by lactone or Bulgarian tablets and fresh milk is
as nourishing and as desirable as that made in the process of butter
making, and it has the advantage of being fresh. When the whole
milk is used it, of course, contains the same amount of fat, protein,
sugar, and ash as the milk. It is of value in cases of poor digestion of
protein and fat, and in chronic stomach trouble. It has been claimed
that the bacilli in buttermilk made from the Bulgarian tablets prevent
putrefaction in the large intestine. This is disputed, however.
Clabbered Milk. The casein in clabbered milk coagulates and if
kept in a hot place the coagulation continues until the water, sugar,
and salts are separated. Clabbered or loppered milk is wholesome. It
may be sweetened or salted and flavored to taste.
Whey is the watery portion of milk from which the casein has
been removed in the process of making cheese. It is a palatable
drink and may be flavored with a little nutmeg and sugar or salt.
Invalids usually relish it. Beef tea or egg yolk may be added to it.
Milk Sugar. Sugar made from milk is now a commercial product; it
is evaporated and transformed into a fine powder. This powder is
used by physicians and druggists in compounding powders, pills,
tablets, etc.
Junket. The tablets used in making junket are the essence of
rennet. Milk coagulated by rennin has not the sour taste of milk
coagulated by acid. It is an admirable article of diet in many
weakened conditions of the digestive tract.
Condensed Milk is made by evaporating the water until it is
reduced to about sixty-one per cent. It is then hermetically sealed. It
is convenient for use whenever fresh milk cannot be obtained, but
the process of evaporation changes its flavor so that few care for it
as a drink. It may be substituted for cream in coffee, and diluted
with three times its volume in water the proportions are again the
same as before the water was evaporated.

FOOTNOTES:
[4] Charles D. Woods, Dr. Sc., in Cereal Breakfast Foods.
CHAPTER IV
BEVERAGES

B EVERAGES are used primarily to relieve thirst; they may also


contain food elements; they may be used for their effect in heat
and cold, for their flavor, which helps to increase the appetite, or for
their stimulating properties.
They are used to aid digestion and the elimination of waste, to
promote sweating, to soothe inflamed air passages or digestive
membranes. They furnish extra nutrition, stimulate nerve action,
quench thirst in fevers, warm the body when it is cold or cool it
when it is hot. They are used in health or disease, from the snows of
the arctics to the palms of the tropics. They may be alkaline or acid,
mineral, medicated or mucilaginous, effervescing or plain. The
question of their utility and preparation is important in any
discussion of foods and food products, though in themselves they
are not foods.
The people of all races seemingly crave a stimulant, after bodily or
mental exertion, in fatigue, as a “bracer” in prolonged effort, as a
promoter of sociability, or as an offering of hospitality. These
stimulants are either alcoholic or non-alcoholic.
It is a notable fact that no tribe is so remote that it does not
possess some form of beverage which may be offered to friends or
used to promote feelings of conviviality; or it may be used to stir up
rage if onslaughts against neighboring tribes are contemplated. The
craving is universal and as old as the race.
Those who decry this craving when it takes the form of alcohol are
often themselves addicted to excessive drinking of non-alcoholic
stimulants.
Tea is not a food—it is a stimulant. It is made by
Tea steeping the leaves of a shrub, called Thea, which
grows in the tropical regions of Asia and adjacent
islands.
Green tea differs from black in the mode of its preparation. In
green tea the leaves are steamed before they are dried.
The amount of tannin in green tea is greater than in black, hence
green tea is regarded as not so wholesome a drink as black tea.
The young tender leaves are more delicate of flavor.
Varieties of plants differ both in the amount of tannin and the
delicacy of flavor.
Tea should never be boiled or allowed to stand longer than a few
minutes; standing causes the tannin to be extracted from the leaves,
and this tannin disturbs digestion. It is the tannin extracted from the
bark of trees which toughens animal skins into leather.
The best way to make tea is to pour on boiling water and serve
within five minutes.
Because of the uncertainty as to the length of time tea may be
allowed to steep in hotel kitchens or restaurants, it is a wise custom
to have a ball of tea and a pot of hot water served that the guest
may make the tea at the table.
Tea is diuretic, stimulating the action of the kidneys. Through its
stimulant action it relieves fatigue and has been found especially
useful in Arctic explorations and for soldiers on long marches.
When taken hot it will often relieve sick headache. When taken on
an empty stomach, after a long fatiguing tramp or a prolonged
“shopping” excursion, its refreshing effect may be felt for an hour or
two.
The ease of its preparation and the quickness of its effect tends to
produce the “tea habit.” When drunk to excess with meals, it causes

You might also like