100% found this document useful (10 votes)
14K views

Kolman - Discrete Mathematical Structures 6e

Uploaded by

Pangdam Setiawan
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 (10 votes)
14K views

Kolman - Discrete Mathematical Structures 6e

Uploaded by

Pangdam Setiawan
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/ 550

List of Frequently Used Symbols

Chapter 1 p=}q P implies q , p. 57


0, b, c, x, )1, Z elements of a set, p. 2 p=.q p is equivalent to q, p. 58
E belongs to, p. 2
Z+ the set of positive integers, p. 2 Chapter 3
N the set of nonnegative integers, p. 2 lIP,. the number of permutations of n
Z the set of integers, p. 2 objects taken r at a time, p. 94
Q the set of rational numbers, p. 2 /1 1 Il-factorial, p. 94
IR the set of real numbers, p. 3 lI e,. the number of combinations of 11
0, { } the empty set, p. 3 objects taken r at a time, p. 97
c is contained in , p. 3 peE ) the probability of the even t E,
p. 106
U the uni versal set, p. 3
IAI the card inality of A, p. 4 !E the frequency of occurrence of
event E, p. 106
peA) the set of all subsets of A, p. 4
AUB the un ion of sets A and B, p. 5 Chapter 4
An B the intersection of sets A and B,
A x B the Cartesian product of A and B ,
p.6
p. 123
"
UA k the union from J to n of Ab p. 7 R(x) the R -relative set of x, p. 130
k =J
R(A) the R-relative set of A, p. 130
"
nA k the intersection from 1 to 11 of Ab
MR the matrix of R, p. 131
k= J p. 7
ROO the connectivity relation of R, the
A-B the complement of B with respect
to A, p. 7 transitivity closure of R, p. 136
R* the reachabi1ity relation of R,
A the complement of A, p. 7
p.139
A EB B the symmetric difference of sets A
!:::,. the relation of equality, p. 141
and B, p. 7
A* the set of all fin ite sequences of =. b (mod /1) congruent to b mod II , p. 148
elements of A, p. 17 [a ) the equivalence class of a, p. 150
/\. the empty sequence or string, p. 17
AIR a partition of set A determined by
11 1m 12 divides m , p. 21 the equivalence relation R on A,
GCD(a , b) the greatest common divisor of a p. 150
and b , p. 22 SoR the composition of Rand S, p. 164
LCM(a , b) the least common multiple of a and
b,p.25
Chapter 5
((hdk- I . .. d ldo)" the base b expansion, p. 27
AT I II the identity function on A, p. 183
the transpose of the matrix A, p. 35
f- I the inverse of the function f , p. 185
Av B the join of A and B, p. 37
A /\ B the meet of A and B, p. 37 f ll the characteri stic function of a set
A , p. 190
AOB the Boolean product of A and B,
p. 38 LxJ the largest integer less than or equal
to x , p. 190
rxl the smallest integer greater than or
Chapter 2 equal to x , p. 190
,../ ~ p not p , p. 5 1 o (f) the order of a function f , p. 200
P /\ q P and q , p. 52 8(f) the 8 -c1 ass of a function f , p. 20 I
p Vq P or q, p. 52 19 the base 2 log function, p. 202
V for all , p. 54 (a, a, · .. a )
:3 there exi sts, p. 54 pea,) P (~1) ... p(~,,) permutation of the set
A = {a i, a2, ... , a,, }, p. 205
Chapter 6 //? natural homomorphism of S onto
S/R, p. 359
< a partial order relation, p. 218
a// a left coset of H in G, p. 373
a v b, LUB(#, b) the least upper bound of a and b,
p. 230, 233
Chapter 10
a Ab, GLB(#, b) the greatest lower bound of a and b,
p. 230, 233 (V, 5, i>0, «->) phrase structure grammar, p. 388

a! the complement of a, p. 240 => direct derivability, p. 388


Bn Boolean algebra, p. 244 L(G) the language of G, p. 389
() ::= BNF specification of a grammar,
* y
o ** and gate, pp. 251-252 p. 395
y the set of transition functions of a
* y finite-state machine, p. 403
:£> *~ or gate, pp. 251-252
(5, /, 5^ a finite-state machine, p. 403
fx the transition function
•1>> - inverter (NOT), pp. 251-252
corresponding to input x, p. 403
(S, /, T, so, T) Moore machine, p. 405
Chapter 7 M/R quotient machine of machine M,
(7, u()) the tree with root i>o, p. 271 p. 406
r(i;) the subtree of T with root v, p. 273 l(w) the length of a string w, p. 411

Chapter 8 Chapter 11
(V, E,y) the graph with vertices in V and e an (m,n) encoding function, p. 430
edges in E, p. 306
8(x, y) the distance between the words x
£/„ the discrete graph on at vertices,
and >', p. 432
p. 308
A0 B the mod 2 sum of A and B, p. 435
Kn the complete graph on n vertices,
p. 308 A*B the mod 2 Boolean product of A
Ln the linear graph on n vertices, and B, p. 435
p. 308 d an (n, m) decoding function, p. 440
Ge the subgraph obtained by omitting e €j a coset leader, p. 443
from G, p. 308
x *H the syndrome of x, p. 446
GR the quotient graph with respect to
R, p. 309
etj excess capacity of edge (/, j),
p. 323
c(K) the capacity of a cut K, p. 327
X(G) the chromatic number of C, p. 335
PG the chromatic polynomial of G,
p. 336

Chapter 9
S5 the set of all functions from S to 5,
p. 349
S/R the quotient semigroup of a
semigroup 5, p. 358
Z„ the quotient set Z/ = (mod a?),
p. 358
Discrete Mathematical Structures
Discrete Mathematical
Structures
Sixth Edition

Bernard Kolman
Drexel University

Robert C. Busby
Drexel University

Sharon Cutler Ross


Georgia Perimeter College

Upper Saddle River, NJ 07458


Library of Congress Cataloging-in-Publication Data

Kolman, Bernard
Discrete mathematical structures / Bernard Kolman, Robert C. Busby,
Sharon Cutler Ross. — 6th ed.
p. cm.
Includes index.
I. Computer Science—Mathematics. I. Busby, Robert C. n. Ross,
Sharon Cutler m. Title.
QA76.9.M35K64 2009
511.6—dc22 2008010264

President: Greg Tobin


Editor-in-Chief: Deirdre Lynch
Senior Acquisitions Editor: William Hoffman
Associate Editor: Caroline Celano
Project Manager: Kristy S. Mosch
Senior Managing Editor: Linda Mihatov Behrens
Operations Specialist: Lisa McDowell
Senior Operations Supervisor: Alan Fischer
Marketing Manager: Katie Winter
Marketing Assistant: Jon Connelly
Art Director/Cover Designer: Heather Scott
Interior Design/Illustrations/Composition: Dennis Kletzing
AV Project Manager: Thomas Benfatti
Cover Photo: Swinging (Schaukeln), 1925, Kandinsky, Wassily (1866-1944) ©ARS NY
Manager, Cover Visual Research and Permissions: Karen Sanatar
Director, Image Resource Center: Melinda Patelli
Manager, Rights and Permissions: Zina Arabia
Manager, Visual Research: Beth Brenzel
Image Permissions Coordinator: Debbie Hewitson
Photo Researcher: Beth Anderson
Art Studio: Laserwords

© 2009, 2004, 2000, 1996, 1987, 1984


Pearson Prentice Hall
Pearson Education, Inc.
Upper Saddle River, NJ 07458

All rightsreserved. No partof this book may be reproduced, in any form


or by any means, without permission in writing from the publisher.

PearsonPrentice Hall™ is a trademark of Pearson Education, Inc.

Printed in the United States of America


10 987654321

ISBN-13: 17fl-a-13-2ecn5:i,-b
ISBN-ID: O-ia-fiETTSl-S

Pearson Education Ltd., London


Pearson Education Singapore, Pte. Ltd.
Pearson Education Canada, Inc.
Pearson Education—Japan
Pearson Education Australia PTY, Limited
Pearson Education North Asia, Ltd., Hong Kong
Pearson Education de Mexico, S.A. de C.V.
Pearson Education Malaysia, Pte. Ltd.
Pearson Education Upper Saddle River, New Jersey
To the memory ofLillie and to Judith
B.K.

To my wife, Patricia, and our sons, Robert and Scott


R.C.B.

To Bill and bill


S.C.R.
Contents

Preface xi
A Word to Students xv

1 Fundamentals 1
1.1 Sets and Subsets 2
1.2 Operations on Sets 5
1.3 Sequences 13
1.4 Properties of the Integers 20
1.5 Matrices 32
1.6 Mathematical Structures 41

2 Logic 50
2.1 Propositions and Logical Operations 51
2.2 Conditional Statements 57
2.3 Methods of Proof 62
2.4 Mathematical Induction 68
2.5 Mathematical Statements 75
2.6 Logic and Problem Solving 78

3 Counting 91
3.1 Permutations 92
3.2 Combinations 96
3.3 Pigeonhole Principle 100
3.4 Elements of Probability 104
3.5 Recurrence Relations 112

4 Relations and Digraphs 122


4.1 Product Sets and Partitions 123
4.2 Relations and Digraphs 127
4.3 Paths in Relations and Digraphs 135
4.4 Properties of Relations 141
4.5 Equivalence Relations 148
4.6 Data Structures for Relations and Digraphs 152
4.7 Operations on Relations 159
4.8 Transitive Closure and Warshall's Algorithm 169
vii
viii Contents

5 Functions 180
5.1 Functions 181
5.2 Functions for Computer Science 190
5.3 Growth of Functions 200
5.4 Permutation Functions 205

Order Relations and Structures 217


6.1 Partially Ordered Sets 218
6.2 Extremal Elements of Partially Ordered Sets 228
6.3 Lattices 233
6.4 Finite Boolean Algebras 243
6.5 Functions on Boolean Algebras 250
6.6 Circuit Design 254

Trees 270
7.1 Trees 271
7.2 Labeled Trees 275
7.3 Tree Searching 280
7.4 Undirected Trees 288
7.5 Minimal Spanning Trees 295

O Topics in Graph Theory 305


8.1 Graphs 306
8.2 Euler Paths and Circuits 311
8.3 Hamiltonian Paths and Circuits 318
8.4 Transport Networks 321
8.5 Matching Problems 329
8.6 Coloring Graphs 334

V Semigroups and Groups 344


9.1 Binary Operations Revisited 345
9.2 Semigroups 349
9.3 Products and Quotients of Semigroups 356
9.4 Groups 362
9.5 Products and Quotients of Groups 372
9.6 Other Mathematical Structures 377
Contents ix

10 Languages and Finite-State Machines 386


10.1 Languages 387
10.2 Representations of Special Grammars and Languages 394
10.3 Finite-State Machines 403
10.4 Monoids, Machines, and Languages 409
10.5 Machines and Regular Languages 414
10.6 Simplification of Machines 420

1 1 Groups and Coding 429


11.1 Coding of Binary Information and Error Detection 430
11.2 Decoding and Error Correction 440
11.3 Public Key Cryptology 449

Appendix A: Algorithms and Pseudocode 455


Appendix B: Additional Experiments in
Discrete Mathematics 467

Appendix C: Coding Exercises 473


Answers to Odd-Numbered Exercises 477

Answers to Chapter Self-Tests 515


Glossary G-1
Index 1-1

Photo Credits P-l


Preface
Discrete mathematics is an interesting course both to teach and to study at the
freshman and sophomore level for several reasons. Its content is mathematics,
but most of its applications and more than half of its students are from computer
science or engineering concentrations. Thus, careful motivation of topics and pre
views of applications are important and necessary strategies. Moreover, there are
a number of substantive and diverse topics covered in the course, so a text must
proceed clearly and carefully, emphasizing key ideas with suitable pedagogy. In
addition, the student is generally expected to develop an important new skill: the
ability to write a mathematical proof. This skill is excellent training for writing
computer programs.
This text can be used by students as an introduction to the fundamental ideas of
discrete mathematics, and as a foundation for the development of more advanced
mathematical concepts. If used in this way, the topics dealing with specific com
puter science applications can be omitted or selected independently as important
examples. The text can also be used in a computer science or electrical and com
puter engineering curriculum to present the foundations of many basic computer
related concepts, and to provide a coherent development and common theme for
these ideas. The instructor can easily develop a suitable syllabus by referring to
the chapter prerequisites which identify material needed by that chapter.

• Approach
First, we have limited both the areas covered and the depth of coverage to what
we deem prudent in afirst course taught at the freshman and sophomore level. We
have identified a set of topics that we feel are of genuine use in computer science
and elsewhere and that can be presented in a logically coherent fashion. We have
presented an introduction to these topics along with an indication of how they can
be pursued in greater depth. This approach makes our text an excellent reference
for upper-division courses.
Second, the material has been organized and interrelated to minimize the mass
of definitions and the abstraction of some of the theory. Relations and digraphs are
treated as two aspects of the same fundamental mathematical idea, with a directed
graph being a pictorial representation of a relation. This fundamental idea is then
used as the basis of virtually all the concepts introduced in the book, including
functions, partial orders, graphs, and mathematical structures. Whenever possible,
each new idea introduced in the text uses previously encountered material and,
in turn, is developed in such a way that it simplifies the more complex ideas that
follow.

• What Is New in the Sixth Edition


We have been gratified by the wide acceptance of the first five editions of this book
throughout the 25 years of its life. Equally pleasing is the confirmation of the orig
inal decisions about content and approach for the book from the earliest editions.
For example, the Association of Computing Machinery Special Interest Group for
Computer Science Education (SIGCSE) and others have recently made recom
mendations regarding the structure of a one-semester course in discrete structures
that are well supported by this text. In preparing this edition, we have carefully
considered these recommendations, as well as many suggestions from faculty and

XI
xii Preface

students for improving the content and presentation of the material. Although
many changes havebeen made to develop this revision, our objective has remained
the same as in the first five editions: topresentthe basic notions ofdiscrete math
ematics and some of its applications in a clear and concise manner that will be
understandable to the student.
Webelieve that this bookworks well in the classroom becauseof the unifying
role playedby the twokey concepts: relations and digraphs. Substantial strength
ening of the logic material has been made by the addition of two new sections,
Mathematical Statements and Logic andProblem Solving along with accompany
ing exercises. New material on fuzzy sets and fuzzy logic introduces students to
a topic that is extremely important for modern issues of automated feedback and
control of processes. The popular puzzle Sudoku, related puzzles, and their under
lying mathematical connections, form a continuing thread in the text connecting
set theory, Boolean matrices, algorithms and coding, logic, the general construc
tion of proofs, coloring problems and polynomials, and other topics in a way that
students will find both interesting and instructive. Other important changes in
clude:

• Additional emphasis on how to develop a conjecture and how to prove or


disprove it.
• This edition continues to weave the discussion of proofs and proof tech
niques throughout the book with comments on most proofs, exercises related
to the mechanics of proving statements, and Tips for Proofs sections. Many
of the new exercises provide more practice in building proof-reading and
-writing skills.
• More applications are included.
• More exercises have been added.
• More figures have been included
• A number of explanations have been rewritten for greater clarity and im
proved pedagogy.
• The End-of-Chapter material from the fifth edition has been rearranged as
follows: the conceptual review questions are now folded into the Self-Test
at the end of each chapter and the coding exercises have been moved to
Appendix C.

• Exercises
The exercises form an integral part of the book. Many are computational in na
ture, whereas others are of a theoretical type. Many of the latter and the experi
ments, to be further described below, require verbal solutions. Exercises to help
develop proof-writing skills ask the student to analyze proofs, amplify arguments,
or complete partial proofs. Guidance and practice in recognizing key elements
and patterns have been extended in many new exercises. Answers to all odd-
numbered exercises and self-test items appear in the back of the book. Solutions
to all exercises appear in the Instructor's Solutions Manual, which is available
(to instructors only) gratis from the publisher. The Instructor's Solutions Manual
also includes notes on the pedagogical ideas underlying each chapter, goals and
grading guidelines for the experiments (further described below), and a test bank.

• Experiments
Chapters 1 through 10 each end with a student experiment. These provide oppor
tunities for discovery and exploration, or a more-in-depth look at topics discussed
Preface xiii

in the text. They are designed as extended-time, out-of-class experiences and are
suitable for group work. Each experiment requires significantly more writing than
section exercises do. Some additional experiments are to be found in Appendix B.
Content, prerequisites, and goals for each experiment are given in the Instructor's
Solutions Manual.

• Coding Exercises
A set of coding exercises for each chapter are included in Appendix C.

• End-of-Chapter Material
Each chapter contains Tips for Proofs, a summary of Key Ideas, and a Self-Test
including a set of conceptual review questions covering the chapter's material.

• Organization
Chapter 1 contains material that is fundamental to the course. This includes sets,
subsets, and their operations; sequences; properties of the integers including base
n representations; matrices; and mathematical structures. A goal of this chapter
is to help students develop skills in identifying patterns on many levels. Chapter
2 covers logic and related material, including methods of proof and mathematical
induction. Although the discussion of proof is based on this chapter, the commen
tary on proofs continues throughout the book. Two new sections, Mathematical
Statements and Logic and Problem Solving have been added. This material is used
to briefly discuss the currently widely popular puzzle Sudoku and related puzzles.
Chapter 3, on counting, deals with permutations, combinations, the pigeonhole
principle, elements of discrete probability, and recurrence relations.
Chapter 4 presents basic types and properties of relations, along with their rep
resentation as directed graphs. Connections with matrices and other data structures
are also explored in this chapter. Chapter 5 deals with the notion of a function, and
gives important examples of functions, including functions of special interest in
computer science. An introduction to the growth of functions is developed. New
material on fuzzy sets and fuzzy logic has been added. Chapter 6 covers par
tially ordered sets, including lattices and Boolean algebras. A symbolic version
for finding a Boolean function for a Boolean expression is developed along with
the pictorial Karnaugh method. Chapter 7 introduces directed and undirected trees
along with applications of these ideas. Elementary graph theory with applications
to transport networks and matching problems is the focus of Chapter 8.
In Chapter 9 we return to mathematical structures and present the basic ideas
of semigroups, groups, rings, and fields. By building on work in previous chapters,
only a few new concepts are needed. Chapter 10 is devoted to finite state machines.
It complements and makes effective use of ideas developed in previous chapters.
Chapter 11 finishes the discussion of coding for error-detecting and correction and
for security purposes. Appendix A discusses Algorithms and Pseudocode. The
simplified pseudocode presented here is used in some text examples and exercises;
these may be omitted without loss of continuity. Appendix B gives some additional
experiments dealing with extensions or previews of topics in various parts of the
course. Appendix C contains a set of coding exercises, separated into subsets for
each chapter.

• Optional Supplements
There is available with this text a 406 page workbook: Practice Problems in Dis
crete Mathematics by Boyana Obrenic (ISBN 0-13-045803-1). It consists entirely
xiv Preface

of problem sets with fully worked out solutions. In addition, there is a 316 page
workbook: Discrete Mathematics Workbook by James Bush (ISBN 0-13-046327-
2). This item has outlines of key ideas, key terms, and sample problem sets (with
solutions).

• Acknowledgments
We are pleased to express our thanks to the following reviewers of the first four
editions: Harold Fredrickson, Naval Postgraduate School; Thomas E. Gerasch,
George Mason University; Samuel J. Wiley, La Salle College; Kenneth B. Reid,
Louisiana Sate University; Ron Sandstrom, Fort Hays State University; Richard
H. Austing, University of Maryland; Nina Edelman, Temple University; Paul
Gormley, Villanova University; Herman Gollwitzer and Loren N. Argabright, both
at Drexel University; Bill Sands, University of Calgary, who brought to our atten
tion a number of errors in the second edition; Moshe Dror, University of Ari
zona, Tucson; Lloyd Gavin, California State University at Sacramento; Robert
H. Gilman, Stevens Institute of Technology; Earl E. Kymala, California State
University at Sacramento; and Art Lew, University of Hawaii, Honolulu; Ashok
T. Amin, University of Alabama at Huntsville; Donald S. Hart, Rochester Institute
of Technology; Minhua Liu, William Rainey Harper College; Charles Parry, Vir
ginia Polytechnic Institute & University; Arthur T. Poe, Temple University; Suk
Jai Seo, University of Alabama at Huntsville; Paul Weiner, St. Mary's Univer
sity of Minnesota; and of the fifth edition: Edward Boylan, Rutgers University;
Akihiro Kanamori, Boston University; Craig Jensen, University of New Orleans;
Harold Reiter, University of North Carolina; Charlotte Zhong-Hui Duan, Univer
sity of Akron; and of the sixth edition: Danrun Huang, St. Cloud State University;
George Davis, Georgia State University; Ted Krovetz, California State Univer
sity, Sacramento; Lester McCann, The University of Arizona; Sudipto Ghosh,
Colorado State University; Brigitte Servatius, Worcester Polytechnic Institute;
Carlo Tomasi, Duke University; Andrzej Czygrinow, Arizona State University;
Johan Belinfante, Georgia Institute of Technology; Gary Walker, Pennsylvania
State University-Erie. The suggestions, comments, and criticisms of these people
greatly improved the manuscript.
We thank Dennis R. Kletzing, who carefully typeset the entire manuscript; Lil
ian N. Brady for carefully and critically reading page proofs; Blaise de Sesa, who
checked the answers and solutions to all the exercises in the book; and instructors
and students from many institutions in the United States and other countries, for
sharing with us their experiences with the book and offering helpful suggestions.
Finally, a sincere expression of thanks goes to Bill Hoffman, Senior Editor,
Caroline Celano, Associate Editor, Linda Behrens, Senior Managing Editor, Kristy
Mosch, Production Project Manager, Katie Winter, Marketing Manager, Jon Con
nelly, Marketing Assistant, Lisa McDowell, Operations Specialist, Heather Scott,
Art Director, Tom Benfatti, Art Editor, and to the entire staff of Pearson for their
enthusiasm, interest, and unfailing cooperation during the conception, design, pro
duction, and marketing phases of this edition.

B.K.
R.C.B.
S.C.R.
A Word to Students
This course is likely to be different from your previous mathematics courses in
several ways. There are very few equations to solve, even fewer formulas, and just
a handful of procedures. Although there will be definitions and theorems to learn,
rote memorization alone will not carry you through the course. Understanding
concepts well enough to apply them in a variety of settings is essential for success.
The good news is that there is a wealth of interesting and useful material in
this text. We have chosen topics that form a basis for applications in everyday life,
mathematics, computer science, and other fields. We have also chosen the topics
so that they fit together and build on each other; this will help you to master the
concepts covered.
Two distinctive features of this course are a higher level of abstraction and
more emphasis on proofs than you have perhaps encountered in earlier mathemat
ics courses. Here is an example of what we mean by abstraction. When you studied
algebra, you learned the distributive property of multiplication over addition. In
this course, you will abstract the concept of a distributive property and investigate
this idea for many pairs of operations, not just multiplication and addition.
The other feature is proofs. Before you close the book right here, let us tell
you something about how proofs are handled in this book. The goals are for you
to be able to read proofs intelligently and to produce proofs on your own. The way
we help you to these goals may remind you of your composition classes. Learning
to write a persuasive essay or a meaningful sonnet or another style composition is a
complicated process. First, you read, analyze, and study many examples. Next you
try your hand at the specific style. Typically this involves draft versions, revisions,
critiques, polishing, and rewriting to produce a strong essay or a good sonnet or
whatever form is required. There are no formulas or rote procedures for writing.
Proofs, like the products of a composition course, have structures and styles.
We give you lots of proofs to read and analyze. Some exercises ask that you
outline, analyze, or critique a proof. Other exercises require the completion of
partial proofs. And finally, there are many opportunities for you to construct a
proof on your own. Believe us, reading and writing proofs are learnable skills.
On a larger scale, we hope this text helps you to become an effective commu
nicator, a critical thinker, a reflective learner, and an innovative problem solver.
Best wishes for a successful and interesting experience.

XV
CHAPTER

1 Fundamentals
Prerequisites: There are noformal prerequisitesfor
thischapter; the reader is encouraged to read care
fully and work through all examples.

In this chapter we introduce some of the basic tools of discrete mathematics. We


begin with sets, subsets, and their operations, notions with which you may already
be familiar. Next we deal with sequences, using both explicit and recursive pat
terns. Then we review some of the basic properties of the integers. Finally we
introduce matrices and matrix operations. This gives us the background needed to
begin our exploration of mathematical structures.

Looking Back: Matrices


The origin of matrices goes back to approximately 200 B.C.E., 1897), a British mathematician and lawyer. In 1851, Sylvester
when they were used by the Chinese to solve linear systems of met Arthur Cayley (1821-1895), also a British lawyer with a
equations. After being in the shadows for nearly two thousand strong interest in mathematics. Cayley quickly realized the im-
years, matrices came back into mathematics toward the end of portance of the notion of a matrix and in 1858 published a book
the seventeenth century and from then research in this area pro- showing the basic operations on matrices. He also discovered a
ceeded at a rapid pace. The term "matrix" (the singular of "ma- number of important results in matrix theory,
trices") was coined in 1850 by James Joseph Sylvester (1814—

James Joseph Sylvester Arthur Cayley


2 Chapter 1 Fundamentals

1.1 Sets and Subsets

Sets

A set is any well-defined collection of objects called the elements or members


of the set. For example, the collection of all wooden chairs, the collection of all
one-legged black birds, or the collection of real numbers between zero and one
are all sets. Well-defined just means that it is possible to decide if a given object
belongs to the collection or not. Almost all mathematical objects are first of all
sets, regardless of any additional properties they may possess. Thus set theory is,
in a sense, the foundation on which virtually all of mathematics is constructed. In
spite of this, set theory (at least the informal brand we need) is quite easy to learn
and use.
One way of describing a set that has a finite number of elements is by listing
the elements of the set between braces. Thus the set of all positive integers that are
less than 4 can be written as

{1,2,3}. (1)
The order in which the elements of a set are listed is not important. Thus
{1,3, 2}, {3, 2,1}, {3,1,2}, {2, 1, 3}, and {2, 3, 1} are all representations of the set
given in (1). Moreover, repeated elements in the listing of the elements of a set can
be ignored. Thus, {1, 3, 2, 3,1} is another representation of the set given in (1).
We use uppercase letters such as A, B, C to denote sets, and lowercase letters
such as ay b, c, x, y, z, t to denote the members (or elements) of sets.
We indicate the fact that x is an element of the set A by writing x € A, and
we indicate the fact that x is not an element of A by writing x £ A.

Example 1 Let A = {1, 3,5,7}. Then 1 e A, 3 e A,but 2 £ A. ♦

Sometimes it is inconvenient or impossible to describe a set by listing all of


its elements. Another useful way to define a set is by specifying a property that
the elements of the set have in common. We use the notation P(x) to denote
a sentence or statement P concerning the variable object x. The set defined by
P(x), written {x \ P(x)}, is just the collection of all objects for which P is sensi
ble and true, {x \ P(x)} is read, "the set of all x such that P(x)." For example,
{x | x is a positive integer less than 4} is the set {1, 2, 3} described in (1) by listing
its elements.

Example 2 The setconsisting ofallthe letters inthe word "byte" canbe denoted by {b, y, t, e}
or by {x \ x is a letter in the word "byte"}. ♦

Example 3 We introduce here several sets and their notations thatwill be used throughout this
book.

(a) Z+ = {x | x is a positive integer}.


Thus Z+ consists of the numbers used for counting: 1,2,3
(b) N = {x | x is a positive integer or zero} = {x \ x is a natural number}.
Thus N consists of the positive integers and zero: 0, 1, 2,
(c) Z = {jc | x is an integer}.
Thus Z consists of all the integers: ..., -3, -2, -1, 0, 1, 2, 3,....
(d) Q = {x | x is a rational number}.
a
Thus Q consists of numbers that can be written as -, where a and b are inte-
b
gers and b is not 0.
1.1 Sets and Subsets 3

(e) R = {x | x is a real number}.


(f) The set that has no elements in it is denoted either by { } or the symbol 0 and
is called the empty set. ♦

Example 4 Since thesquare of a real number is always nonnegative,


{x | x is a real number andx2 = —1} = 0. ♦

Sets are completely known when their members are all known. Thus we say
two sets A and B are equal if they have the same elements, and we write A = B.

Example 5 If A = {1, 2, 3} and B = {x \ x is a positive integer and x2 < 12}, then A = B. ♦

Example 6 If A = {JAVA, PASCAL, C++} and B = {C++, JAVA, PASCAL}, then A = B. ♦

Subsets
If every element of A is also an element of B, that is, if whenever x e A then
x € B, we say that A is a subset of B or that A is contained in B, and we write
A c B. If A is not a subset of B, we write A <£ B. (See Figure 1.1.)
ACB a£b Diagrams, such as those in Figure 1.1, which are used to show relationships
between sets, are called Venn diagrams after the British logician John Venn. Venn
Figure 1.1 diagrams will be used extensively in Section 1.2.

Example 7 We have Z+ c Z. Moreover, if Qdenotes thesetof rational numbers, then Z c

Example 8 Let A = {1,2,3,4,5,6}, B = {2,4,5}, and C = {1,2,3,4,5}. Then B c A,


B c C, and C c A. However, A £ B, A <£ C, and C £ B. ♦

Example 9 If A is any set, then A c A. Thatis, every set is a subset of itself. ♦

Example 10 Let A be a setand let B = {A, {A}}. Then, since A and {A} areelements of B, we
have A € £ and {A} e B. It follows that {A} c S and {{A}} c B. However, it is
not true that A c B. ♦

For any set A, since there are no elements of 0 that are not in A, we have
0 c A. (We will look at this again in Section 2.1.)
It is easy to see that A = B if and only if A c B and 5 c A. This simple
statement is the basis for proofs of many statements about sets.
The collection of everything, it turns out, cannot be considered a set without
presenting serious logical difficulties. To avoid this and other problems, which
need not concern us here, we will assume that for each discussion there is a "uni
versal set" U (which will vary with the discussion) containing all objects for which
the discussion is meaningful. Any other set mentioned in the discussion will auto
matically be assumed to be a subset of U. Thus, if we are discussing real numbers
and we mention sets A and B, then A and B must (we assume) be sets of real
numbers, not matrices, electronic circuits, or rhesus monkeys. In most problems,
a universal set will be apparent from the setting of the problem. In Venn diagrams,
the universal set U will be denoted by a rectangle, while sets within U will be
Figure 1.2 denoted by circles as shown in Figure 1.2.
4 Chapter 1 Fundamentals

A set A is called finite if it has n distinct elements, where n g N. In this


case, n is called the cardinality of A and is denoted by |A|. Thus, the sets of
Examples 1, 2, 4, 5, and 6 are finite. A set that is not finite is called infinite. The
sets introduced in Example 3 (except 0) are infinite sets.
If A is a set, then the set of all subsets of A is called the power set of A and is
denoted by P(A). (Be sure to distinguish between P(A), a statement about A, and
P(A), the power set of A.)

Example 11 Let A = {1,2, 3}. Then P(A) consists ofthe following subsets ofA: { }, {1}, {2},
{3}, {1, 2}, {1, 3}, {2, 3}, and {1, 2, 3} (or A). In a later section, we will count the
number of subsets that a set can have. ♦

1.1 Exercises

1. Let A = {1, 2,4, a, b, c}. Identify each of the following (e) {x | x is a real number and x —x + 1}
as true or false.
12. List all the subsets of [a,b].
(a) 2 e A (b) 3 e A (c) c £ A
13. List all the subsets of {JAVA, PASCAL, C++}.
(d) 0 g A (e) { } i A (f) A g A
14. List all the subsets of { }.
2. Let A = {x | x is a real number and x < 6}. Identify
each of the following as true or false. 15. Let A = {1, 2, 5, 8, 11}. Identify each of the following as
true or false.
(a) 3 g A (b) 6 g A (c) 5 i A
(a) {5,1}CA (b) {8,1}gA
(d) 8£ A (e) -8gA (f) 3.4 i A
3. In each part, give the set of letters in each word by listing (c) {1,8,2,11,5} £ A (d) 0C A
the elements of the set. (e) {1,6} £ A (f) {2}CA
(a) AARDVARK (b) BOOK (g) {3}£ A (h) AC {11,2,5,1,8,4}
(c) MISSISSIPPI 16. Let A = {x | x is an integer andx2 < 16}. Identify each
4. Give the set by listing its elements. of the following as true or false.
(a) The set of all positive integers that are less than ten. (a) {0,1, 2, 3} c A (b) {-3, -2, -1} c A
(b) {jc | x GZand*2 < 12} (c) { }c A
5. Let A = {1, {2,3}, 4}. Identify each of the following as (d) {x | x is an integer and \x\ < 4} c A
true or false.
(e) AC {-3,-2,-1,0, 1,2,3}
(a) 3 g A (b) {1,4} c A (c) {2,3} c A 17. Let A = {1}, B = {1, a, 2, b, c}, C = {b, c}, D = {a, b},
(d) {2,3}gA (e) {4}gA (f) {1,2,3}CA and E = {1, a, 2, b, c, d}. For each part, replace the sym
bol • witheither c or £ to givea true statement.
In Exercises 6 through 9, write the set in theform {x \ P(x)},
where P(x) is a property thatdescribes the elementsof theset. (a) A • B (b) 0 d A (c) BBC
(d) CD£ (e) D • C (f) BDE
6. {2,4,6,8,10} 7. {a,e,i,o,u}
8. {1, 8, 27, 64,125} 9. {-2, -1,0,1, 2} In Exercises 18 through 20, find the set ofsmallest cardinality
10. Let A = {1,2, 3,4, 5}. Which of the following sets are that contains the given sets as subsets.
equal to A? 18. {a,b,c}Aa,d,e,f),{b,c,e,g}
(a) {4,1,2,3,5} (b) {2,3,4} (c) {1,2,3,4,5,6} 19. {1,2},{1,3},0
(d) {x | x is an integer and x2 < 25}
20. {2,4,6,...,20},{3,6,9,...,21}
(e) {x | x is a positive integer and x < 5}
21. Is it possible to have two different (appropriate) univer
(f) {x | x is a positive rational number and x < 5} sal sets for a collection of sets? Would having different
11. Which of the following sets are the empty set? universal sets create any problems? Explain.
(a) {x | x is a real number and x2 —1 = 0} 22. Use the Venn diagram in Figure 1.3 to identify each of the
(b) {x | x is a real number and x2 + 1 = 0} following as true or false.
(c) {* | x is a real number and x2 = —9} (a) A c B (b) B c A (c) C cz B
(d) {x | x is a real number and x = 2x + 1} (d) x G B (e) x G A (f) y e B
1.2 Operations on Sets 5

25. Complete the following statement. A generic Venn dia


gram for three sets has regions. Describe them in
words.

26. (a) IfA = {3,7},findP(A).


(b) Whatis|A|? (c) What is |P(A)|?
27. If P(B) = {{ },{m},{/2}, {m,n}}, then find £.
28. (a) If A = {3,7,2}, find P(A).

Figure 1.3 (b) What is |A|? (c) What is |P(A)|?


29. If P(B) = {{a},{ },{c},{fc,c}, {a, &},...} and
23. Use the Venn diagram in Figure 1.4 to identify each of the
\P(B)\ = 8, then B =
following as true or false.
(a) KA (b) A c C (c)Ca In Exercises 30 through 32, draw a Venn diagram that repre
sents these relationships.
(d) w g A (e) t eA (f) w e B
30. A c B, A c C, B £ C, and C g B
31. x G A, x G £, x <£ C, y G B, y G C, and y <£ A
32. A c £, x £ A, * G £, A £ C, y G £, y G C
33. Describe all the subset relationships that hold for the sets
given in Example 3.
34. Show that if A c B and B c C, then A c C.
35. The statement about sets in Exercise 34 can be restated
as "Any subset of is also a subset of any set that
contains "
Figure 1.4 36. Suppose we know that set A has n subsets, Si, S2,..., Sn.
If set B consists of the elements of A and one more ele
24. (a) Complete the following statement. A generic Venn
diagram for a single set has regions. Describe ment so |Z?| = IAI+1, show that B must have 2n subsets.
them in words, 37. Compare the results of Exercises 12, 13, 26, and 28 and
(b) Complete the following statement. A generic Venn complete the following: Any set with two elements has
diagram for two sets has regions. Describe subsets. Any set with three elements has
them in words. subsets.

1.2 Operations on Sets


In this section we will discuss several operations that will combine given sets to
yield new sets. These operations, which are analogous to the familiar operations
on the real numbers, will play a key role in the many applications and ideas that
follow.
If A and B are sets, we define their union as the set consisting of all elements
that belong to A or B and denote it by A U B. Thus

AU B = {x \x e Aorx e B}.

Observe that x e AU B if x e A or x e B or x belongs to both A and B.

Example 1 Let A = {a,b,c, e, f] and B = {b, d, r, s}. Find AU B.

Solution
Since AU B consists of all the elements that belong to either A or B, AU B =
{a, b, c,d, e, /, r, s}. ♦

We can illustrate the union of two sets with a Venn diagram as follows. If A
and B are the sets in Figure 1.5(a), then A U B is the set represented by the shaded
region in Figure 1.5(b).
6 Chapter 1 Fundamentals

(b)AUfi

Figure 1.5

If A and B are sets, we define their intersection as the set consisting of all
elements that belong to both A and B and denote it by A fl B. Thus

A fl B = {x | x g A and jc G 5}.

Example 2 Let A = {a, ft, c,e, /}, B = {ft, e, /, r, *}, and C = [a, t, w, u}. Find A n fi,
A fl C, and B fl C.

Solution
The elements ft, e, and / are the only ones that belong to both A and B, so AHi? =
{ft, e, /}. Similarly, A fl C = {a}. There are no elements that belong to both B
and C, so B fl C = { }. ♦

Two sets that have no common elements, such as B and C in Example 2, are
called disjoint sets.
We can illustrate the intersection of two sets by a Venn diagram as follows. If
A and B are the sets given in Figure 1.6(a), then A fl B is the set represented by
the shaded region in Figure 1.6(b). Figure 1.7 illustrates a Venn diagram for two
disjoint sets.

(b)AHB

Figure 1.7

The operations of union and intersection can be defined for three or more sets
in an obvious manner:

A U B U C = {x | x G A or* G B orx g C]

and
A fl B n C = {x | x g A and x e B and x e C}.
The shaded region in Figure 1.8(b) is the union of the sets A, B, and C shown
in Figure 1.8(a), and the shaded region in Figure 1.8(c) is the intersection of the
sets A, B, and C. Note that Figure 1.8(a) says nothing about possible relation
ships between the sets, but allows for all possible relationships. In general, if
Ai, A2,..., A„ are subsets of £/, then A\ U A2 U ••• U An will be denoted by
1.2 Operations on Sets 7

<ffm^. U

m
M,

lift!
$M
wi0k ^•pf >W$i$\
\pC: m|:;v pfttSj
lm^JWf
W'W
(b)AU£UC (c) A n b n c

Q A*, read as, "the union from 1to nof Asub fc," and Ai DA2 H•••fl An will be
denotedby P| A*, read as, "the intersection from 1 to n of A sub /:."

Example 3 Let A = {1, 2, 3,4, 5,7}, B = {1, 3, 8, 9}, and C = {1, 3, 6, 8}. Then AHBDC
is the set of elements that belong to A, £, and C. Thus A fl B H C = {1,3}. ♦

If A and B are two sets, we define the complement of B with respect to A as


the set of all elements that belong to A but not to B, and we denote it by A - B.
Thus
A - B = {x | x G A and jc £ 5}.

Example 4 Let A = {a, 6, c) and £ = {6, c, J, e}. Then A- B = {a} and B - A = {d, e). ♦

If A and B are the sets in Figure 1.9(a), then A - B and £ - A are represented
by the shaded regions in Figures 1.9(b) and 1.9(c), respectively.

( A(

(b) A - B (c) B-A

If U is a universal set containing A, then [/ —A is called the complement of


A and is denoted by A. Thus A = [x \ x £ A}.

Example 5 LetA = {x \ x is an integer and * < 4} and U = Z. Then A = {x | x is aninteger


and jc > 4}. ♦

If A is the set in Figure 1.10, its complement is the shaded region in that figure.
If A and B are two sets, we define their symmetric difference as the set of all
elements that belong to A or to B, but not to both A and B, and we denote it by
A © B. Thus

A © B = [x | (jc g A and jc £ B) or (jc G £ and x £ A)}.

Example 6 Let A = {«, ft, c, d] and £ = {a,c, e, /, g}. Then A® B = {b,d, e, /, g}.
8 Chapter 1 Fundamentals

Figure 1.10

If A and B are as indicatedin Figure 1.11(a),their symmetricdifferenceis the


shaded region shownin Figure 1.11(b). It is easy to see that

A 0 B = (A - B) U (B - A).

(a) (b) A H B

Figure 1.11

Algebraic Properties of Set Operations


The operations on sets that we havejust defined satisfymany algebraic properties,
some of which resemble the algebraic properties satisfied by the real numbers and
their operations. All the principal properties listed here can be proved using the
definitions given and the rules of logic. We shall proveonly one of the properties
and leave proofs of the remaining ones as exercises for the reader. Proofs are
fundamental to mathematics. We discuss proof techniques in Chapter 2, but in this
chaptersomeproofsare given as examples for later work. Some simpleproofs are
required in the exercises. Venn diagrams are often useful to suggest or justify the
method of proof.

THEOREM 1 The operations defined on setssatisfy the following properties:


Commutative Properties
1. AUB = BUA
2. ADB = BHA

Associative Properties
3. A U (B U C) = (A U B) U C
4. A n (B n C) = (A n B) n c
Distributive Properties
5. A H (B U C) = (A fl B) U (A n C)
6. A U (B fl C) = (A U B) n (A U C)
1.2 Operations on Sets 9

Idempotent Properties
7. A U A = A
8. A fl A = A

Properties ofthe Complement


9. (A) = A
10. A U A = 17
11. Ar\A = 0
12. 0 = U
13. £/ = 0
14. A U B = A fl B Properties 14 and 15 are known as
15. ADA = AUfl De Morgan's laws.
Properties ofa Universal Set
16. A U U = U
17. A H f/ = A

Properties ofthe Empty Set


18. AU0 = AorAU{ } = A
19. A H 0 = 0 or A D { } = { }

Proof
We prove Property 14 here and leave proofs of the remaining properties as ex
ercises for the reader. A common style of proof for statements about sets is to
choose an element in one of the sets and see what we know about it. Suppose that
x € A U B. Thenwe know that x i A U fl, so x £ A and x £ fl. JWhy?) This
means x e_A HB (why?), so each element of A U fl belongs to A fl fl. Thus
A U B c AC) fl. Conversely, suppose thatx e A D fl. Then x £ A andxjz fl
(why?), so x fi AUfl, which means that x e A U fl. Thus each element of AH fl
also belongs to A U fl, and A D fl c A U fl. Now we see that A U fl = A fl fl. •

Anfl
The Addition Principle
Suppose now that A and fl are finite subsets of a universal set U. It is frequently
useful to have a formula for |A U fl|, the cardinality of the union. If A and fl are
disjoint sets, that is, if A fl fl = 0, then each element of A U fl appears in either A
or B, but not in both; therefore, |AUfl| = |A| + |fl|.IfA and fl overlap, as shown
in Figure 1.12, then elements in A fl fl belong to both sets, and the sum \A\ + \B\
Figure 1.12 counts these elements twice. To correct for this double counting, we subtract
|A fl fl|. Thus we have the following theorem, sometimes called the addition
principle. Because of Figure 1.12, this is also called the inclusion-exclusion
principle.

THEOREM 2 If A and fl are finite sets, then |A U fl| = |A| + |fl| - |A n fl|. •

Example 7 Let A = {a, b,c, d, e] and fl = {c, e, /, h, k,m}. Verify Theorem 2.

Solution
We have A U fl = {a, b, c, d, e, f h, k, m] and A fl fl = {c, e). Also, \A\ = 5,
|fl| = 6, |A U fl| = 9, and \A D fl| = 2. Then |A| + |fl| - |A fl fl| = 5 + 6 - 2
or 9 and Theorem 2 is verified. ♦
10 Chapter 1 Fundamentals

ADB If A and fl are disjoint sets, ADA = 0 and \A n fl| = 0, so the formula in
Theorem 2 now becomes |AUfl| = |A| + |fl|. This special case can be stated in
a way that is useful in a variety of counting situations.
If a task T\ can be performed in exactly n ways, and a different task T2 can be
An Bn C performed in exactly m ways, then the number of ways of performing task T\ or
task T2 is n +m.

ADC Bnc
The situation for three sets is shown in Figure 1.13. We state the three-set
Figure 1.13 addition principle without discussion.

THEOREM 3 Let A, fl, and C befinite sets. Then \A Ufl UC\ = \A\ + \B\ + \C\ - |A n fl| -
|fl n c| - |A n C| + |A n fl n C|. •
Theorem 3 can be generalized for more than three sets. This is done in Exer
cises 50 and 51.

Example 8 Let A = {a,b,c, d, e}, fl = {a, b, e, g, /z}, and C = {b,d,e, g,h9k,m,n}.


Verify Theorem 3.

Solution
We have AUBUC = (a,fe,c,rf, e, g, h, k, m, n}, A fl fl = {a, b, e}, A fl C =
{6, d, e},BDC = {b, e, g, /*}, and AHflHC = {£, <?}, so \A\ = 5, |fl| = 5, \C\ =
8, |AUflUC| = 10, |AHfl| = 3, |AHC| = 3, |flnC|=4,and|AflflnC| =2.
Thus |A|+|fl|+|C|-|Anfl|-|flnC|-|AnC|+|AnflnC| = 5+5+8-3-3-4+2
or 10, and Theorem 3 is verified. ♦

Example 9 A computer company wants to hire 25 programmers to handle systems program


ming jobs and 40 programmers for applications programming. Of those hired, ten
will be expected to perform jobs of both types. How many programmers must be
hired?

Solution
Let A be the set of systems programmers hired and fl be the set of applications
programmers hired. The company must have \A\ = 25 and |fl| = 40, and \A fl
fl I = 10. The number of programmers that must be hired is |A U fl |, but |A U fl | =
\A\ + IA| - IA fl fl|. So the company must hire 25 + 40 - 10 or 55 programmers.

Example 10 A survey has been taken on methods of commuter travel. Each respondent was
asked to check BUS, TRAIN, or AUTOMOBILE as a major method of traveling
to work. More than one answer was permitted. The results reported were as fol
lows: BUS, 30 people; TRAIN, 35 people; AUTOMOBILE, 100 people; BUS and
TRAIN, 15 people; BUS and AUTOMOBILE, 15 people; TRAIN and AUTOMO
BILE, 20 people; and all three methods, 5 people. How many people completed a
survey form?

Solution
Let fl, 7\ and A be the sets of people who checked BUS, TRAIN, and AUTOMO
BILE, respectively. We know |fl| = 30, \T\ = 35, \A\ = 100, |fl n T\ = 15,
|fl H A\ = 15, \T H A\ = 20, and |fl n T D A\ = 5. So |fl| + \T\ + \A\ - |fl fl
7| - |fl n A| - |r n A| + |fl n r n A| = 30 + 35 + 100 - 15 - 15 - 20 + 5 or
120 is IA U fl U C|, the number of people who responded. ♦
1.2 Operationson Sets 11

1.2 Exercises
In Exercises 1 through 4, let U = [a, b, c, d, e, /, g, h, k], 10. Compute
A = (fl,i,c,g), B = [d,e,f,g], C = [a,c,f], and (a) AOfl (b) flUC (c) AUA
D = [f,h,k}.
(d) enc (e) A0fl (f) flee
1. Compute 11. Let t/ be the set of real numbers, A = {x \ x is a solution
(a) AUB (b) flUC (c) A D C of jc2 - 1 = 0}, and fl = {-1,4}. Compute
(d) flOD (e) (AUfl)-C (f) A-B (a) A (b) fl (c) AUfl (d) ATTfl
(g) A (h) A 0 fl (i) A e c In Exercises 12 and 13, refer to Figure 1.14.
U) (Anfl)-c
2. Compute
(a) AUD (b) flUD (c) CflD
(d) AHD (e) (AUfl)-(CUfl)
(f) fl - C (g) fl (h) C - fl
(i) C0D (J) (Aflfl)-(flnD)
3. Compute
(a) A U fl U C (b) A n fl n c
(c) AH(flUC) (d) (AUfl)HC Figure 1.14
(e) ATTfl (f) ATTfl
4. Compute 12. Identify the following as true or false.
(a) AU0 (b) AUtf (c) flUfl (a) y e A fl fl (b) x e B U C
(d) CH{ } (e) CUD (f) cTTd (c) w e B fl C (d) u$C

In Exercises 5 through 8, let U = {1,2, 3, 4, 5, 6, 7, 8, 9}, 13. Identify the following as true or false.
A = {1,2,4,6,8}, fl = {2,4,5,9}, C = {x \ x is a posi (a)jcGAflflnC (b) yeAUBUC
tive integer andx2 < 16}, and D = {7, 8}. (c) z € A n C (d) v € fl 0 C
5. Compute 14. Describe the shaded region shown in Figure 1.15 using
(a) AUfl (b) AUC (c) AUD unions and intersections of the sets A, fl, and C. (Several
descriptions are possible.)
(d) flUC (e) AC\C (f) AflD
(g) flHC (h) COD
6. Compute
(a) A-B (b) fl-A (c) C-D
(d) C (e) A (f) A0fl
(g) C0D (h) flee
7. Compute Figure 1.15
(a) AUflUC (b) AflflflC
15. Let A, fl, and C be finite sets with \A\ = 6, |fl| = 8,
(c) Afl(flUC) (d) (AUfl)DD
\C\ = 6, |A U fl U C| = 11, |A D fl| = 3, |A n C| = 2,
(e) AUfl (f) AOfl and |fl fl C\ = 5. Find |A fl fl n C|.
8. Compute
/n Exercises 16 through 18, verify Theorem 2 for the given sets.
(a) flUCUD (b) flOCHD
16. (a) A = {1,2, 3,4}, fl = {2,3,5, 6, 8}
(c) AUA (d) ADA
(b) A = {l,2,3,4},fl = {5,6,7,8,9}
(e) AUA (f) AC)(CUD)
17. (a) A = {a,b,c,d9e,f},B = {a,c,f,g,h,i,r}
In Exercises 9 and 10, let U = {a,b,c, d, e, f,g,h], A =
(b) A = {a,b,c,d,e}9 fl = {/, g, r, s, f, «}
{a, c, /, g}, B = {a, e], and C = [b, h}.
18. (a) A = {jc | x is a positive integer < 8},
9. Compute fl = {^ | jc is an integer such that 2 < x < 5}
(a) A (b) B (c) AUB
(b) A = {jc | jc is a positive integerand jc2 < 16},
(d) ADB (e) U (1) A-B fl = {jc | jc is a negativeinteger and jc2 < 25}
12 Chapter 1 Fundamentals

19. If A and fl are disjoint sets such that |A U fl| = |A|, what 100 people questioned, 37 say they eat fruits, 33 say they
must be true about fl? eat vegetables, 9 say they eat cheese and fruits, 12 eat
20. Write Property 14 of Theorem 1 in ordinary English. cheese and vegetables, 10 eat fruits and vegetables, 12 eat
only cheese, and 3 report they eat all three offerings. How
21. Write Property 15 of Theorem 1 in ordinary English.
many people surveyed eat cheese? How many do not eat
In Exercises22 through 24, verifyTheorem 3for the given sets. any of the offerings?
22. A = [a, b, c, d, e], B = [d, e, /, g, h, i, k], 29. In a psychology experiment, the subjects under study
C = {a, c, d, e, k, r, s, t] were classified according to body type and gender as fol
lows:
23. A = {1, 2, 3,4,5, 6}, fl = {2,4, 7, 8, 9},
C = {1,2,4, 7,10,12}
ENDO- ECTO- ; MESO-
24. A = {jc | jc is a positive integer < 8}, MORPH MORPH MOKPH
fl = {jc | jc is an integer such that 2 < jc < 4},
C = {jc | x is an integersuch that jc2 < 16} Male 72 54; 36
25. In a survey of 260 college students, the following data Female 62 64 38
were obtained:
64 had taken a mathematics course, (a) How many male subjects were there?
94 had taken a computer science course, (b) How many subjects were ectomorphs?
58 had taken a business course, (c) How many subjects were either female or endo-
28 had taken both a mathematics and a business course, morphs?

26 had taken both a mathematics and a computer science (d) How many subjects were not male mesomorphs?
course, (e) How many subjects were either male, ectomorph, or
22 had taken both a computer science and a business mesomorph?
course, and 30. The following table displays information about the sopho
more, junior, and senior classes at Old U.
14 had taken all three types of courses.
(a) How many students were surveyed who had taken Major . .Major
none of the three types of courses?
Declared (D) Undeclared (U)
(b) Of the students surveyed, how many had taken only
a computer science course? Sophomore (S) 143

26. A survey of 500 television watchers produced the follow Junior (J) 245 158
ing information: 285 watch football games, 195 watch Senior (R) 392 36
hockey games, 115 watch basketball games, 45 watch
football and basketball games, 70 watch football and For each of the following tell how many students are in
hockey games, 50 watch hockey and basketball games, the set and describe those students in words.
and 50 do not watch any of the three kinds of games. (a) Dfi; (b) UUR (c) (DUS)HR
(a) How many people in the survey watch all three kinds 31. Create a Venn diagram that displays the information in the
of games? table in Exercise 30.
(b) How many people watch exactly one of the sports? 32. Complete the following proof that A c AUB. Suppose
27. The Journalism 101 class recently took a survey to deter x € A. Then x e AUB, because Thus by the
mine where the city's people obtained their news. Un definition of subset A c A U B.
fortunately, some of the reports were damaged. What we
know is that 88 people said they obtained their news from In Exercises 33 through 38, classify each statement as true,
television, 73 from the local paper, and 46 from a news false, or not possible to identify as true orfalse.
magazine. Thirty-four people reported that they obtained 33. Choose jc e A n B.
news from television and the local paper, 16 said they ob
(a) x e A (b) x e B (c) x $ A (d) x £ B
tained their news from television and a news magazine,
and 12 obtained theirs from the local paper and a news 34. Choose y eAUB.
magazine. A total of five people reported that they used all (a) y € A (b) yeB (c) y £ A
three media. If 166 people were surveyed, how many use (d) y <£ B (e) y e A n B (f) y <£AHB
none of the three media to obtain their news? How many
obtain their news from a news magazine exclusively? 35. Choose z € A U (B n C).

28. The college catering service must decide if the mix of (a) z e A (b) z € B (c)zeC
food that is supplied for receptions is appropriate. Of (d) zeBDC (e) z ft A (I) z $ C
1.3 Sequences 13

36. Choose w e DD(EU F). (b) To prove AUB c C, we should choose an element
from which set?
(a) w e D (b) w e E (c) w e F
(d) w ft D (e) w e F U E (c) Prove that if A c C and B c C, then A U fl c C.
(f) w e(DDE)U(DnF) 42. Prove that A - (A - B) c 5.
37. Choose t e DDE.
43. Suppose that A 0 5 = A®C. Does this guarantee that
(a) t eD (b) t e E (c) t i D B = C? Justify your conclusion.
(d) t i E (e) t € D U £
44. Prove that A-fi = AflI.
38. Choose jc e AU(flnC).
45. If A U fl = A U C, must B = C? Explain.
(a) jc € A (b) jc € 5 (c) x € C
(d) jc € A U 5 (e) jc€(IU5)n(AUC) 46. If A H fl = A O C, must fl = C? Explain.

39. Complete the following proof that A fl fl c A. Suppose 47. Prove that if A c fl and C c D, then AUC Q BUD
jc € A H B. Then jc belongs to Thus A H fl C A. and A H C c fl n D.

40. (a) Draw a Venn diagram to represent the situation 48. When isA-A = fl-A? Explain.
C C A and C C fl.
49. Explain the last term in the sum in Theorem 3. Why is
(b) To prove C c A U fl, we should choose an element |A O fl fl C\ added and |fl O C\ subtracted?
from which set?
(c) Prove that if C c A and C c fl, then C c A U B. 50. Write the four-set version of Theorem 3; that is, \A U fl U
CUD| = ---.
41 (a) Draw a Venn diagram to represent the situation
A c C and B c C. 51. Describe in words the /z-set version of Theorem 3.

1.3 Sequences
Some of the most important sets arise in connection with sequences. A sequence
is simply a list of objects arranged in a definite order; a first element, second
element, third element, and so on. The list may stop after n steps, n e N, or it may
go on forever. In the first case we say that the sequence is finite, and in the second
case we say that it is infinite. The elements may all be different, or some may be
repeated.

Example 1 The sequence 1,0, 0, 1,0, 1,0, 0, 1, 1, 1 is a finite sequence with repeated items.
The digit zero, for example, occurs as the second, third, fifth, seventh, and eighth
elements of the sequence. ♦

Example 2 Thelist3, 8,13,18,23,... is aninfinite sequence. Thethree dots in theexpression


mean "and so on," that is, continue the pattern established by the first few elements.

Example 3 Another infinite sequence is 1,4,9,16,25,. ,., the list of the squares of all positive
integers.

It may happen that how a sequence is to continue is not clear from the first few
terms. Also, it may be useful to have a compact notation to describe a sequence.
Two kinds of formulas are commonly used to describe sequences. In Example 2, a
natural description of the sequence is that successive terms are produced by adding
5 to the previous term. If we use a subscript to indicate a term's position in the
sequence, we can describe the sequence in Example 2 as a\ = 3, an — an-\ +5,
2 < n. A formula, like this one, that refers to previous terms to define the next
term is called recursive. Every recursive formula must include a starting place.
On the other hand, in Example 3 it is easy to describe a term using only its
position number. In the nth position is the square of n\ bn = n2, 1 < n. This type
of formula is called explicit, because it tells us exactly what value any particular
term has.
14 Chapter 1 Fundamentals

Example 4 The recursive formula c\ = 5, cn = 2cn-u 2 < n < 6, defines the finite sequence
5, 10, 20,40, 80, 160. ♦

Example 5 The infinite sequence 3, 7, 11, 15, 19, 23, ... can be defined by the recursive
formula d\ = 3, dn = dn-\ +4. ♦

Example 6 The explicit formula sn = (-4)", 1 < n, describes the infinite sequence
-4,16,-64,256,.... ♦

Example 7 The finite sequence 87, 82, 77, 72, 67 can be defined by the explicit formula
tn = 92 - 5n, 1 < n < 5. ♦

Example 8 Anordinary English word such as "sturdy" canbe viewed as the finite sequence

s, t, u, r, d, y

composed of letters from the ordinary English alphabet. ♦

In examples such as Example 8, it is common to omit the commas and write


the word in the usual way, if no confusion results. Similarly, even a meaningless
word such as "abacabcd" may be regarded as a finite sequence of length 8. Se
quences of letters or other symbols, written without the commas, are also referred
to as strings.

Example 9 An infinite string such as abababab... may be regarded as the infinite sequence
a, b,a,b,a,b, ♦

Example 10 The sentence "now is the time forthetest" canbe regarded as a finite sequence of
English words: now, is, the, time, for, the, test. Here the elements of the sequence
are themselves words of varying length, so we would not be able simply to omit
the commas. The custom is to use spaces instead of commas in this case. ♦

The set corresponding to a sequence is simply the set of all distinct elements
in the sequence. Note that an essential feature of a sequence is the order in which
the elements are listed. However, the order in which the elements of a set are listed
is of no significance at all.

Example 11 (a) The set corresponding to the sequence in Example 3 is {1,4,9,16,25, .}.
(b) The set corresponding to the sequence in Example 9 is simply {a, b}.

The idea of a sequence is important in computer science, where a sequence is


sometimes called a linear array or list. We will make a slight but useful distinc
tion between a sequence and an array, and use a slightly different notation. If we
have a sequence S: s\, S2, S3,..., we think of all the elements of 5 as completely
determined. The element 54, for example, is some fixed element of 5, located in
position four. Moreover, if we change any of the elements, we have a new se
quence and will probably name it something other than S. Thus if we begin with
the finite sequence S: 0,1, 2, 3, 2, 1, 1 and we change the 3 to a 4, getting 0, 1,2,
4, 2, 1, 1, we would think of this as a different sequence, say S'.
1.3 Sequences 15

5[1] 5[2] 5[3]


Array 5:

Figure 1.16

An array, on the other hand, may be viewed as a sequence of positions, which


we represent in Figure 1.16 as boxes. The positions form a finite or infinite list, de
pending on the desired size of the array. Elements from some set may be assigned
to the positions of the array 5. The element assigned to position n will be denoted
by S[n], and the sequence 5[1], 5[2], 5[3],... will be called the sequence of val
ues of the array 5. The point is that 5 is considered to be a well-defined object,
even if some of the positions have not been assigned values, or if some values are
changed during the discussion. The following shows one use of arrays.

Characteristic Functions

A very useful concept for sets is the characteristic function. We discuss functions
in Section 5.1, but for now we can proceed intuitively, and think of a function on a
set as a rule that assigns some "value" to each element of the set. If A is a subset of
a universal set £/, the characteristic function /a of A is defined for each x e U
as follows:

if x e A
/a(x) =
10 ifjc£ A.

We may add and multiply characteristic functions, since their values are numbers,
and these operations sometimes help us prove theorems about properties of sub
sets.

THEOREM 1 Characteristic functions of subsetssatisfy the following properties:


(a) /adb = SaSb\ that is, fAnB(x) = /a (*)/*(*) for all x.
(b) /aub = fA + fB-fAfB', that is, /aubW = /aW + /bW- •/a (*)/*(*)
for all x.
(c) fA®B =fA+fB-2fAfB;thstis9fAeB(x) = fA(x)+fB(x)-2fA(x)fB(x)
for all x.

Proof
(a) fA(x)fB(x) equals 1 if and only if both fA(x) and fB(x) are equal to 1,
and this happens if and only if x is in A and x is in B, that is, x is in A fl B.
Since /a/b is 1 on A fl B and 0 otherwise, it must be /adb-
(b) If* € A, then A (x) = hso fA(x) + fB(x)-fA(x)fB(x) = l + fB(x)-
fB(x) = 1. Similarly, when* € fi, fA(x) + fB(x) - fA(x)fB(x) = 1.
If x is not in A or B, then /a(x) and fB(x) are 0, so /a(x) + fB(x) —
fA(x)fB(x) = 0. Thus /a + fB — /a/b is 1 on A U B and 0 otherwise,
so it must be /aub-
(c) We leave the proof of (c) as an exercise. •

Note that the proof of Theorem 1 proceeds by direct application of the defini
tion of the characteristic function.
16 Chapter 1 Fundamentals

Computer Representation of Sets and Subsets


Another use of characteristic functions is in representing sets in a computer. To
represent a set in a computer, the elements of the set must be arranged in a se
quence. The particular sequence selected is of no importance. When we list the
set A = {a, b, c,..., r} we normally assume no particular ordering of the ele
ments in A. Let us identify for now the set A with the sequence a, b, c,..., r.
When a universal set U is finite, say U = {x\, x2,..., xn}9 and A is a subset
of £/, then the characteristic function assigns 1 to an element that belongs to A
and 0 to an element that does not belong to A. Thus /a can be represented by a
sequence of O's and l's of length n.

Example 12 Lett/ = {1,2,3,4,5,6}, A = {1,2}, B = {2,4,6}, and C = {4,5,6}. Then


fA(x) has value 1 when x is 1 or 2, and otherwise is 0. Hence fA corresponds to
the sequence 1, 1, 0, 0, 0, 0. In a similar way, the finite sequence 0, 1,0, 1,0, 1
represents fB and 0,0,0, 1, 1,1 represents fc. ♦

Any set with n elements can be arranged in a sequence of length n, so each of


its subsets corresponds to a sequence of zeros and ones of length n, representing
the characteristic function of that subset. This fact allows us to represent a univer
sal set in a computer as an array A of length n. Assignment of a zero or one to
each location A[k] of the array specifies a unique subset of U.

Example 13 Let U = {a, b, e, g, h, r, s, w}. The array of length 8 shown in Figure 1.17 repre
sents £/, since A[k] = 1 for 1 < k < 8.

1 1 1 1 1 1 1 1

Figure 1.17

If S = {a, e, r, w}, then

1 if x = a, e, r, w
fs(x) =
0 if x = b, g, h,s.

Hence the array in Figure 1.18 represents the subset 5.

1 0 1 0 0 1 0 1

Figure 1.18 ♦

A set is called countable if it is the set corresponding to some sequence. In


formally, this means that the members of the set can be arranged in a list, with a
first, second, third,..., element, and the set can therefore be "counted." We shall
show in Section 2.4 that all finite sets are countable. However, not all infinite sets
are countable. A set that is not countable is called uncountable.
The most accessible example of an uncountable set is the set of all real num
bers that can be represented by an infinite decimal of the form 0.<z102^3 • • •» where
a, is an integer and 0 < ax < 9. We shall now show that this set is uncountable.
We will prove this result by contradiction; that is, we will show the countability
of this set implies an impossible situation. (We will look more closely at proof by
contradiction in Chapter 2.)
1.3 Sequences 17

Assume that the set of all decimals 0.aia2a3 • • • is countable. Then we could
form the following list (sequence), containing all such decimals:
d\ = 0.#i02#3 • • •
d?2 = 0.fci&2&3 • • •
<i3 = O.C1C2C3 ...

Each of our infinite decimals must appear somewhere on this list. We shall
establish a contradiction by constructing an infinite decimal of this type that is not
on the list. Now construct a number x as follows: x = 0.x\X2X?>..., where x\ is 1
if a\ = 2, otherwise x\ is 2; x2 = 1 if hi = 2, otherwise X2 = 2; *3 = 1 if C3 = 2,
otherwise X3 = 2. This process can clearly be continued indefinitely. The resulting
number is an infinite decimal consisting of l's and 2's, but by its construction x
differs from each number in the list at some position. Thus x is not on the list, a
contradiction to our assumption. Hence no matter how the list is constructed, there
is some real number of the form 0.jtiJt2*3... that is not in the list. On the other
hand, it can be shown that the set of rational numbers is countable.

Strings and Regular Expressions


Given a set A, we can construct the set A* consisting of all finite sequences of
elements of A. Often, the set A is not a set of numbers, but some set of symbols. In
this case, A is called an alphabet, and the finite sequences in A* are called words
from A, or sometimes strings from A. For this case in particular, the sequences in
A* are not written with commas. We assume that A* contains the empty sequence
or empty string, containing no symbols, and we denote this string by A. This
string will be useful in Chapters 9 and 10.

Example 14 Let A = {a,b, c,..., z}, theusual English alphabet. Then A* consists of ordinary
words, such as ape, sequence, antidisestablishmentarianism, and so on, as well as
"words" such as yxaloble, zigadongdong, esy, and pqrst. All finite sequences from
A are in A*, whether they have meaning or not. ♦

If w\ = s\S2S3... sn and u>2 = hhh •.. f* are elements of A* for some set
A, we define the catenation of w\ and u>2 as the sequence 51*2*3 • • •Sntxhh ..-**•
The catenation of w\ with u>2 is written as w\ • W2 or w\ W2, and is another element
of A*. Note that if w belongs to A*, then u; • A = w and A • w = w. This property
is convenient and is one of the main reasons for defining the empty string A.

Example 15 Let A = {John, Sam, Jane, swims, runs, well, quickly, slowly}. Then A* con
tains real sentences such as "Jane swims quickly" and "Sam runs well," as well as
nonsense sentences such as "Well swims Jane slowly John." Here we separate the
elements in each sequence with spaces. This is often done when the elements of
A are words. ♦

The idea of a recursive formula for a sequence is useful in more general set
tings as well. In the formal languages and the finite state machines we discuss in
Chapter 10, the concept of regular expression plays an important role, and regu
lar expressions are defined recursively. A regular expression over A is a string
constructed from the elements of A and the symbols (,), v, *, A, according to the
following definition.
RE1. The symbol A is a regular expression.
18 Chapter 1 Fundamentals

RE2. If x e A, the symbol x is a regular expression.


RE3. If a and /J are regular expressions, then the expressionaf} is regular.
RE4. If a and /J are regularexpressions, then the expression (a v£) is regular.
RE5. If a is a regular expression, then the expression (a)* is regular.
Note here that RE1 and RE2 provide initial regular expressions. The other
parts of the definition are used repetitively to define successively larger sets of
regular expressions from those already defined. Thus the definition is recursive.
By convention, if the regular expression a consists of a single symbol jc,where
x e A, or if a begins and ends with parentheses, then we write (a)* simply as a*.
When no confusionresults, we will refer to a regular expression over A simply as
a regular expression (omitting reference to A).

Example 16 Let A = {0,1}. Show that the following expressions are all regular expressions
over A.

(a) 0*(0 v 1)* (b) 00*(0 v 1)*1 (c) (01)*(01 v 1*)

Solution
(a) By RE2, 0 and 1 are regular expressions. Thus (0 v 1) is regular by RE4,
and so 0* and (0 v 1)* are regular by RE5 (and the convention mentioned
previously). Finally, we see that 0*(0 v 1)* is regular by RE3.
(b) We know that 0, 1, and 0*(0 v 1)* are all regular. Thus, using RE3 twice,
00*(0 v 1)*1 must be regular.
(c) By RE3,01 is a regular expression. Since 1* is regular, (01 v 1*) is regular
by RE4, and (01)* is regular by RE5. Then the regularity of (01)* (01 v 1*)
follows from RE3. ♦

Associated with each regular expression over A, there is a corresponding sub


set of A*. Such sets are called regular subsets of A* or just regular sets if no
reference to A is needed. To compute the regular set corresponding to a regular
expression, we use the following correspondence rules.
1. The expression A corresponds to the set {A}, where A is the empty string in
A*.
2. If x € A, then the regular expression x corresponds to the set {jc}.
3. If a and /3 are regular expressions corresponding to the subsets M and N of
A*, then aft corresponds to M - N = {s • t \ s e M and t e N). Thus M • Af
is the set of all catenations of strings in M with strings in N.
4. If the regular expressions a and ft correspond to the subsets M and N of A*,
then (a v /3) corresponds to M U N.
5. If the regular expression a corresponds to the subset M of A*, then (a)* cor
responds to the set Af*. Note that M is a set of strings from A. Elements
from M* are finite sequences of such strings, and thus may themselves be
interpreted as strings from A. Note also that we always have A € M*.

Example 17 Let A = {a,b,c}. Then the regular expression a* corresponds to the set of all
finite sequences of <z's, such as aaa, aaaaaaa, and so on. The regular expression
a(b V c) corresponds to the set {ab, ac] c A*. Finally, the regular expression
ab(bc)* corresponds to the set of all strings that begin with ab, and then repeat
the symbols be n times, where n > 0. This set includes the strings ab, abbebe,
abbcbcbcbc, and so on. ♦
1.3 Sequences 19

Example 18 LetA = {0, 1] Find regular sets corresponding to the three regular expressions in
Example 16.

Solution
(a) The set corresponding to 0*(0 v 1)* consists of all sequences of O's and
l's. Thus, the set is A*.
(b) The expression 00*(0 v 1)*1 corresponds to the set of all sequences of O's
and 1's that begin with at least one 0 and end with at least one 1.
(c) The expression (01)*(01 v 1*) corresponds to the set of all sequences
of O's and l's that either repeat the string 01 a total of n > 1 times, or
begin with a total of n > 0 repetitions of 01 and end with some number
k > 0 of l's. This set includes, for example, the strings 1111,01,010101,
0101010111111, and Oil. ♦

1.3 Exercises

In Exercises 1 through 4, give the set corresponding to the se 23. Let A = {x | jc is a real number and 0 < x < l], B = {x \
quence. jc is a real number and jc2 + 1 = 0}, C = {x \ x = 4m,
m e Z}, D = {(jc, 3) | jc is an English word whose length
1. 1,2,1,2,1,2,1,2,1
is 3}, and E = {jc | jc e Z and jc2 < 100}. Identify each
2. 0,2,4,6,8,10,... set as finite, countable, or uncountable.
3. aabbccddee... zz 24. Let A = W* for W = {a,b}, B = {jc | jc e R and
4. abbcccdddd
jc2 + 41jc + 41 = 0}, C = {jc I jc = *, m, n e Z+,
n > 4}, D = {jc I jc € R and jc2 + 3jc + 2 # 0}, and
5. Give three different sequences that have {jc, v, z] as a cor E = {(jc, y,z) \x eZ,y eR+,z e Z+}. Identify each
responding set. set as finite, countable, or uncountable.
6. Give three different sequences that have {1, 2, 3,...} as a 25. Let A = [ab, be, ba). In each part, tell whether the string
corresponding set. belongs to A*.
In Exercises 7 through 14, write out thefirst four terms (begin (a) ababab (b) abc (c) abba
with n = I) of the sequence whose general term is given. (d) abbebaba (e) bcabbab (f) abbbeba
7. an = 5n 26. Let U = {arithmetic, algebra, calculus, geometry, trig
8. bn =3n2 + 2n-6 onometry, analysis, topology, statistics}, B = {analysis,
topology, calculus), C = {algebra, calculus, trigonom
9. gn = 1 • 2 . 3 n etry, analysis}, D = {arithmetic, algebra, calculus,
an - 1 topology, statistics}, E = {algebra, calculus, geometry,
10. hn -,a^\ trigonometry, analysis}. In each of the following, repre
a-\
sent the given set by an array of zeros and ones.
11. c\ = 2.5, cn = cn-\ + 1.5
(a) B U C (b)CflD
12. dx =-3,dn = -2dn-l + 1
(c) BD(DnE) (d) BUE
13. ex = 0, en = en-i - 2
(e) Cn(BUE)
14. /, =4,/, =/!•/„_,
27. Let U = {b,d,e,g,h,k,m,n}, B = {Z?}, C = {d,g,
In Exercises 15 through 20, write a formula for the nth term of m, n}, and D = [d, k, n}.
the sequence. Identifyyourformula as recursive or explicit. (a) What is fB(b)l (b) What is fc{e)l
15. 1,3,5,7,... 16. 0, 3, 8, 15, 24, 35,... (c) Find the sequences of length 8 that correspond to fB,
17. 1,-1,1,-1,1,-1, 18. 0, 2, 0, 2, 0, 2,... fc, and fD.

19. 1,4,7,10,13,16 20. 1, I, J, I, ±,... (d) Represent B U C, C U D, and C fl D by arrays of


zeros and ones.
21. Write an explicit formula for the sequence 2, 5, 8, 11,
28. Complete the proof that fA(BB = fA + fB- 2fAfB
14, 17,....
[Theorem 1(c)]. Suppose x e A and x g B. Then
22. Write a recursive formula for the sequence 2, 5, 7, 12, fA(x) = , fB(x) = , and fA(x)fB(x) =
19,31,.... , so fA(x) + fB(x) - 2fA(x)fB(x) =
20 Chapter 1 Fundamentals

Now suppose x £ A and x e B. Then fA(x) = (a) {00,010,0110,011110,...}


, /*(*) = , and fA(x)fB(x) = , so
(b) {0, 001, 000,00001,00000, 0000001,...}
fA(x) + /,(*) - 2fA(x)fB(x) = _ _. The remaining
case to check is jc £ A©5. Ifjc £ A®B,thenx e 36. We define 7-numbers recursively as follows:
and fA(x) +fB(x)-2fA(x)fB(x) = Explain how 1. 0 is a 7-number.
these steps prove Theorem 1(c).
2. If X is a T-number, X + 3 is a T-number.
29. Using characteristic functions, prove that (A® B)®C =
Write a description of the set of T-numbers.
A®(B®C).
30. Let A = {+, x, a, b}. Show that the following expres 37. Define an 5-number by
sions are regular over A. 1. 8 is an S-number.
(a) a + b(ab)*(a xbva) 2. If X is an S-number and Y is a multiple of X, then Y
(b) a + b x (a* v b) is an 5-number.
(c) (a*b v +)* v x b* 3. If X is an 5-number and X is a multiple of Y, then Y
is an 5-number.
In Exercises 31 and 32, let A = {a, b, c}. In each exercise a
string in A* is listed and a regular expression over A is given. Describe the set of 5-numbers.
In each case, tell whetheror not the string on the left belongs 38. Let F be a function defined for all nonnegative integers
to the regular set corresponding to the regular expression on by the following recursive definition.
the right.
31. (a) ac a*b*c (b) abcc (abcVc)* F(0) = 0, F(l) = 1
(c) aaabc ((a v b) v c)* F(n + 2) = 2F(n) + F(n + 1), n > 0
32. (a) ac (a*b v c) (b) abab (ab)*c
Compute the first six values of F; that is, write the values
(c) aaccc (a* V b)c* of F(n) for n = 0,1,2,3,4,5.
33. Give three expressions that are not regular over the A
39. Let G be a function defined for all nonnegative integers
given for Exercises 31 and 32.
by the following recursive definition.
34. Let A = {/?, q, r}. Give the regular set corresponding to
the regular expression given. G(0) = 1, G(l) = 2
(a) (pvq)rq* (b) p(qq)*r G(n + 2) = G(n)2 + G(n + 1), n>0
35. Let S = {0,1}. Give the regular expression correspond
ing to the regular set given. Compute the first five values of G.

1A Properties of Integers
We shall now discuss some results needed later about division and factoring in
the integers. If m is an integer and n is a positive integer, we can plot the integer
multiples of n on a line, and locate m as in Figure 1.19. If m is a multiple of n,
say m = qn, then we can write m = qn + r, where r is 0. On the other hand (as
shown in Figure 1.19), if m is not a multiple of n, we let qn be the first multiple of
n lying to the left of m and let r be m —qn. Then r is the distance from qn to m,
so clearly 0 < r < n, and again we have m = qn + r. We state these observations
as a theorem.

-In 2n (q+Dn
_J _J_ _L_ J .
-*

Figure 1.19

THEOREM 1 If n and m are integers and n > 0, we can write m = qn + r for integers <? and r
with 0 < r < n. Moreover, there is just one way to do this. •
1.4 Properties of Integers 21

Example 1 (a) If n is 3 and mis 16, then 16 = 5(3) + 1 so q is 5 andr is 1.


(b) If n is 10 and m is 3, then 3 = 0(10) + 3 so q is 0 and r is 3.
(c) If n is 5 and m is —11, then —11 = -3(5) + 4 so q is -3 and r is 4. ♦

If the r in Theorem 1 is zero, so that m is a multiple of n, we write n \ m,


which is read "h divides m." If n | m, then m = qn and n < |m|. If m is not a
multiple of n, we write n { m, which is read "n does not divide ra." We now prove
some simple properties of divisibility.

THEOREM 2 Let a, b, and c be integers.


(a) If a | b and a | c, then a | (fc + c).
(b) If a | b and a | c, where b > c, then a \ (b —c).
(c) If a | fe or a | c, then a | Z?c.
(d) If a | fc and fc | c, then a | c.

Proo/
(a) If a | b and a | c, then b = k\a and c = /:2<z for integers £i and ki. So
fc + c = (&i + £2)0 and a \ (b + c).
(b) This can be proved in exactly the same way as (a).
(c) As in (a), we have b = k\a or c = £20. Then either be = k\ac or
be = kiab, so in either case be is a multiple of a and a \ be.
(d) If a I b and £ | c, we have ft = k\a and c = £2^ so c = k^b = k2(k\a) =
(k2k\)a and hence 0 | c. •

Note that again we have a proof that proceeds directly from a definition by
restating the original conditions. As a consequence of Theorem 2, we have that if
a I b and a | c, then a | (mb + nc), for any integers m and n. (See Exercises 23
and 24.)
A number p > 1 in Z+ is called prime if the only positive integers that divide
p are/? and 1.

Example 2 Thenumbers 2,3,5,7,11, and 13 areprime, while 4,10,16, and 21 arenotprime.

It is easy to write a set of steps, or an algorithm,* to determine if a positive


integer n > 1 is a prime number. First we check to see if n is 2. If n > 2, we
could divide by every integer from 2 to n —1, and if none of these is a divisor of n,
then n is prime. To make the process more efficient, we note that if mk = n, then
either m or k is less than or equal to *Jn. This means that if n is not prime, it has a
divisork satisfying the inequality 1 < k < *Jn, so we need only test for divisors in
this range. Also, if n has any even number as a divisor, it must have 2 as a divisor.
Thus after checking for divisibility by 2, we may skip all even integers.

Algorithm
To test whether an integer N > 1 is prime:
Step 1 Check whether N is 2. If so, Af is prime. If not, proceed to
Step 2 Check whether 2 | TV. If so, iV is not prime; otherwise, proceed to
Step 3 Compute the largest integer K < +/N. Then

*Algorithms are discussed in Appendix A.


22 Chapter 1 Fundamentals

Step 4 Check whether D \ N9 where D is any odd number such that


1 < D < K. If D | N9 then Af is not prime; otherwise, N is prime. •

Testingwhetheran integeris prime is a common task for computers. The algorithm


given here is too inefficientfor testing very large numbers, but there are many other
algorithms for testing whether an integer is prime.

THEOREM 3 Every positive integer n > 1 can be written uniquely as pk{]p^2 - —Pss, where
P\ < Pi < - • • < Ps are distinct primes that divide n and the £'s are positive
integers giving the number of times each prime occurs as a factor of n. •
We leave the proof of Theorem 3 to Section 2.4, but we give several illustra
tions.

Example 3 (a) 9 = 3 -3 = 32
(b) 24 = 8 • 3 = 2 • 2 • 2 •3 = 23 •3
(c) 30 = 2.3-5 ♦

Greatest Common Divisor


If a, b, and k are in Z+, and k \ a and k \ b, we say that k is a common divisor
of a and b. If d is the largest such k, d is called the greatest common divisor, or
GCD, of a and b, and we write d = GCD(a, b). This number has some interesting
properties. It can be written as a combination of a and b, and it is not only larger
than all the other common divisors, it is a multiple of each of them.

THEOREM 4 If d is GCD(a, b)9 then


(a) d = sa+tb for some integers s and t. (These are not necessarily positive.)
(b) If c is any other common divisor of a and b, then c \ d.

Proof
Let x be the smallest positive integer that can be written as sa + tb for some
integers s and t9 and let c be a common divisor of a and b. Since c \ a and c \ b, it
follows from Theorem 2 that c \ jc, so c < x. If we can show that jc is a common
divisor of a and b, it will then be the greatest common divisor of a and b and both
parts of the theorem will have been proved. By Theorem I, a = qx + r with
0 < r < x. Solving for r, we have

r = a qx q(sa + tb) = a —qsa —qtb = (1 —qs)a + (-qt)b.

If r is not zero, then since r < x and r is the sum of a multiple of a and a multiple
of b, we will have a contradiction to the fact that x is the smallest positive number
that is a sum of multiples of a and b. Thus r must be 0 and x \ a. In the same way
we can show that x \ b, and this completes the proof. •

This proof is more complex than the earlier ones. At this stage you should
focus on understanding the details of each step. We will discuss the structure of
this proof later.
From the definition of greatest common divisor and Theorem 4(b), we have
the following result: Let a, b, and d be in Z+. The integer d is the greatest common
divisor of a and b if and only if
(a) d \ a and d \ b.
(b) Whenever c | a and c \ b, then c \ d.
1.4 Properties of Integers 23

Example 4 (a) Thecommon divisors of 12and30 are 1, 2, 3, and6, so that


GCD(12,30) = 6 and 6 = 1 • 30 + (-2) • 12.

(b) It is clear that GCD(17, 95) = 1 since 17 is prime and 17 \ 95, and the reader
may verify that 1 = 28 • 17 + (-5) • 95. ♦

If GCD(a, b) = 1, as in Example 4(b), we say a and b are relatively prime.


One remaining question is that of how to compute the GCD conveniently in
general. Repeated application of Theorem 1 provides the key to doing this.
We now present a procedure, called the Euclidean algorithm, for finding
GCD(<z, b). Suppose that a > b > 0 (otherwise interchange a and b). Then by
Theorem 1, we may write

a = k\b + r\, where k\ is in Z+ and 0 < r\ < b. (1)

Now Theorem 2 tells us that if n divides a and b, then it must divide r\, since
ri = a —k\b. Similarly, if n divides b and r\9 then it must divide a. We see that
the common divisors of a and b are the same as the common divisors of b and r\,
soGCD(a,fe) = GCD(6,r!).
We now continue using Theorem 1 as follows:

divide b by r\: b = k2r\ + r2 0 < r2 < r\


divide r\ by r2\ r\ = k3r2 + r3 0 < r3 < r2
divide r2 by r3\ r2 = k4r3 + r4 0 < r4 < r3
(2)

divide r„_2 by r„_i: rn-2 = Krn-\ + rn 0 < rn < r„_i


divide rw_i by rn\ rn-\ = kn+\rn +rn+\ 0 < rn+1 < rn.

Since a > b > r\ > r2 > r3 > r4 > •• •, the remainder will eventually become
zero, so at some point we have rn+\ = 0.
We now show that rn = GCD(a, b). We saw previously that

GCD(a,fc) = GCD(fc,n).

Repeating this argument with b and r\9 we see that

GCD(Z7,r1) = GCD(rI,r2).

Upon continuing, we have

GCD(a, b) = GCD(Z?, r{) = GCD(n, r2) = • • • = GCD(rw_!, rn).

Since r„_i = kn+\rn, we see that GCD(r„_i, rn) = rn. Hence rn = GCD(a, b).

Example 5 Compute GCD(273, 98). Leta be273 andbbe98. Using theEuclidean algorithm,
divide 273 by 98: 273 = 2 • 98 + 77
divide 98 by 77: 98 = 1-77 + 21
divide 77 by 21: 77 = 3 • 21 + 14
divide 21 by 14: 21 = 1-14 + 7
divide 14 by 7: 14 = 2-7 + 0

so GCD(273, 98) = 7, the last of the nonzero divisors.


24 Chapter 1 Fundamentals

In Theorem 4(a), we observed that if d = GCD(a, b)y we can find integers s


and t such that d = sa + tb. The integers s and t can be found as follows. Solve
the next-to-last equation in (2) for rn\

rn=rn-2-knrn-i. (3)

Now solve the second-to-last equation in (2), r„_3 = kn-\rn-2 + rn-\ for rn-\\

r„_! =r„_3 -kn-\rn-2

and substitute this expression in (3):

rn = rn-2 - kn[rn..3 - kn-irn-2].

Continue to work up through the equations in (2) and (1), replacing r/ by an ex


pression involving r,-_i and r/_2, and finally arriving at an expression involving
only a and b.

Example 6 (a) Leta be 273 and b be98, asin Example 5. Then

GCD(273, 98) = 7 = 21 - 1 • 14
= 21 - 1(77 -3-21) 14 = 77 - 3 • 21
= 4 • 21 - 1 • 77

= 4(98 - 1 • 77) - 1 • 77 21 = 98 - 1 • 77
= 4-98-5-77
= 4 • 98 - 5(273 - 2 - 98) 77 = 273 - 2 • 98
= 14(98) - 5(273)

Hence s = -5 and t = 14. Note that the key is to carry out the arithmetic
only partially.
(b) Let a = 108 and b = 60. Then

GCD(108, 60) = 12 = 60 - 1(48)


= 60 - 1[108 - 1(60)] 48 = 108 - 1 • 60
= 2(60) - 108.

Hence s = -1 and t = 2. ♦

THEOREM 5 If a and b are in Z+, b > a, then GCD(a, b) = GCD(Z?, b ± a).

Proof
If c divides a and £>, it divides b ± a, by Theorem 2. Since a = b — (b —a) =
—b + {b + a), we see, also by Theorem 2, that a common divisor of b and fo ± a
also divides a and b. Since a and £ have the same common divisors as b and b ± a,
they must have the same greatest common divisor. •

This is another direct proof, but one that uses a previous theorem as well as
definitions.
1.4 Properties of Integers 25
Least Common Multiple
If a, b, and k are in Z+, and a \ k, b \ k, we say k is a common multiple of a and
ft. The smallest such k, call it c, is called the least common multiple, or LCM,
of a and b, and we write c = LCM(a, b). The following result shows that we can
obtain the least common multiple from the greatest common divisor, so we do not
need a separate procedure for finding the least common multiple.

THEOREM 6 If a and b are two positive integers, then GCD(<s, b) •LCM(a, b) = ab.

Proof
Let p\, /?2,.. •, Pk be all the prime factors of either a orb. Then we can write

a = Pa\Pai'"Pak and b = Pb\Pi''"Pbkk


where some of the at and b\ may be zero. It then follows that

GCD(a, b) = p{ p2 '"Pk

and

LCM(a, b) —px ' !'p2 -" Pk .


Hence

GCD(a, ft) •LCM(a, fe) = p?1^1 pa22+bl •••pf^


= (p?pa22'"Pakk)'(PblP22'"Pbkk)
= ab. M

Example 7 Leta = 540 and b = 504. Factoring a and b into primes, weobtain
a = 540 = 22 • 33 • 5 and 6 = 504 = 23 • 32 • 7.

Thus all the prime numbers that are factors of either a or b are p\ = 2, /?2 = 3,
/?3 = 5, and p4 = 7. Then a = 22 . 33 •51 •7° and fe = 23 • 32 • 5° •71. We then
have

GCD(540 504) = 2min(2'3) • 3min<3'2) . 5min(l,0) . yminCCU)


= 22 • 32 • 5° • 7°
= 22 • 32 or 36.

Also,

LCM(540 504) = 2max(2'3) • 3max(3'2) . 5max(l,0) #^max(0,l)


= 23.33-51 -71 or 7560.

Then

GCD(540, 504) • LCM(540, 504) = 36 • 7560 = 272,160 = 540 • 504.

As a verification, we can also compute GCD(540, 504) by the Euclidean algorithm


and obtain the same result. ♦

If n and m are integers and n > 1, Theorem 1 tells us we can write m = qn+r,
0 < r < n. Sometimes the remainder r is more important than the quotient q.
26 Chapter 1 Fundamentals

Example 8 If the time is now 4 o'clock, what time will it be 101 hours from now?

Solution
Let n = 12 and m = 4 + 101 or 105. Then we have 105 = 8 • 12 + 9. The
remainder 9 answers the question. In 101 hours it will be 9 o'clock. ♦

For each n e Z+, we define a function /„, the mod-n function, as follows: If z
is a nonnegative integer, fn(z) = r, the remainder when z is divided by n. (Again,
functions are formally defined in Section 5.1, but as in Section 1.3, we need only
think of a function as a rule that assigns some "value" to each member of a set.)
The naming of these functions is made clear in Section 4.5.

Example 9 (a) f3(U) = 2, because 14= 4 •3 + 2.


(b) /7(153) = 6. ♦

Pseudocode Versions
An alternative to expressing an algorithm in ordinary English as we did in this
section is to express it in something like a computer language. Throughout the
book we use a pseudocode language, which is described fully in Appendix A.
Here we give pseudocode versions for an algorithm that determines if an integer
is prime and for an algorithm that calculates the greatest common divisor of two
integers.
In the pseudocode for the algorithm to determine if an integer is prime, we as
sume the existence of functions SQR and INT, where SQR(iV) returns the greatest
integer not exceeding V77, and INT(X) returns the greatest integer not exceeding
X. For example, SQR(10) = 3, SQR(25) = 5, INT(7.124) = 7, and INT(8) = 8.

SUBROUTINE PRIME(N)
1. IF (JV = 2) THEN
a. PRINT ('PRIME')
b. RETURN
2. ELSE
a. IF {N/2 = INTCJV/2)) THEN
1. PRINT ('NOT PRIME')
2. RETURN
b. ELSE
1. FOR D = 3 THRU SQR(N) BY 2
a. IF QN/D = INT(N/D)) THEN
1. PRINT ('NOT PRIME')
2. RETURN
2. PRINT ('PRIME')
3. RETURN
END OF SUBROUTINE PRIME

The following gives a pseudocode program for finding the greatest common
divisor of two positive integers. This procedure is different from the Euclidean
algorithm, but in Chapter 2, we will see how to prove that this algorithm does
indeed find the greatest common divisor.

FUNCTION GCD(X, 30
1. WHILE (X ^ Y")
a. IF (X > Y) THEN
1. X <r- X - Y
1.4 Properties of Integers 27

b. ELSE
1. Y <e- Y - X
2. RETURN (X)
END OF FUNCTION GCD

Example 10 Usethepseudocode for GCD to calculate thegreatest common divisor of 190 and
34.

Solution
The following table gives the values of X, 7, X - T, or Y - X as we go through
the program.

X-Y Y-X

190 34 156
156 34 122

122 34 88

88 34 54
54 34 20
20 34 14
20 14 6
6 14 8
6 8 2

6 2 4
4 2 2

2 2

Since the last value of X is 2, the greatest common divisor of 190 and 34 is 2. ♦

Representations of Integers
The decimal representation of an integer is so familiar that we sometimes regard
it as the symbol, or name for that integer. For example, when we write the integer
3264, we are saying that the number is the result of adding 3 times 103, 2 times
102, 6 times 101, and 4, or 4 times 10°. We say 3264 is the base 10 expansion of
n or the decimal expansion of w; 10 is called the base of this expansion.
There is nothing special about using the number 10 as a base, and it is likely
the result of our having 10 fingers on which to count. Any positive integer b > 1
can be used in a similar way, and these expansions are often of much greater use
than the standard decimal expansion. The bases 2, 8, and 16 are frequently used in
computer science, and the base 26 is sometimes used in cryptology (the science
of producing and deciphering secret codes).

THEOREM 7 If b > 1 is an integer, then every positive integer n can be uniquely expressed in
the form

n = dkbK + dk-\br~l + -- + dib + d0, (4)

where 0 < d\ < b, i = 0, 1,..., k, and dk ^ 0. The sequence dkdk-\ ... d\do is
called the base b expansion of n. If we need to explicitly indicate the base b, we
will write the above sequence as (dkdk-\... d\do)b.
28 Chapter 1 Fundamentals

Proof
Suppose thatk is thelargest nonnegative integer so thatbk < n (k could be 0). By
Theorem 1 we can uniquely write n = qbk + r, where 0 <r < bk. Letdk = q. If
k = 0, then r = 0 and we are done (n = do). Otherwise we have
n = dkbk + r.
Repeat this process, using r in place of n. Let s be the largest nonnegative integer
so that bs < r, write r = qbs + r\9 where 0 < r\ < b\ and define ds to be q. If
s < k, define ds+\,..., dk-\ to be 0. Then

n = dkbk + dk-\bk~x + ... + dsV + rx.


Continuing this process using r\, r2,..., we will eventually arrive at (4). •

Now that we know that the base b expansion exists, we can find the digits
dk, dk~\,..., d\, do by a more direct method, easily implemented on a computer.
Note that
n = (dkbk-{ + dk-\bk~2 + •••+ dfib + d0
so that do is the remainder after dividing n by b, and the quotient is dkbk~{ +
dk-\bk~2 H hd\. Similarly, if this quotient is divided by b,theremainder is d\.
By repeatedly dividing the quotients by b and saving the remainders, we produce
the digits of the base b representation of n from right to left.

Example 11 Find thebase 4 representation of 158.


Solution
We repeatedly divide by 4 and save the remainder:
4|158 2
4^9 3
4[9. 1
4 [2 2
0

Thus 158 = (2132)4. ♦

The following pseudocode algorithm returns the digits of the base b expansion
of an integer. We use the expression m mod n to denote the mod-n function
value for m, that is, the remainder after dividing m by n. These are the functions
defined after Example 8. The mod-n functions are commonly implemented in
most programming languages.

SUBROUTINE EXPANSION(AO
1. Q <- N
2. K <- 0
3. WHILE (Q ^ 0)
a. Dk <- Q mod B
b. Q <r- INT(Q/B)
c. K <- K + 1
4. RETURN
END OF SUBROUTINE EXPANSION

When this subroutine ends, the base B expansion of Af consists of the integers £>,-,
which can then be further processed.
1.4 Properties of Integers 29

No matter what base is used to represent integers, the elementary rules of


addition and multiplication are still valid. Only the appearance of the numbers
changes.

Example 12 Letm = (313)4 and n = (322)4. Find the base4 expansion of m + n.

Solution
Adding the digits in the last column, we have 3 + 2 = (11)4, so we record a 1 and
carry a 1 to the next column.
1
313
+ 322
1

Adding the digits in the second column, we have 1 + 1 + 2 = (10)4, so we record


a 0 and carry the 1.
11
313
+ 322
01

Finally, adding the digits in the first column, we obtain 3 + 3 + 1 = (13)4, so the
answer is (1301)4. ♦

The most common expansion used in computer work is the base 2 or binary
expansion. Since the only remainders of division by 2 are 0 and 1, the binary ex
pansion of every number needs only the digits 0 and 1 and so is easily implemented
and manipulated by the on-off digital circuits of a computer.

Example 13 (a) The binary expansion of 39is (100111)2.


(b) (110101)2 = 32 + 16 + 4 + 1 = 53. ♦

Binary addition and multiplication are usually implemented in computer cir


cuitry rather than by software. Another common base in computer science is base
16, or hexadecimal (or hex) representation. This representation requires six addi
tional symbols to use with 0, 1,2, 3, 4, 5, 6, 7, 8, 9 to represent the digits usually
written 10, 11, 12, 13, 14, 15. It is customary to choose the letters A, B, C, D, E,
F for this purpose.

Example 14 To use 26 as a base, we can use the letters A, B, ..., Z of the English alphabet
to represent the digits 0, 1, ..., 25. In this way we can interpret any text as the
base 26 representation of an integer. Thus we can interpret "TWO" as the base 26
representation of (Tx262) + (Wx 26)+0 = (19x 676)+ (22x26) +14 = 13430.
The ability to "add" words can be made the basis of cryptographic encoding. We
will explore this further in Chapter 11. ♦

Example 15 As an example of cryptology, we consider a remarkable code due to Sir Francis


Bacon, the English writer and philosopher. Suppose that we wish to encode a
message, say FLEE NOW. We first write the base 2 representation of the position
of each letter of the message in the English alphabet, starting with A in position 0,
and ending with Z in position 25. Thus we have the following table.

F L E E N O W
ooioi oioii ooioo ooioo onoi oino 10110
30 Chapter 1 Fundamentals

Since F is in position 5, its binary representation is (00101)2, and so on. Now


choose an unrelated "dummy" message exactly five times as long (padded with
a few extra letters if necessary). Place the dummy message in a third row. The
letters of the dummy message correspondexactly to the string of 0's and 1's in the
secondrow of the abovetable. We agree to write each letter in one font (say Times
Roman) if it corresponds to a 0 in the table, and another font (say Times Roman
Italic) if it correspondsto a 1 (Bacon used fonts that were even more similar). Thus
if the dummy message is ONCE UPON A TIME IN THE WEST THERE WAS A
TOWN, we would write that message as ONCE UPON A TIME IN TH£ WESr
THERE WAS A TOWN. Note that when the letters in this message are arranged
in a third row of the table, the patterns of nonitalic for 0 and italic for 1 allow us to
decode the message.

F L E E N O w
00101 01011 00100 00100 01101 oino 10110
ONCEU PONAT MEIN TH£WE STTHE R£WAS ATOWN

Example 16 Suppose that we wish to decode the following dummy message, using the Bacon
code

NOW IS THE TIME FOR ALL GOOD MEN TO AID THE COUNTRF

Since there are 40 letters, the true message must have 8 letters. Arrange the dummy
message, 5 letters at a time in the following table, and then list the corresponding
binary digits, using 1 for italic and 0 for plain text.
NOWIS TUETI MEFOR ALLGO ODMEN TOAID THECO UKTRY
iooio loon ooooo ioooi loon oiooi oino ooooi

The binary representations in the second row correspond respectively to the num
bers 18,19, 0,17,19, 9,14, and 1, and therefore represent the letters STARTJOB.
Thus the decoded message is START JOB. ♦

If the fonts used are quite similar, it will not be obvious that the text is a
coded message. Thus this example also illustrates steganography, the science of
concealment of coded information. Modern versions include hiding information
in stray bits of a digital photograph. One use of this is to watermark copyrighted
artistic material.

1.4 Exercises
In Exercises 1 through 4, for the given integers m and n, write In Exercises 6 through 9, find the greatest common divisor d
m as qn + r, with 0 < r < n. of the integers a and b, and write d as sa + tb.
1. m = 20, n = 3 6. a = 60, b = 100

2. m = 64, n = 37 7. a =45,6 = 33

3. m = 3, n = 22 8. a = 34, b = 58

4. m = 48,« = 12 9. a = ll,b= 128

5. Write each integer as a product of powers of primes (as in In Exercises 10 through 13, find the least common multiple of
Theorem 3). the integers.
(a) 828 (b) 1666 (c) 1781 10. 72,108 11. 150,70
(d) 1125 (e) 107 12. 175,245 13. 32, 27
1.4 Properties of Integers 31

14. If / is the mod-7 function, compute each of the following, 34. Let a be an integer and let p be a positive integer. Prove
(a) /(17) (b) /(48) (c) /(1207) that if p | a, then /? = GCD(a, p).

(d) /(130) (e) f(93) (f) /(169) 35. Theorem 2(c) says that if a \ b or a | c, then a | fcc. Is the
converse true; that is, if a | be, then a \ b or a | c? Justify
15. If / is the mod-11 function, compute each of the follow your conclusion.
ing.
36. Prove that if m and n are relatively prime and mn is a
(a) /(39) (b) /(386) (c) /(1232) perfect square, then m and n are each perfect squares.
(d) /(573) (e) 2/(87) (I) /(175) + 4 37. Is the statement in Exercise 36 true for cubes? For any
16. If / is the mod-7 function, compute each of the following, fixed power? Justify your conclusion.
(a) /(752 + 793) (b) /(752) +/(793) In Exercises 38 through 40, let U = {1, 2, 3,..., 1689),
(c) /(3 • 1759) (d) 3 • /(1759) A = {x | x e U and 3 | x}, B = {y | y € U and 5 \ y], and
17. If / is the mod-12 function, compute each of the follow C = {z | z € U and 11 | z}. Compute each of thefollowing.
ing. 38. (a) \A\ (b) |£| (c) \C\
(a) /(1259 + 743) (b) /(1259) + /(743) 39. (a) The number of elements in U that are divisible by 15
(c) /(2-319) (d) 2-/(319) (b) The number of elements of U that are divisible by
18. Let / be the mod-n function for a fixed n. What do the re 165
sults of Exercises 16 and 17 suggest about the relationship (c) The number of elements of U that are divisible by 55
between k • f{a) and f(k • a)l
40. Use the results of Exercises 38 and 39 to compute each of
19. Let / be the mod-rc function for a fixed n. Based on the the following.
results of Exercises 16 and 17, explain why f{a-\-b) does
(a) \AUB\ (b) \AUB\JC\
not always equal f{a)-\-f{b).
41. (a) Write the expansion in base 5 of each of the follow
20. Let / be the mod-n function for a fixed n. Explain when
ing numbers.
/(* + *) =/(*) + /(*) is true.
(i) 29 (ii) 73 (iii) 215 (iv) 732
21. If g is the mod-5 function, solve each of the following.
(a) g{n) = 2 (b) g(n)=A (b) Write the expansion in base 10 of each of the follow
ing numbers.
22. If g is the mod-6 function, solve each of the following,
(i) (144)5 (ii) (320)5
(a) g(n) = 3 (b) g(n) = 1
(iii) (1242)5 (iv) (11231)5
23. Prove that if a \ b, then a \ mb, for any m e Z.
42. (a) Write the expansion in base 7 of each of the follow
24. Prove that if a \ b and a | c, then a \ mb + nc, for any ing numbers.
m, n € Z.
(i) 29 (ii) 73 (iii) 215 (iv) 732
25. Complete the following proof. Let a and b be integers. If
p is a prime and p \ ab, then p \ a or p \ b. We need (b) Write the expansion in base 10 of each of the follow
to show that if p \ a, then p must divide b. If p \ a, ing numbers.
then GCD(#, p) = 1, because By Theorem 4, we (i) (102)7 (ii) (161)7
can write 1 = sa + tp for some integers s and t. Then
(iii) (460)7 (iv) (1613)7
b = sab + tpb. (Why?) Then p must divide sab + tpb,
because So p \ b. (Why?) 43. For each of the following, write the expansion in the spec
ified base.
26. Show that if GCD(a, c) = 1 and c \ ab, then c \ b.
{Hint: Model the proof on the one in Exercise 25.) (i) 29 (ii) 73 (iii) 215 (iv) 732

27. Show that if GCD(a, c) = 1, a | m, and c \ m, then (a) 2 (b) 4 (c) 16


ac\m. {Hint: Use Exercise 26.) 44. (a) How are the numbers 2, 4, and 16 related?
28. Show that if d = GCD(a,fc), a \ b, and c | b, then (b) Because of the way 2, 4, and 16 are related, it is
ac | bd. possible to change the expansion of a number rela
tive to one of these numbers to the expansion relative
29. Show that GCD(ca, cb) = c GCD(a, b).
to another directly without using the number's base
30. Show that LCM(a, ab) = ab. 10 expansion. Examine the results of Exercise 43
31. Show that if GCD(a, b) = 1, then LCM(a, Z>) = ab. (and other examples, if needed) and describe how to
change from
32. Let c = LCM(<2, b). Show that if a \ k and fc | k, then
(i) a base 2 expansion to a base 4 expansion.
33. Prove that if a and b are positive integers such that a \ b (ii) a base 16 expansion to a base 2 expansion.
and& | a, then a = b. (iii) a base 4 expansion to a base 16 expansion.
32 Chapter 1 Fundamentals

45. Use Bacon's code as given in Example 15 between words and the digits 0, 1, 2,..., 9.
(a) to create a dummy message for COME BACK 47. If ONE and TWO are the base 26 representations of two
(b) to decode WEEN THE MOON COMES OVER integers, then what is the base 26 representation of the
THE MOUNTAIN, THE OWLS FLY HIGH. sum ONE + TWO?
46. (a) For Bacon's code as given in Example 15, why 48. Use Bacon's code, as given in Example 15, to de
should the dummy message be five times as long as code DO YOU KNOW THAT THE NLHVIBER PI IS
the true message? NOW KNOWN TO MORE THAN FOUR HUNDRED
(b) Modify Bacon's code so that it handles the spaces MILLION DECIMAL PLACES.

1.5 Matrices

A matrix is a rectangular array of numbers arranged in m horizontal rows and n


vertical columns:

a\\ <zi2
#21 an din
A = (1)

-Ami 0m2 •*• O'tnn _l

The ith row ofA is [ an al2 •*• a>in ], 1 < i < rn, and the jth column ofA
aij
a2j
is »1 < j < n. We say that A is hi by #i, written mxn.Ifm = «,we say

A is a square matrix of order n and that the numbers a\\, a22,. • •, CLnn form the
main diagonal of A. We refer to the number a^, which is in the ith row and jth
column of A as the i, jth element of A or as the (i, j) entry of A, and we often
write (1) as A= [ay ]. Note that first the row is named and then the column.
Example 1 Let

A=[o -? J]- »-[*1\ c=[' -1 3"i


-1 1 0 -1
D = 2 , and E = -1 2 3
0 2 4 5

Then A is 2 x 3 with a{2 = 3 and a23 = 2, B is 2 x 2 with b2\ = 4, C is 1 x 4,


D is 3 x 1, and E is 3 x 3. ♦

A square matrix A = [ <z/y ] for which every entry off the main diagonal is
zero, that is, a^ = 0 for i ^ j, is called a diagonal matrix.

Example 2 Each of the following is a diagonal matrix.


2 0 0 0 0 0
0 -3 0 , and H = 0 7 0
0 0 5 0 0 6

Matrices are used in many applications in computer science, and we shall see
them in our study of relations and graphs. At this point we present the following
simple application showing how matrices can be used to display data in a tabular
form.
1.5 Matrices 33

Example 3 The following matrix gives the airline distances between thecities indicated.
London Madrid New York Tokyo
London - 0 785 3469 5959
Madrid 785 0 3593 6706
New York 3469 3593 0 6757
Tokyo _ 5959 6706 6757 0

Two m x n matrices A = [ay ] and B = [ fey ] are said to be equal if


aij = fey, 1 < / <m,\ < j < n; that is, if corresponding elements are the same.
Notice how easy it is to state the definition using generic elements ay, fey.

Example 4 If
2 -3 -1 x -1
A = 0 5 2 and B = y 5 2
4 -4 6 4 -4 z

then A = B if and only if x = —3, y = 0, and z = 6.

IfA = [ ay ] and B = [ fey ] are m x n matrices, then the sum ofAand Bis
the matrix C = [ cy ] defined by cy = ay + fey, 1 < / < m, 1 < j <n. That is,
C is obtained by adding the corresponding elements of A and B. Once again the
use of generic elements makes it easy to state the definition.

4
Example 5 Let
M 0
andB = Then

3+ 4 4 + 5 -1+3 7 9
A + B =
5+ 0 0 + (-3) -2 + 2 5 -3

Observe that the sum of the matrices A and B is defined only when A and
B have the same number of rows and the same number of columns. We agree to
write A + B only when the sum is defined.
A matrix all of whose entries are zero is called a zero matrix and is denoted
byO.

Example 6 Each of thefollowing is a zero matrix.


0 0 0
[0 0] ["0 0 0] 0 0 0
[o oj [o 0 oj 0 0 0

The following theorem gives some basic properties of matrix addition; the
proofs are omitted.

THEOREM 1 (a) A + B = B + A
(b) (A + B) + C = A + (B + C)
(c) A + 0 = 0 + A = A •
IfA = [ ay ] is an m x p matrix and B = [ fey ] isa p x n matrix, then the
product ofA and B,denoted AB, isthe m x n matrix C = [ cy ] defined by
Cjj = a,ifei7- + a,-2fe2y H 1-aipb
pupi 1 < i < m, 1 < j < n. (2)
34 Chapter 1 Fundamentals

an al2

a2\ a22 a2p. c\\ c\2

"22 ... b7l ... ** c2\ c22

bp\ bp2 ... !* ... *„ cm\ cm2

am\ am2 ••• am

an - -•^ii
Multiply corresponding
aii' -** elements together and
add the results to
form c^
-*bpJ

Figure 1.20

Let us explain (2) in more detail. The elements an, ai2,..., aip form the ith row
of A, and the elementsb\j, b2j,..., bPj form the jth column of B. Then (2) states
that for any i and j, the element c/7 of C = AB can be computed in the following
way, illustrated in Figure 1.20.
1. Select row i of A and column j of B, and place them side by side.
2. Multiply corresponding entries and add all the products.

3 1
Example 7 Let A = - 2 ~ andB = -2 2 Then
5 -3

AR_r(2)(3) +(3)(-2) +(-4)(5) (2)(l) + (3)(2) + (-4)(- -3)1


AJ5 " [ (D(3) +(2)(-2) +(3)(5) (1)(1) + (2)(2) + (3)( -3) J
_ f—20 20]
-[ 14 -4j
An array of dimension two is a modification of the idea of a matrix, in the
same way that a linear array is a modification of the idea of a sequence. By an
m x n array A we will mean an m x n matrix A of mn positions. We may
assign numbers to these positions later, make further changes in these assignments,
and still refer to the array as A. This is a model for two-dimensional storage of
information in a computer. The number assigned to row / and column j of an array
A will be denoted A[/, j].
As we have seen, the properties of matrix addition resemble the familiar prop
erties for the addition of real numbers. However, some of the properties of matrix
multiplication do not resemble those of real number multiplication. First, observe
that if A is an m x p matrix and B is a p x n matrix, then AB can be computed
and is an m x n matrix. As for BA, we have the following four possibilities:
1. BA may not be defined; we may have n ^ m.
2. BA may be defined and then BA is p x p, while AB is m x m and p ^ m.
Thus AB and BA are not equal.
3. AB and BA may both be the same size, but not be equal as matrices.
4. AB = BA.
1.5 Matrices 35

We agree as before to write AB only when the product is defined

4 -5
Example 8 Let A = I 2 and
• " [i -l Then AB =
-1
and

-=[:5 I]
The basic properties of matrix multiplication are given by the following
theorem.

THEOREM 2 (a) A(BC) = (AB)C


(b) A(B + C) = AB + AC
(c) (A + B)C = AC + BC •
The n x n diagonal matrix

0 0
1 0
I„ =

0 0 1

all of whose diagonal elements are 1, is called the identity matrix of order n. If
A is an m x n matrix, it is easy to verify that ImA = AI„ = A. If A is an n x n
matrix and p is a positive integer, we define

Ap = A • A • • • A and A° = L
p factors

If p and q are nonnegative integers, we can prove the following laws of exponents
for matrices:
A"A«=A^ and {Ap)q = Apq.
Observe that the rule {AR)P = A^B'7 does not hold for all square matrices. How
ever, if AB = BA, then (AB)P = APBP.
IfA= [ay ] is an mx nmatrix, then the n x mmatrix AT = [«//], where
ajj = aji, 1< i < m, 1 < j < n, is called the transpose ofA. Thus the transpose
of A is obtained by interchanging the rows and columns of A.

4 5
2 -3 5
Example 9 LetA
•[i" 3] andB = -1
6 -2
0 .Then

3 2 1
A' = and B7" = 4-1 6
5 0-2

The following theorem summarizes the basic properties of the transpose oper
ation.

THEOREM 3 If A and B are matrices, then


(a) (AT)T = A
(b) (A + B)T=AT+Br
(c) (AB)7" = BrAr •
36 Chapter 1 Fundamentals

Amatrix A= [ a^ ] is called symmetric ifAr = A. Thus, ifAissymmetric,


it must be a square matrix. It is easy to show that A is symmetric if and only if
aU = aji- That is, A is symmetric if and only if the entries of A are symmetric
with respect to the main diagonal of A.

1 2 -3 1 2 -3
IfA = 2 4 5 andB = 2 4 0 , then A is symmetric and B
-3 5 6 3 2 1
is not symmetric.

If x is a nonzero number, there is a number y such that xy = 1. The number


y is called the multiplicative inverse of x. When we have a multiplication for
objects other than numbers, it is reasonable to ask if a multiplicative inverse exists.
One example is matrix multiplication, described in this section.
If A and B are n x n matrices, then we say that B is an inverse of A if AB = In
and BA = I„, where In is the n x n identity matrix defined earlier. The identity
matrix behaves like the number 1, in that I„A = AI„ = A for any n x n matrix A,
so the matrix inverse is analogous to the reciprocal of a nonzero number. However,
it is not clear how to construct inverses, or even when they exist.

1 3 0 -2 3 -3
Example 11 Aninverse of the matrix 2 2 1 is the matrix 1—1 1 . This can
1 0 1 2-3 4
be verified by checking that

1 3 0 -2 3 -3 1 0 0
2 2 1 1 -1 1 0 1 0
1 0 1 2 -3 4 0 0 1

and

2 3 -3" 1 3 0" 1 0 0
1 -1 1 2 2 1 = 0 1 0
2 -3 4 1 0 1 0 0 1

There are tests to determine if an n x n matrix has an inverse, and formulas for
computing an inverse if it exists. Many of these are programmed into calculators
and computer algebra systems. We will be content to give the results for the case
of 2 x 2 matrices.

Suppose that the 2 x 2 matrix A = , , has aan inverse B =


c d\ lg
Then
'a bite f
[:c d\[eg
d \\ g h\
h =[o lj
and we have two pairs of equations

ae + bg = 1 af + bh = 0
and
ce + dg = 0 cf + dh = 1.

When we solve the first pair for e and g, we find that we must divide by ad —be.
This can only be done if ad — be ^ 0. The same condition is needed when
solving the second pair for / and h. The results of solving for e, f, g, and h are
summarized in Theorem 4.
1.5 Matrices 37

has a unique inverse if and only if ad —be jL 0. In this


THEOREM 4 A matrix A

case we have
-['«
ad — be ad — be
A~{ =
c a

ad — be ad — be

Boolean Matrix Operations


A Boolean matrix (also called a bit matrix) is an m x n matrix whose entries are
either zero or one. We shall now define three operations on Boolean matrices that
have useful applications in Chapter 4.
Let A = [ ay ] and B = [ by ] be m x n Boolean matrices. We define
Av B = C = [ cy ], the join ofAand B, by
II if ay = 1 or by = 1
0 if ay and by are both 0

and AAB = D = [ d// ], the meet ofAand B, by


if ay and by are both 1
dij =
10 if ay = 0 or by = 0.
Note that these operations are only possible when A and B have the same size, just
as in the case of matrix addition. Instead of adding corresponding elements in A
and B, to compute the entries of the result, we simply examine the corresponding
elements for particular patterns.

1 0 11 ri l 0
0 1 1 i n 1
Example 12 LetA andB =
1 1 0 0 0 1
0 0 0 l 1 0

(a) Compute A vB. (b) Compute A A B.

Solution
(a) Let A v B = [ c,y- ]. Then, since a^ and b^ are both 0, we see that
C43 = 0. In all other cases, either a-,j or b,j is 1, so c,y is also 1. Thus
111
1 1 1
AvB =
1 1 1
1 1 0

(b) Let AAB = [ dij ]. Then, since a\\ and b\\ are both 1, d\ \ = 1, and since
an and b?$ are both 1, dn = 1. In all other cases, either a,-7- or btj is 0, so
du = 0. Thus
1 0 0'
0 0 1
AaB =
0 0 0
0 0 0
38 Chapter 1 Fundamentals

Finally, suppose that A= [au ] is an mxpBoolean matrix and B= [ btj ] is


a p x n Boolean matrix. Notice that the condition on the sizesof A and B is exactly
the condition needed to form the matrix product AB. We now define another kind
of product.
The Boolean product of A and B, denoted A© B, is the m x n Boolean matrix
C = [ cij ] defined by

II if aik = 1 and bkj = 1 for some k,l <k < p


0 otherwise.

This multiplication is similar to ordinary matrix multiplication. The preceding


formula states thatfor any i and j the element c,-y- of C = A O B can be computed
in the following way, as illustrated in Figure 1.21. (Compare this with Figure
1.20.)
1. Select row i of A and column j of B, and arrange them side by side.
2. Compare corresponding entries. If even a single pair of correspondingentries
consists of two l's, then c/y = 1. If this is not the case, then ctj = 0.

au an ..

^21 #22 •• a2p bl\ b\2 ... b LU L\2

c2\ c22 C2n


0

bp\ bp2 ... bni

Ami Qm7

0/1-
If any corresponding pair
of entries are both
equal to 1,thenCy = 1;
otherwise ctj = 0.
+ bn

Figure 1.21

We can easily perform the indicated comparisons and checks for each posi
tion of the Boolean product. Thus, at least for human beings, the computation of
elements in A O B is considerably easier than the computation of elements in AB.

1 1 0'
10 0 0
0 1 0
Example 13 Let A = andB = 0 110 Compute A © B.
1 1 0
10 11
0 0 1

Solution

Let AOB = [ eij ]. Then e\\ = 1, since row 1ofAand column 1ofBeach have
a 1 as the first entry. Similarly, en — 1, since an = 1 and £22 = 1; that is, the first
row of A and the second column of B have a 1 in the second position. In a similar
way we see that e\3 = 1. On the other hand, eu = 0, since row 1 of A and column
1.5 Matrices 39

4 of B do not have common l's in any position. Proceeding in this way, we obtain
n l o
o l o
A0B =
l l o
l o l

The following theorem, whose proof is left as an exercise, summarizes the


basic properties of the Boolean matrix operations just defined.

THEOREM 5 If A, B, and C are Boolean matrices of compatible sizes, then


1. (a) A v B = B v A
(b) A A B = B a A
2. (a) (AvB)vC = Av(BvC)
(b) (AaB)aC = Aa(BaC)
3. (a) A a (B v C) = (A a B) v (A a C)
(b) A v (B a C) = (A v B) a (A v C)
4. (AOB)OC = AO(B©C) •

1.5 Exercises
3"
1. LetA=[j ~\ *],B = -2
4
, and
In Exercises 5 through 10, let

0 1
2 1 3
"2 3 4" A = 1 2
4 1 -2
C = 5 6-1 2 3
2 0 8 1 -2 3
(a) What is a\ 2, a22, tf23 ? C = 4 2 5
3 1 2
(b) Whatisfc,,,^,?
3 2 -1
(c) \ Vhat is C13, C23, c 33? E 5 4 -3
0 1 2
(d) List the elements on the main diagonal of C.
2. Which of the following are diagonal matrices? 5. If possible, compute each of the following,
3 0 0 (a) C+ E (b) AB
(b) B =
(a) A
-[ii] 0
0
-2
0
0
5
(c) CB + F (d) AB + DF
6. If possible, compute each of the following.
0 0 0 (a) A(BD) and (AB)D
(c) C = 0 0 0 (b) A(C + E) and AC + AE
0 0 0
(c) FD + AB
2 6-2 7. If possible, compute each of the following.
(d) D = 0-10 (a) EB + FA
0 0 3
(b) A(B + D) and AB + AD

4 0 0 (c) (F + D)A (d) AC + DE


(e) E = 0 4 0 8 If possible, compute each of the following.
0 0 4 (a) Arand(Ar)r

lf[ac-d *-*] =[10 62\^^b,c^ndd. (b) (C + E)randCr+E7


(c) (AB)r and BrAr (d) (BrC) + A
9. If possible, compute each of the following.
lf[2*+d ?-"&/] =[4 13 }Andfl,*c, and* (a) A7(D + F) (b) (BC)randCrBr
40 Chapter 1 Fundamentals

(c) (Br+A)C (d) (Dr+E)F For Exercises 27 and 28, let


10. Compute D3. 1 0 1 0.2 0.4 0.2"
11. Let A be an m x n matrix. Show that \m A = AI„ = A. A = 0 0 1 » B = -0.4 0.2 0.6 »

(Hint: Choose a generic element of lm A.) 1 1 1 0.2 --0.6 0.2

r2
_* I and B= -1 1 -1 0" "2 -1 1L"
12. Let A

AB ^ BA.
-[ 3
]• Show that
c = 1
0
0
1
1
0
and D = 1
1
0
1
-1I
I

3 0 0" 27. (a) Verify that C is an inverse of A.


13. LetA = 0 -2 0
0 0 4
(b) Verify that D is an inverse of B.
28. Determine whether CD is the inverse of AB. Explain your
(a) Compute A3. (b) Whatis A*?
reasoning.
14. Show that A0 = 0 for any matrix A.
29. Show that if A and B are n x n matrices and A"1, B_1
15. Show thatlTn =ln. both exist, then (AB)"1 = (B^A"1).
16. (a) Show that if A has a row of zeros, then AB has a In Exercises 30 and 31, computeA v B, A A B, and A O Bfor
corresponding row of zeros. (Hint: Use the generic the given matrices A and B.
element definition of AB given in this section.)
(b) Show that if B has a column of zeros, then AB has a
corresponding column of zeros.
K»*-[J!}-[i !]
17. Show that the yth column of the matrix product AB is (b) A =
equal to the matrix product ABy, where B, is the yth col
umn of B.

18. If 0 is the 2 x 2 zero matrix, find two 2x2 matrices A


(c)
*-[: :]• -[? i]
and B, with A # 0 and B ^ 0, such that AB = 0. 0 0" 1 1 1
31. (a) A = 1 1 , B = 0 0 1
19.
»*-[? ;]• show that A2 = I2. 0

0
0_
1"
1

0
0

1
1

1
(b) A = , B =
20. Determine all 2 x 2 matrices A

A2 = I2.
[!'.] such that 1
0
0
0
1
1
1
0
0
1

0 1 1 1
21. Let A and B be symmetric matrices.
(C) A: 0 B = 1 1 1
(a) Show that A + B is also symmetric. 0 1 0 0
(b) Is AB also symmetric?
In Exercises 32 and 33, let F = [ fy ]be a p x q matrix.
22. Let A be an n x n matrix.
32. (a) Give a generic element in row k of F.
(a) Show that AAr and ArA are symmetric.
(b) What is the largest value of 7?
(b) Showthat A + Ar is symmetric.
(c) Give a generic element in column / of F.
23. Prove Theorem 3. [Hint: For part (c), show that the /, jth
element of (AB)r equals the /, 7th element of BrAr.] (d) What is the largest value of i ?
33. (a) Give the element in the lower left corner of F.
24. Let A be a symmetric 2x2 matrix that has an inverse.
Must A-1 also be symmetric? Explain your reasoning. (b) Give the element in the upper left corner of F.

25. Find the inverse of each matrix.


(c) Give the element in the lower right corner of F.
(d) Give the element in the upper right corner of F.
(a)
[-] (b)
[~lt] (e) Givea genericelementin row r of Fr.
(f) Give a generic element on the diagonal of F.
(c)
In Exercises 34 and 35, let M = [ m^ ], N = [ n^ ], and
26. Find the inverse of each matrix. P = [ pjj ] be square matrices ofthe same size. Use the en
-8 3l „J 3 tries ofM, N, and P to represent the entry in the ij-position of
°> [~l-l]
0
9
(b)
[-> .o] each of thefollowing.
34. (a) P + M + N (b) Pr+M (c) Nr (d) NM
(c)
[-1 1] 35. (a) PM (b) MP (c) P(M + N) (d) MN + PN
1.6 Mathematical Structures 41

In Exercises 36 and 37, let M = [ m,7 ], N = [ntj ], and Prove that p divides all the entries of A and all the entries
P = [ ptj ] be square Boolean matrices ofthe same size. Use ofB.
the entries of M, N, and P to represent the entry in the ij- Another operation on matrices is scalar multiplication. Let
position of each of thefollowing. k be a real number and A = [ ay ] be an m x n matrix.
36. (a) MaP (b) PvN (c) (MaN)v(MaP) The result of multiplying A by the scalar k is the matrix
kA = [ kaij ]. For Exercises 49 through 53, use the defini
37. (a) M O P (b) P O M (c) (M O N) O P
tion ofscalar multiplication and the matrices given.
38. Complete the following proofs.
2 -3 -1 2 4 -6
(a) A v A = A. Proof: Let by be an element of A v A.
If bij = 0, then au = , because If A = 0 5 2 , B = 4 0 9
4 -4 6 7 -1 3
bij = 1, then atj . because Hence
b^ = aij for each i, j pair,
and
(b) A A A = A. Proof: Let by be an element of A A A.
If bu =0, then. If bn = 1, then. (Ex
4 0
plain.) Hence by = ay for each /, j pair. C = 3 1
39. ShowthatAvB = BvA. -2 5
40. ShowthatAAB = B A A.
49. Compute each of the following,
41. Show that A v (B v C) = (A v B) v C.
(a) 3A (b) 5B (c) -1C
42. Show that A A (B A C) = (A A B) A C.
50. Compute each of the following.
43. ShowthatAO(BOC) = (AOB)OC.
(a) 3(A + B) (b) 3A + 3B
44. Show that A A (B v C) = (A A B) v (A a C).
(c) -2(AC) (d) A(-2C)
45. Show that A v (B A C) = (A v B) a (A v C). 51. Show that scalar multiplication has the following prop
46. What fact does Example 8 illustrate? erty.
47. Let A = [ a^ ] and B = [ by ] be two nxn matrices and k(A + B) = kA + kB
let C = [ cy ] represent AB. Prove that ifkis an integer 52, Show that scalar multiplication has the following prop
and k | ay for all i, j, then k \ cy for all i, j. erty.

48. Let p be a prime number with p > 2, and let A and B be *(AB) = (*A)B = A(&B)
matrices all of whose entries are integers. Suppose that p 53 Let A be an m x n matrix. Find a matrix K such that
divides all the entries of A-f-B and all the entries of A—B. KA = kA, for a fixed k.

1.6 Mathematical Structures

Several times in this chapter, we have defined a new kind of mathematical object;
for example, a set or a matrix. Then notation was introduced for representing the
new type of object and a way to determine whether two objects are the same was
described. Next we classified objects of the new type; for example, finite or infinite
for sets, and Boolean or symmetric for matrices. And then operations were defined
for the objects and the properties of these operations were examined.
Such a collection of objects with operations defined on them and the accom
panying properties form a mathematical structure or system. In this book we
deal only with discrete mathematical structures.

Example 1 The collection of sets with the operations of union, intersection, and complement
and their accompanying properties is a (discrete) mathematical structure. We de
note this structure by (sets, U, D, ~). ♦

Example 2 The collection of 3 x 3 matrices with the operations of addition, multiplication,


and transpose is a mathematical structure denoted by (3 x 3 matrices, +, *, r). ♦
42 Chapter 1 Fundamentals

An important property we have not identified before is closure. A structure


is closed with respect to an operation if that operation always produces another
member of the collection of objects.

Example 3 The structure (5x5 matrices, +, *, T) is closed with respect to addition because
the sum of two 5x5 matrices is another 5x5 matrix. ♦

Example 4 The structure (odd integers, +, *) is not closed with respect to addition. The sum
of two odd integersis an even integer. This structure does have the closure property
for multiplication, since the product of two odd numbers is an odd number. ♦

An operation that combines two objects is a binary operation. An operation


that requires only one object is a unary operation. Binary operations often have
similar properties, as we have seen earlier.

Example 5 (a) Setintersection is a binary operation since it combines two sets to produce a
new set.

(b) Producing the transpose of a matrix is a unary operation. ♦

Common properties have been given names. For example, if the order of the
objects does not affect the outcome of a binary operation, we say that the operation
is commutative. That is, if x • y = y • jc, where • is some binary operation, Q
is commutative.

Example 6 (a) Join and meet forBoolean matrices arecommutative operations.


AvB = BvA and AaB = BaA.

(b) Ordinary matrix multiplication is not a commutative operation. AB ^ BA. ♦

Note that when we say an operation has a property, this means that the state
ment of the property is true when the operation is used with any objects in the
structure. If there is even one case when the statement is not true, the operation
does not have that property. If • is a binary operation, then D is associative or has
the associative property if
(xBy)Dz = xn(yDz).

Example 7 Setunion is anassociative operation, since (A UB) UC = A U(B UC) is always


true. ♦

If a mathematical structure has two binary operations, say • and V, a dis


tributive property has the following pattern:
x • (y V z) = (x • y) V (x • z).
We say that "• distributes over V."

Example 8 (a) We are familiar with the distributive property for real numbers; if <z, b, and
c are real numbers, then a • (b + c) = a • b + a • c. Note that because we
have an agreement about real number arithmetic to multiply before adding,
parentheses are not needed on the right-hand side.
(b) The structure (sets, U, n, ~) has two distributive properties:
A U (B n C) = (A U B) n (A U C)
and

a n (B u c) = (A n B) u (A n C). ♦
1.6 Mathematical Structures 43

Several of the structures we have seen have a unary operation and two binary
operations. For such structures we can ask whether De Morgan's laws are proper
ties of the system. If the unary operation is o and the binary operations are • and
V, then De Morgan's laws are
(jc • y)° = x° V y° and (jc V y)° =jc°D y°.

Example 9 (a) As we saw in Section 1.2, sets satisfy De Morgan's laws for union, intersec
tion, and complement: (A UB) = A n ~B and (A n B) = AUB.
(b) The structure (real numbers, +, *, y/~) does not satisfy De Morgan's laws,
since y/x + y / V* * y/y. ♦

A structure with a binary operation • may contain a distinguished object e,


with the property x • e = e • x = x for all x in the collection. We call e an
identity for •. In fact, an identity for an operation must be unique.

THEOREM 1 If e is an identity for a binary operation •, then e is unique.

Proof
Assume another object / also has the identity property, so x • / = / • x = x.
Then e • / = e, but since e is an identity for •, i • e = e • / = /. Thus, / = e.
Therefore there is at most one object with the identity property for D. •

This is one of our first examples of a proof that does not proceed directly. We
assumed that there were two identity elements and showed that they were in fact
the same element.

Example 10 For (n x n matrices, +, *, r), In is the identity for matrix multiplication and the
n x n zero matrix is the identity for matrix addition. ♦

If a binary operation • has an identity e, we say y is a D-inverse of x if


xC\y = y\Jx = e.

THEOREM 2 If • is an associative operation andx has a D-inverse y, then y is unique.

Proof
Assume there is another D-inverse for x, say z. Then (z&x)ny = eDy = y
and z D (x D y) = z • e = z. Since D is associative, (z D jc) • y = z D (x D y)
and so y = z. •

Example 11 (a) In the structure (3x3 matrices, +, *, r), each matrix A = [ ay ] has a
+-inverse, or additive inverse, —A = [ —ay ].
(b) In the structure (integers, +, *), only the integers 1 and —1 have multiplicative
inverses. ♦

Example 12 Let d, v, and o bedefined for the set {0, 1} by thefollowing tables.
• 0 1 V 0 1 x° X

0 0 1 0 0 0 0 1
1 1 0 1 0 1 1 0

Thus 1 D 0 = 1, 0 V 1 = 0, and 1° = 0. Determine if each of the following is


true for ({0, 1}, •, V, o).
(a) D is commutative. (b) V is associative.
44 Chapter 1 Fundamentals

(c) De Morgan's laws hold.


(d) Two distributive properties hold for the structure.

Solution
(a) The statement x • y = y D x must be true for all choices of x and y.
Here there is only one case to check: Is 0 • 1 = 1 D 0 true? Since both
0 D 1 and 1 D 0 are 1, D is commutative.
(b) The eight possible cases to be checked are left as an exercise. See Exercise
6(b).
(c) (0 D 0)° = 0° = 1 0° V 0° = 1 V 1 = 1
(0 D 1)° = 1° = 0 0° v 1° = 1 v 0 = 0
(1 D 1)° = 0° = 1 1° v 1° = 0 V 0 = 0
The last pair shows that De Morgan's laws do not hold in this structure.
(d) One possible distributive property is x • (y V z) = (x • y) V (jc D z).
We must check all possible cases. One way to organize this is shown in a
table.

x y z y vz x • (y v z) xOy x D z (* D y) V (;c • z)
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 0 0
1 1 0 0 1 0 1 0
1 1 1 1 0 0 0 0
(A) (B)

Since columns (A) and (B) are not identical, this possible distributive
property does not hold in this structure. The check for the other distribu
tive property is Exercise 7. ♦

In later sections, we will find it useful to consider mathematical structures


themselves as objects and to classify them according to the properties associated
with their operations.

1.6 Exercises

In Exercises 1 and 2, tell whether the structure has the closure (b) (prime numbers, +, *) addition
property with respect to the operation. 5. Show that 0 is a commutative operation for sets.
1. (a) (sets, U, fl, ~) union 6. Using the definitions in Example 12, (a) show that • is
(b) (sets, U, n, ~) complement associative, (b) Show that V is associative.

2. (a) (4x4 matrices, +, *, T) multiplication 7. Using the definitions in Example 12, determine if the
other possible distributive property holds.
(b) (3x5 matrices, +, *, T) transpose
8. Give the identity element, if one exists, for each binary
In Exercises 3 and 4, tell whether the structure has the closure operation in the given structure.
property with respect to the operation. (a) (real numbers, +, *, </~)
3. (a) (integers, +,—,*, -r) division (b) (sets,U,H,-)
(b) (A*, catenation) catenation (c) ({0,1}, •, V, *) as defined in Example 12
4. (a) (n x n Boolean matrices, v, a, r) meet (d) (subsets of a finite set A, 0, ~)
1.6 Mathematical Structures 45

9. Give the identity element, if one exists, for each binary Determine which of the following properties hold for this
operation in the structure (5x5 Boolean matrices, v, a, structure.

O). (a) Closure (b) Commutative


In Exercises 10 through 16, use the structure S = (n x n diag (c) Associative
onal matrices, +, *, T).
30. Let R be as in Exercise 29. Determine which of the fol
10. Show that S is closed with respect to addition. lowing properties hold for this structure.
11. Show that S is closed with respect to multiplication. (a) An identity element
12. Show that S is closed with respect to the transpose opera (b) An inverse for every element
tion.
31. Let S =(1x2 matrices, •), where [x y] •
13. Does S have an identity for addition? If so, what is it?
14. Does S have an identity for multiplication? If so, what is
[w z] = [ x + w
y + z
]• Determine which of the

it? following properties hold for this structure,


15. Let A be an n x n diagonal matrix. Describe the additive (a) Closure (b) Commutative
inverse of A.
(c) Associative
16. Let A be an n x n diagonal matrix. Describe the multi 32. Let S be as in Exercise 31. Determine which of the fol
plicative inverse of A. lowing properties hold for this structure.
In Exercises 17 through 23, use the structure R = (a) An identity element
(M, +, *, T), where M is the set of matrices of the form
(b) An inverse for every element
[o oj where a is a real number.
33. (a) Give a symbolic statement of the distributive prop
erty for scalar multiplication over V as defined in Ex
17. Show that R is closed with respect to addition. ercise 29.
18. Show that R is closed with respect to multiplication.
(b) Is the distributive property in part (a) a property of
19. Show that R is closed with respect to the transpose oper Rl
ation.

20. Does R have an identity for addition? If so, what is it? 34. (a) Give a symbolic statement of the distributive prop
erty for scalar multiplication over • as defined in Ex
21. Does R have an identity for multiplication? If so, what is
ercise 31.
it?

22. Let A be an element of M. Describe the additive inverse (b) Is the distributive property in part (a) a property of
for A. SI

23. Let A be an element of M. Describe the multiplicative 35. For a Boolean matrix B, we define comp B to be the ma
inverse for A. trix formed by changing each 0 entry of B to 1 and each
In Exercises 24 through 28, let R = (Q, •), where x D y = 1 entry of B to 0. Let R = (5 x 5 Boolean matrices, A,
x + y v, comp). Do De Morgan's laws hold for Rl Justify your
—-—. Determine which of thefollowing properties hold for answer.

this structure:
The properties of a mathematical structure can be used to
24. Closure rewrite expressions just as is done in ordinary algebra. In Ex
25. Commutative ercises 36 through39, rewrite the given expression to produce
26. Associative
the requested result.

27. An identity element 36. (A U B) n (A U B) one set, no operations


28. An inverse for every element 37. (A Pi B) n A two sets, two operations
29. Let R = (2 x 1 matrices, V), where
38. (A U B) U (A fl B) two sets, two operations

[»]'["H/+t:.]- 39. (AU B) D(AU B) one set, no operations


46 Chapter 1 Fundamentals

Tips for Proofs


Many exercises in this chapter ask that you show, prove, or verify a statement. To
show or prove a statement means to give a written explanation demonstrating that
the statement is always true. To verify a statement, in this book, means to check
its truth for a particularcase; see, for example, Section 1.2, Exercises 16 and 24.
Most proofs requiredin this chapter proceed directly from the given conditions
using definitions and previously provenfacts; an exampleis Section 1.4, Theorem
2. A powerful tool for constructing a proof is to choose a generic object of the
type in the statement and to see what you know about this object. Remember that
you must explain why the statement is always true, so choosing a specific object
will only verify the statement for that object.
The most common way to show that two sets are equal is to show each is a
subset of the other (Section 1.2, Theorem 1).
In proving statements about sets or matrix operations, try to work at the level
of object names rather than at the element or entry-level. For example, Section
1.5, Exercise 22 is more easily proved by using the facts that if A is symmetric,
then A7 = A and Theorem 3 rather than by using the fact that if A = [ ay ] is
symmetric, then ay = a}{ for each i and j.
One other style of direct proof is seen in Section 1.6, Example 12. Sometimes
we show the statement is always true by examining all possible cases.

• Key Ideas for Review


Set: a well-defined collection of objects x e A
0 (empty set): the set with no elements
Characteristic function of a set A: /a(*)
=1'if
[0 if xiA
Equal sets: sets with the same elements Countable set: a set that corresponds to a sequence
A c B (A is a subset of B): Every element of A is an ele Word: finite sequence of elements of A
ment of B.
Regular expression: see page 17
\A\ (cardinality of A): the number of elements of A Theorem: If n and m are integers and n > 0, we can write
Infinite set: see page 4 m = qn + r for integers q and r with 0 < r < n. Moreover,
P(A) (power set of A): the set of all subsets of A there is just one way to do this.
AU B (union of A and B): {x \ x e A or x e B] GCD(a, b): d = GCD(a, b) if d \ a, d \ b, and d is the
largest common divisor of a and b.
AC\B (intersection of A and B):{x \ x e A and x e B]
Theorem: If d is GCD(a, b), then
Disjoint sets: two sets with no elements in common
(a) d = sa + tb for some integers s and t.
A —B (complement of B with respect to A): (b) If c | a and c | b, then c \ d.
{x \x e A and x £ B]
Relatively prime: two integers a and b with GCD(a, b) = 1
A (complement of A): {x \ x £ A]
Euclidean algorithm: method used to find GCD(a, b); see
Algebraic properties of set operations: see pages 8-9 pages 22-23
Theorem (the addition principle): If A and B are finite sets, LCM(#, b): c = LCM(<z, b) if a \ c, b \ c, and c is the
then \A U B\ = \A\ + \B\ - \A D B\. smallest common multiple of a and b
Theorem (the three-set addition principle): If A, B, and C Theorem: GCD(a, b) • LCM(a, b) = ab
are finite sets, then \A U B U C\ = \A\ + \B\ + \C\ - Base b expansion of a number: see page 27
\a n b\ - \a n c\ - \b n c\ + \a n b n c\.
Cryptology: the science of producing and deciphering se
Inclusion-exclusion principle: see page 9 cret codes
Sequence: list of objects arranged in a definite order Bacon's code: see page 29
Recursive formula: formula that uses previously defined Steganography: the science of concealment of coded infor
terms mation

Explicit formula: formula that does not use previously de mod-n function: fn(z) = r, where r is the remainder when
fined terms z is divided by n
Linear array: see page 14 Matrix: rectangular array of numbers
Chapter 1 Self-Test 47

• Size of a matrix: A is m x n if it has m rows and n columns • A v B: see page 37


• Diagonal matrix: a square matrix with zero entries off the • A A B: see page 37
main diagonal • A O B: see page 37
• Equal matrices: matrices of the same size whose corre • Properties of Boolean matrix operations: see page 39
sponding entries are equal • Mathematical structure: a collection of objects with opera
• A + B: the matrix obtained by adding corresponding entries tions defined on them and the accompanying properties
of A and B • Binary operation: an operation that combines two objects
• Zero matrix: a matrix all of whose entries are zero • Unary operation: an operation that requires only one object
• AB: see page 33 • Closure property: each application of the operation pro
• I„ (identity matrix): a square matrix with ones on the diag duces another object in the collection
onal and zeros elsewhere • Associative property: (x • y) • z = x • (y • z)
• Array of dimension 2: see page 34 • Distributive property: x D (y V z) = (x D y) V (x • z)
• Ar: the matrix obtained from A by interchanging the rows • De Morgan's laws: (jc • y)° = x° V y° and
and columns of A (jc V y)° = x° D y°
• Symmetric matrix: Ar = A • Identity for •: an element e such that x^e = eUx=x
• Inverse of a matrix: see page 36 for all jc in the structure
• Boolean matrix: a matrix whose entries are either one or • D-inverse for jc: an element y such that jc Dy = yDx = e,
zero where e is the identity for •

• Chapter 1 Self-Test
1. What kind of mathematical object is P(A)1 9. Under what conditions will ADB = AU Bl

2. What kind of mathematical object is | P (A) |? 10. Suppose that 109 of the 150 mathematics students at
3. What kind of mathematical object is LCM(#, b)l Verysmall College take at least one of the following com
4. What kind of mathematical object is AA? puter languages: PASCAL, BASIC, C++. Suppose 45
study BASIC, 61 study PASCAL,53 study C++, 18 study
5. What are the components of a mathematical structure? BASIC and PASCAL, 15 study BASIC and C++, and 23
6. Let A = {x | jc is a real number and 0 < jc < 1}, study PASCAL and C++.
B = {jc I jc is a real number and x2 + 1 = 0}, (a) How many students study all three languages?
C = {x | jc = 4m, m e Z}, D = {0, 2, 4, 6,...}, and
E = {jc \x €Zand;c2 < 100). (b) How many students study only BASIC?
(a) Identify the following as true or false. (c) How many students do not study any of the lan
guages?
(i) CCD (ii) {4, 16} cc
(iii) {4,16} c E (iv) DC/) 11. Define a sequence as follows: <z0 = 0, a\ =0,
an — 1 —3<2n_i + 2a„_2. Compute the first six terms of
(v) K0
this sequence.
(b) Identify the following as true or false.
12. Lett/ = [a,b,c,d,e,f,g,h,ij], A = {a,b,d,f},
(i) C H E £ (C U E) B = {a, b, c, h, j], C = {b, c, /, h, /}, and D = {g, h}.
(ii) 0 c (A fl B) (iii) CHD = D Represent each of the following sets by an array of zeros
(iv) CUE ^D and ones.

(v) a n d c a n c (a) A U B (b) AHB

7. Let A = {jc I jc = 2/i, n € Z+}, (c) AH(BUC) (d) (AnB)UD


B = {x | x = In + 1, n e Z+}, C = {jc | jc = 4/i, n e 13. Let / = {a, b, c}. In each part that follows is listed a
Z+}, and D = {jc | jc(jc2 - 6x + 8) = 0, jc g Z}. Use Z as string in /* and a regular expression over /. For each,
the universal set and find state whether the string belongs to the regular set corre
(a) AUB (b) A sponding to the expression.
(c) (AnD)®(AnB) (d) AUC (a) ab a*bc* (b) acbb ((acb)vb)*
(e) A-C (c) be ((ab*) v c) (d) abaca (ab)*ac
8. Draw a Venn diagram to represent (a) A fl B and 14. Use the Euclidean algorithm to compute
(b) AOB. GCD(4389, 7293) and write it as ^(7293) + f (4389).
48 Chapter 1 Fundamentals

15. LetA=T_J 3 2JandB=r_3 J1. Compute, 16. LetC=


10 1
1 1 0 andD=
[110
0 1 0
if possible, each of the following, 0 1 lj |_1 1 0
(a) AB (b) BA (c) B^ Compute each of the following.
(a) COD (b) CvD (c) CaD
(d) A + B (e) ArB (I) B"1
17. Let S = (2 x 2 Boolean matrices, A, v, O) and A be a
(g) B-'A 2x2 Boolean matrix. Describe the A-inverse of A in S.

I Experiment 1
In many votingprocedures the rules are one person, one vote, and a simple major
ity is required to elect a candidate or to pass a motion. But it is not unusual to have
a procedure where individual voters have more than one vote or where something
other than a simple majority is required. An example of such a situation is when
not all shareholders in a company own the same number of shares, and each share
holder has as many votes as shares. Does a shareholder with twice as many shares
as another have twice as much control, or power, over the company? In this experi
ment you will investigate this question and some related ones. First, we begin with
some definitions. The number of votes that a voter has is called the voter's weight.
Here only counting numbers can be weights. The total number of votes needed to
elect a candidate or to pass a motion is the quota. The collection of the quota and
the individual weights for all voters is called a weighted voting system. If the vot
ers are designated v\, V2,..., v* with corresponding weights w\, W2,..., Wk and
q is the quota, then the weighted voting system may be conveniently represented
by [q : u>i, u>2,..., Wk\> For ease of computations, the weights are usually listed
from largest to smallest.
1. For the weighted voting system [9 : 9,4, 2,1], what is the quota? How many
voters are there? What is the total number of votes available?
2. In a weighted voting system [q : w\, W2,..., Wk]> what are the restrictions on
the possible values of ql Explain each restriction.
3. For the weighted voting system [9 : 9,4, 2,1], describe how much power
voter v\ has. Such a voter is called a dictator. Why is this appropriate?
Could a system have two dictators? Explain why or why not.
4. For [8 : 5, 3, 2,1], is v\ a dictator? Describe ui's power relative to the other
voters.

More interesting cases arise when the power of each voter is not so obvious as in
these first examples. One way to measure a voter's power was developed by John
Banzhaf in 1965. A coalition is a subset of the voters in a weighted voting system.
If the total number of votes controlled by the members of the coalition equals or
exceeds the quota, we call the coalition a winning coalition. If not, this is a losing
coalition.

5. (a) List all the coalitions for [9 : 9,4, 2,1]. Which of these are winning coali
tions?
(b) List all the winning coalitions for [8 : 5, 3, 2,1].
Banzhaf's idea is to measure a voter's power by examining how many times re
moval of that voter from a coalition would change the coalition from winning
to losing. Consider the system [7 : 5,4, 3]. The winning coalitions are {v\, V2},
{ui> U3}, {i>2, U3}, and {t>i, V2, V3}. Each member of the first three coalitions has
the power to change it from winning to losing, but none have this power in the last
Experiment 1 49

coalition. All together there are six opportunities for change. Each of v\, v2, v$
has two of these opportunities. We record this information as the Banzhaf power
distribution for the system: vx\\, v2\\, v$\\. According to this analysis, all
three voters have the same amount of power despite having different weights. The
fraction of powerassigned to a voteris the voter's Banzhaf power index.
6. Here is a test for Banzhaf's definition of power. Calculate the Banzhaf power
distribution for [9 : 9,4, 2, 1]. Explain how the results are consistent with the
designation of v\ as a dictator.
7. Calculate the Banzhaf power distribution for [8 : 5, 3, 2, 1]. A voter like v\
that must belong to every winning coalition has veto power in the system.
8. Let [q : 6, 3, 1] be a weighted voting system.
(a) Give values for q for which the system has a dictator and identify that
voter.

(b) Give values for q for which one or more voters have veto power and iden
tify these voters.
(c) Give values for q for which at least one player is powerless, but there is
no dictator. Which player is powerless?
Banzhaf's idea is adaptable to cases where each voter has one vote, but special
rules for voting apply.
9. The four partners in a company agree that each partner has one vote and a
simple majority passes a motion. In the case of a tie the coalition containing
the senior partner is the winning coalition. Give the Banzhaf power distri
bution for this system. Would the distribution change if the tie-breaking rule
were changed to the coalition containing the most junior member is the losing
coalition? Explain.
10. Suppose you are the voter with weight one in [8 : 5, 3, 2, 1].
(a) What is your Banzhaf power index?
(b) Unhappy with this situation, you offer to buy a vote from one of the other
voters. If each is willing to sell and each asks the same price, from whom
should you buy a vote and why? Give the Banzhaf power distribution for
this system for the resulting weighted voting system.
11. Here is another feature of Banzhaf's way of measuring power. Let
[q : w\, W2,..., Wk\ be a weighted voting system and n be a positive inte
ger. Prove that the Banzhaf power distributions for [q : w\, tt>2> • • •, u>k\ and
[nq : nw\, nw2,..., nwk] are the same.
12. We now return to the original question about power. Suppose we have a
weighted voting system in which v\ has weight w\, V2 has weight W2, and
w\ = 2vt)2. Construct such a system where the Banzhaf power index of v\ is
(a) the same as that of V2
(b) twice that of i>2
(c) more than twice that of t>2.
CHAPTER

2 Logic
Prerequisites: Chapter 1

Logic is the discipline that deals with the methods of reasoning. On an elemen
tary level, logic provides rules and techniques for determining whether a given
argument is valid. Logical reasoning is used in mathematics to prove theorems,
in computer science to verify the correctness of programs and to prove theorems,
in the natural and physical sciences to draw conclusions from experiments, in the
social sciences, and in our everydaylives to solve a multitude of problems. Indeed,
we are constantly using logical reasoning. In this chapter we discuss a few of the
basic ideas.

Looking Back
In the 1840s Augustus De Morgan, a British mathematician, set at Queen's College in Ireland for many years. Thus, De Mor
out to extend the logic developed by the early Greeks and others gan started and Boole completed the task of folding a large part
and to correct some of the weaknesses in these ideas. De Mor of the study of logic into mathematics. We shall briefly study
gan (1806-1871) was bom in India but was educated in Eng the work of De Morgan and Boole in logic in this chapter, and
land. He taught at London University for many years and was in Chapter 8 we shall further examine important applications of
the first to use the word "induction" for a method of proof that the work of Boole to many areas in mathematics and computer
had been used in a rather informal manner and put it on a firm science.
rigorous foundation. In 1847, a few years after De Morgan's
work on an extended system of logic had appeared, his coun
tryman George Boole published the book entitled The Mathe
matical Analysis of Logic and followed it up a few years later
by the book An Investigation of the Laws of Thought. Boole's
objective in these books was
to investigate the fundamental laws of those operations
of the mind by which reasoning is performed; to give ex
pression to them in the symbolical language of a Calcu
lus; and upon this foundation to establish the science of
Logic and construct its method.*
Boole's work in this area firmly established the point of view
that logic should use symbols and that algebraic properties
should be studied in logic. George Boole (1815-1864) taught Augustus De Morgan George Boole

*Quotedin VictorJ. Katz,A History of Mathematics, AnIntroduction, New York: HarperCollins, 1993, p. 619.

50
2.1 Propositions and Logical Operations 51

2.1 Propositions and Logical Operations


A statement or proposition is a declarative sentence that is either true or false,
but not both.

Example 1 Which of the following are statements?


(a) The earth is round.
(b) 2 + 3 = 5
(c) Do you speak English?
(d) 3 - x = 5
(e) Take two aspirins.
(f) The temperature on the surface of the planet Venus is 800° F.
(g) The sun will come out tomorrow.

Solution
(a) and (b) are statements that happen to be true.
(c) is a question, so it is not a statement.
(d) is a declarative sentence, but not a statement, since it is true or false de
pending on the value of x.
(e) is not a statement; it is a command.
(f) is a declarative sentence whose truth or falsity we do not know at this
time; however, we can in principle determine if it is true or false, so it is a
statement.

(g) is a statement since it is either true or false, but not both, although we
would have to wait until tomorrow to find out if it is true or false. ♦

Logical Connectives and Compound Statements


In mathematics, the letters x, y9 z,... often denote variables that can be replaced
by real numbers, and these variables can be combined with the familiar operations
+, x, -, and -r. In logic, the letters /?, #, r,... denote propositional variables;
that is, variables that can be replaced by statements. Thus we can write p: The
sun is shining today, q: It is cold. Statements or propositional variables can be
combined by logical connectives to obtain compound statements. For example,
we may combine the preceding statements by the connective and to form the com
pound statementp and q: The sun is shining today and it is cold. The truth value
of a compound statement depends only on the truth values of the statements being
combined and on the types of connectives being used. We shall look at the most
important connectives.
If p is a statement, the negation of p is the statement notp, denoted by ~p.
Thus ~/? is the statement "it is not the case that p." From this definition, it follows
that if p is true, then ^p is false, and if p is false, then ~p is true. The truth value
T F
of ~/? relative to p is given in Table 2.1. Such a table, giving the truth values
F T
of a compound statement in terms of its component parts, is called a truth table.
Strictly speaking, not is not a connective, since it does not join two statements, and
^p is not really a compound statement. However, not is a unary operation for the
collection of statements and ~p is a statement if p is.

Example 2 Give the negation of thefollowing statements:


(a) p: 2 + 3 > 1 (b) q: It is cold.
52 Chapter 2 Logic

Solution
(a) ~p: 2 + 3 is not greater than 1. That is, ~p: 2 + 3 < 1. Since p is true
in this case, ~p is false.
(b) ~g: It is not the case that it is cold. More simply, ^q: It is not cold. ♦

Bslil If p and q are statements, the conjunction of p and q is the compound state
lfei»8ss mmmms ment "p and q" denotedby p Aq. The connectiveandis denoted by the symbol A.
•JaJ&M sSMm: In the language of Section 1.6, and is a binary operation on the set of statements.
11811 lllllll The compound statement p Aq is true when both p and q are true; otherwise, it is
llllti Sllill false. The truthvalues of p Aq in terms of the truthvalues of p and q are given in
the truth table shown in Table 2.2. Observe that in giving the truth table of p A q
iBiiiil lllllll we need to look at four possible cases. This follows from the fact that each of p
slllii sisiii and q can be true or false.

Example 3 Form the conjunction ofp and q for each ofthe following.
(a) p: It is snowing. q: I am cold.
(b) p: 2 < 3 q: -5 > -8
(c) p: It is snowing. q: 3 < 5

Solution
(a) p A q: It is snowing and I am cold.
(b) p Aq: 2 < 3 and-5 > -8
(c) p A q: It is snowing and 3 < 5. ♦

Example 3(c) shows that in logic, unlike in everyday English, we may join
two totally unrelated statements by the connective and.
If p and q are statements, the disjunction of p and q is the compound state
ment "p or q," denoted by p v q. The connective or is denoted by the symbol v.
The compound statement p v q is true if at least one of p or q is true; it is false
whenboth p and q are false. The truthvalues of p v q are given in the truth table
shown in Table 2.3.

Example 4 Form the disjunction of p and q for each of the following.


(a) p: 2 is a positive integer q: V2 is a rational number.
(b) p: 2 + 3 ^ 5 q: London is the capital of France.
^S^Kl Solution
p ? Pv<i (a) p v q: 2 is a positive integer or*J2 is a rational number. Since p is true,
T T T the disjunction pvqis true, even though q is false.
T F T (b) p v #: 2 + 3 ^ 5 or London is the capital of France. Since both p and #
F TV T are false, pv q is false. ♦
F F F
Example 4(b) showsthat in logic, unlike in ordinary English, we may join two
totally unrelated statements by the connective or.
The connective or is more complicated than the connective and because it is
used in two different ways in English. Suppose that we say "I left for Spain on
Monday or I left for Spain on Friday." In this compound statement we have the
disjunction of the statements p: I left for Spain on Monday and q: I left for Spain
on Friday. Of course, exactly one of the two possibilities could have occurred.
Both could not have occurred, so the connective or is being used in an exclusive
sense. On the other hand, consider the disjunction "I passed mathematics or I failed
French." In this case, at least one of the two possibilities occurred. However, both
2.1 Propositions and Logical Operations 53

could have occurred, so the connective or is being used in an inclusive sense. In


mathematics and computer science we agree to use the connective or always in the
inclusive manner.
In general, a compound statement may have many component parts, each of
which is itself a statement, represented by some propositional variable. The state
ment s: p v (q A (p v r)) involves three propositions, p, q, and r, each of which
may independently be true or false. There are altogether 23 or 8 possible combi
nations of truth values for p, q, and r, and a truth table for s must give the truth
or falsity of s in all these cases. If a compound statement s contains n component
statements, there will need to be 2n rows in the truth table for s. (In Section 3.1
we look at how to count the possibilities in such cases.) Such a truth table may be
systematically constructed in the following way.
Step 1 The firstn columnsof the table are labeled by the componentpropositional
variables. Further columns are included for all intermediate combinations
of the variables, culminating in a column for the full statement.
Step 2 Under each of the first n headings, we list the 2n possible rc-tuples of truth
values for the n component statements.
Step 3 For each of the remaining columns, we compute, in sequence, the remain
ing truth values.

Example 5 Make a truth table forthe statement (p Aq)v (~p).

Solution
p 1 pAq V ~p
Because two propositions are involved, the truth table will have 22 or 4 rows. In
T T T T F
the first two columns we list all possible pairs of truth values for p and q. The
T F F , F F
numbers below the remaining columns show the order in which the columns were
, F- T . • F. , T T filled. ♦
' F ' ,uF> . --F-- ' T T

(1) (3) (2)


Quantifiers

In Section 1.1, we defined sets by specifying a property P(x) that elements of the
set have in common. Thus, an element of {x | P(jc)} is an object t for which the
statement P(f) is true. Such a sentence P(x) is called a predicate, because in
English the property is grammatically a predicate. P(x) is also called a propo
sitional function, because each choice of x produces a proposition P(x) that is
either true or false. Another use of predicates is in programming. Two common
constructions are "if P(jc), then execute certain steps" and "while QOO, do speci
fied actions." The predicates P(x) and Q(jc) are called the guards for the block of
programming code. Often the guard for a block is a conjunction or disjunction.

Example 6 Let A = {x \ x is an integer less than 8}. Here P(jc) is the sentence "x is an
integer less than 8." The common property is "is an integer less than 8." P(l) is
the statement "1 is an integer < 8." Since P(l) is true, 1 e A. ♦

Example 7 (a) Consider thefollowing program fragment,


1. IF N < 10 THEN
a. Replace N with N + 1
b. RETURN

Here the statement N < 10 is the guard.


54 Chapter 2 Logic

(b) Consider the following program fragment,

1. WHILE t e T and s G S
a. PRINT t + s
b. RETURN

Here the compound statement t e T and s e S is the guard. ♦

The universal quantification of a predicate P(jc) is the statement "For all


values of x, P(x) is true." We assume here that only values of jc that make sense in
P(x) are considered. The universal quantification of P(jc) is denoted Vjc P(jc). The
symbol Vis called the universal quantifier.

Example 8 (a) The sentence P(x): -(-x) = x is a predicate that makes sense for real num
bers x. The universal quantification of P(jc), Vjc P(jc), is a true statement,
because for all real numbers, —(-jc) = jc.
(b) Let Q(x): x + 1 < 4. Then Vx Q(jc) is a false statement, because Q(5) is not
true. ♦

Universal quantification can also be stated in English as "for every jc," "every
x," or "for any x."
A predicate may contain several variables. Universal quantification may be
applied to each of the variables. For example, a commutative property can be
expressed as Vjc Vj x • y = y • x. The order in which the universal quantifiers
are considered does not change the truth value. Often mathematical statements
contain implied universal quantifications (for example in Theorem 1, Section 1.2).
In some situations we only require that there be at least one value for which the
predicate is true. The existential quantification of a predicate P(jc) is the state
ment"Thereexists a value of x for which P(jc) is true." The existential quantifica
tionof P(x) is denoted 3x P(x). The symbol 3 is calledthe existential quantifier.

Example 9 (a) Let Q(x): x + 1 < 4. The existential quantification ofQ(jc), 3jc Q(jc), is a true
statement, because Q(2) is a true statement,
(b) The statement 3y y + 2 = y is false. There is no value of y for which the
propositional function y + 2 = y produces a true statement. ♦

In English 3x can also be read "there is an jc," "there is some jc," "there exists
an * " or "there is at least one jc " Occasionally a variation of a universal or exis
tentialquantifier is useful. The possiblevaluesof the variablemay be restrictedas
in the following examples. The statement Vjc e A P(jc) represents "for all jc in the
set A, P(jc) is true," and the statement 3k > n Q(k) represents "there is a A: greater
than or equal to n such that Q(k) is true."

Example 10 (a) Let D be the setofnxn diagonal matrices. Consider the statement 3M g D
suchthatM_1 does notexist. Todetermine if this statement is trueor false, we
must decide if there is an n x n diagonal matrix that does not have an inverse.
(b) For the statement Vrc > 6, 2n > 2n, only integers greater than or equal to 6
need to be tested. ♦

Existential quantification may be applied to several variables in a predicate


and the order in which the quantifications are considered does not affect the truth
value. For a predicate with several variables we may apply both universal and
existential quantification. In this case the order does matter.
2.1 Propositions and Logical Operations 55

Example 11 LetA and Bbenxn matrices.


(a) The statement VA 3B A + B = I;| is read "for every A there is a B such
that A+ B = I„." For a given A = [ ai} ], define B = [ by ] as follows:
bu = 1- an, 1< i < nand bu = -au, i^j,l<i<n,\<j< n. Then
A + B = ln and we have shown that VA 3B A + B = In is a true statement.
(b) 3B VA A + B = I„ is the statement "there is a B such that for all A, A + B =
I„." This statement is false; no single B has this property for all A's.
(c) 3B VA A + B = A is true. What is the value for B that makes the statement
true? ♦

Let p: Vjc P(jc). The negation of p is false when p is true, and true when p
is false. For p to be false there must be at least one value of x for which P(x) is
false. Thus, p is false if 3jc ~P(jc) is true. On the other hand, if 3x HP(*) is false,
then for every jc, ~P(jc) is false; that is, Vx P(x) is true.

Example 12 (a) Letp: For all positive integers n,n2 + 4ln + 41 is a prime number. Then ~/?
isThere isatleast one positive integer n for which n2 + 4ln + 41 is not prime.
(b) Let q: There is some integer k for which 12 = 3k. Then —q\ For all integers
k, 12 + 3k. ♦

Example 13 Let p: Theempty set is a subset of any set A. For p to be false, there must be an
element of 0 that is not in A, but this is impossible. Thus, p is true. ♦

2.1 Exercises
1. Which of the following are statements? (b) 2 > 3 and 3 is a positive integer.
(a) Is 2 a positive number? (c) 2 < 3 and 3 is not a positive integer.
(b) jc2+jc + 1 =0 (d) 2 > 3 and 3 is not a positive integer.
(c) Study logic. 7. Determine the truth or falsity of each of the following
(d) There will be snow in January. statements.

(e) If stock prices fall, then I will lose money. (a) 2 < 3 or 3 is a positive integer.
2. Give the negation of each of the following statements. (b) 2 > 3 or 3 is a positive integer.
(a) 2 + 7 < 11 (c) 2 < 3 or 3 is not a positive integer.
(b) 2 is an even integer and 8 is an odd integer. (d) 2 > 3 or 3 is not a positive integer.
3. Give the negation of each of the following statements.
In Exercises8 and 9,find the truth value of eachproposition if
(a) It will rain tomorrow or it will snow tomorrow. p and r are true and q isfalse.
(b) If you drive, then I will walk.
8. (a) ^p A ^q (b) (~p v q) A r
4. In each of the following, form the conjunction and the
disjunction of p and q. (c) pv qv r (d) ~(p V q) A r
(a) p: 3 + 1 <5 f 7 = 3x6 9. (a) ^PA(qV r) (b) p a (~(q v ~r))
(b) p: I am rich. q: I am happy. (c) (rA^)v(pVr) (d) (qAr)A(pV^r)
5. In each of the following, form the conjunction and the
10. Which of the following statements is the negation of the
disjunction of p and q.
statement "2 is even and —3 is negative"?
(a) p: I will drive my car. q: I will be late.
(a) 2 is even and —3 is not negative.
(b) p: NUM > 10 q: NUM < 15
(b) 2 is odd and —3 is not negative.
6. Determine the truth or falsity of each of the following
statements.
(c) 2 is even or —3 is not negative.
(a) 2 < 3 and 3 is a positive integer. (d) 2 is odd or —3 is not negative.
56 Chapter 2 Logic
11. Which of the following statements is the negation of the 21. IfQ(n): w + 3 = 6,then
statement "2 is even or —3 is negative"? (a) Q(5) is the statement
(a) 2 is even or —3 is not negative. (b) Q(m) is the statement
(b) 2 is odd or -3 is not negative. 22. lfP(y): 1 + 2 + • • • + y = 0, then
(c) 2 is even and —3 is not negative. (a) P( 1) is the statement
(d) 2 is odd and -3 is not negative. (b) P(5) is the statement
In Exercises12 and 13, use p: Today is Monday; q: Thegrass (c) P(k) is the statement
is wet; and r: Thedish ran away with the spoon. 23. IfQ(w):m < 3"1, then
12. Writeeach of the following in terms of /?,q, r, and logical (a) Q(0) is the statement
connectives.
(b) Q(2) is the statement
(a) Today is Monday and the dish did not run away with (c) Q(k) is the statement
the spoon.
24. Give a symbolic statement of the commutative property
(b) Either the grass is wet or today is Monday.
for addition of real numbers using appropriate quantifiers.
(c) Today is not Monday and the grass is dry.
25. Give a symbolic statement of De Morgan's laws for sets
(d) The dish ran away with the spoon, but the grass is using appropriate quantifiers.
wet.
26. Give a symbolic statement of the multiplicative inverse
13. Write an English sentence that corresponds to each of the property for real numbers using appropriate quantifiers.
following.
In Exercises 27 through 30, make a truth table for the state
(a) ~r A q (b) ~# v r
ment.
(c) ~(/?V#) (d) pv~r
27. (~/? A q) V p 28. (pVq)V ^q
In Exercises 14 through 19, use P(jc): x is even; Q(x): x is a
29. (pVq)Ar 30. (^pVq)A^r
prime number; R(x, y): x + y is even. The variables x and y
represent integers. For Exercises31 through 33, define p I q to be a true state
ment if neither p nor q is true.
14. Write an English sentence corresponding to each of the
following.
(a) Vjc P(jc) (b) 3jc Q(jc) p q p\q
15. Write an English sentence corresponding to each of the T T F~
following. T F F
(a) Vx3y R(x, y) (b) 3x Vy R(x, y) FT F
16. Write an English sentence corresponding to each of the F F T
following.
(a) Wx (~Q(*)) (b) By (HPO0) 31. Make a truth table for (p | q) 4, r.
17. Write an English sentence corresponding to each of the 32. Make a truth table for (p | q) a (p 4, r).
following. 33. Make a truth table for (p | q) \ (/? 4, r).
(a) ~(3x P(jc)) (b) -(Vjc Q(jc))
ForExercises 34 through 36, define p A q to be true if eitherp
18. Write each of the following in terms of P(jc), Q(x), or q, butnot both, is true. Make a truth tablefor thestatement.
R(x, y), logical connectives, and quantifiers.
(a) Every integer is an odd integer. 34. (a) p Aq (b) p A ~p

(b) The sum of any two integers is an even number. 35. (p A q) A p


(c) There are no even prime numbers. 36. (p A q) A (q A r)
(d) Every integer is even or a prime. In Exercises 37 through 40, revisionofthe given programming
19. Determine the truth value of each statement given in Ex block is needed. Replace the guard P(jc) with ^P(jc).
ercises 14 through 18. 37. IF (jc 7^max and y > 4) THEN take action
20. IfP(jc):jc2 < 12, then 38. WHILE (key = "open" or t < limit) take action
(a) P(4) is the statement 39. WHILE (item ^ sought and index < 101) take action
(b) P(1.5) is the statement 40. IF (cell > 0 or found) THEN take action
2.2 Conditional Statements 57

2.2 Conditional Statements


If p and q are statements, the compound statement "if p then g," denoted
p => 9, is called a conditional statement, or implication. The statement p is
called the antecedent or hypothesis, and the statement q is called the consequent
or conclusion. The connective if... then is denoted by the symbol =».

Example 1 Form the implication p q for each of the following.


(a) p: I am hungry. q: I will eat.
(b) p: It is snowing. 4: 3 + 5 = 8.

Solution
(a) If I am hungry, then I will eat.
(b) If it is snowing, then 3 + 5 = 8. ♦

Example 1(b) shows that in logic we use conditional statements in a more


general sense than is customary. Thus in English, when we say "if p then q" we
are tacitly assuming there is a cause-and-effect relationship between p and q. That
is, we would never use the statement in Example 1(b) in ordinary English, since
there is no way statement p can have any effect on statement q.
In logic, implication is used in a much weaker sense. To say the compound
statement p => q is true simply asserts that if p is true, then q will also be found to
be true. In other words, p => q says only that we will not have p true and q false
TABLE 2.4 at the same time. It does not say that p "caused" q in the usual sense. Table 2.4
describes the truth values of p => q in terms of the truth of p and q. Notice that
p q p=*q p => q is considered false only if p is true and q is false. In particular, if p is false,
T T T then p => q is true for any q. This fact is sometimes described by the statement
T F F
"A false hypothesis implies any conclusion." This statement is misleading, since
it seems to say that if the hypothesis is false, the conclusion must be true, an
F T T
obviously silly statement. Similarly, if q is true, then p => q will be true for any
F F T
statement p. The implication "If 2 + 2 = 5, then I am the king of England" is true,
simply because p: 2 + 2 = 5 is false, so it is not the case that p is true and q is
false simultaneously.
In the English language, and in mathematics, each of the following expres
sions is an equivalent form of the conditional statement p => q: p implies q\ q,
if p; p only if q\ p is a sufficient condition for q\ q is a necessary condition for p.
If p =$> q is an implication, then the converse of p => q is the implication
q => p9 and the contrapositive of p => q is the implication ~g => ~p.

Example 2 Give the converse and the contrapositive of the implication "If it is raining, then I
get wet."

Solution
We have p: It is raining; and q: I get wet. The converse is q => p: If I get wet,
then it is raining. The contrapositive is ^q => ~p: If I do not get wet, then it is
TABLE 2.5 not raining. ♦

p q POq If p and q are statements, the compound statement p if and only if q, denoted
T T T by p O q, is called an equivalence or biconditional. The connective if and only
T F F
if is denoted by the symbol <&. The truth values of p <& q are given in Table 2.5.
Observe that p <fr q is true only when both p and q are true or when both p and
F T F
q are false. The equivalence p O q can also be stated as p is a necessary and
F F T
sufficient condition for q.
58 Chapter 2 Logic

Example 3 Is the following equivalence a true statement? 3 > 2 if and only if 0 < 3 —2.
Solution
Let p be the statement 3 > 2 and let q be the statement 0 < 3 - 2. Since both p
and q are true, we conclude that p 4> q is true.

Example 4 Compute the truth table of the statement (p => q) <& (~# 'P)-
Solution
The following table is constructed using steps 1, 2, and 3 as given in Section 2.1.
The numbers below the columns show the order in which they were constructed.

p q p=>q ~q -/? ~q =£ ~p (p=>q) & (~q=*~p)


T T T F F T T

T F i F T F F T

F T i' T F T T T

F F T T T T T

(1) (2) (3) (4) (5)

A statement that is true for all possible values of its propositional variables is
called a tautology. A statement that is always false is called a contradiction or an
absurdity, and a statement that can be either true or false, depending on the truth
values of its propositional variables, is called a contingency.

Example 5 (a) The statement in Example 4 is a tautology.


(b) The statement p A ~p is an absurdity. (Verify this.)
(c) The statement (p => q) A (p v q) is a contingency. ♦

We have now defined a new mathematical structure with two binary operations
and one unary operation, (propositions, A, v, ~). It makes no sense to say two
propositions are equal; instead we say p and q are logically equivalent, or simply
equivalent, if p o q is a tautology. When an equivalence is shown to be a
tautology, this means its two component parts are always either both true or both
false, for any values of the propositional variables. Thus the two sides are simply
different ways of making the same statement and can be regarded as "equal." We
denote that p is equivalent to q by p = q. Now we can adapt our properties for
operations to say this structure has a property if using equivalent in place of equal
gives a true statement.

Example 6 The binary operation v has the commutative property; that is, p v q = q v p. The
truth table for (pVq)O(qV p) shows the statement is a tautology.

p q pVq qvp (pVq) & (qvp)


T T T T T

T F T T T
F T T T T

F F F F T

Another way to use a truth table to determine if two statements are equivalent
is to construct a column for each statement and compare these to see if they are
identical. In Example 6 the third and fourth columns are identical, and this will
guarantee that the statements they represent are equivalent.
2.2 Conditional Statements 59

Forming p => q from p and q is another binary operation for statements, but
we can express it in terms of the operations in Section 2.1.

Example 7 The conditional statement p =>> q is equivalent to (~p) v q. Columns 1 and 3 in


the following table show that for any truth values of p and q, p => q and (~p) v q
have the same truth values.

r^p {~p)s/q
p q p=>q

T T T F T

T F F F F
F T T T T
F F T T T

(1) (2) (3)

The structure (propositions, A, v, ~) has many of the same properties as the


structure (sets, U, n, "*).

THEOREM 1 The operations for propositions havethe following properties.


Commutative Properties
1. p V q = q V p
2. p Aq = q /\p
Associative Properties
3. pV (qVr) = (pVq)Vr
4. p A (q A r) = (p A q) A r
Distributive Properties
5. p V (q A r) = (p V q) A (p V r)
6. p A(qV r) = (p Aq)V (p Ar)
Idempotent Properties
1. pvp = p
8. p a p = p
Properties ofNegation
9. ~(~p) = p
10. ~(p V q) = (~p) A (~#) Properties 10 and 11
11. ~(p Aq) = (~p) V (~#) are De Morgan's laws.

Proof
We have proved Property 1 in Example 6. The remaining properties may be proved
the same way and are left for the reader as exercises. •

Truth tables can be used to prove statements about propositions, because in a


truth table all possible cases are examined.
The implication operation also has a number of important properties.

THEOREM 2 (a) (p =• q) = ((~p) V q)


(b) (p => q) = (^q =)• ~p)
(c) (p <& q) = ((p => q) A (q => p))
(d) ~(p 4 ^ ( p A ~#)
(e) -(p 4> #) = ((p A ~#) V (<? A ~p))
60 Chapter 2 Logic

Proof
(a) was proved in Example 7 and (b) was proved in Example 4. Notice that
(b) says a conditional statement is equivalent to its contrapositive.
(d) gives an alternate version for the negation of a conditional statement. This
could be proved using truth tables, but it can also be proved by using
previously proven facts. Since (p =>> q) = ((~p) v #), the negation
of p =*• q must be equivalent to ~((~p) V q). By De Morgan's laws,
~((~P) V?)s (~(~p)) A(~4) or p A(~q). Thus, ~(p => q) =
(p A ~#).
The remaining parts of Theorem 2 are left as exercises. •

Theorem 3 states two results from Section 2.1, and several other properties for
the universal and existential quantifiers.

THEOREM 3 (a) ~(Vjc P(jc)) = 3x ~P(x)


(b) ~(3jc P(jc)) = Vjc (~P(jc))
(c) 3x (P(jc) => Q(jc)) = Vjc P(jc) =* 3jc Q(jc)
(d) 3jc (P(jc) v Q(jc)) = 3jc P(jc) v 3jc Q(jc)
(e) Vjc (P(jc) A Q(jc)) = Vjc P(jc) A Vjc Q(jc)
(f) ((Vjc P(jc)) v (Vjc Q(jc))) => Vjc (P(jc) v Q(jc)) is a tautology.
(g) 3jc (P(x) a Q(jc)) =» 3jc P(jc) a 3jc Q(x) is a tautology. •
The following theorem gives several important tautologies that are implica
tions. These are used extensively in proving results in mathematics and computer
science and we will illustrate them in Section 2.3.

THEOREM 4 Each of the following is a tautology,


(a) (pA^)=>p (b) (pAq)^q
(c) p^(pvq) (d) q=>(pvq)
(e) ~p=>(p=>q) (f) ^(P^q)^p
(g) (pA(p=*q))=>q (h) (~p A (p V q)) : *<7
(i) (r-qA(p=>q))=*"xp (I) ((P=*?)A(0 = r)) => (p r)

2.2 Exercises

In Exercises 1 and 2, use thefollowing: p. I am awake; q: I (c) I do not work hard only if I am awake and I do not
workhard; r: I dream ofhome. dream of home.

1. Write each of the following statements in terms of p, q, (d) Not being awake and dreaming of home is sufficient
r, and logical connectives. for me to work hard.

(a) I am awake implies that I work hard. State the converse of each of the following implications.

(b) I dream of home only if I am awake. (a) If 2 + 2 = 4, then I am not the Queen of England.
(b) If I am not President of the United Sates, then I will
(c) Working hard is sufficient for me to be awake. walk to work.
(d) Being awake is necessary for me not to dream of (c) If I am late, then I did not take the train to work.
home.
(d) If I have time and I am not too tired, then I will go to
2. Write each of the following statements in terms of p, q, the store.
r, and logical connectives.
(e) If I have enough money, then I will buy a car and I
(a) I am not awake if and only if I dream of home. will buy a house.
(b) If I dream of home, then I am awake and I work hard. State the contrapositive of each implication in Exercise 3.
2.2 Conditional Statements 61

5. Determine the tmth value for each of the following state 17. Fill the grid so that each row, column, and marked 2x2
ments. square contains the letters M, A, T, H, with no repeats.
(a) If 2 is even, then New York has a large population. (a) mA I I I (b) T
(b) If 2 is even, then New York has a small population.
M A
(c) If 2 is odd, then New York has a large population.
T M M
(d) If 2 is odd, then New York has a small population.

In Exercises 6 and 7, let p, q, and r be the following state H H

ments', p: I will study discrete structure; q: I will go to a


movie; r: lamina good mood.

6. Write the following statements in terms of p, q, r, and 18. Fill the grid so that each row, column, and marked 2x3
logical connectives. block contains 1,2, 3,4,5,6, with no repeats.
(a) If I am not in a good mood, then I will go to a movie. (a) 4 3
(b) I will not go to a movie and I will study discrete
structures. 2 3

(c) I will go to a movie only if I will not study discrete


1 6 5
structures.

6 1 5
(d) If I will not study discrete structures, then I am not in
a good mood. 6 5
7. Write English sentences corresponding to the following
4 1
statements.

(a) ((~p) A q) => r (b) r =* (p v q)


(c) (~r) => {{~q V p) (d) (q A (~p)) & r
(b)
1 6 2 3
In Exercises 8 and 9, let p, q, r, and s be thefollowing state
ments: p: 4 > 1; q: 4 < 5; r: 3 < 3; s: 2 > 2. 2 1

8. Write the following statements in terms of p, q, r, and 5 1 6


logical connectives.
3
(a) Either 4 > 1 or 4 < 5.
4 5 2
(b) If3<3,then2>2.
(c) It is not the case that 2 > 2 or 4 > 1. 6 4

9. Write English sentences corresponding to the following


statements.

(a) (p A s) => q (b) ~(r A q) (c) (~r) => p


19. Fill the grid so that each row, column, and marked 3x3
In Exercises 10 through 12, construct truthtables to determine block contains 1, 2, 3,4, 5, 6, 7, 8, 9, with no repeats.
whether the given statement is a tautology, a contingency, or
an absurdity.
6 9 3 1
10. (a) p A ^p (b) q V {~-q A p)
11. (a) p=>(q=> p) (b) q => (q => p) 1 2 8 7 6

12. (a) (qAp)v(qA^p) 3 4 6 5 8

(b) (PAq)=>p (c) p =* (q A p)


6 2 8 1 4 9 5
13. If p =$ q is false, can you determine the tmth value of
3 7
(~(p Aq)) =$ ql Explain your answer.
14. If p => q is false, can you determine the tmth value of 5 9 4 1
(~p) v (p O q)7 Explain your answer.
6 3
15. If p =$> q is true, can you determine the tmth value of
(p a q) =» ~#? Explain your answer. 1 7 5

16. If p => q is tme, can you determine the tmth value of 4 9 3 2 1


~(p =>> g) a ~p? Explain your answer.
62 Chapter 2 Logic

20. Fill the grid so that each row, column, and marked 3x3 (a) Jack did not eat fat, but he did eat broccoli.
block contains 1, 2, 3,4, 5, 6, 7, 8, 9, with no repeats. (b) Mary lost her lamb or the wolf ate the lamb.
(c) If Tom stole a pie and ran away, then the three pigs
4 7
do not have any supper.
9 1 5 26. Consider the following conditional statement:
6 1 7 4 8 9 p: If the flood destroys my house or the fire
destroys my house, then my insurance company
4 1 7 9
will pay me.
9 8 2 3 4 (a) Which of the following is the converse of p?
4 5 2
(b) Which of the following is the contrapositive of p?
(i) If my insurance company pays me, then the
8 2 6 1 5
flood destroys my house or the fire destroys my
9 7 house.
(ii) If my insurance company pays me, then the
5 2 6
flood destroys my house and the fire destroys my
house.
/h Exercises 21 and 22, find the truth value of each statement (iii) If my insurance company does not pay me, then
if p and q are trueand r, s, and t arefalse. the flood does not destroy my house or the fire
21. (a) ~(p =» q) (b) (~p) => r does not destroy my house,
(iv) If my insurance company does not pay me, then
(c) (p => 5-) A (s => 0 (d) t => -#
the flood does not destroy my house and the fire
22. (a) {~q) =>(r^(r^(pV s))) does not destroy my house.
(b) p^(r=>q)
27. Prove Theorem 1 part 6.
(c) (# =* (r =* *)) A ((p =^ s) => (~0)
28. Prove Theorem 1 part 11.
(d) (r A s A t) =*• (p v 4)
29. Prove Theorem 2 part (e).
23. Use the definition of p | q given for Exercise 31 in Sec
30. Prove Theorem 3 part (d).
tion 2.1 and show that ((p | p) I (q i q)) is equivalent
to p A#. 31. Prove Theorem 3 part (e).
24. Write the negation of each of the following in good En 32. Prove Theorem 4 part (a).
glish. 33. Prove Theorem 4 part (d).
(a) The weather is bad and I will not go to work. 34. Prove Theorem 4 part (g).
(b) If Carol is not sick, then if she goes to the picnic, she 35. Prove Theorem 4 part (j).
will have a good time. 36. Explain why proving part (e) of Theorem 4 provides a
(c) I will not win the game or I will not enter the contest. one-line proof of part (f) of Theorem 4.
25. Write the negation of each of the following in good En 37. Explain why proving part (a) of Theorem 4 provides a
glish. one-line proof of part (b) of Theorem 4.

2.3 Methods of Proof

Some methods of proof we have already used are direct proofs using generic ele
ments, definitions, and previously proven facts, and proofs by cases, such as ex
amining all possible truth value situations in a truth table. Here we look at proofs
in more detail.
If an implication p =*• q is a tautology, where p and q may be compound
statements involving any number of propositional variables, we say that q logically
follows from p. Suppose that an implication of the form (p\ Ap2 a •••a pn) => q
is a tautology. Then this implication is true regardless of the truth values of any of
its components. In this case, we say that q logically follows from pupi,...,pn.
2.3 Methods of Proof 63

When q logically follows from pi, P2,..., pn, we write

P\
Pi

Pn
.'. q

where the symbol .*. means therefore. This means if we know that p\ is true, P2 is
true,..., and pn is true, then we know q is true.
Virtually all mathematical theorems are composed of implications of the type

(pi Ap2 A--- Apn) =>q.

The p/'s are called the hypotheses or premises, and q is called the conclusion.
To "prove the theorem" means to show that the implication is a tautology. Note
that we are not trying to show that q (the conclusion) is true, but only that q will
be true if all the p/ are true. For this reason, mathematical proofs often begin with
the statement "suppose that pi, P2,..., and pn are true" and conclude with the
statement "therefore, q is true." The proof does not show that q is true, but simply
shows if the p/ are all true, then q has to be true.
Arguments based on tautologies represent universally correct methods of rea
soning. Their validity depends only on the form of the statements involved and not
on the truth values of the variables they contain. Such arguments are called rules
of inference. The various steps in a mathematical proof of a theorem must follow
from the use of various rules of inference, and a mathematical proof of a theorem
must begin with the hypotheses, proceed through various steps, each justified by
some rule of inference, and arrive at the conclusion.

Example 1 According to Theorem 4(j) of the last section, ((p =» q) a (q =^ r)) => (p => r)
is a tautology. Thus the argument

p=>q
q^r
:. p=>r

is universally valid, and so is a rule of inference. ♦

Example 2 Is thefollowing argument valid?


If you invest in the stock market, then you will get rich.
If you get rich, thenyou will be happy.
.-. If you invest in the stock market, then you will be happy.

Solution
The argument is of the form given in Example 1, hence the argument is valid,
although the conclusion may be false. ♦

Example 3 The tautology (p <& q) O ((p =*• q) a (q =^ p)) is Theorem 2(c), Section 2.2.
Thus both of the following arguments are valid.

p^q
poq q=> P
(p^q)A(q^ p) p^q
64 Chapter 2 Logic

Some mathematical theorems are equivalences; that is, they are of the form
p O q. They are usually stated p if and only if q. By Example 3, the proof of
such a theorem is logically equivalent with proving both p => q and q =>• p, and
this is almost always the way in which equivalences are proved. We wish to show
that both p =$ q and q =>> p are true. To do so, we first assume that p is true, and
show that q must then be true; next we assume that q is true and show that p must
then be true.
A very important rule of inference is

P
p^q
:. q.

That is, p is true, and p =» q is true, so q is true. This follows from Theorem 4(g),
Section 2.2.
Some rules of inference were given Latin names by classical scholars. Theo
rem 4(g) is referred to as modus ponens, or loosely, the method of asserting.

Example 4 Is the following argument valid?


Smoking is healthy.
If smoking is healthy, then cigarettes are prescribed by physicians.
.-. Cigarettes are prescribed by physicians.

Solution
The argument is valid since it is of the form modus ponens. However, the conclu
sion is false. Observe that the first premise p: smoking is healthy is false. The
second premise p =>» q is then true and (p A (p =>• q)), the conjunction of the two
premises, is false. ♦

Example 5 Is the following argument valid?


If taxes are lowered, then income rises.
Income rises.
.-. Taxes are lowered.

Solution
Let p: taxes are lowered and q: income rises. Then the argument is of the form
p=*q
q

Assume that p => q and q are both true. Now p => q may be true with p
being false. Then the conclusion p is false. Hence the argument is not valid.
Another approach to answering this question is to verify whether the statement
((P =^ q) A?) logically implies the statement p. A truth table shows this is not
the case. (Verify this.) ♦

An important proof technique, which is an example of an indirect method of


proof, follows from the tautology (p =» q) <& ((~q) => (~p)). This states, as we
previously mentioned, that an implication is equivalent to its contrapositive. Thus
to prove p => q indirectly, we assume q is false (the statement ~q) and show that
p is then false (the statement ~p).

Example 6 Letn be an integer. Prove that if n2 is odd, then n is odd.


2.3 Methods of Proof 65

Solution
Let p: n2 is odd and q: n is odd. We have to prove that p =>• q is true. Instead,
we prove the contrapositive ~# =^ ~p. Thus suppose that n is not odd, so that
n is even. Then n = 2fc, where k is an integer. We have n2 = (2fc)2 = 4k2 =
2(2k2), so a2 is even. We thus show that if n is even, then n2 is even, which is the
contrapositive of the given statement. Hence the given statement has been proved.

Another important indirect proof technique is proof by contradiction. This


method is based on the tautology ((p => q) A (~#)) =>> (~p). Thus the rule of
inference
p=>q

:. ~p

is valid. Informally, this states that if a statement p implies a false statement q9


then p must be false. This is often applied to the case where q is an absurdity
or contradiction, that is, a statement that is always false. An example is given by
taking q as the contradiction r A (~r). Thus any statement that implies a contra
diction must be false. In order to use proof by contradiction, suppose we wish to
show that a statement q logically follows from statements pi, p2,..., p„. Assume
that ~# is true (that is, q is false) as an extra hypothesis, and that pi, p2,..., pn
are also true. If this enlarged hypothesis p\ A p2 A • • • a p„ A (~q) implies a
contradiction, then at least one of the statements p\, p2,..., pn, ^q must be false.
This means that if all the p/'s are true, then ~q must be false, so q must be true.
Thus q follows from pi, p2,..., p„. This is proof by contradiction.

Example 7 Prove there is no rational number p/q whose square is 2. In other words, show
42 is irrational.

Solution
This statement is a good candidate for proof by contradiction, because we could
not check all possiblerational numbersto demonstrate that none had a square equal
to 2. Assume (p/q)2 = 2 for some integers p and q, which have no common
factors. If the originalchoice of p/q is not in lowest terms, we can replace it with
its equivalent lowest-term form. Then p2 = 2q29 so p2 is even. This implies p is
even, since the square of an odd number is odd. Thus, p = 2n for some integer
n. We see that 2q2 = p2 = (2n)2 = An2, so q2 = 2w2. Thus q2 is even, and so
q is even. We now have that both p and q are even, and therefore have a common
factor 2. This is a contradiction to the assumption. Thus the assumption must be
false. ♦

We have presented several rules of inference and logical equivalences that cor
respond to valid proof techniques. In order to prove a theorem of the (typical) form
(p\ A P2 A • • • A pn) ==> q, we begin with the hypothesis p\, p2,..., pn and show
that some result r\ logically follows. Then, using pi, P2,..., p«, n, we show that
some other statement r2 logically follows. We continue this process, producing in
termediate statements r\, r2,..., r*, called steps in the proof, until we can finally
show that the conclusion q logically follows from pi, p2,..., pw, n, r2,..., r*.
Each logical step must be justified by some valid proof technique, based on the
rules of inference we have developed, or on some other rules that come from
tautological implications we have not discussed. At any stage, we can replace
a statement that needs to be derived by its contrapositive statement, or any other
equivalent form.
66 Chapter 2 Logic

In practice, the construction of proofs is an art and must be learned in part


from observation and experience. The choice of intermediate steps and methods
of deriving them is a creative activity that cannot be precisely described. But a few
simple techniques are applicable to a wide variety of settings. We will focus on
these techniques throughout the book. The "Tips for Proofs" notes at the end of
each chapter highlight the methods most useful for that chapter's material.
Example 8 Letmand n be integers. Prove that n2 = m2 if and only if n is m or n is —m.
Solution
Let us analyze the proofas we present it. Suppose p is the statement n2 = m2, q
is the statement n is m, and r is the statement n is —m. Then we wish to prove the
theorem p <& (q v r). We know from previous discussion that we may instead
prove s: p => (q v r) and t: (q v r) => p are true. First, we assume that either
q: n is m or r: n is —m is true. If q is true, then n2 = m2, and if r is true, then
n2 = (—m)2 = m2, so in either case p is true. We have therefore shown that the
implication t: (qVr)=>pis true.
Now we must prove that s: p =* (q v r) is true; that is, we assume p and
try to prove either q or r. If p is true, then n2 = m2, so n2 —m2 = 0. But
n2 —m2 = (n-m)(n+m). If n is the intermediate statement (n —m)(n+m) = 0,
we have shownp =>> n is true. Wenow show that r\ => (qvr) is true, by showing
that the contrapositive ~(q Vr)^ (~r0 is true. Now ~(q v r) is equivalent to
(~q) A (~r), so we show that (yq) A (~r) =>- (~n). Thus, if (r*q): n is not
m and (~r): n is not -m are true, then (n —m) ^ 0 and (n + m) ^ 0, so
(n —m)(n + m) ^ 0 and n is false. We have therefore shown that r\ => (q v r)
is true. Finally, from the truth of p =» n and n=^(jvr), we can conclude that
p => (# v r) is true, and we are done. ♦

We do not usually analyze proofs in this detailed manner. We have done so


only to illustrate that proofs are devised by piecing together equivalences and valid
steps resulting from rules of inference. The amount of detail given in a proof
depends on who the reader is likely to be.
As a final remark, we remind the reader that many mathematical theorems
actually mean that the statementis true for all objects of a certain type. Sometimes
this is not evident. Thus the theorem in Example8 really states that for all integers
m and n, n2 = m2 if and only if n is mor n is —m. Similarly, the statement "Ifx
and y are real numbers, and x ^ y, then x < y or y < jc" is a statement about all
real numbersx and y. To prove such a theorem, we must make sure that the steps
in the proof are valid for every real number. We could not assume, for example,
that x is 2, or that y is n or >/3. This is why proofs often begin by selecting a
generic element, denoted by a variable. On the other hand, we know from Section
2.2 that the negation of a statement of the form Vjc P(x) is 3x ~P(jc), so we need
only find a single example where the statement is false to disprove it.
Example 9 Prove or disprove the statement that if x and y are real numbers, (jc2 = y2) &
(x = y).

Solution
The statement can be restated in the form Vjc Vj R(jc, y). Thus, to prove this result,
we would need to provide steps, each of which would be true for all jc and y. To
disprove the result, we need only find one example for which the implication is
false.
Since (-3)2 = 32, but —3 ^ 3, the result is false. Our example is called a
counterexample, and any other counterexample would do just as well. ♦
2.3 Methods of Proof 67

In summary, if a statement claims that a property holds for all objects of a


certain type, then to prove it, we must use steps that are valid for all objects of that
type and that do not make references to any particular object. To disprove such a
statement, we need only show one counterexample, that is, one particular object
or set of objects for which the claim fails.

2.3 Exercises

In Exercises 1 through 11, state whether the argument given is 10. (a) pVq (b) p=>q
valid or not. If it is valid, identify the tautology or tautologies -p
on which it is based. .'. p .*. ~q

1. If I drive to work, then I will arrive tired. n. Write each argument in Exercise 10 as a single compound
I am not tired when I arrive at work. statement.

.-. I do not drive to work. 12. (a) (p => q) A (q =» r) (b) ~(p =» q)


(~g) A r p
2. If I drive to work, then I will arrive tired.
.'. P .\ ~q
I arrive at work tired.
.-. I drive to work. 13. Write each argument in Exercise 12 as a single compound
statement.
3. If I drive to work, then I will arrive tired.
14. Prove that the sum of two even numbers is even.
I do not drive to work.
.•. I will not arrive tired. 15. Prove that the sum of two odd numbers is even.

16. Prove that the structure (even integers, +, *) is closed with


4. If I drive to work, then I will arrive tired.
respect to *.
I drive to work.
.*. I will arrive tired. 17. Prove that the structure (odd integers, +, *) is closed with
respect to *.
5. I will become famous or I will not become a
18. Provethat n2 is even if and only if n is even.
writer.
I will become a writer. 19. Prove that A = B if and only if A c B and B c A.
.-. I will become famous. 20. Let A and B be subsets ofa universal set U. Prove that
A c B if and only if B c A.
6. I will become famous or I will be a writer.
I will not be a writer. 21. Show that
.*. I will become famous. (a) A c B is a necessary and sufficient condition for
AUB = B.
7. If I try hard and I have talent, then I will
become a musician. (b) A c B is a necessary and sufficient condition for
If I become a musician, then I will be happy. AHB = A.
.-. If I will not be happy, then I did not try hard or 22. Show that k is odd is a necessary and sufficient condition
I do not have talent. for k3 to be odd.

8. If I graduate this semester, then I will have 23. Prove or disprove: «2-f41rc+41isa prime number for
passed the physics course. every integer n.
If I do not study physics for 10 hours a week, 24. Prove or disprove: The sum of any five consecutive inte
then I will not pass physics. gers is divisible by 5.
If I study physics for 10 hours a week, then I
25. Prove or disprove that 3 | (n3 —n) for every positive inte
cannot play volleyball.
ger n.
.-. If I play volleyball, I will not graduate this
semester. 26. Prove or disprove: 1 + 2n > 3", for all n e Z+.
27. Determine if the following is a valid argument. Explain
9. If my plumbing plans do not meet the
your conclusion.
construction code, then I cannot build my
house. Prove: Vx x3 > x2.
If I hire a licensed contractor, then my Proof: Vjc jc2 > 0 so Vjc jc2(jc - 1) > 0(jc - 1) and
plumbing plans will meet the construction Vjc jc3 —x2 > 0. Hence Vx x3 > x2.
code.
I hire a licensed contractor. 28. Determine if the following is a valid argument. Explain
.-. I can build my house. your conclusion.
68 Chapter 2 Logic

Prove: If A and B are matrices such that AB = 0, then 30. Determine if the following is a valid argument. Explain
either A = 0 or B = 0. your conclusion.
Proof: There are two cases to consider: A = 0 or
Prove: If x is an irrational number, then 1 —x is also an
A^O. If A = 0, then we are done. If A ^ 0, then
irrational number.
A"1(AB) = A"J0 and (A"1A)B = 0 and B = 0.
Proof: Suppose 1 —x is rational. Then we can write
29. Determine if the following is a valid argument. Explain a a

your conclusion. 1 —x as -, with a,b e Z. Now we have 1 = x and


b b
Let m and n be two relatively prime integers. Prove that b-a
x = —-—, a rational number. This is a contradiction.
if mn is a cube, then m and n are each cubes. b
Hence, if x is irrational, so is 1 —x.
Proof: We first note that in the factorization of any cube
into prime factors, each prime must have an exponent that 31. Prove that the sum of two prime numbers, each larger than
is a multiple of 3. Write m and n each as a product of 2, is not a prime number.
primes; m= p"1 p£2 •••pakk and n = q\' q%2 •••qJ. Sup 32. Prove that if two lines are each perpendicular to a third
pose m is not a cube. Then at least one a, is not a multiple line in the plane, then the two lines are parallel.
of 3. Since each prime factor of mn must have an expo
33. Prove that if x is a rational number and y is an irrational
nent that isa multiple of3, nmust have a factor pf' such number, then x + y is an irrational number.
that hi t^ 0 and a{ + _>, is a multiple of 3. But this means
that m and n share a factor, p,. This contradicts the fact 34. Prove that if 2y is an irrational number, then y is an irra
that m and n are relatively prime. tional number.

2.4 Mathematical Induction


Here we discuss another proof technique. Suppose the statement to be proved can
be put in the form Vn > no P(n), where no is some fixed integer. That is, suppose
we wish to show that P(n) is true for all integers n > n0. The following result
shows how this can be done. Suppose that (a) P(n0) is true and (b) If P(k) is true
for some k > n0, then P(k + 1) must also be true. Then P(n) is true for all n > no.
This result is called the principle of mathematical induction. Thus to prove the
truth of a statement Vn > no P(n), using the principle of mathematical induction,
we must begin by proving directly that the first proposition P(n0) is true. This is
called the basis step of the induction and is generally very easy.
Then we must prove that P(k) => P(k + 1) is a tautology for any choice of
k > n0. Since the only case where an implication is false is if the antecedent is
true and the consequent is false, this step is usually done by showing that if P(ifc)
were true, then P(k + 1) would also have to be true. Note that this is not the same
as assuming that P(k) is true for some value ofk. This step is called the induction
step, and some work will usuallybe required to show that the implication is always
true.

Example 1 Show, by mathematical induction, thatfor all n > 1,


i.o.qj.
1+2 + 3H
.hn =
n(n + l) .

Solution
n(n + 1)
Let P(n) be the predicate 1+ 2 + 3 H \-n = . In this example, n0 = 1.

Basis Step
We must first show that P(l) is true. P(l) is the statement
1(1 + 1)
1 =
2 '
which is clearly true.
2.4 Mathematical Induction 69

Induction Step
We must now show that for k > 1, if P(k) is true, then P(k + 1) must also be true.
We assume that for some fixed k > 1,

k(k + 1)
1 + 2 + 3 + • • •+k = (1)

We now wish to show the truth of P(fc + 1):

(*+l)((* + l) + l)
1 + 2 + 3H h(*+l) =

The left-hand side of P(k + 1) can be written as 1 + 2 + 3 -\ h k + (k + 1) and


we have

(1+2 + 3 + -.- + *) + (*+l)

*(Jfc + 1)
+ (k + 1) using (1) to replace 1 + 2 + • • • + k
2

= (*+l)
!♦' factoring

(*+!)(*+ 2)

(fc+l)((* + l) + l)
the right-hand side of P(A: + 1)

Thus, we have shown the left-hand side of P(k +1) equals the right-hand side of
P(k + 1). By the principle of mathematical induction, it follows that P(n) is true
foralln>l. ♦

Example 2 Let A\, A2, A3,..., An be any n sets. We show by mathematical induction that

LH=n^-
v=i 1=1

(This is an extended version of one of De Morgan's laws.) Let P(n) be the pred
icate that the equality holds for any n sets. We prove by mathematical induction
that for all n > 1, P(n) is true.

Basis Step
P(l) is the statement A\ = Ai, which is obviously true.
70 Chapter 2 Logic
Induction Step
We use P(Jfc) to show P(k + 1). The left-hand side of P(jk + 1) is

A+i
\jAi) =A,UA2U...U^UAH1
v=i

= (A i U A2 U • • • U Ak) U A*+i associative property of U

= (Ai U A2 U • • • U Ak) H A*+i by De Morgan's law for two sets

=(p|A;)nA^ using P(t)

=n^ right-hand side of P{k + 1)


i=l

Thus, the implication P(fc) =» P(& + 1) is a tautology, and by the principle of


mathematical induction P(n) is true for all n > 1. ♦

Example 3 We show by mathematical induction that any finite, nonempty set is countable;
that is, it can be arranged in a list.
Let P(n) be the predicate that if A is any set with \A\ = n > 1, then A is
countable. (See Chapter 1 for definitions.)

Basis Step
Here no is 1, so we let A be any set with one element, say A = {x}. In this case x
forms a sequence all by itself whose set is A, so P(l) is true.

Induction Step
We want to use the statement P(k) that if A is any set with k elements, then A is
countable. Now choose any set B with k + 1 elements and pick any element x
in B. Since B - {x} is a set with k elements, the induction hypothesis P(k) tells
us there is a sequence *i, *2» ••• >** with B —{x} as its corresponding set. The
sequence x\, X2,..., **, x then has B as the corresponding set so B is countable.
Since B can be any set with k + 1 elements, P(k + 1) is true if P(k) is. Thus, by
the principle of mathematical induction, P(n) is true for all n > 1. ♦

In proving results by induction, you should not start by assuming that P(k+1)
is true and attempting to manipulate this result until you arrive at a true statement.
This common mistake is always an incorrect use of the principle of mathematical
induction.
A natural connection exists between recursion and induction, because objects
that are recursively defined often use a natural sequence in their definition. Induc
tion is frequently the best, maybe the only, way to prove results about recursively
defined objects.

Example 4 Consider thefollowing recursive definition of thefactorial function: 1! = 1, n! =


n(n —1)!,n > 1. Suppose we wish to provefor all n > 1, n! > 2n~l. We proceed
by mathematical induction. Let P(n): n! > 2n~x. Here no is 1.

Basis Step
P(l) is the statement 1! > 2°. Since 1! is 1, this statement is true.
2.4 Mathematical Induction 71

Induction Step
We want to show P(k) => P(k + 1) is a tautology. It will be a tautology if P(k)
true guarantees P(k + 1) is true. Suppose k\ > 2k~x for some k > 1. Thenby the
recursive definition, the left side of P(k + 1) is

(* + l)! = (*+_)*!
> (k + l)2k~l using P(jfc)
> 2 x 2k~l k + 1 > 2, since k > 1
= 2* right-hand side of P(k+l)

Thus, P(k + 1) is true. By the principle of mathematical induction, it follows that


P(n) is true for all n > 1. ♦

The following example shows one way in which induction can be useful in
computer programming. The pseudocode used in this and following examples is
described in Appendix A.

Example 5 Consider the following function given in pseudocode.


FUNCTION SQ(A)
1. C <e- 0
2. D <e- 0
3. WHILE CD •£ A)
a. C <- C + A
b. D <r- D + 1
4. RETURN (C)
END OF FUNCTION SQ

The name of the function, SQ, suggests that it computes the square of A. Step
3b shows A must be a positive integer if the looping is to end. A few trials with
particular values of A will provide evidence that the function does carry out this
task. However, suppose we now want to prove that SQ always computes the square
of the positive integer A, no matter how large A might be. We shall give a proof
by mathematical induction. For each integer n > 0, let Cn and Dn be the values
of the variables C and D, respectively, after passing through the WHILE loop n
times. In particular, Co and Do represent the values of the variables before looping
starts. Let P(n) be the predicate Cn = A x Dn. We shall prove by induction that
Vn > 0 P(n) is true. Here no is 0.

Basis Step
P(0) is the statement Co = A x Do, which is true since the value of both C and D
is zero "after" zero passes through the WHILE loop.

Induction Step
We must now use

P(k):Ck = AxDk (2)

to show that P(k + 1): C*+i = A x D*+i. After a pass through the loop, C is
72 Chapter 2 Logic

increased by A, and D is increased by 1, so Ck+\ = Ck + A and D*+i = Dk + 1.

left-hand side of P(Jk + 1): C*+i = Q + A


= A x Dk + A using (2) to replace C*
= A x (Dk + 1) factoring
= A x D*+i right-hand side of
P(* + 1)

By the principle of mathematical induction, it follows that as long as looping oc


curs, Cn = A x Dn. The loop must terminate. (Why?) When the loop terminates,
D = A, so C = A x A, or A2, and this is the value returned by the function SQ.

Example 5 illustrates the use of a loop invariant, a relationship between vari


ables that persists throughall iterationsof the loop. This technique for proving that
loops and programs do what is claimed they do is an important part of the theory
of algorithm verification. In Example 5 it is clear that the looping stops if A is a
positive integer,but for more complex cases, this may also be proved by induction.

Example 6 Use the technique of Example 5 to prove that the pseudocode program given in
Section 1.4 does computethe greatest common divisor of two positive integers.

Solution
Here is the pseudocode given earlier.
FUNCTION GCD(X,Y)
1. WHILE (X ^ 10
a. IF (X > Y) THEN
1. X «- X - Y
b. ELSE
1. Y +- Y - X
2. RETURN (X)
END OF FUNCTION GCD

We claim that if X and Y are positive integers, then GCD returns GCD(X, Y). To
prove this, let Xn and Yn be the values of X and Y after n > 0 passes through
the WHILE loop. We claim that P(n): GCD(X„, Yn) = GCD(X, Y) is true for all
n > 0, and we prove this by mathematical induction. Here no is 0.

Basis Step
Xo = X, Fb = Y, since these are the values of the variables before looping begins;
thus P(0) is the statement GCD(X0, Y0) = GCD(X, Y), which is true.

Induction Step
Consider the left-hand side of P(jfc + 1), that is, GCD^+i, Yk+i). After the k+ 1
pass through the loop, either Xk+\ = Xk and l^+i = Yk —Xk or X*+i = Xk —Yk
and Yk+i = Yk. Then if P(*): GCD(X*, Yk) = GCD(X, Y) is true, we have, by
Theorem 5, Section 1.4, that GCD(X*+i, Yk+{) = GCD(Xk, Yk) = GCD(X, Y).
Thus, by the principle of mathematical induction, P(n) is true for all n > 0. The
exit condition for the loop is Xn = Yn and we have GCD(X„, Yn) = Xn. Hence
the function always returns the value GCD(X, Y). ♦
2.4 Mathematical Induction 73

A discussion of how to construct a loop invariant for a given loop would take
us too far from the main ideas of this section. In writing programs, loop invariant
construction usually precedes decisions about the steps to be executed in the loop.
In the exercises, loop invariants will be provided where needed.

Strong Induction
A slightly different form of mathematical induction is easier to use in some proofs.
In the strong form of mathematical induction, or strong induction, the induction
step is to show that

P(n0) A P(n0 + 1) A P(n0 + 2) A • • • A P(k) =• P(* + 1)

is a tautology. As before, the only case we need to check is that if each P(j),
j = no, ...,&, is true, then P(k + 1) is true. The strong form of induction is
equivalent to the form we first presented, so it is a matter of convenience which
one we use in a proof.

Example 7 Prove that every positive integer n > 1can be written uniquely as p\x p^2 •••pf,
where the pt are primes and p\ < pi < - • - < ps (Theorem 3, Section 1.4).

Proof (by strong induction)


Basis Step
Here no is 2. P(2) is clearly true, since 2 is prime.

Induction Step
We use P(2), P(3),..., P(k) to show P(k + 1): k + 1 can be written uniquely as
P\ Pi ''' Pass> where the pt are primes and p\ < pi < - - < Ps- There are
two cases to consider. If k + 1 is a prime, then P(k + 1) is true. If k + 1 is not
prime, then k + 1 = /m, 2 < / < k, 2 < m < k. Using P(/) and P(m), we have
k= Im = qx lq22 •••qbt'r\x r£2 •••rcuu = p"1 p^2 •••pass, where each pt —qj or rk,
Pi < Pi < ''' < Ps, and if qj = rk = /?/, then a\ —bj + c*, otherwise pt = qj
and a/ = bj or p-x = r^ and a/ = ck. Since the factorization of I and m are unique,
so is the factorization of k + 1. ♦

2.4 Exercises

In Exercises 1 through 7, prove the statement is true by using


mathematical induction.
8. LetP(n): 13 +23 +33 +..- +,3 =^^)2 +4.
(a) UseP(fc)toshowP(A: + l).
1. 2 + 4 + 6 + ••• + 2n = n(n + l)
(b) Is P(n) tme for all n > 1?
« ,9 .9 _9 ,* ,,, n(2n + l)(2n - 1)
2. I2 + 32 + 52 + •••+ (2n - l)2 = ~ ^ 9. LetP(n): 1 +5 + 9 + • • • + {An - 3) = (2#i + l)(/i - 1).
(a) Use P(fc) to show P(A: + 1).
3. 1 + 21 + 22 + • • • + 2" = 2n+x - 1
(b) Is P(n) true for all n > 1?
5n(n + 1)
4. 5 + 10+15 + -.. + 5n = 10. Prove 1 + 2n < 3" for n > 2.
11. Proven < 2W forn > 1.
^ 2 n(n + l)(2w + 1) (2#i + l)2
5. l2 + 22 + 32 + . • + >r =
12. Prove 1+2 + 3H \-n <
8
an - 1 13. Find the least n for which the statement is tme and then
6. 1 + a + a2 + + an
a- 1 provethat (1 +n2) < 2n.
«(1 -rn) 14. Find the least n for which the statement is tme and then
7. a + ar + ar2 H + arn~l = for r ^ 1 prove that lOn < 3n.
1
74 Chapter 2 Logic
15. Prove by mathematical induction that if a set A has n ele 24. (A, + A2 + •••+ An)T = A[ + AJ + •••+ ATn
ments, then P{A) has 2" elements. 25. A2A',=A2+n
16. Prove by mathematical induction that 3 | (n3 - n) for 26. Let A and B be square matrices. If AB = BA, then
every positive integer n. (AB)" = AnBnJorn> 1.
17. Prove by mathematical induction that if A\, A2,..., An 27. Prove that any restaurant bill of $n, n > 5, can be paid
are any n sets, then exactly using only $2 and $5 bills.
28. Prove that every integer greater than 27 can be written as
5a + 8_>, where a, b e Z+.
29. Use induction to show that if p is a prime and p \ a" for
18. Prove by mathematical induction that if /_i, A2, n > 1, then p \ a.
and B are any n + 1 sets, then 30. Prove that if GCD(a, b) = 1, then GCD(a\ bn) = 1 for
all n > 1. (Hint: Use Exercise 29.)
njA,.jpi_=Q(A,n_). 31. (a) Find the smallest positive integer no such that 2n° >
n\.
19. Prove by mathematical induction that if __i, A2, (b) Prove 2" > n2 for all n > n0.
and 2? are any n + 1 sets, then 32. Prove or disprove: 2 + 8 + 18 H \- 2n2 = n2 + n.
33. Prove or disprove: x —y divides xn —yn for n > 1.
pA/)|J_? =f|(A/U_?).
(M
20. Let P(n) be the statement 2 | (2n - 1).
In Exercises34 through 39, show thatthegiven algorithm, cor
rectlyused,produces the outputstated, by using mathematical
induction to prove the relationship indicated is a loop invari
(a) Prove that P(k) =*> P(£ + 1) is a tautology. ant and checking values when the looping stops. All variables
(b) Show that P(n) is not tme for any integer n. represent nonnegative integers.

(c) Do the results in (a) and (b) contradict the principle 34. SUBROUTINE COMP(X, Y\Z)
of mathematical induction? Explain. 1. Z <r- X
2. W <- Y
21. Let P(n) be the statement n2 + n is an odd number for
n eZ+. 3. WHILE CW > 0)
a. Z <- Z + Y
(a) Prove that P(k) =» P(k + 1) is a tautology. b. W <- W - 1
(b) Is P(n) tme for all nt Explain. 4. RETURN

22. Explain the flaw in the following "argument." END OF SUBROUTINE COMP
COMPUTES: Z = X + Y2
Forz#0,zn = l,n >0.
LOOP INVARIANT: (Y x HO + Z = X + y2
Proof: Basis Step: For n = 0, P(0): z" = 1 is tme by
definition. 35. SUBROUTINE DIFF (X, Y;Z)
1
Induction Step: z + = —r—r • z = - • 1 or 1. 1. Z 4r- X
zk~x 1 2. W <- Y
23. Explain the flaw in the following "argument." 3. WHILE CW > 0)
All trucks are the same color. a. Z <- Z - 1

Proof: Let P(n): Any set of n trucks consists of trucks of b. W <- W - 1

the same color. 4. RETURN

Basis Step: Certainly P(l) is tme, since there is only one END OF SUBROUTINE DIFF

truck in this case. COMPUTES: Z = X - Y

Induction Step: We use P(k): Any set of k trucks con LOOP INVARIANT: X - Z + W = Y
sists of trucks of the same color to show P(k +1): Any
36. SUBROUTINE EXP2 (AT,/*;JO
set of k + 1 trucks consists of trucks of the same color.
1. R <- 1
Choose one truck from the set of k + 1 trucks and con
2. K <- 2M
sider the remaining set of k trucks. By P(k) these are all
3. WHILE QK > 0)
the same color. Now return the chosen truck and set aside
a. R *- R x N
another truck. The remaining trucks are all the same color
b. K <- K - 1
by P(k). But trucks do not change color in this procedure,
4. RETURN
so all k + 1 trucks must be the same color.
END OF SUBROUTINE EXP2
In Exercises 24 through 26, prove the given statement about COMPUTES: R = N2M
matrices. Assume Ais n x n. LOOP INVARIANT: R x NK = N2M
2.5 Mathematical Statements 75

37. SUBROUTINE POWER (X, Y;Z) 1. R <- R - Y


1. Z <r- 0 2. K <r- K + 1
2. W ^ Y d. IF (i? = 0) THEN
3. WHILE (W > 0) 1. PRINT ('true')
a. Z +- Z + X e. ELSE
b. V «- W - 1 1. PRINT ('false1)
4. V <- Y - 1 3. RETURN
5. C7 <r- Z END OF SUBROUTINE DIV
6. WHILE (F/ > 0) COMPUTES: TRUTH VALUE OF Y \ X,
a. Z *- Z + U LOOP INVARIANT: R + K x Y = X
b. W <- W - 1
7. RETURN 39. SUBROUTINE SQS(X, Y;Z)
END OF SUBROUTINE POWER 1. Z ^ Y

COMPUTES: Z = X x Y2 2. W <- X

LOOP INVARIANT (first loop): 3. WHILE (W > 0)


X+(XxW0=XxY a. Z <- Z + X
LOOP INVARIANT (second loop): b. tf <- _/ - 1
X+(XxYxW)=XxY2 4. */ «- Y - 1

(Hint: Use the value of Z at the end of the first loop in 5. WHILE (W > 0)
loop 2.) a. Z «- Z + X
b. F/ <- W - 1
SUBROUTINE DIV(X, Y) 6. RETURN
1. IF (Y = 0) THEN END OF SUBROUTINE SQS
a. PRINT (' error Y = 0') COMPUTES: Z = X2 x Y2
2. ELSE LOOP INVARIANT (first loop):
a. i. <- X Z+(XxH0 = Y+X2
b. X <- 0 LOOP INVARIANT (second loop)
c. WHILE (JC > Y) Z+(YxH0=X2 + Y2

2.5 Mathematical Statements

The previous sections in this chapter lay the groundwork for learning to write
proofs. The examples and exercises give many mathematical statements for which
you are asked to write proofs. How are statements like this produced? Some of
the most common ways to create a statement that may be mathematically true are
from experience, by applying old ideas in new settings, by extending known facts
to more general cases, and by experimentation. A mathematical statement that has
not been proved or disproved yet is called a conjecture.

Example 1 (a) Young students soon notice thatadding twoodd numbers yields an even num
ber. A conjecture that captures this experience is "The sum of two odd num
bers is an even number."
(b) Suppose S is a set of objects and a binary operation < has been defined for
these objects. Then the truth of s < t = t < s9 s,t € S can be proved or
disproved to determine whether < is commutative.
(c) If A, B, and C aren x n matrices, the fact that (A+ B)T = AT + Br suggests
the conjecture that (A + B + C)T = Ar + BT + CT. ♦

Example 2 Produce a reasonable conjecture aboutthe sum of the powers of 2 beginning with
2°.
76 Chapter 2 Logic

Solution
We begin by experimenting with small cases and recording the results.

2U 1 1

2° + 2' 1+ 2 3

2° + 21 + 22 1+2 + 4 7

2° + 21 + 22+ 23 1+2+4+8 15

2° + 21 + 22 + 23 + 24 1+2 + 4 + 8+16 31

Note that each sum is one less than the next term to be added. (Recognizing
a pattern may take more experimentation than shown here.) Thus, a reasonable
conjecture is "The sum of the powers of 2 beginning with 2° is one less than the
next power of 2 to be added." This would be clearer in symbolic form. The sum
of an arbitrary number of powers of 2 beginning with 2° can be represented by
2° + 21 + •••+ 2n. The result is then 2"+1 - 1, one less than the next power of 2
to be added. 2U + 21 + • • • + 2n = 2;w+i 1 is given to be proved in Exercise 3,
Section 2.4.

Even when a mathematical statementis written in ordinary language, the proof


often needs a way to represent a generalcase. For example, a proof of the conjec
ture "The sum of two odd numbers is an even number" requires a way to represent
a generic odd number. One way to do this is with 2n + \. (What is another one?)
We need to identify what n can represent. If n is a whole number, then the original
conjecture becomes "The sum of two odd whole numbers is an even whole num
ber." If n is an integer, the statement becomes "The sum of two odd integers is an
even integer." Let us examine a proof of this last version. The conjecturerefers to
two odd integers, so we must represent another odd integer. This requires another
variable, say k. Now the two odd integers are represented as 2n + 1 and 2k + 1,
where both n and k are integers. Note that this description includes the case that
an odd integer is added to itself. Any even integer can be written as 2t, t e Z.

Example 3 The sum oftwo odd integers is an even integer.


Proof
Let 2n + 1 and 2k + 1 be two odd integers. Their sum is (2n + 1) + (2k + 1)
or 2n + 2k + 2. 2n + 2k + 2 = 2(n + k + 1). Since n + k + 1 is an integer,
(2n + 1) + (2k + 1) is an even integer. ♦

This proof assumes that the reader knows the distributive property and that the
sum of two integers is an integer. Depending on the audience for the proof, these
facts might have to be proved first or spelled out. Remember that here a proof
is a written communication, and the intended audience must be considered when
writing a proof.

Example 4 Let A, B, C, andD be n x n Boolean matrices. The fact that


A a (B v C) = (A a B) v (A a C)

suggests that the extended case

A A (B v C v D) = (A a B) v (A A C) v (A a D)

may be true.
2.5 Mathematical Statements 77

Often the key to proving an extension is to apply the original statement. Here
A A (B v C v D) = A A ((B v C) v D), because v is associative. The original
statement for three matrices implies that AA((BvC)vD) = (Aa(BvQ)v(AaD)
when we view (B A C) as a single matrix. Now using the original statement again,
we have

A A ((B v C) v D) = (A A (B v Q) v (A A D)
= ((A A B) v (A A C)) v (A A D)
= (A A B) v (A A C) v (A A D).

The last equality follows again from the fact that v is associative. ♦

Notice that in Example 4 we used more than the original statement to complete
the proof. Thus, we cannot expect that extension statements will always be true.
A variation of applying an old idea in a new setting is to identify a special
situation where a statement that is false in general will now be true. For example,
in general, matrix multiplication is not commutative, but for some special cases it
may be true that AB = BA.

Example 5 Let 5 be thesetof matrices of theform

a 0 0
0 0 0
0 0 b

where a, b e R. Prove that for the mathematical structure (5, matrix multiplica
tion) the commutative property holds.

Solution
We need to represent two generic elements of 5, and because we need to examine
the results of matrix multiplication, the entries of these generic elements need to
be shown. Let

c\ 0 0 dx 0 0
C = 0 0 0 and D = 0 0 0
0 0 c2 0 0 d2

(How do we know C and D are in 5?) Then

cidi 0 0 d\c\ 0 0
CD = 0 0 0 and DC = 0 0 0
0 0 c2d2 0 0 d2c2

Hence, CD = DC, because multiplication in R is commutative; c\d\ = d\C\


and C2^2 = ^2^2. As noted after Example 3, the intended audience for the proof
determines how much detail about R is included. ♦

There are many other ways to create conjectures than have been discussed
thus far. More of these are covered when we discuss more proof techniques in the
following chapters.
78 Chapter 2 Logic

2.5 Exercises

1. Prove or disprove that the cube of an even number is even. For Exercises 15 through 17, use the sequence 3, 9, 15, 21, 27,
2. Prove or disprove that the cube of an odd number is odd. 33,....

3. (a) Prove or disprove that the sum of three consecutive 15. Give both a recursive and an explicit formula for this se
integers is divisible by 3. quence.
(b) Prove or disprove that the sum of four consecutive 16. Experiment with the sums of the terms of the sequence to
integers is divisible by 4. produce a reasonable conjecture.
4. Prove that the product of a nonzero rational number and
17. Prove the conjecture from Exercise 16.
an irrational number is a(n) number.
5. Prove that the quotient of a nonzero rational number and 18. State and prove a reasonable conjecture about the sum of
an irrational number is a(n) number. the first n terms of the sequence 6, 10, 14, 18, 22,
State and prove the extension of A U B = A n B for three For Exercises 19 through 22, use the recursively defined se
sets. quence gX = 1, g2 = 3, g„ = g„_! + g„_2.
State and prove the extension of A O B = A U B for three 19. Write the first ten terms of the sequence.
sets.
20. Experiment with the sums of terms in the sequence that
8. Let A, B, C, and Dbenxn Boolean matrices. State and
occupy even-numbered positions to produce a reasonable
prove the extension of A v (B A C) = (A v B) A (A v C)
conjecture.
to four matrices.

9. Modify the conjecture and proof in Example 4 to give the 21. Experimentwith the sums of terms of the sequenceto pro
general case for m + 1 Boolean matrices. duce a reasonable conjecture about the sum of the first n
terms of the sequence.
10. Let p and q be propositions. State and prove an extension
of ~(/? v q) = ~/? a ~q to the case of 22. Experiment with the sums of terms in the sequence that
(a) 3 propositions (b) n propositions. occupy odd-numbered positions to produce a reasonable
conjecture.
11. Let p and q be propositions. State and prove an extension
of ~(p A q) = ~p V ~q to the case of 23. Prove the conjecture from Exercise 20.
(a) 3 propositions (b) n propositions. 24. Prove the conjecture from Exercise 21.
12. Prove that the commutative property holds for the mathe 25. Prove the conjecture from Exercise 22.
matical structure (3x3 diagonal matrices, matrix multi
plication). 26. Produceand prove a conjectureabout the sum of the pow
ers of 3 beginning with 3°.
13. Prove that the commutative property holds for the mathe
matical structure (r x r diagonal matrices, matrix multi 27. Build on the work done in Exercise 3 to produce a con
plication). jecture about when the sum of k consecutive integers is
divisible by k.
14. State and prove a conjecture about the sum of the first n
positive odd integers. 28. Prove the conjecture of Exercise 27.

2.6 Logic and Problem Solving


In previous sections, we investigated the use of logic to prove mathematical the
orems and to verify the correctness of computational algorithms. However, logic
is also valuable in less formal settings. Logic is used every day to decide between
alternatives and investigate consequences. It is, in many situations, essentially the
same as precise and careful thinking, particularly in cases where the details of
the situation are complex. One of the most important uses of logic is to develop
correct and efficient algorithms to solve problems. Part of this process may be to
express the solution in terms of a computation, even if the problem does not at
first seem computational. In Section 2.5, we noted that one common way to create
mathematical conjectures is to apply old ideas in new settings. This approach is
also a powerful problem-solving technique. To demonstrate these two ideas, we
present a variety of seemingly unrelated problems that can be solved by a single
method.
2.6 Logic and Problem Solving 79

We begin with an easily stated mathematical question. Given a set A and a


finite number of subsets of A, say A\, A2,..., A*, is it possible to find a collection
5 of the A; 's with the following two properties:
1. Any two sets in 5 are disjoint.
2. The union of all sets in 5 is A?

The collection S is called an exact cover of A with respect to the A,- 's, because
together the A;'s "cover" A with no overlaps.

Example 1 Let A = {a,b,c,d,e, f,g,h,i, j} and A\ = {a,c,d}, A2 = {a,b,e,f},


A3 = {b,f,g}, A4 = [d,h,i], A5 = {a,hj}, A6 = {,-,/z}, A7 = {c, /,;},
Ag = {/,./}. Is there an exact cover of A with respect to A\, A2, A3, A4, A5, A6,
A7, A8?

Solution
We start with Ai and consider each of the other sets in turn. We reject A2, since
A\ n A2 7^ 0, but A3 is suitable. Ai and A3 together contain the elements a, £>,
c, d, /, and g of A. The sets A4 and A5 contain d and _z respectively, and so they
are rejected. At this point we can see that Ae and Ag will complete the search, and
Ai, A3, Ae, Ag form an exact cover of A. ♦

If we did not find an exact cover that contained A\, we would have started
the search over with A2 as the first choice. This method would be continued until
either we found an exact cover or failed for each choice of a starting set. A system
atic way to try all possibilities, such as we just described, is a key step in writing
algorithms and computer programs to solve many types of problems involving
only a finite number of possible solutions. The technique is called backtracking,
and is an essential part of many algorithms that search all possible outcomes of a
process. This methodis a way of implementinga brute force search of possibilities
and will always produce a solution if one exists.

Example 2 Lett/ = {1,2,3,4,5,6,7,8,9,10} and let A! = {2,4,6,7}, A2 = {1,2,5},


A3 = {9,10}, A4 = {5, 8,1}, A5 = {1, 3, 5}. Find an exact cover of U with
respect to the given subsets.

Solution
A\ is not disjoint from A2, so A2 cannot be used. A\, A3, and A4 are a collection
of disjoint sets, but A4 has elements in common with A5, so A5 is eliminated.
However, A\ U A3 U A4 ^ A and we begin the search again with A2. A2 is only
disjoint from A3. Again, this is not enough for a cover; A2 U A3 ^ A. Continuing
to check, starting with A3, A4, and A5 in turn, we find there is no exact cover of A
with respect to these subsets. ♦

The exact cover problem can be restated in a way that leads to an algorithm
that can be implemented by a computer program. In Section 1.3, we show that if
U is a set with n elements, then each subset of U can be represented by a unique
sequence of 0's and l's of length n. We can use this representation to restate the
exact cover problem. If U is a set with n elements, and if S\, S2,..., S& are a finite
number of subsets of U, we form a matrix M whose rows correspond, in order, to
the representations of Si, S2, • • •» & as sequences of 0's and l's.

Example 3 Represent the subsets A\, A2,..., A8 of Example 1 by a matrix M.


80 Chapter 2 Logic

Solution
The set A of Example 1 has 10 elements. The eight subsets can be represented in
order by the rows of the following matrix

10 110 0 0 0 0 0
110 0 110 0 0 0
0 10 0 0 110 0 0
0 0 0 10 0 0 11
M =
10 0 0 0 0 0 1 0
0 0 0 0 10 0 1 0 0
0 0 10 0 0 0 0 1 1
00000000 1 1

We can now use M to find an exact cover of A with respect to Ai, A2, A3, A4,
A5, A6, A7, and Ag. Let

0 = [0 00000000 0]
and

1 = [1 111111111].
In matrix terms the problem becomes: Find a collection ri, r2,..., _•* of rows of
M having the following properties:
(a) r,- A Tj = 0 for 1 < /, j < k and
(b) r1vr2v.-vrJfc = l
It is easy to see that one solution is given by rows 1, 3, 6, and 8. This is the
solution found before.
Once it is reducedto searchinga Boolean matrix, the exact cover problem can
be more easily tackled with computer-implemented algorithms. The best-known
algorithmfor solvingthe exact cover problem is Donald Knuth's Algorithm X.

Algorithm ALGORITHM X
Label the rows of the original matrix A and retain these labels throughout the
application of the algorithm. Begin with M = A and L = { }.
Step 1 If M has a column of 0's, then there is no solution, since by definition the
rows representing an exact cover must together have 1's in every position.
Step 2 Otherwise:
(a) Choose the column c of M with the fewest 1's.
(b) Choose a row r with a 1 in column c, and place the number r in L.
(c) Eliminate any row Y\ having the property that r A ri ^ 0 (where 0
represents a row with all 0 entries).
(d) Eliminate all columns in which r has a 1.
(e) Eliminate row r.
(f) Let M be the resulting matrix and repeat steps 1 and 2. •

The logic behind (c) is that any such row 1*1 represents a subset that is not
disjoint from the subset of row r. The logic of (d) is that the deleted columns
record elements that are already in the subset of row r, and so cannot play any
further role in additional rows chosen.
2.6 Logic and Problem Solving 81

We repeat Steps 1 and 2 producing ever smaller matrices, choosing a row


each time and accumulating corresponding row labels from A, until the process
terminates. Let us call such a succession of choices and computations a path.
In general, there may be many paths to follow, since we may have several rows
available at each successive stage in the algorithm. A path is successful if the final
matrix produced is empty (has no rows or columns), in which case L will contain
the row labels of an exact cover. A path fails if the final matrix produced has a
column of 0's.
Note that if all paths that start with row r fail, there may still be a solution. In
this case, we remove r from L (and from any further consideration) and choose (if
possible) another row with a 1 in column c.

Example 4 Apply Algorithm X to find anexact cover for A = [a, b, c, d, e, /, g} with respect
to Ai = {a, £>, e}, A2 = {a, _>}, A3 = {a, e, /}, A4 = [d, f, g], A5 = {c, d, e, g],
A6 = {c, e).

Solution
The matrix A represents the original situation.
1 110 0 10 0
2 110 0 0 0 0
3 10 0 0 110
A =
4 0 0 0 10 11
5 0 0 1110 1
6 0 0 10 10 0

The rows of A have been numbered. Let M = A and L = { }.


Step 1 M does not have a column of zeros.
Step 2 The least number of l's in any column is 2, so we may choose the first
such column, column 2. We need to choose a row with a 1 in column 2,
say r = 1. Now L = {1}. We perform actions (c) through (e). Rows 2,
3, 5, and 6 are eliminated, since they each have a 1 in a common column
with the first row. We then eliminate columns 1, 2, and 5, and row 1. The
new matrix is what remains of row 4 of A.

[o 1 1
1]
Note. The original row label is still attached. However, this matrix has a
column of 0's, and so this path fails.
That means that we backtrack, removing row 1 from further consideration. So
L = 0 again, and we return to the original matrix A. Since row 1 failed to start a
successful path, we try row 2, the only other row to have a 1 in column 2. If this
also fails, then no solution is possible.
Perform Steps 1 and 2 on M, based on row 2. This first gives L — {2}, and the
following matrix:
4 0 10 11
5 1110 1
6 10 10 0

Column 4 of this matrix has the least number of l's, and the top row has a 1 in
column 4, so we choose to work with it. Since that row corresponds to row 4 of A,
we have L = {2,4}. Actions (c) through (e) on the new matrix, using its top row,
produce
6 [1 1].
82 Chapter 2 Logic

Now we can only choose the last remaining row and add 6 to L, so that
L = {2,4, 6}. Actions (c) through (e), applied to this matrix, eliminate all rows
and columns, so the path is successful, and an exact cover consists of rows 2, 4,
and 6 of A, as is easily verified. ♦

Many other problems and recreational puzzles are equivalent to the exact cover
problem.

Example 5 Figure 2.1(a) shows a 3 x 3 matrix with two positions filled.


1 • • " 1 2 3 1 2 3
• • 2 • • 2 3 1 2
• • • • • 1 2 • 1

(a) (b) (c)


Figure 2.1

Fill the remaining positions with 1,2, and 3, so that each row and each column
has exactly one 1, one 2, and one 3.

Solution
We reason as follows: Position (1, 3) must contain a 3, since there is already a 1
in the first row and a 2 in the third column, and duplicates are not permitted. The
rest of row 1 and column 3 must then be as shown in Figure 2.1(b).
Similar reasoning shows that position (2,1) can only contain a 3, and so row
2 and column 1 must be as shown in Figure 2.1(c). Finally, we see that position
(3, 2) must contain a 3, and we have found the unique solution. ♦

Example 6 Fill the remaining positions of Figure 2.2 with 1, 2, and 3, so that each row and
each column has exactly one 1, one 2, and one 3.

'1 • •
D • 2
• 2 •

Figure 2.2

Solution
As before, we reason that position (1, 3) must contain the number 3. However, this
forces position (1, 2) to contain a 2. On the other hand, this is impossible, since
there would then be two 2's in the second column. Thus we see that no solution is
possible. ♦

Consider again the puzzle given in Figure 2.1. Recall that we are trying to
put the digits 1, 2, and 3 in a 3 x 3 matrix so that each row and column contains
these digits exactly once. Suppose that we are free to choose nine digits, each of
which is either 1, 2, or 3 (without restrictions on the number of each), and place
them in the matrix at any location (where more than one number can occupy the
same location, and some locations can be empty). In order for such a placement
to constitute an allowable solution to the puzzle, three sets of constraints must be
true.

1. Each cell in the matrix must contain a digit. (9 constraints)


2. Each digit must occur in each column. (9 constraints)
2.6 Logic and Problem Solving 83

3. Each digit must occur in each row. (9 constraints)


Thus, there are 27 constraints in all.
With the complete freedom of placement described above, we could easily fill
the array so that any two of the three conditions were true, but the third was not,
even if we always had three of each number. Some cases are shown in Figure 2.3.

,2,3 • • 1 2 3 1 1 1
• 1,2,3 • 1 2 3 2 2 2
• • 1,2,3 1 2 3 3 3 3

Figure 2.3

Thus, we need all 27 constraints satisfied in order to have a solution. We now


construct a Boolean matrix A with 27 columns, one for each constraint. The first 9
columns of A represent respectively the constraints that the positions (1, 1), (1, 2),
(1, 3), (2,1), ..., (3, 3) contain one digit. The columns from 10 to 18 represent
respectively the constraints that (a 1 is in row 1), (a 1 is in row 2), ..., (a 3 is in
row 3). Finally, the columns from 19 to 27 represent respectively the constraints
that (a 1 is in column 1), (a 1 is in column 2),..., (a 3 is in column 3).
Let us say that a "move" is the placement of one of the digits 1, 2, 3 in a
particular location of A. Since there are three digits and nine cells, there are 27
moves. Hence, let matrix A have 27 rows, one for each possible move. The
rows of A contain 0's and 1's and are constructed in the following way. If a row
corresponds to putting a 2 in position (3, 1), then three constraints are satisfied—
there is a digit in position (3,1), there is a 2 in row 3, and there is a 2 in column 1.
We place l's in the columns of that row to correspond to these three constraints,
namely columns 7, 15, and 22, and place 0's elsewhere. Then the row of A that
corresponds to the placement of a 2 in position (3, 1) is

[0 0000010000000100000010000 0].
Each row of A corresponds to a move, thus satisfying three constraints: one
in the range 1-9, one in the range 10-18, and one in the range 19-27. It therefore
has exactly three l's in the positions corresponding to satisfied constraints. Thus,
the row

[0 0000100000000001000000000 1]
corresponds to placing a 3 in position (2, 3).

Example 7 (a) Give therow of A for themove thatplaces a 1 in position (2, 2).
(b) Describe the move represented by this row of A:

[0 1000000000010000000001000 0].

Solution
(a) [0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0]
(b) The move consists of placing a 2 in the position (1,2). ♦

If we now solve the exact cover problem for a set represented by A, then the
rows in the solution correspond to placements that are a legitimate solution to the
84 Chapter 2 Logic
puzzle, since each constraint is satisfied in exactly one way. If there is an initial
placement of digits, then the corresponding rows must belong to the solution. The
solution to the puzzle shown in Figure 2.1(a) is then represented by the following
matrix.

10000000010000000010000000 0'
010000000000100000000010000
001000000000000100000000001
00010000 0000000010000000100
000010000010000000010000000
000001000000010000000001000
000000100000001000000100000
000000010000000001000000010
000000001001000000001000000

Rows 1 and 6 correspond to the initial placement of digits.

Sudoku

A generalization of the simple puzzle shown in Example 5 is one of the most


popular puzzles of recent times, Sudoku. We begin with a simplified version of
Sudoku shown in Figure 2.4(a). It has 16 small squares, organized into 4 larger
2x2 squares, outlined more thickly.

1 4 1 4 12 3 1 3 4
1 4 2 3

1 1 4
2 3 2 3 2 3 1 4

1 3 1
4 2 4 2 3 1 4 2

1 3 4 1 2 4 1 3 1 3
4 2 3 1

(a) (b) (c)

Figure 2.4

The goal of the puzzle is to fill the grid with 1, 2, 3, and 4 in such a way
that each row, each column, and each of the outlined 2x2 squares will contain
these numbers exactly once. Often there is an initial assignment, as shown in
Figure 2.4(a).
The main hand techniques for solving a Sudoku puzzle are variations of what
may be described as "guess and check the consequences." The ideas are similar in
nature to those for Example 1, but may involve more complex logical deductions.
We could, for example, temporarily place in each cell all the numbers that might
go there; that is, numbers not obviously ruled out by the initial placements. Thus
in cell (1,1), the top left cell, we would place 1 and 4, since both 2 and 3 are else
where in the top left large block. The resulting matrix is shown in Figure 2.4(b).
Then we test these possible choices by investigating the logical consequences, as
we did in the simpler 3x3 version.
In Figure 2.4(b) we see that positions (2, 3) and (3, 2) can only contain 1. Hav
ing used 1's in columns 2 and 3, we see that positions (1,2) and (4, 3) must contain
4 and 3 respectively. In turn, we deduce that positions (1,1) and (4,4) must con
tain l's to fill in the top left and bottom right 2x2 squares. We continue this
2.6 Logic and Problem Solving 85

logical progression and find the solution shown in Figure 2.4(c). Sometimes we
have to make an arbitrary choice in some positions, and follow its consequences.
Occasionally this results in a contradiction, and we must then make an alternative
choice and start over.
The most common Sudoku puzzle consists of a 9 x 9 grid divided into 9 larger
3x3 grids, as shown in Figure 2.5. You must make each row, each column, and
each larger grid contain the numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9 exactly once.
Solutions are found by methods similar to, but often more complex than, those
used above.
Sudoku-type puzzles can be reduced to the exact cover problem in ways sim
ilar to how the 3 x 3 case was handled. In general, the following constraints must
be satisfied:

(a) Each cell in the matrix must contain a digit.


(b) Each digit must occur in each column.
(c) Each digit must occur in each row.
Figure 2.5 (d) Each digit must occur in certain submatrices.
For the 4 x 4 case, this gives a total of 64 constraints (16 for each category of
constraint). There are also 64 possible moves (putting any of 4 digits into any of
16 cells), and so the Boolean matrix corresponding to this problem is 64 x 64.
In the more common 9x9 Sudoku case, the corresponding matrix has 729 rows
and 324 columns. (See Exercises 13 and 14.) In spite of these large sizes of these
matrices, computer implementations of solution algorithms easily handle them.
Dozens of other types of puzzles reduce by similar methods to the exact cover
problem, and so can be solved by computers implementing Knuth's Algorithm X
in various ways. For example, the eight-queens puzzle is the problem of putting
eight chess queens on an 8 x 8 chessboard such that none of them is able to cap
ture any other using the standard chess queen's moves. One solution is shown in
Figure 2.6, and there are 91 others.
Pentominoes are figures formed from 5 squares connected on one or more
edges. There are 12 pentominoes, which are shown in Figure 2.7 with the standard
letters used to identify them. A popular problem is to arrange sets of pentominoes
Figure 2.6 into rectangular or other shaped figures. Two cases are shown in Figures 2.8 and
2.9.

V Y

u L N F L
X
Z I

F W
p I0
U T

Figure 2.7 Figure 2.8 Figure 2.9

Both the eight-queens puzzle and the pentominoes problems reduce to the ex
act cover problem, and so can be solved by any algorithm that solves this problem.
86 Chapter 2 Logic

A computer implementation of Algorithm X involves data structures such as


trees and linked lists to facilitate searching and backtracking. We define such
structures later in the text. One of the most efficient and interesting ways to do
this implementation is shown in Donald Knuth's "Dancing Links" paper. The
interested reader should consult this paper for details and other applications of
the exact cover problem. Because of the many applications of this algorithm, the
underlying problem is often referred to as the open cover problem.
Although this section has focused on one family of related problems, the tech
nique of reducing a problemto one that has already been solved is widely used. In
later sections some of these cases are pointed out.

2.6 Exercises

1. Find an exact cover for A = {1,2, 3,4,5,6,7, 8,9,10} 15. (a) Name the columns where 1's appear for the move of
with respect to Ax = {1,2,5}, A2 = {3,5,8,9}, placing a 4 in position (5,7).
A3 = {1,8,10}, A4 = {4,7,10}, A5 = {3,7}, and (b) Name the columns where 1's appear for the move of
A6 = {1,2,6}. placing a 6 in the upper left comer of the block in the
2. Find an exact cover for B = {a, b, c, d, e, f g, h, i] center of the grid.
with respect to Bx = {a,6, d,/*}, B2 = {c, /, /}, 16. (a) Name the columns where 1's appear for the move of
2?3 = {a, e, /}, B4 = {e, g], and B5 = {a, g, h}. placing a 2 in position (3,8).
3. Represent the subsets of A in Exercise 1 in a matrix. (b) Name the columns where 1's appear for the move of
4. Represent the subsets of B in Exercise 2 in a matrix. placing an 8 in the center position of the block in the
center of the bottom row of the grid.
5. Apply Algorithm X to the sets in Exercise 1 to produce an
exact cover of A. 17. Suppose the problem is to cover a 5 x 6 rectangle us
ing some of the twelve pentominoes of Figure 2.7 exactly
6. Apply Algorithm X to the sets in Exercise 2 to produce an once each.
exact cover of B.
(a) What constitutes a move in this situation?
In Exercises 7 through 10, consider the problem offilling a (b) Name the columns needed for the Boolean matrix for
3x3 matrix with the digits 1, 2, and 3, so that each digit this problem.
appears exactly once in each row and each column.
18. Use the results of Exercise 17 to give a matrix that de
7. Give the row for the move that places a 3 in position scribes the solution shown in Figure 2.10.
(1,1).
I
8. Give the row for the move that places a 2 in position
F
(2,3).
X U
9. Give the row for the move that places a 1 in position
(3,2). F
L
10. Give the row for the move that places a 3 in position
(1,3). Figure 2.10
11. For the 4 x 4 Sudoku case, give an example that shows Thefour tiles shown in Figure 2.11 are used in Exercises 19
that the 4th category of constraints is necessary. through 28. In this situation, tiles may not be flipped or ro
12. Describe a method for labeling the columns correspond tated when used to cover a given figure. For example, tile U
ing to the 4th category of constraints in the 4 x 4 Sudoku will always have its dot in the upposition.
case.
•_ _
Exercises 13 through 16 refer to the 9 x 9 Sudoku case.
13. (a) Describe the required categories of constraints.
(b) How many columns are needed in each category of Figure 2.11
constraints?
19. If each tile is used exactly once, then only rectangles that
(c) Give a description of column names that correspond are by can be covered.
to the categories given in part (a).
20. Draw two figures that are not rectangles but are composed
14. Explain why there need to be 729 rows in the initial of squares and can be covered by using the four tiles ex
Boolean matrix. actly once.
Key Ideas for Review 87

21. (a) How many ways can tile D be placed in rectangle A? 25. Give a matrix that records the initial placement shown in
(b) How many ways can tile L be placed in rectangle A? Figure 2.12. Include the column names.

E __
3
Figure 2.12
26. Give a matrix that records the initial placement shown in
Figure 2.13. Include the column names.
22. (a) How many ways can tile U be placed in rectangle 2??
_ •
(b) How many ways can tile R be placed in rectangle Bl

Figure 2.13
23. Using tiles U, D, R, L exactly once each and rectangle A, 27. Figure 2.12 cannot be covered with U, D, R, L. Use Al
what information is required to define a move? gorithm X to prove this.
24. Using tiles U, D, R, L exactly once each and rectangle Z?, 28. Figure 2.13 can be covered in two different ways using U,
what information is required to define a move? D, R, L exactly once each. Use Algorithm X to prove this.

Tips for Proofs


This chapter provides the formal basis for our proofs, although most proofs are
not so formal as the patterns given in Section 2.3. Two new types of proofs are
presented: indirect proofs and induction proofs. Indirect proofs are based either on
the pattern (p =» q) A ~q (proof by contradiction) or on the fact that (p => q) =
(~g =>. ~p) (prove the contrapositive). There are no hard and fast rules about
when to use a direct or indirect proof. One strategy is to proceed optimistically
with a direct proof. If that does not lead to anything useful, you may be able to
identify a counterexampleif the statement is in fact false or start a new proof based
on one of the indirect models. Where the difficulty occurs in the attempted direct
proof can often point the way to go next. Remember that a certain amount of
creativity is required for any proof.
Conjectures that are good candidates for proof by induction are ones that in
volve the counting of whole numbers in some way, either to count something or to
describe a pattern. Examples of these are in Section 2.4, Exercises 11 and 15. No
tice that for most of the induction proofs in Section 2.4, P(k) is used early and then
properties of operations and arithmetic are used, but in proving loop invariants, the
"arithmetic" comes first, then the use of P(&).
In proving conjectures about propositions, try to use the properties of logical
operations (see Section 2.2, Theorem 1 for some of these). Building truth tables
should be your second-choice strategy. The proof of a conjecture that is the exten
sion of a known fact usually requires the application of the original fact.

Key Ideas for Review


• Statement: declarative sentence that is either tme or false, two or more statements by a logical connective
but not both
Logical connectives: not (~), and (a), or (v), if then (=»),
• Propositional variable: letter denoting a statement if and only if (<3>)
• Compound statement: statement obtained by combining Conjunction: p A q (p and q)
88 Chapter 2 Logic
• Disjunction: p V q (p or q) • Methods of proof:
• Predicate (propositional function): a sentence of the form q logically follows from p: see page 62
Pto Rules of inference: see page 63
• Universal quantification: Vx ?(x) [For all values of x, P(x) Modus ponens: see page 64
is tme.] Indirect method: see page 64
• Existential quantification: 3x P(x) [There exists an x such Proof by contradiction: see page 65
that P(jc) is true.] • Counterexample: single instance that disproves a theorem
• Conditional statement or implication: p =>• q (if p then q)\ or proposition
p is the antecedent or hypothesis and q is the consequent or • Principle of mathematical induction: Let rc0 be a fixed inte
conclusion ger. Suppose that for each integer n > n0 we have a propo
• Converse of p =$> q: q ==» p sition P(n). Suppose that (a) P(n0) is tme and (b) If P(fc),
• Contrapositive of p =$ q: ~q => ^p then P(k + 1) is a tautology for every k > n0. Then the
principle of mathematical induction states that P(w) is tme
• Equivalence: p O q
for all n >n0.
• Tautology: a statement that is tme for all possible values of
• Loop invariant: a statement that is tme before and after ev
its propositional variables
ery pass through a programming loop
• Absurdity: a statement that is false for all possible values of
• Strong form of mathematical induction: see page 73
its propositional variables
• Contingency: a statement that may be tme or false, depend • Conjecture: a mathematical statement that has not been
proved or disproved
ing on the tmth values of its propositional variables
• p = q (Logically equivalent statements p and q): p <& q is • Exact cover: see page 79
a tautology • Algorithm X: see page 80

• Chapter 2 Self-Test
1. Why is it important to recognize the converse and the con 11. Give the tmth value of each proposition in Problem 9.
trapositive of a conditional statement?
12. The English word "or" is sometimes used in the exclusive
2. How does the strong form of induction differ from basic sense meaning that either p or q, but not both, is tme.
mathematical induction? Make a tmth table for this exclusive or, xor.
3. What mathematical stmcture previously studied has the 13. Let p: An Internet business is cheaper to start, q: I will
same properties as (logical statements, v, a, ~)? start an Internet business, and r: An Internet business
4. How does an indirect proof technique differ from a direct makes less money. For each of the following write the
proof? argument in English sentences and also determine the va
5. What is the stmcture of a proof by contradiction? lidity of the argument.
6. Determine the truth value of the given statements if p is (a) r =>(q =» p) (b) p => q
tme and q is false. ^p q => r
:. (~r) v (~q) p
(a) ~p A q (b) ~/7 v ~#
.*. r
7. Determine the tmth value for each of the following state 14. Suppose that m and n are integers such that n \ m and
ments. Assume x, y e Z.
m | n. Are these hypotheses sufficient to prove that
(a) Vx, y x + y is even. m = nl If so, give a proof. If not, supply a simple addi
(b) 3xVy x + y is even. tional hypothesis that will guarantee m = n and provide a
8. Make a tmth table for (p A ~p) v (~(q a r)). proof.
15. Prove or disprove by giving a counterexample that the
ForProblems9 through 11, let p: 1 < -1, q: |2| = |-2|,
sum of any three consecutive odd integers is divisible
r: —3 < —1, ands: 1 < 3.
by 6.
9. Write the symbolic version of the converse and of the con 16. Use mathematical induction to prove that 4" —1 is divisi
trapositive for each of the following propositions. ble by 3.
(a) p =• q (b) (~r) V (^s) => q 17. Use mathematical induction to prove that
(c) q => p v s
10. Write the converse and the contrapositive of the proposi (n + l)2
1+2 + 3 + ... + /! <
tions in Problem 4 as English sentences.
Experiment 2 89

| Experiment 2
Many games and puzzles use strategies based on the rules of mathematical logic
developed in Chapter 2. We begin here with a simple puzzle situation: Construct
an object from beads and wires that satisfies some given conditions. After investi
gating this object, you will prove that it satisfies certain properties.
Part I. Here are the conditions for the first object.
(a) You must use exactly three beads.
(b) There is exactly one wire between every pair of beads.
(c) Not all beads can be on the same wire.
(d) Any pair of wires has at least one bead in common.
1. Draw a picture of the object.
2. Your object might not be the only one possible, so the following
statements are to be proved referring only to the conditions and not
to your object.
Tl. Any two wires have at most one bead in common.
T2. There are exactly three wires.
T3. No bead is on all the wires.

Part II. Here are the conditions for the second object.
(a) You must use at least one bead.
(b) Every wire has exactly two beads on it.
(c) Every bead is on exactly two wires.
(d) Given a wire, there are exactly three other distinct wires that have
no beads in common with the given wire.
1. Draw a picture of the object.
2. Your object might not be the only one possible, so the following
statements are to be proved referring only to the conditions and not
to your object.
Tl. There is at least one wire.
T2. Given a wire, there are exactly two other wires that have a bead
in common with the given wire.
T3. There are exactly wires.
T4. There are exactly beads.
Part III. The two objects you created in Parts I and II can be viewed in a number
of ways. Instead of beads and wires, consider players and two-person
teams, or substitute the words point and line for bead and wire.
1. Translate the statements Tl, T2, and T3 in Part I into statements
about players and two-person teams.
2. Translate the conditions (a)-(d) given in Part II into statements about
points and lines.
3. The type of object created here is often called a finite geometry,
because each has a finite number of points and lines. What common
geometric concept is described in condition (d) of Part II?
4. The Acian Bolex Tournament will be played soon. Determine the
number of players needed and the number of teams that will be
formed according to these ancient rules for bolex.
(a) A team must consist of exactly three players.
90 Chapter 2 Logic
(b) Two players may be on at most one team in common.
(c) Each player must be on at least three teams.
(d) Not all the players can be on the same team.
(e) At least one team must be formed.
(f) If a player is not on a given team, then the player must be on ex
actly one team that has no members in common with the given
team.
CHAPTER

Counting
Prerequisites: Chapter 1

Techniques for counting are important in mathematics and in computer science,


especially in the analysis of algorithms. In Section 1.2, the addition principle
was introduced. In this chapter, we present other counting techniques, in partic
ular those for permutations and combinations, and we look at two applications of
counting, the pigeonhole principle and probability. In addition, recurrence rela
tions, another tool for the analysis of computer programs, are discussed.

Looking Back
An early contributor to the study of combinations was Abra whom mathematics was a hobby. This series of letters laid the
ham ben Meir ibn Ezra (1092-1167), who was bom and died foundation for the theory of probability. The correspondence
in Spain. Rabbi ben Ezra also worked in astrology, astron between Pascal and Fermat developed when Pascal's friend, the
omy, philosophy, and medicine. Another early researcher in the Chevalier de Mere, asked him to solve several dice problems. In
area of permutations and combinations was the French mathe addition to making many other important contributions in math
matician, astronomer, and philosopher Levi ben Gerson (1288— ematics and hydrostatics, Pascal invented a mechanical calcula
1344). tor that was very similar to the mechanical calculators used in
In 1654 Blaise Pascal (1623-1662), a French mathemati the 1940s, just before the development of the digital electronic
cian who had been a child prodigy, exchanged a small series of computer.
letters with Pierre de Fermat (1601-1665), a French lawyer for

Blaise Pascal Pierre de Fermat

91
92 Chapter 3 Counting

3.1 Permutations

We begin with a simple but general result we will use frequently in this section
and elsewhere.

THEOREM 1 Suppose that two tasks T\ and T2 are to be performed in sequence. If T\ can be
performed in n\ ways, and for each of these ways T2 can be performed in n2 ways,
then the sequence T\T2 can be performed in n\ri2 ways.

Proof
Each choice of a method of performing T\ will result in a different way of per
forming the task sequence. There are n\ such methods, and for each of these we
may choose n2 ways of performing r2. Thus, in all, there will be n\n2 ways of
performing the sequence T\T2. See Figure 3.1 for the case where n\ is 3 and n2
is 4. •

A
Possible ways of performing task 1
^k
Possible ways of performing task 2

Possibleways of performing task 1, then task 2 in sequence

Figure 3.1

Theorem 1 is sometimes called the multiplication principle of counting.


(You shouldcompareit carefullywith the addition principle of counting from Sec
tion 1.2.) It is an easy matterto extendthe multiplication principle as follows.

THEOREM 2 Suppose that tasks T\% 7_, •. •, Tk are to be performed in sequence. If T\ can be
performed in rt\ ways, and for each of these ways T2 can be performed in ri2
ways, and for each of these n\ni ways of performing T\ T2 in sequence, T3 can be
performedin n3 ways, and so on, then the sequence TiT2-Tk can be performed
in exactly n\ri2 • • •n^ ways.

Proof
This result can be proved by using the principle of mathematical induction on k.

Example 1 A label identifier, for a computer system, consists of one letter followed by three
digits. If repetitions are allowed, how many distinct label identifiers are possible?

Solution
There are 26 possibilities for the beginning letter and there are 10 possibilities for
each of the three digits. Thus, by the extended multiplication principle, there are
26 x 10 x 10 x 10 or 26,000 possible label identifiers. ♦
3.1 Permutations 93

Example 2 Let A be a setwith n elements. How many subsets does A have?


Solution
We know from Section 1.3 that each subset of A is determined by its characteristic
function, and if A has n elements, this function may be described as an array of 0's
and l's having length n. The first element of the array can be filled in two ways
(with a 0 or a 1), and this is true for all succeeding elements as well. Thus, by the
extended multiplication principle, there are

2-2. 2 = 2"
n factors

ways of filling the array, and therefore 2n subsets of A. ♦

We now turn our attention to the following counting problem. Let A be any
set with n elements, and suppose that 1 < r < n.

Problem 1 How many different sequences, each of length r, can be formed using elements
from A if
(a) elements in the sequence may be repeated?
(b) all elements in the sequence must be distinct?
First we note that any sequence of length r can be formed by filling r boxes
in order from left to right with elements of A. In case (a) we may use copies of
elements of A.

box 1 box 2 box 3 box r — 1 boxr

Let Ti be the task "fill box 1," let T2 be the task "fill box 2," and so on. Then
the combined task TiT2"Tr represents the formation of the sequence.
Case (a). T\ can be accomplished in n ways, since we may copy any element
of A for the first position of the sequence. The same is true for each of the tasks
72, T3,..., Tr. Then by the extended multiplication principle, the number of se
quences that can be formed is

n - n n — n.

r factors

We have therefore proved the following result.

THEOREM 3 Let A be a set with n elements and 1 < r < n. Then the number of sequences of
length r that can be formed from elements of A, allowing repetitions, is nr. •

Example 3 How many three-letter "words" can be formed from letters in the set {a, b, y, z} if
repeated letters are allowed?

Solution
Heren is 4 and r is 3, so the number of such words is 43 or 64, by Theorem 3. ♦
Now we consider case (b) of Problem 1. Here also T\ can be performed in
n ways, since any element of A can be chosen for the first position. Whichever
element is chosen, only (n — 1) elements remain, so that T2 can be performed
in (n — 1) ways, and so on, until finally Tr can be performed in n — (r — 1) or
94 Chapter 3 Counting

(n - r + 1) ways. Thus, by the extended principle of multiplication, a sequence of


r distinct elementsfrom A can be formed in n(n —\)(n —2) •••(n —r + 1) ways.
A sequence of r distinct elements of A is often called a permutation of A taken
r at a time. This terminology is standard, and therefore we adopt it, but it is con
fusing. A better terminology might be a "permutation of r elements chosen from
A." Many sequences of interest are permutations of some set of n objects taken
r at a time. The preceding discussion shows that the number of such sequences
depends only on n and r, not on A. This number is often written nPr and is called
the number of permutations of n objects taken r at a time. We have just proved
the following result.

THEOREM 4 If 1 < r < n, then nPr, the number of permutations of n objects taken r at a time,
is n • (n - 1) • (n - 2) (n - r + 1). •

Example 4 Let Abe{1,2, 3,4}. Then the sequences 124,421, 341, and 243 are some permu
tations of A taken 3 at a time. The sequences 12, 43, 31, 24, and 21 are examples
of different permutations of A taken two at a time. By Theorem 4, the total number
of permutations of A taken three at a time is 4P3 or 4 •3 •2 or 24. The total number
of permutations of A taken two at a time is 4P2 or 4 • 3 or 12. ♦

When r = n, we are counting the distinct arrangements of the elements of


A, with \A\ = n, into sequences of length n. Such a sequence is simply called
a permutation of A. In Chapter 5 we use the term "permutation" in a slightly
different way to increase its utility. The number of permutations of A is thus nPn
orn-(n — l)>(n —2) 2 • 1, if n > 1. This number is also written n\ and is
read n factorial. Both nPr and n\ are built-in functions on many calculators.

Example 5 Let A be [a, b, c}. Then the possible permutations of A are the sequences abc,
acb, bac, bca, cab, and cba. ♦

For convenience, we define 0! to be 1. Then for every n > 0 the number of


permutations of n objects is n\. If n > 0 and 0 < r < n, we can now give a more
compact form for nPr as follows:

nPr = n • (n - 1) • (n - 2) (n - r + 1)

n • (n —1) (n —r + 1) • (n —r) • (n —r —1) 2\


(n-r)-(n-r-l) 2-1

(n-r)\

Example 6 Let A consist of all 52 cards in an ordinary deck of playing cards. Suppose that
this deck is shuffled and a hand of five cards is dealt. A list of cards in this hand,
in the order in which they were dealt, is a permutation of A taken five at a time.
Examples would include AH, 3D, 5C, 2H, JS; 2H, 3H, 5H, QH, KD; JH, JD,
JS, 4H, 4C; and 3D, 2H, AH, JS, 5C. Note that the first and last hands are the
same, but they represent different permutations since they were dealt in a different
order. The number of permutations of A taken five at a time is 52P5 = ||| or
52 • 51 • 50 • 49 • 48 or 311,875,200. This is the number of five-card hands that can
be dealt if we consider the order in which they were dealt. ♦

Example 7 If Ais the setinExample 5, then n is 3 and the number of permutations of Ais 3!
or 6. Thus, all the permutations of A are listed in Example 5, as claimed. ♦
3.1 Permutations 95

Example 8 How many "words" of three distinct letters can be formed from the letters of the
word MAST?

Solution

The number is 4P3


4! 4! ,_„
or — or 24.
(4-3)! 1!
In Example 8 if the word had been MASS, 4P3 would count as distinct some
permutations that cannot be distinguished. For example, if we tag the two S's as
Si and S2, then Si AS2 and S2ASi are two of the 24 permutations counted, but
without the tags, these are the same "word." We have one more case to consider,
permutations with limited repeats.

Example 9 How many distinguishable permutations of the letters in the word BANANA are
there?

Solution
We begin by tagging the A's and N's in order to distinguish between them tem
porarily. For the letters B, Ai, Nj, A2, N2, A3, there are 6! or 720 permutations.
Some of these permutations are identical except for the order in which the N's
appear; for example, A1A2A3BN1N2 and Ai A2A3BN2Ni. In fact, the 720 permu
tations can be listed in pairs whose members differ only in the order of the two N's.
This means that ifthe tags are dropped from the N's only ™ or360 distinguishable
permutations remain. Reasoning in a similar way we see that these can be grouped
in groups of 3! or 6 that differ only in the order of the three A's. For example, one
group of 6 consists of BNNA!A2A3, BNNA1A3A2, BNNA2AiA3, BNNA2A3Ai,
BNNA3Ai A2, BNNA3A2A1. Dropping the tags would change these 6 into the sin
gle permutation BNNAAA. Thus, there are ^p or 60 distinguishable permutations
of the letters of BANANA. ♦

The following theorem describes the general situation for permutations with
limited repeats.

THEOREM 5 The number of distinguishable permutations that can be formed from a collection
of n objects where the first object appears k\ times, the second object fe times, and
so on, is

n\
where k\ + £2 H + kt =n.
kx\k2\--ktV

Example 10 The number of distinguishable "words" that can be formed from the letters of
MISSISSIPPI is jt^t or 34,650. ♦

3.1 Exercises

1. A bank password consists of two letters of the English al tails are possible?
phabet followed by two digits. How many different pass- 4 A catered menu is to include a soup, a main course, a
words are there?
dessert, and a beverage. Suppose a customer can select
2. In a psychological experiment, a person must arrange a from four soups, five main courses, three desserts, and two
square, a cube, a circle, a triangle, and a pentagon in a beverages. How many different menus can be selected?
row. How many different arrangements are possible? 5 A fair six-sided die is tossed four times and the numbers
3. A coin is tossed four times and the result of each toss is shown are recorded in a sequence. How many different
recorded. How many different sequences of heads and sequences are there?
96 Chapter 3 Counting

6. Let A = {0, 1}. A* denotes the set of all finite sequences 26. Give a proof of your result for Exercise 25.
of elements of A as defined in Section 1.3. 27. A bookshelfis to be used to displaysix new books. Sup
(a) How many strings of length three are there in A*? pose there are eight computer science books and five
(b) How many strings of length seven are there in A*? French books from which to choose. If we decide to show
four computer science books and two French books and
7. (a) Compute the number of strings of length four in the
we are required to keep the books in each subject together,
set corresponding to the regular expression (01)*1.
how many different displays are possible?
(b) Compute the number of strings of length five in the
28. Three fair six-sided dice are tossed and the numbers
set corresponding to the regular expression (01)*1.
showing on the top faces are recorded as a triple. How
8. Compute each of the following. many different records are possible?
(a) 4P4 (b) 6P5 (c) -jP2 29. Prove that n • n.x Pn.{ = nPn.
9. Compute each of the following. 30. Most versions of Pascal allow variable names to consist
(a) nPn- (b) „P„_2 (c) ,,+,/V of eight letters or digits with the requirement that the first
character must be a letter. How many eight-character vari
In Exercises 10 through 13, compute the numberofpermuta able names are possible?
tions of the given set.
31. Until recently, U.S. telephone area codes were three-digit
10. {r,_,f,w} 11. {1,2,3,4,5} numbers whose middle digit was 0 or 1. Codes whose
12. [a,b, 1,2,3, c] 13. {4,7,10,13} last two digits are 1's are used for other purposes (for ex
ample, 911). With these conditions how many area codes
InExercises14 through 16,find the number ofpermutations of were available?
A taken rata time. 32. How many Social Security numbers can be assigned at
14. A = {l,2,3,4,5,6,7},r = 3 any one time? Identify any assumptions you have made.
15. A = {a, by c, d, e, /}, r = 2 33. How many zeros are there at the end of 12!? at the end of
26!? at the end of 53!?
16. A = {x | x is an integerand x2 < 16}, r = 4
34. Give a procedure for determining the number of zeros at
17. In how many ways can six men and six women be seated
the end of n\. Justify your procedure.
in a row if

(a) any person may sit next to any other? In Exercises 35 through 37, use the following information.
(b) men and women must occupy alternate seats? There are threeroutesfrom Atlanta to Athens, four routesfrom
Athens to Augusta, and two routesfrom Atlanta to Augusta.
18. Find the number of different permutations of the letters in
the word GROUP. 35. (a) How many ways are there to travel from Atlanta to
19. How many different arrangements of the letters in the Augusta?
word BOUGHT can be formed if the vowels must be kept (b) How many ways are there to travel from Athens to
next to each other? Atlanta?
20. Find the number of distinguishable permutations of the 36. (a) How many different ways can the round trip between
letters in BOOLEAN. Atlanta and Augusta be made?
21. Find the number of distinguishable permutations of the (b) How many different ways can the round trip between
letters in PASCAL. Atlanta and Augusta be made if each route is used
22. Find the number of distinguishable permutations of the only once?
letters in ASSOCIATIVE. 37. (a) How many different ways can the round trip between
23. Find the number of distinguishable permutations of the Augusta and Athens be made if the trip does not go
letters in REQUIREMENTS. through Atlanta?
24. In how many ways can seven people be seated in a circle? (b) How many different ways can the round trip between
25. How many different ways can n people be seated around Augusta and Athens be made if the trip does not go
a circular table? through Atlanta and each route is used only once?

3.2 Combinations

The multiplication principle and the counting methods for permutations all apply
to situations where order matters. In this section we look at some counting prob
lems where order does not matter.
3.2 Combinations 97

Problem 2 Let A be any set with n elements and 0 < r < n. How many different subsets of
A are there, each with r elements?

The traditional name for an r -element subset of an n -element set A is a com


bination of A, taken r at a time.

Example 1 Let A = {1,2,3,4}. The following are all distinct combinations of A, taken
three at a time: A{ = {1,2,3}, A2 = {1,2,4}, A3 = {1,3,4}, A4 = {2,3,4}.
Note that these are subsets, not sequences. Thus A\ = {2, 1, 3} = {2, 3, 1} =
{1, 3, 2} = {3, 1, 2} = {3, 2, 1}. In other words, when it comes to combinations,
unlike permutations, the order of the elements is irrelevant. ♦

Example 2 Let A be the set of all 52 cards in an ordinary deck of playing cards. Then a
combination of A, taken five at a time, is just a hand of five cards regardless of
how these cards were dealt. ♦

We now want to count the number of r-element subsets of an ^-element set A.


This is most easily accomplished by using what we already know about permuta
tions. Observe that each permutation of the elements of A, taken r at a time, can
be produced by performing the following two tasks in sequence.
Task 1: Choose a subset B of A containing r elements.
Task 2: Choose a particular permutation of B.
We are trying to compute the number of ways to choose B. Call this number C.
Then task 1 can be performed in C ways, and task 2 can be performed in r\ ways.
Thus the total number of ways of performing both tasks is, by the multiplication
principle, C r\. But it is also nPr. Hence,

m
Cr\ = nPr =
(n-r)\

Therefore,

C =
r\(n-r)\
We have proved the following result.

THEOREM 1 Let A be a set with |A\ = n, and let 0 < r < n. Then the number of combinations
of the elements of A, taken r at a time, that is, the number of r-element subsets of
A, is

n\
r\(n-r)\

Note again that the number of combinations of A, taken r at a time, does not
depend on A, but only on n and r. This number is often written nCr and is called
the number of combinations of n objects taken r at a time. We have

n\
/?Lr —
r\(n-r)\

This computation is a built-in function on many calculators.

Example 3 Compute the number of distinct five-card hands that can be dealt from a deck of
52 cards.
98 Chapter 3 Counting

Solution
This number is 52 C5 because the order in which the cards were dealt is irrelevant.
52C5 = 57^ or 2,598,960. Compare this number with the number computed in
Example 6, Section 3.1. ♦

In the discussion of permutations, we considered cases where repetitions are


allowed. We now look at one such case for combinations.
Consider the following situation. A radio station offers a prize of three CDs
from the Top Ten list. The choice of CDs is left to the winner, and repeats are
allowed. The order in which the choices are made is irrelevant. To determine the
number of ways in which prize winners can make their choices, we use a problem-
solving technique we have used before; we model the situation with one we already
know how to handle.
Suppose choices are recorded by the station's voice mail system. After prop
erly identifying herself, a winner is asked to press 1 if she wants CD number n and
to press 2 if she does not. If 1 is pressed, the system asks again about CD number
n. When 2 is pressed, the system asks about the next CD on the list. When three
1's have been recorded, the system tells the caller the selected CDs will be shipped.
A record must be created for each of these calls. A record will be a sequence of 1's
and 2's. Clearly there will be three l's in the sequence. A sequence may contain as
many as nine 2's, for example, if the winner refuses the first nine CDs and chooses
three copies of CD number 10. Our model for counting the number of ways a
prize winner can choose her three CDs is the following. Each three-CD selection
can be represented by an array containing three l's and nine 2's or blanks, or a
total of twelve cells. Some possible records are 222122122221 (selecting num
bers 4, 6, 10), I2llbbbbbbbb (selecting number 1 and two copies of number 2),
and 222222222111 (selecting three copies of number 10). The number of ways to
select three cells of the array to hold l's is i2C3 since the array has 3 + 9 or 12
cells and the order in whichthis selection is made does not matter. The following
theorem generalizes this discussion.

THEOREM 2 Suppose k selections are to be made from n items without regard to order and
repeats are allowed, assuming at least k copies of each of the n items. The number
of ways these selections can be made is (n+fc_i)C*. •

Example 4 Inhow many ways can a prize winner choose three CDs from the Top Ten list if
repeats are allowed?

Solution
Here n is 10 and k is 3. By Theorem 2, there are 10+3-1C3 or 12C3 ways to make
the selections. The prize winner can make the selection in 220 ways. ♦

In general, when ordermatters, we count the number ofsequences or permu


tations', when order does not matter, we count the number of subsets or combina
tions.
Some problems require that the counting of permutations and combinations be
combined or supplemented by the direct use of the addition or the multiplication
principle.

Example 5 Suppose that a valid computer password consists of seven characters, the first of
which is a letter chosen from the set {A, B, C, D, E, F, G} and the remaining six
characters are letters chosen from the English alphabet or a digit. How many
different passwords are possible?
3.2 Combinations 99

Solution
A password can be constructed by performing the tasks T\ and T2 in sequence.
Task 1: Choose a starting letter from the set given.
Task 2: Choose a sequence of letter and digits. Repeats are allowed.
Task T\ can be performed in 7C\ or 7 ways. Since there are 26 letters and 10 digits
that can be chosen for each of the remaining six characters, and since repeats are
allowed, task T2 canbe performed in 366 or 2,176,782,336 ways. By the multipli
cation principle, there are 7 • 2176782336 or 15,237,476,352 different passwords.

Example 6 How many different seven-person committees canbeformed eachcontaining three


women from an available set of 20 women and four men from an available set of
30 men?

Solution
In this case a committee can be formed by performing the following two tasks in
succession:

Task 1: Choose three women from the set of 20 women.


Task 2: Choose four men from the set of 30 men.

Here order does not matter in the individual choices, so we are merely counting
the number of possible subsets. Thus task 1 can be performed in 20C3 or 1140
ways and task 2 can be performed in 30C4 or 27,405 ways. By the multiplication
principle, there are (1140)(27405) or 31,241,700 different committees. ♦

3.2 Exercises
1. Compute each of the following, 8. How many different eight-card hands with five red cards
and three black cards can be dealt from a deck of 52 cards?
(a) 7C7 (b) 7C4 (c) 16C5
2. Compute each of the following. 9. (a) Find the number of subsets of each possible size for
a set containing four elements.
(a) „C„_i (b) nCn-2 (C) n+\Cn-\
3. Show that nCr = nCn-r- (b) Find the number of subsets of each possible size for
a set containing n elements.
4. In how many ways can a committee of three faculty mem
bers and two students be selected from seven faculty For Exercises 10 through 13, suppose that an urn contains 15
members and eight students? balls, of which eight are red and seven are black.
5. In how many ways can a six-card hand be dealt from a 10. In how many ways can five balls be chosen so that
deck of 52 cards?
(a) all five are red?
6. At a certain college, the housing office has decided to ap
point, for each floor, one male and one female residential (b) all five are black?
advisor. How many different pairs of advisors can be se 11. In how many ways can five balls be chosen so that
lected for a seven-story building from 12 male candidates (a) two are red and three are black?
and 15 female candidates?
(b) three are red and two are black?
7. A microcomputer manufacturer who is designing an ad
12. In how many ways can five balls be chosen so that at most
vertising campaign is considering six magazines, three
three are black?
newspapers, two television stations, and four radio sta
tions. In how many ways can six advertisements be mn if 13. In how many ways can five balls be chosen so that at least
(a) all six are to be in magazines? two are red?

(b) two are to be in magazines, two are to be in newspa 14. Give a model in terms of combinations to count the num
pers, one is to be on television, and one is to be on ber of strings of length 6 in {0, 1}* that have exactly four
radio? ones.
100 Chapter 3 Counting

15. Give a model in terms of combinations to count the num (a) record sequences are possible?
ber of ways to arrange three of seven people in order from (b) sequences contain exactly one six?
youngest to oldest.
(c) sequences contain exactly four twos, assuming n >
16. A committee of six people with one person designated as 4?
chair of the committee is to be chosen. How many differ
ent committees of this type can be chosen from a group of 25. How many ways can you choose three of seven fiction
10 people? books and two of six nonfiction books to take with you on
your vacation?
17. A gift certificate at a local bookstore allows the recipient
to choose six books from the combined list of ten best- 26. For the driving part of your vacation you will take 6 of the
selling fiction books and ten bestselling nonfiction books. 35 rock cassettes in your collection, 3 of the 22 classical
In how many different ways can the selection of six books cassettes, and 1 of the 8 comedy cassettes. In how many
be made? ways can you make your choice(s)?
18. The college food plan allows a student to chose three 27. The array commonly called Pascal's triangle can be de
pieces of fruit each day. The fruits available are apples, fined by giving enough information to establish its pat
bananas, peaches, pears, and plums. For how many days tern.
1
can a student make a different selection?
1 1
19. Show that n+lCr = nCr.x + nCr.
1 2 1
20. (a) How many ways can a student choose eight out of 13 3 1
ten questions to answer on an exam? 14 6 4 1
(b) How many ways can a student choose eight out of (a) Write the next three rows of Pascal's triangle.
ten questions to answer on an exam if the first three
questions must be answered? (b) Give a rule for building the next row from the previ
ous row(s).
21. Five fair coins are tossed and the results are recorded.
28. Pascal's triangle can also be defined by an explicit pattern.
(a) How many different sequences of heads and tails are Use the results of Exercises 9 and 27 to give an explicit
possible? rule for building the nth row of Pascal's triangle.
(b) How many of the sequences in part (a) have exactly
29. Explain the connections between Exercises 19, 27, and
one head recorded?
28.
(c) How many of the sequences in part (a) have exactly
three heads recorded?
30. The list of numbers in any row of Pascal's triangle reads
the same from left to right as it does from right to left.
22. Three fair six-sided dice are tossed and the numbers
Such a sequence is called a palindrome. Use the results of
showing on top are recorded. Exercise 28 to prove that each row of Pascal's triangle is
(a) How many different record sequences are possible? a palindrome.
(b) How many of the records in part (a) contain exactly 31. (a) The sum of the entries in the second row of Pascal's
one six? triangle is
(c) How many of the records in part (a) contain exactly (b) The sum of the entries in the third row of Pascal's
two fours?
triangle is
23. If n fair coins are tossed and the results recorded, how (c) The sum of the entries in the fourth row of Pascal's
many
triangle is
(a) record sequences are possible?
32. Make a conjecture about the sum of the entries in the nth
(b) sequences contain exactly three tails, assuming n > row of Pascal's triangle and prove it.
3?
33. Marcy wants to buy a book of poems. If she wants to read
(c) sequences contain exactly k heads, assuming n > kl a different set of three poems every day for a year (365
24. If n fair six-sided dice are tossed and the numbers show days), what is the minimum number of poems the book
ing on top are recorded, how many should contain?

3.3 Pigeonhole Principle


In this section we introduce another proof technique, one that often makes use of
the counting methods we have discussed.
3.3 Pigeonhole Principle 101

THEOREM 1 If n pigeons are assigned to m pigeonholes, and m < n, then at leastone pigeon-
The Pigeonhole Principle hole contains two or more pigeons.
Proof
Suppose eachpigeonhole contains at most 1 pigeon. Then at mostm pigeons have
been assigned. But sincem < n9 not all pigeons have been assigned pigeonholes.
This is a contradiction. At least one pigeonhole contains two or more pigeons. •

This informal and almost trivial-sounding theorem is easy to use and has un
expected power in proving interesting consequences.

Example 1 If eight people arechosen in any way from some group, at leasttwo of them will
have been born on the same day of the week. Here each person (pigeon) is assigned
to the day of the week (pigeonhole) on which he or she was born. Since there are
eight people and only sevendays of the week, the pigeonhole principle tells us that
at least two people must be assigned to the same day of the week. ♦

Note that the pigeonhole principle provides an existence proof; there must be
an object or objects with a certain characteristic. In Example 1, this characteris
tic is having been born on the same day of the week. The pigeonhole principle
guarantees that there are at least two people with this characteristic but gives no
information on identifying these people. Only their existence is guaranteed. In
contrast, a constructive proof guarantees the existence of an object or objects
with a certain characteristic by actually constructing such an object or objects.
For example, we could prove that given two rational numbers p and q there is a
rational number between them by showing that ^^ isbetween p and q.
In order to use the pigeonhole principle we must identify pigeons (objects)
and pigeonholes (categories of the desired characteristic) and be able to count the
number of pigeons and the number of pigeonholes.

Example 2 Show that if any five numbers from 1 to 8 are chosen, then two of them will add
to 9.

Solution
Construct four different sets, each containing two numbers that add up to 9 as
follows: Ax = {1,8}, A2 = {2,7}, A3 = {3,6}, A4 = {4,5}. Each of the five
numbers chosen must belong to one of these sets. Since there are only four sets,
the pigeonhole principle tells us that two of the chosen numbers belong to the same
set. These numbers add up to 9. ♦

Example 3 Show that if any 11 numbers are chosen from the set {1, 2,..., 20}, then one of
them will be a multiple of another.

Solution
The key to solving this problem is to create 10 or fewer pigeonholes in such a
way that each number chosen can be assigned to only one pigeonhole, and when
x and y are assigned to the same pigeonhole we are guaranteed that either x \ y
or y | x. Factors are a natural feature to explore. There are eight prime numbers
between 1 and 20, but knowing that x and y are multiples of the same prime will
not guarantee that either x \ y or y \ x. We try again. There are ten odd numbers
between 1 and 20. Every positive integer n can be written as n = 2km, where m is
odd and k > 0. This can be seen by simply factoring all powers of 2 (if any) out of
n. In this case let us call m the odd part of n. If 11 numbers are chosen from the set
102 Chapter 3 Counting

{1,2,..., 20}, then two of them must have the same odd part. This follows from
the pigeonhole principle since there are 11 numbers (pigeons), but only 10 odd
numbers between 1 and 20 (pigeonholes) that can be odd parts of these numbers.
Let n\ and «2 be two chosen numbers with the same odd part. We must have
m = 2kxm and n2 = 2*2m, for some k{ and k2. If&i __ k2, then n{ isa multiple of
n2\ otherwise, ^2 is a multiple of n\. ♦
Figure 3.2

Example 4 Consider the region shown inFigure 3.2. Itisbounded by aregular hexagon whose
sides are of length 1 unit. Show that if any seven points are chosen in this region,
then two of them must be no farther apart than 1 unit.

Solution
1
/ 6 Divide the region into six equilateral triangles, as shown in Figure 3.3. If seven
2\ points are chosen in the region, we can assign each of them to a triangle that
\ 5 3/ contains it. If the point belongs to several triangles, arbitrarily assign it to one
4 of them. Then the seven points are assigned to six triangular regions, so by the
pigeonhole principle, at least two points must belong to the same region. These
Figure 3.3 two cannot be more than one unit apart. (Why?) ♦

Example 5 Shirts numbered consecutively from 1 to 20 are worn by the 20 members of a


bowling league. When any three of these members are chosen to be a team, the
league proposes to use the sum of their shirt numbers as a code number for the
team. Show that if any eight of the 20 are selected, then from these eight one may
form at least two different teams having the same code number.

Solution
From the eight selected bowlers, we can form a total of sC3 or 56 different teams.
These will play the role of pigeons. The largest possible team code number is
18 + 19 + 20 or 57, and the smallest possible is 1 + 2 + 3 or 6. Thus only the 52
code numbers (pigeonholes) between 6 and 57 inclusive are available for the 56
possible teams. By the pigeonhole principle, at least two teams will have the same
code number. The league should use another way to assign team numbers. ♦

The Extended Pigeonhole Principle


Note that if there are m pigeonholes and more than 2m pigeons, three or more
pigeons will have to be assigned to at least one of the pigeonholes. (Consider the
most even distribution of pigeons you can make.) In general, if the number of
pigeons is much larger than the number of pigeonholes, Theorem 1 can be restated
to give a stronger conclusion.
First a word about notation. If n and m are positive integers, then \n/m\
stands for the largest integer less than or equal to the rational number n/m. Thus
L3/2J is 1, L9/4J is 2, and L6/3J is 2.

THEOREM 2 If n pigeons are assigned to m pigeonholes, then one of the pigeonholes must
The Extended contain at least \_{n —l)/m\ + 1 pigeons.
Pigeonhole Principle
Proof (by contradiction)
If each pigeonhole contains no more than \_(n — \)/m\ pigeons, then there are at
most m • \_(n —\)/m\ < m • (n — \)/m = n —1 pigeons in all. This contradicts
our hypothesis, so one of the pigeonholes must contain at least \_(n — l)/m\ + 1
pigeons. •
3.3 Pigeonhole Principle 103

This proof by contradiction uses the fact that there are two ways to count the
total number of pigeons, the original count n and as the productof the number of
pigeonholes times the number of pigeons per pigeonhole.

Example 6 We give an extension of Example 1. Show thatif any 30 people are selected, then
one may choose a subset of five so that all five were born on the same day of the
week.

Solution
Assign eachperson to the day of the weekon which she or he was born. Then 30
pigeons arebeing assigned to 7 pigeonholes. By theextended pigeonhole principle
with n = 30 and m = 7, at least L(30 - 1)/7J + 1 or 5 of the people must have
been born on the same day of the week. ♦

Example 7 Show that if 30 dictionaries in a library contain a total of 61,327 pages, then one
of the dictionaries must have at least 2045 pages.

Solution
Let the pages be the pigeons and the dictionaries the pigeonholes. Assign each
page to the dictionary in which it appears. Then by the extended pigeonhole prin
ciple, one dictionary must contain at least |_61,326/30J + 1 or 2045 pages. ♦

3.3 Exercises

1. If thirteen people are assembled in a room, show that at 9. If the store in Exercise 8 allows repetitions in the choices,
least two of them must have their birthday in the same show that there must be at least ten ways to make different
month. choices that have the same cost.

2. Show that if seven integers from 1 to 12 are chosen, then 10. Show that there must be at least 90 ways to choose six
two of them will add up to 13. integers from 1 to 15 so that all the choices have the same
sum.
3. Let T be an equilateral triangle whose sides are of length
1 unit. Show that if any five points are chosen lying on 11. How many friends must you have to guarantee at least five
or inside the triangle, then two of them must be no more of them will have birthdays in the same month?
than ^ unit apart. 12. Show that if five points are selected in a square whose
4. Show that if any eight positive integers are chosen, two of sides have length 1 inch, at least two of the points must be
them will have the same remainder when divided by 7. nomore than \[2 inches apart.
13. Let A be an 8 x 8 Boolean matrix. If the sum of the entries
5. Show that if seven colors are used to paint 50 bicycles, at
in A is 51, prove that there is a row i and a column j in
least eight bicycles will be the same color.
A such that the entries in row i and in column j add up to
6. Ten people volunteer for a three-person committee. Ev more than 13.
ery possible committee of three that can be formed from
14. Write an exercise similar to Exercise 13 for a 12 x 12
these ten names is written on a slip of paper, one slip for
Boolean matrix.
each possible committee, and the slips are put in ten hats.
Show that at least one hat contains 12 or more slips of 15. Prove that if any 14 integers from 1 to 25 are chosen, then
paper. one of them is a multiple of another.

7. Six friends discover that they have a total of $21.61 with 16. How large a subset of the integers from 1 to 50 must be
them on a trip to the movies. Show that one or more of chosen to guarantee that one of the numbers in the subset
them must have at least $3.61. is a multiple of another number in the subset?

8. A store has an introductory sale on 12 types of candy bars.


17. How large a subset of the integers from 1 to n must be
A customer may choose one bar of any five different types
chosen to guarantee that one of the numbers in the subset
and will be charged no more than $1.75. Show that al is a multiple of another number in the subset?
though different choices may cost different amounts, there 18. Twenty disks numbered 1 through 20 are placed face
must be at least two different ways to choose so that the down on a table. Disks are selected one at a time and
cost will be the same for both choices. turned over until 10 disks have been chosen. If two of the
104 Chapter 3 Counting
disks add up to 21, the player loses. Is it possible to win 21. Prove that any sequence of six integers must contain a
this game? subsequence whose sum is divisible by six. {Hint: Con
19. Suppose the gamein Exercise 18has beenchanged so that siderthe sumscu ci+c2, ci+c2+c3, ••• and the possible
12 disks are chosen. Is it possible to win this game? remainders when dividing by six.)
20. Complete the following proof. It is not possible to arrange 22. Prove that any sequence of n integers must contain a sub
the numbers 1,2, 3,..., 10 in a circle so that everytriple sequence whose sum is divisible by n.
of consecutively placed numbers has a sum less than 15. 23. Show that any set of six positive integers whose sum is 13
Proof: In any arrangement of 1,2,3,..., 10 in a circle, must contain a subset whose sum is three.
there are triples of consecutively placed numbers,
because Each number appears in of these
24. Use the pigeonhole principle to prove that any rational
triples. If the sum of each triple were less than 15, then number can be expressed as a number with a finite or re
peating decimal part.
the total sum of all triples would be less than times
15 or But 1 +2+3 + - • - + 10 is 55 and since each 25. The computer classroom has 12 PCs and 5 printers. What
number appears in. . triples, the total sum should be is the minimum number of connections that must be made
. times 55. This is a contradiction so not all triples to guarantee that any set of 5 or fewer PCs can access
can have a sum less than 15. printers at the same time?

3.4 Elements of Probability


Another area where counting techniques are important is probability theory. In
this section we present a brief introduction to probability.
Many experiments do not yield exactly the same results when performed re
peatedly. For example, if we toss a coin, we are not sure if we will get heads or
tails, and if we toss a die, we have no way of knowing which of the six possible
numbers will turn up. Experiments of this type are called probabilistic, in contrast
to deterministic experiments, whose outcome is always the same.

Sample Spaces
A set A consisting of all the outcomes of an experiment is called a sample space
of the experiment. With a given experiment, we can often associate more than one
sample space, depending on what the observer chooses to record as an outcome.

Example 1 Suppose that a nickel and a quarter are tossed inthe air. We describe three possible
sample spaces that can be associated with this experiment.
1. If the observer decides to record as an outcome the number of heads observed,
the sample space is A = {0,1,2}.
2. If the observer decides to record the sequence of heads (H) and tails (T) ob
served, listing the conditionof the nickel first and then that of the quarter, then
the sample space is A = {HH, HT, TH, TT}.
3. If the observer decides to record the fact that the coins match (M) (both heads
or both tails) or do not match (N), then the sample space is A = {M, N}. ♦

We thus see that in addition to describing the experiment, we must indicate


exactly what the observer wishes to record. Then the set of all outcomes of this
type becomes the sample space for the experiment.
A sample space may contain a finite or an infinite number of outcomes, but in
this chapter, we need only finite sample spaces.

Example 2 Determine thesample space foranexperiment consisting of tossing a six-sided die


twice and recording the sequence of numbers showing on the top face of the die
after each toss.
3.4 Elements of Probability 105

Solution
An outcome of the experiment can be represented by an ordered pair of numbers
(h, ra), where n and m can be 1, 2, 3,4, 5, or 6. Thus the sample space A contains
6 x 6 or 36 elements (by the multiplication principle). ♦

Example 3 Anexperiment consists ofdrawing three coins in succession from a boxcontaining


four pennies and five dimes, and recording the sequence of results. Determine the
sample space of this experiment.

Solution
An outcome can be recorded as a sequence of length 3 constructed from the letters
P (penny) and D (dime). Thus the sample space A is {PPP, PPD, PDP, PDD, DPP,
DPD, DDP, DDD}. ♦

Events

A statement about the outcome of an experiment, which for a particular outcome


will be either true or false, is said to describe an event. Thus for Example 2, the
statements, "Each of the numbers recorded is less than 3" and "The sum of the
numbers recorded is 4" would describe events. The event described by a statement
is taken to be the set of all outcomes for which the statement is true. With this
interpretation, any event can be considered a subset of the sample space. Thus the
event E described by the first statement is E = {(1, 1), (1, 2), (2, 1), (2, 2)}. Sim
ilarly, the event F described by the second statement is F = {(1, 3), (2, 2), (3,1)}.

Example 4 Consider theexperiment in Example 2. Determine theevents described by each of


the following statements.
(a) The sum of the numbers showing on the top faces is 8.
(b) The sum of the numbers showing on the top faces is at least 10.

Solution
(a) The event consists of all ordered pairs whose sum is 8. Thus the event is
{(2, 6), (3,5), (4,4), (5, 3), (6, 2)}.
(b) The event consists of all ordered pairs whose sum is 10, 11, or 12. Thus
the event is {(4,6), (5,5), (5, 6), (6,4), (6, 5), (6, 6)}. ♦

If A is a sample space of an experiment, then A itself is an event called the


certain event and the empty subset of A is called the impossible event.
Since events are sets, we can combine them by applying the operations of
union, intersection, and complementation to form new events. The sample space
A is the universal set for these events. Thus if E and F are events, we can form
the new events E U F, E 0 F, and E. What do these new events mean in terms of
the experiment? An outcome of the experiment belongs to E U F when it belongs
to E or F (or both). In other words, the event E U F occurs exactly when E or
F occur^ Similarly, the event EOF occurs if and only if both E and F occur.
Finally, E occurs if and only if E does not occur.

Example 5 Consider theexperiment of tossing a dieandrecording thenumber on thetopface.


Let E be the event that the number is even and let F be the event that the number is
prime. Then E = {2,4, 6} and F = {2, 3, 5}. The event that the number showing
is either even or prime is E U F = {2, 3,4, 5, 6}. The event that the number
showing is an even prime is E fl F = {2}. Finally, the event that the number
106 Chapter 3 Counting

showing js not even is E = {1, 3, 5} and the event that the number showingis not
prime is F = {1,4, 6}. ♦

Events E and F are said to be mutually exclusive or disjoint if EOF = { }.


If E and F are mutually exclusive events, then E and F cannot both occur at the
same time; if E occurs, then F does not occur, and if F occurs, then E does not. If
Ei, £2, ...,£„ are all events, then we say that these sets are mutually exclusive,
or disjoint, if each pair of them is mutually exclusive. Again, this means that at
most one of the events can occur on any given outcome of the experiment.

Assigning Probabilities to Events


In probability theory, we assume that each event E has been assigned a number
p(E) called the probability of the event/.. We now look at probabilities. We will
investigate ways in which they can be assigned, properties they must satisfy, and
the meaning that can be given to them.
The number p(E) reflects our assessment of the likelihood that the event E
will occur. More precisely, suppose the underlying experiment is performed re
peatedly, and that after n such performances, the event E has occurred nE times.
Then the fraction fE = nE/n, called the frequency of occurrence of E in n trials,
is a measure of the likelihood that E will occur. When we assign the probability
p(E) to the event E, it means that in our judgment or experience, we believe that
the fraction fE will tend ever closer to a certain number as n becomes larger, and
that p(E) is this number. Thus probabilities can be thought of as idealized fre
quencies of occurrence of events, to which actual frequencies of occurrence will
tend when the experiment is performed repeatedly.

Example 6 Suppose anexperiment is performed 2000 times, and the frequency of occurrence
fE of an event E is recorded after 100, 500, 1000, and 2000 trials. Table 3.1
summarizes the results.

Number of Repetitions
of the Experiment nE fs = tie/n

100 48 0.48
0:518
; , 4:000 '". 493 0.496
2000 1002 0.501

ible, it appears that the frequency ft: approaches \ as n becomes


larger. It could therefore be argued that p(E) should be set equal to j. On the
other hand, one might require more extensive evidence before assigning ^ as the
value ofp(E). In any case, this sort ofevidence can never "prove" that p(E) is \.
It only serves to make this a plausible assumption. ♦

If probabilities assigned to various events are to represent frequencies of oc


currence of the events meaningfully, as explained previously, then they cannot be
assigned in a totally arbitrary way. They must satisfy certain conditions. In the
first place, since every frequency fE must satisfy the inequalities 0 < fE < 1, it is
only reasonable to assume that
PI: 0 < p(E) < 1 for every event E in A.
3.4 Elements of Probability 107

Also, since the event A must occur every time (every outcome belongs to A), and
the event 0 cannot occur, we assume that

P2: p(A) = 1 and p(0) = 0.


Finally, if £1, 2_2, ...,£* are mutually exclusive events, then
W(_r,u_?2u-u_:4) = nEx + ke2 H r- w£*>
since only one of these events can occur at a time. If we divide both sides of this
equation by n, we see that the frequencies of occurrence must satisfy a similar
equation. We therefore assume
P3: /?(__, U E2 U • • • U Ek) = p(Ex) + p(E2) + • • • + p(Ek)
whenever the events are mutually exclusive. If the probabilities are assigned to
all events in such a way that PI, P2, and P3 are always satisfied, then we have a
probability space. We call PI, P2, and P3 the axioms for a probability space.
It is important to realize that mathematically, no demands are made on a prob
ability space except those given by the probability axioms PI, P2, and P3. Prob
ability theory begins with all probabilities assigned, and then investigates conse
quences of any relations between these probabilities. No mention is made of how
the probabilities were assigned. However, the mathematical conclusions will be
useful in an actual situation only if the probabilities assigned reflect what actually
occurs in that situation.
Experimentation is not the only way to determine reasonable probabilities
for events. The probability axioms can sometimes provide logical arguments for
choosing certain probabilities.

Example 7 Consider the experiment oftossing a coin and recording whether heads ortails re
sults. Consider the events E: heads turns up and F: tails turns up. The mechanics
of the toss are not controllable in detail. Thus in the absence of any defect in the
coin that might unbalance it, one may argue that E and F are equally likely to
occur. There is a symmetry in the situation that makes it impossible to prefer one
outcome over the other. This argument lets us compute what the probabilities of
E and F must be.
We have assumed that p(E) = p(F), and it is clear that E and F are mutually
exclusive events and A = E U F. Thus, using the properties P2 and P3, we see
that 1 = p{A) = p(E) + p(F) = 2p(E) since p(E) = p(F). This shows that
p(E) = 5 = p(F). One may often assign appropriate probabilities to events by
combining the symmetry of situations with the axioms of probability. ♦

Finally, we will show that the problem of assigning probabilities to events can
be reduced to the consideration of the simplest cases. Let A be a probability space.
We assume that A is finite, that is, A = {jci, JC2,..., xn}. Then each event {jc*},
consisting of just one outcome, is called an elementary event. For simplicity,
let us write pk for p({xk}). Then /?* is called the elementary probability corre
sponding to the outcome jc*. Since the elementary events are mutually exclusive
and their union is A, the axioms of probability tell us that
EP1: 0< pk < 1 for all it
EP2: pi+p2 + --- + A, = l.
If E is any event in A, say E = {*,-,,jc/2, ...,jc/m}, then we can write E =
[xil }U{xi2 }U- •'U{xim}. This means, by axiomP2, that p(E) = ph+p,-2H Ypim.
Thus if we know the elementary probabilities, then we can compute the probability
of any event E.
108 Chapter 3 Counting

Example 8 Suppose thatan experiment has a sample space A = {1, 2, 3,4,5,6} and thatthe
elementary probabilities have been determined as follows:
1 1 1 1 1 1
P2 = ~, P3 P4 = ~6,
3' P6=n-
Let E be the event "The outcome is an even number." Compute p(E).

Solution
Since E = {2,4, 6}, we see that

p(E) = p2 +P4 +p6 = ±+1- + ± or I.


In a similar way we can determine the probability of any event in A. ♦

Thus we see that the problem of assigning probabilities to all events in a con
sistent way can be reduced to the problem of finding numbers p\, p2,..., pn that
satisfy EP1 and EP2. Again, mathematically speaking, there are no other restric
tions on the /Vs. However, if the mathematical structure that results is to be useful
in a particular situation, then the /Vs must reflect the actual behavior occurring in
that situation.

Equally Likely Outcomes


Let us assume that all outcomes in a sample space A are equally likely to oc
cur. This is, of course, an assumption, and so cannot be proved. We would make
such an assumption if experimental evidence or symmetry indicated that it was
appropriate in a particular situation (see Example 7). Actually these situations
arise commonly. One additional piece of terminology is customary. Sometimes
experiments involve choosing an object, in a nondeterministic way, from some
collection. If the selection is made in such a way that all objects have an equal
probability of being chosen, we say that we have made a random selection or
chosen an object at random from the collection. We will often use this terminol
ogy to specify examples of experiments with equally likely outcomes.
Suppose that \A\ = n and these n outcomes are equally likely. Then the
elementary probabilities are all equal, and since they must add up to 1, this means
that each elementary probability is l/n. Now let E be an event that contains k
outcomes, say E = {jti, *2,..., **}. Since all elementary probabilities are l/n,
we must have
,™ = -l + -l + ... + -l = -.
p(E) k

k summands

Since k = \E |, we have the following principle: If all outcomes are equally likely,
then for every event E

\E\ total number of outcomes in E


|A | total number of outcomes
In this case, the computation of probabilities reduces to counting numbers of el
ements in sets. For this reason, the methods of counting discussed in the earlier
sections of this chapter are quite useful.

Example 9 Choose fourcards at random from a standard 52-card deck. Whatis theprobability
that four kings will be chosen?
3.4 Elements of Probability 109

Solution
The outcomes of this experiment are four-card hands; each is equally likely to
be chosen. The number of four-card hands is 52C4 or 270,725. Let E be the
event that all four cards are kings. The event E contains only one outcome. Thus
p(E) = 210125 or approximately 0.000003694. This is an extremely unlikely
event. ♦

Example 10 A boxcontains sixredballs and four green balls. Fourballs areselected at random
from the box. What is the probability that two of the selected balls will be red and
two will be green?

Solution
The total number of outcomes is the number of ways to select four objects out
of ten, without regard to order. This is 10C4 or 210. Now the event £, that two
of the balls are red and two of them are green, can be thought of as the result of
performing two tasks in succession.
Task 1: Choose two red balls from the six red balls in the box.
Task 2: Choose two green balls from the four green balls in the box.
Task 1 can be done in ^Ci or 15 ways and task 2 can be done in 4C2 or 6 ways.
Thus, event Ecan occur in 15 •6or 90 ways, and therefore p(E) = ^ or |. ♦

Example 11 A fair six-sided dieis tossed three times and the resulting sequence of numbers is
recorded. What is the probability of the event E that either all three numbers are
equal or none of them is a 4?

Solution
Since the die is assumed to be fair, all outcomes are equally likely. First, we
compute the total number of outcomes of the experiment. This is the number of
sequences of length 3, allowing repetitions, that can be constructed from the set
{1, 2, 3,4, 5, 6}. This number is 63 or 216.
Event E cannot be described as the result of performing two successive tasks
as in Example 10. We can, however, write E as the union of two simpler events.
Let F be the event that all three numbers recorded are equal, and let G be the
event that none of the numbers recorded is a 4. Then E = F U G. By the addition
principle (Theorem 2, Section 1.2), |F U G\ = \F\ + \G\ - \F H G\.
There are only six outcomes in which the numbers are equal, so |F| is 6.
The event G consists of all sequences of length 3 that can be formed from the
set {1, 2, 3, 5, 6}. Thus \G\ is 53 or 125. Finally, the event FOG consists of all
sequences for which the three numbers are equal and none is a 4. Clearly, there
are five ways for this to happen, so \F n G\ is 5. Using the addition principle,
\E\ = \F UG\ = 6+ 125 - 5or 126. Thus, we have p(E) = ±ff or ^. ♦

Example 12 Consider again theexperiment in Example 10, in which four balls are selected at
random from a box containing six red balls and four green balls.
(a) If E is the event that no more than two of the balls are red, compute the
probability of E.
(b) If F is the event that no more than three of the balls are red, compute the
probability of F.
110 Chapter 3 Counting

Solution
(a) Here E can be decomposed as the union of mutually exclusive events. Let
£o be the event that none of the chosen balls are red, let E\ be the event
that exactly one of the chosen balls is red, and let £2 be the event that
exactly two of the chosen balls are red. Then £0, £1, and £2 are mutually
exclusive and E = £0 U E\ U £2- Using the addition principle twice,
I£ I = I£01 + IE\ I+ I£21. If none of the balls is red, then all four must be
green. Since there are only four green balls in the box, there is only one
way for event £0 to occur. Thus |£01 = 1. If one ball is red, then the other
three must be green. To make such a choice, we must choose one red ball
from a set of six, and then three green balls from a set of four. Thus, the
number of outcomes in E\ is (6C1X4C3) or 24.
In exactly the same way, we can show that the number of outcomes
in £2 is (6C2X4C2) or 90. Thus, |£| = 1 + 24 + 90 or 115. On the other
hand, the total number of ways of choosing four balls from the box is 10C4
or210,so/7(£) = i{§or|.
(b) We could compute \F\ in the same way we computed |£| in part (a), by
decomposing F into four mutually exclusive events. The analysis would,
however, be even longer than that of part (a). We choose instead to illus
trate another approach that is frequently useful. _
Let F be the complementary event to F. Since F and F are mutu-
allyexclusive and their union is the sample space, we must have p(F) +
p(F) = 1. This formula holds for any event F and is used when the
complementary event is easier to analyze. This is the case here, since F
is the event that all four balls chosen are red. These four red balls can be
15
chosen from the six red balls in ^C^ or 15 ways, so p(F) = 210
or-

This means that p(F) = 1 l U1


14 or^
14*
A common use of probability in computer science is in analyzing the effi
ciency of algorithms. For example, this may be done by considering the number
of steps we "expect" the algorithmto execute on an "average" run. Here is a simple
case to consider. Ifa fair coin is tossed 500 times, we expect 250 (^ •500) heads
to occur. Of course, we would not be surprised if the number of heads were not
exactly 250. This idea leads to the following definition. The expected value of an
experimentis the sum of the value of each outcome times its probability. Roughly
speaking, the expected value describes the "average" value for a large number of
trials.

Example 13 An array of length 10is searched for a key word. The number of steps needed to
find it is recorded. Assuming that the key is equally likely to be in any position of
the array, the expected value ofthis experiment is 1•-^ + 2 •-^ + + 10- 10
or

jfi. On the average, we can expectto find a key word in 5.5 steps.

3.4 Exercises

In Exercises 1 through 4, describe the associated sample 3. A silver urn and a copper urn contain blue, red, and green
space. balls. An urn is chosen at random and then a ball is se
lected at random from this urn.
1. A coin is tossed three times and the sequence of heads and
tails is recorded. 4. A box contains 12 items, four of which are defective. An
item is chosen at random and not replaced. This is contin
2. Two letters are selected simultaneously at random from ued until all four defective items have been selected. The
the letters a, b, c, d. total number of items selected is recorded.
3.4 Elements of Probability 111

5. (a) Suppose that the sample space of an experiment is 14. Let £ be an event for an experiment with sample space A.
{1, 2, 3}. Determine all possible events. Show that

(b) Let S be a sample space containing n elements. How (a) £ U £ is the certain event.
many events are there for the associated experiment? (b) £ H £ is the impossible event.
In Exercises 6 through 8, use the following assumptions. A 15. A medical team classifies people according to the follow
card is selected at randomfrom a standard deck. Let E, F, ing characteristics.
and G be thefollowing events.
Drinking habits: drinks (d), abstains (a)
E: The card is black. Income level: low (/), middle (m), upper (w)
F: The card is a diamond. Smoking habits: smoker 0), nonsmoker (n)
G: The card is an ace.
Let £, F, and G be the following events.
Describe thefollowing events in complete sentences. £: A person drinks.
6. (a) £UG (b) £0G F: A person's income level is low.
7. (a) EHG (b) £UFUG G: A person smokes.
8. (a) £UFUG (b) (FHG)U£ List the elements in each of the following events.
In Exercises 9 and 10, assume that a die is tossed twice and the (a) £UF (b)£DF (c) (£UG)DF
numbers showing on the top faces are recorded in sequence.
Determine the elements in each ofthe given events. In Exercises 16 and 17, let S = {1, 2, 3,4, 5, 6} be the sample
space ofan experiment and let
9. (a) At least one of the numbers is a 5.
£ = {1,3,4,5}, F = {2,3}, G = {4}.
(b) At least one of the numbers is an 8.
10. (a) The sum of the numbers is less than 7. 16. Compute the events £ U F, £ n F, and F.
(b) The sum of the numbers is greater than 8. 17. Compute the following events: £ U F and FOG.
11. A die is tossed and the number showing on the top face is In Exercises 18 and 19, list the elementary eventsfor the given
recorded. Let £, F, and G be the following events. experiments.

E: The number is at least 3. 18. A vowel is selected at random from the set of all vowels
a, e, i, o, u.
F: The number is at most 3.
19. A card is selected at random from a standard deck and it
G: The number is divisible by 2.
is recorded whether the card is a club, spade, diamond, or
(a) Are E and F mutually exclusive? Justify your an heart.

swer. 20. (a) What is the probability of correctly guessing a per


(b) Are F and G mutually exclusive? Justify your an son's four-digit PIN?
swer. (b) People often use the four digits of their birthday
(c) Is E U F the certain event? Justify your answer. (MM-DD) to create a PIN. What is the probability
of correctly guessing a PIN created this way, if the
(d) Is E n F the impossible event? Justify your answer. birthday is known?
12. A card is chosen from a standard deck of 52 cards. Con
21. When a certain defective die is tossed, the numbers from
sider the following events. 1 to 6 will be on the top face with the following probabil
ities.
£i: The card drawn is a face card.
E2: The card drawn is a heart.
£3: The card drawn has an even number on it.
P, = l8' P2 = T8' P3 = !8' P4=18
£4: The card drawn is a red card. Ps =
18' P6=l8
Compute each of the following. Find the probability that
(a) p(Ex) (b) p(E2nE3) (c) p(E~3UE2) (a) an odd number is on top.
13. For the events defined in Exercise 12, which of the fol (b) a prime number is on top.
lowing pairs is a pair of mutually exclusive events? (c) a number less than 5 is on top.
(a) £2, £3 (b) £1, £2 (d) a number greater than 3 is on top.
(c) £3, £4 (d) £i,£3 22. Repeat Exercise 21, assuming that the die is not defective.
112 Chapter 3 Counting
23. Suppose that £ and F are mutually exclusive events such (a) all three balls are red.
that p(E) = 0.3 and p(F) = 0.4. Find the probability (b) at least two balls are black.
that
(c) at most two balls are black.
(a) £ does not occur. (b) £ and F occur.
(d) at least one ball is red.
(c) £ or F occurs.
34. A fair die is tossed three times in succession. Find the
(d) £ does not occur or F does not occur.
probability that the three resulting numbers
24. Consider an experiment with sample space A =
(a) include exactly two 3's.
{x\, x2, JC3, X4} for which
(b) form an increasing sequence.
1 1
P\ P2 = -r Pi = = , /?4 = (c) include at least one 3.
(d) include at most one 3.
Find the probability of the given event.
(e) include no 3's.
(a) E = {x\, x2] (b) F = {x\, x3, x4}
35. There are four cards numbered 1, 2, 3, 4. Choose three
25. There are four candidates for president, A, B, C, and D.
cards at random and lay them face up side by side.
Suppose A is twice as likely to be elected as B, B is three
times as likely as C, and C and D are equally likely to be (a) What is the probability that the cards chosen show
elected. What is the probability of being elected for each numbers in increasing order from left to right?
candidate? (b) What is the probability that the cards chosen show
26. The outcome of a particular game of chance is an integer numbers that are not in decreasing order from left to
from 1 to 5. Integers 1, 2, and 3 are equally likely to oc right?
cur, and integers 4 and 5 are equally likely to occur. The 36. Each day five secretaries draw numbers to determine the
probability that the outcome is greater than 2 is +. Find order in which they will take their breaks.
the probability of each possible outcome. (a) What is the probability that today's order is exactly
27. A fair coin is tossed five times. What is the probability of the same as yesterday's order?
obtaining three heads and two tails? (b) What is the probability that in today's order four sec
In Exercises 28 through 30, suppose afair die is tossed and the retaries have the same position as they had yester
number showing on the topface is recorded. Let E, F, and G day?
be thefollowing events. (c) What is the probability that at least one secretary has
the same position as yesterday?
£:{1,2,3,5}, F:{2,4}, G: {1,4,6}
37. An array of length n is searched for a key word. On the
Compute the probability of the event indicated. average, how many steps will it take to find the key?
28. (a) £UF (b) £ n F 38. How should the analysis in Exercise 37 be changed if we
do not assume that the key word is in the array?
29. (a) FflF (b) FUG
30. (a) FUG (b) £HG
39. A game is played by rolling two dice and paying the
player an amount (in dollars) equal to the sum of the num
31. Suppose two dice are tossed and the numbers on the top bers on top if this is 10 or greater. The player must pay $3
faces recorded. What is the probability that for each game. What is the expected value of this game?
(a) a 4 was tossed?
40. For the game described in Exercise 39, what would be a
(b) a prime number was tossed? "fair" cost to play the game? Justify your answer.
(c) the sum of the numbers is less than 5? 41. Suppose two cards are selected at random from a standard
(d) the sum of the numbers is at least 7? 52-card deck.

32. Suppose that two cards are selected at random from a stan (a) If both cards are drawn at the same time, what is the
dard 52-card deck. What is the probability that both cards probability that both cards have an odd number on
are less than 10 and neither of them is red? them and neither is black?

33. Suppose that three balls are selected at random from an (b) If one card is drawn and replaced before the second
urn containing seven red balls and five black balls. Com card is drawn, what is the probability that both cards
pute the probability that have an odd number on them and neither is black?

3.5 Recurrence Relations

The recursive definitions of sequences in Section 1.3 are examples of recurrence


relations. When the problem is to find an explicit formula for a recursively defined
3.5 Recurrence Relations 113

sequence, the recursive formula is called a recurrence relation. Remember that


to define a sequence recursively, a recursive formula must be accompanied by
information about the beginning of the sequence. This information is called the
initial condition or conditions for the sequence.

Example 1 (a) The recurrence relation an = an-\ + 3 with a\ = 4 recursively defines the
sequence 4, 7,10,13,... .
(b) The recurrencerelation /„ = fn-\ +/„_2, f\ = fi = 1, defines the Fibonacci
sequence 1,1,2,3,5, 8,13,21,... . The initial conditions are /i = 1 and
/2 = 1. ♦
Recurrence relations arise naturally in many counting problems and in analyz
ing programming problems.

Example 2 Let A = {0,1}. Give a recurrence relation for c„, the number of strings of length
n in A* that do not contain adjacent 0's.

Solution
Since 0 and 1 are the only strings of length 1, c\ =2. Also, c2 = 3; the only such
strings are 01,10,11. In general, any string w of length n -1 that does not contain
00 can be catenated with 1 to form a string 1 • w, a string of length n that does not
contain 00. The only other possible beginning for a "good" string of length n is
01. But any of these strings must be of the form 01 • v9 where v is a "good" string
of length n —2. Hence, cn = cn-\ + cn-2 with the initial conditions c\ = 2 and
c2 = 3. ♦

Example 3 Suppose we wish to print outall ^-element sequences without repeats that canbe
made from the set {1,2, 3,..., n}. One approach to this problem is to proceed
recursively as follows.
Step 1 Produce a list of all sequences without repeats that can be made from
{l,2,3,...,/i-l}.
Step 2 For each sequence in step 1, insert n in turn in each of the n available
places (at the front, at the end, and between every pair of numbers in the
sequence), print the result, and remove n.
The number of insert-print-remove actions is the number of n-element sequences.
It is also clearly n times the number of sequences produced in step 1. Thus we
have

number of n-element sequences = n x (number of (w —l)-sequences).


This gives a recursive formula for the number of n-element sequences. What is the
initial condition? ♦

One technique for finding an explicit formula for the sequence defined by a
recurrence relation is backtracking, as illustrated in the following example.

Example 4 Therecurrence relation an = an-\+3 with a\ = 2 defines thesequence 2, 5, 8,


We backtrack the value of an by substituting the definition of an_i, art_2, and so
on until a pattern is clear.
an = an-\ +3 or an = an-\ + 3
= (flB_2 + 3) + 3 = an-2 + 2-3
= ((an-3 + 3) + 3) + 3 = an-3 + 3-3
114 Chapter 3 Counting
Eventually this process will produce

an = £„_(„_!) + (n - 1) • 3
= a\ + (n - 1) • 3
= 2 + (/i — 1) • 3.

An explicit formula for the sequence is an = 2 + (n - 1)3. ♦

Example 5 Backtrack to find an explicit formula for the sequence defined by the recurrence
relation bn = 2bn-\ + 1 with initial condition b\ = 7.

Solution
We begin by substituting the definition of the previous term in the defining for
mula.

bn = 2bn-{ + 1
= 2(2ftn_2 + 1) + 1
= 2[2(2fc„_3 + 1) + 1] + 1
= 23^_3+4 + 2+1
= 23Z>„_3 + 22 + 21 + l.
A pattern is emerging with these rewritings of bn. (Note: There are no set rules for
how to rewrite these expressions and a certain amount of experimentation may be
necessary.) The backtracking will end at

bn = 2"-1fc„_(K-i) + 2n~2 + 2""3 + ••. + 22 + 21 + 1


= 2n~lbi + 2n~l - 1 using Exercise 3, Section 2.4
= 7-2"-1+2n-1-l using fei =7
= 8-2""1-l or 2"+2-l. 4
Two useful summing rules were proved in Section 2.4. We record them again
for use in this section.

SI. 1+a+a2 +a3 + •••+an~x = °—Z±


a-\
n(n + 1)
S2. l+2 + 3 + .-- + n =
2
Backtracking may not reveal an explicit pattern for the sequence defined by
a recurrence relation. We now introduce a more general technique for solving a
recurrence relation. First we give a definition. A recurrence relation is a linear
homogeneous relation of degree k if it is of the form

an = r\an-\ + r2<zn-2 H h r^an-k with the r/'s constants.

Note that on the right-hand side, the summands are each built the same (homoge
neous) way, as a multiple of one of the k (degree k) previous terms (linear).

Example 6 (a) The relation cn = (—2)cn-\ is a linear homogeneous recurrence relation of


degree 1.
(b) The relation an = an-\ + 3 is not a linear homogeneous recurrence relation.
(c) The recurrence relation fn = fn_\ + fn_2 is a linear homogeneous relation of
degree 2.
3.5 Recurrence Relations 115

(d) The recurrence relation gn = gl_x+gn-2 isnot a linear homogeneous relation.

For a linear homogeneous recurrence relation of degree k, an = r\an-\ +


r2an-2-\ \-nan-ki wecall theassociated polynomial ofdegree k,xk = r\xk~x +
r2xk~2 + ••• + J-*, its characteristic equation. The roots of the characteristic
equation play a key role in the explicit formula for the sequence defined by the
recurrence relation and the initial conditions. While the problem can be solved
in general, we give a theorem for degree 2 only. Here it is common to write the
characteristic equation as x2 —r\x —r2 = 0.
THEOREM 1 (a) If the characteristic equation x2 —r\x —r2 = 0 of the recurrence relation
an —r\an-\ + r2an-2 has two distinct roots, s\ and s2, then an = us" + vs%,
where u and v depend on the initial conditions, is the explicit formula for the
sequence.
(b) If the characteristic equation x2 —r\x —r2 = 0 has a single roots, the explicit
formula is an = usn + vns", where u and v depend on the initial conditions.

Proof
(a) Suppose that s\ and s2 areroots ofx2 —r\x —r2 = 0, sos2 —r\s\ - r2 = 0,
s\ —r\s2 —r2 = 0, and an = us" + vs^, for n > 1. We show that this
definition of an defines the same sequence as an = r\an-\ + r2an-2. First
we note that uand v are chosen sothat a\ = us\+vs2 and a2 = us2 + vs\
and so the initial conditions are satisfied. Then

an = us" + vsf2 split out s2 and s\.


= us"~2s2 + vsl~2s\ substitute for s2 and s\.
= us"~2(r{s\ + r2) + vs2~2(r\s2 + r2)
= r{us"~l + r2us"~2 + rxvsl~x + r2vs\~2
= rx(us"x~x + vs%-1) + r2(us"x-2 + vs^2)
= r\an-.\ + r2an-2 use definitions of an-\
and an-2.

(b) This part may be proved in a similar way. •

This direct proof requires that we find a way to use what is known about s\
and s2. We know something about s2 and s^, and this suggests the first step ofthe
algebraic rewriting. Finding a useful first step in a proof may involve some false
starts. Be persistent.

Example 7 Find an explicit formula for the sequence defined by cn = 3cn-\ —2cn-2 with
initial conditions c\ = 5 and c2 = 3.

Solution
The recurrence relation cn = 3cn-\ —2cn-2 is a linear homogeneous relation of
degree 2. Its associated equation is x2 = 3x —2. Rewriting this asx2—3x+2 = 0,
we see there are two roots, 1 and 2. Theorem 1(a) says we can find u and v so that
c\ = u(\) + v(2) and c2 = u(\)2 + v(2)2. Solving this 2x2 systemyields u is 7
and v is —1.
116 Chapter 3 Counting

By Theorem 1, we have cn = 1 • \" + (-1) •2" or cn = 1 - 2". Note that using


cn = 3cn-\ - 2cn-2 with initial conditions c\ = 5 and c2 = 3 gives 5, 3, -1, —9
as the first four terms of the sequence. The formula cn = 1 —2" also produces 5,
3, —1, —9 as the first four terms. ♦

Example 8 Solve the recurrence relation dn = 2dn-\ —dn-2 with initial conditions d\ = 1.5
and d2 = 3.

Solution
The associated equation for this linear homogeneous relation is x2 —2x + 1 = 0.
This equation has one (multiple) root, 1. Thus, by Theorem 1(b), dn = u(\)n +
vn(\)n. Using this formula and the initial conditions, d\ = 1.5 = u + v(l) and
d2 = 3 = u + v(2), we find that u is 0 and v is 1.5. Then d„ = l.5n. ♦

The Fibonacci sequence in Example 1(b) is a well-known sequence whose


explicit formula took over two hundred years to find.

Example 9 The Fibonacci sequence is defined by a linear homogeneous recurrence relation


of degree 2, so by Theorem 1, the roots of the associated equation are needed
to describe the explicit formula for the sequence. From /„ = /n_i + fn_2 and
f\ = f2 = 1, wehave x2 —x —1 = 0. Using the quadratic formula to obtain the
roots, we find

1+V5 j 1-V5
s\ = —-— and s2 = —-—.

It remains to determine the u and v of Theorem 1. We solve

,=u(l±^\+J^\ and ,..(!±^Y+.(i^lY.


Forthe given initial conditions, u is 4= and v is —4=. The explicit formula for the
Fibonacci sequence is

Sometimes properties of a recurrence relation are useful to know. Because of


the close connection between recurrence (recursion) and mathematical induction,
proofs of these properties by induction are common.

Example 10 For the Fibonacci numbers in Example 1(b), /„ < (|)'\ This gives a bound on
how fast the Fibonacci numbers grow.

Proof (by strong induction)

Basis Step
Here no is 1. P(l) is 1 < f and this isclearly true.
3.5 Recurrence Relations 117

Induction Step
We use P(j), j < kto show P(k + 1): fM < (f)*+1. Consider the left-hand
side of P(k + l):

fk+l = fk + fk-l

•(ir(i+o
•(irG)
<(rw
= 1-1 , the right-hand sideof P(k + 1). ♦

3.5 Exercises
/rc Exercises 1 through 6, give the first four terms and identify 13. bn = 5bn.x+3,bx =3
the given recurrence relation as linear homogeneous or not. If 14. cn =c„_i + w, c\ =4
the relation is a linear homogeneous relation, give its degree.
15. dn = —1.14,-1» d\ — 5
1. an =2.5fln_i,0i =4
16. en = en-\ —2,e\ =0
2. bn = —3bn-{ —2bn-2, b\ = —2, b2 = 4
17. gn =rtg„_i,gi =6
3. cn = 2/,c„_i, ci = 3
In Exercises 18 through 23, solve each of the recurrence rela
4. dn =ndn-l,dl =2
tions.
5. e„ = 5en-\ + 3, «i = 1
18. an = 4<2„_i -j- 5a„_2, ax = 2, a2 = 6
<>• gn = V&i-l + £*-2> gl = 1, #2 = 3
19. bn = -3V, - 2V2, bx = -2, fc2 = 4
7. Let A = {0,1}. Give a recurrence relation for the number
of strings of length n in A* that do not contain 01. 20. cn = -6cn-i - 9c„_2, c, = 2.5, c2 = 4.7

8. Let A = {0,1}. Give a recurrence relation for the number 21. dn = 44,_i - 44-2, dx = 1, d2 = 1
of strings of length n in A* that do not contain 111. 22. en = 2en-2, ex = yfl, e2 = 6
9. On the first of each month Mr. Martinez deposits $100 in a 23. g„ = 2g„_1 - 2g„_2, g\ = 1, g2 = 4
savings account that pays 6% compounded monthly. As 24. Develop a general explicit formula for a nonhomogeneous
suming that no withdrawals are made, give a recurrence recurrence relation of the form an = ran-\ + s, where r
relation for the total amount of money in the account at and 5 are constants.
the end of n months.
25. Test the results of Exercise 24 on Exercises 13 and 16.
10. An annuity of $10,000 earns 8% compounded monthly.
Each month $250 is withdrawn from the annuity. Write a 26. Let rn be the number of regions created by n lines in the
recurrence relation for the monthly balance at the end of plane, where each pair of lines has exactly one point of
n months. intersection.

11. A game is played by moving a marker ahead either 2 or 3 (a) Give a recurrence relation for rn.
steps on a linear path. Let cn be the number of different (b) Solve the recurrence relation of part (a).
ways a path of length n can be covered. Give a recurrence 27. Let an be the number of ways a set with n elements can
relation for cn. be written as the union of two disjoint subsets.
In Exercises 12 through 17, use the technique of backtrack (a) Give a recurrence relation for an.
ing to find an explicit formula for the sequence defined by the (b) Solve the recurrence relation of part (a).
recurrence relation and initial condition(s).
28. Prove Theorem 1(b). (Hint: Find the condition on rx and
12. an = 2.5<2„_i, ax—A r2 that guarantees that there is one solution s.)
118 Chapter 3 Counting

29. Solve the recurrence relation of Example 2. (b) Solve the recurrence relation.
30. Using the argument in Example 3 for „Pr would produce 35. Solve the recurrence relation an = —2an-X + 2an-2 +
nPr = r • nP,—x. But this is easily shown to be false for 4a/,_3, ax = 0, a2 = 2, #3 = 8.
nearly all choices of n and r. Explain why the argument 36. Use mathematical induction to prove that for the recur
is not valid. rence relation b„ = bn.x + 2bn-i, bx = 1, b2 = 3,
31. For the Fibonacci sequence, prove that for n > 2, ^ < (!)"•
Jn+X ~~ Jn = Jn-\Jn+2- 37. Use mathematical induction to prove that for the re
currence relation an = 2a„_i + fl„_2, ax = 10,
32. Solve the recurrence relation of Exercise 7.
a2 = 12, 5 | a3«+i» w > 0.
33. Solve the recurrence relation of Exercise 9. 38. Let A], A2, A3,..., An+X each be a /: x &matrix. Let Cn
be the number of ways to evaluate the product Ai x A2 x
Theorem 1 can be extended to a linear homogeneous relation
A3 x • • • x AH+| by choosing different orders in which to
of degree k, an = rxan-X + r2an-2 + • •• + rkan-k. If the
do the n multiplications. Compute CXy C2, C3, C4, C5.
characteristic equation has k distinct roots sx,s2,..., fy, then
an = uxs1 + u2s\x + •• • + Uksl, where ux, u2,..., w* depend 39. Give a recurrence relation for Cn (defined in Exercise 38).
on the initial conditions.
40. Verify that Cn = is a possible solution to the recur
/i + 1
34. Let an = lan~2 + 6fl„_3, ax = 3, a2 = 6, a3 = 10. rence relation of Exercise 39 by showing that this formula
(a) What is the degree of this linear homogeneous rela produces the first fi\e values as found in Exercise 38. (The
tion? terms of this sequence are called the Catalan numbers.)

Tips for Proofs


Proofs based on the pigeonhole principle are introduced in this chapter. Two sit
uations are possible; the pigeons and pigeonholes are implicitly defined in the
statement of the problem (Section 3.3, Exercise 5) or you must create pigeons and
pigeonholes by defining categories into which the objects must fall (Section 3.3,
Exercises 12 and 13). In the first case, the phrases "at least k objects" "have the
same property" identify the pigeons (objects) and the labels on the pigeonholes
(possible properties).
Proofs of statements about nCr and nPr are usually direct proofs based on the
definitions and elementary algebra. Remember that a direct proof is generally the
first approach to try.

• Key Ideas for Review


Theorem (The Multiplication Principle): Suppose two tasks can be formed from a collection of n objects where the first
Tx and T2 are to be performed in sequence. If Tx can be object appears kx times, the second object k2 times, and so
performed in nx ways and for each of these ways T2 can be on, is k,/|!,„A.,, where kx + k2 -\ hk{ = n.
performed in n2 ways, then the sequence Tx T2 can be per • Combination of n objects taken r at a time: a subset of r
formed in nxn2 ways. elements taken from a set with n elements
Theorem (The Extended Multiplication Principle): see page
• Theorem: Let A be a set with \A\ = n and let 0 < r < n.
92
Then „Cr, the number of combinations of the elements of
Theorem: Let A be a set with n elements and 1 < r < n. A, taken r at a time, is "! ...
Then the number of sequences of length r that can be
• Theorem: Suppose k selections are to be made from n items
formed from elements of A, allowing repetitions, is n''.
without regard to order and that repeats are allowed, assum
Permutation of n objects taken r at a time (1 < r < n): a ing at least k copies of each of the n items. The number of
sequence of length r formed from distinct elements ways these selections can be made is („+;._ dQ.
Theorem: If 1 < r < n, then „P,., the number of permuta • The pigeonhole principle: see page 101
tions of n objects taken r at a time, is n • (n — 1) • (n —2) •
....(n-r+Dorj^jf. • The extended pigeonhole principle: see page 102
Permutation: an arrangement of n elements of a set A into a • Sample space: the set of all outcomes of an experiment
sequence of length n • Event: a subset of the sample space
Theorem: The number of distinguishable permutations that • Certain event: an event certain to occur
Experiment 3 119

• Impossible event: the empty subset of the sample space Expected value: the sum of the products (valueof at) •
(p(aj)) for all outcomes a, of an experiment
• Mutually exclusive events: any two events E and F with
Recurrence relation: a recursive formula for a sequence
EHF = {}
Initial conditions: information about the beginning of a re
• fE: the frequency of occurrence of the event E in n trials cursively defined sequence
• p(E): the probability of event E Linear homogeneous relation of degree k: a recurrence re
lation of the form a„ = rxan-X+ r2an-2 H h rkan-k with
• Probability space: see page 107
the r,'s constants
• Elementary event: an event consisting of just one outcome Characteristic equation: see page 115
• Random selection: see page 108 Catalan numbers: see page 118

• Chapter 3 Self-Test
1. How can you decide whether combinations or permuta (b) record sequences begin 1,2?
tions or neither should be counted in a particular counting The IC Shoppe has 14 flavors of ice cream today. If you
problem? allow repeats, how many different triple-scoop ice cream
2. What are some clues for deciding how to define pigeons cones can be chosen? (The order in which the scooping is
and pigeonholes? done does not matter.)

3. What are some of the advantages and disadvantages of the 10. The Spring Dance Committee must have 3 freshman and
recursive form of a recurrence relation? 5 sophomore members. If there are 23 eligible freshmen
and 18 eligible sophomores, how many different commit
4. What are some of the advantages and disadvantages of the tees are possible?
solution form of a recurrence relation?
11. Show that 2nC2 = 2 •nC2 + n2.
5. What is our primary tool (from previous work) for an
12. Pizza Quik always puts 50 pepperoni slices on a pepper-
swering probability questions?
oni pizza. If you cut a pepperoni pizza into eight equal
6. Compute the number of size pieces, at least one piece must have pepperoni
(a) five-digit binary numbers. slices. Justify your answer.
(b) five-card hands from a deck of 52 cards. 13. Complete and prove the following statement. At least
months of the year must begin on the same day
(c) distinct arrangements of the letters of DISCRETE. of the week.
7. A computer program is used to generate all possible six- 14. What is the probability that exactly two coins will land
letter names for a new medication. Suppose that all the heads up when five fair coins are tossed?
letters of the English alphabet may be used. How many
possible names can be formed 15. Let p(A) = 0.29, p(B) = 0.41, and p(A U B) = 0.65.
Are A and B mutually exclusive events? Justify your an
(a) if the letters are to be distinct? swer.

(b) if exactly two letters are repeated? 16. Solve the recurrence relation b„ = lbn-X — I2bn_2, bx =
8. A fair six-sided die is rolled five times. If the results of hb2 = 7.
each roll are recorded, how many 17. Develop a formula for the solution of a recurrence relation
(a) record sequences are possible? of the form an = man-X — \,ax = m.

| Experiment 3
The purpose of this experiment is to introduce the concept of a Markov chain. The
investigations will use your knowledge of probability and matrices.
Suppose that the weather in Acia is either rainy or dry. We say that the weather
has two possible states. As a result of extensive record keeping, it has been deter
mined that the probability ofa rainy day following a dry day is |, and the proba
bilityof a rainy dayfollowing a rainy day is 5. If we know the weather today, then
we can predict the probability that it will be rainy tomorrow. In fact, if we know
the state in which the weather is today, then we can predict the probability for each
possible state tomorrow. A Markov chain is a process in which the probability of
120 Chapter 3 Counting

a system's being in a particular state at a given observation period depends only


on its state at the immediately preceding observation period. Let ttj be the prob
ability that if the system is in state j at a certain observation period, it will be in
state i at the next period; ty is called a transition probability. It is convenient to
arrange the transition probabilities for a system with n possible states as an n x n
transition matrix. A transition matrix for Acia's weather is

D R

" 2 1 '
3 2
T = i i
i i

_ 3 <. _,R
2 _

1. What is the sum of the entriesin each columnof T? Explain why this must be
the same for each column of any transition matrix.
The transition matrix of a Markov chain can be used to determine the proba
bility of the system being in any of its n possible states at future times. Let

p(*) = p?

LP(nk)J
denote the state vector of the Markov chain at the observation period k, where
pj* is the probability that the system is in state j at the observation period k. The
state vector P(0) is called the initial state vector.
2. Suppose today, a Wednesday, is dry in Acia and this is observation period 0.
(a) Give the initial state vector for the system.
(b) What is the probability that it will be dry tomorrow? What is the proba
bilitythat it will be rainy tomorrow? GiveP(1).
(c) Compute TP(0). What is therelationship between TP(0) andP(1)?
It can be shown that, in general, P(*} = T*P(0). Thusthe transition matrix and
the initial state vector completely determine every other state vector.
3. Using the initial state vector from part 2, what is the state vector for next
(a) Friday?
(b) Sunday?
(c) Monday?
(d) What appears to be the long-term behavior of this system?
In some cases the Markov chain reaches an equilibrium state, because the state
vectors converge to a fixed vector. This vector is called the steady-state vector.
The most common use of Markov chains is to determine long-term behavior, so it
is important to know if a particular Markov chain has a steady-state vector.
4. Let

T = and P(0) =

Compute enough state vectors to determine the long-term behavior of this


Markov chain.
Experiment 3 121

A transition matrix T of a Markov chain is called regular if all the entries in


some power of T are positive. If a Markov chain has a regular transition matrix,
then the process has a steady-state vector. One way to find the steady-state vector,
if it exists, is to proceed as in question 3; that is, calculate enough successive
state vectors to identify the vector to which they are converging. Another method
requires the solution of a system of linear equations. The steady-state vector U
must be a solution of the matrix equation TU = U, and the entries of U have a
sum equal to 1.
5. Verify that the transition matrix for the weather in Acia is regular and that the
transition matrix in part 4 is not regular.
6. Solve
o i ~i r
x

with the condition that x + y = 1. Compare your solution with the results of
part 3.
7. Consider a plant that can have red (R), pink (P), or white (W) flowers de
pending on the genotypes RR, RW, and WW. When we cross each of these
genotypes with genotype RW, we have the following transition matrix.
Flowers of parent plant
R P w

R
"0.5 0.25 0.0
Flowers of
P 0.5 0.50 0.5
offspring plant
W
0.0 0.25 0.5

Suppose that each successive generation is produced by crossing only with


plants of RW genotype.
(a) Will the process reach an equilibrium state? Why or why not?
(b) If there is a steady-state vector for this Markov chain, what are the long-
term percentages of plants with red, pink, and white flowers?
In Acia there are two companies that produce widgets, Widgets, Inc., and
Acia Widgets. Each year Widgets, Inc., keeps one-fourth of its customers
while three-fourths switch to Acia Widgets. Each year Acia Widgets keeps
two-thirds of its customers and one-third switch to Widgets, Inc. Both com
panies began business the same year and in that first year Widgets, Inc., had
three-fifths of the market and Acia Widgets had the other two-fifths of the
market. Under these conditions, will Acia Widgets ever run Widgets, Inc., out
of business? Justify your answer.
CHAPTER

4 Relations and Digraphs


Prerequisites: Chapters 1 and 2

Relationships between people, numbers, sets, and many other entities can be for
malized in the idea of a binary relation. In this chapter we develop the concept of
binary relation, and we give several different methods of representing such objects.
We also discuss a variety of different properties that a binary relation may possess,
and we introduce important examples such as equivalence relations. Finally, we
introduce several useful types of operations that may be performed on binary rela
tions. We discuss these operations from both a theoretical and computational point
of view.

Looking Back
According to John N. Warfield, the theory of relations was de was given by the great British philosopher and mathematician
veloped by Augustus De Morgan, who we met in Chapter 1. Bertrand Russell in 1919.
Warfield also notes that the earliest illustration of a digraph

Bertrand Russell

122
4.1 Product Sets and Partitions 123

4.1 Product Sets and Partitions

Product Sets
An ordered pair (a, b) is a listing of the objects a and b in a prescribed order,
with a appearing first and b appearing second. Thus an ordered pair is merely a
\* sequence of length 2. From our earlier discussion of sequences (see Section 1.3) it
A\ r 5

follows that the ordered pairs (a\, b\) and (a2, bi) are equal if and only if a\ = a2
1 (l,r) (U)
and b\ = b2.
2 (2,r) (2,s)
If A and B are two nonempty sets, we define the product set or Cartesian
3 (3,r) (3,s) product A x B as the set of all ordered pairs (a, b) with a G A and b e B. Thus
Figure 4.1 Ax B = {(a, b)\a eAandbe B}.

Example 1 Let
A = {1,2,3} and B = {r,s}\
then
AxB = {(1, r), (1, s), (2, r), (2, s), (3, r), (3, *)}.
Observe that the elements ofAxB can be arranged in a convenient tabular array
as shown in Figure 4.1. ♦

Example 2 If A and B areas in Example 1,then


B x A = {(r, 1), (s, 1), (r, 2), (s, 2), (r, 3), (s, 3)}. ♦

THEOREM 1 For any two finite, nonempty sets A and B, \A x B\ = \A\ \B\.

Proof
Suppose that \A\ = m and \B\ = n. To form an ordered pair (a,b), a € A and
b e J5, we must perform two successive tasks. Task 1 is to choose a first element
from A, and task 2 is to choose a second element from B. There are m ways to
perform task 1 and n ways to perform task 2; so, by the multiplication principle
(see Section 3.1), there are m x n ways to form an ordered pair (a,b). In other
words, \A x B\ = m • n = |A| • |B|. •

Example 3 If A = 5 = E, the set of all real numbers, then IxR, also denoted by 1R2, is
the set of all points in the plane. The ordered pair (a, b) gives the coordinates of a
point in the plane. ♦

Example 4 A marketing research firm classifies a person according to thefollowing two crite
ria:

Gender: male (m); female (/)


Highest level ofeducation completed: elementary school (e)\
high school (h)\ college (c); graduate school (g)
Let S = {m, /} and L = {e, h, c, g}. The product set S x L contains all the
categories into which the population is classified. Thus the classification (/, g)
represents a female who has completed graduate school. There are eight categories
in this classification scheme. ♦

We now define the Cartesian product of three or more nonempty sets by gen
eralizing the earlier definition of the Cartesian product of two sets. That is, the
124 Chapter 4 Relations and Digraphs
Cartesian product Ax x A2 x • • • x A„ of the nonempty sets A1, A2,..., Am is
the set of all ordered m-tuples (ax,a>i, • ., am), where a-, e A/, i = 1, 2,..., m.
Thus

Ai x A2 x ••• x A,„ = {(ax,a2i ...,am) \ a{ e A/, / = 1, 2,..., m}.

Example 5 A manufacturer offers the following options for its refrigerators:


Doors: side-by-side (s), over-under (w), three (t)
Icemaker: freezer (/), door (d)
Finish: standard (r), metallic (m), custom (c)
Let D = {s, w, /}, / = {/, d}, and F = {r, m, c}. Then the Cartesian product
D x / x F contains all the categories that describe refrigerator options. There are
3 • 2 • 3 or 18 categories. ♦

Proceeding in a manner similar to that used to prove Theorem 1, using the


extended multiplication principle, we can show that if Ax has nx elements, A2
has n2 elements, ..., and A,„ has nm elements, then A\ x A2 x • • • x Am has
nx - n2 • nm elements.
The remainder of this chapter uses only ordered pairs, but there are many
applications for ordered n-tuples. One application is to represent records in a
database, a collection of data usually stored in a computer. A relational database
D is a subset of Ax x A2 x •• • x A„9 where each A/ designates a characteristic
or attribute of the data. Each n-tuple in D is a single record of related informa
tion. In a relational database there must be a single attribute (or set of attributes)
whose value(s) in a record uniquely identifies the record. This attribute (or set of
attributes) is called a key.
Table 4.1 shows part of a relational database, Employees, that contains in
formation about a company's employees. The attributes are Employee ID, Last
Name, Department, and Years with Company. The attribute Employee ID is the
key for this database. For ease in reading the information, the 4-tuples are dis
played without parentheses in this table.

Employee ID ^ajStNaine Department Years with Company


8341; Front office 1 t;
7984 Cojtoiigiin ;iSale)s- ' 2
2086 'King "> Htuuan Resources 4
0340 BosweU Rekeareh 3
7182 Chin Huidan Resources 3
1748 Harris Sales 1

4039 Gonzalez Public Relations 6


4596 Greene Human Resources 1
2914 Salainat Sales 5
5703 Sahni Research 7
3465 Harris Sales 4
4.1 Product Sets and Partitions 125

Inserting or deleting records in the database is straightforward, since by using the


key we do not have to maintain a fixed order and can retrieve any single record
directly. Database management also requires the ability to answer queries about
the data. Two basic operations on a database D are sufficient to answer most
queries.
The select operation retrieves the set of records in D that satisfy a specific
condition. Thus, select D[ail = required^ ai2 = required2, ...,aik = required^
is the set of records in D that have the values required^ required^ ..., requiredk
in the positions i\, i2,..., i*, respectively. In practice, it is common to use the
attribute names to specify the positions. Referring to Table 4.1, we see that

select EmployeesfDepartment = Human Resources]


= {(2086, King, Human Resources, 4),
(7182, Chin, Human Resources, 3),
(4596, Greene, Human Resources, 1)}.

This example shows that retrieving entire records may be cumbersome, presenting
more information than is required to answer the query.
The project operation allows us to report partial records with only specified
attributes. The setproject D[Ai{, A/2,..., Aik] is the set of fc-tuples with attributes
A,-,, A/2,..., Aik such that (bi{, bi2,..., bik) € project D[Ai{, A/2,..., Aik\ if
and only if there is an n-tuple (a\, a2,..., an) e D with 6,-. = a,-., j = 1,..., k.
That is, (ft,-,,6,-2, ...,bik) is formed by choosing the values of the specified at
tributes for a record in D and omitting the others. Select can be viewed as
choosing rows in the table, while project chooses columns from the table. From
Table 4.1 we have project Employees [Employee ID, Years with Company]
= {(8341,2), (7984,2), (2086,4), (0340,3), (7182,3), (1748,1), (4039,6),
(4596, 1), (2914,5), (5703,7), (3465,4)}. The operations select and project
can be combined to produce only the data required by the query. For example,
project(select Employees[Years with Company > 5])[Employee ID, Last Name]
= {(4039, Gonzalez), (2914, Salamat), (5703, Sahni)} answers the question, Who
are the employees who have worked for the company for at least 5 years?

Partitions

A partition or quotient set of a nonempty set A is a collection P of nonempty


subsets of A such that

1. Each element of A belongs to one of the sets in P.


2. If A] and A2 are distinct elements of P, then A\HA2 = 0.
A
The sets in P are called the blocks or cells of the partition. Figure 4.2 shows
Figure 4.2 a partition P = {Ax, A2, A3, A4, A5, A$, A7} of A into seven blocks.

Example 6 Let A = {a,b,c, d, e, /, g, h}. Consider thefollowing subsets of A:

A\ = [a, b, c, d], A2 = {a, c, e, f, g, h], A3 = [a, c, e, g],


A4 = {b,d), A5 = {/,A}.

Then {Aj, A2] is not a partition since A\ n A2 ^ 0. Also, {Ai, A$) is not a
partition since e £ A\ and e £ A5. The collection P = {A3, A4, A$] is a partition
of A. ♦
126 Chapter 4 Relations and Digraphs
Example 7 Let
Z = set of all integers,
Ai = set of all even integers, and
A2 = set of all odd integers.
Then {Ax, A2} is a partition of Z,

Since the members of a partition of a set A are subsets of A, we see that


the partition is a subset of P(A), the power set of A. That is, partitions can be
considered as particular kinds of subsets of P(A).

4.1 Exercises

In Exercises 1 through 4, find x or y so that the statement is In Exercises 12 and 13, let A = {a \ a is a real number] and
true. B = {1, 2, 3}. Sketch the given set in the Cartesian plane.
1. (a) (*, 3) = (4, 3) (b) (a, 3)0 = (fl, 9) 12. Ax B 13. B xA

2. (a) (3jc + 1,2) = (7,2) In Exercises 14 and 15, let A = {a \ a is a real number and
(b) (C++, PASCAL) = (y, *) —2 < a < 3} and B = {b \bisa real number and 1 < b < 5}.
Sketch the given set in the Cartesianplane.
3. (a) (4*,6) = (16,y)
14. A x B 15. B xA
(b) (2*-3,3y-l) = (5,5)
16. Show that if Ax has nx elements, A2 has n2 elements, and
4. (a) (x\ 25) = (49, y) (b) (jc, y) = (x\ y2) A3 has n3 elements, then Ax x A2 x A3 has nx • n2 • n3
elements.
In Exercises 5 and 6, let A = {a, b] and B = {4, 5, 6}.
17. If A c C and B c D, prove that A x B c C x D.
5. List the elements in

(a) A x B (b) B x A /n Exercises 18 through21, refer to Table4.1, Employees. Use


the operations select, project, and standard set operations to
6. List the elements in
describe the answers to thefollowing queries.
(a) A x A (b) B x 5
18. Who works in either Public Relations or Research?
7. Let A = {Fine, Yang} and 5 = {president, vice-
president, secretary, treasurer}. Give each of the follow 19. What are the names of the employees in the Human Re
ing. sources department?
(a) A x B (b) B xA (c) A x A 20. How many employees are there in Sales?
8. A genetics experiment classifies fruit flies according to 21. How many years has each of the employees in Research
the following two criteria: worked for the company?

Gender: male (m), female (/) In Exercises 22 and 23, let A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
and
Wingspan: short (s), medium (m), long (/)
A, = {1,2,3,4}, A2 = {5,6,7}
(a) How many categories are there in this classification?
A3 = {4, 5, 7, 9}, A4 = {4, 8, 10}
(b) List all the categories in this classification scheme.
A5 = {8, 9,10}, A6 = {1, 2, 3, 6, 8, 10}.
9. A car manufacturer makes three different types of car
frames and two types of engines. 22. Which of the following are partitions of A?
(a) {AX,A2,A5} (b) {A!,A3,A5}
Frame type: sedan (s), coupe (c), van (v)
Engine type: gas (g), diesel (d) 23. Which of the following are partitions of A?
(a) {A3,A6} (b) {A2,A3,A4]
List all possible models of cars.
24. If A i is the set of positive integers and A2 is the set of
10. If A = {a, b, c}, B = {1, 2}, and C = {#, *}, list all the all negative integers, is {Ax, A2] a partition of Z? Explain
elements of Ax B x C. your conclusion.
11. If A has three elements and B has n > 1 elements, use 25. Explain the difference between an exact cover of a set T
mathematical induction to prove that \A x B\ = 3n. and a partition of T.
4.2 Relations and Digraphs 127

26. (a) Give an example of a set T, \T\ = 6, and two parti subsets, that is, 5(3, 2). Compare your result with the re
tions of T. sults of Exercise 31.

(b) For the set T in part (a), give a nonempty collection 34. Find the number of partitions of a set with four elements
of subsets for which T has no exact cover. into two subsets using the recurrence relation in Exercise
33. Compare the result with the results of Exercise 32.
For Exercises 27 through 29, use A = {a, b, c,..., z].
35. Find the number of partitions of a set of cardinality 4 into
27. Give a partition P of A such that |^| = 4 and one ele three subsets.
ment of P contains only the letters needed to spell your 36. Find the number of partitions of a set of cardinality 5 into
first name.
two subsets.
28. Give a partition P of A such that \P\ = 3 and each ele 37. Let A, B, and C be subsets of U. Prove that A x (BUC) =
ment of <JP contains at least five elements. (A x B) U (A x C).
29. Is it possible to have a partition P of A such that ^ = 38. Use the sets A = {1,2,4}, B = {2,5,7}, and C =
{A,,A2, ...,A10}andV/ |A,| > 3? {1, 3, 7} to investigate whether Ax (BC\C) = (Ax B)D
30. If B = {0, 3, 6,9,...}, give a partition of B containing (A x C). Explain your conclusions.
(a) two infinite subsets. 39. Let A c. B. Describe how to use a partition of B to pro
(b) three infinite subsets. duce a partition of A. Justify your procedure.

31. List all partitions of A = {1, 2, 3}. 40. Let Px = {Ax,A2l Ak] be a partition of A and
P2 = {Bu B2,..., Bm] a partition of B. Prove that
32. List all partitions of B = {a, b, c, d]. P = [At x Bj, 1 < / < k, 1 < j < m] is a partition
33. The number of partitions of a set with n elements into k of A x B.
subsets satisfies the recurrence relation
41. (a) Construct a table of values for 5(n, /:), the number of
partitions of a set of cardinality n into k subsets for
S(n, k) = S(n - 1, k - 1) + k • S(n - 1, k)
n = 1, 2,..., 6, k = 1, 2,..., 6 (as appropriate).
with initial conditions S(n, 1) = S(n,n) = 1. Find the (b) Based on the results of part (a), describe a pattern for
number of partitions of a set with three elements into two the values of S (n, 2).

4.2 Relations and Digraphs


The notion of a relation between two sets of objects is quite common and intu
itively clear (a formal definition will be given later). If A is the set of all living
human males and B is the set of all living human females, then the relation F (fa
ther) can be defined between A and B. Thus, if x e A and y e B, then x is related
to y by the relation F if x is the father of y, and we write x F y. Because order
matters here, we refer to F as a relation from A to J?. We could also consider the
relations S and H from A to B by letting x S y mean that x is a son of y, and
x H y mean that x is the husband of y.
If A is the set of all real numbers, there are many commonly used relations
from A to A. Some examples are the relation "less than," which is usually denoted
by <, so that x is related to y if x < y, and the other order relations >, >, and <.
We see that a relation is often described verbally and may be denoted by a familiar
name or symbol. The problem with this approach is that we will need to discuss
any possible relation from one abstract set to another. Most of these relations have
no simple verbal description and no familiar name or symbol to remind us of their
nature or properties. Furthermore, it is usually awkward, and sometimes nearly
impossible, to give any precise proofs of the properties that a relation satisfies if
we must deal with a verbal description of it.
To solve this problem, observe that the only thing that really matters about
a relation is that we know precisely which elements in A are related to which
elements in B. Thus suppose that A = {1, 2, 3,4} and R is a relation from A to
A. If we know that 1 R 2, 1 R 3, 1 R 4, 2 R 3, 2 R 4, and 3 R 4, then we know
everything we need to know about R. Actually, R is the familiar relation <, "less
than," but we need not know this. It would be enough to be given the foregoing list
128 Chapter 4 Relations and Digraphs
of related pairs. Thus we may say that R is completely known if we know all R-
related pairs. Wecould then write R = {(1,2), (1, 3), (1,4), (2, 3), (2,4), (3,4)},
since R is essentially equal to or completely specified by this set of ordered pairs.
Each ordered pair specifies that its first element is related to its second element,
and all possible related pairs are assumed to be given, at least in principle. This
method of specifying a relation does not requireany specialsymbol or description
and so is suitable for any relation between any two sets. Note that from this point
of view a relation from A to B is simply a subset of A x B (giving the related
pairs), and, conversely, any subset of A x B can be considered a relation, even if
it is an unfamiliar relation for which we have no name or alternative description.
We choose this approach for defining relations.
Let A and B be nonempty sets. A relation R from A to B is a subset of
Ax B. If R <z Ax B and (a, b) e R, we say that a is related to b by R, and we
also write a R b. If a is not related to b by R, we write a ft b. Frequently, A and
B are equal. In this case, we often say that R c A x A is a relation on A, instead
of a relation from A to A.
Relations are extremely important in mathematics and its applications. It is
not an exaggeration to say that 90% of what will be discussed in the remainder of
this book will concern some type of object that may be considered a relation. We
now give a number of examples.

Example 1 Let A = {1,2, 3} and B = {r, s}. Then R = {(1, r), (2, s), (3, r)} is a relation
from A to B.

Example 2 Let A and B be sets of real numbers. We define the following relation R (equals)
from A to B:

a Rb if and only if a = b. ♦

Example 3 Let A = {1, 2, 3, 4, 5}. Define the following relation R (less than) on A:
a Rb if and only if a < b.

Then

R = {(1,2), (1,3), (1,4), (1,5), (2, 3), (2,4), (2, 5), (3,4), (3, 5), (4, 5)}. ♦

Example 4 Let A = Z+, the setof all positive integers. Define the following relation Ron A:
a Rb if and only if a divides b.

Then 4 R 12, but 5 #7. ♦

Example 5 Let A be the set of all people in the world. We define the following relation R
on A: a R b if and only if there is a sequence ao,ax,... ,an of people such that
ao = a, an = b and a-x-\ knows a,,i = 1, 2,..., n (n will depend on a and b). ♦

Example 6 Let A = M, the set of realnumbers. We define the following relation Ron A:
2 2
x y
x Ry if and only if x and y satisfy the equation 1 = 1.

The set R consists of all points on the ellipse shown in Figure 4.3. ♦
4.2 Relations and Digraphs 129

(0, -3)

Figure 4.3

Example 7 LetAbethesetof allpossible inputs to a given computer program, and let B bethe
set of all possible outputs from the same program. Define the following relation R
from A to B: a R b if and only if b is the output produced by the program when
input a is used. ♦

Example 8 Let A be thesetof all lines in theplane. Define the following relation R on A:
l\ R l2 if and only if l\ is parallel to l2. ♦

Example 9 An airline services the five cities c{, c2, c3, c4, andc5. Table 4.2 gives thecost(in
dollars) of going from c, to cj. Thus the cost of going from cx to c3 is $100, while
the cost of going from c4 to c2 is $200.

Nsxlb
c2 <?3 c4 cs
ci

WiMiiB ;,:i4|| SW;'::' 150 w


Vy£^^. 190 200 160 220

'^vMJ':' 110 180 190 250


c4 190 200 120 150

cs 200 100 200 150

We now define the following relation R on the set of cities A = {cx, c2, c3, c4,
c5}: Cj R Cj if and only if the cost of going from c, to c, is defined and less than
or equal to $180. Find/?.

Solution
The relation R is the subset of A x A consisting of all cities (q, c,), where the
cost of going from a to c7 is less than or equal to $180. Hence

A = {(Cl,C2), (C|,C3), (C1>C4), (<?2,C4), (C3>C\), (C3,C2),


(C4, C3), (C4, C5), (C5, C2), (c5, C4)}. ♦

Sets Arising from Relations


Let R c A x Z? be a relation from A to 5. We now define various important and
useful sets related to R.
130 Chapter 4 Relations and Digraphs
The domain of /?, denoted by Dom(tf), is the set of elements in A that are
related to some element in B. In other words, Dom(#), a subset of A, is the set
of all first elements in the pairs that make up R. Similarly, we define the range of
/?, denoted by Ran(/?), to be the set of elements in B that are second elements of
pairs in R, that is, all elements in B that are paired with some element in A.
Elements of A that are not in Dom(7?) are not involved in the relation R in any
way. This is also true for elements of B that are not in Ran(tf).

Example 10 If R is therelation defined in Example 1, then Dom(7?) = A andRan(#) = B. ♦

Example 11 If/? is therelation given in Example 3, then Dom(#) = {1, 2, 3,4} andRan(/?) =
{2,3,4,5}. ♦

Example 12 Let R be the relation of Example 6. Then Dom(#) = [-2, 2] and Ran(/?) =
[—3, 3]. Note that these sets are given in interval notation. ♦

If R is a relation from A to B and x e A, we define R(x), the /f-relative set


of x, to be the set of all y in B with the property that x is /?-related to y. Thus, in
symbols,
R(x) = {y e B | x R y].
Similarly, if Ax c A, then R(A\), the /{-relative set of Ai, is the set of all y in B
with the property that x is R-related to y for some x in A i. That is,
R(A\) = {y G B | x R y for some x in A\}.

Note that R(x) can also be written as R({x]), but we choose the simpler notation.
From the preceding definitions, we see that R(A\) is the union of the sets R(x)9
where x e A\. The sets R(x) play an important role in the study of many types of
relations.

Example 13 LetA = {a, b,c, d] and let R = {(a, a), (a, b), (b, c), (c,a), (d, c), (c, b)}. Then
R(a) = {a, b), R(b) = {c}, and if Ax = {c, d}9 then R(A{) = {a, b, c}. ♦

Example 14 Let R be the relation of Example 6, and let x € R. If x R y for some y, then
x2/4 + y2/9 = 1. We see that if x is not in the interval [-2, 2], then no y can
satisfy the preceding equation, since x2/4 > 1. Thus, in this case, R(x) = 0.
If x = -2, then x2/4 = 1, so x can only be related to 0. Thus R(-2) = {0}.
Similarly, R(2) = {0}. Finally, if —2 < x < 2 and x R y, then we must have
y = y/9 —(9jc2/4) or y = --^9 —(9x2/4), as we see by solving the equation
x2/4 + y2/9 = 1, so that R(x) = {y/9 - (9jc2/4), -y/9 - (9x2/4)}. Thus, for
example, R(l) = {(3^3)/2, -(3a/3)/2}. ♦

The following theorem shows the behavior of the 7?-relative sets with regard
to basic set operations.

THEOREM 1 Let R be a relation from A to B, and let A\ and A2 be subsets of A. Then:


(a) If A, c A2, then R(AX) c R(A2).
(b) R(AX U A2) = R(AX) U 7?(A2).
(c) R(AxnA2)<ZR(Ax)nR(A2).

Proof
(a) If y € /?(Ai), then jc R y for some jc € A\. Since Aj c A2, * G A2.
Thus, y e R(A2), which proves part (a).
4.2 Relations and Digraphs 131

(b) If y e R(AX U A2), then by definition x R y for some x in A\ U A2. If


x is in Ai, then, since x R y, we must have y e R(AX). By the same
argument, if jc is in A2, then y e R(A2). In either case, y e R(AX) U
R(A2). Thus we have shown that R(AX U A2) c R(AX) U #(A2).
Conversely, since Ai c (Ai U A2), part (a) tells us that R(AX) c
R(AX U A2). Similarly, R(A2) c #(Ai U A2). Thus R(A{) U 7?(A2) c
R(AX U A2), and therefore part (b) is true.
(c) If y e R(AX H A2), then, for some x in A\ n A2, jc /? y. Since a: is in
both A\ and A2, it follows that y is in both R(A\) and /?(A2); that is,
y e R(AX)H R(A2). Thus part (c) holds. •

The strategy of this proof is one we have seen many times in earlier sections:
Apply a relevant definition to a generic object.
Notice that Theorem 1(c) does not claim equality of sets. See Exercise 20 for
conditions under which the two sets are equal. In the following example, we will
see that equality does not always hold.

Example 15 Let A = Z, R be "<," Ax = {0, 1, 2}, and A2 = {9, 13}. Then R(A{) consists of
all integers n such that 0 < n, or 1 < n, or 2 < n. Thus R(AX) = {0, 1,2,...}.
Similarly, R(A2) = {9, 10,11,...}, so R(AX) n R(A2) = {9, 10, 11,...}. On the
other hand, Ax f) A2 = 0; thus R(AX fl A2) = 0. This shows that the containment
in Theorem 1(c) is not always an equality. ♦

Example 16 Let A = {1,2,3} and B = {x, y,z,w, p,q], and consider the relation R =
{(l,x),(l,z),(2,w;),(2,/7),(2,^,(3,j)}. Let A! = {1,2} and A2 = {2,3}.
Then R(A{) = {*, z, w, p, q] and R(A2) = [w, p, q, y}. Thus R(AX) U R(A2) =
B. Since A\ UA2 = A, we see that /?(Aj UA2) = R(A) = B, as stated in Theorem
1(b). Also, R(A{) fl R(A2) = {w, p, q] = R({2}) = R(A{ n A2), so in this case
equality does hold for the containment in Theorem 1(c). ♦

It is a useful and easily seen fact that the sets R(a), for a in A, completely
determine a relation R. We state this fact precisely in the following theorem.

THEOREM 2 Let R and S be relations from A to B. If R(a) = S(a) for all a in A, then # = S.

Proof
If a R b, then b e R(a). Therefore, b e S(a) and a S b. A completely similar
argument shows that, if a S b, then a R b. Thus R = S. •

The Matrix of a Relation

We can represent a relation between two finite sets with a matrix as follows. If
A = {ax,a2,..., am] and B = {bx, b2,..., bn] are finite sets containing m and
n elements, respectively, and R is a relation from A to 5, we represent R by the
mx n matrix M# = [ m/7 ], which is defined by

ma — {
fl if(a,-, fey)
J
eR
lJ 10 if (ai,bj)tR.

The matrix Mr is called the matrix of R. Often M/? provides an easy way to
check whether R has a given property.
132 Chapter 4 Relations and Digraphs

Example 17 Let R be the relation defined in Example 1. Then the matrix of R is


"l 0"
MR = 0 1
1 0

Conversely, given sets A and B with \A\ = m and \B\ = n, an m x n matrix


whose entries are zeros and ones determines a relation, as is illustrated in the
following example.

Example 18 Consider the matrix


10 0 1
M = 0 110
10 10

Since M is 3 x 4, we let

A = [a\,a2ia3] and B = {bx, b2, Z?3, £4}.

Then (ax, bj) e R if and only if mxj —1. Thus

R = {(aubi), (ax,bA), (a2, b2), (a2, Z?3), (<33, bx), (a3, 63)}. ♦

Figure 4.4

The Digraph of a Relation


If A is a finite set and R is a relation on A, we can also represent R pictorially as
follows. Draw a small circle for each element of A and label the circle with the
corresponding element of A. These circles are called vertices. Draw an arrow,
called an edge, from vertex ax to vertex aj if and only if ax R aj. The resulting
pictorial representation of R is called a directed graph or digraph of R.
Thus, if R is a relation on A, the edges in the digraph of R correspond exactly
to the pairs in R, and the vertices correspond exactly to the elements of the set A.
Sometimes, when we want to emphasize the geometric nature of some property of
R, we may refer to the pairs of R themselves as edges and the elements of A as
Figure 4.5 vertices.

Example 19 Let
A = {1,2, 3,4}
R = {(1,1), (1, 2), (2, 1), (2, 2), (2, 3), (2, 4), (3,4), (4,1)}.

Then the digraph of R is as shown in Figure 4.4. ♦

A collection of vertices with edges between some of the vertices determines a


relation in a natural manner.

Example 20 Find the relation determined by Figure 4.5.

Solution
Since at R aj if and only if there is an edge from ax to a$, we have

R = {(1, 1), (1, 3), (2, 3), (3, 2), (3, 3), (4, 3)}. ♦
4.2 Relations and Digraphs 133

In this book, digraphs are nothing but geometrical representations of relations,


and any statement made about a digraph is actually a statement about the corre
sponding relation. This is especially important for theorems and their proofs. In
some cases, it is easier or clearer to state a result in graphical terms, but a proof
will always refer to the underlying relation. The reader should be aware that some
authors allow more general objects as digraphs; for example, by permitting several
edges in the same direction between the same vertices.
An important concept for relations is inspired by the visual form of digraphs.
If R is a relation on a set A and a e A, then the in-degree of a (relative to the
relation R) is the number of b e A such that (b, a) € R. The out-degree of a is
the number ofbeA such that (a,b) e R.
What this means, in terms of the digraph of R, is that the in-degree of a vertex
is the number of edges terminating at the vertex. The out-degree of a vertex is the
number of edges leaving the vertex. Note that the out-degree of a is \R(a)\.

Example 21 Consider the digraph of Figure 4.4. Vertex 1 has in-degree 3 and out-degree 2.
Also consider the digraph shown in Figure 4.5. Vertex 3 has in-degree 4 and out-
degree 2, while vertex 4 has in-degree 0 and out-degree 1. ♦

Example 22 Let A = [a, b,c, d], and let R be the relation on A thathas thematrix

10 0 0
0 10 0
MR =
1110
0 10 1

Construct the digraph of /?, and list in-degrees and out-degrees of all vertices.

Solution
The digraph of R is shown in Figure 4.6. The following table gives the in-degrees
and out-degrees of all vertices. Note that the sum of all in-degrees must equal the
sum of all out-degrees.

a b c d
In-degree 2 3 1 1
Out-degree 1 1 3 2

Figure 4.6

Example 23 Let A = {1, 4, 5}, and let R be given by the digraph shown in Figure 4.7. Find
MR and R.

Figure 4.7
134 Chapter 4 Relations and Digraphs

Solution

0 1 1
1 1 0 , R = {(1,4), (1, 5), (4, 1), (4,4), (5,4), (5, 5)} ♦
0 1 1

If R is a relation on a set A, and B is a subset of A, the restriction ofRtoB


is R fl (B x B).

Example 24 Let A = {a,b,c, d, e, f} and R = {(a,a), (a, c), (b, c), (a, e), (£, e), (c, e)}. Let
J? = {a,b,c}. Then

BxB = {(a, a), (a, fe), (a, c), (£, a), (fc, fc), (fc, c), (c, a), (c, fo), (c, c)}

and the restriction of R to B is {(a, a), (a, c), (b, c)}. ♦

4*2 Exercises

1. For the relation R defined in Example 4, which of the fol 13. Let A = Z+, the positive integers, and R be the relation
lowing ordered pairs belong to Rl defined by a R b if and only if there exists a k in Z+ so
(a) (2,3) (b) (0,8) (c) (1,3) thata = bk (kdepends on a andb). Which of the follow
ing belong to Rl
(d) (6,18) (e) (-6,24) (f) (8,0)
(a) (4,16) (b) (1,7) (c) (8,2)
2. For the relation R defined in Example 6, which of the fol
lowing ordered pairs belong to Rl (d) (3,3) (e) (2,8) (f) (2,32)
(a) (2,0) (b) (0,2) (c) (0,3) 14. Let A = R. Consider the following relation R on A:
(d) (0,0) (e) (l,^) (f) (1,1) a R b if and only if 2a + 3b = 6. Find Dom(#) and
Ran(/?).
3. Let A = Z+, the positive integers, and R be the relation
defined by a R b if and only if 2a < b + 1. Which of the 15. Let A = R. Consider the following relation R on A:
following ordered pairs belong to Rl a R b if and only if a2 + b2 = 25. Find Dom(#) and
Ran(tf).
(a) (2,2) (b) (3,2) (c) (6,15)
(d) (1,1) (e) (15,6) (f) (n,n) 16. Let R be the relation defined in Example 6. Find /?(A0
for each of the following.
In Exercises 4 through 12, find the domain, range, matrix, and,
when A = B, the digraph of the relation R. (a) A! = {1,8} (b) A! = {3,4,5}

4. A = [a,b,c,d], B = [1,2,3], (c) A, = { }


R = {(a,l),(a,2),(b,l),(c,2),(d,l)] 17. Let R be the relation defined in Exercise 9. Find each of
5. A = {daisy, rose, violet, daffodil, peony}, the following.
B = {red, white, purple, yellow, blue, pink, orange} (a) R(3) (b) R(6) (c) R({2,4,6])
R = {(daisy, red), (violet, pink), (rose, purple),
18. Let R be the relation defined in Exercise 11. Find each of
(daffodil, white)}
the following.
6. A = {1,2, 3,4}, B = {1,4, 6, 8, 9}; a R b if and only if
(a) R({3,1}) (b) R(9) (c) #({1,3})
b = a2.
19. Let R be the relation defined in Exercise 13. Find each of
7. A = {1, 2, 3,4, 8} = B; a R b if and only if a = b. the following.
8. A = {1,2, 3,4, 8}, B = {1,4, 6, 9}; a R b if and only if (a) R(3) (b) R(4)
a \b.
9. A = {1, 2, 3,4,6} = B; a R b if and only if a is a multi (c) R({4,3]) (d) R({2,4])
ple of b. 20. Let R be a relation from A to B. Prove that for all subsets

10. A = {1, 2, 3,4, 5} = B; a R b if and only if a < b. Ax and A2 of A

11. A = {1, 3, 5,7,9}, B = {2,4, 6, 8}; a R b if and only if


b < a. R(AX fl A2) = fl(Ai) fl R(A2) if and only if
12. A = {1, 2, 3,4, 8} = B; a R b if and only if a + b < 9. R(a) D #(Z?) = { } for any distinct a, b in A.
4.3 Paths in Relations and Digraphs 135

21. Let A = R. Give a description of the relation R specified 26.


by the shaded region in Figure 4.8.

(0,2)

Figure 4.10
27. For the digraph in Exercise 25, give the in-degree and the
out-degree of each vertex.
Figure 4.8
28. For the digraph in Exercise 26, give the in-degree and the
22. If A has n elements and B has m elements, how many out-degree of each vertex.
different relations are there from A to Bl
29. Describe how to find the in-degree and the out-degree of
In Exercises 23 and 24, give the relation R defined on A and a vertex directly from the matrix of a relation.
its digraph.
In Exercises 30 and 31, let A = {1,2,3,4,5,6,7} and
1 1 0 11 R = {(1,2), (1,4), (2, 3), (2, 5), (3, 6), (4, 7)}. Compute the
0 110 restriction of R to B for the given subset of A.
23. Let A = {1, 2, 3, 4} and MR =
0 0 11
30. B = {1,2, 4, 5}
1 o o oj
r i l o (3 0 31. B = {2, 3,4, 6}
0 0 1 1 0
32. Let R be a relation on a set A and B c. A. Describe how
24. Let A = [a, b, c, d, e] and MR = 0 0 0 1 1
to create the matrix of the restriction of R to B from MR.
0 1 1 (3 0
.1 0 0 (3 0 33. Let R be a relation on a set A and B c, A. Describe how
to create the digraph for the restriction of R to B from the
In Exercises 25 and 26, find the relation determinedby the di
digraph of R.
graph and give its matrix.
34. Let R be a relation on A = [ax, a>i,..., an] given by the
25.
matrix Mr. Give a procedure using Mr directly to find
each of the following.
(a) R(ak) (b) R([ax,aj,an])
35. Let R be a relation on A = [ax, a2, ••.,««} given by its
digraph. Give a procedure using the digraph directly to
find each of the following.
(a) R(ak) (b) R({ax,aj,an])
36. Let S be the product set {1, 2, 3} x {a, b]. How many
relations are there on SI

37. Let S be the product set A x B. If \A\ = m and |£| = n,


Figure 4.9 then how many relations are there on SI

4.3 Paths in Relations and Digraphs


Suppose that R is a relation on a set A. A path of length n in R from a to b is
a finite sequence n : a, xx, xi,..., xn-X, b, beginning with a and ending with b,
such that
a R xx, xx R X2, • • •, xn-\ R b.

Note that a path of length n involves n + 1 elements of A, although they are not
necessarily distinct.
136 Chapter 4 Relations and Digraphs
A path is most easily visualized with the aid of the digraph of the relation. It
appears as a geometric path or succession of edges in such a digraph, where the
indicated directions of the edges are followed, and in fact a path derives its name
from this representation. Thus the length of a path is the number of edges in the
path, where the vertices need not all be distinct.

Example 1 Consider the digraph in Figure 4.11. Then nx: 1,2, 5,4, 3 is a path of length 4
from vertex 1 to vertex 3,7i2: 1, 2,5,1 is a path of length 3 from vertex 1 to itself,
and 7r3: 2, 2 is a path of length 1 from vertex 2 to itself. ♦

A path that begins and ends at the same vertex is called a cycle. In Example
1, 7t2 and 7r3 are cycles of lengths 3 and 1, respectively. It is clear that the paths of
length 1 can be identified with the ordered pairs (x, y) that belong to R. Paths in a
relation R can be used to define new relations that are quite useful. If n is a fixed
positive integer, we define a relation Rn on A as follows: x Rn y means that there
is a path of length n from x to y in R. We may also define a relation R°° on A, by
Figure 4.11 letting x R°° y mean that there is some path in R from x to y. The length of such
a path will depend, in general, on x and y. The relation R°° is sometimes called
the connectivity relation for R.
Note that Rn (x) consists of all vertices that can be reached from x by means of
a path in R of length n. The set R°°(x) consists of all vertices that can be reached
from x by some path in R.

Example 2 Let A be the set of all living human beings, and let R be the relation of mutual
acquaintance. Thatis, a R b means that a and b know one another. Thena R2 b
means that a and b have an acquaintance in common. In general, a Rn b if a
knows someone x\, who knows x2, ..., who knows jc„_i, who knows b. Finally,
a R00 b means that some chain of acquaintances exists that begins at a and ends at
b. It is interesting (and unknown) whether every two Americans, say, are related
by R°°. ♦

Example 3 Let A be a set of U.S. cities, and let x R y if there is a direct flight from x to y on
at least one airline. Then x and y are related by Rn if one can book a flight from x
to y having exactly n —1 intermediate stops, and x R°° y if one can get from x to
y by plane. ♦

Example 4 Let A = {1, 2, 3,4, 5, 6}. Let R be therelation whose digraph is shown in Figure
4.12. Figure 4.13 shows the digraph of the relation R2 on A. A line connects two
vertices in Figure 4.13 if andonly if they are J?2-related, thatis, if andonlyif there
is a path of length two connecting those vertices in Figure 4.12. Thus

IR22 since 1 R2 and 2R2


IR24 since 1 R2 and 2R4
IR25 since 1 R2 and 2R5
2R22 since 2R2 and 2R2
2R24 since 2R2 and 2R4
2R25 since 2R2 and 2R5
2R26 since 2R5 and 5 R6
3R25 since 3 R4 and 4R5
4R26 since 4R5 and 5 R6

In a similar way, we can construct the digraph of Rn for any n.


4.3 Paths in Relations and Digraphs 137

Figure 4.12 Figure 4.13

Example 5 Let A —{a,b,c, d, e] and


R = {(a, a), (a, b), (b, c), (c, e), (c, d), (d, e)}.

Compute (a) R2\ (b) R°°.

Solution
(a) The digraph of R is shown in Figure 4.14.

a R2 a since a R a and a R a.
a R2b since a R a and a Rb.
a R2 c since a Rb and b Re.
bR2e since b Re and c Re.
bR2d since b Re and cRd.
c R2e since cRd and d Re.

Hence
R2 = {(a,a), (a, b), (a, c), (b, e), (b, d), (c, e)}.
(b) To compute R°°, we need all ordered pairs of vertices for which there is
a path of any length from the first vertex to the second. From Figure 4.14
Figure 4.14 we see that

R°° = [(a, a), (a, b), (a, c), (a, d), (a, e), (b, c),
(b,d),(b,e),(c,d),(c,e),(d,e)].

For example, (a, d) e R°°, since there is a path of length 3 from a to d:


a, b, c, d. Similarly, (a, e) e R°°, since there is a path of length 3 from a
to e: a, b, c, e as well as a path of length 4 from a to e: a, b, c, d, e. ♦

If |R| is large, it can be tedious and perhaps difficult to compute R00, or even
R2, from the set representation of R. However, MR can be used to accomplish
these tasks more efficiently.
Let R be a relation on a finite set A = [ax, a2,..., an], and let MR be the
n x n matrix representing R. We will show how the matrix M/?2, of R2, can be
computed from MR.

THEOREM 1 If R is a relation on A = [ax, a2,..., an], then M^ = MR O MR (see Section


1.5).

Proof
Let Mr = [ ntij ] and M^ = [ n^ ]. By definition, the /, y'th element ofM/^QM/?
is equal to 1 if and only if row i of Mr and column j of M# have a 1 in the same
relative position, say position k. This means that mz* = 1 and mkj = 1 for some
138 Chapter 4 Relations and Digraphs
k, 1 < k < n. By definition of the matrix MR, the preceding conditions mean that
ax Rak and ak Raj. Thus at R2 aj, and so nu = 1. We have therefore shown
that position /, ; ofM* OMR is equal to 1if and only if nu = 1. This means that
MroMr = mR2. m

For brevity, we will usually denote MR ©MR simply as (M*)| (the symbol
O reminds us that this is not the usual matrix product).

Example 6 Let A and Rbeasin Example 5. Then


110 0 0
0 0 10 0
MR= 0 0 0 1 1
0 0 0 0 1
0 0 0 0 0

From the preceding discussion, we see that

110 0 0 110 0 0
0 0 10 0 0 0 10 0
M^2 =MrQMr = 0 0 0 11 O 0 0 0 11
0 0 0 0 1 0 0 0 0 1
0 0 0 0 0. 0 0 0 0 0

1110 0
0 0 0 11
0 0 0 0 1
0 0 0 0 0
,00000

Computing M^ directly from R2, we obtain the same result. ♦

We can see from Examples 5 and 6 that it is often easier to compute R2 by


computing MR© MR instead of searching the digraph of R for all vertices that can
be joined by a path of length 2. Similarly, we can show that M^ = MR © (MR Q
Mr) = (Mr)q. In fact, we now show by induction that these two results can be
generalized.

THEOREM 2 For n > 2 and R a relation on a finite set A, we have

MRn = Mr © Mr © • • • O Mr (n factors).

Proof
Let P(n) be the assertion that the statement holds for an integer n > 2.

Basis Step
P(2) is true by Theorem 1.

Induction Step
We use P(k) to show P(k + 1). Consider the matrix M^in-i. Let MRk+i = [ xij ],
MRk = [ yij ], and MR = [ m,y ]. Ifxy = 1, we must have a path oflength k+ 1
from ai to aj. If we let as be the vertex that this path reaches just before the last
vertex aj, then there is a path of length k from ax to as and a path of length 1 from
as to aj. Thus yis = 1 and mSj = 1, so M^ ©M/? has a 1 in position i, j. We can
4.3 Paths in Relations and Digraphs 139

see, similarly, thatif M^ © M* has a 1 in position i, j, thenxu = 1. Thismeans


that MrIc+i = MRk O M*.
Using
P(k):Mric=MrQ--OMr (k factors),
we have

MRk+X = MRk © Mr = (Mr © M* © ••• © Mr) © Mr

and hence

P(k + 1): M^+i =MrO---OMrOMr (k + l factors)


is true. Thus, by the principle of mathematical induction, P(n) is true for all n > 2.
This provesthe theorem. As before,we writeM^O- •-0Mj? (n factors) as (Mr)q.

Note that the key to an induction step is finding a useful connection between
P(Jfc)andP(ifc+l).
Now that we know how to compute the matrix of the relation Rn from the
matrix of R, we would like to see how to compute the matrix of R°°. We proceed
as follows. Suppose that R is a relation on a finite set A, and x £ A, y e A. We
know that jc R00 y means that x and y are connected by a path in R of length n
for some n. In general, n will depend on x and y, but, clearly, x R°° y if and only
if x R y or x R2 y or x R3 y or Thus the preceding statement tells us that
oo

R°° = R U R2 U R3 U ••• = U Rn. If R and S are relations on A, the relation


n=\
R U 5 is defined by x (R U 5) y if and only if x R y or x S y. (The relation
R U S will be discussed in more detail in Section 4.7.) The reader may verify that
MrUS = Mr v Ms, and we will show this in Section 4.7. Thus

Mroo = Mr VM*2 VM^3 V•••= Mr V(M*)| V(M*)*, V••• .


The reachability relation R* of a relation /? on a set A that has n elements
is defined as follows: x R* y means that x = y or x R°° y. The idea is that y is
reachable from x if either y is x or there is some path from x to j>. It is easily seen
that Mr* = Mroo v I„, where I„ is then x n identity matrix. Thus our discussion
shows that
M** = In VMr V(Mr)2q V(Mr)3q V••• .
Let nx: a, jti, Jt2,..., x„_i, fc be a path in a relation R of length n from a to
£, and let 7T2: b,yx,y2,..., ym-\, c be a path in /? of length m from &to c. Then
the composition of ixx and n2 is the path a, xx, x2,..., b, yx, y2,..., ym-\, c of
Figure 4.15 length n + m, which is denoted by n2 o ttx . This is a path from a to c.

Example 7 Consider the relation whose digraph is given in Figure 4.15 and thepaths
TTi: 1,2,3 and n2: 3,5,6,2,4.

Then the composition of 7t[ and n2 is the path n2 o n\: 1, 2, 3, 5, 6, 2,4 from 1 to
4 of length 6. ♦
140 Chapter 4 Relations and Digraphs
4.3 Exercises

ForExercises 1 through 8, let R be therelation whosedigraph 14. Find a cycle starting at vertex a.
is given in Figure 4.16.
15. Draw the digraph of/?2.
16. Find MRi. Is this result consistent with the result of Exer
cise 15?

17. (a) FindM/joo.


(b) Find/?00.
18. Let R and S be relations on a set A. Show that

MRUS = Mrv Ms.

19. Let R be a relation on a set A that has n elements. Show


that MR* = MRoo v I„, where I„ is the n x n identity
matrix.
Figure 4.16
In Exercises20 through 25, let R be the relation whose digraph
1. List all paths of length 1. is given in Figure 4.18.
2. (a) List all paths of length 2 starting from vertex 2.
(b) List all paths of length 2.
3. (a) List all paths of length 3 starting from vertex 3.
(b) List all paths of length 3.
4. Find a cycle starting at vertex 2.
5. Find a cycle starting at vertex 6.
6. Drawthe digraph of R2.
7. FindM^.
8. (a) Find/?00,
(b) FindMfloo.

For Exercises 9 through 16, let R be the relation whose di


graph is given in Figure 4.17. Figure 4.18

20. If 7Ti: 1, 2,4, 3 and jt2: 3, 5,6,4, find the composition


1X2 O 7tX.

21. If nx: 1,7, 5 and n2: 5, 6,7,4, 3, find the composition


H2 O TTX.

22. If jtx : 3,4,5, 6, and n2: 6, 7,4, 3, 5, find the composition


7V2 O 7tX.

23. If nx: 2,3,5,6,1, and K2: 1,5,6,4, find the composition


7t2 O JVX.

Figure 4.17 24. Find two cycles of length at least 3 in the relation R.
25. Find a cycle with maximum length in the relation R.
9. List all paths of length 1.
26. Let A = {1, 2, 3,4, 5] and R be the relation defined by
10. (a) List all paths of length 2 starting from vertex c. a R b if and only if a < b.
(b) Find all paths of length 2. (a) Compute R2 and R3.
11. (a) List all paths of length 3 starting from vertex a. (b) Complete the following statement: a R2 b if and
(b) Find all paths of length 3. only if
12. Find a cycle starting at vertex c. (c) Complete the following statement: a R3 b if and
13. Find a cycle starting at vertex d. only if
4.4 Properties of Relations 141

27. By Theorem 1, MR (DMR = MRi so that M* QMR shows 30. (a) What about the statement of Theorem 2 indicates that
where there are paths of length 2 in the digraph of R. Let an induction proof is appropriate?
(b) What is the central idea of the induction step in the
1111
proof of Theorem 2?
0 0 10
MR = 31. Let D be the digraph of a finite relation R. Show that
0 10 0
0 111 if there are no cycles in D, then at least one vertex has
out-degree 0.
What does MR • MR show? Justify your conclusion. 32. Draw a digraph with six vertices that has exactly one path
28. Is it possible to generalize the results of Exercise 27? For of length 6 and exactly six paths of length 1.
example, does (M^)3 tell us anything useful about Rl 33. Juan and Nils have each drawn a digraph to represent the
29. Complete the following. The proof of Theorem 1 is relation R. The digraphs do not "look" alike. How would
proof based on of matrices. you determine if the digraphs both represent R correctly?

4.4 Properties of Relations


In many applications to computer science and applied mathematics, we deal with
relations on a set A rather than relations from A to B. Moreover, these relations
often satisfy certain properties that will be discussed in this section.

Reflexive and Irreflexive Relations


A relation R on a set A is reflexive if (a, a) e R for all a e A, that is, ifaRa for
all a e A. A relation R on a set A is irreflexive if a ft a for every a e A.
Thus R is reflexive if every element a e A is related to itself and it is irreflex
ive if no element is related to itself.

Example 1 (a) Let A = {(a, a) \ a e A], so that A is the relation of equality on the set A.
Then A is reflexive, since (a, a) e A for all a e A.
(b) Let R = {(a, b) e A x A | a ^ b], so that R is the relation of inequality on
the set A. Then R is irreflexive, since (a, a) £ R for all a e A.
(c) Let A = {1, 2, 3}, and let R = {(1, 1), (1, 2)}. Then R is not reflexive since
(2, 2) £ R and (3, 3) g R. Also, R is not irreflexive, since (1, 1) e R.
(d) Let A be a nonempty set. Let R = 0 c A x A, the empty relation. Then R is
not reflexive, since (a, a) £ R for all a € A (the empty set has no elements).
However, R is irreflexive. ♦

We can identify a reflexive or irreflexive relation by its matrix as follows. The


matrix of a reflexive relation must have all 1's on its main diagonal, while the
matrix of an irreflexive relation must have all 0's on its main diagonal.
Similarly, we can characterize the digraph of a reflexive or irreflexive relation
as follows. A reflexive relation has a cycle of length 1 at every vertex, while an
irreflexive relation has no cycles of length 1. Another useful way of saying the
same thing uses the equality relation A on a set A: R is reflexive if and only if
AC/?, and R is irreflexive if and only if A D R = 0.
Finally, we may note that if R is reflexive on a set A, then Dom(/?) =
Rzn(R) = A.

Symmetric, Asymmetric, and Antisymmetric Relations


A relation R on a set A is symmetric if whenever a Rb, then b R a. It then
follows that R is not symmetric if we have some a and b e A with a R b, but
b $. a. A relation R on a set A is asymmetric if whenever a Rb, then b $ a. It
142 Chapter 4 Relations and Digraphs
then follows that R is not asymmetric if we have some a and b e A with both
a Rb and/? R a.
A relation R on a set A is antisymmetric if whenever a Rb and b R a, then
a = b. The contrapositive of this definition is that R is antisymmetricif whenever
a ^ b, then a ft b orb ft a. It follows that /? is not antisymmetric if we have a
and bin A,a ^ b, and both a Rb and Z? /? a.
Given a relation /?, we shall want to determine which properties hold for R.
Keep in mind the following remark: A property fails to hold in general if we can
find one situation where the property does not hold.

Example 2 Let A = Z, the setof integers, and let


R = {(a,b) e A x A \a < b]

so that R is the relation less than. Is R symmetric, asymmetric, or antisymmetric?

Solution

Symmetry: If a < b, then it is not true that b < a, so R is not symmetric.


Asymmetry: If a < b, then b ^ a (bis not less than a), so R is asymmetric.
Antisymmetry: If a ^ b, then either a jtb orb yt a, so that R is antisymmet
ric. ♦

Example 3 Let A be a set of people and let R = {(jc, y) e A x A | jc is a cousin of y}. Then
R is a symmetric relation (verify). ♦

Example 4 Let A = {1,2,3,4} and let


R = {(1,2), (2, 2), (3,4), (4,1)}.

Then /? is not symmetric, since (1, 2) € R, but (2, 1) ^ R. Also, /? is not asym
metric, since (2, 2) e R. Finally, R is antisymmetric, since if a ^ b, either
(a,/?) £ Ror(b,a) £ R. ♦

Example 5 Let A = Z+, thesetof positive integers, and let


R = {(a, b) € A x A | a divides /?}.

Is # symmetric, asymmetric, or antisymmetric?

Solution
If a \ b, it does not follow that b \ a, so R is not symmetric. For example, 2 | 4,
but 4 f 2.
If a = b = 3, say, then a Rb and Z? R a, so /? is not asymmetric.
If a | b and Z> | a, then a = b, so R is antisymmetric. (See Exercise 33 in
Section 1.4.) ♦

We now relate symmetric, asymmetric, and antisymmetric properties of a re


lation to properties ofits matrix. The matrix Mr = [ m// ] ofasymmetric relation
satisfies the property that

if rtiij = 1, then my = 1.
Moreover, if my = 0, then m,y = 0. Thus MR is a matrix such that each pair of
entries, symmetrically placed about the main diagonal, are either both 0 or both 1.
It follows that MR = MjJ, sothat MR is a symmetric matrix (see Section 1.5).
4.4 Properties of Relations 143

The matrix M* = [ my ] ofan asymmetric relation Rsatisfies the property


that
if m,; = 1, then mi = 0.

If R is asymmetric, it follows that ma = 0 for all /; that is, the main diagonal
of the matrix Mr consists entirely of O's. This must be true since the asymmetric
property implies that if ma = 1, then m„ = 0, which is a contradiction.
Finally, the matrix MR = [ my ] ofan antisymmetric relation Rsatisfies the
property that if i ^ j, then ml} = 0 or my = 0.

Example 6 Consider the matrices in Figure 4.19, eachof which is the matrix of a relation, as
indicated.
Relations R\ and R2 are symmetricsince the matrices MR[ and Mr2 are sym
metric matrices. Relation R$ is antisymmetric, since no symmetrically situated,
off-diagonal positions of M^3 both contain l's. Such positions may both have
O's, however, and the diagonal elements are unrestricted. The relation R3 is not
asymmetric becauseM/?3 has l's on the main diagonal.
Relation R4 has none of the three properties: Mr4 is not symmetric. The
presence of the l's in positions 4, 1 and 1, 4 of M^4 violates both asymmetry and
antisymmetry.
Finally, R5 is antisymmetric but not asymmetric, and Re is both asymmetric
and antisymmetric. ♦

0 110
1 0 1 110 0
= M R2
0 0 1 M *i 10 11
1 1 1 0 0 11

(a) (b)

0 0 11
1 1 1 0 0 1 0
= M R4
0 1 0 = M R3 0 0 0 1
0 0 0 1 0 0 0

(C) (d)

10 0 1 0 1 1 1
0 111 0 0 1 0
= M «5 = M *6
0 0 10 0 0 0 1
0 0 0 1 0 0 0 0

(e) (f)

Figure 4.19

We now consider the digraphs of these three types of relations. If R is an


asymmetric relation, then the digraph of R cannot simultaneously have an edge
from vertex / to vertex j and an edge from vertex j to vertex /. This is true for
any i and j, and in particular if / equals j. Thus there can be no cycles of length
1, and all edges are "one-way streets."
If R is an antisymmetric relation, then for different vertices i and j there
cannot be an edge from vertex / to vertex j and an edge from vertex j to vertex /.
144 Chapter 4 Relations and Digraphs
When i = j, no condition is imposed. Thus there may be cycles of length 1, but
again all edges are "one way."
We consider the digraphs of symmetric relations in more detail.
The digraph of a symmetric relation R has the property that if there is an
edge from vertex i to vertex j, then there is an edge from vertex j to vertex /.
Thus, if two vertices are connected by an edge, they must always be connected in
both directions. Because of this, it is possible and quite useful to give a different
representation of a symmetric relation. We keep the vertices as they appear in the
digraph, but if two vertices a and b are connected by edges in each direction, we
replace these two edges with one undirected edge, or a "two-way street." This
undirected edge is just a single line without arrows and connects a and b. The
resulting diagram will be called the graph of the symmetric relation. ("Graph"
will be given a more general meaning in Chapter 8.)

Example 7 Let A= {a,b, c,d,e] and let Rbe the symmetric relation given by
R = {(a, b), (b, a), (a, c), (c, a), (b, c), (c, b),
(b, e), (e, b), (e, d), (d, e), (c, d), (d, c)}.

The usual digraph of R is shown in Figure 4.20(a), while Figure 4.20(b) shows the
graph of R. Note that each undirected edge corresponds to two ordered pairs in
the relation R. ♦

Digraphof R Graph of R
(a) (b)

Figure 4.20

An undirected edge between a and b, in the graph of a symmetric relation R,


corresponds to a set {a, b] such that (a, b) e R and (b, a) e R. Sometimes we
will also refer to such a set {a, b] as an undirected edge of the relation R and call
a and b adjacent vertices.
A symmetric relation R on a set A is called connected if there is a path from
any element of A to any other element of A. This simply means that the graph
of R is all in one piece. In Figure 4.21 we show the graphs of two symmetric
relations. The graph in Figure 4.21(a) is connected, whereas that in Figure 4.21(b)
is not connected.

Transitive Relations

We say that a relation R on a set A is transitive if whenever a Rb and b R c, then


a R c. It is often convenient to say what it means for a relation to be not transitive.
A relation R on A is not transitive if there exist a, b, and c in A so that a Rb and
b R c, but a $ c. If such a, b, and c do not exist, then R is transitive.
4.4 Properties ofRelations 145

(b)

Figure 4.21

Example 8 Let A = Z, the set of integers, and let R be the relation less than. To see whether
R is transitive, we assume that a Rb and b R c. Thus a < b and b < c. It then
follows that a < c, so a R c. Hence R is transitive. ♦

Example 9 Let A = Z+ and let R be therelation considered in Example 5. Is R transitive?


Solution
Suppose that a Rb and b R c, so that a \ b and b \ c. It then does follow that
a | c. [See Theorem 2(d) of Section 1.4.] Thus R is transitive. ♦

Example 10 Let A = {1, 2, 3,4} and let


/? = {(!, 2), (1,3), (4, 2)}.

Is /? transitive?

Solution
Since there are no elements a, b, and c in A such that a R b and Z? /? c, but <z ^ c,
we conclude that R is transitive. ♦

Arelation Ris transitive ifand only if its matrix Mr = [ m/y ] has the prop
erty
if ntij = 1 andm^ = 1, then m,-* = 1.
The left-hand side of this statement simply means that (Mr)q has a 1 in position
/, k. Thus the transitivity of R means that if (MR)^ has a 1 in any position, then
Mr must have a 1 in the sameposition. Thus, in particular, if (Mr)q = Mr, then
R is transitive. The converse is not true.

Example 11 Let A = {1, 2, 3} and let R be therelation on A whose matrix is


1 1 1
M* = 0 0 1
0 0 1

Show that R is transitive.

Solution
By directcomputation, (MR)^ = Mr; therefore, R is transitive. ♦

To see what transitivity means for the digraph of a relation, we translate the
definition of transitivity into geometric terms.
If we consider particular vertices a and c, the conditions a Rb and b R c
mean that there is a path of length 2 in R from a to c. In other words, a R2 c.
146 Chapter 4 Relations and Digraphs
Therefore, we may rephrase the definition of transitivity as follows: If a R2 c,
then a Re; that is, R2 c R (as subsets of A x A). In other words, if a and c are
connected by a path of length 2 in /?, then they must be connected by a path of
length 1.
We can slightlygeneralize the foregoing geometric characterizationof transi
tivity as follows.

THEOREM 1 Arelation Ris transitive if and only if it satisfies the following property: If there
is a pathof length greater than 1from vertex a to vertex b, there is a pathof length
1 from a to b (that is, a is relatedto b). Algebraically stated, R is transitive if and
only if Rn c # for all n > 1.

Proof
The proof is left to the reader. •

It will be convenient to have a restatement of some of these relational proper


ties in terms of R-relative sets. We list these statements without proof.

THEOREM 2 Let J? be a relation on a set A. Then


(a) Reflexivity of R means that a e R(a) for all a in A.
(b) Symmetry of R means that a e R(b) if and only if b e R(a).
(c) Transitivity of R means that if b e R(a) and c e R(b), then c e R(a). •

4.4 Exercises

In Exercises 1 through 8, let A = {1,2,3,4}. Determine 10.


whetherthe relation is reflexive, irreflexive, symmetric, asym
metric, antisymmetric, or transitive.

1. R = {(1,1), (1,2), (2,1), (2, 2), (3, 3), (3,4),


(4, 3), (4,4)}

2. R = {(1, 2), (1, 3), (1,4), (2, 3), (2,4), (3,4)}


Figure 4.23
3. R = {(1,3), (1,1), (3,1), (1, 2), (3, 3), (4,4)}
Figure 4.22
4. J? = {(1,1), (2,2), (3, 3)}
In Exercises 11 and 12, let A = {1,2,3,4}. Determine
5. R = 0 whether the relation R whose matrix MR is given is reflexive,
irreflexive, symmetric, asymmetric, antisymmetric, or transi
tive.
6. R = A x A
0 10 1 ri i o o
10 11 110 0
7. R = {(1,2), (1, 3), (3,1), (1,1), (3, 3), (3,2), 11. 12.
0 10 0 0 0 10
(1,4), (4, 2), (3,4)}
110 0 0 0 0 1.

8. R = {(1,3), (4, 2), (2,4), (3,1), (2, 2)} In Exercises 13 through 24, determine whether the relation R
on the set A is reflexive, irreflexive, symmetric, asymmetric,
/« Exercises 9 and 10 (Figures 4.22 and 4.23), let A = {1,2,3, antisymmetric, or transitive.
4,5}. Determine whether the relation R whose digraph is
13. A = Z; a Rb if and only if a < b + 1.
given is reflexive, irreflexive, symmetric, asymmetric, antisym
metric, or transitive. 14. A = Z+; a R b if and only if \a - b\ < 2.
4.4 Properties of Relations 147

15. A = Z+; a R b if and onlyif a = bk for some k eZ+. 28. Consider the graph of a symmetric relation R on A =
[a, b, c, d, e] shown in Figure 4.25. Determine R (list all
16. A = Z;a R bif and only if a + b is even.
pairs).
17. A = Z; a tf fc if and only if \a - b\ = 2.
18. A = the set of real numbers; a R b if and only if
A2 + fc2 = 4.
19. A = Z+; a /? 6 if and only if GCD(a, b) = 1. In this
case, we say that a and b are relatively prime. (See Sec
tion 1.4 for GCD.)
20. A is the set of all ordered pairs of real numbers;
(a, b) R (c, d) if and only if a = c.
21. S = {1,2, 3,4}, A = S x S; (a, b) R (c, d) if and only if
ad = be. Figure 4.25
22. A is the set of all lines in the plane. l\ /? /2 if and only if
29. Let R be a symmetric relation given by its matrix Mr . De
l\ is parallel to/2.
scribe a procedure for using M^ to determine if the graph
23. A is the set of all triangles in the plane, t\ R t2 if and only of R is connected.
if the three angles of t\ have the same measures as the
30. Let R be a relation on A and B c A. Which relational
three angles of h.
properties of R would be inherited by the restriction of R
24. A is the set of all people in the world, a R bif and only if to Bl
a is the sister of b.
31. Prove or disprove that if a relation on a set A is transitive
25. Let R be the following symmetric relation on the set and irreflexive, then it is asymmetric.
A = {1,2, 3, 4, 5}:
32. Prove or disprove that if a relation R on A is transitive,
R = {(1, 2), (2, 1), (3,4), (4, 3), (3, 5), (5, 3), then R2 is also transitive.

(4, 5), (5,4), (5, 5)}. 33. Let R be a nonempty relation on a set A. Suppose that R
is symmetric and transitive. Show that R is not irreflexive.
Draw the graph of R. 34. Prove that if a relation R on a set A is symmetric, then the
26. Let A = {a,b, c, d] and let R be the symmetric relation relation R2 is also symmetric.
35. Prove by induction that if a relation R on a set A is sym
R = {(a, b), (b, a), (a, c), (c, a), (a, d), (d, a)].
metric, then Rn is symmetric for n > 1.
Draw the graph of R. 36. Define a relation on Z+ that is reflexive, symmetric, and
27. Consider the graph of a symmetric relation R on A = transitive and has not been defined previously.
{1, 2, 3,4, 5, 6, 7} shown in Figure 4.24. Determine R 37. Define a relation on the set {a, b, c, d] that is
(list all pairs). (a) reflexive and symmetric, but not transitive.
(b) reflexive and transitive, but not symmetric.
38. Define a relation on the set {a, b, c, d] that is
(a) irreflexive and transitive, but not symmetric.
(b) antisymmetric and reflexive, but not transitive.
39. Define a relation on the set {a, b, c, d] that is
(a) transitive, reflexive, and symmetric.
(b) asymmetric and transitive.
Figure 4.24
40. Give a direct proof of Theorem 1 of this section.
148 Chapter 4 Relations and Digraphs

4.5 Equivalence Relations


A relation R on a set A is called an equivalence relation if it is reflexive, sym
metric, and transitive.

Example 1 Let A be the setof all triangles in the plane and let R be the relation on A defined
as follows:

R = {(a, b) € A x A \ a is congruent to b}.

It is easy to see that R is an equivalence relation. ♦

Example 2 Let A = {1,2, 3,4} and let

R = {(1,1), (1, 2), (2, 1), (2, 2), (3,4), (4, 3), (3, 3), (4, 4)}.

It is easy to verify that R is an equivalence relation. ♦

Example 3 Let A = Z, the setof integers, and let R be defined by a R b if and only if a < b.
Is R an equivalence relation?

Solution
Since a < a, R is reflexive. If a < b, it need not follow that b < a, so R is not
symmetric. Incidentally, R is transitive, since a < b and b < c imply that a < c.
We see that R is not an equivalence relation. ♦

Example 4 Let A = Z and let

R = {(a,b) e A x A \ a and b yield the same remainder when divided by 2}.

In this case, we call 2 the modulus and write a = b (mod 2), read "<z is congruent
to b mod 2."
Show that congruence mod 2 is an equivalence relation.

Solution
First, clearly a = a (mod 2). Thus R is reflexive.
Second, if a = b (mod 2), then a and Z? yield the same remainder when di
vided by 2, so b = a (mod 2). /? is symmetric.
Finally, suppose that a = b (mod 2) and b = c (mod 2). Then a, b, and
c yield the same remainder when divided by 2. Thus, a = c (mod 2). Hence
congruence mod 2 is an equivalence relation. ♦

Example 5 Let A = Z and let n e Z+. We generalize the relation defined in Example 4 as
follows. Let
R = {(a, b)eAxA\a = b (mod n)}.

That is, a = b (mod n) if and only if a and b yield the same remainder when
divided by n. Proceeding exactly as in Example 4, we can show that congruence
mod n is an equivalence relation. ♦

We note that if a = b (mod n), then a = qn + r and b = tn + r and a —bis


a multiple of n. Thus, a = b (mod n) if and only if n \ (a —b).
4.5 Equivalence Relations 149

Equivalence Relations and Partitions


The following resultshows that if P is a partitionof a set A (see Section4.1), then
Pczn be used to construct an equivalence relation on A.

THEOREM 1 Let P be a partition of a set A. Recall that the sets in P are called the blocks of P.
Define the relation R on A as follows:

a Rb if and only if a and b are members of the same block.

Then R is an equivalence relation on A.

Proof
(a) If a e A, then clearly a is in the same block as itself; so a R a.
(b) If a Rb, then a and b are in the same block; sob R a.
(c) If a Rb and b R c, then a, b, and c must all lie in the same block of P.
Thus a Re.

Since R is reflexive, symmetric, and transitive, R is an equivalence relation. R


will be called the equivalence relation determined by P. •

Example 6 Let A = {1,2, 3,4} and consider the partition P —{{1, 2, 3}, {4}} of A. Findthe
equivalence relation R on A determined by P.

Solution
The blocks of P are {1, 2, 3} and {4}. Each element in a block is related to every
other element in the same block and only to those elements. Thus, in this case,

R = {(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3), (4,4)}. ♦

If P is a partition of A and /? is the equivalence relation determined by P,


then the blocks of P can easily be described in terms of R. If Ai is a block of
P and a e A\, we see by definition that A\ consists of all elements jc of A with
a R x. That is, A\ = R(a). Thus the partition Pis {R(a) \ a e A}. In words, P
consists of all distinct R-relative sets that arise from elements of A. For instance,
in Example 6 the blocks {1, 2, 3} and {4} can be described, respectively, as R(l)
and R(4). Of course, {1, 2, 3} could also be described as R(2) or R(3), so this way
of representing the blocks is not unique.
The foregoing construction of equivalence relations from partitions is very
simple. We might be tempted to believe that few equivalence relations could be
produced in this way. The fact is, as we will now show, that all equivalence rela
tions on A can be produced from partitions.
We begin with the following result. Since its proof uses Theorem 2 of Section
4.4, the reader might first want to review that theorem.

Lemma 1* Let R be an equivalence relation on a set A, and let a e A and b e A. Then

a Rb if and only if R(a) = R(b).

Proof
First suppose that R(a) = R(b). Since R is reflexive, b e R(b); therefore, b e
R(a), so a Rb.

*A lemma is a theorem whose main purpose is to aid in proving some other theorem.
150 Chapter 4 Relations and Digraphs
Conversely, suppose that a Rb. Then note that
1. b e R(a) by definition. Therefore, since R is symmetric,
2. a € R(b), by Theorem 2(b) of Section 4.4.
We must show that R(a) = R(b). First, choose an element x e R(b). Since
R is transitive, thefact that x e R(b), together with (1), implies by Theorem 2(c)
of Section 4.4 that x e R(a). Thus R(b) c R(a). Now choose y e R(a). This
fact and (2) imply, as before, that y e R(b). Thus R(a) c R(b), so we must have
R(a) = R(b). m

Notethe two-part structure of the lemma's proof. Because we wantto prove a


biconditional, p <$ g, we must show q =$ p as well as p => q.
We now prove our main result.

THEOREM 2 Let R be an equivalence relation on A, and let P be the collection of all distinct
relative sets R(a) for a in A. Then ^ is a partition of A, and /? is the equivalence
relation determined by P.

Proof
Accordingto the definition of a partition, we must show the following two proper
ties:

(a) Every element of A belongs to some relative set.


(b) If R(a) and R(b) are not identical, then R(a) H R(b) = 0.
Now property (a) is true, since a e R(a) by reflexivity of R. To show property (b)
we prove the following equivalent statement:

If R(a) H R(b) # 0, then R(a) = R(b).

To prove this, we assume that c e R(a)f) R(b). Then a R c and b R c.


Since R is symmetric, we have c Rb. Then a R c and c Rb, so, by transitiv
ity of R, a R b. Lemma 1 then tells us that R(a) = R(b). We have now proved
that P is a partition. By Lemma 1 we see that a R bif and only if a and b belong
to the same block of P. Thus P determines R, and the theorem is proved. •

Note the use of the contrapositive in this proof.


If R is an equivalence relation on A, then the sets R(a) are traditionally called
equivalence classes of R. Some authors denote the class R(a) by [a] (see Section
9.3). The partition P constructed in Theorem 2 therefore consists of all equiva
lence classes of R, and this partition will be denoted by A/R. Recall that partitions
of A are also called quotient sets of A, and the notation A/R reminds us that P is
the quotient set of A that is constructed from and determines R.

Example 7 Let R be therelation defined in Example 2. Determine A/R.


Solution
From Example 2 we have R(\) = {1, 2} = R(2). Also, R(3) = {3,4} = R(4).
Hence A/R = {{1,2}, {3,4}}. ♦

Example 8 Let R be the equivalence relation defined in Example 4. Determine A/R.


Solution
First, R(0) = {..., -6, -4, -2, 0, 2,4, 6, 8,...}, the set of even integers, since
the remainder is zero when each of these numbers is divided by 2. R(l) —
4.5 Equivalence Relations 151

{..., -5, -3, -1, 1, 3, 5, 7,...}, the set of odd integers, since each gives a re
mainder of 1 when divided by 2. Hence A/R consists of the set of even integers
and the setof odd integers. ♦
From Examples 7 and 8 we can extract a general procedure for determining
partitions A/R for A finite or countable. Theprocedure is as follows:
Step 1 Choose any element of A and compute the equivalence class R(a).
Step 2 If R(a) ^ A, choose an element b, not included in R(a), andcompute the
equivalence class R(b).
Step 3 If A is not the union of previously computed equivalence classes, then
choose an element jc of A that is not in any of those equivalence classes
and compute R(x).
Step 4 Repeat step 3 until all elements of A are included in the computed equiv
alence classes. If A is countable, this process could continue indefinitely.
In that case, continue until a pattern emerges that allows you to describe
or give a formula for all equivalence classes.

4.5 Exercises

In Exercises 1 and 2, let A = {a, b, c]. Determine whether the In Exercises 5 through 12, determine whether the relation R
relation R whose matrix MR is given is an equivalence rela on the set A is an equivalence relation.
tion.
5. A = {a,b, c,d],
1 0 0 1 0 1 R = {(a, a), (b, a), (b, b), (c, c), (d, d), (d, c)]
1. M* 0 1 1 2. M,= 0 1 0
6. A = {1, 2, 3,4, 5}, R = {(\, 1), (1, 2), (1, 3), (2, 1),
0 1 1 0 0 1
(2, 2), (3, 1), (2, 3), (3, 3), (4,4), (3, 2), (5, 5)}
In Exercises 3 and 4 (Figures 4.26 and 4.27), determine 7. A = {1,2,3,4}, R = {(1,1), (1,2), (2,1), (2, 2), (3,1),
whether the relation R whose digraph is given is an equiva (3, 3), (1,3), (4,1), (4,4)}
lence relation.
8. A = the set of all members of the Software-of-the-Month
Club; a R b if and only if a and b buy the same number
of programs.
9. A = the set of all members of the Software-of-the-Month
Club; a R bif and only if a and b buy the same programs.
10. A = the set of all people in the Social Security database;
a R bif and only if a and b have the same last name.
11. A = the set of all triangles in the plane; a R bif and only
if a is similar to b.

Figure 4.26 12. A = Z+ x Z+; (a, b) R (c, d) if and only if b = d.


13. If {{a,c, e], {b, d, /}} is a partition of the set A =
{a,b,c, d,e, f], determine the corresponding equiva
lence relation R.

14. If {{1,3, 5), {2,4}} is a partition of the set A = {1,2,3,


4, 5}, determine the corresponding equivalence relation
R.

15. If {{1,3, 5, 7, 9}, {2, 4, 6, 8, 10}} is a partition of the


set A = {1, 2, 3,..., 10}, determine the corresponding
equivalence relation R.
16. If {{a, /}, {e, o], {u}] is a partition of the set A =
[a,e,i,o,u], determine the corresponding equivalence
Figure 4.27 relation R.
152 Chapter 4 Relations and Digraphs
17 LetA andR be thesetandrelation defined in Example 5. (a) Show that R is an equivalence relation.
Compute A/R.
(b) Compute A/R.
18. Let A= {1,2,3,4} and Rbethe relation on Adefined by
23. A relation R on a set A is called circular if a Rb and
1 ooo-i
b Re imply c R a. Show that R is reflexive and circular
0 1 1 1
M* = if and only if it is an equivalence relation.
0 1 1 1
0 111. 24. Show that if R{ and R2 are equivalence relations on A,
Compute A/R. then R\ n R2 is an equivalence relation on A.
19. Let A = R x R. Define the following relation R on A: 25. Define an equivalence relation R on Z, the setof integers,
(a, b) R (c, d) if and only if a2 + b2 = c2 + d2. different from that used in Examples 4 and 8 and whose
(a) Show that R is an equivalencerelation. corresponding partition contains exactly two infinite sets.
(b) Compute A/R.
26. Define an equivalence relation R on Z, the set of integers,
20. Let A = {a,b,c, d, e] and R be the relation on A defined whosecorresponding partitioncontainsexactlythree infi
by nite sets.
1 1 1 0 1
1 1 1 0 1 In Exercises27 and 28, use thefollowing definition. Givenan
M* = 1 1 1 0 1 equivalence relation R on a set where + is defined, the sum
0 0 0 1 0 ofR-relative sets, R(a) + R(b), is {x \ x = s + t, s e R(a),
1 1 1 0 1 t e R(b)].
Compute A/R.
27. Let R be the equivalence relation in Example 4. Show
21. Let S = {1, 2,3,4,5} and A = S x S. Define the fol that R(a) + R(b) = R(a + b) for all a, b.
lowing relation R on A: (a, /?) /? (a', b') if and only if
aV = a'fc. 28. Let R be the equivalence relation in Exercise 12. Show
(a) Show that /? is an equivalence relation. that R(a) + R(b) = R(a + b) for all a, b.
(b) Compute A/R. 29. Let R be the equivalence relation in Exercise 21. De
22. Let 5 = {1,2,3,4} and A = S x S. Define the fol fine (a, b) + (a', b') = (a + a',b + b') for elements
lowing relation R on A: (a,b) R(a', b') if and only if of A. Prove or disprove that R((a, b)) + R((a', b')) =
a + fc = fl' + />'. R((a + a',b + b')).

4.6 Data Structures for Relations and Digraphs


The most straightforward method of storing data items is to place them in a lin
A
ear list or array. This generally corresponds to putting consecutive data items in
Do consecutively numbered storage locations in a computer memory. Figure 4.28 il
D,
lustrates this method for five data items D\,..., D5. The method is an efficient
use of space and provides, at least at the level of most programming languages,
D4 random access to the data. Thus the linear array might be A and the data would be
D5 in locations A[l], A[2], A[3], A[4], A[5], and we would have access to any data
item Dt by simply supplying its index i.
Figure 4.28 The main problem with this storage method is that we cannot insert new data
between existing data without moving a possibly large number of items. Thus, to
add another item E to the list in Figure 4.28 and place E between D2 and D3, we
would have to move D3 to A[4], D4 to A[5], and D5 to A[6], if room exists, and
then assign E to A[3].
An alternative method of representing this sequence is by a linked list, shown
in schematic fashion in Figure 4.29. The basic unit of information storage is the
storage cell. We imagine such cells to have room for two information items. The
first can be data (numbers or symbols), and the second item is a pointer, that is, a
number that tells us (points to) the location of the next cell to be considered. Thus
cells may be arranged sequentially, but the data items that they represent are not
assumed to be in the samesequence. Instead, we discoverthe properdata sequence
by following the pointers from each item to the next.
4.6 Data Structures for Relations and Digraphs 153

As shown in Figure 4.29, we represent the storage cell as a partitioned box


(o.-^ DATA1"e"|, with a dot in the right-hand side representing a pointer. A line is
drawn from each such dot to the cell that the corresponding pointer designates as
next. The symbol •—=i- means that data have ended and that no further pointers
need be followed.

1 D,^D In practice, the concept of a linked list may be implemented using two linear
arrays, a data array A and a pointer array P, as shown in Figure 4.30. Note that
U^ once we have accessed the data in location A[i], then the number in location P[i]
gives, or points to, the index of A containing the next data item.
Thus, if we were at location A[3], accessing data item D-i, then location P[3]
would contain 5, since the next data item, D3, is located in A[5]. A zero in some
location of P signifies that no more data items exist. In Figure 4.30, P[4] is zero
because A[4] contains D5, the last data item. In this scheme, we need two arrays
for the data that we previously represented in a single array, and we have only
sequential access. Thus we cannot locate D2 directly, but must go through the
Figure 4.29 links until we come to it. The big advantage of this method, however, is that the
actual physical order of the data does not have to be the same as the logical, or
natural, order. In the preceding example, the natural order is D\D2D^D4D5, but
the data are not stored this way. The links allow us to pass naturally through the
D4 4
data, no matter how they are stored. Thus it is easy to add new items anywhere.
3 If we want to insert item E between D2 and D3, we adjoin E to the end of the
array A, change one pointer, and adjoin another pointer, as shown in Figure 4.31.
D2 P 5
This approach can be used no matter how long the list is. We should have one
0 additional variable STARTholding the index of the first data item. In Figures 4.30
and 4.31, START would contain 2 since D{ is in A[2].
D3 1
It does not matter how large the data item is, within computer constraints, so
A might actually be a two-dimensional array or matrix. The first row would hold
Figure 4.30
several numbers describing the first data item, the second row would describe the
next item, and so on. The data can even be a pointer to the location of the actual
data. Some programming languages implement pointers directly, but there are
situations where it is advantageous to control linked lists explicitly as shown here.
START 2
Arrays and linked lists are examples of data structures. A data structure is
a conceptual way to organize data; the way a data structure is implemented may
o4 4 change depending on the hardware and computer language used. These are not
3
details appropriate for this book; here we use the abstract idea of a data structure.
Di
A computer program's efficiency often depends on the data structure it uses. In the
D2 6 remainder of this section, we investigate these issues by examining different data
P
structures for a relation.
D5 0
The problem of storing information to represent a relation or its digraph also
D3 1
has two solutions similar to those presented previously for simple data. In the first
E 5 place, we know from Section 4.2 that a relation R on A can be represented by an
n x n matrix MR if A has n elements. The matrix M^ has entries that are 0 or 1.
Figure 4.31 Then a straightforward data structure for R would beannxn array having O'sand
l's stored in each location. Thus, if A = {1, 2} and R = {(1, 1), (1, 2), (2, 2)},
then

--[J !]
and these data could be represented by a two-dimensional array MAT, where
MAT[1, 1] = 1, MAT[1, 2] = 1, MAT[2, 1] = 0, and MAT[2, 2] = 1.
A second data structure that could represent relations and digraphs is the
linked list idea described previously. For clarity, we use a graphical language. A
linked list will be constructed that contains all the edges of the digraph, that is, the
154 Chapter 4 Relations and Digraphs

ordered pairs of numbers that determinethose edges. The data can be represented
by two arrays, TAIL and HEAD, giving the beginning vertex and end vertex, re
spectively, for all arrows. If we wish to make these edge data into a linked list, we
will also need an array NEXT of pointers from each edge to the next edge.
Consider the relation whose digraph is shown in Figure 4.32. The vertices are
the integers 1 through 6 and we arbitrarily number the edges as shown. If we wish
to store the digraph in linked-list form so that the logical order coincides with the
numbering of edges, we can use a scheme such as that illustrated in Figure 4.33.
START contains 2, the index of the first data item, the edge (2, 3) (this edge is
labeled with a 1 in Figure 4.32). This edge is stored in the second entries of TAIL
and HEAD, respectively. Since NEXT[2] contains 10, the next edge is the one
located in position 10 of TAIL and HEAD, that is, (1, 2) (labeled edge 2 in Figure
4.32).
NEXT[10] contains 5, so we go next to data position 5, which contains the
edge (5,4). This process continues until we reach edge (3, 6) in data position 7.
This is the last edge, and this fact is indicated by having NEXT[7] contain 0. We
use 0 as a pointer, indicating the absence of any more data.
Figure 4.32 If we trace through this process, we will see that we encounter the edges in
exactly the order corresponding to their numbering. We can arrange, in a similar
way, to pass through the edges in any desired order.
This scheme and the numerous equivalent variations of it have important dis
advantages. In many algorithms, it is efficient to locate a vertex and then imme
diately begin to investigate the edges that begin or end with this vertex. This is
not possible in general with the storage mechanism shown in Figure 4.33, so we
now give a modification of it. We use an additional linear array VERT having one
position for each vertex in the digraph. For each vertex /, VERT[/] is the index,
in TAIL and HEAD, of the first edge we wish to consider leaving vertex /. In the
digraph of Figure 4.32, the first edge could be taken to be the edge with the small
est number labeling it. Thus VERT, like NEXT, contains pointers to edges. For
each vertex /, we must arrange the pointers in NEXT so that they link together all
edges leaving /, starting with the edge pointed to by VERT[/]. The last of these
edges is made to point to zero in each case. In a sense, the data arrays TAIL and
HEAD really contain several linked lists of edges, one list for each vertex.

START TAIL HEAD NEXT VERT TAIL HEAD NEXT

1 3 9 10 1 2 0
2 3 10 2 2 3 3
2 1 4 4 2 1 0
3 5 8 0 3 5 6
5 4 1 5 5 4 0
3 4 3 8 3 4 7
3 6 0 3 6 0
6 1 7 6 1 0
1 6 6 1 6 1
1 2 5 1 3 9

Figure 4.33 Figure 4.34

This method is shown in Figure 4.34 for the digraph of Figure 4.32. Here
VERT[1] contains 10, so the first edge leaving vertex 1 must be stored in the tenth
data position. This is edge (1, 3). Since NEXT[10] = 9, the next edge leaving
vertex 1 is (1, 6) located in data position 9. Again NEXT[9] = 1, which points us
to the edge (1, 2) in data position 1. Since NEXT[1] = 0, we have come to the end
4.6 Data Structures for Relations and Digraphs 155

of those edges that begin at vertex 1. The order of the edges chosen here differs
from the numbering in Figure 4.32.
We then proceed to VERT[2] and get a pointer to position 2 in the data. This
containsthe first edge leaving vertex 2, that is, (2, 3), and we can follow the point
ers to visit all edges coming from vertex 2. In a similar way, we can trace through
the edges (if any) coming from each vertex. Note that VERT[4] = 0, signifying
that there are no edges beginning at vertex 4.
VERT TAIL HEAD NEXT
Figure 4.35 shows an alternative to Figure 4.34 for describing the digraph.
The reader should check the accuracy of the method described in Figure 4.35. We
9 1 2 0 remind the reader again that the ordering of the edges leaving each vertex can be
3 2 3 0 chosen arbitrarily.
6 2 1 2 We see then that we have (at least) two data structures for representing a re
0 3 5 7
lation or digraph, one using the matrix of the relation and one using linked lists.
5 5 4 0
A number of factors determines the choice of a data structure. The total number
8 3 4 4
of elements n in the set A, the number of ordered pairs in R or the ratio of this
3 6 0
6 1 0
number to n2 (the maximum possible number of ordered pairs), and the possible
1 6 10
information that is to be extracted from R are all considerations. An analysis of
1 3 1
such factors will determine which of the storage methods is superior. We will
consider two cases.

Figure 4.35 Suppose that A = {1,2,..., N}, and let R be a relation on A, whose matrix
Mr is represented by the array MAT. Suppose that R contains P ordered pairs so
that MAT contains exactly P ones. First, we will consider the problem of adding
a pair (/, /) to R and, second, the problem of testing R for transitivity.
Adding (/, /) to R is accomplished by the statement
MAT[/,7] «-1.
This is extremely simple with the matrix storage method.
Now, consider the following algorithm, which assigns RESULT the value
T (true) or F (false), depending on whether R is or is not transitive. We note
that TRANS itself does not report whether R is transitive or not.
Algorithm TRANS
1. RESULT <- T
2. FOR 1 = 1 THRU N
a. FOR J = 1 THRU N
1. IF (MAT[J,J] = 1) THEN
a. FOR K = 1 THRU N
1. IF (MAT[J,X] = 1 and MAT[J,X] = 1) THEN
a. RESULT «- F •

Here RESULT is originally set to T, and it is changed only if a situation is


found where (/, J) e R and (J, K) e /?, but (/, K) £ R (a situation that violates
transitivity).
We now provide a count of the number of steps required by algorithm TRANS.
Observe that / and J eachrange from 1 to N. If (/, /) is not in /?, we only perform
the one test "IF MAT[7, /] = 1,"which will be false, and the rest of the algorithm
will not be executed. Since N2 - P ordered pairs do not belong to R9 we have
N2 —P steps that mustbe executed for such elements. If (/, /) € R, then thetest
"IF MAT[7, /] = 1" will be true and an additional loop
a. FOR K = 1 THRU N
1. IF CMAT[J,X] = 1 and MAT[J,X] = 0) THEN
a. RESULT «- F
156 Chapter 4 Relations and Digraphs

of N steps will be executed. Since R contains P ordered pairs, we have PN steps


for such elements. Thus the total number of steps required by algorithm TRANS
is

TA = PN + (N2-P).
Suppose that P = kN2, where 0 < k < 1, since P must be between 0 and N2.
Then algorithm TRANS tests for transitivity in

TA = kN3 + (1 - k)N2

steps.
Now consider the same digraph represented by our linked-list scheme using
VERT, TAIL, HEAD, and NEXT. First we deal with the problem of adding an edge
(/, J). We assume that TAIL, HEAD, and NEXT have additional unused position
available and that the total number of edges is counted by a variable P. Then the
following algorithm adds an edge (/, J) to the relation R.

Algorithm ADDEDGE
1. P «- P + 1
2. TAIL[P] <- I
3. HEAD[P] <- J
4. NEXT[P] +- VERT[J]
5. VERT[J] «- P

Figure 4.36 shows the situation diagrammatically in pointer form, both before
and after the addition of edge (/, /). VERT[/] now points to the new edge, and
the pointer from that edge goes to the edge previously pointed to by VERT[7], that
is, (/, J')- This method is not too involved, but clearly the matrix storage method
has the advantage for the task of adding an edge.

VERT TAIL HEAD NEXT

Blank Blank Blank

HEAD NEXT

•fir f ^ /
'

> *- / J 1

Figure 4.36
4.6 Data Structures for Relations and Digraphs 157

Algorithm NEWTRANS
1. RESULT <- T
2. FOR J = 1 THRU N
a. X <- VERT[J]
b. WHILE (X ^ 0)
1. J ^- HEAD[X]
2. Y <- VERT[J]
3. WHILE (Y ^ 0)
a. K <- HEAD[r]
b. TEST <- EDGE[I,X]
c. IF (TEST) THEN
1. Y <- NEXT[Y]
d. ELSE
1. RESULT <- F
2. Y <- NEXT[r]
4. X <- NEXT[X] •

The reader should follow the steps of this algorithm with several simple ex
amples. For each vertex /, it searches through all paths of length 2 beginning at /
and checks these for transitivity. Thus it eventually checks each path of length 2
to see if there is an equivalent direct path. Algorithm NEWTRANS is somewhat
longer than algorithm TRANS, which corresponds to the matrix method of stor
age, and NEWTRANS also uses the function EDGE; but it is much more like the
human method of determining the transitivity of R. Moreover, NEWTRANS may
be more efficient.
Let us analyze the average number of steps that algorithm NEWTRANS takes
to test for transitivity. Each of the P edges begins at a unique vertex, so, on the
average, P/N = D edges begin at a vertex. It is not hard to see that a function
EDGE, such as needed in NEWTRANS, can be made to take an average of about D
steps, since it must check all edges beginning at a particular vertex. The main FOR
loop of NEWTRANS will be executed N times, and each subordinate WHILE
statement will average about D executions. Since the last WHILE calls EDGE
eachtime, weseethattheentire algorithm will average about ND3 execution steps.
As before, we suppose that P = kN2 with 0 < k < 1. Then NEWTRANS
averages about
/kN2\3
Tl = nI — \ =k3N4 steps.

Recall that algorithm TRANS, using matrix storage, required about TA = kN3 +
(1 - k)N2 steps.
Consider now the ratio Ti/TA of the average number of steps needed with
linked storage versus the number of steps needed with matrix storage to test R for
transitivity. Thus

TL k3N4 k2N
TA kN3 + (1 - k)N2
G-0*
When k is close to 1, that is, when there are many edges, then TL/TA is nearly
N, so TL « TAN, and the linked-list method averages N times as many steps as
the matrix-storage method. Thus the matrix-storage method is N times faster than
the linked-list method in most cases.
158 Chapter 4 Relations and Digraphs

On the otherhand, if k is very small, then TL/TA may be nearly zero. This
means that if the number of edges is small compared with N2, it is, on average,
considerably more efficient to test for transitivity in a linked-list storage method
than with adjacency matrix storage.
We have, of course, made some oversimplifications. All steps do not take the
same time to execute, and each algorithm to test for transitivity may be shortened
by haltingthe searchwhenthe firstcounterexample to transitivity is discovered. In
spite of this, the conclusions remain true and illustrate the important point that the
choice of a data structureto represent objects such as sets, relations, and digraphs
has an importanteffect on the efficiency with which informationabout the objects
may be extracted.
Virtually all relations and digraphs of practical importance are too large to
be explored by hand. Thus the computer storage of relations and the algorithmic
implementation of methods for exploring them are of great importance.

4.6 Exercises
1. Verify that the linked-list arrangement of Figure 4.35 cor
rectly describes the digraph of Figure 4.32.

2. Construct a function EDGE(/, J) (in pseudocode) that re


turns the value T (true) if the pair (/, j) is in R and F
(false) otherwise. Assume that the relation R is given by
arrays VERT, TAIL, HEAD, and NEXT, as described in
this section.

3. Show that the function EDGE of Exercise 2 runs in an av


Figure 4.37
erage of D steps, where D = P/N, P is the number of
edges of R, and N is the number of vertices of R. (Hint: 7. Consider the following arrays.
Let Pij be the number of edges running from vertex i to
VERT =[1,2, 6,4]
vertex j. Express the total number of steps executed by
EDGE for each pair of vertices and then average. Use the TAIL = [1,2, 2,4,4, 3,4,1]
factthat££P,7 = P.) HEAD = [2, 2, 3, 3,4,4,1,3]
NEXT = [8, 3, 0, 5,7, 0,0, 0]
4. Let NUM be a linear array holding N positive integers,
and let NEXT be a linear array of the same length. Sup These describe a relation R on the set A = {1,2, 3,4).
pose that START is a pointer to a "first" integer in NUM, Compute both the digraph of R and the matrix MR.
and for each /, NEXT[7] points to the "next" integer in 8. The following arrays describe a relation R on the set
NUM to be considered. If NEXT[7] = 0, the list ends. A = {1, 2, 3,4, 5}. Compute both the digraph of R and
Write a function LOOK(NUM, NEXT, START, N, the matrix M/?.
K) in pseudocode to search NUM using the pointers in
NEXT for an integer K. If K is found, the position of K in VERT = [6, 2, 8, 7, 10]
NUM is returned. If not, LOOK prints "NOT FOUND." TAIL =[2, 2, 2, 2,1, 1,4,3,4,5]
HEAD = [4, 3, 5,1,2,3,5,4,2,4]
5. Let A = {1,2,3,4} and let R = {(1,1), (1,2), (1, 3),
(2,3), (2, 4), (3,1), (3,4), (4, 2)} be a relation on A. NEXT = [3, 1, 4, 0, 0, 5, 9, 0, 0, 0]
Compute both the matrix MR and the values of arrays
VERT, TAIL, HEAD, and NEXT desribing R as a linked 9. Let A = {1, 2, 3,4, 5} and let R be a relation on A such
that
list. You may link in any reasonable way.
1 0 0 1 0
0 1 1 0 0
6. Let A = {1, 2, 3,4} and let R be the relation whose di
M* = 0 0 0 1 0
graph is shown in Figure 4.37. Describe arrays VERT,
1 0 1 0 1
TAIL, HEAD, and NEXT, setting up a linked-list repre
0 10 0 1
sentation of R, so that the edges out of each vertex are
reached in the list in increasing order (relative to their Construct a linked-list representation, VERT, TAIL,
numbering in Figure 4.37). HEAD, NEXT, for the relation R.
4.7 Operations on Relations 159

10. Let A = {a, b, c, d, e] and let R be a relation described Construct a linked-list representation, VERT, TAIL,
by HEAD, NEXT, for the relation R.
ri o o 12. Let A = {F, M, R, W} and let R be a relation on A such
0 o 1 that
M* = 1 1 o ri 0
o 1 o 1 0
M* =
.10 0 1 1
Construct a linked-list representation, VERT, TAIL, 1 0
HEAD, NEXT, for the relation R. Construct a linked-list representation, VERT, TAIL,
11. Let A = {a, b, c, d] and let R be a relation on A such that HEAD, NEXT, for the relation R.
r i i o i •
0 110
MR =
0 111
1111

4.7 Operations on Relations


Now that we have investigated the classification of relations by properties they
do or do not have, we next define some operations on relations. As described
in Section 1.6, relations, together with these operations, and the accompanying
properties form a mathematical structure.
Let R and S be relations from a set A to a set B. Then, if we remember that
R and 5 are simply subsets of A_x B, we can use set operations on R and 5. For
example, the complement of R, R, is referred to as the complementary relation.
It is, of course, a relation from A to B that can be expressed simply in terms of R:

a Rb if and only if a ft b.

We can also form the intersection R D S and the union R U 5 of the relations R
and S. In relational terms, we see that a RH S b means that a Rb and a S b. All
our set-theoretic operations can be used in this way to produce new relations. The
reader should try to give a relational description of the relation R 0 S (see Section
1.2).
A different type of operation on a relation R from A to B is the formation
of the inverse, usually written R~l. The relation R~l is a relation from B to A
(reverse order from R) defined by

b R~l a if andonlyif a Rb.

It is clear from this that (R~{)~] = R. It is not hard to see that Dom(/?"1) =
Ran(#) and Ran(/?-1) = Dom(R). We leave these simple facts for the reader to
check.

Example 1 Let A = {1,2, 3,4} and B = {a, b, c}. Let

R = {(1, a), (1, b), (2, b), (2, c), (3, b), (4, a)]

and

S = {(l,b),(2,c),(3,b),(4,b)].

Compute (a) R', (b) RHS; (c)RU S; and (d) R~l.


160 Chapter 4 Relations and Digraphs
Solution
(a) We first find

A x B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c), (3, a),
(3,b),(3,c),(4,a),(4,b),(4,c)}.

Then the complement of R in A x B is

R = {(1, c), (2, fl), (3, a), (3, c), (4, b), (4, c)}.

(b) We have R n 5 = {(1, fc), (3, Z>), (2, c)}.


(c) We have

/? U S = {(1, a), (1, b), (2, b), (2, c), (3, b), (4, a), (4, b)].

(d) Since (x, y) e /?_I if and only if (y, x) e R, we have


R-1 = {(a, 1), (b, 1), (£, 2), (c, 2), (b, 3), (a, 4)}. ♦

Example 2 LetA = R. Let# bethe relation < on A and let 5 be >. Then thecomplement of
R is the relation >, since a ^ b means that a > b. Similarly, the complement of
S is <. On the otherhand, R~] = S, since for any numbers a and b,

a R~l b if and onlyif b R a if and only if b < a if and only if a >b.


Similarly, we have S~l = R. Also, we note that R D S is the relation of equality,
since a (R fl S) b if and only if a < b and a > b if and only if a = b. Since, for
any a and b, a < b or a > b must hold, we see that R U 5 = A x A; that is, /? U 5
is the universalrelation in which any a is related to any b. ♦

Example 3 LetA = {a,b,c, d, e] and let RandS be two relations on A whose corresponding
digraphs are shown in Figure 4.38. Then the reader can verify the following facts:

R = {(a, a), (b, b), (a, c), (b, a), (c, b), (c, d), (c, e), (c, a), (d, b),
(d, a), (d, e), (e, b), (e, a), (e, d), (e, c)}

R-1 = {(b, a), (e, b), (c, c), (c, d), (d, d), (d, b), (c, b), (d, a), (e, e), (e, a)}
RnS = {(a,b),(b,e),(c,c)]. ♦

Figure 4.38
4.7 Operations on Relations 161

Example 4 Let A = {1,2,3} and let Rand S berelations on A. Suppose that the matrices of
R and S are

1 0 1 0 1 1
M* = 0 1 1 and Ms = 1 1 0
0 0 0 0 1 0

Then we can verify that

0 1 o" 1 0 0
M« = 1 0 0 Mfi-,= 0 1 0
1 1 1 1 1 0

0 0 r 1 1 1
MRns = 0 1 0 M/?us = 1 1 1
0 0 0 0 1 0

Example 4 illustrates some general facts. Recalling the operations on Boolean


matrices from Section 1.5, we can show (Exercise 31) that if R and S are relations
on set A, then

M/ens = MR a M5
Mrus = Mr v Ms
M^-, = (Mr)7-.

Moreover, if M is a Boolean matrix, we define the complement M of M as the


matrix obtained from M by replacing every 1 in M by a 0 and every 0 by a 1. Thus,
if
"1 0 0'
M= 0 1 1
1 0 0

then
0
M = 1
0

We can also show (Exercise 31) that if R is a relation on a set A, then

M« = M*.

We know that a symmetric relation is a relation R such that MR = (MR)T,


and since (MR)T = Mr-i , weseethat R is symmetric if and only if R = R~l.
We now prove a few useful properties about combinations of relations.

THEOREM 1 Suppose that R and S are relations from A to B.


(a) If/?cs,then/r' c S~l.
(b) If R c 5, then S £R.
(c) (/?nS)-' = R~l D 5"1 and (R U S)~l = R~l U S"1.
(d) R~T)S = R US and RAJS = RC\S.
162 Chapter 4 Relations and Digraphs
Proof
Parts (b) and (d) are special cases of general set properties proved in Section 1.2.
We now prove part (a). Suppose that R c S and let (a, b) e R~l. Then
(b,a) e R, so (b, a) e S. This, in turn, implies that (a,b) e S~K Since each
element of R~l is in 5"1, we are done.
Wenextprovepart (c). For the firstpart, supposethat (a, b) e (RCiS)~l. Then
(b, a) e R n 5, so (b, a) e R and (b, a) e S. This means that (a, b) e R~l and
(a, b) e S~l, so (a, b) e R~l DS~l. The converse containment can beproved by
reversing the steps. A similarargument worksto showthat (RUS)~l = R~l US-1.

The relations R and R~l can be used to check if R has the properties of re
lations that we presented in Section 4.4. For instance, we saw earlier that R is
symmetric if and only if R = R~{. Here are some other connections between
operations on relations and properties of relations.

THEOREM 2 Let R and S be relations on a set A.


(a) If R is reflexive, so is R~{.
(b) If R and S are reflexive, then so are R C\ S and R U S.
(c) R is reflexive if and only if R is irreflexive.

Proof
Let A be the equality relation on A. We know that R is reflexive if and only if
AC/?. Clearly, A = A"1, so if A c R, then A = A-1 c R~l by Theorem
1, so R~~l is also reflexive. This proves part (a). To prove part (b), we note that if
A c R and A c 5, then A c R n S and A c R U S. To show part (c), we note
that a relation S is irreflexive if and only if 5 fl A = 01Then R is reflexive if and
only if A c R if and only if A fl R = 0 if and only if R is irreflexive. •

Example 5 Let A = {1, 2,3} and consider thetwo reflexive relations


J? = {(1,1), (1,2), (1,3), (2, 2), (3, 3)}

and

5 = {(1,1), (1,2), (2, 2), (3, 2), (3, 3)}.

Then

(a) R~{ = {(1,1), (2,1), (3,1), (2, 2), (3, 3)}; R and R~l are both reflexive.
(b) R = {(2,1), (2, 3), (3,1), (3, 2)} is irreflexive while R is reflexive.
(c) R H 5 = {(1, 1), (1, 2), (2, 2), (3, 3)} and R U 5 = {(1, 1), (1, 2), (1, 3),
(2, 2), (3, 2), (3, 3)} are both reflexive. ♦

THEOREM 3 Let R be a relation on a set A. Then


(a) R is symmetric if andonly if R = R~{.
(b) R is antisymmetric if and only if R C\ R~l c A.
(c) R is asymmetric if and onlyif R 0 R~~l =0.

Proof
The proof is straightforward and is left as an exercise.
4.7 Operations on Relations 163

THEOREM 4 Let R and 5 be relations on A.


(a) If R is symmetric, so are R~[ and R.
(b) If R and 5 are symmetric, so are R fl 5 and i?US.

If R is symmetric, /? = R~l and thus (J?"1)-1 = R = R~\ which means that


R~~l is also symmetric. Also, (a, b) € (R)~l if andonly if (b, a) € R if andonly
if (b, a) i R if and only if (a, b) <£ R~l = R if and only if (a, b) € /?, so R is
symmetric and part (a) is proved. The proof of part (b) follows immediately from
Theorem 1(c). •

Example 6 Let A = {1,2,3} and consider the symmetric relations

i? = {(1,1), (1,2), (2,1), (1,3), (3,1)}

and

5 = {(1,1), (1,2), (2,1), (2, 2), (3, 3)}.

Then

(a) R-{ = «1, 1), (2,1), (1,2), (3,1), (1,3)} and R = {(2, 2), (2, 3), (3, 2),
(3, 3)}; R l and R are symmetric.
(b) R H 5 = {(1, 1), (1, 2), (2, 1)} and R U 5 = {(1, 1), (1, 2), (1, 3), (2,1),
(2, 2), (3, 1), (3, 3)}, which are both symmetric. ♦

THEOREM 5 Let R and 5 be relations on A.


(a) (R fl 5)2 c R2 n 52.
(b) If /? and 5 are transitive, so is R n 5.
(c) If J? and 5 are equivalence relations, so is R (1 5.

Proof
We prove part (a) geometrically. We have a (R n S)2 b if and only if there is a
path of length 2 from a to b in RHS. Both edges of this path lie in R and in 5,
soa R2 b and a S2 b, which implies that a (R2 n 52) b. To show part (b), recall
from Section 4.4 that a relation T is transitive if and only if T2 c T. If /? and 5
are transitive, then R2 c J?, 52 c 5, so (/? fl 5)2 c/?2n52 [by part (a)] c Rn 5,
so /? fl 5 is transitive. We next prove part (c). Relations R and 5 are each reflexive,
symmetric, and transitive. The same properties hold for R fl 5 from Theorems
2(b), 4(b), and 5(b), respectively. Hence R fl S is an equivalence relation. •

Example 7 Let Rand Sbe equivalence relations on a finite set A, and let A/R and A/5 be the
corresponding partitions (see Section 4.5). Since R D S is an equivalence relation,
it corresponds to a partition A/(R fl S). We now describe A/(R fl S) in terms of
A/R and A/5. Let W be a block of A/(fl fl 5) and suppose that a and b belong to
W. Then a (RDS) b,soa R b and a 5 ft. Thus a and b belong to the same block,
say X, of A/R and to the same block, say Y, of A/5. This means that W c. XHY.
The steps in this argument are reversible; therefore, W = X D Y. Thus we can
directly compute the partition A/(R D S) by forming all possible intersections of
blocks in A/R with blocks in A/S. ♦
164 Chapter 4 Relations and Digraphs
Closures
If 7? is a relation on a set A,it may wellhappen that R lacks some of the important
relationalpropertiesdiscussedin Section4.4, especiallyreflexivity, symmetry, and
transitivity. If R does not possess a particular property, we may wish to add pairs
to R until we get a relation that does have the required property. Naturally, we
want to add as few new pairs as possible, so what we need to find is the smallest
relation R\ on A that contains R and possesses the property we desire. Sometimes
R\ does not exist. If a relation such as R\ does exist, we call it the closure of R
with respect to the property in question.

Example 8 Suppose that Ris a relation on a set A, and R is notreflexive. This canonly occur
because some pairs of the diagonal relation A are not in R. Thus R\ = R U A is
the smallest reflexive relation on A containing /?; that is, the reflexive closure of
R is R U A. ♦

Example 9 Suppose now that Ris a relation on Athatis notsymmetric. Then there must exist
pairs (x, y) in R such that (y, x) is not in R. Of course, (y, x) e R~\ so if R
is to be symmetric we mustadd all pairsfrom R~l; that is, we must enlarge R to
R UR~l. Clearly, (R UR~l)~l = R UR~\ soRU R~l is the smallest symmetric
relation containing R-, thatis, R U R~l is the symmetric closure of R.
If A = [a,b,c,d] and/? = {(a,b), (b,c), (a,c), (c, d)}, then R~l = {(b, a),
(c, b), (c, a), (d, c)}, so the symmetric closure of R is

R U R~l = {(a,b), (b, a), (b, c), (c, b), (a, c), (c, a), (c, d), (d, c)}. ♦

The symmetric closure of a relation R is very easy to visualize geometrically.


All edges in the digraph of R become "two-way streets" in R U R~l. Thus the
graph of the symmetric closure of R is simply the digraph of R with all edges
made bidirectional. We show in Figure 4.39(a) the digraph of the relation R of
Example 9. Figure 4.39(b) shows the graph of the symmetric closure R UR~l.

(b) flu/r1

The transitive closure of a relation R is the smallest transitive relation con


taining R. We will discuss the transitive closure in the next section.

Composition
Now suppose that A, B, and C are sets, R is a relation from A to B, and 5 is a
relation from B to C. We can then define a new relation, the composition of R
and 5, written SoR. The relation 5 o R is a relation from A to C and is defined as
follows. If a is in A and c is in C, then a (5 o R) c if and only if for some b in B,
we have a Rb and b 5 c. In other words, a is related to c by 5 o /? if we can get
from a to c in two stages: first to an intermediate vertex b by relation R and then
4.7 Operations on Relations 165

from b to c by relation 5. The relation So R mightbe thought of as "5 following


R" since it represents the combined effect of two relations, first R, then S.

Example 10 Let A = {1,2,3,4}, R = {(1,2), (1,1), (1,3), (2,4), (3,2)}, and 5 = {(1,4),
(1, 3), (2, 3), (3,1), (4,1)}. Since (1, 2) e R and (2, 3) e 5, we must have
(1, 3) e SoR. Similarly, since (1,1) € R and (1,4) € 5, we see that (1,4) e SoR.
Proceeding in this way, we find that 5 o R = {(1, 4), (1, 3), (1,1), (2,1), (3, 3)}.

The following result shows how to compute relative sets for the composition
of two relations.

THEOREM 6 Let R be a relation from A to B and let 5 be a relation from B to C. Then, if A i is


any subset of A, we have

(SoR)(Al) = S(R(Al)). (1)

Proof
If an element z e C is in (5 o R)(A\), then x (S o R) z for some jc in Ai. By the
definition of composition, this means that x R y and y 5 z for some y in B. Thus
y e R(x), so z e S(R(x)). Since {jc} c At, Theorem 1(a) of Section 4.2 tells us
that S(R(x)) c S(R(A{)). Hence z e S(R(A{)), so (5 o R)(AX) c S(R(A{)).
Conversely, suppose that z e S(R(A{)). Then z e S(y) for some j in R(A\)
and, similarly, y € R(x) for some x in A\. This means that jc R y and j 5 z, so
x (SoR) z. Thus z g (5 o J?)(Ai), so S(R(A{)) c (5 o l?)(Ai). This proves the
theorem. •

Example 11 Let A = [a, b,c] and let R and 5 be relations on A whose matrices are
0 1
M* = 1 Mc = 0
1 1

We see from the matrices that

(a,a)eR and (a,a)eS, so (a, a) e S o R


(a,c)eR and (c,a)eS, so (a,a) e S o R
(a,c)eR and (c,c)eS, so (a,c) e S o R.

It is easily seen that (a, b) £ SoR since, if we had (a, x) € R and (jc,Z?) e 5,
then matrix M* tells us that jc would have to be a or c; but matrix Ms tells us that
neither (a, b) nor (c, b) is an element of 5.
We see that the first row of MSor is 1 0 1. The reader may show by similar
analysis that
"10 1
MSoR= 1 1 1
0 1 1

We note that MSor = MR © Ms (verify this).

Example 11 illustrates a general and useful fact. Let A, B, and C be finite sets
with n, p, and m elements, respectively, let R be a relation from A to B, and let 5
be a relation from 5 to C. Then R and 5 have Boolean matrices MR and M5 with
respective sizes nx p and pxm. Thus M/? © M5 can be computed, and it equals
M5o*.
166 Chapter 4 Relations and Digraphs
To see this let A = [au..., an], B = [bu..., bp], and C = {c1?..., cm].
Also, suppose that MR = [ru ],Ms = [su ], and MSoR = [ tu ]. Then tu = 1
if and only if (a{, Cj) e SoR, which means that for some k, (ah bk) e R and
(bk, Cj) g 5. In other words, rik = 1 and skj = 1 for some k between 1 and p.
This condition is identical to the condition needed for MR Q Ms to have a 1 in
position i, j, and thus MSor and MR © Ms are equal.
In the specialcase where R and 5 are equal, we have SoR = R2 andM5o/? =
M^2 = MR © MR, as was shown in Section 4.3.

Example 12 Let us redo Example 10 using matrices. We see that


1 1 1 0 0 0 11
0 0 0 1 0 0 10
M* = and Ms =
0 10 0 10 0 0
0 0 0 0 10 0 0

Then
0 i r
0 0 0
M*©M5
0 0
0 0
so

5 o R = {(!,!), (1,3), (1,4), (2,1), (3, 3)}


as we found before. In cases where the number of pairs in R and 5 is large, the
matrix method is much more reliable. ♦

THEOREM 7 Let A, B, C, and D be sets, R a relation from A to B, 5 a relation from B to C,


and T a relation from C to D. Then

To(SoR) = (ToS)oR. M

Proof
The relations R, 5, and T are determined by their Boolean matrices MR, Ms, and
My, respectively. As we showed after Example 11, the matrix of the composition
is the Boolean matrix product; that is, M$qr = MR 0 M$. Thus

MTo{SoR) = MSoR QMT = (MR © Ms) O Mr.


Similarly,
M{ToS)or = MR © (Ms O Mr).
Since Boolean matrix multiplication is associative [see Exercise 37 of Section 1.5],
we must have
(MR © M5) © MT = MR © (Ms © MT),
and therefore
Mto(SoR) = M(7-0S)o/?
Then
T o (5 o R) = (T o 5) o R
since these relations have the same matrices.

The proof illustrates the advantage of having several ways to represent a rela
tion. Here using the matrix of the relation produces a simple proof.
In general, R o S ^ S o R, as shown in the following example.
4.7 Operations on Relations 167
Example 13 Let A = [a, b], R = [(a, a), (b, a), (b, b)]9 and 5 = {(a, b), (b, a), (b, b)}. Then
SoR = {(a, b), (b, a), (b, b)}> while R o S = {(a, a), (a, fo), (fc, a), (fc, ft)}. ♦

THEOREM 8 Let A, fl, and C be sets, /? a relation from A to fl, and 5 a relation from fl to C.
Then (5 o R)~{ = R~l oS~l.

Proof
Let c e C and agA, Then (c, a) e (S o R)~l if and only if (a, c) e S o R,
that is, if and only if there is a b € fl with (a, b) e R and (b, c) e 5. Finally,
this is equivalent to the statement that (c, b) e S~l and (b, a) e R~l; that is,
(c,a)€R-loS~l. M

4.7 Exercises

In Exercises I and 2, let R and S be the given relations from A


to B. Compute (a) R; (b) R D S; (c) R U S; (d) S~l.
1. A = B = {1,2,3}
R = {(1,1), (1,2), (2, 3), (3,1)}
S = {(2,1), (3,1), (3, 2), (3, 3)}

2. A = {a,b,c];B = [1,2,3]
R = {(a,l),(b,l),(c,2),(c,3)]
S = {(a,l),(a,2),(b,l),(b,2)]

3. Let A = a set of people. Let a Rb if and only if a and


fc are brothers; let a S b if and only if a and b are sisters.
Describe RUS.

4. Let A = a set of people. Let a R bif and only if a is older Figure 4.41
than b; let a 5 b if and only if a is a brother of b. Describe
RDS. In Exercises 9 and 10, let A = {1, 2, 3} and B = {1, 2, 3,4}.
Let R and S be the relations from A to B whose matrices are
5. Let A = a set of people. Let a R b if and only if a is the given. Compute(a) S; (b) R fl 5; (c) R U S; (d) R~l.
father of b; \etaSb if and only if a is the mother of b.
Describe RUS. 1 1 0 1~| 0 110
9. MR = 0 0 0 1 , Ms = 10 0 1
6. Let A = {2, 3, 6, 12} and let R and S be the following 1110 110 0
relations on A: x R y if and only if 2 | (jc - y); x S y if
and only if 3 | (jc — y). Compute
10 10" 1111
(a) R (b)RDS (c)RUS (d)S~l. 10. MR = 0 0 0 1 , M5 = 0 0 0 1
1110 0 10 1
In Exercises 7 and 8, let R and S be two relations whose corre-
sponding_digraphs are shown in Figures 4.40 and4.41. Com In Exercises 11 and 12, let A = {1,2, 3,4} and B = {1,2, 3}.
pute (a) R; (b) R D S; (c) R U S; (d) S~l. Given the matrices MR and Ms of the relations R and S from
A to B, compute (a) MRns; (b) MR{JS; (c) M/j-i; (d) Mj.
10 1" "0 i o-
0 1 1 1 0 1
11. MR = , M5 =
0 1 0 1 0 1
10 1. -1 1 1-

0 i o- "10 1-
0 1 1 1 0 1
12. MR = , M5 =
0 0 1 0 1 0
Figure 4.40 111. .0 1 0.
168 Chapter 4 Relations and Digraphs
13. Let A = fl = {1,2,3,4}, R = {(1, 1), (1, 3), (2, 3), (a) Is (2, 3) € R o 5?
(3, 1), (4, 2), (4,4)}, and S = {(1,2), (2, 3), (3,1), (3,2), (b) Is(8, l)efloS?
(4, 3)}. Compute (a) MRns; (b) MRUS; (c) M*-i; (d) My.
21. Let A = fl = C = the set of real numbers. Let R and S
14. Let
be the following relations from A to fl and from fl to C,
A = {1,2, 3,4,5, 6}, respectively:
R = {(1, 2), (1, 1), (2,1), (2, 2), (3, 3), (4,4), R = [(a, b)\a< 2b]
(5, 5), (5,6), (6,5), (6,6)}, and S = [(b,c)\b<3c].
S = {(1,1), (1,2), (1,3), (2,1), (2, 2), (2, 3),
(a) ls(l,5)eSoRl
(3,1), (3, 2), (3, 3), (4,6), (4,4), (6,4),
(b) Is (2, 3) € S o /??
(6, 6), (5,5)}
(c) Describe SoR.
be equivalence relations on A. Compute the partition cor
22. Let A = {1,2, 3,4}. Let
responding to R fl S.
15. Let A = [a,b,c, d, e] and let the equivalence relations R R = {(1,1), (1, 2), (2, 3), (2,4), (3,4), (4,1), (4,2)}
and S on A be given by S = [(3, 1), (4,4), (2, 3), (2,4), (1, 1), (1,4)}.
•1 1 1 1 0
(a) Is (1,3) eRoRl
1 1 1 1 0
MR = 1 1 1 1 0 (b) Is (4, 3)eSoRl
1 1 1 1 0 (c) Is (1, l)eRoSl
.0 0 0 0 1
(d) Compute R o R. (e) Compute SoR.
1 0 0 0 0"
(f) Compute Ro S. (g) Compute S o S.
0 1 1 0 0 23. (a) Which properties of relations on a set A are preserved
Mc 0 1 1 0 0 by composition? Prove your conclusion.
0 0 0 1 1 (b) If R and S are equivalence relations on a set A, is
0 0 0 1 1. S o R an equivalence relation on A? Prove your con
Compute the partition of A corresponding to R fl S. clusion.

16. Let A = {1,2,3,4} and R = {(2, 1), (2, 3), (3, 2), In Exercises 24 and 25, let A = [1,2,3,4,5] and let MR and
(3, 3), (2,2), (4, 2)}. Ms be the matrices of the relations R and S on A. Compute
(a) Find the reflexive closure of R. (a) MRoR; (b) MSoR; (c) MRoS; (d) M5o5.
(b) Find the symmetric closure of R. 24.
i o i i r
17. Let R be the relation whose matrix is 0 110 0
1 0 0 1 1 M* = 10 0 10
0 0 1 0 1 10 10 0
1 1 1 0 0 0 1111.
0 1 1 0 0
0 0 1 0 1 10 0 10
10 10 0
(a) Find the reflexive closure of R. 10 10 0
Mc =
(b) Find the symmetric closure of R. 0 1111
18. (a) Let R be a relation on a set A. Explain how to use .10 0 0 1
the digraph of R to create the digraph of the reflexive
25.
closure of R. 110 0 1
(b) Let R be a relation on a set A. Explain how to use the 0 0 0 10
digraph of R to create the digraph of the symmetric M* = 110 0 1
closure of R. 0 10 11

19. Explain why the concept of closure is not applicable for .10 0 0 0,
irreflexivity, asymmetry, or antisymmetry.
0 0 0 11
20. Let A = fl = C = the set of real numbers. Let R and S
10 0 0 1
be the following relations from A to fl and from fl to C, Mc = 0 10 10
respectively: 110 11
R = [(a, b)\a< 2b] and S = [(b, c)\b< 3c]. 10 10 0
4.8 Transitive Closure and Warshall's Algorithm 169

26. Let R and S be relations on a set A. If R and S are asym 31. Show that if fl and S are relations on a set A, then
metric, prove or disprove that RC\S and R U S are asym (a) M*n5 = MR a M5 (b) M*u5 = M«vMs
metric.
(c) Mtf-i = (M*)r (d) M*=M*
27. Let R and S be relations on a set A. If J? and S are an 32. Let fl and S be relations on a set A. Prove that
tisymmetric, prove or disprove that R 0 S and R U S are (RC)S)n Q R" HS", for n> 1.
antisymmetric.
In Exercises 33 through 35, let R and S be relations on a fi
In Exercises 28 and 29, let Rbe a relationfrom A to B and let nite set A. Describe how to form the digraph of the specified
S and T be relations from B to C. Prove or disprove. relation directlyfrom the digraphs of R and S.
28. (S U T) o R = (S o R) U (T o R) 33, fl"1 34. RPiS 35. flUS
29. (S C)T) o R = (S o R) D (T o R) 36, Let R and S be symmetric relations on a set A. Prove or
30. Let fl and S be relations from A to fl and let T be a rela disprove that R —S is also a symmetric relation on A.
tion from fl to C. Show that if fl c S, then ToR^ToS. 37. Prove Theorem 3.

4.8 Transitive Closure and Warshall's Algorithm


Transitive Closure

In this section we consider a construction that has several interpretations and many
important applications. Suppose that R is a relation on a set A and that R is not
transitive. We will show that the transitive closure of R (see Section 4.7) is just the
connectivity relation R°°, defined in Section 4.3.

THEOREM 1 Let R be a relation on a set A. Then fl00 is the transitive closure of R.

Proof
We recall that if a and b are in the set A, then a R°° b if and only if there is a path
in R from a to b. Now R°° is certainly transitive since, ifaR°°b and b fl°° c, the
composition of the paths from a to b and from b to c forms a path from a to c in fl,
and so a R°° c. To show that R00 is the smallest transitive relation containing fl,
we must show that if 5 is any transitive relation on A and R c 5, then fl00 c 5.
Theorem 1 of Section 4.4 tells us that if S is transitive, then Sn c S for all n;
that is, if « and b are connected by a path of length n, then a S b. It follows that
00

S°° = U 5" c 5. It is also true that if fl c S, then fl°° c S°°, since any path
in R is also a path in 5. Putting these facts together, we see that if fl c S and 5
is transitive on A, then fl°° c S°° c S. This means that R°° is the smallest of all
transitive relations on A that contain fl. •

We see that fl°° has several interpretations. From a geometric point of view,
it is called the connectivity relation, since it specifies which vertices are connected
(by paths) to other vertices. If we include the relation A (see Section 4.4), then
fl°° U A is the reachability relation fl* (see Section 4.3), which is frequently more
useful. On the other hand, from the algebraic point of view, fl°° is the transitive
closure of fl, as we have shown in Theorem 1. In this form, it plays important
roles in the theory of equivalence relations and in the theory of certain languages
(see Section 10.1).

Example 1 Let A = {1, 2, 3,4}, and let fl = {(1, 2), (2, 3), (3,4), (2, 1)}. Find the transitive
closure of fl.
170 Chapter 4 Relations and Digraphs
Solution

Method 1: The digraph of R is shown in Figure4.42. Since R°° is the transitive


closure, we can proceed geometrically by computing all paths. We see that from
vertex 1 we have paths to vertices 2, 3, 4, and 1. Note that the path from 1 to 1
proceedsfrom 1 to 2 to 1. Thus we see that the ordered pairs (1, 1), (1,2), (1, 3),
and (1,4) are in R°°. Startingfrom vertex 2, we have paths to vertices 2, 1, 3, and
4, so the ordered pairs (2,1), (2,2), (2,3), and (2,4) are in R00. The only other
path is from vertex 3 to vertex 4, so we have

Figure 4.42 R00 = {(1, 1), (1,2), (1,3), (1,4), (2,1), (2, 2), (2, 3), (2,4), (3,4)}.
Method 2: The matrix of R is

0 10 0
10 10
M,
0 0 0 1
0 0 0 0

We may proceed algebraically and compute the powers of Mr. Thus


10 10 0 10 1
0 10 1 10 10
(M,)| = 0 0 0 0
(M*)| = 0 0 0 0
0 0 0 0 0 0 0 0

10 10
0 10 1
(MR)4Q = 0 0 0 0
0 0 0 0

Continuing in this way, we can see that (Mr)q equals (Mr)^ if n is even and
equals (M/?)© if n is odd and greater than 1. Thus
1 1
1 1
M«oo = MR v (Mr)1 v (Mr)1 = 0 0
0 0 0 0

and this gives the same relation as Method 1. ♦

In Example 1 we did not need to consider all powers R" to obtain R00 This
observation is true whenever the set A is finite, as we will now prove.

THEOREM 2 Let A be a set with |A\ = n, and let R be a relation on A. Then

Rco = RUR2U--URn.

In other words, powers of R greater than n are not needed to compute R00.

Proof
Let a and b be in A, and suppose that a, xi, X2, • • •, xm, b is a path from a to b
in R; that is, (a, x\), {x\,X2),..., (xm, b) are all in R. If jc, and Xj are the same
vertex, say i < j, then the path can be divided into three sections. First, a path
from a to *,, then a path from *, to xj, and finally a path from Xj to b. The middle
path is a cycle, since xt = Xj, so we simply leave it out and put the remaining two
paths together. This gives us a shorter path from a to b (see Figure 4.43).
4.8 Transitive Closure and Warshall's Algorithm 171

Vi-----©
Figure 4.43

Now let a, jci, JC2,..., **, b be the shortest path from a to b. If a ^ b, then
all vertices a, x\, x2,..., **, b are distinct. Otherwise, the preceding discussion
shows that we could find a shorter path. Thus the length of the path is at most n —1
(since |A\ = n). If a = b, then for similar reasons, the vertices a, x\, x2,..., xk
are distinct, so the length of the path is at most n. In other words, if a R°° b, then
a Rk b, for some k, 1 < k < n. Thus R°° = R U R2 U •• • U Rn. •

The methods used to solve Example 1 each have certain difficulties. The
graphical method is impractical for large sets and relations and is not system
atic. The matrix method can be used in general and is systematic enough to be
programmed for a computer, but it is inefficient and, for large matrices, can be
prohibitively costly. Fortunately, a more efficient algorithm for computing transi
tive closure is available. It is known as Warshall's algorithm, after its creator, and
we describe it next.

Warshall's Algorithm
Let R be a relation on a set A = [a\, a2,..., an}. If x\, x2, ..., xm is a path in
R, then any vertices other than x\ and xm are called interior vertices of the path.
Now, for 1 < k < n, we define a Boolean matrix W* as follows. W* has a 1 in
positioni, j if and onlyif thereis a path from at to aj in R whoseinteriorvertices,
if any, come from the set [a\, a2,..., ak].
Since any vertex must come from the set [a\, a2,..., an], it follows that the
matrix Wn has a 1 in position i, j if and only if some path in R connects at
with aj. In other words, Wrt = M^oo. If we define W0 to be MR, then we will
have a sequence Wo, Wi,..., W„ whose first term is Mr and whose last term is
M/?oo. We will show how to compute each matrix W* from the previous matrix
W*_i. Then we can begin with the matrix of R and proceed one step at a time
until, in n steps, we reach the matrix of R°°. This procedure is called Warshall's
algorithm. The matrices W* are different from the powers of the matrix M*, and
this difference results in a considerable savings of steps in the computation of the
transitive closure of R.
Suppose that W* = [ ty ] and W*_i = [ su ]. If t{j = 1, then there must be
Subpath 2 a path from a, to a. whose interior vertices come from the set [a\,a2,..., ak}. If
the vertex ak is not an interior vertex of this path, then all interior vertices must
actually come from the set [a\, a2,..., ak-\], so stj = 1. If ^ is an interior
vertex of the path, then the situation is as shown in Figure 4.44. As in the proof of
Theorem 2, we may assume that all interior vertices are distinct. Thus a* appears
only once in the path, so all interior vertices of subpaths 1 and 2 must come from
the set [a\, a2,..., a^-x]. This means that sik = 1 and sy = 1.
Thus Uj = 1 if and only if either

(1) stj = 1 or
(2) sik = 1 and skj = 1.
172 Chapter 4 Relations and Digraphs
This is the basis forWarshall's algorithm. If W*_i has a 1 in position /, j then, by
(1), so will Wk. By (2), a new 1 can be added in position /, j of W* if andonly if
column k of W*_i has a 1 in position / and row k of W^-i has a 1 in position j.
Thus we have the following procedurefor computing W* from W*_i.
Step 1 First transfer to W* all 1's in W*_i.
Step 2 List the locations p\, p2,..., in column k of W*_i, where the entry is 1,
and the locationsq\, q2,..., in row k of W*_i, where the entry is 1.
Step 3 Put 1's in all the positions ph qj of W* (if they are not already there).

Example 2 Consider the relation Rdefined inExample 1. Then

0 10 0'
10 10
Wn - MR =
0 0 0 1
0 0 0 0

and n — 4.
First we find Wi so that k = 1. Wo has l's in location 2 of column 1 and
location 2 of row 1. Thus Wi is just Wo with a new 1 in position 2, 2.

0 10 0
1110
W, =
0 0 0 1
0 0 0 0

Now we compute W2 so that k = 2. We must consult column 2 and row 2 of


Wi. Matrix Wi has l's in locations 1 and 2 of column 2 and locations 1, 2, and 3
of row 2.
Thus, to obtain W2, we must put l's in positions 1, 1; 1, 2; 1, 3; 2, 1; 2, 2; and
2, 3 of matrix Wi (if l's are not already there). We see that

1110
1110
W2 =
0 0 0 1
0 0 0 0

Proceeding, we see that column 3 of W2 has l's in locations 1 and 2, and row
3 of W2 has a 1 in location 4. To obtain W3, we must put 1's in positions 1, 4 and
2, 4 of W2, so
1 1 1 1
1 1 1 1
W3 =
0 0 0 1
0 0 0 0

Finally, W3 has l's in locations 1, 2, 3 of column 4 and no l's in row 4, so no


new l's are added and M/?oo = W4 = W3. Thus we have obtained the same result
as in Example 1. ♦

The procedure illustrated in Example 2 yields the following algorithm for


computing the matrix, CLOSURE, of the transitive closure of a relation R rep
resented by the N x N matrix MAT.
4.8 Transitive Closure and Warshall's Algorithm 173

Algorithm WARSHALL
1. CLOSURE <- MAT
2. FOR K = 1 THRU N
a. FOR 1 = 1 THRU N
1. FOR J = 1 THRU N
a. CLOSURE [J, J] <- CLOSURE [J, J]
V (CLOSURE[ J,K] A CLOSURE[X, J] ) •

This algorithm was set up to proceed exactly as we have outlined previously.


With some slight rearrangement of the steps, it can be made a little more effi
cient. If we think of the testing and assignment line as one step, then algorithm
WARSHALL requires n3 steps in all. The Boolean product of twon x n Boolean
matrices A and B also requires n3 steps, since we must compute n2 entries, and
each of these requires n comparisons. To compute all products (Mr)%> (Mr)q,
..., (Mr)q, we require n3(n —1) steps, since we will need n —l matrix multipli
cations. The formula

Mtfoo = M* v (MR)% v ... v (MR)%, (1)

if implemented directly, would require about n4 steps without thefinal joins. Thus
Warshall's algorithm is a significant improvement over direct computation of MR<x>
using formula (1).
An interesting application of the transitive closure is to equivalence relations.
We showed in Section 4.7 that if R and S are equivalence relations on a set A,
then R H S is also an equivalence relation on A. The relation R fl S is the largest
equivalence relation contained in both R and 5, since it is the largest subset of
Ax A contained in both R and S. We would like to know the smallest equivalence
relation that contains both R and 5. The natural candidate is RUS, but this relation
is not necessarily transitive. The solution is given in the next theorem.

THEOREM 3 If R and S are equivalence relations on a set A, then the smallest equivalence
relation containing both R and S is (R U S)°°.

Proof
Recall that A is the relation of equality on A and that a relation is reflexive if
and only if it contains A. Then A c /?, A c 5 since both are reflexive, so
Ac/fusc(j?u S)00, and (R U S)00 is also reflexive.
Since R and S are symmetric, R = R~l and S = 5"1, so (R U S)~{ =
R~l US"1 = RU5, and RUS is also symmetric. Because of this, all paths in
R U S are "two-way streets," and it follows from the definitions that (R U S)00
must also be symmetric. Since we already know that (R US)°° is transitive, it is an
equivalence relation containing R U 5. It is the smallest one, because no smaller
set containing R U 5 can be transitive, by definition of the transitive closure. •

Example 3 Let A = [1,2, 3,4,5}, R = {(1,1), (1,2), (2,1), (2,2), (3, 3), (3,4), (4,3),
(4,4), (5, 5)}, and 5 = {(1, 1), (2, 2), (3, 3), (4,4), (4, 5), (5,4), (5, 5)}. The
reader may verify that both R and S are equivalence relations. The partition A/R
of A corresponding to R is {{1, 2}, {3,4}, {5}}, and the partition A/S of A cor
responding to S is {{1}, {2}, {3}, {4, 5}}. Find the smallest equivalence relation
containing R and 5, and compute the partition of A that it produces.
174 Chapter 4 Relations and Digraphs
Solution
We have

110 0 0 10 0 0 0
110 0 0 0 10 0 0
MR = 0 0 110 and Ms = 0 0 10 0
0 0 110 0 0 0 11
0 0 0 0 1 0 0 0 11

so
110 0 0
110 0 0
MRUS = MR V Ms = 0 0 110
0 0 111
0 0 0 11

We now compute M(Rus)oo by Warshall's algorithm. First, Wo = M/jus. We


next compute Wi, so k = 1. Since Wo has l's in locations 1 and 2 of column 1
and in locations 1 and 2 of row 1, we find that no new 1's must be adjoined to Wi.
Thus
Wi = W0.
We now compute W2, so k = 2. Since Wi has l's in locations 1 and 2 of
column 2 and in locations 1 and 2 of row 2, we find that no new 1's must be added
to Wi. Thus
W2 = W,.
We next compute W3, so k = 3. Since W2 has l's in locations 3 and 4 of
column 3 and in locations 3 and 4 of row 3, we find that no new 1's must be added
to W2. Thus
W3 = W2.
Things change when we now compute W4. Since W3 has l's in locations 3,
4, and 5 of column 4 and in locations 3,4, and 5 of row 4, we must add new 1's to
W3 in positions 3,5 and 5, 3. Thus
110 0 0
110 0 0
W4 = 0 0 111
0 0 111
0 0 111

The reader may verify that W5 = W4 and thus


(/? U S)00 = {(1,1), (1,2), (2, 1), (2, 2), (3, 3), (3,4), (3, 5), (4, 3),
(4,4), (4, 5), (5, 3), (5,4), (5, 5)}.

The corresponding partition of A is then (verify) {{1,2}, {3,4,5}}.

4.8 Exercises
1. (a) Let A = {1,2,3} and let R = {(1,1), (1,2), (2,3), (b) List the relation R°° whose matrix was computed in
(1, 3), (3,1), (3,2)}. Compute the matrix MR°° of part (a).
the transitive closure R by using the formula
2. For the relation R of Exercise 1, compute the transitive
Mroo = M« V (MR)l V (M*)* closure J?00 by using Warshall's algorithm.
4.8 Transitive Closure andWarshall's Algorithm 175
1 1 1 0 0-
3. Let A = [a{,a2,03, a4, a5] and let R be a relation on A
1 1 1 0 0
whose matrix is
15. MR = 1 1 1 0 0
0 0 0 1 1
10 0 10
0 0 0 1 1_
0 10 0 0
1 0 0 0 0-
M* = 0 0 0 11 Wo.
0 1 1 1 0
10 0 0 0
M, 0 1 1 1 0
0 10 0 1
0 1 1 1 0
0 0 0 0 1_
Compute Wj, W2, and W3 as in Warshall's algorithm.
1 0 0 0 0"
4. Find R°° for the relation in Exercise 3.
0 1 1 0 0

5. Let A = Z+ and R be the relation on A defined by a R b 16. MR = 0 1 1 0 0


0 0 0 1 1
if and only if b = a + 1. Give the transitive closure of R.
0 0 0 1 1_
6. Let A be the set of all people and R be the relation on A 1 1 0 0 0-

defined by a R b if and only if b is the mother of a. Give 1 1 0 0 0

the transitive closure of R. Ms = 0 0 1 0 0


0 0 0 1 0
7. Prove that if R is reflexive and transitive, then Rn = R for 0 0 0 0 1_
allw.
17. Compute A/R, A/S, and the partition of A that corre
sponds to the equivalence relation found in Exercise 15.
8. Let R be a relation on a set A, and let S = R2. Prove that
ifa,beA, then a S°° b if and only if there is a path in R 18. Compute A/R, A/S, and the partition of A that corre
from a to b having an even number of edges. sponds to the equivalence relation found in Exercise 16.
In Exercises 9 through 12, let A = {1, 2, 3, 4}. For the rela 19. Examine the results of Example 3 and Exercises 17 and
tion R whose matrix is given, find the matrix of the transitive 18. Based on these, give a procedure for producing
closure by using Warshall's algorithm. A/(R U 5)°° from A/R and A/S. Explain why the proce
1 0 0 n 110 0 dure works.
1100 10 0 0
9. M,= 10. MR = 20. Why is the procedure developed in Exercise 19 not a re
0010 0 0 0 0
placement for Warshall's algorithm?
0001 .0010
21. Let A = {1, 2, 3,4} and let R and S be the relations on A
1001 0 0 0 1 described by
0110 10 0 1
11. MR = 12. MR = -0001
0110 0 10 1
0 0 0 0
1001 0 0 10 MR =
0 10 0
_0 0 1 0
13. Let A = [I, 2, 3,4] and R = [(2, 1), (2, 3), (3, 2), (3, 3),
(2, 2), (4, 2)}. Define Rr to be the reflexive closure of and
110 0"
R and Rs to be the symmetric closure of R. Prove or dis
0 10 0
prove that the symmetric closure of Rr is the same relation Mc =
0 0 10
as the reflexive closure of Rs.
0 10 1

Use Warshall's algorithm to compute the transitive clo


14. Let A = {1, 2, 3,4} and R = [(2, I), (2, 3), (3, 2), (3, 3),
sure of R U S.
(2, 2), (4, 2)}. Define /?, to be the transitive closure of
R and Rs to be the symmetric closure of R. Prove or dis 22. Let A = [a,b,c, d, e] and let R and S be the relations on
prove that the symmetric closure of Rt is the same relation A described by
as the transitive closure of Rs.
10 10 1
In Exercises 15 and 16, let A = {1, 2, 3, 4, 5} and let R and 0 0 0 10
S be the equivalence relationson A whose matrices are given. M* = 10 0 0 0
Compute the matrix of the smallest equivalence relation con 0 0 110
taining R and S, and list the elements of this relation. 10 10 0
176 Chapter 4 Relations and Digraphs
and 23. Outline thestrategy of theproofof Theorem 1. What type
0 10 10 of proof is it?
110 0 1
Mc = 1110 0 24. Outline thestrategy of theproofof Theorem 2. Whattype
0 10 0 0 of proof is it?
0 10 10
25. Let A = R and R be the relation defined by a R b if and
Use Warshall's algorithm to compute the transitive clo only if \a\ < \b\. Compute the smallest equivalence rela
sure of R U S. tion containing R.

Tips for Proofs


Before beginning a proof, you should be able to restate the statement in your own
words. Consider carefully what the statement says. For example, Theorem 1,
Section 4.1, tells how to count the elements of \A x B\. Thus to prove it you
should try to apply one of the counting methods from Chapter 3.
Many statements about relations are statements about them as sets, and the
techniques of Chapter 1 can be used to prove them. As an example, consider Sec
tion 4.2, Theorem 1. Remember that a very common way to show that two sets are
equal is to show that each is a subset of the other. We do have other representa
tions for relations, too, and in some cases a proof based on matrix or digraph ideas
may be clearer. Also, this chapter contains many facts about relational properties,
operations on relations, and their interactions. These facts can form the basis of a
proof at the name level rather than at the element level; see, for example, Section
4.7, Theorem 2.
Many definitions in this chapter are biconditional statements. A biconditional,
p if and only if q, is generally proved in two parts: If p then q and if q then p.
This is done for Lemma 1, Section 4.5. A frequently used grammatical structure is
to introduce the second part of the proof with the word conversely. See Theorem
6, Section 4.7. Occasionally the proof of a biconditional is of the form p <$ q &
r <& ... <&t [Theorem 2(c), Section 4.7].
Checking whether a relation is an equivalence relation or has a certain re
lational property is the same as proving or disproving the statement R has the
property P(x). For this reason, you must work with generic elements or if R is
small, check all cases.
Some exercises in this chapter ask you to analyze a proof and outline its strat
egy or identify its key points. These exercises should help you develop the habit
of looking at all proofs for these features. Understanding how proofs you read are
carried out will help you create proofs yourself. At this point you should be able
to read a simple proof with understanding and recognize its structure.

• Key Ideas for Review


• Ax B (product set or Cartesian product): • Relative sets R(a), a in A, and R(B), B a subset of A: see
[(a,b) | a e A and 6 e B] page 130
• \AxB\ = \A\\B\ • Matrix of a relation: see page 131
• Database: collection of data • Digraph of a relation: pictorial representation of a relation:
• Relational database: see page 124 see page 132
• Attribute: characteristic of data • Path of length n from a to b in a relation R: finite se
quence a, x\, X2,..., xn-i, b such that a R x\,x\ R X2,...,
• Select: database operation that retrieves a set of records
xn-x R b
• Project: database operation that reports partial records
• jc Rn y (R a relation on A): There is a path of length n from
• Partition or quotient set; see page 125 x to v in R.
• Relation from A to J?: subset of A x B • x R°° v (connectivity relation for R): Some path exists in
• Domain and range of a relation: see page 130 R from x to v.
Chapter 4 Self-Test 177

• Theorem: M** = MR O M* 0 • • • © MR (n factors) a ~R b (complement of R): a ~Rb if and only ifa tb


• Properties of relations on a set A: R~l: (x,y) e R~l if andonly if (y, x) e R
Reflexive (a, a) e R for all a € A MRns = MR A M5
Irreflexive (a, a) £ R for all a e A MRUS = MR v M5
Symmetric (a,b) e R implies that (b,a) e R
M*-i =WR)T
Asymmetric (a,b) € R implies that (b, a) £ R
Antisymmetric (a,b) e R and (b,a) e R imply that
a = b
If R and S are equivalence relations, so is R fl S: see page
162
Transitive (a, b) e R and (b, c) e R imply that
(a, c)e R SoR: seepage 164
• Graph of a symmetric relation: see page 144 MSoR = MR O M5: see page 165
• Adjacent vertices: see page 144 Theorem: R°° is the smallest transitive relation on A that
• Equivalence relation: reflexive, symmetric, and transitive contains R: see page 169
relation Theorem: If \A\ = n, R00 = R U R2 U ••• U Rn
• Equivalence relation determined by a partition: see Warshall's algorithm: computes M^oo efficiently;
page 149 see page 172
• Linked-list computer representation of a relation: see Theorem: If R and S are equivalence relations on A,
page 152 (R U S)°° is the smallest equivalence relation on A contain
• Data structure: conceptual way to organize data ing both A and B.

• Chapter 4 Self-Test
1. What kind of mathematical object is A x Bl 12. Let D = {1,2,3,4,5,6} and R be the relation on D
whose matrix is
2. What kind of mathematical object is a partition of A?
10 0 0 0 1
3. What are the ways to represent a relation on a set A? 0 110 10
0 0 0 10 1
4. Which representations of a relation R on a finite set A MR =
10 0 10 1
would you use to test the transitivity of RI Why?
0 0 10 10
5. What are two interpretations of the transitive closure of a 0 10 0 11
relation RI
Determine whether R is reflexive, irreflexive, symmetric,
6. Let A = [2, 5, 7} and B = [x | x € Z+ and x3 < 100}. asymmetric, antisymmetric, or transitive.
(a) What is \A x B\l (b) List Ax B. 13. Suppose R is a relation on a set A and that R is asymmet
7. Let A and B be subsets of the universal set U. Then ric. Can R also be antisymmetric? Must R be antisym
AxBC.UxU. Is Ax B = A x 5? Justify your metric? Explain your answers.
answer. 14. Let B = [\,2,3,4,5], A = Bx B, and define R on A as
follows: (u, v) R (x, y) if and only if u —v = x —y.
8. Give all two-element partitions of [a, b, c, d, e].
(a) Prove that R is an equivalence relation.
9. Let C = [2, 8,14, 18}. Define a relation on C by x R y (b) Find [(2, 3)].
if and only if x —y > 5.
(c) Compute A/R.
(a) Draw the digraph of R.
15. The following arrays describe a relation R on the set
(b) GiveM*. A = {1, 2, 3, 4}. Give the matrix of R.
10. Let B = [a, b, c, d] and R = [(a, a), (a, b), {b, c), VERT = [5, 3, 1,8]
(c,d),(d,b)}.
TAIL = [3, 3, 2, 2, 1,1,4,4]
(a) Draw the digraphs of R and R2.
HEAD = [1,4, 1,3,2,3,4,2]
(b) Give MR and M^. NEXT = [2, 0, 4, 0, 6, 0, 0, 7]
(c) GiveM/joo.
16. Let R and S be relations on [a, b, c, d, e] where
11. Determine whether the relation R on the set A is reflex R = [(a, b), (a, c), (b, c), (c, e), (e, a), (a, a), (d, c)]
ive, irreflexive, symmetric, asymmetric, antisymmetric, or and S = {(a, a), (a, b), (b, a), (c, c), (c, d), (d, e),
transitive, if A = Z+; x R y if and only if x < 3y. (b,e),(e,d)].
178 Chapter 4 Relations and Digraphs
(a) Give R~l. (b) Compute RoS. Use Warshall's algorithm to find the matrix ofthe con-
17. Let /? = {(!,4), (2,1), (2,5), (2,4), (4, 3), (5, 3), (3, 2)}. nectivity relation based on R.

| Experiment 4
Equivalence relations and partial orders are defined as relations with certain prop
erties. In this experiment, you will investigate compatibility relations that are also
defined by the relation properties they have. A compatibility relation is a relation
that is reflexive and symmetric. Every equivalence relation is a compatibility re
lation, but here you will focus on compatibility relations that are not equivalence
relations.

Part I. 1. Verify that the relation R on A is a compatibility relation.


(a) A is the set of students at your college; x R y if and only if x
and y have taken the same course.
(b) A is the set of all triangles; x R y if and only if x and y have an
angle with the same measure.
(c) A = {1, 2, 3,4, 5}; R = {(1,1), (2, 2), (3, 3), (4,4), (5, 5),
(2, 3), (3, 2), (4,1), (1,4), (2,4), (4, 2), (1, 2), (2, 1), (4, 5),
(5,4), (1,3), (3,1)}.
2. In Part 1.1(c), the relation is given as a set of ordered pairs. A rela
tion can also be represented by a matrix or a digraph. Describe how
to determine if R is a compatibility relation using its
(a) Matrix.
(b) Digraph.
3. Give another example of a compatibility relation that is not an equiv
alence relation.

Part II. Every relation has several associated relations that may or may not share
its properties.
1. If R is a compatibility relation, is R~l, the inverse of R, also a com
patibility relation? If so, prove this^Jfnot, givea counterexample.
2. If R is a compatibility relation, is R, the complement of R, also a
compatibility relation? If so, prove this. If not, give a counterexam
ple.
3. If R and S are compatibility relations, is R o S also a compatibility
relation? If so, prove this. If not, give a counterexample.
Part III. In Section 4.5, we showed that each equivalence relation R on a set
A gives a partition of A. A compatibility relation R on a set A gives
instead a covering of A. A covering of A is a set of subsets of A,
k
[A\, A2,..., Ak}, such that (J A/ = A. We define a maximal compat-
/=i
ibility block to be a subset B of A with each element of B related by
R to every other element of B, and no element of A — B is R-related
to every element of B. For example, in Part 1.1(c), the sets {1, 2, 3} and
{1, 2,4} are maximal compatibility blocks. The set of all maximal com
patibility blocks relative to a compatibility relation R forms a covering
of A.

1. Give all maximal compatibility blocks for the relation in Part 1.1(c).
Verify that they form a covering of A.
Experiment 4 179

2. Describe the maximal compatibility blocks for the relation in Part


1.1(b). The set of all maximal compatibility blocks form a covering
of A. Is this covering also a partition for this example? Explain.
3. Thedigraph of a compatibility relation Rcanbe simplified byomit
ting the loop at each vertex and using a single edge with no arrow
between related vertices.
(a) Draw the simplified graph for the relation in Part 1.1(c).
(b) Describe how to find the maximal compatibility blocks of a
compatibility relation, given its simplified graph.
4. Find the covering of A associated with the relation whose simplified
graph is given in
(a) Figure 1. (b) Figure 2. (c) Figure 3.

Figure 1 Figure 2 Figure 3

5. Given the following covering of A, produce an associated compat


ibility relation R; that is, one whose maximal compatibility blocks
are the elements of the covering.

{{1,2}, {1,3, 6, 7}, {4, 5, 11},


{5,10}, {8, 5}, {2, 8, 9}, {3, 9}, {9,10}}

Is there another compatibility relation that would produce the same


covering of A?
CHAPTER

5 Functions
Prerequisites: Chapter 4

In this chapter we focus our attention on a special type of relation, a function, that
plays an important role in mathematics, computer science, and many applications.
We also define some functions used in computer science and examine the growth
of functions.

Looking Back
The origins of the notion of a function can be traced back to
the great Italian philosopher, astronomer, and mathematician
Galileo Galilei (1564-1642), who in the 1630s observed the
relationship between two variables. The early work on func
tions in the second half of the seventeenth century concentrated
on the study of special functions as curves. These included the
power, exponential, logarithmic, and trigonometric functions.
Gottfried Wilhelm Leibniz (1646-1716) was the first person to
use the word function for a quantity whose value varies as a
point moves on a curve. Leibniz was an extraordinary person
who made brilliant contributions in a number of diverse areas,
including logic, philosophy, law, metaphysics, religion, math
ematics, diplomacy, and literature. He has often been called a
"universal genius." Leibniz was born in Leipzig, and died in
Gottfried Wilhelm Leibniz Leonhard Euler
Hanover, both in Germany. Early in his career, he developed
the foundations for what would later be called symbolic logic
(which we discussed in Chapter 2). Leibniz began his study
of advanced contemporary mathematics in 1672 at the age of The commonly used notation for a function value, /(jc),
26. Three years later he discovered the Fundamental Theorem is due to Leonhard Euler (1707-1783), who was born in Basel,
of Calculus independently of Newton, who had also discovered Switzerland, and died in St. Petersburg, Russia. Euler is one of
the same result. Indeed, a heated battle raged over a number of the greatest and most prolific mathematicians in history. After
years between the supporters of Leibniz and Newton as to who his death, it took nearly 50 years to publish all his papers and his
had discovered calculus first. Today, both Newton and Leibniz collected works comprise more than 75 volumes. He was also
are considered the fathers of calculus. It is quite surprising to able to carry out complex calculations in his head. During the
learn what a visionary Leibniz was. In the 1670s he invented last 17 years of his life, Euler was totally blind, but his mathe
a mechanical calculator, known as the Leibniz wheel, capable matical output remained undiminished. Euler made significant
of adding, subtracting, multiplying, and dividing. He almost contributions to many areas of mathematics and used mathe
envisioned the modern age of computing! matics to solve a wide variety of problems in the sciences.

180
5.1 Functions 181

5.1 Functions
In this section we define the notion of a function, a special type of relation. We
study its basic properties and then discuss several special types of functions. A
number of important applications of functions will occur in later sections of the
book, so it is essential to get a good grasp of the material in this section.
Let A and B be nonempty sets. A function / from A to B, which is denoted
/: A -> B, is a relation from A to B such that for all a e Dom(/), f(a), the /-
relative set of a, containsjust one element of B. Naturally, if a is not in Dom(/),
then f(a) = 0. If f(a) = [b], it is traditional to identify the set [b] with the ele
ment b and write f(a) = b. We will follow this custom, since no confusion results.
The relation / can then be described as the set of pairs [(a, f(a)) \ a e Dom(/)}.
Functions are also called mappings or transformations, since they can be geo
metrically viewed as rules that assign to each element a e A the unique element
f(a) e B (see Figure 5.1). The element a is called an argument of the function
/, and f(a) is called the value of the function for the argument a and is also re
ferred to as the image of a under /. Figure 5.1 is a schematic or pictorial display
of our definition of a function, and we will use several other similar diagrams.
They should not be confused with the digraph of the relation /, which we will not
generally display.

Figure 5.1

Example 1 Let A = {1, 2, 3,4} and B = [a, b, c, d], and let


f = [(l,a),(2,a),(3,d),(4,c)}.
Here we have

f(D = a
f(2) = a
fO)=d
/(4) = c.
Since each set f(n) is a single value, / is a function.
Note that the element a e B appears as the second element of two different
ordered pairs in /. This does not conflict with the definition of a function. Thus a
function may take the same value at two different elements of A. ♦

Example 2 Let A = [I, 2, 3} and B = [x, y, z}. Consider the relations


R = [(l,x),(2,x)} and 5 = {(1,jc), (1, y), (2, z), (3, y)}.
The relation S is not a function since 5(1) = {jc, y}. The relation R is a function
with Dom(#) = {1, 2} and Ran(R) = [x]. ♦

Example 3 Let P be a computer program that accepts an integer as input and produces an
integer as output. Let A = B = Z. Then P determines a relation fP defined as
182 Chapter 5 Functions

follows: (m,n) e fP means that nisthe output produced by program P when the
input is m.
It is clear that fP is a function, since any particular input corresponds to a
unique output. (We assume that computer results are reproducible; that is,they are
the same each time the program is run.) +

Example 3 can be generalized to a program with any set A of possible in


puts and set B of corresponding outputs. In general, therefore, we may think of
functions as input-output relations.

Example 4 Let A = R be the set of real numbers, and let p(x) = a0 + a\x H f- anxn be
a real polynomial. Then p may be viewed as a relation on R. For each r in R we
determine the relative set p(r) by substituting r into the polynomial. Then, since
all relative sets p(r) are known, the relation p is determined. Since a unique value
is produced by this substitution, the relation p is actually a function. ♦

If the formula defining the function does not make sense for all elements of A,
then the domain of the function is taken to be the set of elements for A for which
the formula does make sense.
In elementary mathematics, the formula (in the case of Example 4, the poly
nomial) is sometimes confused with the function it produces. This is not harmful,
unless the student comes to expect a formula for every type of function.
Suppose that, in the preceding construction, we used a formula that produced
more than one element in p(x), for example, p(x) = ±*/x. Then the resulting
relation would not be a function. For this reason, in older texts, relations were
sometimes called multiple-valued functions.

Example 5 A labeled digraph is a digraph in which the vertices or the edges (or both) are
labeled with information from a set. If V is the set of vertices and L is the set of
labels of a labeled digraph, then the labeling of V can be specified to be a function
Boston f:V -> L, where, for each v e V, f(v) is the label we wish to attach to v.
Worcester ster^^ Similarly, we can define a labeling of the edges £ as a function g: E -> L, where,
49
for each e e E, g(e) is the label we wish to attach to e. An example of a labeled
Providence digraph is a map on which the vertices are labeled with the names of cities and
Hartford
n
39\J
• New Haven
the edges are labeled with the distances or travel times between the cities. Figure
5.2 shows an example of a labeled digraph. Another example is a flow chart of a
program in which the vertices are labeled with the steps that are to be performed at
that point in the program; the edges indicate the flow from one part of the program
Figure 5.2 to another part. ♦

Example 6 Let A = B = Z andlet /: A -> B be defined by


f(a) = a + 1, for a e A.

Here, as in Example 4, / is defined by giving a formula for the values f(a).

Example 7 Let A = Z andlet B = {0,1}. Let /: A -+ B be found by


if a is even
f(a) =
if a is odd.

Then / is a function, since each set f(a) consists of a single element. Unlike
the situation in Examples 4 and 6, the elements f(a) are not specified through an
algebraic formula. Instead, a verbal description is given. ♦
5.1 Functions 183

Example 8 Let A be an arbitrary nonempty set. The identity function on A, denoted by lA,
is defined by Ia(ci) = a. ♦

The reader may notice that \A is the relation we previously called A (see
Section 4.4), which stands for the diagonal subset of A x A. In the context of
functions, the notation 1^ is preferred, since it emphasizes the input-output or
functional nature of the relation. Clearly, if Aj c A, then l^(Ai) = Ai.
Suppose that /: A -» B and g: B -> C are functions. Then the composition
of / and g, g o f (see Section 4.7), is a relation. Let a e Dom(g o /). Then, by
Theorem 6 of Section 4.7, (g o f)(a) = g(f(a)). Since / and g are functions,
f(a) consists of a single element b e B, so g(f(a)) = g(b). Since g is also a
function, g(b) contains just one element of C. Thus each set (g o f)(a), for a
in Dom(g o /), contains just one element of C, so g o / is a function. This is
illustrated in Figure 5.3.

Figure 5.3

Example 9 LetA = B = Z, and C bethe setof even integers. Let /: A -> 5 and g: 5 -• C
be defined by
/(a) = ^ + 1
*(*) = 2b.
Find g o /.

Solution
We have
(S o /)(*) = *(/(*)) = g(a + 1) = 2(a + 1).
Thus, if / and g are functions specified by giving formulas, then so is g o f and the
formula forgof is produced by substituting the formula for / into the formula
for g. ♦

Special Types of Functions


Let / be a function from A to B. Then we say that / is everywhere defined if
Dom(/) = A. We say that / is onto if Ran(/) = B. Finally, we say that / is
one to one if we cannot have f(a) = f(a') for two distinct elements a and a' of
A. The definition of one to one may be restated in the following equivalent form:
If f (a) = f(a')9 then a = a'.
The latter form is often easier to verify in particular examples.

Example 10 Consider the function / defined in Example 1. Since Dom(/) = A, / is every


where defined. On the other hand, Ran(/) = {a,c,d} ^ B\ therefore, / is not
onto. Since
/(l) = /(2) = £i,
184 Chapter 5 Functions

we can conclude that / is not one to one. ♦

Example 11 Consider the function / defined inExample 6. Which ofthe special properties, if
any, does / possess?

Solution
Since the formula defining / makes sense for all integers, Dom(/) = Z = A, and
so / is everywhere defined.
Suppose that
f(a) = f(a')
for a and a! in A. Then
a + 1 = af + 1
so

a = a

Hence / is one to one.


To see if / is onto, let b be an arbitrary element of B. Can we find an element
a e A such that f(a) = bl Since

f(a)=a + h
we need an element a in A such that

a + l=b.

Of course,
a = b-l

will satisfy the desiredequationsince b-1 is in A. Hence Ran(/) = B\ therefore,


/ is onto. ♦

Example 12 Let A = {aua2ia3},B = {bub2,b3},C = {cuc2}, and D = {dud2,d3,d4}.


Consider the following four functions, from A to B, A to D, B to C, and D to B,
respectively.

(a) /i = {(fli, fe2), (a2, 63), (03, *i)l


(b) /2 = {(aud2), (a2, dx), (a3, d4)}
(c) /3 = {(fci,c2),(fc2,c2),(fe3,c1)}
(d) /4 = {Wl,*l),(d2,fe2),W3,*l)}
Determine whether each function is one to one, whether each function is onto, and
whether each function is everywhere defined.

Solution
(a) f\ is everywhere defined, one to one, and onto.
(b) f2 is everywhere defined and one to one, but not onto.
(c) /3 is everywhere defined and onto, but is not one to one.
(d) fa is not everywhere defined, not one to one, and not onto. ♦

If /: A -• B is a one-to-one function, then / assigns to each element a


of Dom(/) an element b = f(a) of Ran(/). Every b in Ran(/) is matched,
in this way, with one and only one element of Dom(/). For this reason, such
an / is often called a bijection between Dom(/) and Ran(/). If / is also every
where defined and onto, then / is called a one-to-one correspondence between A
and 5.
5.1 Functions 185

Example 13 Let SI be the set ofall equivalence relations on agiven set A, and let n be the set of
allpartitions onA. Then we can define a function /: 51 -> n asfollows. For each
equivalence relation Ron A, let f(R) = A/R, the partition of A that corresponds
to R. The discussion in Section 4.5 shows that / is a one-to-one correspondence
between fR and II. ♦

Invertible Functions
Afunction /: A->• B issaid to be invertible ifits inverse relation, f~\ isalso a
function. The next example shows that a function is not necessarily invertible.

Example 14 Let / be the function of Example 1. Then


f-1 = [{a,l)Aa,2),(d,3)AcA)}.
We see that f~l is nota function, since f~{ (a) = {1, 2}. ♦

The following theorem is frequently used.

THEOREM 1 Let /: A -> B be a function.


(a) Then f~l is a function from B to A if and only if / is one to one.
If f~l is a function, then
(b) the function f~x is also one to one.
(c) f~x is everywhere defined if and only if / is onto.
(d) f~l is ontoif and only if / is everywhere defined.

Proof
(a) We prove the following equivalent statement.

f~l is not a function if and only if / is notone to one.


Suppose first that f~l is not a function. Then, for some b in B, f~l(b)
must contain at least two distinct elements, a\ and a2. Then f(a\) = b =
f(a2), so / is not one to one.
Conversely, suppose that / is not one to one. Then f(a\) = f(a2)
= b for twodistinct elements a\ and a2 of A. Thus f~x (b) contains both
a\ and a2, so f~l cannotbe a function.
(b) Since (f~l)~l is thefunction /, part (a) shows that f~l is oneto one.
(c) Recall that Dom(/~1) = Ran(/). Thus B = Dom(/"1) if and only if
B = Ran(jf). In other words, f~l is everywhere defined if and only if /
is onto.
(d) Since Ran(/"1) = Dom(/), A = Dom(/) if and onlyif A = Ran(/"1).
That is, / is everywhere defined if and only if f~l is onto. •

As an immediate consequence of Theorem 1, we see that if / is a one-to-


one correspondence between A and B, then f~l is a one-to-one correspondence
between B and A. Note also that if /: A -> B is a one-to-one function, then the
equation b = f(a) is equivalent to a = f~~l(b).

Example 15 Consider thefunction / defined in Example 6. Since it is everywhere defined, one


to one, and onto, / is a one-to-one correspondence between A and B. Thus / is
invertible, and f~[ is a one-to-one correspondence between B and A. ♦
186 Chapter 5 Functions

Example 16 Let Rbe the set of real numbers, and let /: be definedby f(x) = x2. Is
/ invertible?

Solution
We must determine whether / is one to one. Since

/(2) = /(-2) = 4,
we conclude that / is not one to one. Hence / is not invertible. ♦

There are some useful results concerning the composition of functions. We


summarize these in the following theorem.

THEOREM 2 Let /: A -> B be any function. Then


(a) l*o/ = /.
(b) folA = f.
If / is a one-to-one correspondence between A and B, then
(c) rlof = lA.
(d) / o ri = \B.

Proof
(a) (1B o f)(a) = lB(f(a)) = f(a), for all a in Dom(/). Thus, by Theorem
2 of Section 4.2, lBof = f.
(b) (/ o lA)(a) = f(\A(a)) = /(fl), for all a in Dom(/), so / o \A = f.
Suppose now that / is a one-to-one correspondence between A and B.
As we pointed out, the equation b = f(a) is equivalent to the equation
a = f~{ (b). Since / and f~l are both everywhere defined and onto, this
means that, for allam A andb in B9 f(f~l (b)) = b and f~l (f(a)) = a.
(c) For all a in A, \A(a) = a = f~l(f(a)) = (f~{ o f)(a). Thus \A =
f~{of.
(d) For all b in fl, lB(b) = b = f(f~l(b)) = (/ o Z"1)^). Thus 1* =
/o/"1. •
THEOREM 3 (a) Let /: A -• B and g: B -+ A be functions such that g o / = 1A and
/og = 1#. Then / is a one-to-one correspondence between A and B, g is
a one-to-one correspondence between 5 and A, and each is the inverse of the
other.
(b) Let /: A -• B and g: B -> C be invertible. Then g o f is invertible, and
(gof)-l = f-log-K

Proof
(a) The assumptions mean that

g(/(fl)) = 0 and f(g(b)) = b, for all a in A and ft in 5.


This shows in particular that Ran(/) = B and Ran(g) = A, so each
function is onto. If f(ax) = f(a2), then ax = g(f(ax)) = g(f(a2)) =
a2. Thus / is one to one. In a similar way, we see that g is one to one,
so both / and g are invertible. Note that f~l is everywhere defined since
Dom(/_1) == Ran(/) = B. Now, if b is any element in B,
r\b) = rl(f(g(b)) = cr1 o ngm = iA(g(b)) = g(b).
5.1 Functions 187

Thus g = /-1, so also / = (fl)~l = g"1. Then, since g and / are


onto, fx and g~x are onto, so / and g must beeverywhere defined. This
proves all parts of part (a),
(b) We know that (g o f)~x = f"x o g'\ since this is true for any two
relations. Since g~~x and f~x are functions by assumption, so is their
composition, and then (g o f)~l is a function. Thus g o f is invertible.

Example 17 LetA = B = R, the set ofreal numbers. Let /: A -> B be given bythe formula
/(jc) = 2jc3 - 1 andlet g: B -* A be given by

*O0 =^b +5-


Show that / is a bijection between A and B and g is a bijection between B and A.

Solution

Let jc GAand y = f(x) = 2x3 - 1. Then \(y + 1) = jc3; therefore,

*=yfky +l =*w =*(/(*)) =(*° /)(*)•


Thus g o f = lA. Similarly, fog = 15, so by Theorem 3(a) both / and g are
bijections. ♦

As Example 17 shows, it is often easier to show that a function, such as /, is


one to one and onto by constructing an inverse instead of proceeding directly.
Finally, we discuss briefly some special results that hold when A and B are fi
nite sets. Let A = {a\,..., an) and B = [b\,..., bn}, and let / be a function from
A to B that is everywhere defined. If / is one to one, then f(a\), f(a2),..., f(an)
are n distinct elements of B. Thus we must have all of 5, so / is also onto. On
the other hand, if / is onto, then f(a\),...,f(an) form the entire set B, so they
must all be different. Hence / is also one to one. We have therefore shown the
following:

THEOREM 4 Let A and B be two finite sets with the same number of elements, and let
/: A ->• B be an everywhere defined function.
(a) If / is one to one, then / is onto.
(b) If / is onto, then / is one to one. •
Thus for finite sets A and B with the same number of elements, and particularly if
A = B, we need only prove that a function is one to one or onto to show that it is
a bijection. This is an application of the pigeonhole principle.

One-to-one functions are a fundamental tool in cryptology, because of the


need to both encode and decode. Many secret codes are simple substitution
codes created as follows. Let A = {a, b,..., z} be the English alphabet, and let
/: A —> A be a function agreed on in advance by each party to a correspondence.
A message is encoded by replacing each letter with its / image. In order for the
message to be decoded, the function / must have an inverse. The recipient de
codes the message by applying f~x to each letter. Weknow by Theorem 3(a) that
/ must therefore be one to one.
188 Chapter 5 Functions

Example 18 Suppose that / is defined by the following table:


A B C D E F G H I J K L M
D E S T I N Y A B C F G H
N 0 P Q R S T U V W X Y Z
J K L M 0 P Q R U V W X Z

Thus /(D) = T, /(R) = O, and so on. The rearrangement of the alphabet that
defines this function is an example of using a keyword to begin, then listing all
remaining letters in order.
The phrase THE TRUCK ARRIVES TONIGHT is encoded as

QAIQORSFDOOBUIPQKJBYAQ.
In this case, the inverse function is easily found by using the table from bottom to
top. Thus, we can decode the phrase CKAJADPDGKJYEIDOT as
JOHNHASALONGBEARD;

that is, JOHN HAS A LONG BEARD. ♦

5.1 Exercises

1. Let A = {a,b,c,d} and B = {1,2,3}. Determine that ZCR. Then for any real number a, let
whether the relation R from A to B is a function. If it
is a function, give its range. if a £Z
/(*) =
(a) fl = {(a,l),(ft,2),(c,l),(tf\2)} if a €Z.

(b) R = {(a, 1), (ft, 2), (flf 2), (c, 1), (d, 2)} 8. A = R, 2? = Z; /(a) = the greatest integer less than or
2. Let A = [a9b9c,d] and B = {1,2,3}. Determine equal to a.
whether the relation R from A to B is a function. If it
9. Let A = B = C = R, and let /: A -> B, g: B -> C be
is a function, give its range.
defined by f(a) = a —1 and g(ft) = ft2. Find
(a) * = {(a,3),(ft,2),(c,l)}
(a) (/og)(2) (b) (go/)(2)
(b) R = {(a, 1), (ft, 1), (c, 1), (<*, 1)} (c) (*o/)(x) W) (/<>*)(*)
3. Determine whether the relation R from A to B is a func (e) (/o/)(y) (f) (gog)()0
tion.
10. Let A = £ = C = R, and let /: A -* £, g: 5 -> C be
A = the set of all recipients of Medicare in the United defined by /(a) = a + 1 and g(ft) = ft2 + 2. Find
States, (a) (go/)(-2) (b) (/og)(-2)
B = {jc | x is a nine-digit number}, (c) (go/)(x) (d) (/og)W
a R ft if ft is a's Social Security number.
(e) (fof)(y) (f) (gog)OO
4. Determine whether the relation R from A to B is a func 11. In each part, sets A and B and a function from A to 2? are
tion. given. Determine whether the function is one to one or
A = a set of people in the United States, onto (or both or neither).
B = {* | jc is a nine-digit number}, (a) A = {1,2,3,4} = B\
a /? ft if ft is a9s passport number. / = {(1,1), (2, 3), (3,4), (4, 2)}
(b) A = {l,2,3};£ = {a,ft,c,rf};
In Exercises 5 through 8, verify that theformula yields a func / = {(1,0), (2,0), (3, c)}
tionfrom A to B.
12. In each part, sets A and B and a function from A to B are
5. A = B=Z;f(a)=a2 given. Determine whether the function is one to one or
onto (or both or neither).
6. A = B = R;f(a) = ea
(a) A= {i,i,I};£ = {*,;y,z,u;};
7. A = R, 5 = {0,1}; let Z be the set of integers and note
5.1 Functions 189

(b) A = {1.1,7,0.06}; B = {/?,?}; 24. / = {(l,a),(2,a),(3,c),(4,J)}


/ = {(1.1, p), (7,4), (0.06,/?)} 25. / = {(l,fl),(2,c),(3t«,(4,d)}
13. In each part, sets A and B and a function from A to B are 26. Let A = 5 = C = R and consider the functions
given. Determine whether the function is one to one or /: A -» £ and g: £ -> C defined by f(a) = 2a + 1,
onto (or both or neither). g(ft) = ft/3. Verify Theorem 3(b): (go/)"1 =/"1og"1.
(a) A = B = Z;f(a)=a-l 27. If a set A has « elements, how many functions are there
(b) A = R, B = {jc I jc is real and x > 0}; f(a) = \a\ from A to A?

14. In each part, sets A and B and a function from A to B are 28. If a set A has n elements, how many bijections are there
given. Determine whether the function is one to one or from A to A?
onto (or both or neither). 29. If A has m elements and B has n elements, how many
(a) A = R x R, B = R; f((a, ft)) = a functions are there from A to Bl

(b) Let 5 = {1, 2, 3}, 7 = {a, ft}. Let A = B = S x 7 30. Complete the following proof.
and let / be defined by /(n, a) = (n, ft), n = 1,2, 3, If /: A -» B and g: B -> C are one-to-one functions,
and/(n,ft) = (l,a),« = 1,2,3. then g o f is one to one.
15. In each part, sets A and 5 and a function from A to B are Proof: Let a\,a2 e A. Suppose (g o f){a\) =
given. Determine whether the function is one to one or (g o f)(a2). Then g(/(a,)) = g(/(a2)) and f(ax) =
onto (or both or neither). /(<22), because Thus a\ = a2, because
(a) A = B = R x R; /((a, ft)) = (a + ft, a - ft) Hence g o / is one to one.
(b) A = R, £ = {jc I jc is real and jc > 0}; f(a) = a2 31. Complete the following proof.
16. Let f(n) be the number of divisors of n, n e Z+. Deter
If /: A -> B and g: B -» C are onto functions, then
mine whether / is one to one or onto (or both or neither).
g o f is onto.
17. Let f(n) be the maximum of n and 50, n e Z+. Deter Proof: Choose x e Then there exists y e
mine whether / is one to one or onto (or both or neither). such that g(y) = x. (Why?) Then there exists z G
18. Explain why Theorem 1(a) is equivalent to "/_1 is not a such that f(z) = y (why?) and (g o /)(z) = jc. Hence,
function if and only if / is not one to one." g o / is onto.
19. Let/: A-+ £andg: B ^ A. Verify that g = f~x. 32. Let /: A -• 5 and g: B -> C be functions. Show that
(a) A = B = R; f(a) = s±l, g(b) = 2ft - 1 if g o / is one to one, then / is one to one.
(b) A = {x | jc is real and x > 0}; £ = {y [ y is real and 33. Let /: A -» B and g: B —> C be functions. Show that
y > -i}; /(<*) = a2-h g(b) = VftTT if g o / is onto, then g is onto.
20. Let/: A -• B andg: 5 -• A. Verify thatg = f~]. 34. Let A be a set, and let /: A -• A be a bijection. For any
integerk > 1, let /* = / o / o •••o / (Jc factors), andlet
(a) A = B =_P(S), where 5 is a set. If X e P(5), let
/-* = /"' o /-' o •.. o /-1 (* factors). Define /° to be
/(X) = X = g(X).
I4. Then fn is defined for all n € Z. For any a e A, let
(b) A = B = {1,2, 3,4}; 0(a, /) = {fn(a) I n e Z}. Prove that if a,, a2 € A, and
/ = {(1,4), (2,1), (3, 2), (4, 3)}; Ofo, /) H 0(fl2, /) ^ 0, then 0(a,, /) = 0(a2, /).
£ = {(1,2), (2, 3), (3,4), (4,1)}
35. Let /: A —• 5 be a function with finite domain and
21. Let / be a function from A to B. Find f~l. range. Suppose that | Dom(/)| = n and | Ran(/)| = m.
(a) A = {x | jc is real andjc > —1}; B = {jc \ Prove that
x is real and jc > 0}; f(a) = ^a + 1 (a) if / is one to one, then m — n.
(b) A = 5=R;/(a)=a3 + l (b) if / is not one to one, then m < n.
22. Let / be a function from A to 5. Find /_1. 36. Let \A\ = \B\ = n and let /: A -» B be an every
(a) A= B = R;f(a) = ^ where defined function. Prove that the following three
statements are equivalent.
(b) A = 5 = {1,2, 3,4, 5};
/ = {(1,3), (2, 2), (3,4), (4, 5), (5,1)} (a) / is one to one. (b) / is onto.
23. Let /(jc, y) = (2x - y, x - 2y), (jc, y) e R x R. (c) / is a one-to-one correspondence (that is, / is one to
one and onto).
(a) Show that / is one to one.
37. Give a one-to-one correspondence between Z+, the set
(b) Find/"1. of positive integers, and A = {jc | jc is a positive even
In Exercises 24 and 25, let f be a function from A = {1,2, integer}.
3,4} to B = [a, ft, c, d). Determine whether f~x is a func 38. Give a one-to-one correspondence between Z+, the set of
tion. positive integers, and A = {jc | jc is a positive odd integer}.
190 Chapter 5 Functions

39. Based on Exercises 37 and 38, does |Z+| = \A\ = \B\? 42, (a) Use the function in Example 18 to encode the mes
Justify your conclusion. sage COME BACK AT ONCE.
40. (a) LetA = Mand/: A-> R be defined by/(a) = a2. (b) Decode the following message that was encoded us
Proveor disprove that f(ax + a2) = f(ax) + f(a2). ing the function of Example 18.
(b) Let A = {a, b] and /: A* -* Z be defined by /(j)
is the length of the string s. Prove or disprove that QODLLITSDJJKQOIQROJ
f(si-si) = f(sx) + f(s2).
43. Use the method of Example 18 and the keyword JOUR
41. Let A = {0,1} and define aob = (a + b) mod 2. Let NALISM to encode the message ALL PROJECTS ARE
5 = [true,false). Define /: A -* B by /(0) = m<e and ON TRACK.
/(l) =/ate.
44. Substitution codeslikethe onein Example 18are not very
(a) Prove or disprove that f(a ob) = f(a) v /(Z?). secure. Describe a commonsense method to break such a
(b) Prove or disprove that f(a ob) = f(a) A f(b). code.

5.2 Functions for Computer Science


In previous chapters, we introduced on an informal basis some functions com
monly used in computer science applications. In this section we review these and
define some others.

Example 1 Let A be a subset of the universal set U = {ux, u2, u3,..., un}. The characteristic
function of A is defined as a function from U to {0,1} by the following:

if Ui e A
/a(k/) =
10 if ui £ A.

If A = {4, 7, 9} and U = {1, 2, 3,..., 10}, then fA(2) = 0, fA(4) = 1, fA(l) =


1, and /4(12) is undefined. It is easy to check that fA is everywhere defined and
onto, but is not one to one. ♦

Example 2 In Section 1.4 we defined a family of mod-rc functions, one for each positive
integer n. We call these functions fn\ that is, fn(m) = m (mod n). Each fn is
a function from the nonnegative integers to the set {0, 1, 2, 3, ..., n — 1}. For a
fixed a, any nonnegative integer z can be written as z = kn + r with 0 < r < n.
Then fn(z) = r. We can also express this relation as z = r (mod n) (see Section
4.5). Each member of the mod function family is everywhere defined and onto,
but not one to one. ♦

Example 3 Let A be the setof nonnegative integers, B = Z+, and let /: A -> B be defined
by f(n) = n\. ♦

Example 4 The general version of the pigeonhole principle (Section 3.3) required the floor
function, which is defined for rational numbers as f(q) is the largest integer less
than or equal to q. Here again is an example of a function that is not defined by a
formula. The notation LgJ is often used for f(q). Thus
/(1.5) = L1.5J = 1, /(-3) = L-3J = -3, f(-2.1) = L-2.7J = -3. ♦

Example 5 A function similar to that in Example 4 is the ceiling function, which is defined
for rational numbers as c(q) is the smallest integer greater than or equal to q. The
notation [q~\ is often used for c(q). Thus
c(1.5) = T1.51 = 2, c(-3) = r—31 = -3, c(-2.7) = r—2.71 = -2. ♦

Many common algebraic functions are used in computer science, often with
domains restricted to subsets of the integers.
5.2 Functions for Computer Science 191

Example 6 (a) Any polynomial with integer coefficients, p, can be used to define a function
onZ asfollows: If p(x) = a0 + axx + a2x2 + •••+ anxn and z € Z, then f(z)
is the value of p evaluated at z.
(b) Let A = B = Z+ and let /: A -• 5 be defined by /(z) = 2Z. We call /
the base 2 exponential function. Other bases may be used to define similar
functions.
(c) Let A = B = R and let fn: A -• B be defined for each positive integer
n > 1 as fn(x) = log„(jc), the logarithm to the base n of x. In computer
science applications, the bases 2 and 10 are particularly useful. ♦

In general, the unary operations discussed in previous sections can be used


to create functions similar to the function in Example 3. The sets A and B in
the definition of a function need not be sets of numbers, as seen in the following
examples.

Example 7 (a) Let A be a finite set and define /: A* -* Z as l(w) is the length of the string
w (see Section 1.3 for the definition of A* and strings).
(b) Let B be a finite subset of the universal set U and define pow(B) to be the
power set of B. Then pow is a function from V, the power set of U, to the
power set of V.
(c) Let A = B = the set of all 2 x 2 matrices with real number entries and let
t(M) = Mr, the transpose of M. Then t is everywhere defined, onto, and one
to one. ♦

Example 8 (a) For elements of Z+ x Z+, define g(zx,z2) to be GCD(zi, zi). Then g is a
function from Z+ x Z4" to Z+. The GCD of two numbers is defined in Section
1.4.
(b) In a similar fashion we can define m(zx, zi) to be LCM(zi, z2). ♦

Another type of function, a Boolean function, plays a key role in nearly all
computer programs. Let B = {true, false}. Then a function from a set A to 5 is
called a Boolean function. The predicates in Section 2.1 are examples of Boolean
functions.

Example 9 Let P(x): x is even and Q(y): y is odd. Then P and Q are functions from Z to B.
We see that P(4) is true and Q(4) is false. The predicate RQt, y): x is even or y is
odd is a Boolean function of two variables from Z x Z to B. Here R(3,4) is false
and R(6,4) is true. ♦

Hashing Functions
In Section 4.6, two methods of storing the data for a relation or digraph in a com
puter were presented. Here we consider a more general problem of storing data.
Suppose that we must store and later examine a large number of data records, cus
tomer accounts for example. In general we do not know how many records we
may have to store at any given time. This suggests that linked-list storage is ap
propriate, because storage space is only used when we assign a record to it and
we are not holding idle storage space. In order to examine a record we will have
to be able to find it, so storing the data in a single linked list may not be practical
because looking for an item may take a very long time (relatively speaking). One
technique for handling such storage problems is to create a number of linked lists
and to provide a method for deciding onto which list a new item should be linked.
This method will also determine which list to search for a desired item. A key
192 Chapter 5 Functions

point is to attemptto assignan item to one of the lists at random. (Rememberfrom


Section 3.4 that this means each list has an equal chance of being selected.) This
will have the effect of making the lists roughly the same size and thus keep the
searching time about the same for any item.
Suppose wemust maintain thecustomer records for a large company andwill
store the information as computer records. We begin by assigning each customer
a unique seven-digit account number. A unique identifier for a record is called its
key. For now we will not considerexactly how and what information will be stored
for each customer account, but will describe only the storage of a location in the
computer's memory where this information will be found. In order to determine
to which list a particular record should be assigned, we createa hashing function
from the setof keys to the setof listnumbers. Hashing functions frequently usea
mod-rc function, as shownin the next example.

Example 10 Suppose that (approximately) 10,000 customer account records must bestored and
processed. The company's computer is capable of searching a list of 100 items in
an acceptable amount of time. We decide to create 101 linked lists for storage,
because if the hashing function works well in "randomly" assigning records to
lists, we would expect to see roughly 100 records per list. We define a hashing
function fromthe set of seven-digit accountnumbersto the set {0,1, 2, 3,..., 100}
as follows:

h(n) = n (mod 101).

That is, h is the mod-101 function. Thus,

/K2473871) = 2473871 (mod 101) = 78.

This means that the record with account number 2473871 will be assigned to list
78. Note that the range of h is the set {0,1, 2,..., 100}. ♦

Because the function h in Example 10 is not one to one, different account


numbers may be assigned to the same list by the hashing function. If the first
position on list 78 is already occupied when the record with key 2473871 is to be
stored, we say a collision has occurred. There are many methods for resolving col
lisions. One very simple method that will be sufficient for our work is to insert the
new record at the end of the existing list. Using this method, when we wish to find
a record, its key will be hashed and the list /*(key) will be searched sequentially.
Many other hashing functions are suitable for this situation. For example, we
may break the seven-digit account number into a three-digit number and a four-
digit number, add these, and then apply the mod-101 function. Chopping the key
into pieces to create the function is the origin of the name hashing function. Many
factors are considered in addition to the number of records to be stored; the speed
with which an average-length list can be searched and the time needed to compute
the list number for an account are two possible factors to be taken into account.
For reasons that will not be discussed here, the modulus used in the mod function
should be a prime. Thus, in Example 10, we chose 101 as the modulus, rather than
100 or 102. Determining a "good" hashing function for a particular application is
a challenging task.
Hashing functions are also employed in other applications such as cryptology
where they are used to produce digital fingerprints and other electronic means to
verify the authenticity of messages.
5.2 Functions for Computer Science 193

Fuzzy Sets
Inour previous discussions, we saw that sets are precisely defined objects. If Ais
a subset of a universal set U9 then given any element x of U, it must be possible,
in principle at least, to say that x is a member of A or x is not a member of A.
However, the descriptions of many collections used in daily life and in practical
technology arenotsoprecise, but"fuzzy" in nature. Anexample is the"collection
of tall humans" in the universal set U of human beings. The adjective "tall" is
imprecise; its meaning is likely to depend on the people using it andthe situations
in which it is used.
Givena fixed range of height,the difficulty centers around the boundaryof the
collection. We may regard some people as definitely tall, and some as definitely
not tall, but in between there will be people that we feel are "somewhat tall" or "a
little tall." Membership in the collection of tall people is not a yes-or-no question,
but has degrees. One can be a member, somewhat of a member, or definitely not a
member. This is the idea of a fuzzy set. Other examples are

• the collection of rich people,


• the collection of automobile speeds that are too fast,
• the collection of dangerously close distances between moving objects, and
• the collection of useful laws.

What is needed is a precise way to deal with these useful "fuzzy" collections
that are not sets. We know from Chapter 1 that a set is completely described by
its characteristic function. By definition, the set A determines the characteristic
function fA. On the other hand, A = [x \ fA(x) = 1}, so the function, in turn,
determines the set. Which representation of a set we choose to use depends on the
task at hand. Any mathematical operation that we can perform on sets has a corre
sponding operation on the characteristic functions. Theorem 1, Section 1.3, states
some of these correspondences. For example, Theorem 1(a), Section 1.3, shows
that intersecting two sets corresponds to multiplying their characteristic functions.
One way to define a fuzzy set precisely is to use a function representation that is a
generalization of a characteristic function.
A fuzzy set in a universalset U is a function / defined on U and having values
in the interval [0,1]. This function is a generalization of the characteristic function
of a set. If f(x) = 0, then we say that x is not in the fuzzy set. If f(x) = 1, then
we say that x is in the fuzzy set. But if 0 < f(x) < 1, then f(x) can be thought of
as the degree to which x is in the fuzzy set. If the range of / is only the numbers
0 and 1, then / is the characteristic function of an ordinary set. Thus, ordinary
sets are special cases of fuzzy sets. Here, a function such as / is the fuzzy set, but
some other authors call a function such as / the membership function for the
fuzzy set.

Example 11 We define a universal set U to consist of all yearly incomes between $0 and
$1,000,000, in thousands. Thus, U is the interval [0, 1000]. Suppose we wish
to define the (fuzzy) set of rich people, based on yearly income. We may consider
that a person whose yearly income is greater than $250,000 is definitely rich, a
person with an income less than $30,000 is definitely not, and a person with an
income in between has some degree of "richness." With these initial conditions, a
possible fuzzy set of rich people is the function / in Figure 5.4. (The horizontal
line continues to 1000.)
An equation of the slanted line segment is f(x) = (x —30)/220, 30 < x <
250. (Why?) Based on this, a person with a yearly salary of $100,000 (or jc = 100)
194 Chapter 5 Functions

Figure 5.4

has degree of membership (100 - 30)/220 = 7/22 or about 0.32 in the fuzzy set
/, a person making less than $30,000 a year is not in this fuzzy set at all, and
a person making $300,000 a year is definitely rich. Many other fuzzy sets with
the same initial conditions could define the collection of rich people. The choice
of a defining function is highly subjective and may depend on the situation under
discussion.
Figure 5.5 shows another appropriate fuzzy set, g, where 0 < x < 1000,
g(x) = OforO < x < 30, andg(jc) = 1 forx > 250. ♦

l --

8 0.8--
|
5 0.6 +
o

6 0.4 f
Q
0.2

—r

30 250 500
Income

Figure 5.5

Example 12 Determine in which fuzzy set /, or g9 shown in Figures 5.4 and 5.5, the given
income has a higher degree of richness.
(a) $30,000 (b) $75,000 (c) $200,000 (d) $260,000

Solution
Although no explicit definition of g is provided, a comparison of the graphs shows
that /(30) = g(30) = 0 and /(260) = g(260) = 1, so the answer for parts (a) and
(d) is neither. It is geometrically clear that g(75) < f(15) and g(200) > /(200).
Thus, (b) and (c) have greater degrees of richness in / and g, respectively. ♦
5.2 Functions for Computer Science 195

Fuzzy Set Operations


Just as we can form unions, intersections, complements, and so on for sets, we can
define similar operations for fuzzy sets. Theorem 1, Section 1.3, shows one way
in which set operations can be described by computations with the characteristic
functions of these sets. Here is a generalization of this theorem that also appliesto
fuzzy sets.

THEOREM 1 Let A and B be subsets of the same universal set U. Then


(a) fAnB(x) = rmn{fa(x)9 fb(x)}.
(b) fAUBW = max{fA(x)9 fB(x)}.
(c) fA(x) = 1 - fA(x) (characteristic function of the complement of A). •
The proof of this theorem is left to the reader. Parts (a) and (c) can easily
be combined to express the characteristic function of the complement of one set
with respect to another or the symmetric difference of two sets. We note that
the computations on the right-hand side of these equations are also meaningful
for fuzzy sets. We now use these computations to define intersection, union, and
complementfor fuzzy sets. _
If / and g are fuzzy sets, then the fuzzy sets / n g9 f U g9 and / are defined,
respectively, to be the functions defined by the extension of parts (a), (b), and (c)
of Theorem 1.

Example 13 Two fuzzy sets, / and g9 in the universe of real numbers between 0 and 10 are
shown in Figure 5.6 and their explicit definitions are also given. Compute the
degree of membership of
(a) 3.5in/Hg (b) Tin ff)g (c) 3.5in/U# (d) 7in/Ug.

-j^jc2 for 0 < x < 4


for 0 < jc < 3
1 f or 4 < jc < 6
/(*) = x-x+n- for 3 < x < 5
- \x + 4 for 6 < jc < g(x) =
for 5 < x < 1
for 8 < jc < 10

0.5--

Figure 5.6

Solution
By using the algebraic definitions, we have /(3.5) = (3.52)/16 = 49/64 and
#(3.5) = (-3.5/4) + (7/4) = 56/64. So (/ n g)(3.5) = min{49/64, 56/64}
or 49/64 and (/ U g)(3.5) = 56/64. We also see that f(l) = 4 - 7/2 = 1/2
and g(l) = 1/2. Thus, the degree of membership of 7 in both the union and
intersection of / and g is 1/2. ♦
196 Chapter 5 Functions

Because / and g are in the same universal set, we can quickly sketch the graph
of/ n g (or / Ug) by graphing / and g on the same axes, as shown in Figure 5.7,
and tracing the lower (or upper) graph segments.

l --

Figure 5.7

Using this method, we construct the intersection and union of / and g and
show the results in Figure 5.8.

(/n*)(*) (/u*)(*)

^—i—*x

(a)

Figure 5.8

Fuzzy Logic
In Chapter 2 we note the many similarities between sets and propositions. (Com
pare, for example, Theorem 1, Section 1.2, and Theorem 1, Section 2.2.) These
similarities are not surprising since many sets can be defined by specifying a prop
erty P(x) that elements of the set have in common. A simple case is A = [x \
x is an even number}; here P(jc) is "jc is an even number." Such a P(jc) is called
a prepositional function or a predicate. The range of P is {false, true}. If false is
assigned the value 0 and true, the value 1, then the predicate is the same as the
characteristic function of the set.
By allowing a predicate to have values in the interval [0,1], we create the
notion of a fuzzy predicate. This allows us to work with statements that are not
simply true or false, but may be true to varying degrees. Fuzzy logic is the name
given to the analysis and manipulation of fuzzy predicates, and to the process of
forming arguments, drawing conclusions, and taking actions based on them.
Fuzzy logic plays an important role in control theory and expert systems. For
example, some computers use fuzzy logic to control a machine in a way similar
to that used by a human, reacting to conditions such as "too close" or "too hot,"
5.2 Functions for Computer Science 197

and interpreting "fuzzy" implications such as"If you are too close, slow down and
move a little to the right."
Today many automobiles contain devices that are controlled by fuzzy logic.
Considerthe following simplified example. An automobile has sensors that mea
sure the distance between the front bumper and the rear of the car ahead, and
sensors that can determine if the tires are skidding on the road surface. Automo
bile engineers want to design a device that accepts these inputs and applies the
brakes automatically to various degrees.
First the engineers state in general terms what they want to happen. For ex
ample:
If the car is too close to the car in front, then apply the brakes.
If the car gets even closer to the car in front, apply the brakes more.
If the car is near the point wherethe tires will skid, then apply the brakesless.
One simple way to approach this problem is to construct fuzzy sets for the predi
cates /(jc): "x is too close" and g(x): "jc is near to skidding." Then the pressure
on the brakescan be computed from the degreeof memberships in the fuzzy sets /
and g, possibly by looking at the fuzzy set f —g.Tf(f —g)(x) is 0, no additional
brakes are applied, and higher degrees of membership will translate into greater
pressure on the brakes. Thisexample is too simplified for practical situations, but
more complex versions are in use in many ways today.

5.2 Exercises

1. Let / be the mod-10 function. Compute 9. f(n) = 3n2 - 1


(a) /(417) (b) /(38) (c) /(253) (a) /(3) (b) /(17) (c) /(5) (d) /(12)
2. Let / be the mod-10 function. Compute 10. g(n) = 5-2n
(a) /(81) (b) /(316) (c) /(1057) (a) g(4) (b) g(U) (c) g(129) (d) g(23)
In Exercises 3 and 4, use the universal set U = {a9b, c, ..., 11. Let f2(n) = 2n. Compute each of the following.
y9z] and the characteristicfunction for the specified subset to (a) /2(1) (b) /2(3) (c) f2(5) (d) /2(10)
compute the requestedfunction values. 12. Let f3(n) = 3". Compute each of the following.
3. A = {a9 e9 /, o9 u) (a) /3(2) (b) /3(3) (c) /3(6) (d) /3(8)
(a) fA(i) (b) fA(y) (c) fA(o)
4. B = {m,n9o9 p9q9r9z} In Exercises 13 through 16, let lg(x) = log2(x).
(a) fB(a) (b) fB(m) (c) fB(s) 13. Compute each of the following.
5. Compute each of the following. (a) fe(16) (b) fe(128) (c) fe(512) (d) lg(l02A)
(a) L2.78J (b) L-2.78J (c) LHI 14. For each of the following find the largest integer less than
(d) L-17.3J (e) L21.5J or equal to the function value and the smallest integer
6. Compute each of the following. greater than or equal to the function value.
(a) T2.781 (b) T-2.781 (c) R41 (a) /g(10) (b) lg(25)
(d) r-17.31 (e) T21.51 15. For each of the following find the largest integer less than
or equal to the function value and the smallest integer
7. Let k9 n be positive integers with k < n. Prove that the
greater than or equal to the function value.
number of multiples of k between 1 and n is - .
(a) lg(50) (b) Ig(lOO)
16. For each of the following find the largest integer less than
8. Prove that if n is odd, then — = .
I4 | 4 or equal to the function value and the smallest integer
greater than or equal to the function value.
In Exercises 9 and 10, compute the values indicated. Note that
if the domainofthesefunctions is Z+, then eachfunction is the (a) lg(256) (b) lg(500)
explicitformula for an infinite sequence. Thus sequences can 17. Prove that the function in Example 7(c), t: {2x2 matrices
be viewed as a special type offunction. with real entries} ->(2x2 matrices with real entries} is
198 Chapter 5 Functions

everywhere defined, onto, and one to one. InExercises 30 through 36, let f andg bethefuzzy setswhose
18. Let A = {a9 b9 c9 d}. Let / be the function in Example graphs anddefinitions are shown in Figure 5.9.
7(a).
1-X+2-3 f or 0 < x < 3
(a) Prove that / is everywhere defined. (x-3)2
1- for 3 < x < 5
(b) Prove that / is not one to one.
f(x) = 0 for 5 < x < 1
(c) Prove or disprove that / is onto.
for 7 < x < 9
19. Let A be a set with n elements, S be the set of relations
on A, and M the set of n x n Boolean matrices. Define for9<x < 10
/: S -+ M by f(R) = M*. Prove that / is a bijection
between S and M.

20. Let p be a Boolean variable. Howmanydifferent Boolean


functions of p are there? How many different Boolean
functions of two Boolean variables are there?
21. Build a table to represent the Boolean function
f(x, y9 z) = (~* A y) v z for all possible valuesof
x9 y9 and z.
22. Let P be the propositional function defined by P(jc, y) =
(x v y) a ~y. Evaluate each of the following.
(a)
(a) P(true, true) (b) P(false, true)
(c) P(true, false)
23. Let Q be the propositional function defined by 0 for 0 < x < 2
Q(x): 3(y € Z+)(xy = 60). Evaluate each of the fol
\x- 1 for 2 < x < 4
lowing.
-jc + 5 f or 4 < x < 5
(a) Q(3) (b) Q(7) (c) Q(-6) (d) Q(15) g(x) =
0 for 5 < jc < 7
In Exercises 24 through 26, use the hashingfunction h, which x- 1 f or 7 < x < 8
takes thefirst three digits of the account number as one num for 8 <x < 10
ber and the last four digits as another number, adds them, and
then applies the mod-59function.
24. Assume that there are 7500 customer records to be stored
using this hashing function.
(a) How many linked lists will be required for the stor
age of these records?
(b) If an approximately even distribution is achieved,
roughly how many records will be stored by each
linked list?

25. Determine to which list the given customer account


should be attached. (b)

(a) 3759273 (b) 7149021 (c) 5167249 Figure 5.9


26. Determine which list to search to find the given customer
30. Find the degree of membership of 2.5 in
account.
(a) fOg (b) fUg (c) /.
(a) 2561384 (b) 6082376 (c) 4984620
31. Find the degree of membership of 3.5 in
27. Refer to Section 3.4, Exercise 37 for the average num
ber of steps needed to search an array of length n for a (a) frig (b) fug (c) /.
key. Suppose a hashing function based on mod k is used 32. Find the degree of membership of 8 in
to store m items. On average, how many steps will be (a) fng (b) fUg (c) J.
required on average to search for a key?
33. (a) For what values does x belong to / for certain?
28. Use the characteristic function of a set to prove that if
\A\ = n9 then \pow(A)\ = 2\ (b) For what values does x belong to g for certain?

29. Let fA be the characteristic function of A with respect to 34. Sketch the graph of / U g.
the universal set U. What does the set f~x (1) represent? 35. Sketch the graph of fOg.
5.2 Functions for Computer Science 199

This new string qxq2--q2n has left and


36. Sketch the graph of g.
rightparentheses. Explain yourreasoning.
37. Forthegraph shown in Figure 5.8(b), give thecoordinates
of the lowestpoint between (3, 1) and (5, 1). 45. To complete the one-to-one correspondence between the
p and the q strings of Exercise 44, we must show that
38. (a) Define the complement of fuzzy set g with respect
to the fuzzy set / by generalizing the definition of any string withn - 1 left and n + 1 rightparentheses can
be paired with exactly one string with n left and n right
A — B for sets,
parentheses that is not well formed. Let rxr2r3 --r2n con
(b) Define the symmetric difference of fuzzy sets / and sist of n - 1 left and n + 1 right parentheses. There must
g by generalizing the definition of symmetric differ be a firstpositionj wherethe numberof rightparentheses
ence for sets. is greater than the number of left parentheses. Why? So
In Exercises 39 and 40, use thefuzzy sets f and g shown in in rxr2r3 •••r,- there is one more rightthan left parenthe
Figure 5.9. sis. Hence in rj+x •••r2n, thenumber of leftparentheses is
than the number of right parentheses. Make a new
39. Compute the degree of membership in the complementof string sxs2 - - -s2n as follows:
g with respect to /, / —g, of
(a) 2 (b) 9. Sk = n, 1,2,...,7
40. Compute the degree of membership in the symmetric dif
and
ference of / and g, / 0 g, of
(a) 2 (b) 4.5.
ifrk = )
41. Prove Theorem 1. Sk for k = j + 1, j + 2,..., 2n.
ifrk = (
Exercises 42 through 46 use ideas from this section to com
plete a discussion begun in Section 3.5, Exercises 38 through This new string sxs2 • • •s2n has. . left and _ -right
40. Pairs of parentheses are often used in mathematical ex parentheses. Explain how you know sxs2 • • •s2n is not well
pressions to indicate the order in which operations are to be formed.

done. A compiler (or interpreter)for a programming language 46. Using the results of Exercises 44 and 45, the number of
must check that pairs ofparentheses are properly placed. This strings with n left and n right parentheses that are not well
may involve a number of things, but one simple check is that formed is equal to the number of strings with n — 1 left
the number of left and right parentheses are equal and that and n + 1 right parentheses. By Section 3.2, this number
in reading from left to right the number of left parentheses is is
always greater than or equal to the number of right parenthe 47. Use the results of Exercises 42 and 46 to give a formula
ses read. An expression that passes this check is called well for Cn. Confirm this result by comparing its values with
formed. The task here is to count the number of well-formed those found in Exercise 43.
strings ofn left and n right parentheses. This number is Cn,
48. Express C„ using the notation for combinations and with
the nth Catalan number.
out this notation.
42. How many strings of n left and n right parentheses can be
Another application of mod functions occurs in assigning an
made (not just well-formed ones)?
ISBN (International Standard Book Number) to each title pub
43. List all well-formed strings of n left and n right parenthe lished. The 10-digit ISBN encodes information about the lan
ses for n = 1, 2, 3. What are the values of CXy C2, and guage ofpublication, the publisher, and the book itself. This
C3? is an example of coding for error checking rather thanfor se
44. We will count the strings that are not well formed by mak curity purposes. For example, the ISBN for the fourth edition
ing a one-to-one correspondence between them and a set of this book is 0-13-083143-3; the 0 indicates the book was
of easier to count strings. Suppose pxp2p3 • • •p2n is not published in an English-speaking country and the 13 identifies
well formed; then there is a first /?, that is a right parenthe the publisher. The last digit is a check digit chosen to help
sis and there are fewer left parentheses than right paren prevent transcription errors. Ifdxd2di • • •dgc is an ISBN, then
theses in pxp2 • • • pt. How many fewer are there? So to c is chosen so that
the right of pi the number of left parentheses is
than the number of right parentheses. Make a new string (d\ + 2d2 + 3d3 + • • • + 9d9 + 10c) = 0 (mod 11).
qxq2'-q2n as follows:
Ifc is 10, then the Roman numeral X is used.
qj = Pj> 7 = 1,2, ...,/
49. (a) Verify that 3 is the correct check digit for this book's
ISBN.
and
(b) Compute the check digit c for the following ISBNs.
if Pj = )
*J for; =i + 1,/ +2, ...,2n. (i) 0-471-80075-c (ii) 0-80504826-c
if Pj = ( (iii) 88-8117-275-c (iv) 5-05-001801-c
200 Chapter 5 Functions

50. (a) Make one change in the first nine digits ofthe ISBN (b) Make two changes in thefirst nine digits of theISBN
0-183-47381-7 so that the check digit will indicate 0-183-47381-7 so that the check digit will not indi
an error.
cate an error.

5.3 Growth of Functions


In the earlier discussion of data structures forrelations (Section 4.6), we saw that
one ofthe factors determining the choice ofdata structure is the efficiency ofhan
dling the data. Inthe example oftesting tosee ifarelation istransitive, the average
number of steps needed was computed for an algorithm with the relation storedas
a matrix andfor an algorithm with the relation stored using a linked list. The re
sults were that it would take roughly kn3 + (1 - k)n2 steps using matrix storage
and k3n4 steps using a linked list, where the relation contains kn2 ordered pairs.
Although many details were ignored, these rough comparisons give enough infor
mation to make some decisions about appropriate data structure. In this section
we apply some concepts from previous sections and lay the groundwork for more
sophisticated analysis of algorithms.
The idea of one function growing more rapidly than another arises naturally
when working with functions. In this section we formalize this notion.

Example 1 Let Rbe a relation on a set A with \A\ = n and \R\ = \n2. If Ris stored as a
matrix, then t(n) = \n3 + \n2 is a function that describes (roughly) the average
number of steps needed to determine if R is transitive using the algorithm TRANS
(Section 4.6). Storing R with a linked list and using NEWTRANS, the average
number ofsteps needed is (roughly) given by s(n) = |w4. Table 5.1 shows that s
grows faster than t.

10 55Q ;? 1250
100 * 505,000 12;500,000

Let / and g be functions whose domains are subsets of Z+, the positive inte
gers. We say that / is O(g), read / is big-Oh of g, if there exist constants c and
k such that \f(n)\ < c • \g(n)\ for all n > k. If / is O(g), then / grows no faster
than g does.

Example 2 The function f(n) = \n3 + \n2 is 0(g) for g(n) = n3. To see this, consider

-n3 + -n2 < -n3 + -n39 ifn > 1.


2 2 ~ 2 2

Thus,
-n3 + -n2 < 1 -n3, ifn > 1.
2 2
Choosing 1 for c and 1 for k, we have shown that |/(n)| < c • \g(n)\ for all n > 1
and/is 0(g). ♦

The reader can see from Example 2 that other choices of c, k, and even g are
possible. If \f(n)\ < c\g(n)\ for all n > k, then we have \f(n)\ < C • \g(n)\
for all 7i > £ for any C > c, and \f(n)\ < c • \g(n)\ for all n > K for any
5.3 Growth of Functions 201

K > k. For the function t inExample 2,t is 0(h) for h(n) = dn3, if d > I, since
\t(n)\ < 1•\g(n)\ < \h(n)\. Observe also that t is 0(r(n))for r(n) = n4, because
^rc3 + \n2 <n3 <n4 for all n > 1. When analyzing algorithms, we want to know
the "slowest growing" simple function g for which / is 0(g).
It is common to replace g in 0(g) with the formula that defines g. Thus we
writethat t is 0(n3). This is calledbig-0 notation.
We say that / and g have the same order if / is 0(g) and g is 0(f).

Example 3 Let f(n) = 3n4 - 5n2 and g(n) = n4 bedefined for positive integers n. Then /
and g have the same order. First,

3n4 - 5n2 < 3n4 + 5n2


<3n4 + 5n4, ifn> 1
= Sn4.

Let c = 8 and Jfc = 1, then |/(n)| < c . |g(n)| for all n > £. Thus / is 0(#).
Conversely, n4 = 3n4 - 2n4 < 3n4 - 5n2 ifn>2. This is because if n > 2, then
n2 > |, 2n2 > 5, and 2n4 > 5n2. Using 1for c and 2for k, we conclude that g is
0(f). ♦

If / is 0(g) but g is not 0(f), we say that / is lower order than g or that /
grows more slowly than g.

Example 4 The function f(n) = n5 is lower order than g(n) = n7. Clearly, if n > 1, then
h5 < n1. Suppose that there exist c and k such that n1 < cn5 for all n > fc.
Choose N so that N > k and N2 > c. Then N7 < cN5 < N2 • AT5, but this is a
contradiction. Hence / is 0(g), but g is not 0(/), and / is lower order than g.
This agrees with ourexperience thatn5 grows more slowly than n1. ♦

We define a relation ©, big-theta, on functions whose domains are subsets of


Z+ as / © g if and onlyif / and g havethe same order.

THEOREM 1 Therelation 0, big-theta, is an equivalence relation.

Proof
Clearly, © is reflexive since every function has the same order as itself. Because
the definition of same order treats / and g in the same way, this definition is
symmetric and the relation 0 is symmetric.
To see that © is transitive, suppose / and g have the same order. Then there
exist cx and kx with \f(n)\ < cx • \g(n)\ for all n > kx, and there exist c2 and k2
with \g(n)\ < c2 • \f(n)\ for all n > k2. Suppose that g and h have the same order;
then there exist c3, k3 with \g(n)\ < c3 • \h(n)\ for all n > k3, and there exist c4, k4
with \h(n)\ < c4 • \g(n)\ for all n > k4.
Then \f(n)\ < c{ . \g(n)\ < cx(c3 • \h(n)\) if n > k{ and n > k3. Thus
\f(n)\ < cxc3 • \h(n)\ for all n > maximum of k\ and k3.
Similarly, \h(n)\ < c2c4 • \f(n)\ for all n > maximum of k2 and k4. Thus /
and h have the same order and © is transitive. •

The equivalence classes of © consist of functions that have the same order.
We use any simple function in the equivalence class to represent the order of all
functions in that class. One ©-class is said to be lower than another ©-class if a
representative function from the first is of lower order than one from the second
class. This means functions in the first class grow more slowly than those in the
202 Chapter 5 Functions

second. It is the ©-class of a function that gives the information we need for
algorithm analysis.

Example 5 All functions that have the same order as g(n) = n3 are said to have order ®(n3).
The mostcommon orders in computer scienceapplications are ©(1), ©(n), ©(n2),
®(n3), ®(lg(n))9 @(nlg(n)), and 0(2"). Here 0(1) represents the class of con
stant functions and Ig is the base 2 log function. The continuous versions of some
of these functions are shown in Figure 5.10. ♦

Figure 5.10

Example 6 Every logarithmic function f(n) = \ogb(n) has the same order as g(n) = lg(n).
There is a logarithmic change-of-base identity

logfc(x) =
loga(b)

in which loga(b) is a constant. Thus

|lo&(n)| <J^Mn)\
and, conversely,
\lg(n)\<lg(b).\logb(n)\.

Hence g is 0(f) and / is 0(g). ♦

It is sometimes necessary to combine functions that give the number of steps


required for pieces of an algorithm as is done in the analysis of TRANS (Section
4.6), where functions are added, and in the analysis of NEWTRANS, where func
tions are multiplied. There are some general rules regarding the ordering of the
©-equivalence classes that can be used to determine the class of many functions
and the class of the sum or product of previously classified functions.
5.3 Growth of Functions 203

Rules for Determining the ©-Class of a Function


1. 0(1) functions are constant and have zero growth, the slowest growth possi
ble.
2. ®(lg(n)) is lower than ®(nk) if k > 0. This means that any logarithmic
function grows more slowly than any power function with positiveexponent.
3. ®(na) is lower than ©(nb) if and onlyif 0 < a < b.
4. &(an) is lower than ®(bn) if and only if 0 < a < b.
5. ®(nk) is lower than ®(an) for any power nk and any a > 1. This means that
any exponential function with base greater than 1 grows more rapidly than any
power function.
6. If r is not zero, then ®(rf) = ©(/) for any function /.
7. If h is a nonzero function and © (/) is lower than (or the same as) ©(g), then
®(fh) is lower than (or the same as) © (gh).
8. If ©(/) is lower than 0(g), then ©(/ + g) = 0(g).

Example 7 Determine the ©-class ofeach of the following.


(a) f(n) = An4 - 6n7 + 25n3
(b) g(n) = lg(n)-3n
(c) h(n) = l.ln+n15

Solution
(a) By Rules 3,6, and 8, the degree of the polynomial determines the ©-class
of a polynomial function. ©(/) = ©(w7).
(b) Using Rules 2, 6, and 8, we have that 0(g) = ®(n).
(c) By Rules 5 and 8, ®(h) = 0(1.ln). ♦

Example 8 Using the rules for ordering ©-classes, arrange the following inorder from lowest
to highest.

®(nlg(n)) ®(l000n2-n) ®(n0'2) 0(1,000,000) ®(l3n) 0(w + lO7)

Solution
0(1,000,000) is the class of constant functions, so it is the first on the list. By
Rules 5 and 8, 0(n + 107) is lower than 0(lOOOn2 - n), buthigher than ®(n02).
To determine the position of ®(nlg(n)) on the list, we apply Rules 2 and 7. These
give that ®(nlg(n)) is lower than ®(n2) and higher than ®(n). Rule 5 says that
0(1.3") is the highest class on this list. In order, the classes are

0(1,000,000) ®(n02) ®(n + 107)


®(nlg(n)) ©(lOOOrc2 - n) 0(1.3"). ♦

The ©-class of a function that describes the number of steps performed by


an algorithm is frequently referred to as the running time of the algorithm. For
example, the algorithm TRANS has an average running time of n3. In general,
algorithms with exponential running times are impractical for all but very small
values of n. In many cases the running time of an algorithm is estimated by exam
ining best, worst, or average cases.
204 Chapter 5 Functions
5.3 Exercises

In Exercises 1 and 2, let f be a function that describes the


number ofsteps required to carry out a certainalgorithm. The
16. 1. J <- 1
number of items to be processedis represented by n. For each
2. X <- 0
function, describe whathappens to the number of steps if the
3. WHILE (J < AO
number of items is doubled.
a. X <- X + 1
1. (a) f(n) = 1001 (b) f(n) = 3n b. J <- I + 1
(c) f(n) = 5n2 (d) f(n) = 2.5n3 17. 1. SUM <- 0
2. (a) f(n) = \Alg(n) (b) f(n) = 2n 2. FOR J = 0 THRU 2(AT - 1) BY 2
a. SUM «- SUM + J
(c) f(n) = nlg(n) (d) f(n) = 100n4
3. Show that g(n) = n\ is 0(nn). 18. Assume that N is a power of 2.
1. X «- 1
4. Show that h(n) = 1+2 + 3 + h n is 0(n2). 2. X <r- N
5. Show that f (n) = Sn + lg(n) is 0(n). 3. WHILE (X > 1)
6. Show that g(n) = n2(ln - 2) is 0(n3). a. X «- 3X
b. K <- L-K/2J
7. Showthat f(n) = nlg(n) is 0(g) for g(n) = n2,but that
gisnotO(/). 19. 1. I +- 1
2. SOM ^- 0
8. Show that f(n) = n100 is 0(g) for g(n) = 2", but that g
3. WHILE (J < AT)
is not 0(f).
a. FOR X = 1 THRU I
9. Show that / and g have the same order for f(n) = 1. SUM <r- SUM + X
5n2 + An + 3 and g(«) = n2+ 100«. b. J <r- I + 1
10. Show that / and g havethe sameorderfor f(n) = lg(n3) 20. 1. X «- 0
andg(n) =log5(6n). 2. FOR J = 0 THRU N
11. Determine which of the following are in the same 0-class. a. WHILE X < J
A function may be in a class by itself. 1. X <- X + 1

fx (n) = 5nlg(n)9 f2(n) = 6n2 - 3n + 7, 21. SUBROUTINE MATMUL(A,B,N,M,P,Q;C)


1. IF (M = P) THEN
f3(n) = 1.5", f4(n) = lg(n4)9 a. FOR J = 1 THRU N
f5(n) = 13,463, /6(n) = -15n, 1. FOR J = 1 THRU Q
a. C[I,J] «- 0
/?(*) = /g(/g(n)), /8(«) = 9n°\
b. FOR X = 1 THRU M
f9(n) = n!, /io(n) = n + /g(«), 1. C[J,J] ^~
/n(n) = Vn + 12#i, /12(«) = /g(n!) CCJ.J] +
(A[J,X] x B[X,J])
12. Order the 0-classes in Exercise 11 from lowest to highest. 2. ELSE
13. Consider the functions fx, /2, f49 /s, /is, /io, /n in Exer a. CALL PRINT ('INCOMPATIBLE')
cise 11. Match each of the functions with its 0-class from 3. RETURN
the following list: 0(1), 0(n), ®(nlg(n))9 S(lg(n))9 END OF SUBROUTINE MATMUL
S(n2)9 0Gv^), 0(2"). 22. Determine the 0-class of the function defined in Section
In Exercises 14 through 21, analyze the operation performed 1.3, Exercise 38. What is the running time for computing
by the given piece ofpseudocode and write a function that de F(n)l
scribes the number of steps required. Give the S-class of the 23. (a) Write a recurrence relation to count the number of
function. ways a 3 x 3 square can be placed on an n x n square
with the edges of the squares parallel.
14. 1. A «- 1
2. B <r- 1 (b) What is the running time of an algorithm that uses
3. UNTIL (B > 100) the recurrence relation in (a) to count the number of
a. B <- 2A - 2 placements?
b. A <- A + 3 24. Prove Rule 3.
15. 1. X «- 1 25. Prove Rule 4.
2. y <- 100
26. Prove Rule 6.
3. WHILE (X < Y)
a. X <- X + 2 27. Prove Rule 7.
5.4 Permutation Functions 205

28. Prove that if 0(/) = ®(g) = 0(A), then / + g is 0(h). 29. Prove that if ©(/) = 0(g) and c ^ 0, then
®(cf) = ®(g).

5.4 Permutation Functions


In this section we discuss bijections from a set A to itself. Of special importance
is the case when A is finite. Bijections on a finite set occur in a wide variety of
applications in mathematics, computer science, and physics.
A bijection from a set A to itself is called a permutation of A.

Example 1 Let A = R and let /: A -> A be defined by f(a) = 2a + 1. Since / is one to


one and onto (verify), it follows that / is a permutation of A. ♦

If A = {aX9 a29..., an] is a finite set and p is a bijection on A, we list the


elements of A and the corresponding function values p(ax)9 p(a2)9..., p(an) in
the following form:

ax a2
(1)
p(ax) p(a2) P(an)
Observe that (1) completely describes p since it gives the value of p for every
element of A. We often write

ax a2
P =
p(ax) p(a2) p(an)

Thus, if p is a permutation of a finite set A = [ax, a2,..., an}, then the se


quence p(ax)9 p(a2)9..., p(an) is just a rearrangement of the elements of A and
so corresponds exactly to a permutation of A in the sense of Section 3.1.

Example 2 Let A= {1,2, 3}. Then all the permutations ofAare

lA =(l 23J' " =(l 3 2)' P2=\2 )•


(\ 2 3\ (\ 2 3\ (\
P3 ={2 3 lj' P4=\3 1 2J' P5 =\3 0
Example 3 Using the permutations of Example 2, compute (a) p^x; (b) p3 op2
Solution

(a) Viewing 774 as a function, we have


/74 = {(1,3),(2,1),(3,2)}.
Then
P4~! = {(3,l),a2),(2,3)}
or, when written in increasing order of the first component of each ordered
pair, we have
p^ = {(1,2), (2, 3), (3,1)}.
Thus

^-1 =(^2
fl 2 3\
3 l)=P3'
206 Chapter 5 Functions

(b) The function p2 takes 1 to 2 and p3 takes 2 to 3, so p3 o p2 takes 1 to 3.


Also, p2 takes 2 to 1 and p3 takes 1 to 2, so /?3 o p2 takes 2 to 2. Finally,
/?2 takes 3 to 3 and p3 takes 3 to 1, so p3 o /?2 takes 3 to 1. Thus

p3o p2
=(i I0-
We may view the process of forming p3 o p2 as shown in Figure 5.11.
Observe that p3 o p2 = p5. ♦

r
' 1 2 3
P3 ° P2 :
v® 2 1

Figure 5.11

The composition of two permutations is another permutation, usually referred


to as the product of these permutations. In the remainder of this chapter, we will
follow this convention.

THEOREM 1 If A = [ax, a2,..., an} is a set containing n elements, then there are

n\ = n • (n —1) •• •2 • 1 permutations of A. (2)

Proof
This result follows from Theorem 4 of Section 3.1 by letting r = n. •

Let bx, b2,..., br be r distinct elements of the set A = {ax, a2,..., an}. The
permutation p: A ^ A defined by

p(fri) = &2
/?(fc2) = b3

p(br-\) = br
P(*r) = £l
/?00 = x, if x € A, x i [bx, b2,..., br},

is called a cyclic permutation of length r, or simply a cycle of length r, and


will be denoted by (bx, b2,..., fcr). Do not confuse this terminology with that
used for cycles in a digraph (Section 4.3). The two concepts are different and
we use slightly different notations. If the elements b\,b2, ...,br are arranged
uniformly on a circle, as shown in Figure 5.12, then a cycle p of length r moves
these elements in a clockwise direction so that bx is sent to b2, b2 to b3,..., br-\
to br, and br to bx. All the other elements of A are left fixed by p.

Example 4 Let A = {1,2, 3,4,5}. Thecycle (1, 3,5) denotes the permutation

(\ 2 3 A 5\
\3 2 5 4 lj*
5.4 Permutation Functions 207

Observe that if p = (bx,b2,..., br) is a cycle of length r, then we can also


write p by starting with any bi9 1 < i < r, and moving in a clockwise direction,
as shown in Figure 5.12. Thus, as cycles,
k (3, 5, 8, 2) = (5, 8,2, 3) = (8, 2, 3, 5) = (2, 3, 5, 8).
^ ' Note also that the notation for acycle does not include the number ofelements
in the set A. Thus the cycle (3,2,1,4) could be a permutation of the set {1,2,3,4}
or of {1, 2, 3,4,5,6,7, 8}. We need to be told explicitly the set on which a cycle
Figure 5.12 jsdefined. Itfollows from the definition that a cycle ona setAisoflength 1if and
only if it is the identity permutation, 1a-
Since cycles are permutations, we can form their product. However, as we
show in the following example, the product of two cycles need not be a cycle.

Example 5 Let A = {1,2, 3,4, 5,6}. Compute (4,1, 3, 5)o(5, 6, 3) and (5, 6, 3)o(4,1,3, 5).

Solution
We have

4 135)=^ 2 3 4 5 6\
and
/l 2 3 4 5 6\
(5,6,3) =(^ 2 5 4 6 3j-
Then

(4, l,3,5)o(5,6,3) =(J 23456^1 2


2
3
5
4
4
5
6
6'
3

_(\ 2 3 4 5 6\
~\^3 2 4 1 6 5)
and

c\*X\n(A\ **\ =^
(5,6,3)o(4,l,3,5) /I 2
2 5
3 4
4 6
5 6\
3j o^/l 22 53 41 45 ej
6\

_/l 2 3 4 5 6\
"\5 2 6 1 4 3j'
Observe that
(4,1, 3,5) o (5,6,3) / (5,6,3) o (4, 1,3,5)
and that neither product is a cycle. ♦

Twocyclesof a set A are said to be disjoint if no elementof A appearsin both


cycles.

Example 6 Let A = {1,2,3,4,5,6}. Then the cycles (1,2,5) and (3,4,6) are disjoint,
whereas the cycles (1, 2,5) and (2,4,6) are not. ♦

It is not difficultto showthat if pi = {a\, a2,..., ar) and/>2 = (&i, b2, •••, bs)
are disjoint cycles of A, then pi o p2 = p2 o px. This can be seen by observing
that p\ affects only the a's, while p2 affects only the fc's.
We shall now presenta fundamental theorem and, instead of giving its proof,
we shall give an example that imitates the proof.
208 Chapter 5 Functions

THEOREM 2 Apermutation ofa finite set that is not the identity or a cycle can be written as a
product of disjoint cycles of length > 2. •
Example 7 Write the permutation
2 3 4 5 66 7 8\
'-G 3 4 6 5 2 1 8 1)
of the set A = {1, 2, 3,4,5, 6,7, 8} as a productof disjointcycles.
Solution
We start with 1 and find that p(\) = 3, p(3) = 6, and p(6) = 1, so we have the
cycle (1, 3, 6). Next we choose the first element of A that has not appeared in a
previous cycle. We choose 2, and we have p(2) = A, p(A) = 5, and p(5) = 2, so
we obtain the cycle (2,4, 5). We now choose 7, the first element of A that has not
appeared in a previous cycle. Since p(l) = 8 and p(S) = 7, we obtain the cycle
(7, 8). We can then write p as a product of disjoint cycles as
p = (7, 8) o (2,4,5)o(l,3,6). ♦

It is not difficult to show that in Theorem 2, when a permutation is written as a


product of disjoint cycles, the product is unique except for the order of the cycles.
We saw in Section 5.1 how a permutation of the alphabet produces a substi
tution code. Permutations are also used to produce transposition codes. Unlike
a substitution code in which each letter is replaced by a substitute, the letters in
transposition coded messages are not changed, but are rearranged. Thus if a mes
sage TEST THE WATERS is subjected to the permutation
(1, 2, 3) o (4,7) o (5,10,11) o (6, 8,12,13, 9),
where the numbers refer to the positions of the letters in the message, the message
becomes STEEEATHSTTWR. If the permutation is known to both parties, then
the receiver of the message has only to apply the inverse permutation to decode.

Example 8 One commonly used transposition code is the keyword columnar transposition.
For this it is only necessary to remember a keyword, say JONES. The message to
be encoded is written under the keyword in successive rows, padding at the end
if necessary. For example, the message THE FIFTH GOBLET CONTAINS THE
GOLD would be arranged as shown:
J 0 N E S
T H E F I
F T H G 0
B L E T c
0 N T A I
N S T H E
G 0 L D X

Note that the message has been padded with an X to fill out the row. Then the
coded message is constructed by writing the columns in succession, beginning
with column 4 (since E is the first keyword letter to appear in the alphabet) and
following with the letters in columns 1, 3, 2, 5. The encoded message is thus
FGTAHDTFBOGCEHETTLHTLNSOIOCIEX.

The recipient of the message divides the number of letters by 5 to find that
there are 6 rows. She writes the coded message, six letters at a time, in columns 4,
1, 3, 2, 5, then reads the original message from the rows. ♦
5.4 Permutation Functions 209

Notice that although the encoded message is a permutation of the original


message string, this permutation depends onthelength ofthemessage. InExample
8, the permutation of the 30 positions begins

(l 2 3 --A
^7 19 13 •••)•
But using the keyword JONES to encode MAKE ME AN OFFER produces a
permutation of 15 positions that begin

(I 2 3 ...\
\^4 10 7 -J
A common variation of this idea, used in the U.S. Civil War, is to transpose words
rather than letters and add some superfluous known words for confusion. These
extra words were called arbitraries during the Civil War.

Even and Odd Permutations

A cycle of length 2 is called a transposition. That is, a transposition is a cycle


p = (ai9 dj), where p(afi = a/ and p(aj) = ty.
Observe that if p = (at, aj) is a transposition of A, then p o p = lA, the
identity permutation of A.
Every cycle can be written as a product of transpositions. In fact,

(bub29 ...,br) = (bubr) o (bubr-.i) o • • • o (bu b3) o (bub2).

This case can be verified by induction on r, as follows:

Basis Step
If r = 2, then the cycleis just (b\, b2), which already has the proper form.

Induction Step
Weuse V(k) to show P(k +1). Let (bu b2, ...,bk, bk+\) be a cycleof lengthk+1.
Then (bu b2,...9 bk, bk+{) = (b\9 bk+\) o (b\, b2,...9 bk), as may be verified by
computing the composition. Using P(k), (b\, b2,...9 bk) = (b\, bk) o {bu h-\) o
• • • o (b\9b2). Thus, by substitution,

(bu b29...9 6jh-i) = (bu h+i) o(bubk)o.--o (b\9b3)(bu b2).

This completes the induction step. Thus, by the principle of mathematical induc
tion, the result holds for every cycle. For example,

(1, 2, 3,4,5) = (1, 5) o (1,4) o (1, 3) o (1, 2).

We now obtain the following corollary of Theorem 2.

Corollary 1 Every permutation of a finite set with at least two elements can be written as a
product of transpositions. •
Observe that the transpositions in Corollary 1 need not be disjoint.

Example 9 Write the permutation p ofExample 7 asa product oftranspositions.


210 Chapter 5 Functions

Solution
We have p = (7, 8) o (2,4,5) o (1,3,6). Since we can write

(l,3,6) = (l,6)o(l,3)
(2,4, 5) = (2, 5) o (2,4),

we have p = (7, 8) o (2,5) o (2,4) o (1, 6) o (1, 3). ♦

We have observed that every cycle can be written as a product of transposi


tions. However, this can be donein manydifferent ways. For example,
(1,2, 3) = (1,3) o(l, 2)
= (2,1) o (2, 3)
= (1, 3) o (3, 1) o (1, 3) o (1, 2) o (3, 2) o (2, 3).

It then follows that every permutation on a set of two or more elements can be writ
ten as a product of transpositions in many ways. However, the following theorem,
whose proof we omit, brings some order to the situation.

THEOREM 3 If a permutation of a finite set can be written as a product of an even number


of transpositions, then it can never be written as a product of an odd number of
transpositions, and conversely. •
A permutation of a finite set is called even if it can be written as a product
of an even number of transpositions, and it is called odd if it can be written as a
product of an odd number of transpositions.

Example 10 Is thepermutation
4

•a 7
0
even or odd?

Solution
We first write p as a product of disjoint cycles, obtaining

p = (3,5,6) o (1,2,4,7). (Verify this.)

Next we write each of the cycles as a product of transpositions:

(1,2,4,7) = (l,7)o(l,4)o(l, 2)
(3, 5, 6) = (3, 6) o (3,5).

Then p = (3, 6) o (3, 5) o (1,7) o (1,4) o (1, 2). Since p is a product of an odd
number of transpositions, it is an odd permutation. ♦

From the definition of even and odd permutations, it follows (see Exercises 22
through 24) that
(a) the product of two even permutations is even.
(b) the product of two odd permutations is even.
(c) the product of an even and an odd permutation is odd.

THEOREM 4 Let A = {aX9 a2,..., an] be a finite set with n elements, n > 2. There are nl/2
even permutations and n\/2 odd permutations.
5.4 Permutation Functions 211

Proof
Let An be the set of all even permutations of A, and let Bn be the set of all odd
permutations. We shall define a function f:An-*Bn9 which we show is one to
one and onto, and this will show that An and Bn have the same number of elements.
Since n > 2, we can choose a particular transposition q0 of A. Say that
q0 = (<3„_i, an). We now define the function /: An -> Bn by
f(p) = qo°p, ptAn.
Observe that if p e An, then p is an even permutation, so qo o p is an odd
permutation and thus f(p) e Bn. Suppose now that px and p2 are in An and
/(Pi) = /(P2). Then
qo o px = q0 o p2. (3)

We now compose each side of equation (3) with qo:

qo o (qo o px) = q0o (q0 o p2)\

so, by the associative property, (qo°qo)°P\ = (qo°qo)°P2 or, since qooqo = lA,
lA o px = lA o p2
Pi = Pi-

Thus / is one to one.


Now let q e Bn. Then q0 o q e An, and

f(qo oq) = q0o (q0 o q) = (q0 o q0) o q = \A o q = q,


which means that / is an onto function. Since f:An -> Bn is one to one and
onto, we conclude that An and Bn have the same number of elements. Note that
Anf) Bn = 0 since no permutation can be both even and odd. Also, by Theorem
1, \An U Bn\ = n\. Thus, by Theorem 2 of Section 1.2,

n\ = \An U Bn\ = \An\ + \Bn\ - \An D Bn\ = 2\An\.


We then have
n\
\An\ = \Bn\ = -.

5.4 Exercises

1. Which of the following functions /: ' are permu- 4. Which of the following functions /: Z -> Z are permu
tationsofR? tations of Z?
(a) / is defined by f(a) = a - 1. (a) / is defined by f(a) =a2 + \.
(b) / is defined by f(a) = a2. (b) / is defined by f(a) = a3 - 3.
2. Which of the following functions /: '. are permu-
In Exercises 5 through 8, let A = {1, 2, 3,4, 5, 6} and
tationsofR?

(a) / is definedby f(a) = a3. 2

(b) / is defined by f(a) = ea.


P\
•0 4

3. Which of the following functions /: ! - are permu- 2


tationsofZ?
(a) / is defined by f(a) = a -f 1.
Pi
•0 3 )•
2
(b) / is defined by f(a) = (a - l)2. P3
•0 3
)•
212 Chapter 5 Functions
5. Compute (b) Write the permutation of the positions for the mes
(a) PX{ (b) p3 o px sage in part (a).
6. Compute In Exercises 20 and 21, let A = {1, 2, 3,4, 5, 6, 7, 8}. Deter
(a) (p2 oPx)op2 (b) px o (/?3 o p~l) mine whether the permutation is even or odd.
7. Compute 2 3 4 5 7 8\
20. (a)
(a) /V
8. Compute
(b) p;lop-] 0 4 2 1 6 5 7 3)
2 3 4 5 1 8\
(a) (p3 o p2) o px (b) p3 o (p2 o pi)-1
(b)
0 3 4 2 1 6 5J
21. (a) (6,4,2,1,5)
In Exercises 9 and10, let A = {1, 2, 3,4, 5, 6,7, 8}. Compute
the products. (b) (4, 8) o(3,5,2,l) o(2,4,7,l)

9. (a) (3,5,7,8)o(l,3,2) 22. Provethat the productof two even permutations is even.
(b) (2,6) o(3,5,7,8) o(2,5,3,4) 23. Prove that the product of two odd permutations is even.
10. (a) (1,4) o (2,4,5,6)o(l,4,6, 7) 24. Prove that the productof an even and an odd permutation
is odd.
(b) (5, 8) o(l,2,3,4) o(3,5,6,7)
25. Let A = {1,2, 3,4, 5}. Let / = (5, 2, 3) and
11. Let A = {a9 b9 c, d9 e9 f g}. Compute the products.
g = (3,4,1) be permutations of A. Compute each of the
(a) (a,f,g)o(b,c,d,e) following and write the result as the product of disjoint
(b) (fg)o(b9c9f)o(a9b9c) cycles.
In Exercises 12 and 13, let A = {1, 2, 3,4, 5, 6,7, 8}. Write (a) fog (b) f-xog-*
each permutation as the product ofdisjoint cycles. 26. Show that if p is a permutation of a finite set A, then
p2 = p o p is a permutation of A.
„ ,. /I 22 33 44 55 6 7 8\
1Z- w 1^44 33 22 55 1 8 7 6) 27. Let A = {1,2, 3,4, 5, 6} and

/12345678\ 2 3
(b)V23417586/
/l 2 3 4 5 6 7 8\
•0 2 4 3

be a permutation of A.
"• w \6 5 1 8 4 3 2 lj
(a) Write p as a product of disjoint cycles.
/12345678\
W\23 146785j (b) Compute p~l. (c) Compute p2.
14. Let A = {a, 2?, c, d, e, /, g}. Write each permutation as (d) Find the period of p9 that is, the smallest positive in
the product of disjoint cycles. teger k suchthat pk = lA.
a b c d e f g 28. Let A = {1,2, 3,4,5, 6} and
0
»(; g d b a c f e ) 2 3

(b)
fa
\d
b
e a
c d e
b g f c)
f g\
'-0 3 5

15. Let A = {1, 2, 3,4,5, 6,7, 8}. Write each permutation as be a permutation of A.
a product of transpositions. (a) Write p as a product of disjoint cycles.
(a) (2,1,4, 5, 8, 6) (b) (3,1, 6) o (4, 8, 2, 5) (b) Compute p~l. (c) Compute p2.
16. Code the message WHERE ARE YOU by applying the (d) Find the period of p9 that is, the smallest positive in
permutation (1, 7, 3, 5,11) o (2, 6,9) o (4, 8,10). teger k suchthat pk = 1^.
17. Decode the message ATEHAOMOMNTI, which was en 29. (a) Use mathematical induction to show that if pis a per
coded using the permutation mutation of a finite set A, then pn = p o p o •-• o p
(n factors) is a permutation of A for n eZ+.
(3, 7,1,12) o (2, 5, 8) o (4,10, 6,11, 9).
(b) If A is a finite set and p is a permutation of A, show
18. (a) Give the complete permutation of the positions for that pm = I4 for some m e Z+.
the message in Example 8.
30. Let p be a permutation of a set A. Define the following
(b) Write the permutation found in part (a) as the product relation R on A: a R b if and only if pn(a) = b for some
of disjoint cycles. n e Z. [p° is defined as the identity permutation and p~n
19. (a) Encode the message MAKE ME AN OFFER using is definedas (p~l)n.] Show that R is an equivalence rela
the keyword JONES and the method of Example 8. tion and describe the equivalence classes.
Key Ideas for Review 213

31. Build a composition table for the permutations of A = length 3 can be formed using the elements of A and such
{1,2, 3} given in Example 2. that <zi < a2 < a3?
32. Describe how to use the composition table in Exercise 31 37. We call a permutation p = (ax, a29..., an) up-down if
to identifyp~l for any permutation p of A. the elements in the odd positions form an increasing se
33. Find all subsets of {1A, pu Pi, p3, Pa, Ps), the permuta
quenceand the elements in the evenpositions form a de
tions in Example 2, that satisfy the closure property for creasing sequence.
composition. (a) Let A = {1,2, 3}. How many up-down permutations
of A are there?
34. For each permutation, p9of A in Example 2, determine its
period. How does this relate to the subset in Exercise 33 (b) Let A = {1, 2, 3,4}. How many up-down permuta
to which p belongs? tions of A are there?

35. Let A = {1, 2, 3,..., n}. How many permutations of 38. Let A = {1,2, 3,4,5}. How many up-down permutations
A, p = (aX9 a29..., an)9 are there for which a{ < ai+x, of A are there?
1 < i < n — 1? How many permutations of A, 39. Prove that the number of up-down permutations for A =
p = (al9a29 ...9an)9 are there for which a{ > ai+x, {1,2, 3,..., n] is the same as the number of increasing
1 < i < n - 1? sequences oflength [|] that can be formed from elements
36. Let A = {1, 2, 3,4, 5). How many different sequences of of A.

Tips for Proofs


Before beginning a proof, you might find it helpful to consider what the statement
does not say. This can help clarify your thinking about what facts and tools are
available for the proof. Consider Theorem A, Section 5.1. It does not say that if
/ is one to one, then / is onto. The additional facts that \A\ = \B\ and that / is
everywhere defined will need to be used in the proof.
To show that a function is one to one or onto, we need to use generic ele
ments. See Example 11, Section 5.1. Either the definition of one-to-oneness or
its contrapositive may be used to prove this property. We also have the fact that
if /: A -> B is everywhere defined and \A\ = |fi| = n, then / is one to one if
and only if / is onto. In addition, if we wish to show / is one to one and onto, we
may do this by constructing the inverse function f~l. Establishing a one-to-one
correspondence is a powerful counting strategy, because it allows us to count a
different set than the original one. For example, see Theorem 4, Section 5.4, and
Exercises 32 through 34, Section 5.2.
To prove that / and g have the same order or one is of lower order than the
other, the principaltools are the rules for ©-classes or manipulationof inequalities
(Section 5.3, Examples 2 and 3).

• Key Ideas for Review


Function: seepage 181 Substitution code: see page 187
Identity function, lA: \A(a) = a Boolean function /: Ran(/) c {true, false}
One-to-one function / from A to B: a ^ a' implies Hashing function: see page 192
f(a) # f(af)
Fuzzy set: see page 193
Onto function / from A to B: Ran(/) = B
Fuzzy predicate: see page 196
Bijection: one-to-one and onto function
0(g) (big Oh of g): see page 200
One-to-one correspondence: onto, one-to-one, everywhere
defined function / and g of the same order: / is O(g) and g is 0(f)
If / is a function from A to B9 lB o f = /; / o lA = / Theorem: The relation 0, / 0 g if and only if / and g have
If / is an invertible function from A to B, f~l o f = lA; the same order, is an equivalence relation.
fof-x = lB Lower 0-class: see page 201
• (gof) l = f~l og -1 Rules for determining 0-class of a function: see page 203
214 Chapter 5 Functions

Running time of an algorithm: 0-class of a function that • Even (odd) permutation: onethat can be written as a prod
describes thenumber of steps performed by thealgorithm uct of an even (odd) numberof transpositions
Permutation function: a bijection from a set A to itself
• Theorem: If a permutation of a finite set can be written as
Theorem: If A is a set that has n elements, then there are n\ a product of an even number of transpositions, then it can
permutations of A. neverbe written as a product of an odd numberof transpo
Cycle of length r: (bx, bl9..., br)\ see page 206 sitions, and conversely.
Theorem: A permutation of a finite set that is not the iden • The product of
tity or a cycle can be written as a productof disjointcycles.
(a) Two even permutations is even.
Transposition: a cycle of length 2
Corollary: Every permutation of a finite set with at least two (b) Two odd permutations is even.
elements can be written as a product of transpositions. (c) An even and an odd permutation is odd.
Transposition code: see page 208 • Theorem: If A is a set that has n elements, then there are
Keyword columnar transposition code: see page 208 n\/2 even permutations and n\/2 odd permutations of A.

I Chapter 5 Self-Test
1. How does a function differ from a general relation? digits as another number, adds them, and then applies the
2. What is a common strategy to prove that a function is one mod-89 function.

to one? (a) How many linked lists will be needed?


3. What is a common strategy to prove that a function is (b) If an approximately even distribution of records is
onto? achieved, roughly how many records will be stored
in each linked list?
4. Why are mod functions often used in constructing hashing
functions? (c) Compute A(473810), /i(125332), and /i(308691).
5. What does the 0-class of a function represent? 13. Show that f(n) = 2n2 + 9n + 5 is 0(n2).
6. Let A = {a9b9c9d}9 B = {1,2,3}, and R = {(a, 2), 14. Determine the 0-class of f(n) = lg(n) + n2 + 2n.
(b91), (c, 2), (d91)}. Is R a function? Is R~x a function? 15. Consider the following pseudocode.
Explain your answers. 1. X <- 10

7. Let A = B = R. Let /: A -+ B be the function defined 2. I <- 0

by f(x) = —5x -f 8. Show that / is one to one and onto. 3. UNTIL (J > AO
a. X *- X + J
8. Compute
b. I<-I+2
(a) L16.29J (b) L-1.6J Write a function of N that describes the number of steps
9. Compute required and give the 0-class of the function.
(a) T16.291 (b) F—1.61 16. Let A = {1,2,3,4,5,6} and let px = (3,6,2) and
p2 = (5,1,4) be permutations of A.
10. Compute
(a) Compute px o p2 and write the result as a product of
(a) lg(l) (b) lg(6A)
cycles and as the product of transpositions.
11. Let Q be the propositional function defined by
(b) Compute pxl o p^x.
e(*):ay*y =[J J]. „ r /l 2 3 4 5 6
17. LetPl = ^? 3 2 j 4 5 i) and

_(\ 2 3 4 5 6
EvaluateG([j j])«odfi([j l]} P2~\6 3 2 1 5 4
(a) Compute px o p2.
?)•
12. Assume that 9500 account records need to be stored us
ing the hashing function h9 which takes the first two digits
(b) Compute pj"1.
of the account number as one number and the last four (c) Is px an even or odd permutation? Explain.
Experiment 5 215

| Experiment 5
The 0-class of a function that describes the number of steps performed by an
algorithm is referred to as therunning time of the algorithm. In this experiment
you will analyze several algorithms, presented in pseudocode, to determine their
running times.
Part I. The first algorithm is one method for computing the product of two
n x n matrices. Assume that the matrices are each stored in an array
of dimension 2 and that A[i, j] holds the element of A in row i and
column j.

Algorithm MATMUL(A, B; C)
1. FOR 1 = 1 THRU N
a. FOR J = 1 THRU N
1. C[I,J] «- 0
2. FOR K = 1 THRU N
a. C[I,J] <r- C[J,J] + A[I,X] x B[X,J] •

Assume that each assignment of a value, each addition, and each ele
ment multiplication take the same fixed amount of time.
1. How many assignments will be done in the second FOR loop?
2. How many element multiplications are done in the third FOR loop?
3. What is the running time of MATMUL? Justify your answer.
Part II. The following recursive algorithm will compute n\ for any positive in
teger n.

Algorithm FAC(Af)
1. IF (N = 1) THEN
a. A «- 1
2. ELSE
a. A +- N x FAC(W - 1)
3. RETURN (A) •

1. Let Sn be the number of steps needed to calculate n\ using FAC.


Write a recurrence relation for Sn in terms of Sn-\.
2. Solve the recurrence relation in question 1 and use the result to de
termine the running time of FAC.
Part III. The function SEEKwill givethe cell in which a specified valueis stored
in cells i through i +n - 1 (inclusive) of an array A. Assume that i > 1.
FUNCTION SEEKCJTEM, J, I + N - 1)
1. CELL <r- 0
2. FOR J = I THRU I + N - 1
a. IF (A[J] = ITEM) THEN
b. CELL <r- J
3. RETURN (CELL)
END OF FUNCTION SEEK •

1. How many cells are there from A[i] to A[i + n —1] (inclusive)?
2. Give a verbal description of how SEEK operates.
216 Chapter 5 Functions

3. What is the running time of SEEK? Justify your answer.


Part IV. The algorithm HUNT will give the cell in which a specified value is
stored in cells i through i + n - 1 (inclusive) of an array A. Assume
that i > 1. Tosimplify the analysis of this algorithm, assume that n, the
number of cells to be inspected, is a power of 2.

Algorithm HUNT (ITEM, 1,1 + N - 1)


1. CELL «- 0
2. IF (AT = 1 AND A[J] = ITEM) THEN
a. CELL <- J
3. ELSE
a. CELL1 <- HUNTCJTTEM, J, J + N/2 - 1)
b. CELL2 <- HUNTCITEM, I + N/2, I + N - 1)
4. IF (CELL1 ^ o) THEN
a. CELL 4- CELL1
5. ELSE
a. CELL <- CELL2
6. RETURN (CELL) •

1. Give a verbal description of how HUNT operates.


2. What is the running time of HUNT? Justify your answer.
3. Under what circumstances would it be better to use SEEK (Part III)
rather than HUNT? When would it be better to use HUNT rather
than SEEK?
CHAPTER

6 Order Relations and Structures


Prerequisites: Chapter 4

In this chapter we study partially ordered sets, including lattices and Boolean al
gebras. These structures are useful in set theory, algebra, sorting and searching,
and, especially in the case of Boolean algebras, in the construction of logical rep
resentations for computer circuits.

Looking Back
We have already met George Boole in Chapter 2 and noted the on or off, we can construct each type of connector. Since this
importance of his development of symbolic logic. In 1938, combination is not unique, it is desirable to write it in as simple
Claude E. Shannon, an American mathematician (whom we a manner as possible (a problem that will be examined briefly
will meet in Chapter 11) wrote a Master's thesis at MIT enti in this chapter). The benefits of doing so include greater speed,
tled A Symbolic Analysis of Relay and Switching Circuits, in smaller circuits, and lower power consumption. The field in
which he showed how to use the work of Boole in the design of computer science that deals with this problem is logic design,
circuits. and Boolean algebra plays a major role in this field. As elec
The heart of a computer consists of circuits that perform tronic circuits have grown enormously in size and complexity,
the many different operations and tasks of the computer. Every the field of computer-aided design (CAD) has been developed,
electronic circuit can be written as a combination of the connec whereby very sophisticated computer programs carry out the
tors and, or, and not, and by using a device that can be turned logic design.

circuit

217
218 Chapter 6 Order Relations and Structures

6.1 Partially Ordered Sets


A relation Ron a set Ais called a partial order if Ris reflexive, antisymmetric,
and transitive. The set A together with the partial order R is called a partially
ordered set, or simply a poset, and we will denote this poset by (A, R). If there
is no possibility of confusion about the partial order, we may refer to the poset
simply as A, rather than (A, R).

Example 1 Let A be a collection of subsets of a set S. The relation c of set inclusion is a


partial order on A, so (A, c) is a poset. ♦

Example 2 LetZ+ be the setof positive integers. The usual relation < (less than or equal to)
is a partialorder on Z+, as is > (greater than or equal to). ♦

Example 3 The relation of divisibility (a Rb if and only if a \ b) is a partial order on Z+. ♦

Example 4 Let 31be the set of all equivalence relations on a set A. Since 31consists of subsets
of A x A, 31 is a partially ordered set under the partial order of set containment.
If R and S are equivalence relations on A, the same property may be expressed in
relational notation as follows.

R c 5 if and only ifxRy implies x S y for all x, y in A.


Then (^,c) is a poset. ♦

Example 5 The relation < on Z+ is not a partial order, since it is not reflexive. ♦

Example 6 Let R be a partial orderon a set A, and let R~l be the inverse relation of R. Then
R~l is also a partial order. To see this, we recall the characterization of reflexive,
antisymmetric, and transitive given in Section 4.4. If R has these three properties,
then A c. R, RD R~{ c A, and R2 c R, By taking inverses, we have
A = A"1 c R~\ R-x H(/r1)"1 = R~l n R C A, and (R~1)2 c R~\
so, by Section 4.4, R~l is reflexive, antisymmetric, and transitive. Thus R~l is
also a partial order. Theposet (A, R~l) is called the dual of the poset(A, R), and
the partial orderR~l is called the dual of the partial order R. ♦

The most familiar partial orders are the relations < and > on Z and R. For
this reason, when speaking in general of a partial order R on a set A, we shall
often use the symbols < or > for /?. This makes the properties of R more familiar
and easier to remember. Thus the reader may see the symbol < used for many
different partial orders on different sets. Do not mistake this to mean that these
relations are all the same or that they are the familiar relation < on Z or R. If it
becomes absolutely necessary to distinguish partial orders from one another, we
may also use symbols such as <,,<', >j, >', and so on, to denote partial orders.
We will observe the following convention. Whenever (A, <) is a poset, we
willalways use the symbol > for thepartial order <_1, and thus (A, >) willbe the
dual poset. Similarly, the dual of poset (A, <{) will be denoted by (A, >{), and
the dual of the poset (B9 <') will be denoted by (B9 >'). Again, this convention
is to remind us of the familiar dual posets (Z, <) and (Z, >), as well as the posets
(R, <) and (R, >).
If (A, <) is a poset, the elements a and b of A are said to be comparable if

a < b or b < a.
6.1 Partially Ordered Sets 219

Observe that in a partially ordered setevery pair of elements need notbe compa
rable. For example, consider the poset in Example 3. The elements 2 and 7 are
notcomparable, since 2 \ 7 and 7 \ 2. Thus the word "partial" in partially ordered
set means that someelements maynot be comparable. If every pair of elements in
a poset A is comparable, we say that A is a linearly ordered set, and thepartial
order is called a linear order. We also say that A is a chain.

Example 7 The poset of Example 2 is linearly ordered. ♦

The following theorem is sometimes useful since it shows how to construct a


new poset from given posets.

THEOREM 1 If (A, <) and (B, <) are posets, then (A x B, <) is a poset, with partial order <
defined by
(a, b) < (a', bf) if a < a! in A and b < b' in B.
Note that the symbol < is being used to denote three distinct partial orders. The
reader should find it easy to determine which of the three is meant at any time.

Proof
If (a, b) e A x B, then (a, b) < (a, b) since a < a in A and b < b in B, so <
satisfies the reflexive property in A x B. Now suppose that (a, b) < (af, V) and
(a', b') < (a, b), where a and a! e A and b and b' € B. Then

a < a' and a' < a in A

and
b < b' and b' < b in B.

Since A and B are posets, the antisymmetry of the partial orders on A and B
implies that
a = af and b = br.

Hence < satisfies the antisymmetry property in A x B.


Finally, suppose that

(a9b)<(a\bf) and (a'9bf) < (a",b"),


where a, a!, a" € A, and b, b', b" e B. Then

a <a' and a! < a",

so a < a", by the transitive property of thepartial order on A. Similarly,


b<bf and b" < b"9
sob < b", by the transitive property of the partial order on B. Hence
(a,b) <(a",b").
Consequently, the transitive property holds for the partial order on A x B, and we
conclude that A x B is a poset. •

The partial order < defined on the Cartesian product A x B is called the
product partial order.
If (A, <) is a poset, we say that a < b if a < b but a ^ b. Supposenow that
(A, <) and (B9 <) are posets. In Theorem 1 we have defined the productpartial
220 Chapter 6 Order Relations and Structures

order on A x B. Another useful partial order on A x B, denoted by -<, is defined


as follows:

(a, b) < (af, bf) if a < a! or if a = a! and b < b'.

This ordering is called lexicographic, or "dictionary" order. The ordering of the


elements in the first coordinate dominates, except in case of "ties," when attention
passes to the second coordinate. If (A, <) and (B, <) are linearly ordered sets,
then the lexicographic order -< on A x B is also a linear order.

Example 8 Let A = R, with the usual ordering <. Then the plane R2 = R x R may be
given lexicographic order. This is illustratedin Figure 6.1. We see that the plane
is linearly ordered by lexicographic order. Each vertical line has the usual order,
and points on one line are less than points on a line farther to the right. Thus, in
P3
Figure 6.1, px < p2, px < p3, and p2 •< p3. ♦

Pi
Pi
Lexicographic ordering is easily extended to Cartesian products
-*-x A\ x A2 x • • • x An as follows:

x = x2
(ax, a29 ...,an) < (a[, a2,..., a'n) if and onlyif
ax < a[ or
Figure 6.1
ax = a[ and a2 < a2 or
ax = a[, a2 = a2, and a3 < a'3 or...
ax=a[, a2 = a2, ..., an-\ = a'n_{ and an < afn.

Thus the first coordinate dominates except for equality, in which case we consider
the second coordinate. If equality holds again, we pass to the next coordinate, and
soon.

Example 9 Let S = {a9 b9..., z] be the ordinary alphabet, linearly ordered in the usual way
(a < b9 b < c9..., y < z). Then 5" = S x S x • • • x S (n factors) can be
identified with the set of all words having length n. Lexicographic order on Sn
has the property that if wx -< w2 (wx, w2 e Sn), then wx would precede w2 in a
dictionary listing. This fact accounts for the name of the ordering.
Thus park -< part, help < hind,jump < mump. The third is true since j < m;
the second, since h = h, e < i, and the first is true since p = p, a = a, r = r,
k <t. ♦

If 5 is a poset, we can extend lexicographic order to 5* (see Section 1.3) in


the following way.
If jc = axa2 --an and y = bxb2 • • •bk are in 5* with n < k, we say that x < y
if (ax, ...,an) < (bx,..., bn) in Sn under lexicographic ordering of Sn.
In the previous paragraph, we use the fact that the n-tuple (ax, a2,..., an) e
Sn, and the string axa2- -an e S* are really the same sequence of length n, written
in two different notations. The notations differ for historical reasons, and we will
use them interchangeably depending on context.
6.1 Partially Ordered Sets 221

Example 10 Let Sbe {a, b,..., z}, ordered as usual. Then S* is the set of all possible "words"
of any length, whether such words are meaningful or not.
Thus we have
help -< helping
in S* since
help -< help
in S4. Similarly, we have
helper -< helping
since

helper < helpin


in S6. As theexample
help -< helping
shows, this order includes prefix order; that is, any word is greater than all of its
prefixes (beginning parts). This is also the way that words occur in the dictio
nary. Thus we have dictionary ordering again, but this time for words of any finite
length. ♦

Since a partial order is a relation, we can look at the digraph of any partial
order on a finite set. We shall find that the digraphs of partial orders can be repre
sented in a simpler manner than those of general relations. The following theorem
provides the first result in this direction.

THEOREM 2 The digraph of a partial order hasno cycle of length greater than 1.

Proof
Suppose that the digraph of the partial order < on the set A contains a cycle of
length n > 2. Then there exist distinct elements ax, a2,..., an e A such that
ax < a2, a2 < a3, an-\ < an, an <a\.

By the transitivity of the partialorder,used n-1 times, a\ <an. By antisymmetry,


an < ax and ax < an imply that an = a\, a contradiction to the assumption that
ax,a2, ...,an are distinct. •

Hasse Diagrams
Let A be a finite set. Theorem 2 has shown that the digraph of a partial order on A
has only cycles of length 1. Indeed, since a partial order is reflexive, every vertex
in the digraph of the partial orderis contained in a cycle of length 1. To simplify
matters, we shall delete all such cycles from the digraph. Thus the digraph shown
in Figure 6.2(a) would be drawn as shown in Figure 6.2(b).
We shall also eliminate all edges that are implied by the transitive property.
Thus, if a < b and b < c, it follows that a < c. In this case, we omit the edge
from a to c; however, we do draw the edges from a to b and from b to c. For
example, the digraph shown in Figure 6.3(a) would be drawn as shown in Figure
6.3(b). Wealso agree to draw the digraphof a partial order with all edges pointing
upward, so that arrows may be omitted from the edges. Finally, we replace the
circles representing the vertices by dots. Thus the diagram shown in Figure 6.4
gives the final form of the digraph shown in Figure 6.2(a). The resulting diagram
of a partial order, much simpler than its digraph, is called the Hasse diagram of
the partial order of the poset. Since the Hasse diagram completely describes the
associated partial order, we shall find it to be a very useful tool.
222 Chapter 6 Order Relations and Structures

(b)

(a) (b) (a) (b)

Figure 6.3 Figure 6.4

Example 11 Let A = {1,2,3,4,12}. Consider the partial order of divisibility on A. That is,
if a and b e A, a < b if and only if a \ b. Draw the Hasse diagram of the poset
(A, <).

Solution
The Hasse diagram is shown in Figure 6.5. To emphasize the simplicity of the
Hasse diagram, we show in Figure 6.6 the digraph of the poset in Figure 6.5. ♦

Figure 6.5 Figure 6.6

Example 12 Let S = {a,b, c] andA = P(S). Draw the Hasse diagram of the posetA with the
partial order c (set inclusion).

Solution
We first determine A, obtaining
A = {0, {a}, {b}9 {c}9 {a9 b}9 {a9 c}9 {b9 c}9 {a, b, c}}.
The Hasse diagram can then be drawn as shown in Figure 6.7. ♦
6.1 Partially Ordered Sets 223

{a, 6, c}

{b9c} {a9c}

nd

Figure 6.7 Figure 6.8

Observe that the Hasse diagram of a finite linearly ordered set is always of the
form shown in Figure 6.8.
It is easily seen that if (A, <) is a poset and (A, >) is the dual poset, then the
Hasse diagram of (A, >) is just the Hasse diagram of (A, <) turned upside down.

Example 13 Figure 6.9(a) shows the Hasse diagram ofa poset (A, <), where
A = {a9b9c9d9e9f}.

Figure 6.9(b) shows the Hasse diagram of the dual poset (A, >). Notice that, as
stated, each of these diagrams can be constructed by turning the other upside down.

Figure 6.9

Topological Sorting
If A is a poset with partial order <, we sometimes need to find a linear order < for
the set A that will merely be an extension of the given partial order in the sense
that if a < b, then a < b. The process of constructing a linear order such as -<
is called topological sorting. This problem might arise when we have to enter a
finite poset A into a computer. The elements of A must be entered in some order,
and we might want them entered so that the partial order is preserved. That is, if
a < b9 then a is entered before b. A topological sorting < will give an order of
entry of the elements that meets this condition.

Example 14 Give a topological sorting for the poset whose Hasse diagram is shown inFigure
6.10.
224 Chapter 6 Order Relations and Structures

Solution
The partial order -< whose Hasse diagram is shown in Figure 6.11(a) is clearly a
linear order. It is easy to see that every pairin < is also in the order -<, so < is a
topological sorting of thepartial order <. Figures 6.11(b) and (c) show two other
solutions to this problem. +

'/ t/ J/
»8 8
<> e

n d
c
> e

. d u b

n &
<

>^ U g

• & n C

» tf 1 A •
(a) (b) (c)

Figure 6.10 Figure 6.11

Isomorphism
Let (A, <) and (A1\ <f) be posets and let /: A -> Af be a one-to-one correspon
dence between A and A'. The function / is called an isomorphism from (A, <)
to (A', <') if, for any a and b in A,
a < b if and only if f(a) <' /(£).
If /: A —>• A' is an isomorphism, we say that (A, <) and (Af, <f) are isomorphic
posets.

Example 15 Let A be the set Z+ of positive integers, andlet < be the usual partial order on A
(see Example 2). Let A' be the set of positive even integers, and let <' be the usual
partial order on A'. The function f\A-^Ar given by
f(a) = 2a
is an isomorphism from (A, <) to (A'9 <').
First, / is one to one since, if f(a) = f(b), then 2a = 2b, so a = b. Next,
Dom(/) = A, so / is everywhere defined. Finally, if c € A', then c — 2a for
some a 6 Z+; therefore, c = /(a). This shows that / is onto, so we see that / is
a one-to-one correspondence. Finally, if a and b are elements of A, then it is clear
that a < b if and only if 2a < 2b. Thus / is an isomorphism. ♦

Suppose that /: A -> A! is an isomorphism from a poset (A, <) to a poset


(A!, <'). Suppose also that fi is a subset of A, and B' = /(B) is the corresponding
subset of A!. Then we see from the definition of isomorphism that the following
principle must hold.

THEOREM 3 If the elements of B have any property relating to one another or to other elements
Principle of Correspondence °f A, and if this property can be defined entirely in terms of the relation <, then
the elements of Br must possess exactly the same property, defined in terms of <'.
6.1 Partially Ordered Sets 225

Example 16 Let (A, <) be theposetwhose Hassediagram is shown in Figure6.12, and suppose
that / is an isomorphism from (A, <) to some otherposet (A', <'). Notefirst that
d < x for any x in A (later we will call an element such as d a "least element" of
A). Then the corresponding element f(d) in A' must satisfy the property f(d) <'
y for all y in A'. As another example, note thata ^ b and b ^ a. Such a pairis
called incomparable in A. It then follows from the principle of correspondence
that f(a) and f(b) must be incomparable in A'. ♦

For a finite poset, one of the objects that is defined entirely in terms of the
partial order is its Hasse diagram. It follows from the principle of correspondence
Figure 6.12 that two finite isomorphic posets must have the same Hasse diagrams.
To be precise, let (A, <) and (A', <') be finite posets, let /: A -• A' be a
one-to-one correspondence, and let H be any Hasse diagram of (A, <). Then
1. If / is an isomorphism and each label a of H is replaced by f(a), then H will
become a Hasse diagram for (A*, <').
Conversely,
2. If H becomes a Hasse diagram for (A', <'), whenever each label a is replaced
by f(a), then / is an isomorphism.
This justifies the name "isomorphism," since isomorphic posets have the same
(iso-) "shape" (morph) as described by their Hasse diagrams.

Example 17 Let A = {1, 2, 3,6} and let < be the relation | (divides). Figure 6.13(a) shows the
Hasse diagram for (A, <). Let

Af = P({a9b}) = {09{a}9{b)9{a,b}}9

and let <' be set containment, c. If /: A -> A! is defined by

f(\) = 0, f(2) = {a}9 f(3) = {b}9 f(6) = {a9 b}9

then it is easily seen that / is a one-to-one correspondence. If each label


a € A of the Hasse diagram is replaced by f(a), the result is as shown in Fig
ure 6.13(b). Since thisis clearly a Hassediagram for (A'9 <'), the function / is an
isomorphism. 4-

{a, 6}

Figure 6.13
226 Chapter 6 Order Relations and Structures
6.1 Exercises

1. Determine whether the relation R is a partial order on the 13.


set A.

(a) A = Z, and a Rb if and only if a = 2b.


(b) A = Z, and a R b if and only if b2 \ a.
2. Determine whether the relation R is a partial order on the
set A.

(a) A = Z, and a Rb if and only if a = bk for some


k € Z+. Note that fc depends on a and b.
(b) A = R, and a R b if and only if a < &.
3. Determine whether the relation R is a linear order on the
Figure 6.16
set A.

(a) A = R, and a Rb if and only if a < b.


14.
(b) A = R, and a Rbif and only if a > &.
4. Determine whether the relation R is a linear order on the
set A.

(a) A = P(S), where 5 is a set. The relation R is set


inclusion.

(b) A = R x R, and (a, fc) R (a'', 2/) if and only if 0 < a'
and b < b', where < is the usual partial order on R.
5. On the set A = {a9 b9 c}9 find all partial orders < in which
a < b.

6. What can you say about the relation R on a set A if R is a


partial order and an equivalence relation?

7. Outline the structure of the proof given for Theorem 1.

8. Outline the structure of the proof given for Theorem 2. Figure 6.17
In Exercises 9 and 10, determine the Hasse diagram of the re
lation R. 15. Determine the Hasse diagram of the relation on A =
{1,2, 3,4, 5} whose matrix is shown.
9. A = {1, 2, 3,4}, R = {(1,1), (1, 2), (2, 2), (2,4), (1, 3),
(3, 3), (3,4), (1,4), (4,4)}.

10. A = {a9 b9 c, d9e], R = {(a9a)9 (b9 b)9 (c9 c), (a, c), (c, J), "1 1 1 1 1
(c, e), (0, <0, (d, d)9 (a, e)9 (b, c), (b, d)9 (b9 e)9 (e9e)}. 0 1 1 1 1
0 0 1 1 1
In Exercises 11 and 12, describe the ordered pairs in the
0 0 0 1 1
relation determined by the Hasse diagram on the set A =
_0 0 0 0 1
{1, 2, 3,4} (Figures 6.14 and 6.15).
11. 12. f 4

16. Determine the Hasse diagram of the relation on A =


3 {1, 2, 3,4, 5} whose matrix is shown.
2

1 1 0 1 1 1-
0 1 1 1 1
Figure 6.15 0 0 1 1 1
0 0 0 1 0
In Exercises 13 and 14, determine the Hasse diagram of the
partial order having the given digraph (Figures 6.16 and 6.17). 0 0 0 0 1_
6.1 Partially Ordered Sets 227
In Exercises 17 and 18, determine the matrix of the partial or In Exercises 29 and 30, draw the Hasse diagram ofa topolog
der whose Hasse diagram is given (Figures 6.18 and 6.19). ical sorting of the given poset (Figures 6.20 and 6.21).
17. 3 4 18. 29. 8 30.
1 »

2 /
k7 T 7X
/ \ 3
»

5x x 6
Figure 6.18 l
/
[ /5
Figure 6.19 2x x3 4

19. Let A = {•, A, B9 C, E9 09 M, P9 S] have the usual al


phabetical order, where D represents a "blank" character l Figure 6.21
and • < x for all x e A. Arrange the following in lexi Figure 6.20
cographic order (as elements of A x A x A x A).
(a) MOPD (b) MOPE (c) CAPD 31. If (A, <) is a poset and A! is a subset of A, show that
(d) MAPD (e) BASE (f) ACED (A'9 <') is also a poset, where <' is the restriction of < to
(g) MACE (h) CAPE A.

20. Let A = Z+ x Z+ have lexicographic order. Mark each of 32. Show that if R is a linear order on the set A, then R~l is
the following as true or false. also a linear order on A.
(a) (2,12)^(5,3) (b) (3,6)^(3,24) 33. A relation R on a set A is called a quasiorder if it is tran
(c) (4,8)^(4,6) (d) (15,92) ^ (12,3) sitive and irreflexive. Let A = P(S) be the power set of a
set 5, and consider the following relation RonA.URT
InExercises 21 through 24, considerthepartialorder of divis
if and only if U C T (proper containment). Show that R
ibility on theset A. Drawthe Hasse diagram of the posetand
is a quasiorder.
determine whichposets are linearly ordered.
34. Let A = {jc | jc is a real number and -5 < x < 20}. Show
21. A = {1,2, 3, 5, 6,10,15,30} that the usual relation < is a quasiorder (see Exercise 33)
22. A = {2,4, 8,16,32} on A.
23. A = {3,6,12,36,72} 35. If Risa quasiorder onA(see Exercise 33), prove that R~l
24. A = {1, 2, 3,4, 5, 6,10,12,15, 30, 60} is also a quasiorder on A.
25. Describe how to use MR to determine if R is a partial or 36. Modify the relationin Example3 to producea quasiorder
der. onZ+.
26. A partial order may or may not be a linear order, but any
37. Let B = {2, 3,6,9,12,18,24} and let A = B x B. De
poset can be partitioned into subsets that are each a linear
fine the following relation on A: (a, b) < (a\ bf) if and
order. Give a partition into linearly ordered subsets with
only if a \ a! and b < b', where < is the usual partial
as few subsets as possible for each of the following. The
order. Show that -< is a partial order.
poset whose Hasse diagram is given in
(a) Figure 6.5 (b) Figure 6.9(a) 38. Let A be the set of 2 x 2 Boolean matrices with M R N if
(c) Figure 6.15 (d) Figure 6.20
andonly if mu < nu 1 < i < 2,1 < j < 2. Prove that R
is a partial order on A.
(e) Figure 6.21
27. For each of the posets whose Hasse diagram is indicated 39. Let A = {1, 2, 3, 5, 6, 10, 15, 30} and consider the partial
below, give as large a set of elements as possible that are order < of divisibility on A. That is, define a < b to mean
incomparable to one another.
that a \ b. Let A' = P(S), where S = {e9 f g}, be the
poset with partial order c. Show that (A, <) and (A', c)
(a) Figure 6.5 (b) Figure 6.9(a) are isomorphic.
(c) Figure 6.15 (d) Figure 6.20
40. Let A = {1, 2,4, 8} and let < be the partial order of di
(e) Figure 6.21
visibility on A. Let A' = {0,1, 2, 3} and let <' be the
28. What is the relationship between the smallest number of usual relation "less than or equal to" on integers. Show
subsets needed to partition a partial order into linearly or that (A, <) and (A'9 <') are isomorphic posets.
dered subsets and the cardinality of the largest set of in
comparable elements in the partial order? Justify your 41. Show that the partial order (A, R) of Exercise 38 is iso
response.
morphic to (P({a9 b, c, d})9 C).
228 Chapter 6 Order Relations and Structures

6.2 Extremal Elements of Partially Ordered Sets


Certain elements in a poset are of special importance for many of the properties
and applications of posets. In this section we discuss these elements, and in later
sections we shall see the important role played by them. In this section we consider
a poset (A, <).
An element a e A is called a maximal element of A if there is no element
c in A such that a < c (see Section 6.1). An element b e A is called a minimal
element of A if there is no element c in A such that c < b.
It follows immediately that, if (A, <) is a poset and (A, >) is its dual poset,
an element a € A is a maximal element of (A, >) if and only if a is a minimal
element of (A, <). Also, a is a minimal element of (A, >) if and only if it is a
Figure 6.22 maximal element of (A, <).

Example 1 Consider the poset Awhose Hasse diagram is shown in Figure 6.22. Theelements
ax, a2, and a3 are maximal elements of A, and the elements b\, b2, and b3 are
minimal elements. Observe that, since there is no line between b2 and b3, we can
conclude neither that b3 < b2 nor that b2 <b3. ♦

Example 2 Let A be the poset of nonnegative real numbers with the usual partial order <.
Then 0 is a minimal element of A. There are no maximal elements of A. ♦

Example 3 The poset Z with the usual partial order < has no maximal elements and has no
minimal elements. ♦

THEOREM 1 Let A be a finite nonempty poset with partial order <. Then A has at least one
maximal element and at least one minimal element.

Proof
Let a be any element of A. If a is not maximal, we can find an element ax e A
such that a < ax. If ax is not maximal, we can find an element a2 e A such that
ax < a2. This argument cannot be continued indefinitely, since A is a finite set.
Thus we eventually obtain the finite chain

a < ax < a2 < • • • < a^-X < a^,

which cannot be extended. Hence we cannot have a* < b for any b € A, so a^ is


a maximal element of (A, <).
This same argument says that the dual poset (A, >) has a maximal element,
so (A, <) has a minimal element. •

By using the concept of a minimal element, we can give an algorithm for


finding a topological sorting of a given finite poset (A, <). We remark first that
if a e A and B = A —{a}, then B is also a poset under the restriction of < to
B x B (see Section 4.2). We then have the following algorithm, which produces a
linear array named SORT. We assume that SORT is ordered by increasing index,
that is, SORT[l] -< SORT[2] -<.... The relation -< on A definedin this way is a
topological sorting of (A, <).
6.2 Extremal Elements of Partially Ordered Sets 229

Algorithm
For finding a topological sorting of a finite poset (A, <).

Step 1 Choose a minimal element a of A.


Step 2 Make a the next entry of SORT and replace A with A- {a}.
Step 3 Repeat steps 1 and 2 until A = { }. •

Example 4 Let A = {a, b9 c9 d9 e}, and let the Hasse diagram of a partial order < on A be as
shown in Figure 6.23(a). A minimal element of this poset is the vertex labeled d
(we could also have chosen e). We put d in SORT[l] and in Figure 6.23(b) we
show the Hasse diagram of A - {d}. A minimal element of the new A is e, so e
becomes SORT[2], and A - {e} is shown in Figure 6.23(c). This process continues
until we have exhausted A and filled SORT. Figure 6.23(f) shows the completed
array SORT and the Hasse diagram of the poset corresponding to SORT. This is a
topological sorting of (A, <). ♦

a b a b a b

v SORT
d d e

(b) (c)

a* »

a b bn
SORT SORT SORT
c< •
d e c •
d e c b d e c b a


e<

(d) (e) (f)


d> >

Figure 6.23

An element a e A is called a greatest element of A if x < a for all x e A.


An element a e A is called a least element of A if a < x for all x e A.
As before, an element a of (A, <) is a greatest (or least) element if and only
if it is a least (or greatest) element of (A, >).

Example 5 Consider the poset defined in Example 2. Then 0 is a least element; there is no
greatest element. ♦

Example 6 Let 5 = [a9 b9 c] and consider the poset A = P(S) defined in Example 12 of
Section 6.1. The empty set is a least element of A, and the set 5 is a greatest
element of A. ♦

Example 7 The poset Z with theusual partial order has neither a leastnor a greatest element.
230 Chapter 6 Order Relations and Structures

THEOREM 2 A poset has at mostone greatest elementand at most one least element.

Proof
Suppose that a and b are greatestelements of a poset A. Then, since b is a greatest
element, we have a < b. Similarly, since a is a greatest element, we have b < a.
Hence a = b by the antisymmetry property. Thus, if the poset has a greatest
element, it only has one such element. Since this fact is true for all posets, the dual
poset (A, >) has at most one greatest element, so (A, <) also has at most one least
element. •

The greatest element of a poset, if it exists, is denoted by / and is often called


the unit element. Similarly, the least element of a poset, if it exists, is denoted by
0 and is often called the zero element.
Considera poset A and a subset B of A. An element a € A is called an upper
bound of B if b < a for all b e B. An element a e A is called a lower bound of
Bifa <b for all be B.

Example 8 Consider the poset A = {a, b9 c, d9 e9 f, g, h], whose Hasse diagram is shown in
Figure 6.24. Find all upper and lower bounds of the following subsets of A: (a)
Bx = {a9b};(b)B2 = {c9d9e}.

Solution
(a) B\ has no lower bounds; its upper bounds are c, d, e, f, g, and h.
(b) The upper bounds of B2 are /, g, and h; its lower bounds are c, a, and b.

As Example 8 shows, a subset B of a poset may or may not have upper or


lower bounds (in A). Moreover, an upper or lower bound of B may or may not
belong to B itself.
Let A be a poset and B a subset of A. An element a e A is called a least
upper bound of B, (LUB(B)), if a is an upper bound of B and a < a!, whenever
a! is an upper bound of B. Thus a = LUB(B) if b < a for all b e B, and if
whenever a! e A is also an upper bound of B, then a < a'.
Similarly, an element a 6 A is called a greatest lower bound of B, (GLB(B)),
if a is a lower bound of B and af < a, whenever a! is a lower bound of B. Thus
a = GLB(B) ifa<bfordllbeB, and if whenever a! e A is also a lower bound
of B, then a! < a.
As usual, upper bounds in (A, <) correspond to lower bounds in (A, >) (for
the same set of elements), and lower bounds in (A, <) correspond to upper bounds
in (A, >). Similar statements hold for greatest lower bounds and least upper
bounds.

Example 9 Let A be the posetconsidered in Example 8 with subsets Bx and B2 as defined in


that example. Find all least upper bounds and all greatest lower bounds of (a) Bx\
(b) B2.

Solution
(a) Since Bx has no lower bounds, it has no greatest lower bounds. However,
L\JB(BX) = c.

(b) Since the lower bounds of B2 arte, a, and b, we find that

GLB(£2) = c.
6.2 Extremal Elements of Partially Ordered Sets 231

The upper bounds of B2 are /, g, and h. Since / and g are not compara
ble, we conclude that B2 has no least upper bound. ♦

THEOREM 3 Let (A, <) be a poset. Then a subset B of A has at most one LUB and at most one
GLB.

Proof
The proof is similar to the proof of Theorem 2. •

We conclude this section with some remarks about LUB and GLB in a finite
poset A, as viewed from the Hasse diagram of A. Let B = {b\, b2,..., br}. If
a = LUB(fi), then a is the first vertex that can be reached from bX9b29 ...9br
by upward paths. Similarly, if a = GLB (J?), then a is the first vertex that can be
Figure 6.25 reached from bx, b29..., br by downward paths.

Example 10 Let A = {1,2,3,4,5,..., 11} be the poset whose Hasse diagram is shown in
Figure 6.25. Find the LUB and GLB of B = {6, 7, 10}, if they exist.

Solution
Exploring all upward paths from vertices 6, 7, and 10, we find that LUB(5) =
10. Similarly, by examining all downward paths from 6, 7, and 10, we find that
GLB(fi) =4. ♦

The next result follows immediately from the principle of correspondence (see
Section 6.1).

THEOREM 4 Suppose that (A, <) and (A', <') are isomorphic posets under the isomorphism
f:A-+A'.
(a) If a is a maximal (minimal) element of (A, <), then f(a) is a maximal
(minimal) element of (A', <').
(b) If a is the greatest (least) element of (A, <), then f(a) is the greatest
(least) element of (A', <').
(c) If a is an upper bound (lower bound, least upper bound, greatest lower
bound) of a subset B of A, then f(a) is an upper bound (lower bound,
least upper bound, greatest lower bound) for the subset f(B) of A!.
(d) If every subset of (A, <) has a LUB (GLB), then every subset of (A!9 <')
has a LUB (GLB). •

Example 11 Show that the posets (A, <) and (A!9 <'), whose Hasse diagrams are shown in
Figures 6.26(a) and (b), respectively, are not isomorphic.
a d b'
Solution
/<j The two posets are not isomorphic because (A, <) has a greatestelementa, while
(a) (b) (A'9 <f) does not have a greatest element. We could also argue that they are not
isomorphicbecause (A, <) does not have a least element, while (A'9 <') does have
Figure 6.26 a least element. ♦
232 Chapter 6 Order Relations and Structures
6.2 Exercises

In Exercises 1 through 8, determine all maximal and minimal 14. A = [x | jc is a real number and 0 < jc < 1} with the
elements of theposet. usual partial order <.
1.
/ 8 15. A = {2,4,6, 8,12, 18, 24, 36,72} with the partial order
of divisibility.

16. A = {2, 3,4,6,12,18,24, 36} with the partial order of


divisibility.
Figure 6.27 In Exercises 17 and 18, determine if the statementsare equiv
alent. Justifyyour conclusion.
e f
17. (a) If a e A is a maximal element, then there is no c e A
Kd/ such that a < c.

(b) If a e A is a maximal element, then for all b e A,


b <a.

18. (a) If a e A is a minimal element, then there is no c e A


such that c < a.

Figure 6.29 (b) If a e A is a minimal element, then for all b e A,


a <b.
5. A = R with the usual partial order <.

6. A = {jc I x is a real number and 0 < jc < 1} with the 19. Determine if the given statement is true or false. Explain
usual partial order <. your reasoning.

7. A = {x | x is a real number and 0 < jc < 1} with the (a) A nonempty finite poset has a maximal element.
usual partial order <. (b) A nonempty finite poset has a greatest element.
8. A = {2, 3,4, 6, 8, 24,48} with the partial order of divisi (c) A nonempty finite poset has a minimal element.
bility.
(d) A nonempty finite poset has a least element.
In Exercises 9 through 16, determine the greatest and least el
ements, if they exist, of the poset. 20. Prove that if (A, <) has a greatest element, then (A, <)
9. r 10. has a unique greatest element.

21. Prove that if (A, <) has a least element, then (A, <) has
» e
a unique least element.
1
»c

V V
a
22. Prove Theorem 3.

In Exercises 23 through 32 find, if they exist, (a) all upper


bounds of B; (b) all lower bounds of B; (c) the least upper
Figure 6.31 Figure 6.32
bound ofB; (d) the greatest lower bound ofB.
11. 4 5 12.
23. 24.

1 2
Figure 6.34 5={1, 2, 3, 4, 5}

13. A = {jc | jc is a real number and 0 < jc < 1} with the


usual partial order <. Figure 6.35 Figure 6.36
6.3 Lattices 233

25. 26. 32. A is the set of 2 x 2 Boolean matrices and < denotes the re
lation R with M R N if and only if m,7 < nij9 1 < / < 2,

>*j**'-[[1 !]•[* ,'Hi ?]}•


33. Construct the Hasse diagram of a topological sorting of
the poset whose Hasse diagram is shown in Figure 6.35.
bk Use the algorithm SORT.
£={3, 4, 6} 34. Construct the Hasse diagram of a topological sorting of
B = {b, c, d] the poset whose Hasse diagram is shown in Figure 6.36.
Figure 6.38 Use the algorithm SORT
Figure 6.37 35. Let R be a partial order on a finite set A. Describe how to
27. (A, <) is the poset in Exercise 23; B = {b, g, h}. use MR to find the least and greatest elements of A if they
28. (a) (A, <) is the poset in Exercise 26; B = {4, 6,9}. exist.

(b) (A, <) is the poset in Exercise 26; B = {3,4, 8}. 36. Give an example of a partial order on A = {a, b9 c, d9 e]
that has two maximal elements and no least element.
29. A = R and < denotes the usual partial order;
B = {jc I jc is a real number and 1 < jc < 2}. 37. Let A = {2, 3,4,..., 100} with the partial order of divis
ibility.
30. A = R and < denotes the usual partial order;
B = {jc I x is a real number and 1 < jc < 2}. (a) How many maximal elements does (A, <) have?
31. A is the set of 2 x 2 Boolean matrices and < denotes the re
(b) Give a subset of A that is a linear order under divisi
lation R with M R N if and only if m,; < n,7, 1 < / < 2, bility and is as large as possible.
1 < j < 2; B is the set of matrices in A with exactly two 38. Let (A, <) be as in Exercise 37. How many minimal ele
ones. ments does (A, <) have?

6.3 Lattices

A lattice is a poset (L, <) in which every subset {a, b} consisting of two elements
has a least upper bound and a greatest lower bound. We denote LUB({a, b}) by
a v b and call it the join of a and b. Similarly, we denote GLB ({a, b}) by a A b
and call it the meet of a and b. Lattice structures often appear in computing and
mathematical applications. Observe that a lattice is a mathematical structure as
described in Section 1.6, with two binary operations, join and meet.

Example 1 Let 5 be a set and let L = P(S). As we have seen, c, containment, is a partial
order on L. Let A and B belong to the poset (L, c). Then A v B is the set A U B.
To see this, note that A c A U B, B c A U B, and, if A c C and B c C, then it
follows that AU B c. C. Similarly, we can show that the element A A B in (L, c)
is the set A D B. Thus, L is a lattice. ♦

Example 2 Consider the poset (Z+, <), where for a and b in Z+, a < b if and only if a \ b.
Then L is a lattice in which the join and meet of a and b are their least common
multiple and greatest common divisor, respectively (see Section 1.4). That is,

a vb = LCM(a9b) and a A b = GCD(a9 b). ♦

Example 3 Let n be a positive integer and let Dn be the set of all positive divisors of n. Then
Dn is a lattice under the relation of divisibility as considered in Example 2. Thus,
if n = 20, we have D2q = {1, 2,4, 5, 10, 20}. The Hasse diagram of D20 is shown
in Figure 6.39(a). If n = 30, we have D30 = {1, 2, 3, 5, 6,10,15, 30}. The Hasse
diagram of D30 is shown in Figure 6.39(b). ♦
234 Chapter 6 Order Relations and Structures

20 30

Figure 6.39

Example 4 Which ofthe Hasse diagrams inFigure 6.40 represent lattices?


Solution
Hassediagrams (a), (b), (d), and (e) represent lattices. Diagram(c) does not repre
sent a lattice because / v g does not exist. Diagram (f) does not represent a lattice
because neither d A e nor b v c exist. Diagram (g) does not represent a lattice
because c Ad does not exist. ♦

Example 5 We have already observed inExample 4 ofSection 6.1 that the setfR ofall equiva
lence relations on a set A is a poset under the partial order of set containment. We
can now conclude that SI is a lattice where the meet of the equivalence relations R
and S is their intersection RHS and their join is (R U 5)°°, the transitive closure
of their union (see Section 4.8). ♦

Let (L, <) be a poset and let (L, >) be the dual poset. If (L, <) is a lattice,
we can show that (L, >) is also a lattice. In fact, for any a and b in L, the least
6.3 Lattices 235

upper bound of a and b in (L, <) is equal to the greatest lower bound of a and b
in (L, >). Similarly, the greatest lower bound of a and b in (L, <) is equal to the
least upper bound of a and 2? in (L, >). If L is a finite set, this property can easily
be seen by examining the Hasse diagrams of the poset and its dual.

Example 6 Let S be a set and L = P(S). Then (L, c) is a lattice, and its dual lattice is
(L, 2), where c is "contained in" and 2 is "contains." The discussion preceding
this example then shows that in the poset (L, 2) the join AvBis the set A fl B,
and the meet A A B is the set AU B. ♦

THEOREM 1 If (Lx, <) and (L2, <) are lattices, then (L, <) is a lattice, where L = Lx x L2,
and the partial order < of L is the product partial order.

Proof
We denote the join and meet in Li by Vi and ax, respectively, and the join and
meet in L2 by v2 and A2, respectively. We already know from Theorem 1 of
Section 6.1 that L is a poset. We now need to show that if (ax, bx) and (a2, b2) e L,
then (ax,bx)v(a2, b2) and (ax ,bx)A (a2, b2) exist in L. We leave it as an exercise
to verify that

(ax,bx) V (a2, b2) = (ax vx a2, bx V2 b2)


(ax, bx) A (a2, b2) = (ax Ax a2, bx A2 b2).

Thus L is a lattice. •

Example 7 Let Li and L2 be the lattices shown in Figures 6.41(a) and (b), respectively. Then
L = Lx x L2 is the lattice shown in Figure 6.41(c). ♦

(A. h)

(/„ a) (/„ b)

(0„ a) (0„ ft)

o, 02
i. 1^1
(a) (b)

Figure 6.41

Let (L, <) be a lattice. A nonempty subset 5 of L is called a sublattice of L


ifavbeS and a Ab € S whenever a e S and b e S.

Example 8 The lattice Dn of all positive divisors of n (see Example 3) is a sublattice of the
lattice Z+ under the relation of divisibility (see Example 2). ♦
236 Chapter 6 Order Relations and Structures

Example 9 Consider the lattice L shown in Figure 6.42(a). The partially ordered subset S/,
shown in Figure 6.42(b) is not a sublattice of L since a A b £ Si,. The partially
ordered subset Sc in Figure 6.42(c) is not a sublattice of L since a v b £ Sc.
Observe, however, that Sc is a lattice when considered as a poset by itself. The
partially ordered subset Sd in Figure 6.42(d) is a sublattice of L. ♦

Figure 6.42

Isomorphic Lattices
If /: Lx -> L2 is an isomorphismfrom the poset (Lx, <x) to the poset (L2, <2),
then Theorem 4 of Section 6.2 tells us that Lx is a lattice if and only if L2 is a
lattice. In fact, if a and b are elements of Lx, then f(aAb) = f(a)A f(b) and
f(a v b) = /(a) v /(&). If two latticesare isomorphic, as posets, we say they are
isomorphic lattices.

Example 10 LetL be the lattice D6, and let V bethelattice P(S) under therelation of contain
ment, where S = {a, b}. These posets were discussed in Example 16 of Section
6.1, where they were shown to be isomorphic. Thus, since both are lattices, they
are isomorphic lattices. ♦

If /: A -» B is a one-to-one correspondence from a lattice (A, <) to a set B,


then we can use the function / to define a partial order <' on B. If b\ and b2 are
in B, then bx = f(ax) and fc2 = /(a2) for some unique elements ax and a2 of A.
Define bx <' b2 (in 2?) if and only if ax < a2 (in A). If A and 2? are finite,
then we can describe this process geometrically as follows. Construct the Hasse
diagram for (A, <). Then replace each label a by the corresponding element f(a)
of B. The result is the Hasse diagram of the partial order <' on B.
When B is given the partial order <', / will be an isomorphism from the
poset (A, <) to the poset (B, <'). To see this, note that / is already assumed to
be a one-to-one correspondence. The definition of <' states that, for any ax and a2
in A, ax < a2 if and only if f(ax) <' f(a2). Thus / is an isomorphism. Since
(A, <) is a lattice, so is (B, <'), and they are isomorphic lattices.

Example 11 If A is a set, let St be the set of all equivalence relations on A and let II be the
set of all partitions on A. In Example 13 of Section 5.1 we constructed a one-to-
one correspondence / from Si to II. In Example 4 of Section 6.1, we considered
the partial order c on Si. From this partial order we can construct, using / as ex
plained before, a partialorder <' on II. By construction, if P\ and S>2 are partitions
of A, and Rx and R2, respectively, are the equivalence relations corresponding to
6.3 Lattices 237

these partitions, then 3>x < 3>2 will mean that Rx c R2. Since we showed in
Example 5 that (Si, c) is a lattice, and we know that / is an isomorphism, it fol
lows that (II, <') is also a lattice. In Exercise 35 we describe the partial order <'
directly in terms of the partitions themselves. ♦

Properties of Lattices
Before proving a number of the properties of lattices, we recall the meaning of
av b and a A b.

1. a < av b and b < a v b; a v b is an upper bound of a and b.


2. Ifa<c and b < c, then a v b < c; a v b is the least upper bound of a and b.
1\ a A b < a and a Ab < b',a Abisa. lower bound of a and b.
21. If c < a and c < b, then c < a A b; a A b is the greatest lower bound of a
andfo.

THEOREM 2 Let L be a lattice. Then for every a and b in L,


(a) av b = bif and only ifa<b.
(b) a A £ = a if and only ifa<b.
(c) a A Z? = a if and only ifavb = b.

Proof
(a) Suppose that a\/b = b. Since a < a vb = b, we have a < &. Conversely,
if <z < b, then, since ft < b, b is an upper bound of a and fc; so by definition
of least upper bound we have av b <b. Since a v b is an upper bound,
b < a V b, so a V b = b.
(b) The proof is analogous to the proof of part (a), and we leave it as an
exercise for the reader.
(c) The proof follows from parts (a) and (b). •

Example 12 Let L be a linearly ordered set. If a and b e L, then either a < b or b < a. It
follows from Theorem 2 that L is a lattice, since every pair of elements has a least
upper bound and a greatest lower bound. ♦

THEOREM 3 Let L be a lattice. Then


1. Idempotent Properties
(a) av a = a
(b) a A a = a
2. Commutative Properties
(a) av b = bv a
(b) a A b = b A a
3. Associative Properties
(a) AV(ivc) = (flVi)vc
(b) a A (b A c) = (a A b) A c
4. Absorption Properties
(a) ay (a Ab) = a
(b) a A(av b) = a
238 Chapter 6 Order Relations and Structures
Proof
1. The statements follow from the definition of LUB and GLB.
2. The definitionof LUB and GLB treat a and b symmetrically, so the results
follow.
3. (a) From the definition of LUB, we have a < a v (b v c) and b v c <
av (by c). Moreover, b < bv c and c < b v c, so, by transitivity,
b < av (bv c) and c < a v (b v c). Thus a v (b v c) is an upper
bound of a and b, so by definition of least upper bound we have

avb <aV (bv c).

Since a v (b v c) is an upper bound ofavb and c, we obtain

(avb)v c <av (bv c).

Similarly, a v (bVc) < (avb) vc. By the antisymmetry of <, property


3(a) follows.
(b) The proof is analogous to the proof of part (a) and we omit it.
4. (a) Since a A b < a and a < a, we see that a is an upper bound of a A b
and a; so a v (a A b) < a. On the other hand, by the definition of
LUB, we have a < a v (a A b), so a v (a A b) = a.
(b) The proof is analogous to the proof of part (a) and we omit it. •

It follows from property3 that we can write av(bvc) and (a v b) v c merely


as a v b v c, and similarly for a A b A c. Moreover, we can write

LUB({ai,a2,...,an}) as ax va2 v • • • van


GLB({ax, a2,..., an}) as ax A a2 A • • • A an,

since we can show by induction that these joins and meets are independent of the
grouping of the terms.

THEOREM 4 Let L be a lattice. Then, forevery a, b, and c in L,


1. If a < b, then
(a) av c <bv c.
(b) a Ac <b Ac.
2. a < c and b < c if and only if a v b < c.
3. c < a and c < b if and only if c < a A b.
4. If a < b and c < d, then
(a) aVc <bvd.
(b) a A c < b A d.

Proof
The proof is left as an exercise. •

Special Types of Lattices


A lattice L is said to be bounded if it has a greatest element / and a least element
0 (see Section 6.2).

Example 13 The lattice Z+ under the partial order of divisibility, as defined in Example 2, is
not a bounded lattice since it has a least element, the number 1, but no greatest
element. ♦
6.3 Lattices 239

Example 14 The lattice Z under the partial order < is notbounded since it has neither a greatest
nor a least element. ♦

Example 15 The lattice P(S) of all subsets of a set S, as defined in Example 1, is bounded. Its
greatest element is S and its least element is 0. ♦

If L is a bounded lattice, then for all a e A,

0<a < I
av 0 = a, a a0 = 0
av I = /, a A I — a.

THEOREM 5 Let L = {ax,a2,..., an} be a finite lattice. Then L is bounded.

Proof
The greatest element of L is ax v a2 v v an, and its least element is ax A a2 A
••• Aan.

Note that the proof of Theorem 5 is a constructive proof. We show that L is


bounded by constructing the greatest and the least elements.
A lattice L is called distributive if for any elements a, b, and c in L we have
the following distributive properties:
1. a A(bv c) = (a Ab)v (a Ac)
2. a v (b A c) = (a v b) A (a v c)
If L is not distributive, we say that L is nondistributive.
We leave it as an exercise to show that the distributive property holds when
any two of the elements a, b, or c are equal or when any one of the elements is 0 or
/. This observation reduces the number of cases that must be checked in verifying
that a distributive property holds. However, verification of a distributive property
Figure 6.43 is generally a tedious task.

Example 16 For a set S, the lattice P(S) is distributive, since union and intersection (the join
and meet, respectively) each satisfy the distributive property shown in Section 1.2.

Example 17 The lattice shown in Figure 6.43 is distributive, as can be seen by verifying the
distributive properties for all ordered triples chosen from the elements a, b, c,
and d. ♦

Example 18 Show thatthe lattices pictured in Figure 6.44are nondistributive.


Solution

I
(a) We have
A aA(bvc) = aAl=a
I
a

A
<
K while

b< l>..< b< »


/
\ c
(b) Observe that
(a A b) v (a A c) = b V 0 = b.

aA(bvc) = aAl = a
0 C

(a) Q
3) while
(aAb)v(aAc) = OvO = 0.
Fitgure 6.44
240 Chapter 6 Order Relations and Structures

The nondistributive lattices discussed in Example 18 are useful for showing


that a given lattice is nondistributive, as the following theorem, whose proof we
omit, asserts.

THEOREM 6 Alattice Lisnondistributive ifand only ifitcontains a sublattice that isisomorphic


to one of the two lattices of Example 18. •
Theorem6 can be used quite efficiently by inspectingthe Hasse diagramof L.
Let L be a bounded lattice with greatest element / and least element 0, and let
a e L. An element af e Lis called a complement of a if

av af = I and a A a' = 0.

Observe that
(/ = I and /' = 0.

Example 19 The lattice L = P(S) issuch that every element has acomplement, since if A e L,
then its set complement A has the properties A v A = S and A A A = 0. That is,
the set complement is also the complement in the lattice L. ♦

Example 20 The lattices in Figure 6.44 each have the property that every element has a com
plement. The element c in both cases has two complements, a and b. ♦

Example 21 Consider the lattices D20 and D30 discussed in Example 3 and shown in Figure
6.39. Observethat everyelementin D30 has a complement. For example,if a = 5,
then a' = 6. However, the elements 2 and 10 in D2q have no complements. ♦

Examples 20 and 21 show that an element a in a lattice need not have a com
plement, and it may have more than one complement. However, for a bounded
distributive lattice, the situation is more restrictive, as shownby the following the
orem.

THEOREM 7 Let L bea bounded distributive lattice. If a complement exists, it is unique.


Proof
Let a! and a" be complements of the element a e L. Then

av a' = I, av af/ = I
a a a' = 0, a Aa" = 0.

Using the distributive laws, we obtain

a' = a'vO = a'v(aA a!')


= (a' va)A (a' v a")
= I A (a! v a") =a'v a".

Also,

a" = a"v0 = a" V (a A a!)


= (a" Va)A (a" V a')
= I A (a! v a") = a'v a".

Hence af = a".
6.3 Lattices 241

The proof of Theorem 7 is a direct proof, but it is not obvious how the repre
sentations of a' and a" were chosen. There is some trial and error involved in this
sort of proof, but we expect to use the hypothesis that L is bounded and that L is
distributive. An alternative proof is outlined in Exercise 36.
A lattice L is called complemented if it is bounded and if every element in L
has a complement.

Example 22 The lattice L = P(S) is complemented. Observe that in this case each element
of L has a unique complement, which can be seen directly or is implied by Theo
rem 7. ♦

Example 23 Thelattices discussed in Example 20andshown in Figure 6.44arecomplemented.


In this case, the complementsare not unique. ♦

6.3 Exercises
In Exercises 1 through 6 (Figures 6.45 through 6.50), deter 7. Is the poset A = {2, 3, 6,12, 24, 36, 72} under the rela
mine whether the Hasse diagram represents a lattice. tion of divisibility a lattice?

2. e f 8. Let A be the set of 2 x 2 Boolean matrices with M R N if


and only if mu < nu, 1 < i < 2, 1 < j < 2. Is (A, R) a
lattice?

9. Let A be the set of 2 x 2 matrices with M R N if and only


if niij < nlj9 1 < i < 2, 1 < j < 2. Is (A, R) a lattice?
10. Amplify the explanations in the solution of Example 4 by
explaining why the specified object does not exist.
11. If Lx and L2 are the lattices shown in Figure 6.51, draw
the Hasse diagram of Lx x L2 with the product partial
order.

Figure 6.46 7i T

a2

Li L2

Figure 6.51
12. Complete the proof of Theorem 1 by verifying that
(ax,bx) v (a2, b2) = (ax v, a2, bx v2 b2) and
(aub\) A (a2, b2) = (ax A, a2, bx A2 b2).
13. Let L = P (S) be the lattice of all subsets of a set S under
the relation of containment. Let T be a subset of S. Show
that P(T) is a sublattice of L.
14. Let L be a lattice and let a and b be elements of L such
that a < b. The interval [a, b] is defined as the set of
all x e L such that a < x < b. Prove that [a, b] is a
sublattice of L.

15. Show that a subset of a linearly ordered poset is a sublat


tice.

16. Find all sublattices of D24 that contain at least five ele
ments.

17. Give the Hasse diagrams of all nonisomorphic lattices that


Figure 6.49 Figure 6.50 have one, two, three, four, or five elements.
242 Chapter 6 Order Relations and Structures

18. Show that if a bounded lattice has two or more elements, 30. ef 31.
then 0 ^1.
d
19. Prove Theorem 2(b).
c
20. Show that the lattice Dn is distributive for any n.
b
21. (a) In Example 17 (Figure 6.43), how many ordered
triples must be checked to see if the lattice is dis a

tributive?
(b) In Example 18 (Figure 6.44), what is the maximum Figure 6.55
number of ordered triples that would need to be
checked to show that the lattice is not distributive?
22. Show that a sublattice of a distributive lattice is distribu Figure 6.56
tive.

23, Show that if Lx and L2 are distributive lattices, then


L = Lx x L2 is also distributive, where the order of L 32. Prove Theorem 4, part (2).
is the product of the orders in Lx and L2.
24, Prove that if a and b are elements in a bounded, distribu 33. Let L be a bounded lattice with at least two elements.
tive lattice and if a has a complement a', then Show that no element of L is its own complement.

av (a' Ab) =avb


34. Considerthe complemented lattice shownin Figure 6.57.
a A (a' v b) = a A b. Give the complements of each element.
25, Let L be a distributive lattice. Show that if there exists an
a with a A x = a A y and a v x = a V y, then x = y.
26. A lattice is said to be modular if, for all a, b, c, a < c
implies that av (b Ac) = (av b) Ac.
(a) Show that a distributive lattice is modular.
(b) Show that the lattice shown in Figure 6.52 is a
nondistributive lattice that is modular.
Figure 6.57
/

35. Let Px = {Ax, A2,...}, P2 = {BX,B2,...} be twoparti


tions of a set S. Show that Px < P2 (see the definition in
Example 11) if and only if each A, is contained in some
Bj.
Figure 6.52
36. Complete the following proof of Theorem 7.
27. Find the complement of each element in £>42. Proof: Let a! and a" be complements of a e L. Then
a! = a' AI = Also, a" = a" AI = Hence
In Exercises 28 through 31 (Figures 6.53 through 6.56), de a' = a".
termine whethereach lattice is distributive, complemented, or
both.
37. Prove or disprovethat a sublatticeof a complementedlat
28. 29. tice is also complemented.

38. Prove or disprove that a sublattice of a bounded lattice is


also bounded.

39. Prove or disprove that a sublattice of a modular lattice is


also modular.

Figure 6.54
Figure 6.53 40. Prove that any linear order is a distributive lattice.
6.4 Finite Boolean Algebras 243

6.4 Finite Boolean Algebras


In this section we discuss a certain type of lattice that has a great many applications
in computer science. We have seen in Example 6 of Section 6.3 that if S is a set,
L = P(S), and c is the usual relation of containment, then the poset (L, c)
is a lattice. These lattices have many properties that are not shared by lattices
in general. For this reason they are easier to work with, and they play a more
important role in various applications.
We will restrict our attention to the lattices (P(S), c), where 5 is a finite set,
and we begin by finding all essentially different examples.

THEOREM 1 If S\ = {xx,x2,..., xn} and S2 = {yx, y2,..., yn] are any two finite sets with
n elements, then the lattices (P(SX), c) and (P(S2), c) are isomorphic. Conse
quently, the Hasse diagrams of these lattices may be drawn identically.

Proof
Arrange the sets as shown in Figure 6.58 so that each element of Sx is directly over
the correspondingly numbered element in 52. For each subset A of Si, let f(A)
be the subset of 52 consisting of all elements that correspond to the elements of
A. Figure 6.59 shows a typical subset A of Sx and the corresponding subset f(A)
of 52. It is easily seen that the function / is a one-to-one correspondence from
subsets of Sx to subsets of 52. Equally clear is the fact that if A and B are any
subsets of Si, then A c B if and only if f(A) c /(B). We omit the details. Thus
the lattices (P(SX), c) and (P(S2), c) are isomorphic. •

St : *, x2 X^ Xq

6 j '. x^ x2

s2- yx yi J3 >4 ••• yn

s2 • yx yi yn
/(A)

Figure 6.58 Figure 6.59

The essential point of this theorem is that the lattice (P(S), c) is completely
determined as a poset by the number \S\ and does not depend in any way on the
nature of the elements in S.

Example 1 Figures 6.60(a) and (b) show Hasse diagrams for the lattices (P(S), c) and
(P(T), c), respectively, where S = {a, b, c] and T = {2,3, 5}. It is clear from
this figure that the two lattices are isomorphic. In fact, we see that one possible
isomorphism /: S -• T is given by
f({a}) = {2}, /({*}) = (3}, f({c}) = {5},
f({a,b}) = {2, 3}, f({b,c}) = {3,5}, f({a,c}) = {2,5},
f({a,b,c}) = {2,3,5}, f(0) = 0.

Thus, for each n = 0,1, 2,..., there is only one type of lattice having the
form (P(S), c). This lattice depends only on n, not on S, and it has 2n elements,
as was shown in Example 2 of Section 3.1. Recall from Section 1.3 that if a set S
has n elements, then all subsets of S can be represented by sequences of O's and
244 Chapter 6 Order Relations and Structures
{a, b, c} {2, 3, 5}

{a, b) b, c) {2, 3) {3,5}

Figure 6.60

l's of length n. Wecan thereforelabel the Hasse diagram of a lattice (P(S), c) by


such sequences. In doing so, we free the diagramfrom dependence on a particular
set 5 and emphasize the fact that it depends only on n.

Example 2 Figure 6.60(c) shows how the diagrams that appear in Figures 6.60(a) and (b)
can be labeled by sequences of O's and l's. This labeling serves equally well to
describe the lattice of Figure 6.60(a) or (b), or for that matter the lattice (P(S), c)
that arises from any set S having three elements. ♦

If the Hasse diagram of the lattice corresponding to a set with n elements is


labeled by sequences of O's and l's of length n, as described previously, then the
resulting lattice is named Bn. The properties of the partial order on Bn can be
described directly as follows. If x = axa2 •••an and y = bxb2--bn are two
elements of Bn, then
1. x < y if and only ifak < bk (as numbers 0 or 1) for k = 1, 2,..., n.
2. x A y = cic2 •••cn, where ck = min{a*,bk}.
3. x v y = dxd2 -"dn, where dk = max{ak, bk}.
4. x has a complementxf = zxz2 •••zw, where Zk = 1 if xk = 0, and Zk = 0 if
xk = 1.
The truthof these statements canbe seenby noting that (Bn, <) is isomorphic
with (P(S), c), so each x and y in Bn correspond to subsets Aand B of S.JThen
x < y, x A y, x v y, and xf correspond to A c B, A fl B, A U B, and A (set
complement), respectively (verify). Figure 6.61 shows the Hasse diagrams of the
lattices Bn for n = 0, 1, 2, 3.
We have seen that each lattice (P(S), c) is isomorphic with Bn, where n =
\S\. Other latticesmay also be isomorphic with one of the Bn and thus possess all
the special properties that the Bn possess.

Example 3 In Example 17 ofSection 6.1, we considered the lattice De consisting ofall posi
tive integerdivisors of 6 underthe partial order of divisibility. The Hasse diagram
of D6 is shown in that example, and we now see that D6 is isomorphic with B2. In
fact, /: De -> B2 is an isomorphism, where
/(l) = 00, /(2) = 10, /(3) = 01, /(6) = 11. ♦

We are therefore led to make the following definition. A finite lattice is called
a Boolean algebra if it is isomorphic with Bn for some nonnegative integer n.
6.4 Finite Boolean Algebras 245

n= 0 n= 1

Figure 6.61

Thus each Bn is a Boolean algebra and so is each lattice (P(S), c), where S is a
finite set. Example 3 shows that D6 is also a Boolean algebra.
We will work only with finite posets in this section. For the curious, however,
we note that there are infinite posets that share all the relevant properties of the
lattices (P(S), c) (for infinite sets S, of course), but that are not isomorphic with
one these lattices. This necessitates the restriction of our definition of Boolean
algebra to the finite case, which is sufficient for the applications that we present.

Example 4 Consider the lattices D20 and D30 of all positive integer divisors of 20 and 30,
respectively, under the partial order of divisibility. These posets were introduced
in Example 3 of Section 6.3, and theirHassediagrams were shown in Figure6.39.
Since D20 has six elements and 6 ^ 2n for any integer n > 0, we conclude that D20
is not a Boolean algebra. The poset D30 has eight elements, and since 8 = 23, it
could be a Boolean algebra. By comparingFigure 6.39(b) and Figure 6.61, we see
that D30 is isomorphic with B3. In fact, we see that the one-to-onecorrespondence
/: D3o -> B3 defined by

/(l) = 000, f(2) = 100, f(3) = 010,


/(5) = 001, /(6) = 110, /(10) = 101,
/(15) = 011, /(30) = 111

is an isomorphism. Thus D30 is a Boolean algebra.

If a finite lattice L does not contain 2n elements for some nonnegative integer
n, we know that L cannot be a Boolean algebra. If \L\ =2n, then L may or may
not be a Boolean algebra. If L is relatively small, we may be able to compare its
Hasse diagram with the Hasse diagram of Bn. In this way we saw in Example 4
that D30 is a Boolean algebra. However, this technique may not be practical if L is
large. In that case, we may be able to show that L is a Boolean algebra by directly
constructing an isomorphism with some Bn or, equivalently, with (P(S), c) for
some finite set S. Suppose, for example, that we want to know whether a lattice
Dn is a Boolean algebra, and we want a method that works no matter how large n
is. The following theorem gives a partial answer.
246 Chapter 6 Order Relations and Structures
THEOREM 2 Let
n = PiPi" • Pk,

where the pt are distinctprimes. Then Dn is a Boolean algebra.

Proof
Let S = {px, p2,..., pk}. If T c S and ar is the product of the primesin T, then
aT \n. Any divisor of n must be of the form aT for some subset T of S (where we
let a0 = 1). The reader may verify that if V and T are subsets of S,V C.T if and
only if ay | aT. Also, it follows from the proof of Theorem 6 of Section 1.4 that
avnT = fly A flr = GCD(fly, Ar) and ayur = ay v aT = LCMfay, 07-). Thus
the function f:P(S)->Dn given by f(T) = ar is an isomorphism from P(S)
to Dn. Since B(S) is a Boolean algebra, so is Dn. •

Example 5 Since 210 = 2-3.5-7,66 = 2-3-11, and 646 = 2-17-19, weseefrom Theorem
2 that D210, £*66, and D^ are all Boolean algebras. ♦

In other cases of large lattices L, we may be able to show that L is not a


Boolean algebra by showing that the partial order of L does not have the neces
sary properties. A Boolean algebra is isomorphic with some Bn and therefore with
some lattice (P(S), c). Thus a Boolean algebra L must be a bounded lattice and a
complemented lattice (seeSection 6.3). In other words, it will havea greatest ele
ment / corresponding to the set S and a least element 0 correspondingto the subset
0. Also, every element x of L will have a complement x'. According to Example
16,Section 6.3, L mustalsobe distributive. The principle of correspondence (see
Section 6.1) then tells us that the following rule holds.

THEOREM 3 Any formula involving Uor n that holds for arbitrary subsets of a set S will con-
Substitution Rule for tinue t0 hold for arbitrary elements of a Boolean algebra L if A is substituted for
Boolean Algebras HandvforU. •

Example 6 If L is any Boolean algebra and x, y, and z are in L, then the following three
properties hold.
1. (x'Y = x Involution Property
2. (jc A y)' = xfVyf
De Morgan's Laws
3. (x vy)'=xf Ayf
This is true by the substitutionrule for Boolean algebras, since we know that the
corresponding formulas

V. 0[j = A
2'. (AflB) = AUB
3'. (AUB) = AnB
hold for arbitrary subsets A and B of a set S. ♦

In a similar way, we can list other properties that must hold in any Boolean
algebra by the substitution rule. Next we summarize all the basic properties of a
Boolean algebra (L, <) and, next to each one, we list the corresponding property
for subsets of a set S. We suppose that x, y, and z are arbitrary elements in L,
and A, B, and C are arbitrary subsets of S. Also, we denote the greatest and least
elements of L by / and 0, respectively.
6.4 Finite Boolean Algebras 247

1. x < y if and only if x v y = y. V. A c B if and only if AUB = B.


2. jc < y if and only if x A y = x. 2'.AC5 if and only if A n fi = A.
3. (a) x v x = x. 3'. (a) A U A = A.
(b) x ax = x. (b) A H A = A.
4. (a) jc v y = y v x. 4'. (a) A U £ = B U A.
(b) x Ay = y Ax. (b) A H B = B H A.
5. (a) jfv(yvz) = (xvy)vz. 5'. (a) A U (fi U C) = (A U B) U C.
(b) x A (y A z) = (x A y) A z. (b) A n (5 n C) = (A n 5) n c.
6. (a) x v (x A y) = x. 6'. (a) A U (A H £) = A.
(b) x A (x V y) = x. (b) A H (A U 5) = A.
7. 0 < x < I for all x in L. T.0CACS for all A in P(S).
8. (a) x v 0 = jc. 8'. (a) A U 0 = A.
(b) x a 0 = 0. (b) A 0 0 = 0.
9. (a) x v / = /. 9'. (a) A U 5 = 5.
(b) jc A / = x. (b) ADS = A.
10. (a) jc A (y v z) 10'. (a) Afl(BUC)
= (jc Ay) v (jc az). = (A n #) u (A n C).
(b) x V (y A z) (b) A U (B n C)
= (jc V y) A (jc V z). = (A U B) n (A U C).
11. Every element x has a unique 11'. Every element_ A has a unique
complement jc' satisfying complement A satisfying
(a) jc vjc' = /. (a) AUA = S.
(b) jcajc7 = 0. (b) AHA = 0.

12. (a) 0 = 1. 12'. (a) 0 = 5.


(b) V = 0. (b) 5 = 0.
13. (xj = jc. 13'. (^) = A. _
14. (a) (jc a y)' = x' v /. 14'. (a) (ADB) = A\JB.
(b) (jc v yY = x' a y. (b) (AUB) = An~B.

Thus we may be able to show that a lattice L is not a Boolean algebra by


Figure 6.62 showing that it does not possess one or more of these properties.

Example 7 Show that thelattice whose Hasse diagram is shown inFigure 6.62 is nota Boolean
algebra.

Solution
Elements a and e are both complements of c; that is, they both satisfy properties
11(a) and 11(b) with respect to the element c. But property 11 says that such
an element is unique in any Boolean algebra. Thus the given lattice cannot be a
Boolean algebra. ♦

Example 8 Show that ifnisa positive integer and p2 \ n, where p isa prime number, then Dn
is not a Boolean algebra.

Solution
Suppose that p2 \ n so thatn = p2q for some positive integer q. Since p is also a
divisor of n, p is an element of Dn. Thus, by the remarks given previously, if Dn
is a Boolean algebra, then p musthave a complement pf. Then GCD(/?, p') = 1
248 Chapter 6 Order Relations and Structures

and LCM(/?, p') = n. By Theorem6 of Section 1.4, pp' = n, so pf = nip = pq.


This shows that GCD(p, p#) = 1, which is impossible, since p and pq have /? as
a common divisor. Hence Dn cannot be a Boolean algebra. ♦

If we combineExample8 and Theorem 2, we see that Dn is a Boolean algebra


if and only if n is the product of distinct primes, that is, if and only if no prime
divides n more than once.

Example 9 If n = 40, thenn = 23 •5, so 2 divides n three times. If rc = 75, then n = 3 •52,
so 5 divides n twice. Thus neither D40 nor D75 are Boolean algebras. ♦

Let us summarize what we have shown about Boolean algebras. We may at


tempt to show that a lattice L is a Boolean algebra by examining its Hasse diagram
or constructing directly an isomorphism between L and Bn or (P(S), c). We may
attempt to show that L is not a Boolean algebra by checking the number of ele
ments in L or the propertiesof its partial order. If L is a Boolean algebra, then we
may use any of the properties 1 through 14 to manipulate or rewrite expressions
involving elements of L. Simply proceed as if the elements were subsets and the
manipulations werethosethat arise in set theory. Wecall such a lattice an algebra,
because we use properties 1 through 14 just as the properties of real numbers are
used in high school algebra.
From now on we will denote the Boolean algebra B\ simply as B. Thus B
contains onlythetwoelements 0 and 1. It is a factthatanyof the Boolean algebras
Bn canbe described in terms of B. Thefollowing theorem gives thisdescription.

THEOREM 4 Forany n > 1, Bn is theproduct B xBx x B of B, n factors, where B x B x


•• • x B is given the product partial order.

Proof
By definition, Bn consists of all n-tuples of O's and l's, that is, all w-tuples of
elements from B. Thus, as a set, Bn is equal to B x B x .. • x B (n factors).
Moreover, if x = xxx2 •••xn and y = yxy2 •••yn are two elements of 5„, then we
know that
x < y if and only if xk < yk for all k.
Thus Bn, identified with BxBx-x B (n factors), has the product partial order.

6.4 Exercises

In Exercises 1 through 10, determine whether the poset is a


Boolean algebra. Explain.
1. e 4. e< •

d 1

b< >

c *1

a< >

Figure 6.65
Fi gure 6.66

Figure 6.63
Figure 6.64
6.4 Finite Boolean Algebras 249

21. Show that in a Boolean algebra, for any a, b, and c, if


a <b, then

0 v (& A c) = b A (a v c).

22. Explain the connection between Examples 7 and 8.


For Exercises 23 through 26, let A = {a,b,c, d, e, /, g, h]
and R be the relation defined by

1 1 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 0 1 1 0 0 0 0
Figure 6.67 0 0 0 1 0 0 0 0
MR =
1 1 1 1 1 1 1 1
7. b
0 1 0 1 0 1 0 1
0 0 1 1 0 0 1 1
0 0 0 1 0 0 0 1

23. Show that (A, R) is a poset.


24. Does the poset (A, R) have a least element? a greatest
element? If so, identify them.
25, Show that the poset (A, R) is complemented and give all
Figure 6.69 Figure 6.70 pairs of complements.
9. D385 10. D60 26 Prove or disprove that (A, R) is a Boolean algebra.
11. Are there any Boolean algebras having three elements? 27. Let A = {a, b, c, d, e, /, g, h] and R be the relation
Why or why not? defined by
12. Show that in a Boolean algebra, for any a and b9 a < b if 111111
and only if b' < a!. 0 10 0 11
13. Show that in a Boolean algebra, for any a and b,a = bif 0 0 10 11
and only if (a A b') v {a' A b) = 0. 0 0 0 10 1
MR
14. Show that in a Boolean algebra, for any a, b, and c, if 0 0 0 0 11

a < b, then a v c <bvc. 0 0 0 0 0 10


0 0 0 0 0 0 1
15. Show that in a Boolean algebra, for any a, b, and c, if
0 0 0 0 0 0 0
a <b, then a Ac <b Ac.
16. Show that in a Boolean algebra the following statements Prove or disprove that (A, R) is a Boolean algebra.
are equivalent for any a and b. 28. Let A be the set of 2 x 2 Boolean matrices with M R N if
(a) avb = b (b) a Ab = a and only if m// < ntJ, 1 < i < 2, 1 < j < 2. Prove that
(c) a'vb = I (&) aAb' = 0 (A, R) is a Boolean algebra.
(e) a < b 29. An atom of a Boolean algebra, B7 is a nonzero element a
such that there is no x in B with 0 < x < a.
17. Show that in a Boolean algebra, for any a and &,
(a) Identify the atoms of the Boolean algebra in Figure
(flAft)V(flA b') = a. 6.60(a).
(b) Identify the atoms of D30.
18. Show that in a Boolean algebra, for any a and &,
30. How many atoms does Bn have?
bA(av(a' A(bv b'))) = b. 31. Give the atoms of (A, R) as defined in Exercise 28.

19. Show that in a Boolean algebra, for any a, b, and c, 32. Like physical atoms, the atoms of a Boolean algebra serve
as building blocks for the elements of the Boolean alge
(flA&Ac)V(lJAc)=/?AC. bra. Write each nonzero element of the given Boolean
algebra as the join of distinct atoms.
20. Show that in a Boolean algebra, for any a, b, and c,
(a) £3 (b) D42
((a v c) a (*>' v c))f = (a' v b) A c'. (c) (A, R) in Exercise 28
250 Chapter 6 Order Relations and Structures

6.5 Functions on Boolean Algebras


Tables listing the values of a function / for all elements of Btl, such as shown in
Figure 6.71(a), are often called truth tables for /. This is because they are analo
gous to tables that arise in logic (see Section 2.1). Suppose that the xk represent
propositions, and f(x\, x2i..., xn) represents a compound sentence constructed
from the x*'s. If we think of the value 0 for a sentence as meaning that the sen
tence is false, and 1 as meaning that the sentence is true, then tables such as Figure
6.71(a) show us how truth or falsity of f{x\> x2,..., xn) depends on the truth or
falsity of its component sentences xk. Thus such tables are called truth tables,
even when they arise in areas other than logic, such as in Boolean algebras.

*1 x2 *3 /(*,, x2, x3)


0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0 /(*„ *2, x3)
1 0 0 I
1 0 1 0
1 1 0 1
1 1 1 0

(a) (b)

Figure 6.71

The reason that such functions are important is that, as shown schematically
in Figure 6.71(b), they may be used to represent the output requirements of a cir
cuit for all possible input values. Thus each jc,- represents an input circuit capable
of carrying two indicator voltages (one voltage for 0 and a different voltage for
1). The function / represents the desired output response in all cases. Such re
quirements occur at the design stage of all combinational and sequential computer
circuitry.
Note carefully that the specification of a function f:Bn -> B simply lists
circuit requirements. It gives no indication of how these requirements can be met.
One important way of producing functions from Bn to B is by using Boolean
polynomials, which we now consider.

Boolean Polynomials
Let x\, x2,..., xn be a set of n symbols or variables. A Boolean polynomial
p(x\, *2,..., xn) in the variables jc* is defined recursively as follows:
1. x\, JC2,.. •, xn are all Boolean polynomials.
2. The symbols 0 and 1 are Boolean polynomials.
3. If p{x\, x2, • • •»xn) and q{x\, JC2,.. •, xn) are two Boolean polynomials, then
so are

p(x\, x2,..., xn) vq(xux2,..., xn)


and
p(X], *2, • • • , Xn) A q{X\, *2, • • • , Xn).
4. If p(x\, JC2,..., xn) is a Boolean polynomial, then so is
(p(xux2, ...,*„))'.
By tradition, (0)' is denoted 0;, (1)' is denoted T, and (**)' is denotedx'k.
6.5 Functions on Boolean Algebras 251

5. There are no Boolean polynomials in the variables Xk other than those that can
be obtained by repeated use of rules 1, 2, 3, and 4.
Boolean polynomials are also called Boolean expressions.

Example 1 The following are Boolean polynomials in the variables jc, y, and z.
P\(x,y,z) = (x V y) az
P2(x,y,z) = (xVyf)v(yAl)
Mx> y> z) = (xv (/ A z)) v(xA(yA 1))
P4(x, y, z) = (xv(yv z')) a ((jc' A z)f a (/ v 0)) ♦

Ordinary polynomials in several variables, such as x2y + z4, xy + yz + x2y2,


x3y3 + jcz4, and so on, are generally interpreted as expressions representing al
gebraic computations with unspecified numbers. As such, they are subject to the
usual rules of arithmetic. Thus the polynomials x2 + 2x + 1 and (jc + 1)(jc + 1)
areconsidered equivalent, and so arex(xy + yz)(x + z) andx3y+ 2x2yz + xyz2,
since in each case we can turn one into the other with algebraic manipulation.
Similarly, Boolean polynomials may be interpreted as representing Boolean
computations with unspecified elements of B, that is, with O's and l's. As such,
these polynomials are subject to the rules of Boolean arithmetic, that is, to the
rules obeyed by A, v, and ' in Boolean algebras. As with ordinary polynomials,
two Boolean polynomials are considered equivalent if we can turn one into the
other with Boolean manipulations.
In Section 5.1 we showed how ordinary polynomials could produce functions
by substitution. This process works whether the polynomials involve one or sev
eralvariables. Thus thepolynomial xy + yz3 produces a function /: E3 ->• R by
letting /(jc, y, z) = xy+yz3. Forexample, /(3,4, 2) = (3)(4) + (4)(23) or44. In
a similar way, Boolean polynomials involving n variables produce functions from
Bn to B. These Boolean functions are a natural generalization of those introduced
in Section 5.2.

Example 2 Consider theBoolean polynomial


p(xUX2, *3> = (*1 A X2) V (X\ V (x'2 A X3)).
Construct the truth table for the Boolean function /: B3 -> B determined by this
Boolean polynomial.

Solution
The Boolean function /: B3 -> B is described by substituting all the 23 ordered
triples of values from B for jci, x2, and JC3. The truth table for the resulting function
is shown in Figure 6.72. ♦

Boolean polynomials can also be written in a graphical or schematic way. If


x and y are variables, then the basic polynomials jc v y, x A y, and xf are shown
schematically in Figure 6.73. Each symbol has lines for the variables on the left
and a line on the right representing the polynomial as a whole. The symbol for
jc v y is called an or gate, that for jc A y is called an and gate, and the symbol for
jc' is called an inverter. The logical names arise because the truth tables showing
the functions represented by jc v y and jc a y are exact analogs of the truth table
for the connectives "or" and "and," respectively.
Recall that functions from Bn to B can be used to describe the desired be
havior of circuits with n 0-or-l inputs and one 0-or-l output. In the case of the
252 Chapter 6 Order Relations and Structures

*\ x2 *3 /(*!, Jfc, x3) = (xx A x2) v (.*:, v (x'2 A x3))


0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1

Figure 6.72

xVy x Ay

(a) (b) (c)

Figure 6.73

functions corresponding to the Boolean polynomials x v y9 x A y, and x'9 the de


sired circuits can be implemented,and the schematic forms of Figure 6.73 are also
used to represent these circuits. By repeatedly using these schematic forms for
v, A, and', we can make a schematic form to represent any Boolean polynomial.
For the reasons given previously, such diagrams are called logic diagrams for the
polynomial.

Example 3 Let
p(x,y,z) = (xAy)V(yAz').
Figure 6.74(a) shows the truth table for the corresponding function /: B3 B.
Figure 6.74(b) shows the logic diagram for p. ♦

X y z fix, y,z) = (xAy)v(yAz')


0 0 0 0
0 0 1 0
0 l 0 1
0 l 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1

(a)

x Ay
r>
(x A y) v (v A z0

[>>^L>^
(b)

Figure 6.74
6.5 Functions on Boolean Algebras 253

Suppose that p is a Boolean polynomial in n variables, and / is the corre


sponding function from Bn to B. We know that / may be viewed as a description
of the behavior of a circuit having n inputs and one output. In the same way, the
logic diagram of p can be viewed as a description of the construction of such a
circuit, at least in terms of and gates, or gates, and inverters. Thus if the func
tion /, describing the desired behavior of a circuit, can be produced by a Boolean
polynomial p, then the logic diagram for p will give one way to construct a cir
cuit having that behavior. In general, many different polynomials will produce the
same function. The logic diagrams of these polynomials will represent alternative
methods for constructing the desired circuit. It is almost impossible to overesti
mate the importance of these facts for the study of computer circuitry. Nearly all
circuit design is done by software packages, but it is important to understand the
basic principles of circuit design outlined in this section and the next.

6.5 Exercises
1. Consider the Boolean polynomial 12, (z v (y a (jc v jc'))) A (y A z')'\ one variable
13, (y A z) V jc' v (w A w'Y v (y a z')\ two variables and two
p(x, v, z) = x A (y v z').
operations
If B = {0, 1}, compute the truth table of the function 14, (jc' Ay' Az' aw)v (x' a z' a w' a y() v (u/ A x' A y A
f:B3-^B defined by p. z') v (w A x' A y A z')\ two variables and three operations
2. Consider the Boolean polynomial 15. Construct a logic diagram implementing the function / of
(a) Exercise 1 (b) Exercise 2.
p(x,y,z) = (xvy) A(zvx').
16. Construct a logic diagram implementing the function / of
If B = {0,1}, compute the truth table of the function (a) Exercise 3 (b) Exercise 4.
/: B3 -» B defined by p.
17. Construct a logic diagram implementing the function /
3. Consider the Boolean polynomial for

p(x, y, z) = (xa y') V (v A (*' V y)). (a) f(x9 y, z) = (xv (y' a z)) v (x a (y a 1)).
(b) /(jc, y, z) = (x V (y v z0) A ((xf A z)' A (/ v 0)).
If B = {0, 1}, compute the truth table of the function
18. Give the Boolean function described by the logic diagram
f:B3^B defined by p.
in Figure 6.75.
4. Consider the Boolean polynomial

p(x, v, z) = (x A y) V (*' A (v A z'))- ?oo°


If B = {0,1}, compute the truth table of the function
f.B3^B defined by p.
In Exercises 5 through 10, apply the rules of Boolean arith

metic to show that the given Boolean polynomials are equiva Figure 6.75
lent.
19. Give the Boolean function described by the logic diagram
5. (xvy) A(x'vy);y
in Figure 6.76.
6. xA(vV(/A(y V/)));*
7. (z' vx)A ((jc a y) vz) a (zf v y);x Ay
8. [(x A z) V (y' V z)'] V [(y A z) V (* A z')l; X V y
9. (x' v y)' V z v (x A ((y A z) V (/ A z')))\ (x a/)Vz :D—1>>-
10. (xAz)V (y' V (y' A z)) V ((jc A y') A z')\ (x A z) V y'
In Exercises 11 through 14, rewrite the given Boolean polyno Figure 6.76
mial to obtain the requestedformat.
20. Give the Boolean function described by the logic diagram
11. (x A y' A z) V (jca y A z); two variables and one operation in Figure 6.77.
254 Chapter 6 Order Relations and Structures

o-^^-^> ^>
> O
D-^J
Figure 6.77

21. Use the properties of a Boolean algebra to refine the func and operations. Draw the logic diagram for the new func
tion in Exercise 18 to use the minimal number of variables tion.
and operations. Draw the logic diagram for the new func 23. Use the properties of a Boolean algebra to refine the func
tion.
tion in Exercise 20 to use the minimal number of variables
22. Use the properties of a Boolean algebra to refine the func and operations. Draw the logic diagram for the new func
tion in Exercise 19 to use the minimal number of variables tion.

6.6 Circuit Design


In Section6.5 we considered functions from Bn to B, where B is the Boolean alge
bra {0, 1}. We noted that such functions can represent input-output requirements
for models of many practical computer circuits. We also pointed out that if the
function is given by some Boolean expression, then we can construct a logic dia
gram for it and thus model the implementation of the function. In this section we
show that all functions from Bn to B are given by Boolean expressions, and thus
logic diagrams can be constructed for any such function. Our discussion illustrates
a method for finding a Boolean expression that produces a given function.
If /: Bn -* B, we will let S(f) = {b e Bn \ f(b) = 1}. We then have the
following result.

THEOREM 1 Let /, f\, and f2 be threefunctions from Bn to B.


(a) If S(f) = S(/i) U S(/2), then f{b) = f{ (b) v f2(b) for all b in B.
(b) If S(f) = S(fx) H S(f2), then f(b) = f{(b) A f2(b) for all b in B.
(v and A are LUB and GLB, respectively, in B.)

Proof
(a) Let b e Bn. If b e S(f), then, by the definition of S(f)9 f(b) = 1. Since
S(f) = 5(/i) U S(f2)9 either b e S(f{) or b e S(f2)9 or both. In any
case, f{(b) v f2(b) = 1. Now, if b i S(f), then f(b) = 0. This means
that fx (b) v f2(b) = 0. Thus, for all b e Bn, f(b) = /, (b) v f2(b).
(b) This part is proved in a manner completely analogous to that used in part
(a). •
6.6 Circuit Design 255

Recall that a function /: Bn -• B can be viewed as a function f{x\, x2j...,


jc„)of rc variables, each of which may assume the values 0 or 1. If E(x\, x2i..., xn)
is a Boolean expression, then the function that it produces is generated by substi
tuting all combinations of O's and l's for the jc/'s in the expression.

Example 1 Let /i: B2 -> B beproduced bytheexpression E(x9 y) = x'9 andlet f2: B2 -> B
be produced by the expression E(x9 y) = /. Then the truth tables of /i and f2 are
shown in Figures 6.78(a) and (b), respectively. Let f:B2-> B be the function
whose truth table is shown in Figure 6.78(c). Clearly, S(f) = S(f\) U S(f2)9 since
fx is 1 at the elements (0,0) and (0,1) of B29 f2 is 1 at the elements (0, 0) and
(1,0) of Bl9 and / is 1 at the elements (0,0), (0, 1), and (1, 0) of B2. By Theorem
1, / = /i v f2, so a Boolean expression that produces / is xf v yf. This is easily
verified. ♦

X y Mx,y) X y Mx,y) X y fix, y)

0 0 1 0 0 1 0 0 l
0 i 1 0 l 0 0 l l
1 0 0 1 0 1 1 0 l
1 i 0 1 i 0 1 1 0

(a) (b) (c)

Figure 6.78

It is not hard to show that any function /: Bn -> B for which S(f) has
exactly one element is produced by a Boolean expression. Table 6.1 shows the
correspondence between functions of two variables that are 1 at just one element
and the Boolean expression that produces these functions.

4SHBB
S(/> Expression Producing /

{(0,0)} x' Ay'


m m x' Ay
{(1.0)} x Ay'
1(1, i)} xAy

Example 2 Let f:B2->Bbe thefunction whose truthtableis shown in Figure 6.79(a). This
function is equal to 1 only at the element (0,1) of B2\ that is, S(f) = {(0,1)}.
Thus f(x9 y) = 1 only when x = 0 and y = 1. This is also true for the expression
E(x9 y) = xf A y9 so / is produced by this expression.
The function /: #3 -> B whose truth table is shown in Figure 6.79(b) has
S(f) = {(0, 1,1)}; that is, / equals 1 only when x = 0, y = 1, and z = 1. This is
also true for the Boolean expression x' Ay Az, which must therefore produce /.

If b e Bn9 then b is a sequence (c\9 c29..., cn) of length n9 where each c*


is 0 or 1. Let E^ be the Boolean expression x\ A x2 A • • • A xn9 where x~k = •**
when Ck = 1 and jc* = xfk when c* = 0. Such an expression is called a minterm.
Example 2 illustrates the fact that any function /: Bn -> B for which S(f) is a
single element of Bn is produced by a minterm expression. In fact, if S(f) = {b}9
it is easily seen that the minterm expression Eb produces /. We then have the
following result.
256 Chapter 6 Order Relations and Structures

X y z fix, y, z)

0 0 0 0
X
y /(*, y)
0 0 1 0
0 0 0 0 l 0 0
0 i i 0 i 1 1
1 0 0 1 0 0 0
1 i 0 1 0 1 0
1 1 0 0
1 1 1 0

(a) (b)

Figure 6.79

THEOREM 2 Any function /: Bn -» B is produced by a Boolean expression.


Proof
Let S(f) = [bi, b2,..., bk), and for each /, let fi: B„ ->• B be the function
defined by

Mb,) = 1
f,(b) = 0, if b^bh

Then S(f,) = [b,}, so S(f) = S(/,) U •• • U S(f„) and by Theorem 1,


f = fi v/2v...v/„.

By the precedingdiscussion,each /} is produced by the minterm Eb.. Thus /


is produced by the Boolean expression

Ebx v Ehl v ••• v Ebn


and this completes the proof. •

Example 3 Consider the function /: fl3 -• fl whose truth table is shown in Figure 6.80.
Since S(f) = {(0, 1,1), (1, 1, 1)}, Theorem 2 shows that / is produced by the
Boolean expression E(x9 y, z) = £(o,i,i) v £(i,i,i) = (xf A y a z) v (jc a y A z).
JC z fix, y, z)
This expression, however, is not the simplest Boolean expression that produces /.
y
Using properties of Boolean algebras, we have
0 0 0 0
0 0 1 0 (*' A y Az) V (x Ay Az) = (x' Vjc) A (y Az) = 1 A (y A z) = y Az.
0 l 0 0
0 l 1 1 Thus / is also produced by the simple expression y A z. ♦
1 0 0 0
1 0 1 0 The process of writing a function as an "or" combination of minterms and
1 i 0 0 simplifying the resulting expression can be systematized in various ways. We will
1 i 1 1 demonstrate a graphical procedure utilizing what is known as a Karnaugh map.
This procedure is easy for human beings to use with functions /: Bn -> B, if n
Figure 6.80 is not too large. We will illustrate the method for n = 2, 3, and 4. If n is large or
if a programmable algorithm is desired, other techniques may be preferable. The
Exercises explore a nongraphical method.
We consider first the case where n = 2 so that / is a function of two variables,
say x and y. In Figure 6.81(a), we show a 2 x 2 matrix of squares with each square
containing one possible input b from B2. In Figure 6.81(b), we have replaced each
input b with the correspondingminterm Eb. The labeling of the squares in Figure
6.6 Circuit Design 257

6.81 is for reference only. In the future we will not exhibit these labels, but we
will assume that the reader remembers their locations. In Figure 6.81(b), we note
that x' appears everywhere in the first row and x appears everywhere in the second
row. We label these rows accordingly, and we perform a similar labeling of the
columns.

y y

00 01 xf fA/ xfAy

10 11 X jca/ x Ay

(a) (b)

Figure 6.81

Example 4 Let f:B2^Bb& the function whose truth table is shown in Figure 6.82(a). In
Figure 6.82(b), we have arranged the values of / in the appropriate squares, and
we have kept the row and column labels. The resulting 2x2 array of O's and l's is
called the Karnaugh map of /. Since S(f) = {(0, 0), (0, 1)}, the corresponding
expression for / is (xf A yf) v (x' A y) = x1 A (/ vj) = xr. ♦

X y /(*. y)

0 0 l

0 l i
l 1
1 0 0
1 i 0 0 0

Truth table of/ Karnaugh map of/


(a) (b)

Figure 6.82

The outcome of Example 4 is typical. When the 1-values of a function


f:B2-+B exactly fill one row or one column, the label of that row or column
gives the Boolean expression for /. Of course, we already know that if the 1-
values of / fill just one square, then / is produced by the corresponding minterm.
It can be shown that the larger the rectangle of 1-values of /, the smaller the ex
pression for / will be. Finally, if the 1-values of / do not lie in a rectangle, we
can decompose these values into the union of (possibly overlapping) rectangles.
Then, by Theorem 1, the Boolean expression for / can be found by computing the
expressions corresponding to each rectangle and combining them with v.

Example 5 Consider the function f:B2^>B whose truth table is shown in Figure 6.83(a).
In Figure 6.83(b), we show the Karnaugh map of / and decompose the 1-values

X y fix, y) y y y y

0
0
0
l
l

l
x' 1 l x' l

1 0 l
X 1 0 X l 0
1 i 0

(a) (b) (c)

Figure 6.83
258 Chapter 6 Order Relations and Structures

into the two indicatedrectangles. The expression for the function having 1's in the
horizontal rectangle is x' (verify). The function having all its l's in the vertical
rectangle corresponds to the expression yf (verify). Thus / corresponds to the
expression x' v /. In Figure 6.83(c), we show a different decomposition of the
1-values of / into rectangles. This decomposition is also correct, but it leads
to the more complex expression / v (xf Ay). We see that the decomposition
into rectangles is not unique and that we should try to use the largest possible
rectangles. ♦

We now turn to the case of a function /: B3 -> B9 which we consider to


be a function of x9 y9 and z. We could proceed as in the case of two variables
and construct a cube of side 2 to contain the values of /. This would work, but
three-dimensional figures are awkward to draw and use, and the idea would not
generalize. Instead, we use a rectangle of size 2 x 4. In Figures 6.84(a) and (b),
respectively, we show the inputs (from #3) and corresponding minterms for each
square of such a rectangle.

0 0 0 1 1 1 1 0

0 0 0 0 0 0 1 0 1 1 0 1 0

1 1 0 0 1 0 1 1 1 1 1 1 0

(a)

X1 x' Ay' Az' x' Ay' Az x' Ay Az x' Ay Az'

X XAy' Az' x Ay' Az x Ay Az x Ay Az'

z
y

(b)

Figure 6.84

Consider the rectangular areas shown in Figure 6.85. If the 1-values for a
function f:B$-^B exactly fill one of the rectangles shown, then the Boolean
expression for this function is one of the six expressions jc, y9 z, x'9 y'9 or z\ as
indicated in Figure 6.85.
Consider the situation shown in Figure 6.85(a). Theorem 1(a) shows that /
can be computed by joining all the minterms corresponding to squares of the region
with the symbol v. Thus / is produced by

(jc' A/A Zf) V (xf A / A z) V (JC A / A z') V (JC A / A z)


= ((JC' V JC) A (/ A Z')) V ((*' V JC) A (/ A Z))
= (1a(/az'))V(1a(/Az))
= (/ A z') V (/ A Z)
= / a (zf v z) = y' A 1 = /.

A similar computation shows that the other five regions are correctly labeled.
If we think of the left and right edges of our basic rectangle as glued together
to make a cylinder, as we show in Figure 6.86, we can say that the six large regions
6.6 Circuit Design 259

y az'
Shaded region isy' Shaded region isy
y az' y'Az
(a) (b)

W&M
"T- *
' -4 IP111
lllllil
Shaded region is z Shaded region is z'
(c) id)

.'•yify
MM \fy'4& ;t\:*\
j

Shaded region is x' Shaded region is jc


y az
(e) (f)

Figure 6.85 Figure 6.86

shown in Figure 6.85 consist of any two adjacent columns of the cylinder, or of
the top or bottom half-cylinder.
The six basic regions shown in Figure 6.85 are the only ones whose corre
sponding Boolean expressions need be considered. That is why we used them
to label Figure 6.84(b), and we keep them as labels for all Karnaugh maps of
functions from B3 to B. Theorem 1(b) tells us that, if the 1-values of a function
f:B3->B form exactly the intersection of two or three of the basic six regions,
then a Boolean expression for / can be computed by combining the expressions
for these basic regions with A symbols.
Thus, if the 1-values of the function / are as shown in Figure 6.87(a), then
we get them by intersecting the regions shown in Figures 6.85(a) and (d). The
Boolean expression for / is therefore / A z'. Similar derivations can be given
for the other three columns. If the 1-values of / are as shown in Figure 6.87(b),
we get them by intersecting the regions of Figures 6.85(c) and (e), so a Boolean
expression for / is z A x'. In a similar fashion, we can compute the expression
for any function whose 1-values fill two horizontally adjacent squares. There are
eight such functions if we again consider the rectangle to be formed into a cylinder.
Thus we include the case where the 1-values of / are as shown in Figure 6.87(c).
The resulting Boolean expression is z! a x'.
If we intersect three of the basic regions and the intersection is not empty,
the intersection must be a single square, and the resulting Boolean expression
is a minterm. In Figure 6.87(d), the 1-values of / form the intersection of the
three regions shown in Figures 6.85(a), (c), and (f). The corresponding minterm is
y' Az Ax. Thus we need not remember the placement of minterms in Figure
6.84(b), but instead may reconstruct it.
We have seen how to compute a Boolean expression for any function
f:B3-^B whose 1-values form a rectangle of adjacent squares (in the cylin
der) of size 2n x 2m, n = 0, 1; m = 0, 1, 2. In general, if the set of 1-values of
/ do not form such a rectangle, we may write this set as the union of such rectan
gles. Then a Boolean expression for / is computed by combining the expression
associated with each rectangle with v symbols. This is true by Theorem 1(a).
260 Chapter 6 Order Relations and Structures

The preceding discussion shows that the larger the rectangles that are chosen, the
simpler will be the resulting Boolean expression.

x1 1 0 0 0 xf 0
81 0

1 0 0 0 X 0 0 0 0

z! •
(a) (b)

y y y y

iw^ti
xf 0 0
s§ xf 0 0 0 0

0 0 0 0 0
8 0 0

z z

zf - — z'
(c) (d)

Figure 6.87

Example 6 Consider the function / whose truth table and corresponding Karnaugh map are
shown in Figure 6.88. The placement of the l's can be derived by locating the
corresponding inputs in Figure 6.84(a). One decomposition of the 1-values of /
is shown in Figure 6.88(b). From this we see that a Boolean expression for / is
(/Az') v(jc'A/)v(yAz). ♦

JC y z /(*, y, z)

0 0 0 i
0 0 1 i
1 1 1 0
0 l 0 0
0 l 1 1
1 0 0 1 1 0 1 0

1 0 1 0
1 i 0 0
1 i 1 1

(a) (b)

Figure 6.88

Example 7 Figure 6.89 shows the truth table and corresponding Karnaugh map for a function
/. The decomposition into rectangles shown in Figure 6.89(b) uses the idea that
the first and last columns are considered adjacent (by wrapping around the cylin
der). Thus the symbols are left open ended to signify that they join in one 2x2
rectangle corresponding to z'. The resulting Boolean expression is z! v (jc a y)
(verify). ♦
6.6 Circuit Design 261

X y z /(*, y, z)

0 0 0 l

0 0 1 0
1 0 0 1
0 l 0 1

0 l 1 0
1 0 1 1
1 0 0 1

1 0 1 0
1 1 0 1

1 1 1 1
(b)
(a)

Figure 6.89

Finally, without additional comment, we present in Figure 6.90 the distribu


tion of inputs and corresponding labeling of rectangles for the case of a function
/: B4 -• J5, considered as a function of jc, y9 z, and w. Here again, we consider
the first and last columns to be adjacent, and the first and last rows to be adjacent,
both by wraparound, and we look for rectangles with sides of length some power
of 2, so the length is 1,2, or 4. The expression corresponding to such rectangles is
given by intersecting the large labeled rectangles of Figure 6.91.

00 01 11 10

00 0000 0001 0011 0010 XV' 4


s

01 0100 0101 0111 0110 > >y y

11 1100 1101 1111 1110 x -i

10 1000 1001 1011 1010

w'
(a) (b)

Figure 6.90

Example 8 Figure 6.92 shows the Karnaugh map of a function f:B4->B. The 1-values are
placed by considering the location of inputs in Figure 6.90(a). Thus /(0101) = 1,
/(0001) = 0, and so on.
The center 2x2 square represents the Boolean expression w Ay (verify).
The four corners also form a 2 x 2 square, since the right and left edges and
the top and bottom edges are considered adjacent. From a geometric point of view,
we can see that if we wrap the rectangle around horizontally, getting a cylinder,
then when we further wrap around vertically, we will get a torus or inner tube. On
this inner tube, the four corners form a 2 x 2 square, which represents the Boolean
expression w' A yf (verify).
It then follows that the decomposition leads to the Boolean expression
(w Ay)v (w' A /)
for/.
262 Chapter 6 Order Relations and Structures

( / 4
*.' ,' r.
t

[S1S3 p|l§3
[3'"®il BN^-fi
|~^^Tj
111llll
Shaded region is zf Shaded region is z Shadedregion is xf Shadedregion isx
(a) (b) (c) (d)

Shaded region is y Shaded region is / Shaded region is w Shaded region is w'


(e) (f) (g) (h)

Figure 6.91

1 0 0 1 1 1 1 1

x s

0 1 1 0 0 0 0 0

y y y y
0 1 1 0 0 0 1 0

1 0 0 1 1 1 0 0

w w

Figure 6.92 Figure 6.93

Example 9 In Figure 6.93, we show the Karnaugh map of a function f:B4 -^ B. The
decomposition of 1-values into rectangles of sides 2", shown in this figure, again
uses the wraparound property of top and bottom rows. The resulting expression
for / is (verify)

(z A y') v (xf A / A z) v (jc a y A z A w).

The first term comes from the 2 x 2 square formed by joining the 1 x 2 rectangle
in the upper-left comer and the 1 x 2 rectangle in the lower-left comer. The second
comes from the rectangle of size 1 x 2 in the upper-right comer, and the last is a
minterm corresponding to the isolated square. ♦
6.6 Circuit Design 263

6.6 Exercises
In Exercises 1 through 6, construct Karnaugh maps for the . JC y z w f(x,y,z,w)
functions whose truth tables are given. 0 0 0 0 1

. X fix,y) 0 0 0 1 0
y
0 0 1 0 0 1 0 1

0 i 0 0 0 1 1 0

1 0 0 0 l 0 0 0

1 l 1 0 l 0 1 1

0 i 1 0 1

0 l 1 1 0

0 0 0 0

0 0 1 0

0 1 0 0
2. jc y f(x,y) 0 1 1 0
0 0 1 1 0 0 1
0 i 0 1 0 1 0

1 0 1 1 1 0 1

1 1 0 1 1 1 0

JC y z w f(x9y,z,w)
0 0 0 0 0
0 0 0 1 0

0 0 1 0 1

JC y z f(x,y,z) 0 0 1 1 0
0 0 0 1 0 1 0 0 0

0 0 1 1 0 1 0 1 0
0 i 0 0 0 1 1 0 1

0 i 1 0 0 1 1 1 0

1 0 0 1 0 0 0 0
1 0 1 0 0 0 1 0
1 1 0 1 0 1 0 0
1 1 1 0 0 1 1 1

1 0 0 0
1 0 1 0

1 1 0 1

1 1 1 1

X z f(x,y,z) 7. Construct a Karnaugh map for the function / for which


y
Sif) = {(0,0,1), (0,1,1), (1,0,1), (1,1,1)}.
0 0 0 0

0 0 1 1 8. Construct a Karnaugh map for the function / for which


0 l 0 1 Sif) = {(0,0,0, 1), (0, 0, 1, 1), (1, 0, 1,0), (1,1, 0, 1),
1
(0,1,0,0), (1,0, 0,0)}.
0 l 1

1 0 0 0 In Exercises 9 through 16 (Figures 6.94 through 6.101), Kar


1 0 1 0 naugh maps offunctions are given, and a decomposition of
l-values into rectangles is shown. Write the Boolean expres
1 1 0 0
sion for thesefunctions, which arise from the maps and rect
1 1 1 1
angular decompositions.
264 Chapter 6 Order Relations and Structures

9. , 10. 14.
y y y y

1 0
1 1
1 1 1 1

0 1
1 0
0 0 1 0

Figure 6.94 Figure 6.95

Figure 6.99
11.
15.

1 1 1 1
0 0 1 1

1 0 0 1 0 0 1 1

}y y
1 0 0 1

x <

0 1 1 0
Figure 6.96

w'

12.
Figure 6.100
16.
x' 1 1 0 1

X 0 1 0 11 1 1 0 1

1 1 0 1

>y y

0 0 0 0

Figure 6.97
1 0 0 1

w
13.
w'

Figure 6.101
0 1 0 1
In Exercises 17 through 24, use the Karnaugh map method to
find a Boolean expression for the function f.
1 1 0 1
17. Let / be the function of Exercise 1.
18. Let / be the function of Exercise 2.
19. Let / be the function of Exercise 3.
20. Let / be the function of Exercise 4.
Figure 6.98 21. Let / be the function of Exercise 5.
Key Ideas for Review 265

22. Let / be the function of Exercise 6. (a) Give the reduced minterms for
23. Let / be the function of Exercise 7. SCO = {(0,0), (0,1), d,0)}.

24. Let / be the function of Exercise 8. (b) Verify that / is produced by the join of the reduced
minterms in part (a).
Thefollowing exercises develop another way to produce an ex
pressionfor a Boolean function. For Exercises 25 and 26, let The process in Exercise 26 can be repeated. For Ex
f:B2->B with Sif) = {(0, 0), (0, 1), (1, 0)}. ercises 27 through 29, let f: B3 -^ B with Sif) =
{(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1)}.
25. (a) Give the corresponding minterm for each element of
S{f). 27. Give the reduced minterms for each pair of elements in
(b) If two elements su s2 of Sif) differ in exactly one Sif) that differ in exactly one position.
position, the variable jc, in that position is not needed 28. Using the reduced minterms produced for Exercise 27,
in the join of the minterms corresponding to s\ and again replace each pair of reduced minterms that differ
s2. Explain why. in exactly one position.
26. For each pair in Sif) that differ in exactly one position, 29. (a) Form the join of the expressions represented by the
form a reduced minterm as follows. Suppose the corre reduced minterms of Exercise 28 and any (reduced)
sponding minterms a\ Aa2 A • • •Aan and b\ Ab2A • ••Abn minterms that have not been replaced.
differ only at position /. Replace this pair with the reduced
minterm a\ a a2 a • • • a at-\ A ai+\ A • • • A an9 where x-t (b) Verify that the expression formed in part (a) pro
does not appear. duces /.

Tips for Proofs


Statements of the form Vx P(x) or ~(3jc Q(x)) are candidates for proof by con
tradiction, since it is natural to explore what would happen if there were an object
that did not have property P or if there were an object with property Q. This situa
tion is seen in Theorem 2, Section 6.1. Statements about finite sets also often lend
themselves to indirect proofs, as seen in Theorem 1, Section 6.2.
Many examples and exercises in this chapter ask that you check whether a
specified lattice is a Boolean algebra or not. Remember that this is the same as
proving that the lattice is a Boolean algebra. The fact that the number of elements
is a power of 2 is a necessary condition,but not a sufficientcondition. This means
that if the number of elements is not a power of 2, the lattice is not a Boolean
algebra, but there are lattices with 2n elements that are not Boolean algebras. The
check on a divisibility lattice Dn is an easy one and worth memorizing. If the
Hasse diagram is "small," then comparing it with those of the Bn is an efficient
way to carry out the check. Attempting to construct an isomorphism between the
given lattice and a known Boolean algebra is the next most efficientmethod. As a
last resort, try to verify that the properties of a Boolean algebra are satisfied by the
lattice. But be sensible about this. Try the "single" cases first—there is a unique
least element 0; there is a unique greatest element /; C = /; and so on—not those
that require working through lots of cases, such as the associative property for A.

• Key Ideas for Review


• Partial order on a set: relation that is reflexive, antisymmet • Hasse diagram: see page 222
ric, and transitive • Topological sorting: see page 223
• Partially ordered set or poset: set together with a partial or • Isomorphism of posets: see page 224
der
• Maximal (minimal) element of a poset: see page 228
• Linearly ordered set: partially ordered set in which every
pair of elements is comparable • Theorem: A finite nonempty poset has at least one maximal
element and at least one minimal element.
• Theorem: If A and B are posets, then A x B is a poset with
the product partial order. • Greatest (least) element of a poset A: see page 229
• Dual of a poset (A, <): the poset (A, >), where > denotes • Theorem: A poset has at most one greatest element and at
the inverse of < most one least element.
266 Chapter 6 Order Relations and Structures

Upper (lower) bound of subset B of poset A: element a e A (a) a v c < b v d


such that b <aia <b) for all b e B (b) a Ac <b Ad
Least upper bound (greatest lower bound) of subset B of Isomorphic lattices: see page 236
poset A: element a £ A such that a is an upper (lower) Bounded lattices: lattice that has a greatest element / and a
bound of B and a < a' ia' < a)9 where a' is any upper least element 0
(lower) bound of B
Theorem: A finite lattice is bounded.
Lattice: a poset in which every subset consisting of two el
Distributive lattice: lattice that satisfies the distributive
ements has a LUB and a GLB
laws:
Theorem: If Lx and L2 are lattices, then L = Lx x L2 is a
lattice. a A ib V c) = ia A b) V ia A c),
Theorem: Let L be a lattice, and a9b e L. Then a V ib A c) = ia v b) A ia V c).
(a) a v b = b if and only ifa<b.
ib) a Ab = aif and only if a < b. Complement of a: element a! e L (bounded lattice) such
(c) a Ab = aii and only if a v b = b. that

Theorem: Let L be a lattice. Then


a v d = / and a A d — 0.
1. (a)aVfl=a Theorem: Let L be a bounded distributive lattice. If a com
(b) a Aa = a plement exists, it is unique.
2. (a) <z V £ = b v <2 Complemented lattice: bounded lattice in which every ele
(b) a Ab = b Aa ment has a complement
3. (a)flV(i?vc) = (flV^)vc Boolean algebra: a lattice isomorphic with (P(5), C) for
(b) a A ib A c) = ia A b) A c some finite set S
4. ia) av ia Ab)=a
Properties of a Boolean algebra: see page 247
ib) aAiaV b) =a
Truth tables: see page 250
Theorem: Let L be a lattice, and a,b9c e L.
1. If a <6, then Boolean expression: see page 251
(a) a V c < b v c Minterm: a Boolean expression of the form 3c iA3c2 a- • -A3cn,
(b) AAc<kc where each jc* is either x/c or x'k
2. a < c and Z? < c if and only ifavb<c Theorem: Any function f:Bn -*> B is produced by a
3. c <a and c < b if and only if c < a A b Boolean expression.
4. If a < Z? and c <d9 then Karnaugh map: see page 257

• Chapter 6 Self-Test
1. Upon what common relation is the concept of partial or
der based?

2. How does a partial order differ from a lattice?


3. What is a model for any Boolean algebra?
4. What kind of mathematical object is the Karnaughmap of Figure 6.102 Figure 6.103
a function and how is it used?
8. Let (A, <) be the poset whose Hasse diagram is given in
5. What is the relationship between Boolean functions and Figure 6.103.
Boolean expressions? (a) Find all minimal and maximal elements of A.
6. Determine whether the given relation is a partial order. (b) Find the least and greatest elements of A.
Explain your answer. 9. Let A = {2, 3,4, 6, 8,12, 24,48} and < denote the partial
(a) A is any set; a R b if and only if a = b. order of divisibility; B = {4, 6, 12}. Find, if they exist,
(b) A is the set of parallel fines in the plane; UR l2 if and (a) all upper bounds of B
only ifli coincides with l2 or lx is parallel to l2. (b) all lower bounds of B
(c) the least upper bound of B
7. Given the Hasse diagram in Figure 6.102, (d) the greatest lower bound of B.
(a) Draw the digraph of the partial order R defined; 10. Show that a linearly ordered poset is a distributive lattice.
(b) Draw the Hasse diagram of the partial order R~l. 11. Find the complement of each element in DI05.
Experiment 6 267

12. Let A = {a, b9 c, d] and R be a relation on A whose ma 16. (a) Write the Boolean expression represented by the
trix is logic diagram in Figure 6.105.
10 11
(b) Use the rules of Boolean arithmetic to find an expres
0 111
M.= sion using fewer operations that is equivalent to the
0 0 11
expression found in part (a).
.0001
(a) Prove that R is a partial order. (c) Draw a logic diagram for the expression found in
part (b).
(b) Draw the Hasse diagram of R.
13. Let L be a lattice. Prove that for every a, b9 and c in L, if
a < b and c <d9 then av c <bv d and a Ac <b Ad.
Consider the Hasse diagrams given in Figure 6.104.
35^>-^
14.
(a) Which of these posets are not lattices? Explain.

(b) Which of these posets are not Boolean algebras? Ex
plain. Figure 6.105
17. Use the Karnaugh map method to find a Boolean expres
d sion for the function / whose truth table is as follows.
X y z fix, y, z)
V a
0 0 0 0

0 0 1 0

Figure 6.104 0 l 0 1

0 l 1 0
15. Let (D63, <) be the lattice of all positive divisors of 63
and x < y means x \ y. 1 0 0 1

(a) Draw the Hasse diagram of the lattice. 1 0 1 1

(b) Prove or disprove the statement: (£>63, —) ls a 1 1 0 1


Boolean algebra. 1 1 1 0

I Experiment 6
Many real-life and computer processes can be modeled by a partial order that
shows the necessary sequence of actions to complete the process. Section 6.1
contains a brief description of how to convert such a partial order into a linear
order that could be followed by a person or a computer program. In many cases,
a strict linear order is not necessary, for example, if several actions can take place
concurrently. In this experimentyou will learn the basic ideas of another modeling
technique for concurrent actions.
Part I. To obtain a degree in computer science at Ole U, the following courses
are required: ComputerScience I, Computer Science II, Discrete Mathe
matics, Data Structures, Compiler Design, Algorithm Analysis, Assem
bly Architecture, Formal Languages, Operating Systems, and Complex
ity Theory. Computer Science II has Computer Science I and Discrete
Mathematics as prerequisites. Computer Science II is a prerequisite for
Data Structures, Assembly Architecture, and Formal Languages. Data
Structures is a prerequisite for Algorithm Analysis and for Operating
Systems. Algorithm Analysis is a prerequisite for Complexity Theory;
Compiler Design requires both Assembly Architecture and Formal Lan
guages.

1. Give a Hasse diagram that shows the prerequisite relationships


among these courses.
268 Chapter 6 Order Relations and Structures

2. Suppose you were able to take only one course each term. Give a
topological sorting of the partial order in Question 1.
Part II. Progressing through the required courses in a linear fashion is not neces
sary and certainly not optimal in terms of how long it will take to obtain
your degree. Here we present a different type of digraph to model con
ditions (prerequisites) and possibly concurrent actions.
A Petri net is a digraph whose set of vertices can be partitioned into
P9 the set of places (or conditions), and T9 the set of transitions (or
actions), along with a function / that associates a nonnegative number
with each element of P. Any edge in the digraph is between an element
of P and an element of T. That is, the digraph represents a relation R9
where R = IU09lcpxT9O^TxP. Usually the elements
of P are denoted by circles and those of T by vertical bars. As a way
to indicate that a condition p\ e P is satisfied, one or more dots, called
Figure 1 tokens, are marked inside the circle for /?,. Allowing more than one
token at a place permits Petri nets to model a broad range of situations.
The function / is defined by /(/?,•) is the number of tokens at /?,-; hence,
/ is sometimes called a marking of the Petri net.
Pa
1. For the Petri net depicted by Figure 1, give P9T9 R9 and /.
•o 2. For the Petri net depicted by Figure 2, give P9T9 R9 and /.
Completing the action represented by t e T is called firing the
Pi P5 '3
transition. A transition can be fired only when the conditions for that
action are met. Formally, a transition t can be fired only when every
Figure 2 Pi such that (p/, t) e I contains at least one token. When this is true,
we say that / is enabled. Firing a transition t creates a new Petri net in
which a token is removed from each /?, such that (/?/, t) e I and a token
is placed in eachpj such that (r, pj) e O. In Figure 1, firing t produces
the net in Figure3. Only t2 is enabled in Figure 2. The result of firing t2
is shown in Figure 4. If several transitions are enabled, then any one of
them may fire at any time. This models the sometimes random nature of
Figure 3 choices for concurrent actions.

1. Create a Petri net to represent the course prerequisite situation of


Part I. Identify the set of places and the set of transitions. Based
on your academic record, mark the net appropriately. Which transi
tions are enabled in this digraph?
^ <•>
2. (a) Give the new marking function for the net represented by Fig
ure 3.
(b) Give the new marking function for the net represented by Fig

Pi i -.
P5
ure 4.

Part III. Our simple example of course prerequisites lacks a common feature of
Figure 4
concurrent processes, repeatability. Consider the following Petri net, N9
shown in Figure 5.

Figure 5
Experiment 6 269

We see here that each transition in T can be enabled and fired re


peatedly. A marking of a Petri net is live if every transition can be fired
by some sequence of transition firings. Not every marking is live. In the
net shown in Figure 6, once t\ or t2 is fired, either f3 or f4 is enabled (but
not both). After that transition is fired, no further action is possible.

Figure 6
If no transitions can be fired, we say there is a deadlock.
1. Is it possible to mark Figure 5 using some tokens so that deadlock
occurs? If so, draw this marked Petri net. If not, explain why.
2. Is it possible to mark Figure 6 using some tokens so a deadlock
never occurs? If so, draw this marked Petri net. If not, explain why.
Part IV. Figure 7 gives a model of a simple computer network where two workers
share a high-speed Internet connection and a database. Only one user of
a resource is allowed at a time, but both resources are needed for some
tasks the workers perform.

B releases Internet Internet A releases Internet


available

done

B releases A releases
database database

Figure 7

Give a sequence of transition firings that returns the net to its origi
nal marking. Explain in words what the workers have done.
Give a sequence of transition firings that produces deadlock in this
net. Explain in words what the workers have done.
If they were in the same room, the workers might choose to commu
nicate to avoid deadlock, but this is not always possible. Redesign
the Petri net in Figure 7 so that deadlock cannot occur. Consider us
ing conditions such as p: The system is available; q: A is in control
of the system; and r: B is in control of the system. Clearly identify
all conditions and actions.
CHAPTER

7 Trees
Prerequisites: Chapter 4

In this chapter we study a special type of relation that is exceptionally useful in


a variety of biology and computer scienceapplications and is usually represented
by its digraph. These relations are essential for the construction of databases and
language compilers, to namejust two important computer science areas. They are
calledtreesor sometimes rootedtrees,becauseof the appearance of their digraphs.

Looking Bock
Trees were first used in 1847 by the German mathematician The great German composer Johann Sebastian Bach was
Karl Georg Christian von Staudt in his work on projective ge very proud of his long family musical heritage, dating back to
ometry, and in the same year by the German physicist Gustav the late 1500s. In 1735, he prepared a genealogy of his family
Robert Kirchhoff in a paper on electrical networks. However, entitled, Ursprung der musicalisch-Bachischen Familie ("Ori
it is Arthur Cayley (who we met in Chapter 1) who first used gin of the Musical Bach Family"). A small part of this fam
the word tree in a mathematics paper on differential transfor ily is shown in the tree below. During their annual family re
mations. unions they performed together, and on some occasions there
Trees are used in a wide variety of applications, such as were more than 100 family members present.
family trees, organizational charts, sports competitions, biol
ogy, and computer file structures.

Veit

1
Johannes

/ I X
Johann Cristoph Heinrich

/ / / \
Johann Egidius Georg Christoph Johann Christoph Johann Michael

Johann Bernhard Johann Christoph Johann Ambrosius Johann Nikolaus

Johann Ernst Johann Sebastian Johann Christoph

Wilhelm Friedemann CarlPhilippEmanuel Johann Christoph Friedrich

Family tree of Johann Sebastian Bach

270
7.1 Trees 271

7.1 frees

Let A be a set, and let T be a relation on A. We say that T is a tree if there is


a vertex do in A with the property that there exists a unique path in T from do to
every other vertex in A, but no path from Do to v$.
We show below that the vertex Do, described in the definition of a tree, is
unique. It is often called the root of the tree T9 and T is then referred to as a
rooted tree. We write (71, Do) to denote a rooted tree T with root Do.
If (7\ Do) is a rooted tree on the set A, an element d of A will often be referred
to as a vertex in T. This terminology simplifies the discussion, since it often hap
pens that the underlying set A of T is of no importance.
To help us see the nature of trees, we will prove some simple properties satis
fied by trees.

THEOREM 1 Let (7\ d0) be a rooted tree. Then


(a) There are no cycles in T.
(b) vo is the only root of T.
(c) Each vertex in T9 other than vq9 has in-degree one, and vo has in-degree
zero.

Proof
(a) Suppose thatthere is a cycleq in T9 beginning and endingat vertex v. By
definition of a tree, we know that v ^ d0, and there must be a path p from
vo to v. Thenqop (seeSection 4.3) is a path from d0 to v that is different
from p9 and this contradicts the definition of a tree.
(b) If vf0 isanother root of7\ there isa path p from d0 to d^ and a path q from
Vq to vo (since d^ is a root). Then q o /? is a cycle from d0 to d0, and this
is impossible by definition. Hence the vertex v0 is the unique root.
(c) Let wibea vertex in T other than d0. Then there is a unique path
d0, ..., v*, wi from d0 to wi in 7\ This means that (vk, w{) e T9 so
w\ has in-degree at least one. If the in-degree of w\ is more than one,
there must be distinct vertices w2 and w3 such that (w29 w\) and (w3, w\)
are both in T. If w2 ^ vo and u;3 ^ Do, there are paths p2 from v0 to w2
and p3 from d0 to 103, bydefinition. Then (w2, w\)op2 and (^3, wi) op3
are two different paths from v0 to w\9 and this contradicts the definition
of a tree with root d0. Hence,the in-degreeof wi is one. We leave it as an
exercise to complete the proofif w2 = vo or W3 = vo and to show that Do
has in-degree zero. *
Theorem 1 summarizes the geometric properties of a tree. With these proper
ties in mind, we can see how the digraph of a typical tree must look.
Let us first draw the root d0. No edges enter d0, but several may leave, and we
draw these edges downward. The terminal vertices of the edges beginning at d0
will be called the level 1 vertices, while d0 will be said to be at level 0. Also, d0 is
sometimes called the parent of these level 1 vertices, and the level 1 vertices are
called the offspring of d0. This is shown in Figure 7.1(a). Each vertex at level 1
has no other edges entering it, by part(c) of Theorem 1, but eachof these vertices
may have edges leaving the vertex. The edges leaving a vertex oflevel 1aredrawn
downward and terminate at various vertices, which are said to be at level 2. Figure
7.1(b) shows the situation at this point. A parent-offspring relationship holds also
for these levels (and at every consecutive pair of levels). For example, d3 would
272 Chapter 7 Trees
Level 0

Level 1 Level 1

v9) Level 2
(a)

Figure 7.1

be called the parent of the three offspring d7, Dg, and D9. The offspring of any one
vertex are sometimes called siblings.
The preceding process continues for as many levels as are required to complete
the digraph. If we view the digraph upside down, we will see why these relations
are called trees. The largest level number of a tree is called the height of the tree.
We should note that a tree may have infinitely many levels and that any level
other than level 0 may contain an infinite number of vertices. In fact, any vertex
could have infinitely many offspring. However, in all our future discussions, trees
will be assumed to have a finite number of vertices. Thus the trees will always
have a bottom (highest-numbered) level consisting of vertices with no offspring.
The vertices of the tree that have no offspring are called the leaves of the tree.
The vertices of a tree that lie at any one level simply form a subset of A.
Often, however, it is useful to suppose that the offspring of each vertex of the tree
are linearly ordered. Thus, if a vertex v has four offspring, we may assume that
they are ordered, so we may refer to them as the first, second, third, or fourth
offspring of d. Whenever wedraw the digraph of a tree, we automatically assume
some ordering of theoffspring of each vertex by arranging them from left to right.
Such a tree will be called an ordered tree. Generally, ordering of offspring in a
tree is not explicitly mentioned. If ordering is needed, it is usually introduced at
the time when the need arises, and it often is specified by the way the digraph of
the tree is drawn. The following relational properties of trees areeasily verified.

THEOREM 2 Let (7\ d0) be a rooted tree on a set A. Then


(a) T is irreflexive.
(b) T is asymmetric.
(c) If (a, b)eT and {b9 c) e 7\ then (a9 c) £ T9 for all a9 b9 and c in A.

Proof
The proof is left as an exercise. •

Example 1 Let Abethe set consisting ofa given woman d0 and all ofher female descendants.
We now define the following relation T on A: If v\ and v2 are elements of A, then
Di T v2 if and only if v\ is the mother of d2. The relation T on A is a rooted tree
with root dq. ♦

Example 2 Let A = {vu d2, d3, d4, d5, d6, d7, d8, d9, di0} and let T = {(d2, d3), (d2, v{)9
(d4, d5), (d4, d6), (d5, d8), (d6, d7), (d4, d2), (d7, d9), (d7, dio)}. Show that T is a
rooted tree and identify the root.
7.1 Trees 273

Solution
Since no paths begin at vertices v\, D3, d8, D9, and Dio, these vertices cannot be
roots of a tree. There are no paths from vertices v$9 d7, d2, and D5 to vertex d4,
so we must eliminate these vertices as possible roots. Thus, if T is a rooted tree,
its root must be vertex d4. It is easy to show that there is a path from d4 to every
other vertex. For example, the path d4, D6, d7, vg leads from d4 to vg9 since (d4, D6),
(tys, d7), and (d7, D9) are all in T. We draw the digraph of T9beginning with vertex
d4, and with edges shown downward. The result is shown in Figure 7.2. A quick
inspection of this digraph shows that paths from vertex d4 to every other vertex are
unique, and there are no paths from d4 to d4. Thus T is a tree with root d4. ♦

If a is a positive integer, we say that a tree T is an n-tree if every vertex has


at most ft offspring. If all vertices of T9 other than the leaves, have exactly n
offspring, we say that 7 is a complete w-tree. In particular, a 2-tree is often called
Figure 7.2 a binary tree, and a complete 2-tree is often called a complete binary tree.
Binary trees are extremely important, since there are efficient methods of im
plementing them and searching through them on computers. We will see some of
these methods in Section 7.3, and we will also see that any tree can be represented
as a binary tree.
Let (7, Do) be a rooted tree on the set A, and let v be a vertex of T. Let B be
the set consisting of v and all its descendants, that is, all vertices of T that can be
reached by a path beginning at d. Observe that B c. A. Let T(v) be the restriction
of the relation T to B9 that is, TD(B x B) (see Section 4.2). In other words, T(v)
is the relation that results from 7 in the following way. Delete all vertices that are
not descendants of d and all edges that do not begin and end at any such vertex.
Then we have the following result.

THEOREM 3 If (7, d0) is a rooted tree and v e T9 then 7(d) is also a rooted tree with root v.
We will say that 7(d) is the subtree of T beginning at d.

Proof
By the definition of 7(d), we see that there is a path from d to every other vertex
in 7(d). If there is a vertex w in 7(d) such that there are two distinct paths q and
qf from v to w9 and if p is the path in 7 from Do to d, then q o p and qf o p would
be two distinct paths in 7 from Do to w. This is impossible, since 7 is a tree with
root Do. Thus each path from v to another vertex w in 7(d) must be unique. Also,
if q is a cycle at d in 7(d), then q is also a cycle in 7. This contradicts Theorem
1(a); therefore, q cannot exist. It follows that 7(d) is a tree with root d. •

Subtrees and sublattices (Section 6.3) are examples of substructures of a math


ematical structure. In general, if a set A and a collection of operations and their
properties form a mathematical structure (Section 1.6), then a substructure of the
same type is a subset of A with the same operations that satisfies all the properties
Figure 7.3 that define this type of structure. This concept is used again in Chapter 9.

Example 3 Consider the tree 7 of Example 2. This tree has root d4 and is shown in Figure
7.2. In Figure 7.3 we have drawn the subtrees T(v$)9 7(d2), and 7(d6) of 7. ♦
274 Chapter 7 Trees

7.1 Exercises

In Exercises 1 through 8, each relation R is defined on the set 13. Is (7, Do) an n-tree? If so, for what integer nl Is (7, d0) a
A. In each case determine if R is a tree and, if it is, find the complete n-tree? If so, for what integer nl
root.
In Exercises 14 through 18, consider the rooted tree (7, d0)
1. A = {<
{a9b,c9d,e} shown in Figure 7.5.
/? = {{ia9d),ib9c), ic9a),id,e)}
2. A = {a9b9c,d9e}
{i
R = {(a,
{ «,(*,«), (c, J), W,*),(cffl)}
3. A = {a9b,c,d,e9
{i f]
R = {ia,b)9ic9e),if,a)9if9c),if9d)}
{
4. A = {1,2,3,4,5,6}
{
R = {(2,1),
{ (3,4), (5,2), (6,5), (6, 3)}
5. A = {1,2,3,4,5,6}
{
R = {(1,1),
{ (2,1), (2, 3), (3,4), (4, 5), (4, 6)}
6. A = {1,2,3,4,5,6}
{
R = {(1,2),
{ (1,3), (4, 5), (4, 6)}
7. A = {r,
{ w, u, w, jc, v, z]
R = [it9
{ u), (w, w), iu, x), (w, d), (d, z), (d, y)}
8. A = {{m, d, w,x,y,z}
R = {(w,x),
{ (w, d), (w, d), (x, z), (*, y)}
In Exercises 9 through 13, consider the rooted tree (7, vQ)
shown in Figure 7.4. (T, v0)

Figure 7.5

14. (a) List all level-4 vertices,


(b) List all leaves.
15. (a) What are the siblings of d2?
(b) What are the descendants of d2?
16. (a) Compute the tree 7 (d4).
(b) Compute the tree 7(u2).
17. (a) What is the height of (7, d0)?
(b) What is the height of 7 (d4)?
18. What is the minimal number of vertices that would need
to be added to make (7, d0) a complete 3-tree? Draw the
new tree.

19. Give all the subtrees of the rooted tree (7, v0) shown in
Figure 7.2.
(r, *o)
20. Show that the maximum number of vertices in a binary
Figure 7.4 tree of height n is 2n+l —1.
21. Prove that the largest possible number of leaves in an n-
9. (a) List all level-3 vertices. treeof height fc is nk.
(b) List all leaves. 22. If 7 is a complete rc-tree with exactly three levels, prove
10. (a) What are the siblings of Dg? that the number of vertices of 7 must be 1 + kn, where
2< k <n + l.
(b) What are the descendants of d8?
23. Let 7 be a complete n-tree with m vertices of which Jc are
11 (a) Compute the tree 7 (d2).
nonleaves and / are leaves. (That is, m = Jc + /.) Prove
(b) Compute the tree 7(t>3). that m = nk + 1 and / = in - \)k + 1.
12 (a) What is the height of (7, d0)? 24. Prove Theorem 2(a). 25. Prove Theorem 2(b).
(b) What is the height of 7(d3)? 26. Prove Theorem 2(c).
7.2 Labeled Trees 275

27. Let 7 be a tree. Suppose that 7 has r vertices and s edges. 32. An n-tree of height k is balanced if all the leaves are at
Find a formula relating r to s. level k or k — 1. Which of the following are balanced
trees? The tree shown in
28. Draw all possible unordered trees on the set S = {a, b, c}.
(a) Figure 7.1 (a) (b) Figure 7.1 (b)
29. What is the maximum height for a tree on S = (c) Figure 7.4 (d) Figure 7.5.
{a,b, c,d9 e}l Explain.
33. Let 7 be a balanced n-tree with 125 leaves.
30. What is the maximum height for a complete binary tree (a) What are the possible values of nt
on S = {a, b, c, d, e}l
(b) What are the possible values for the height of 7?
31. Show that if (7, v0) is a rooted tree, then v0 has in-degree 34. Let 7 be a balanced n-tree of height 4 with 125 leaves.
zero. What are the possible values for n?

7.2 Labeled Trees

It is sometimes useful to label the vertices or edges of a digraph to indicate that


the digraph is being used for a particular purpose. This is especially true for many
uses of trees in computer science and biology. We will now give a series of ex
amples in which the sets of vertices of the trees are not important, but rather the
utility of the tree is best emphasized by the labels on these vertices. Thus we will
represent the vertices simply as dots and show the label of each vertex next to the
dot representing that vertex.
Consider the fully parenthesized, algebraic expression

(3-(2xjc)) + ((jc-2)-(3 + jc)).

We assume, in such an expression, that no operation such as —, +, x, or


-4- can be performed until both of its arguments have been evaluated, that is,
until all computations inside both the left and right arguments have been per
formed. Therefore, we cannot perform the central addition until we have evaluated
(3 - (2 x x)) and ((jc - 2) - (3 + x)). We cannot perform the central subtraction
in ((jc - 2) - (3 + jc)) until we evaluate (jc - 2) and (3 + x)9 and so on. It is easy
to see that each such expression has a central operator, corresponding to the last
computation that can be performed. Thus + is central to the main expression, —
is central to (3 - (2 x jc)), and so on. An important graphical representation of
such an expression is as a labeled binary tree. In this tree the root is labeled with
the central operator of the main expression. The two offspring of the root are la
beled with the central operator of the expressions for the left and right arguments,
respectively. If either argument is a constant or variable, instead of an expression,
this constant or variable is used to label the corresponding offspring vertex. This
process continues until the expression is exhausted. Figure 7.6 shows the tree for
the original expression of this example. To illustrate the technique further, we have
shown in Figure 7.7 the tree corresponding to the full parenthesized expression

((3 x (1 - jc)) - ((4 + (7 - iy + 2))) x (7 + (jc 4- y)))).

Our next example of a labeled tree is important for the computer implementa
tion of a tree data structure. We start with an rc-tree (7, Do). Each vertex in 7 has at
most n offspring. We imagine that each vertex potentially has exactly n offspring,
which would be ordered from 1 to n9 but that some of the offspring in the sequence
may be missing. The remaining offspring are labeled with the position that they
occupy in the hypothetical sequence. Thus the offspring of any vertex are labeled
with distinct numbers from the set {1, 2,..., n}.
276 Chapter 7 Trees

Figure 7,7

Such a labeled digraph is sometimes called positional, and we will also use
this term. Note that positional trees are also ordered trees. When drawing the
digraphs of a positional tree, we will imagine that the n offspring positions for each
vertex are arranged symmetrically below the vertex, and we place in its appropriate
position each offspring that actually occurs.
Figure 7.8 shows the digraph of a positional 3-tree, with all actually occurring
positions labeled. If offspring 1 of any vertex d actually exists, the edge from v
to that offspring is drawn sloping to the left. Offspring 2 of any vertex d is drawn
vertically downward from d, whenever it occurs. Similarly, offspring labeled 3
will be drawn to the right. Naturally, the root is not labeled, since it is not an
offspring.

Figure 7.8 Figure 7.9

The positional binary tree is of special importance. In this case, for obvious
reasons, the positions for potential offspring are often labeled left and right, instead
of 1 and 2. Figure 7.9 shows the digraph of a positional binary tree, with offspring
labeled L for left and R for right. Labeled trees may have several sets of labels, all
in force simultaneously. We will usually omit the left-right labels on a positional
binary tree in order to emphasize other useful labels. The positions of the offspring
will then be indicated by the direction of the edges, as we have drawn them in
Figure 7.9.
7.2 Labeled Trees 277

Binary Positional Trees as Data Structures


In Section 4.6, we discussed an idealized information storage unit called a cell.
A cell contains two items. One is data of some sort and the other is a pointer to
the next cell, that is, an address where the next cell is located. A collection of
such cells, linked together by their pointers, is called a linked list. The discus
sion in Section 4.6 included both a graphical representation of linked lists, and an
implementation of them that used arrays.
We need here an extended version of this concept, called a doubly linked list,
in which each cell contains two pointers and a data item. We use the pictorial
symbol -f+"l 1^-H t0 represent these new cells. The center space represents
data storage and the two pointers, called the left pointer and the right pointer,
are represented as before by dots and arrows. Once again we use the symbol
•—=L- for a pointer signifying no additional data. Sometimes a doubly linked list
is arranged so that each cell points to both the next cell and the previous cell. This
is useful if we want to search through a set of data items in either direction. Our
use of doubly linked lists here is very different. We will use them to represent
binary positional labeled trees. Each cell will correspond to a vertex, and the data
part can contain a label for the vertex or a pointer to such a label. The left and
right pointers will direct us to the left and right offspring vertices, if they exist. If
either offspring fails to exist, the corresponding pointer will be •—4r.
We implement this representation by using three arrays: LEFT holds pointers
to the left offspring, RIGHT holds the pointers to the right offspring, and DATA
holds information or labels related to each vertex, or pointers to such information.
The value 0, used as a pointer, will signify that the corresponding offspring does
not exist. To the linked list and the arrays we add a starting entry that points to the
root of the tree.

Example 1 We consider again thepositional binary tree shown inFigure 7.6. InFigure 7.10(a),
we represent this tree as a doubly linked list, in symbolic form. In Figure 7.10(b),
we show the implementation of this list as a sequence of three arrays (see also
Section 4.6). The first row of these arrays is just a starting point whose left pointer

Start INDEX LEFT DATA RIGHT


*i 1 2 X 0
2 3 + 8

3 4 5
4 0 3 0
+ •+ t + H
•¥**! 5
6
6
0
X

2
7

0
7 0 JC 0
9 12
9 10 11
10 0 X 0

-¥^1 11 0 2 0
12 13 + 14
13 0 3 0
14 0 0
rpn^ [jixb-l rp^
X

(a) (b)

Figure 7.10
278 Chapter 7 Trees

points to the root of the tree. As an example of how to interpret the three arrays,
consider the fifth entry in the array DATA, which is x. The fifth entry in LEFT
is 6, which means that the left offspring of x is the sixth entry in DATA, or 2.
Similarly, the fifth entry in RIGHT is 7, so the right offspring of x is the seventh
entry in DATA, or jc. ♦

Example 2 Now consider the tree of Figure 7.7. We represent this tree in Figure 7.11(a) as
a doubly linked list. As before, Figure 7.11(b) shows the implementation of this
linked list in three arrays. Again, the first entry is a starting point whose left pointer
points to the root of the tree. We have listed the vertices in a somewhat unnatural
order to show that, if the pointers are correctly determined, any ordering of vertices
can be used. ♦

INDEX LEFT DATA RIGHT


1 7
X 0
2 0 3 0
t|Start|H—]
3 2 X 5
4 0 1 0
5 4 6
6 0 X 0

b—-sm tl + t

-7- «4
-^mj 7 3 15
8 0 4 0
9 8 11
rprp rp-Tji 10 0
+
7 0
11 10 13

EB—-\KUB -K±JB -tjETBi 12 0 y 0


13 12 + 14
14 0 2 0
fpn—-eeze—~png ^rpnji i~Hjn~ig ^1x51 15 9 X 17
16 0 7 0
17 16 + 19
5DLT| gcnj 18 0 x 0
19 18 20
20 0 y 0

(a) (b)

Figure 7.11

Huffman Code Trees


The simple ASCII code for the letters of the English alphabet represents each letter
by a string of O's and l's of length 7. A Huffman code also uses strings of O's and
l's, but the strings are of variable length. The more frequently used letters are
assigned shorter strings. In this way messages may be significantly shorter than
with ASCII code. A labeled positional binary tree is an efficient way to represent
a Huffman code. The string assigned to a letter gives a path from the root of
the tree to the leaf labeled with that letter; a 0 indicates that we should go to the
left, a 1 that we should go to the right. To decode a message, we follow the path
indicated. When a leaf is reached, the label is recorded, we return to the root and
Figure 7.12 continue with the remainder of the string. We omit the discussion of how to create
a Huffman code.

Example 3 Use the Huffman code tree in Figure 7.12 to decode the string 0101100.
7.2 Labeled Trees 279

Solution
We begin at the root and move to the left (using the first 0). This leaf has label E.
We return to the root and use the string 101100. We go to the right, then to the left
and record A. Repeating the process with 1100 produces S and finally another E.
The string 0101100 represents EASE. ♦

Example 4 Onedisadvantage of a Huffman code is the potential for errors in transmission. If


an error was made in transmitting string 0101100 and string 0101110 is received,
then the word read is EAR, not EASE. ♦

7.2 Exercises

In Exercises 1 through 10, construct the tree of the algebraic INDEX LEFT DATA RIGHT

expression. 1 8 0
2 5 D 7
1. (7 + (6-2))-(jc-(y-4))
3 9 E 0

2. (;t + (y-(* + y)))x((3-M2x7))x4) 4 2 C 3


5 0 F 0
3. 3-(jc + (6x(4 + (2-3)))) 0 B 4
0 G 0
4. (((2x7)+x) + y) + (3-ll) 0
6 A
0 H 0
5. ((2 + jc)-(2xjc))--(jc-2)

6. (11 - (11 x (11+ 11)))+ (11 +(11 x 11)) 18. The following is the doubly linked list representation of
a binary positional labeled tree. Construct the digraph of
7. (3 - (2 - (11 - (9-4)))) + (2 + (3 + (4 + 7))) this tree with each vertex labeled as indicated.
INDEX LEFT DATA RIGHT
8. (jc + y) + ((jcx3)-(z + 4))
1 9 0
9. ((2 x jc) + (3 - (4 x jc))) + (jc - (3 x 11)) 2 10 M 7

3 0 Q 0
10. ((l + l) + (l-2)) + ((2-*) + l) 4 8 T 0
5 3 V 4
11. The annual NCAA Basketball Tournament begins with 64
6 0 X 2
teams. One loss eliminates a team. Suppose the results
7 0 K 0
of the tournament are represented in a binary tree whose
8 0 D 0
leaves are labeled with the original teams and the interior
9 6 G 5
vertices are labeled with the winner of the game between
10 0 C 0
the children of the vertex. What is the height of the tree
created?
19. The following is the doubly linked list representation of
12. Make a "family" tree that shows the descendants of one a binary positional labeled tree. Construct the digraph of
this tree with each vertex labeled as indicated.
of your great grandmothers.
INDEX LEFT DATA RIGHT
13. Construct the digraphs of all distinct binary positional 7 0
trees having three or fewer edges and height 2. 2 0 c 9
3 2 a 6
14. How many distinct binary positional trees are there with
4 0 t 0
height 2?
5 0 s 0

15. How many distinct positional 3-trees are there with height 6 10 a 11

2? 7 3 n 8
8 4 d 13
16. Construct the digraphs of all distinct positional 3-trees 9 0 0
f
having two or fewer edges. 10 0 r 0
11 0 o 0
17. The following is the doubly linked list representation of
12 0 8 0
a binary positional labeled tree. Construct the digraph of
13 12 s 5
this tree with each vertex labeled as indicated.
280 Chapter 7 Trees

20. Give arrays LEFT, DATA, and RIGHT describing the tree In Exercises 21 through 24, give arrays LEFT, DATA, and
given in Figure 7.13 as a doubly linked list. RIGHT describing the tree created in the indicated exercise.
21. Exercise 1 22. Exercise 4
23. Exercise 5 24. Exercise 8
25. Use the Huffman code tree in Figure 7.12 to decode each
of the following messages.
(a) 1111101110 (b) 1100101110
(c) 11101011110 (d) 1101111101110
26. Use the Huffman code tree in Figure 7.12 to find the string
that represents the given word.
(a) CARE (b) SEA
(c) ACE (d) CASE
27. Construct the labeled tree that represents this Huffman
code.
Figure 7.13 A 000 B01 C001 D1100 E1101

7.3 Tree Searching


There are many occasions when it is useful to consider each vertex of a tree T
exactly once in some specific order. As each successive vertex is encountered,
we may wish to take some action or perform some computation appropriate to the
application being represented by the tree. For example, if the tree T is labeled, the
label on each vertex may be displayed. If T is the tree of an algebraic expression,
then at each vertex we may want to perform the computation indicated by the
operator that labels that vertex. Performing appropriate tasks at a vertex will be
called visiting the vertex. This is a convenient, nonspecific term that allows us
to write algorithms without giving the details of what constitutes a "visit" in each
particular case.
The process of visiting each vertex of a tree in some specific order will be
called searching the tree or performing a tree search. In some texts, this process
is called walking or traversing the tree.
Let us consider tree searches on binary positional trees. Recall that in a binary
positional tree each vertex has two potential offspring. We denote these potential
offspring by vL (the left offspring) and vR (the right offspring), and either or both
may be missing. If a binary tree T is not positional, it may always be labeled so
that it becomes positional.
Let T be a binary positional tree with root v. Then, if vi exists, the subtree
T{vL) (see Section 7.1) will be called the left subtree of T9 and if vR exists, the
subtree T(vR) will be called the right subtree of T.
Note that T(vL)9 if it exists, is a positional binary tree with root vL, and sim
ilarly T(vR) is a positional binary tree with root vR. This notation allows us to
specify searching algorithms in a natural and powerful recursive form. Recall that
recursive algorithms are those that refer to themselves. We first describe a method
of searching called a preorder search. For the moment, we leave the details of vis
iting a vertex of a tree unspecified. Consider the following algorithm for searching
a positional binary tree T with root v.
7.3 Tree Searching 281

Algorithm PREORDER
Stepl Visit t>.
Step 2 If vl exists, then apply this algorithm to (T(vL)9 vL).
Step 3 If vR exists, then apply this algorithm to (T(vR)9 vR). •

Informally, we see that a preorder search of a tree consists of the following


three steps:
1. Visit the root.
2. Search the left subtree if it exists.
3. Search the right subtree if it exists.

Example 1 Let T be the labeled, positional binary tree whose digraph is shown in Figure
7.14(a). The root of this tree is the vertex labeled A. Suppose that, for any vertex
v of T, visiting v prints out the label of v. Let us now apply the preorder search
algorithm to this tree. Note first that if a tree consists only of one vertex, its root,
then a search of this tree simply prints out the label of the root. In Figure 7.14(b),
we have placed boxes around the subtrees of T and numbered these subtrees (in
the corner of the boxes) for convenient reference.

D © • L

bS ^H

t"
K
E

>\ '< \
\
@D •g •j
3 5 6 9 11

2 4 8 10

1 1

(b)

Figure 7.14

According to PREORDER, applied to 7, we will visit the root and print A,


then search subtree 1, and then subtree 7. Applying PREORDER to subtree 1
results in visiting the root of subtree 1 and printing B9 then searching subtree 2,
and finally searching subtree 4. The search of subtree 2 first prints the symbol C
282 Chapter 7 Trees

and then searches subtree 3. Subtree 3 has just one vertex, and so, as previously
mentioned, a search of this tree yields just the symbol D. Up to this point, the
search has yielded the string ABCD. Note that we have had to interrupt the search
of each tree (except subtree 3, which is a leaf of T) in order to apply the search
procedure to a subtree. Thus we cannot finish the search of T by searching subtree
7 until we apply the search procedure to subtrees 2 and 4. We could not complete
the search of subtree 2 until we search subtree 3, and so on. The bookkeeping
brought about by these interruptions produces the labels in the desired order, and
recursion is a simple way to specify this bookkeeping.
Returning to the search, we have completed searching subtree 2, and we now
must search subtree 4, since this is the right subtree of tree 1. Thus we print E and
search 5 and 6 in order. These searches produce F and G. The search of subtree 1
is now complete, and we go to subtree 7. Applying the same procedure, we can see
that the search of subtree 7 will ultimately produce the string HIJKL. The result,
then, of the complete search of T is to print the string ABCDEFGHIJKL. ♦

Example 2 Consider the completely parenthesized expression {a —b) x (c + id -r e)). Figure


7.15(a) shows the digraph of the labeled, positional binary tree representation of
this expression. We apply the search procedure PREORDER to this tree, as we did
to the tree in Example 1. Figure 7.15(b) shows the various subtrees encountered in
the search. Proceeding as in Example 1 and supposing again that visiting v simply
prints out the label of v9 we see that the string x —a b + c -=- d e is the result of the
search. This is the prefix or Polish form of the given algebraic expression. Once
again, the numbering of the boxes in Figure 7.15(b) shows the order in which the
algorithm PREORDER is applied to subtrees. ♦

Figure 7.15

The Polish form of an algebraic expression is interesting because it repre


sents the expression unambiguously, without the need for parentheses. To evaluate
an expression in Polish form, proceed as follows. Move from left to right until
we find a string of the form Fxy9 where F is the symbol for a binary operation
(+, —, x, and so on) and x and y are numbers. Evaluate x F y and substitute the
answer for the string Fxy. Continue this procedure until only one number remains.
For example, in the preceding expression, suppose that a = 69 b = 49 c = 5,
d = 2, and e = 2. Then we are to evaluate x — 64 + 5-^2 2. This is done in the
following sequence of steps.
7.3 Tree Searching 283

1. x-64 + 5 + 22
2. X2 + 5-7 22 since the first string of the correct type is —6 4 and
6-4 = 2
3. x2 + 51 replacing + 22 by 2 + 2 or 1
4. x26 replacing + 51 by 5 + 1 or 6
5. 12 replacing x 2 6 by 2 x 6
This example is one of the primary reasons for calling this type of search the
preorder search, because here the operation symbol precedes the arguments.
Consider now the following informal descriptions of two other procedures for
searching a positional binary tree T with root v.

Algorithm INORDER
Step 1 Search the left subtree (T(vl)9 vl)9 if it exists.
Step 2 Visit the root, v.
Step 3 Search the right subtree (T(vR)9 vR)9 if it exists. •

Algorithm POSTORDER
Step 1 Search the left subtree (T(vL)9 vL)9 if it exists.
Step 2 Search the right subtree (T(vR)9 vR)9 if it exists.
Step 3 Visit the root, v. •

As indicated by the naming of the algorithms, these searches are called, re


spectively, the inorder and postorder searches. The names indicatewhen the root
of the (sub)tree is visited relative to when the left and right subtrees are searched.
Informally, in a preorder search, the order is root, left, right; for an inorder search,
it is left, root, right; and for a postorder search, it is left, right, root.

Example 3 Consider the tree of Figure 7.14(b) and apply the algorithm INORDER to search
it. First we must search subtree 1. This requires us to first search subtree 2, and this
in turn requires us to search subtree 3. As before, a search of a tree withonly one
vertex simply prints thelabel of the vertex. Thus D is the first symbol printed. The
search of subtree 2 continues by printing C and then stops, since there is no right
subtree at C. We then visit the root of subtree 1 and print B9 and then proceed to
the search of subtree 4, which yields F9E9 and G, in that order. We then visit the
root of T and print A and proceed to search subtree 7. The reader may complete
the analysis of the search of subtree 7 to show that the subtree yields the string
IJHKL. Thus the complete search yields the string DCBFEGAIJHKL.
Suppose now that we apply algorithm POSTORDER to search the same tree.
Again, the searchof a tree withjust one vertex will yield the label of that vertex.
In general, we must search both the left and the right subtrees of a tree with root v
before we print out the label at v.
Referring again to Figure 7.14(b), we see that both subtree 1 and subtree 7
must be searchedbefore A is printed. Subtrees 2 and 4 must be searched before B
is printed, and so on.
The search of subtree 2 requires us to search subtree 3, and D is the first
symbol printed. The search of subtree 2 continues by printing C. We now search
subtree 4, yielding F, G, and E. We next visit the root of subtree 1 and print B.
Then we proceed with the search of subtree 7 and print the symbols J9 I9 L9 K9
and H. Finally, we visit the root of T and print A. Thus we print out the string
DCFGEBJILKHA. ♦
284 Chapter 7 Trees

Example 4 Let us now apply the inorder and postorder searches to the algebraic expression
tree of Example 2 [see Figure 7.15(a)]. The use of INORDER produces the string
a — bxc + d + e. Notice that this is exactly the expression that we began
with in Example 2, with all parentheses removed. Since the algebraic symbols lie
between their arguments, this is often called the infix notation, and this explains
the name INORDER. The preceding expression is ambiguous without parentheses.
It could have come from the expression a —(b x ((c + d) + e))9 which would have
produced a different tree. Thus the tree cannot be recovered from the output of
search procedure INORDER, while it can be shown that the tree is recoverable
from the Polish form produced by PREORDER. For this reason, Polish notation
is often better for computer applications, although infix form is more familiar to
human beings.
The use of search procedure POSTORDER on this tree produces the string ab
- cde -r + x. This is the postfix or reverse Polish form of the expression. It is
evaluated in a manner similar to that used for Polish form, except that the operator
symbol is after its arguments rather than before them. If a = 2, b = 1, c = 3,
d = 4, and e = 2, the preceding expression is evaluated in the following sequence
of steps.
1. 21-342 + +X
2. 1 3 4 2 -f- + x replacing 2 1 - by 2 - 1 or 1
3. 132+ x replacing42 +by 4 + 2or 2
4. 15 x replacing 32 +by 3 + 2 or 5
5. 5 replacing 15xbylx5or5 ♦

Reverse Polish form is also parentheses free, and from it we can recover the
tree of the expression. It is used even more frequently than the Polish form and is
the method of evaluating expressions in some calculators.

Searching General Trees


Until now, we have only shown how to search binary positional trees. We now
show that any ordered tree T (see Section 7.1) may be represented as a binary
positional tree that, although different from T9 captures all the structure of T and
can be used to re-create T. With the binary positional description of the tree, we
may apply the computer implementation and search methods previously devel
oped. Since any tree may be ordered, we can use this technique on any (finite)
tree.
Let T be any orderedtree and let A be the set of verticesof T. Definea binary
positional tree B(T) on the set of vertices A, as follows. If v e A, then the left
offspring vL of v in B(T) is the first offspring of v in T (in the given order of
siblings in T)9 if it exists. The right offspring vR of v in B(T) is the next sibling
of v in T (in the given order of siblings in T)9 if it exists.

Example 5 Figure 7.16(a) shows the digraph of a labeled tree T. We assume that each set
of siblings is ordered from left to right, as they are drawn. Thus the offspring of
vertex 1, that is, vertices 2, 3, and 4, are ordered with vertex 2 first, 3 second, and
4 third. Similarly, the first offspring of vertex 5 is vertex 11, the second is vertex
12, and the third is vertex 13.
In Figure 7.16(b), we show the digraph of the corresponding binary positional
tree, B(T). To obtain Figure 7.16(b), we simply draw a left edge from each vertex
v to its first offspring (if v has offspring). Then we draw a right edge from each
vertex v to its next sibling (in the order given), if v has a next sibling. Thus the
7.3 Tree Searching 285

11 12 13
T BiT)
(a) (b)

Figure 7.16

left edge from vertex 2, in Figure 7.16(b), goes to vertex 5, because vertex 5 is
the first offspring of vertex 2 in the tree T. Also, the right edge from vertex 2, in
Figure 7.16(b), goes to vertex 3, since vertex 3 is the next sibling in line (among all
offspring of vertex 1). A doubly-linked-list representation of B(T) is sometimes
simply referred to as a linked-list representation of T. ♦

Example 6 Figure 7.17(a) shows the digraph of another labeled tree, with siblings ordered
from left to right, as indicated. Figure 7.17(b) shows the digraph of the corre
sponding tree B(T)9 and Figure7.17(c) gives an array representation of B(T). As
mentioned, the data in Figure 7.17(c) would be called a linked-list representation
of7\ ♦
INDEX LEFT DATA RIGHT
1 2 X 0
by 2 3 a 0

3 6 b 4
bi \d eJf \c
4 0 c 5

W 5 0 d 0
1 V
> • 6 0 e 7
e ) >S
7 0 f 8

BiT) 8 0 8 0
T

(a) (b) (c)

Figur e7.1 7

Pseudocode Versions
The three search algorithms in this section have straightforward pseudocode ver
sions, which we present here. In each, we assume that the subroutine VISIT has
been previously defined.

SUBROUTINE PREORDER (T\ v)


1. CALL VISIT (v)
2. IF (vjr exists) THEN
a. CALL PREORDERC T( vL) ,vL)
3. IF (vR exists) THEN
a. CALL PREORDERC T( v*) ,vR)
4. RETURN
END OF SUBROUTINE PREORDER
286 Chapter 7 Trees

SUBROUTINE lNORDER(r, v)
1. IF (vjr, exists) THEN
a. CALL INORDER(T(Vi),vL)
2. CALL VISITO)
3. IF (vR exists) THEN
a. CALL INORDER(T(vR),vR)
4. RETURN
END OF SUBROUTINE INORDER

SUBROUTINE POSTORDER(r, v)
1. IF (vj, exists) THEN
a. CALL POSTORDERCrX>L),v-L)
2. IF (vR exists) THEN
a. CALL POSTORDER(T(vR) ,vR)
3. CALL VISIT(v)
4. RETURN
END OF SUBROUTINE POSTORDER

7.3 Exercises

In Exercises 1 through 5 (Figures 7.18 through 7.22), the di


graphs of labeled, positional binary trees are shown. In each
case we suppose that visiting a node results in printing out the
label of thatnode. For each exercise, show the result of per
forming a preorder searchof the treewhosedigraph is shown.
1.

\b'°c\ ^

Figure 7.19 Figure 7.22


Figure 7.18
In Exercises 6 through 15, visiting a node means printing out
the label of the node.
6. Show the result of performing an inorder search of the tree
shown in Figure 7.18.
7. Show the result of performing an inorder search of the tree
shown in Figure 7.19.
8. Show the result of performing an inorder search of the tree
shown in Figure 7.20.
9. Show the result of performing an inorder search of the tree
shown in Figure 7.21.
10. Show the result of performing a postorder search of the
tree shown in Figure 7.22.
11. Show the result of performing a postorder search of the
tree shown in Figure 7.18.
12. Show the result of performing a postorder search of the
tree shown in Figure 7.19.
7.3 Tree Searching 287

13. Show the result of performing a postorder search of the 29. (a) Every binary tree whose preorder search produces
tree shown in Figure 7.20. the string JBACDIHEGF must have 10 vertices.
What else do the trees have in common?
14. Show the result of performing a postorder search of the
tree shown in Figure 7.21. (b) Every binary tree whose postorder search produces
15. Show the result of performing an inorder search of the tree the string SEARCHING must have 9 vertices. What
shown in Figure 7.22. else do the trees have in common?

For Exercises 16 through 18, consider the tree whose digraph 30. Show that any element of the string ABCDEF may be the
is shown in Figure 7.23 and the accompanying list of words. root of a binary tree whose inorder search produces this
Suppose that visiting a node means printing out the word cor string.
responding to the number that labels the node.
In Exercises 31 and 32 (Figures 7.24 and 7.25), draw the di
graph of the binarypositional tree BiT) that corresponds to
the tree shown. Label the vertices of BiT) to show their cor
respondence to the vertices ofT.
1. ONE 7. I
2. COW 8. A 31.
3. SEE 9. I
4. NEVER 10. I
5. PURPLE 11. SAW
6. NEVER 12. HOPE

• z
Figure 7.23
Figure 7.24
16. Give the sentence that results from doing a preorder
search of the tree.

17. Give the sentence that results from doing an inorder 32.
search of the tree.

18. Give the sentence that results from doing a postorder


search of the tree.

In Exercises 19 and 20, evaluate the expression, which is given


in Polish, or prefix, notation. R ITEM S

19. X- + 34-72-T- 12x3-64 Figure 7.25


20. -r— x3;cx4y+15x2 —6y, where x is 2 and y is
3. In Exercises 33 and 34, we give, in arrayform, the doubly-
In Exercises 21 through 24, evaluate the expression, which is linked-list representation of a labeled tree T (not binary).
given in reversePolish, or postfix, notation. Draw the digraph of both the labeled binary tree B(T) actu
ally stored in thearrays and the labeled tree T of which BiT)
21. 432-r-5x42x5x3-=--r is the binary representation.
22. 37x4-9x65x2 + -^
33.
INDEX LEFT DATA RIGHT
23. jc2-3 + 23y + -w3-x-r, where x is 7, y is 2,
1 2 X 0
andiy is 1.
2 3 a 0
24. 7xxy —Sxxw + x where x is 7, y is 2, and w is 1. 3 4 b 5

25. Draw a binary tree whose preorder search produces the 4 6 c 7


string JBACDIHEGF. 5 8 d 0
6 0 e 10
26. Draw a binary tree whose preorder search produces the 0
7 0 f
string CATSANDDOGS. 11
8 0 g
27. Draw a binary tree whose postorder search produces the 9 0 h 0
string SEARCHING. 10 0 i 9
11 0 J 12
28. Draw a binary tree whose postorder search produces the
12 0 k 0
string TREEHOUSE.
288 Chapter 7 Trees

34. 36.
INDEX LEFT DATA RIGHT
1 12 X 0
2 0 T 0
3 0 W 0
4 2 0 3
5 0 B 0
6 0 R 0
7 0 A 0
8 6 N 7
9 5 C 8
10 4 H 9
11 0 E 10 Figure 7.27
12 11 S 0
37. Finding information stored in a binary tree is a common
task. We can improve the efficiency of such a search by
In Exercises 35 and 36 (Figures 7.26 and 7.27), consider the having a "balanced" tree. An AVL tree, (7\ i;0), is a bi
digraph of thelabeledbinary positional treeshown. If thistree nary tree where for each v e 7\ the height of T{vL) and
is the binary form B(T) of some tree T, draw the digraph of the height of TivR) differ by at most one. For the given
the labeled tree T.
height, draw an AVL tree using the smallest possible num
35. ber of vertices.

(a) ht = 0 (b) ht = 1
(c) ht = 2 id) ht = 3
38. Is an AVL-tree a balanced 2-tree as defined in Section 7.1,
Exercise 32?

39. Write a recurrence relation for AVL,,, the minimum num


berof vertices neededfor an AVL tree of heightn. Justify
your recurrence relation by giving a procedure for form
ing an AVL tree of height k with a minimum number of
vertices from smaller AVL trees with minimal numbers of
vertices.

7.4 Undirected Trees

An undirected tree is simply the symmetric closure of a tree (see Section 4.7);
that is, it is the relation that results from a tree when all the edges are made bidi
rectional. As is the custom with symmetric relations, we represent an undirected
tree by its graph, rather than by its digraph. The graph of an undirected tree T will
havea singleline without arrows connecting vertices a and b whenever (a9 b) and
(b9 a) belong to T. The set [a9 b}9 where (a9 b) and (b9 a) are in T9 is called an
undirected edge of T (see Section 4.4). In this case, the vertices a and b are called
adjacent vertices. Thus each undirected edge {a9 b] corresponds to two ordinary
edges, ia9 b) and ib, a). The lines in the graph of an undirected tree T correspond
to the undirected edges in T.

Example 1 Figure 7.28(a) shows the graph ofan undirected tree T. In Figures 7.28(b) and
(c), we show digraphs of ordinary trees T\ and T2, respectively, which have T as
symmetric closure. Thisshows that an undirected tree will,in general, correspond
to many directed trees. Labels are included to show the correspondence of under
lying vertices in the threerelations. Note that the graph of T in Figure 7.28(a)has
six lines (undirected edges), although the relation T contains 12 pairs. ♦

We want to present some useful alternative definitions of an undirected tree,


and to do so we must make a few remarks about symmetric relations.
7.4 Undirected Trees 289

a b e f

(c)

Let R be a symmetric relation, and let p: v\, v2,..., vn be a path in R. We


will say that p is simple if no two edges of p correspond to the same undirected
edge. If, in addition, v\ equals vn (so that p is a cycle), we will call p a simple
cycle.

Example 2 Figure 7.29 shows the graph of a symmetric relation R. The path a9 b9 c, e9 d is
simple, but the path /, e9 d9 c9 d9 a is not simple, since d9 c and c, d correspond
to the same undirected edge. Also, /, e9 a9 d9 b9 a9 f and d9 a9 b9 d are simple
cycles, but /, e9 d9 c, e9 f is not a simple cycle, since /, e and e9 f correspond to
the same undirected edge. ♦

We will say that a symmetric relation R is acyclic if it contains no simple


cycles. Recall (see Section 4.4) that a symmetric relation R is connected if there
is a path in R from any vertex to any other vertex.
The following theorem provides a useful statement equivalentto the previous
Figure 7.29 definition of an undirected tree.

THEOREM 1 Let R be a symmetric relation on a set A. Then the following statements are
equivalent.
(a) R is an undirected tree.
(b) R is connected and acyclic.

Proof
We will prove thatpart(a) implies part(b), andwe willomitthe proofthatpart(b)
implies part (a). We suppose that R is an undirected tree, which means that R is
the symmetric closure of sometree T on A. Note first that if (a9 b) e R9 we must
have either (a, b) € T or (b9 a) € T. In geometric terms, this means that every
undirected edge in the graph of R appears in the digraph of 7\ directed one way
or the other.
We willshow bycontradiction that R hasno simple cycles. Suppose that Rhas
a simple cycle p: v\, v2,..., vn, v\. Foreachedge(v,-, Vj) in/?, choose whichever
pair (vi9 Vj) or (vJ9 v() is in T. The result is a closed figure with edges in T9 where
each edge may be pointing in either direction. Now there are three possibilities.
Either all arrows pointclockwise, as in Figure 7.30(a), all point counterclockwise,
or some pair must be as in Figure 7.30(b). Figure 7.30(b) is impossible, since in
a tree T every vertex (except the root) has in-degree 1 (see Theorem 1 of Section
7.1). But either of the other two cases would mean that T contains a cycle, which
is also impossible. Thus theexistence of the cycle p in R leads to a contradiction
and so is impossible.
We must also show that R is connected. Let v0 be the root of the tree T. Then,
if a and b are any vertices in A, there must be paths p from vo to a and q from vo
to b9 as shown in Figure 7.30(c). Now all pathsin T are reversible in R9 so the path
290 Chapter 7 Trees

qop 1, shown in Figure 7.30(d), connects a withb in R9 wherep l is the reverse


path of p. Since a and b are arbitrary, R is connected, and part (b) is proved. •

There are other useful characterizations of undirected trees. We state two of


these without proof in the following theorem.

THEOREM 2 Let R be a symmetric relationon a set A. Then R is an undirected tree if and only
if either of the following statements is true.
(a) R is acyclic, and if any undirected edge is added to R9 the new relation
will not be acyclic.
(b) R is connected, and if any undirected edge is removed from R9 the new
relation will not be connected. •

Note that Theorems 1 and 2 tell us that an undirected tree must have exactly
the "right" number of edges; one too many and a cycle will be created; one too
few and the tree will become disconnected.
The following theorem will be useful in finding certain types of trees.

THEOREM 3 A tree with n vertices has n —1 edges.

Proof
Because a tree is connected, there must be at least n —1 edges to connect the n
vertices. Suppose that there are more than n —1 edges. Then either the root has in-
degree 1 or some other vertex has in-degree at least 2. But by Theorem 1, Section
7.1, this is impossible. Thus there are exactly n —1 edges. •

Spanning Trees of Connected Relations


If J? is a symmetric, connected relation on a set A, we say that a tree T on A is a
spanning tree for R if T is a tree with exactly the same vertices as R and which
can be obtained from R by deleting some edges of R.

Example 3 The symmetric relation R whose graph is shown in Figure 7.31(a) has the tree T'9
whose digraph is shown in Figure 7.31(b), as a spanning tree. Also, the tree 7"",
whose digraph is shown in Figure 7.31(c), is a spanning tree for R. Since R9 T'9
and T" are all relations on the same set A, we have labeled the vertices to show
the correspondence of elements. As this example illustrates, spanning trees are not
unique. +

f / /
nrtt
R

(a) (c) (d)

Figure 7.31

An undirected spanning tree for a symmetric connected relation R is useful


in some applications. Thisis just the symmetric closure of a spanning tree. Figure
7.31(d) shows an undirected spanning treefor R that is derived from the spanning
7.4 Undirected Trees 291

tree of Figure 7.31(c). If R is a complicated relation that is symmetric and con


nected, it might be difficult to devise a scheme for searching R9 that is, for visiting
each of its vertices once in some systematic manner. If R is reduced to a spanning
tree, the searching algorithms discussed in Section 7.3 can be used.
Theorem 2(b) suggests an algorithm for finding an undirected spanning tree
for a relation R. Simply remove undirected edges from R until we reach a point
where removal of one more undirected edge will result in a relation that is not
connected. The result will be an undirected spanning tree.

Example 4 In Figure 7.32(a), we repeat the graph of Figure 7.31(a). We then show the re
sult of successive removal of undirected edges, culminating in Figure 7.32(f), the
undirected spanning tree, which agrees with Figure 7.31(d). ♦

c b c b

c b

f /
(d) (f)

Figure 7.32
This algorithm is fine for small relations whose graphs are easily drawn. For
large relations, perhaps stored in a computer, it is inefficient because at each stage
we must check for connectedness, and this in itself requires a complicated algo
rithm. We now introduce a more efficient method, which also yields a spanning
tree, rather than an undirected spanning tree.
Let R be a relation on a set A, and let a, b € A. Let A0 = A - {a, b}9 and
A' = A0 U {af}9 where a' is some new element not in A. Define a relation R! on
A' as follows. Suppose w, v e A', u ^ a!9 v ^ a'. Let (a!, u) e R' if and only if
(a9 u) e Roy (b9 u) e R. Let (w, a') e R' if and only if (w, a) e R or (w, b) e R.
Finally, let (w, v) e R' if and only if (w, v) e R. We say that R' is a result of
merging the vertices a and b.
Imagine, in the digraph of R9 that the vertices are pins, and the edges are
elastic bands that can be shrunk to zero length. Now physically move pins a and
b together, shrinking the edge between them, if there is one, to zero length. The
resulting digraph is the digraph of Rf. If R is symmetric, we may perform this
operation onthe graph of R. The result is the graph of the symmetric relation R'.
Example 5 Figure 7.33(a) shows the graph of a symmetric relation R. In Figure 7.33(b), we
show the result of merging vertices v0 and v\ into a new vertex v'0. In Figure
7.33(c), we show the result of merging vertices v'0 and v2 of the relation whose
graphis shown in Figure 7.33(b) intoa newvertex v%. Notice in Figure7.33(c) that
the undirected edges that were previously present between v'0 and v5 and between
v2 and vs have been combined into one undirected edge. ♦
292 Chapter 7 Trees

Figure 7.33

The algebraic form of this merging process is also very important. Let us re
strict our attention to symmetric relations and their graphs. We know from Section
4.2 how to construct the matrix of a relation R.
If R is a relation on A, we will temporarily refer to elements of A as vertices
of R. This will facilitate the discussion.
Suppose now that vertices a and b of a relation R are merged into a new vertex
a! that replaces a and b to obtain the relation R!. To determine the matrix of R\
we proceed as follows.
Step 1 Let row i represent vertex a and row j represent vertex b. Replace row i
by the join of rows / and j. The join of two rc-tuples of O's and l's has a 1
in some position exactly when either of those two n-tuples has a 1 in that
position.
Step 2 Replace column i by the join of columns i and j.
Step 3 Restore the main diagonal to its original values in R.
Step 4 Delete row j and column j.
We make the following observation regarding Step 3. If e = (a9 b) e R and
we merge a and b9 then e would become a cycle of length 1 at a'. We do not want
to create this situation, since it does not correspond to "shrinking (a9 b) to zero."
Step 3 corrects for this occurrence.

Example 6 Figure 7.34 gives the matrices for the corresponding symmetric relations whose
graphs are given in Figure 7.33. In Figure 7.34(b), we have merged vertices v0
and v\ into v'0. Note that this is done by taking the join of the first two rows and
entering the result in row 1, doing the same for the columns, then restoring the
diagonal, and removing row 2 and column 2. If vertices v'0 and v2 in the graph
whose matrix is given by Figure 7.34(b) are merged, the resulting graph has the
matrix given by Figure 7.34(c). ♦

vo V\ V2 t>3 v4 v5 V6 v2 v3 v4 v3 v4
»0 us v6 v'o v5 V6
vo "0 1 1 0 0 1 Q~ "0 1 1 1 1 0" -o 1 1 1 1
•* <
V\ 1 0 0 1 1 0 0 v2 1 0 0 0 1 1 v3 1 0 0 0 0
v2 1 0 0 0 0 1 1 v3 1 0 0 0 0 0 v4 1 0 0 0 0
V3 0 1 0 0 0 0 0 v4 1 0 0 0 0 0 v5 1 0 0 0 0
V4 0 1 0 0 0 0 0 V5 1 1 0 0 0 0 V6 _ 1 0 0 0 0
v5 1 0 1 0 0 0 0 V6 _0 1 0 0 0 0_
V6 .0 0 1 0 0 0 0

(a) (b) (c)


Fig ure 7.34
7.4 Undirected Trees 293

We can now give an algorithm for finding a spanning tree for a symmetric,
connected relation R on the set A = {v\, v29..., vn}. The method is equivalent to
a special case of an algorithm called Prim's algorithm. The steps are as follows:
Step 1 Choose a vertex v\ of R9 and arrange the matrix of R so that the first row
corresponds to v\.
Step 2 Choose a vertex v2 of R such that (v\, U2) e /?, merge vi and v2 into a new
vertex v[, representing {v[9v2}9 and replace v\ by i/r Compute the matrix
of the resulting relation R'. Call the vertex v\ a merged vertex.
Step 3 Repeat Steps 1 and 2 on R' and on all subsequent relations until a relation
with a single vertex is obtained. At each stage, keep a record of the set of
original vertices that is represented by each merged vertex.
Step 4 Construct the spanning tree as follows. At each stage, when merging ver
tices a and b9 select an edge in R from one of the original vertices repre
sented by a to one of the original vertices represented by b.

Example 7 We apply Prim's algorithm to the symmetric relation whose graph is shown in
Figure 7.35. In Table7.1, we showthe matrices that are obtained when the original
set of vertices is reduced by merging until a single vertex is obtained, and at each
stage we keep track of the set of original vertices represented by each merged
vertex, as well as of the new vertex that is about to be merged.

TABLE 7.1
Original Vertices New Vertex
Represented by to Be Merged
Matrix Merged Vertices (with First Row)

abed
a -0011-
b 0 0 11

c 110 0
d .110 0.
a' b d
a' "0 1 r
b 1 0 1 a! «» {.a, c]
d 1 1 0_
a" d
Figure 7.35 a"
a" «> {a, c, b)
d
[il]
a'"
a'" [0] am «• {a, c, d9 b]

The first vertex chosen is a9 and we choose c as the vertex to be merged with
a9 since there is a 1 at vertex c in row 1. We also select the edge (a9 c) from the
original graph. Atthe second stage, there is a 1at vertex b in row 1,so wemerge b
with vertex a'. We selectan edgein the original relation R from a vertex of {a9 c]
to b9 say (c,b). At the third stage, we have to merge d with vertex a". Again, we
need an edge in R from a vertex of {a9 c, b) to d9 say (a9 d). The selected edges
(a, c), (c, b)9 and (a, d) form the spanning tree for R9 which is shown in Figure
7.36. Note that the first vertex selected becomes the root of the spanning tree that
is constructed. *
294 Chapter 7 Trees

7A Exercises

In Exercises 1 through 6, construct an undirected spanning 6. Let G be the graph shown in Figure 7.42.
tree for the connected graph G by removing edges in succes b
sion. Show the graph of the resulting undirected tree.
1. Let G be the graph shown in Figure 7.37.
a

Figure 7.42
In Exercises 7 through 12 (Figures 7.37 through 7.42), use
Prim's algorithm to construct a spanning tree for the con
nected graph shown. Use the indicated vertex as the root of
the treeand draw the digraph of the spanning treeproduced.
Figure 7.37
7. Figure 7.37; use e as the root.
2. Let G be the graph shown in Figure 7.38. 8. Figure 7.38; use 5 as the root.
1 2
9. Figure 7.39; use c as the root.
10. Figure 7.40; use 4 as the root.
11. Figure 7.41; use e as the root.
12. Figure 7.42; use d as the root.
3 4
13, Consider the connected graph shown in Figure 7.43.
Figure 7.38 Show the graphs of three different undirected spanning
trees.
3. Let G be the graph shown in Figure 7.39.

Figure 7.43
Figure 7.39 14. For the connected graph shown in Figure 7.44, show the
4. Let G be the graph shown in Figure 7.40. graphs of all undirected spanning trees.
2
1 2

2 7

Figure 7.40
5. Let G be the graph shown in Figure 7.41.
Figure 7.44 Figure 7.45
15. For the undirected tree shown in Figure 7.45, show the
digraphs of all spanning trees. How many are there?
Two trees, T\ and T2, are isomorphic if they are isomorphic
posets; that is, there is a one-to-one correspondence, f, be
tween the vertices of Tx and T2 and (a, b) is an edge in T\ if
and only ififia), fib)) is an edge in T2.
16. For the graph shown in Figure 7.44, show the graphs of
Figure 7.41 all nonisomorphic undirected spanning trees.
7.5 Minimal Spanning Trees 295

17. For the graph shown in Figure 7.45, show the graphs of
all nonisomorphic spanning trees.
18. For the graph in Figure 7.46, give all spanning trees.
/—\

Figure 7.48 Figure 7.49

23. For the graph in Figure 7.49, how many different span
Figure 7.46 Figure 7.47 ning trees are there?
19. For the graph in Figure 7.47, give all spanning trees.
24. State your conclusion for Figure 7.49 as a theorem and
20. For the graph in Figure 7.47, show the graphs of all noni prove it.
somorphic spanning trees.
25. For the graph shown in Figure 7.49, how many noniso
21. For the graph in Figure 7.48, how many different span
morphic spanning trees are there? Justify your answer.
ning trees are there?
22. For the graph shown in Figure 7.48, show the graphs of 26. Prove that a symmetric connected relation has an undi
all nonisomorphic spanning trees. rected spanning tree.

7.5 Minimal Spanning Trees


In many applications of symmetric connected relations, the (undirected) graph of
the relation models a situation in which the edges as well as the vertices carry
information. A weighted graph is a graph for which each edge is labeled with a
numerical value called its weight.

Example 1 The small town ofSocial Circle maintains a system of walking trails between the
recreational areas in town. Thesystem is modeled by the weighted graph in Figure
7.50, where the weights represent the distances inkilometers between sites. ♦

Example 2 Acommunications company is investigating the costs ofupgrading links between


the relay stations it owns. The weighted graph in Figure 7.51 shows the stations
andthecostin millions of dollars for upgrading eachlink. ♦

The weight of an edge (vi9 Vj) is sometimes referred to as the distance be


tween vertices vt and vj. A vertex u is a nearest neighbor of vertex v if u and

D 2 H

F 4 g

Figure 7.50 Figure 7.51


296 Chapter 7 Trees

v are adjacent and no other vertex is joined to v by an edge of lesser weight than
(w, v). Notice that, ungrammatically, v may have more than one nearest neighbor.

Example 3 In the graph shown in Figure 7.50, vertex C is a nearest neighbor of vertex A.
Vertices E and G are both nearest neighbors of vertex F. ♦

A vertex v is a nearest neighbor of a set of vertices V = {v\, v29..., Vk) in


a graph if v is adjacent to some member u,- of V and no other vertex adjacent to a
member of V is joined by an edge of lesser weight than (t>, vt). This vertex v may
belong to V.

Example 4 Referring to thegraph given in Figure 7.51, let V = {C, E9 J}. Then vertex D is a
nearest neighbor of V9 because (D, E) has weight 2.2 and no other vertex adjacent
to C, E9 or / is linked by an edge of lesser weight to one of these vertices. ♦

With applications of weighted graphs, it is often necessary to find an undi


rected spanning tree for which the total weight of the edges in the tree is as small
as possible. Such a spanning tree is called a minimal spanning tree. Prim's al
gorithm (Section 7.4) can easily be adapted to produce a minimal spanning tree
for a weighted graph. We restate Prim's algorithm as it would be applied to a
symmetric, connected relation given by its undirected weighted graph.

Algorithm PRIM'S ALGORITHM


Let R be a symmetric, connected relation with n vertices.
Step 1 Choose a vertex v\ of R. Let V = {v\} and E = { }.
Step 2 Choose a nearest neighbor vt of V that is adjacent to vJ9 Vj e V9 and for
which the edge (vi9 Vj) does not form a cyclewith members of E. Add vt
to V and add (vi9 Vj) to E.
Step 3 Repeat Step 2 until \E\=n-l. Then V contains all n vertices of R9 and
E contains the edges of a minimal spanningtree for R. •

In this version of Prim's algorithm, we beginat any vertexof R and constructa


minimal spanning treeby adding anedgeto a nearest neighbor of the set of vertices
already linked, as long as adding this edge does not complete a cycle. This is an
example of a greedy algorithm. At each stage we chose what is "best" based on
local conditions, rather than looking at theglobal situation. Greedy algorithms do
not always produce optimal solutions, but we can show that for Prim's algorithm
the solution is optimal.

THEOREM 1 Prim's algorithm, asgiven, produces a minimal spanning tree for the relation.
Proof
Let R have n vertices. Let T be the spanning tree for R produced by Prim's
algorithm. Suppose that the edges of 7, in the orderin which they were selected,
are t\9129...9 tn-\. For each i from 1 to az - 1, we define 7} to be the tree with
edges tu t2,...9 tt and T0 = [ }. Then T0 C 7\ c ••• C r„_i = T. We now
prove, by mathematical induction, that each 7} is contained in a minimal spanning
tree for R.

Basis Step
Clearly P(0): T0 = { }is contained in every minimal spanning treefor R.
7.5 Minimal Spanning Trees 297

Induction Step
sl ^-*^ ^2 Let P(k): Tk is contained in a minimal spanning tree V for R. We use P(k) to
show P(A: + 1): 71+1 is contained in a minimal spanning tree for R. By definition
we have {t\9129 ...9tk) c Tf. If tk+\ also belongs to 7", then Tk+X c r' and we
have P(& + 1) is true. If f*+i does not belong to V9 then 7" U {f*+i} must contain
a cycle. (Why?) This cycle would be as shown in Figure 7.52 for some edges
Figure 7.52 s\9s29...9sr in 7". Now the edges of this cycle cannot all be from Tk9 or 7*+i
would contain this cycle. Let si be the edge with smallest index / that is not in 7*.
Then si has one vertex in the tree Tk and one not in 7*. This means that when tk+\
was chosen by Prim's algorithm, si was also available. Thus the weight of 57 is at
least as large as that of f*+i. The spanning tree (7" —[si]) U {fy+i} contains 7i+i.
The weight of this tree is less than or equal to the weight of 7", so it is a minimal
spanning tree for R. Thus, P(k +1) is true. So 7n_i = T is contained in a minimal
spanning tree and must in fact be that minimal spanning tree. (Why?) •

Example 5 Social Circle, the town in Example 1, plans to pave some of the walking trails
to make them bicycle paths as well. As a first stage, the town wants to link all
the recreational areas with bicycle paths as cheaply as possible. Assuming that
construction costs are the same on all parts of the system, use Prim's algorithm to
find a plan for the town's paving.

Solution
Referring to Figure 7.50, if we choose A as the first vertex, the nearest neighbor
is C, 2 kilometers away. So (A, C) is the first edge selected. Considering the set
of vertices {A, C}, B is the nearest neighbor, and we may choose either (A, B) or
(£, C) as the next edge. Arbitrarily, we choose (£, C). B is a nearest neighbor
for {A, B9 C}9 but the only edge available (A, B) would make a cycle, so we must
move to a next nearest neighbor and choose (C, F) [or (C, £)]. Figures 7.53(a)
through (c) show the beginning steps and Figure 7.53(d) shows a possible final
result. Figure 7.53(e) shows a minimal spanning tree using Prim's algorithm be
ginning with vertex E. In either case, thebicycle paths would cover 21 kilometers.

Example 6 A minimal spanning tree for the communication network in Example 2 may be
found by using Prim's algorithm beginning at any vertex. Figure 7.54 shows a
minimal spanning tree produced by beginning at I. The total cost of upgrading
these links would be $20,200,000. ♦

(c)

D 2 H

id) (e)

Figure 7.53 Figure 7.54


298 Chapter 7 Trees

How is Prim's algorithm in Section 7.4 related to Prim's algorithm given in


this section? The earlier version is a special case where each edge has weight 1
and so any spanning tree is minimal. (Remember that each spanning tree will have
n —1 edges to reach n vertices.) This means that we can modify the matrix version
of Prim's algorithm in Section 7.4 to handle the general case of a weighted graph.
A matrix version might be more easily programmed.
The key to the modification is to consider an entry in the matrix as representing
not only the existence of an edge, but also the weight of the edge. Thus, we
construct a matrix containing the weights of edges, with a 0 to show there is no
edge between a pair of vertices as before. Figure 7.55 shows a connected weighted
graph and the associated matrix of weights.

A B C D
A "0 4 3 0
B 4 0 5 3
C 3 5 0 2
D _0 3 2 0

Figure 7.55

Algorithm PRIM'S ALGORITHM (Matrix Version)


Let R be a symmetric, connected relation with n vertices and M be the associated
matrix of weights.
Step 1 Choose the smallest entry in M, say m/7. Let a be the vertex that is repre
sented by row i and b the vertex represented by column j.
Step 2 Merge a with b as follows:
Replace row i with

mik ifmjk = 0
mjk ifmik=0
mik = 1 <k < n
mm(mik9 mjk) ifmik ^ 0, mjk ^ 0
0 if /w/jfe = ntjk = 0.
Replace column / with

mki ifmkj=0
mkj ifmki=0
mki = 1 < k < n
min(m*/, mkj) \fmki ^ 0, mkj # 0
0 if mkl = mkj = 0.
Replace the main diagonal with the original entries of M.
Delete row j and column j. Call the resulting matrix M;.
Step 3 RepeatSteps 1 and 2 on M' and subsequent matrices until a single vertex
is obtained. At each stage, keep a record of the set of original vertices that
is represented by each merged vertex.
Step 4 Construct the minimal spanning tree as follows: At each stage, when
merging vertices a and b9 select the edge represented by the minimal
weight from one of the original vertices represented by a to one of the
original vertices represented by b. •
7.5 Minimal Spanning Trees 299
Example 7 Apply the matrix version of Prim's algorithm to the graph and associated matrix
in Figure 7.55.

Solution
Either 2 may be selected as my. We choose mx4 and merge C and D. This
produces
A B C
A "0 4 3
M'= B 4 0 3
C 3 3 0

with C" «• {C, D) and the first edge (C, £>). We repeat Steps 1 and 2 on M' using
mi,3 = 3. This gives
A! fi
A!i' [0
r o 3]
B 3 [ 33 Oj
with A' «* {A, C, D} and the selection of edge (A, C). A final merge yields the
Figure 7.56 edge (B9 D). The minimal spanning tree is shown in Figure 7.56. ♦

If a symmetricconnectedrelation R has n vertices, then Prim's algorithm has


running time ®(n2). (This can be improved somewhat.) If R has relatively few
edges, a different algorithm may be more efficient. This is similar to the case for
determining whether a relation is transitive, as seen in Section 4.6. Kruskal's algo
rithm is anotherexample of a greedy algorithmthat produces an optimal solution.

Algorithm KRUSKAL'S ALGORITHM


Let Rbe a symmetric, connected relation withn vertices andlet S = {e\, e2,..., ek\
be the set of weighted edges of R.
Step 1 Choose an edge ex in 5 of least weight. Let E = {ex}. Replace 5 with
S-{e{}.
Step 2 Select an edge et in 5 of least weight that will not make a cycle with
members of E. Replace E with E U {et} and S with S - {*?;}.
Step 3 Repeat Step 2 until \E\ = n - 1. •

Since R has n vertices, the n - 1 edges in E will form a spanning tree. The
selection process in Step 2 guarantees that this is a minimal spanning tree. (We
omit the proof.) Roughly speaking, the running time of Kruskal's algorithm is
@(klg(k))9 where k is the number of edges in R.

Example 8 A minimal spanning tree from Kruskal'salgorithm for the walking trails in Exam
ple 1 is given in Figure 7.57. One sequence of edge selections is (D, E)9 (D, H)9
(A, C), (A, B), (E9 G), (£\ F)9 and (C, E) for a total weight of 21 kilometers.
Naturally eitherof the algorithms for minimal spanningtrees shouldproducetrees
of the same weight. ♦

Example 9 Use Kruskal's algorithm to find a minimal spanning tree for the relation given by
the graph in Figure 7.58.
300 Chapter 7 Trees

D 2 H

Solution
Initially, there are two edges of least weight, (B9 C) and (E9 F). Both of these are
selected. Next there are three edges, (A, G), (B9 G), and (D9 E)9 of weight 12.
All of these may be added without creating any cycles. Edge (F, G) of weight
14 is the remaining edge of least weight. Adding (F, G) gives us six edges for a
7-vertex graph, so a minimal spanning tree has been found. ♦

7.5 Exercises

In Exercises 1 through6, use Prim's algorithm as given in this In Exercises 7 through9, use the matrix version ofPrim's algo
section tofind a minimalspanning treefor the connected graph rithm tofind a minimalspanning treefor the indicated graph.
indicated. Use the specified vertex as the initial vertex.
7. Let G be the graph shown in Figure 7.61.
1. Let G be the graph shown in Figure 7.50. Begin at F.
2. Let G be the graph shown in Figure 7.51. Begin at A.
3. Let G be the graph shown in Figure 7.58. Begin at G.
4. Let G be the graph shown in Figure 7.59. Begin at E.
B 2 D F
5

G
"4 "
Figure 7.61
H
8. Let G be the graph shown in Figure 7.50.
Figure 7.59 9. Let G be the graph shown in Figure 7.59.
5. Let G be the graph shown in Figure 7.60. Begin at K. In Exercises 10 through 12, use Kruskal's algorithm tofind a
6. Let G be the graph shownin Figure 7.60. Begin at M. minimal spanning treefor the indicatedgraph.
10. Let G be the graph shown in Figure 7.51.
11. Let G be the graph shown in Figure 7.59.
12. Let G be the graph shown in Figure 7.60.
13. The distances between eight cities are given in the fol
lowing table. Use Kruskal's algorithm to find a minimal
spanning tree whose vertices are these cities. What is the
total distance for the tree?

14. Suppose that in constructing a minimal spanning tree a


certain edge must be included. Give a modified version of
Kruskal's algorithm for this case.
15. Redo Exercise 13 with the requirement that the route from
Atlanta to Augusta must be included. How much longer
Figure 7.60 does this make the tree?
Tips for Proofs 301

Abbeville Aiken Allendale Anderson Asheville Athens Atlanta Augusta


Abbeville 69 121 30 113 70 135 63

Aiken 69 52 97 170 117 163 16

Allendale 121 52 149 222 160 206 59


Anderson 30 97 149 92 63 122 93

Asheville 113 170 222 92 155 204 174

Athens 70 117 160 63 155 66 101

Atlanta 135 163 206 122 204 66 147

Augusta 63 16 59 93 174 101 147

16. Modify Prim's algorithm to handle the case of finding a the graph.
maximal spanning tree if a certain edge must be included 24. Prove or disprove that an edge of unique least weight in
in the tree. a connected graph must be included in any minimal span
17. Use the modification of Prim's algorithm developed in ning tree.
Exercise 16 on the graph shown in Figure 7.60 if the edge 25. A greedy algorithm does not always produce an optimal
from D to L must be included in the tree. solution. Consider the problem of selecting a specified
18. Modify Kruskal's algorithm so that it will produce a max amount of money from an unlimited supply of coins us
imal spanning tree, that is, one with the largest possible ing as few coins as possible. A greedy algorithm would be
sum of the weights. to select as many of the largest denomination coins first,
then as many of the next largest as possible, and so on un
19. Suppose that the graph in Figure 7.60 represents possible
til the specified amount has been selected. If the coins in
flows through a system of pipes. Find a spanning tree that
Acia are the 1-xebec, the 7-xebec, and the 11-xebec, con
gives the maximum possible flow in this system.
struct an example to show that the greedy algorithm does
20. Modify Prim's algorithm as given in this section to find a not always give a minimal solution.
maximal spanning tree.
26. Expand the proof of Theorem 1 by completingthe follow
21. Use the modified Prim's algorithm from Exercise 20 to ing.
find a maximal spanning tree for the graph in Figure 7.60.
(a) T must have n —1 edges, because
22. In Example 5, two different minimal spanning trees for
(b) T' U [tk+\} must contain a cycle, because
the same graph were displayed. When will a weighted
graph have a unique minimal spanning tree? Give reasons (c) iT' - {si}) U [tk+\} is a spanning tree for R9 because
for your answer.
23. Givea simple condition on the weights of a graph that will (d) If T is contained in a minimal spanning tree for /?,
guaranteethat there is a unique maximalspanningtreefor then T must be that tree. Why?

Tips for Proofs


Theuniqueness of theroot or of paths from the rootto othervertices forms theba
sis of many indirect proofs for statements abouttrees. [SeeTheorem 1(c), Section
7.1.] Counting arguments are also common in proofs about trees; for example,
Theorem 3, Section 7.4. Because a tree, like a lattice, is a relation with certain
properties, the various facts andrepresentations for relations are available to create
proofs for tree theorems. We see this in Theorem 2, Section 7.1. The development
of Prim's algorithm in Section 7.4 uses the matrix representation of a relation; this
representation could be used in a proof that the running time of the algorithm is
®(n2).
302 Chapter 7 Trees

• Key Ideas for Review


• Tree: relation on a finite set A such that there exists a vertex Preorder search: see page 280
vo e A with the property that there is a unique path from v0 Inorder search: see page 283
to any other vertex in A and no path from Vo to vq. Postorder search: see page 283
• Root of tree: vertex vo in the preceding definition Reverse Polish notation: see page 284
• Rooted tree (7\ v0): tree T with root v0 Searching general trees: see page 284
• Theorem: Let (7\ v0) be a rooted tree. Then Linked-list representation of a tree: see page 285
(a) There are no cycles in T.
Undirected tree: symmetric closure of a tree
(b) v0 is the only root of T.
Simple path: No two edges correspond to the same undi
(c) Each vertex in 7\ other than vo, has in-degree one, and
rected edge.
vo has in-degree zero.
Connected symmetric relation R: There is a path in R from
• Level: see page 271
any vertex to any other vertex.
• Height of a tree: the largest level number of a tree
Theorem: A tree with n vertices has n — \ edges.
• Leaves: vertices having no offspring
Spanning tree for symmetric connected relation R: tree
• Theorem: Let T be a rooted tree on a set A. Then reaching all the vertices of R and whose edges are edges
(a) T is irreflexive. ofR
(b) T is asymmetric. Undirected spanning tree: symmetric closure of a spanning
(c) If (a, b)eT and (b, c) e 7\ then ia, c) i T, for all a, tree
b9 and c in A.
Prim's algorithm: see page 293
• n-tree: tree in which every vertex has at most n offspring
Weighted graph: a graph whose edges are each labeled with
• Complete n-tree: see page 273 a numerical value
• Binary tree: 2-tree Distance between vertices vt and Vj\ weightof {v-l9 Vj)
• Theorem. If (7\ v0) is a rooted tree and v eT9 then T(v) is Nearest neighbor of v: see page 295
also a rooted tree with root v.
Minimal spanning tree: undirected spanning tree for which
• T(v): subtree of T beginning at v the total weight of the edges is as small as possible
• Positional binary tree: see page 276 Prim's algorithm (second version): see page 296
• Computer representation of trees: see page 277 Greedy algorithm: see page 296
• Huffman code tree: see page 278 Kruskal's algorithm: see page 299

I Chapter 7 Self-Test
1. In this chapter, what kind of mathematical object is a tree?
2. What changes in performing a preorder, inorder, or post-
order search?

3. What are the other three possible sequencesfor searching


a binary tree?
4. What advantagesmight a completen-tree have over a gen
eral n-tree as a data storage structure?
5. What information would help you decide between using
Prim's and Kruskal's algorithms to find a minimal span
ning tree?
6. Determine if the relation R = {(1, 7), (2, 3), (4,1),
(2, 6), (4, 5), (5, 3), (4, 2)} is a tree on the set A =
{1, 2, 3, 4, 5, 6, 7). If it is a tree, what is the root? If it
is not a tree, make the least number of changes necessary
Figure 7.62
to make it a tree and give the root.
7. Consider (7\ v0)9 the tree whose digraph is given in Fig (c) How many subtrees of T contain v4l
ure 7.62.
(d) List the siblings of v-j.
(a) What is the height of Tl
8. Let (7\ vo) be a rooted tree. Prove that if any edge is re
(b) List the leaves of T. moved from 7, then the resulting relation cannot be a tree.
Experiment 7 303

9. Construct the labeled tree representing the algebraic ex


pression

(((jc+3)(jc+3)-(jc-2)(jc-2))-t-(6jc-5))-I-(13-^jc).

10. The arrays LEFT, DATA, RIGHT give a doubly-linked-


list representation of a labeled binary, positional tree.
Construct the digraph of this tree.

INDEX LEFT DATA RIGHT

1 8 X 0

2 0 s 5

3 2 T 0
Figure 7.63
4 0 R 0
15. Give an undirected spanning tree for the relation whose
5 4 U 7 graph is given in Figure 7.64.
6 0 C 9
7 0 T 0

6 U 3

9 0 R 10

10 0 E 0

11. Here, to visit a vertex means to print the contents of the


vertex. Figure 7.64
(a) Show the result of performing a preorder search on
16. Use Prim's greedy algorithm to find a minimal spanning
the tree constructed in Problem 10.
tree for the graph in Figure 7.65. Use vertex E as the ini
(b) Show the results of performing a postorder search on tial vertex and list the edges in the order in which they are
the tree constructed in Problem 10. chosen.

12. Create a binary tree for which the results of perform


ing a preorder search are S\TRE\S2S3E2D and for
which the results of performing a postorder search are
DE2S3S2E\RTS\. Assume that to visit a vertex means
to print the contents of the vertex.

13. Draw a complete 3-tree with height 3 using the smallest


possible number of vertices. Figure 7.65
14. The digraph of a labeled, binary positional tree is shown 17. Use Kruskal's algorithm to find a minimal spanning tree
in Figure 7.63. Construct the digraph of the labeled or for the graph in Figure 7.65. List the edges in the order in
dered tree T such that T = BiT). which they are chosen.

| Experiment 7
Ways to store and retrieve information in binary trees are presented in Sections
7.2 and 7.3. In this experiment you will investigate another type of tree that is
frequently used for data storage.
A B-tree of degree k is a tree with the following properties:
1. All leaves are on the same level.
2. If it is not a leaf, the root has at least two children and at most k children.
3. Any vertexthat is not a leaf or the root has at least k/2 children and at most k
children.

Figure 1 The tree in Figure 1 is a B-tree of degree 3.


304 Chapter 7 Trees
Part I. Recall that the height of a tree is the length of the longest path from the
root to a leaf.

1. Draw three different B-trees of degree 3 with height 2. Your exam


ples should not also be of degree 2 or 1.
2. Draw three different B-trees of degree 4 (but not less) with height 3.
3. Give an example of a B-tree of degree 5 (but not less) with height 4.
4. Discuss the features of your examples in Questions 1 through 3 that
suggest that a B-tree would be a good storage structure.
Part II. The properties that define a B-tree of degree k not only restrict how the
tree can look, but also limit the number of leaves for a given height and
the height for a given number of leaves.
1. If T is a B-tree of degree k and T has height h9 what is the maximum
number of leaves that T can have? Explain your reasoning.
2. If T is a B-tree of degree k and T has height h, what is the minimum
number of leaves that T can have? Explain your reasoning.
3. If T is a B-tree of degree k and T has n leaves, what is the maximum
height that T can have? Explain your reasoning.
4. If T is a B-tree of degree k and T has n leaves, what is the minimum
height that T can have? Explain your reasoning.
5. Explain how your results in Part II, Questions 3 and 4, support your
conclusions in Part I, Question 4.
Topics in Graph Theory
Prerequisites: Chapters 3 and 5

Graph theory begins with very simple geometric ideas and has many powerful
applications. Some uses of graphs are discussed in Chapters 4, 6, and 7. In those
chapters a graph is associated with the digraph of a symmetric relation. Here we
give an alternate definition of graph that includes the more general multigraphs
and is more appropriate for the applications developed in this chapter.

Looking Back
Graph theory began in 1736 when Leonhard Euler solved a by the American mathematicians KennethAppel and Wolfgang
problemthat had been puzzlingthe good citizensof the townof Haken at the University of Illinois. Their proof used as a basis
Konigsberg in Prussia (now Kaliningrad in Russia). The river the work of Kempe and over 1000 hours of computer time to
Pregel divides the town into four sections, and in Euler's days check 1936 different map configurations. Their proof, the first
seven bridges connected these sections. The people wanted to of a major mathematical result by using a computer, was ini
know if it were possible to start at any location in town, cross tially met with considerable skepticism. Some years later, the
every bridge exactly once, and return to the starting location. number of configurations was reduced, but to date there is no
Euler showed that it is impossible to take such a walk. proof that does not involvesignificantuse of a computer.
A problemin graphtheory that attractedconsiderably more
attention is the four-color map problem. Frank Guthrie, a for
mer student of Augustus De Morgan, observed that he was able
to color the map of England so that no two adjacent counties
have the same color by using four different colors. He asked
his brother, who in 1852 was a student of De Morgan, to ask
De Morgan whether his conjecture that four colors will suffice
to color every map so that no two adjacent counties have the
same color was true. De Morgan publicized the problem, and
for years many people worked on the problem.
In 1879, Alfred Bray Kempe, a lawyer who had studied
mathematics at Cambridge University, published a proof of the
four-color conjecture that was highly acclaimed. Unfortunately,
his proof had a fatal error. The theorem was finally proved Wolfgang Haken (1) and Kenneth Appel (r)

305
306 Chapter 8 Topics in Graph Theory

8.1 Graphs
A graph G consists of a finite set V of objects called vertices, a finite set E of
objects called edges, and a function y that assigns to each edge a subset {v9w}9
where i; and w are vertices (and may be the same). We will write G = (V, E9 y)
when we need to name the parts of G. If e is an edge, and y(e) = [v9 w}9 we
say that e is an edge between v and w and that e is determined by v and w. The
vertices v and w are called the end points of e. If there is only one edge between
v and w9 we often identify e with the set {v9 w}. This should cause no confusion.
The restriction that there is only a finite number of vertices may be dropped, but
for the discussion here all graphs have a finite number of vertices.

Example 1 Let V = {1,2, 3,4} and E = {eu e2, e3, e4, e5}. Let y be defined by

Y{ex) = y(e5) = {1, 2}, y(e2) = {4, 3}, y(e3) = {1, 3}, y (e4) = {2,4}.

Then G = (V, E9 y) is a graph. ♦

Graphs are usually represented by pictures, using a point for each vertex and
a line for each edge. G in Example 1 is represented in Figure 8.1. We usually
omit the names of the edges, since they have no intrinsic meaning. Also, we may
want to put other more useful labels on the edges. We sometimes omit the labels
on vertices as well if the graphical information is adequate for the discussion.
Figure 8.1 Graphs are often used to record information about relationships or connec
tions. An edge between vt and Vj indicates a connection between the objects u,-
and Vj. In a pictorial representation of a graph, the connections are the most im
portant information, and generally a number of different pictures may represent
the same graph.

Example 2 Figures 8.2 and 8.3 also represent the graph G given inExample 1.

Figure 8.2

The degree of a vertex is the number of edges having that vertex as an end
point. A graphmaycontain an edgefrom a vertex to itself; such an edgeis referred
to as a loop. A loop contributes 2 to the degree of a vertex, since that vertex serves
as both end points of the loop.

Example 3 (a) In the graph in Figure 8.4, the vertex Ahas degree 2, vertex B has degree 4,
and vertex D has degree 3.
(b) In Figure 8.5, vertex a has degree 4, vertex e has degree 0, and vertex b has
degree 2.
(c) Each vertex of the graph in Figure 8.6 has degree 2. ♦

A vertex with degree 0 is called an isolated vertex. A pair of vertices that


determine an edge are adjacent vertices.
8.1 Graphs 307

Figure 8.4 Figure 8.5 Figure 8*6

Example 4 In Figure 8.5, vertex e is an isolated vertex. In Figure 8.5, a and b are adjacent
vertices; vertices a and d are not adjacent. ♦

A path jt in a graph G consists of a pair (Vn9 En) of sequences: a vertex


sequence Vn: V\, v2,..., vk and an edge sequence En : e\, e2,..., ek-\ for which
1. Each successive pair vi9 u,-+i of vertices is adjacent in G, and edge et has vx
and u/+i as end points, for i — 1, ...9k —1.
2. No edge occurs more than once in the edge sequence.
Thus we may begin at v\ and travel through the edges e\, e2,..., ek-\ to vk without
using any edge twice.
A circuit is a path that begins and ends at the same vertex. In Chapter 4
we called such paths cycles; the word "circuit" is more common in general graph
theory. A path is called simple if no vertex appears more than once in the vertex
sequence, except possibly if t»i = vk. In this case the path is called a simple
circuit. This expanded definition of path is needed to handle paths in graphs that
may have multiple edges between vertices. For the graph in Figure 8.4 we define
a path 7tx by sequences Vnx\ A, B9 E, D, D and Eni: p, r, t9 u9 and the path n2
by the sequences V„2: A, B9 A and En2: p9 q. The vertices alone would not be
sufficient to define these paths. For n\ we would not know which edge to travel
from A to B9 p or q9 and for n2 we would not know which edge to use first
and which to use second. The edges alone would not always be enough either,
for if we only knew the edge sequence p9 q for n2, we would not know if the
vertex sequence was A, fi, A or B9 A, B. If the vertices of a path have only one
edge between each adjacent pair, then the edge sequence is completely determined
by the vertex sequence. In this case we specify the path by the vertex sequence
alone and write n: v{9v2,...9vk. Thus for the graph in Figure 8.2 we can write
n3: 1, 3,4, 2, sincethispathcontains no adjacentvertices with two edges between
them. In cases such as this, it is not necessary to label the edges.

Example 5 (a) Paths ttx and n2 inthe graph of Figure 8.4were defined previously. Path n{ is
not simple, since vertex D appears twice, but n2 is a simple circuit, since the
only vertex appearing twice occurs at the beginning and at the end.
(b) Thepath n4: D, E9 5, C inthegraph ofFigure 8.4is simple. Here nomention
of edges is needed.
(c) Examples of paths in thegraph ofFigure 8.5aren5: a9 b, c, a andjt6 : d, c, a, a.
Here ns is a simple circuit, but ix^ is not simple.
(d) In Figure 8.6 the vertex sequence 1, 2, 3, 2 does not specify a path, since the
single edge between 2 and 3 would be traveled twice.
(e) The path7r7: c,a,b,c,d in Figure 8.5 is not simple. ♦
308 Chapter 8 Topics in Graph Theory
A graph is called connected if there is a path from any vertex to any other
vertex in the graph. Otherwise, the graph is disconnected. If the graph is discon
nected, the various connected pieces are called the components of the graph.

Example 6 The graphs in Figures 8.1 and8.4 are connected. Those in Figures 8.5 and 8.6 are
disconnected. The graph of Figure 8.6 has two components. ♦

Some important special families of graphs will be useful in our discussions.


We present them here.
u2
1. For each integer n > 1, we let Un denote the graph with n vertices and no
Figure 8.7 edges. Figure 8.7 shows U2 and U5. We call Un the discrete graph on n
vertices.
2. For each integer n > 1, let Kn denote the graph with vertices {v\, v2,..., vn}
and with an edge {u/, Vj] for every i and j. In other words, every vertex in
Kn is connected to every other vertex. In Figure 8.8 we show K^9 K^9 and K5.
The graph Kn is called the complete graph on n vertices. More generally, if
each vertex of a graph has the same degree as every other vertex, the graph is
called regular. The graphs Un are also regular.
3. For each integer n > 1, we let Ln denote the graph with n vertices
[v\9 v2,... 9vn} and with edges {vi9 vi+\] for 1 < / < n. We show L2 and L4
in Figure 8.9. We call Ln the linear graph on n vertices.

Figure 8.8 Figure 8.9

Example 7 All the Kn and Ln are connected, while the Un are disconnected for n > 1. Infact,
the graph Un has exactly n components. 4

Subgraphs and Quotient Graphs


Suppose that G = (V7, E9 y) is a graph. Choose a subset E\ of the edges in E
and a subset V\ of the vertices in V, so that V\ contains (at least) all the end points
of edges in E\. Then H = (Vls E\9 y\) is also a graph where y\ is y restricted
to edges in E\. Such a graph H is called a subgraph of G. Subgraphs play an
important role in analyzinggraph properties.

Example 8 The graphs shown inFigures 8.11, 8.12, and 8.13 are each a subgraph ofthe graph
shown in Figure 8.10. 4

One of the most important subgraphs is the one that arises by deleting one
edge and no vertices. If G = (V7, E9 y) is a graph and e e E9 then we denote by
Ge the subgraph obtained by omitting the edge e from E and keeping all vertices.
If G is the graph of Figure 8.10, and e = {a9 b}9 then Ge is the graph shown in
Figure 8.13.
8.1 Graphs 309

^. ^
Figure 8.10 Figure 8.11 Figure 8.12 Figure 8.13

Our second important construction is defined for graphs without multiple edges
between the same vertices. Suppose that G = (V9 E9 y) is such a graph and that
R is an equivalence relation on the set V. Then we construct the quotient graph
GR in thefollowing way. Thevertices of GR are the equivalence classes of V pro
duced by R (see Section 4.5). If [v] and [w] are the equivalence classes of vertices
v and w of G, then there is an edge in GR from [v] to [w] if and only if some
vertex in [v] is connected to some vertex in [w] in the graph G. Informally, this
just says thatweget GR by merging all the vertices in eachequivalence class into
a single vertex and combining any edges that are superimposed by such a process.

Example 9 Let G be the graph of Figure 8.14 (which has no multiple edges), and let R be the
equivalence relation on V defined by the partition

{{a9m9i}9{b9f9j},{c9g9k}9{d9h9l}}.

Then GR is shown in Figure 8.15.

[a] [b]

[a] lb]
lY\
W [g]

[d\ [c]

Figure 8.14 Figure 8.15

If S is also an equivalence relation on V defined by the partition

{{/, ;, k9 /}, {a9 m}9 {/, b9 c}9 [d}9 {g}9 {h}}9

then thequotient graph Gs is shown in Figure 8.16. ♦

Again, one of the most important cases arises from using just one edge. If
e is an edge between vertex v and vertex w in a graph G = {V9 E9 y}9 then we
consider the equivalence relation whose partition consists of {v9 w) and {v/}, for
each vt ^ v9 vt ^ w. That is, we merge v and w and leave everything else alone.
The resulting quotient graph is denoted Ge. If G is the graphof Figure 8.14, and
Figure 8.17 e = {*\ j}>then Ge is the graph shown in Figure 8.17.
310 Chapter 8 Topics in Graph Theory
8.1 Exercises
In Exercises 1 through 4 (Figures 8.18 through 8.21), give For Exercises 19 through 22, use the graph G in Figure 8.22.
V, the set of vertices, and E, the set of edges, for the graph b
G = (V\ E, y).
2.

6 Figure 8.22
Figure 8.18
19. If R is the equivalence relation defined by the partition
{{a, /}, {e, b, d], {c}}, find the quotientgraph, GR.
1- 20. If R is the equivalence relation defined by the partition
f2
[{a, b), {e}, {d}, {/, c}}, find the quotient graph, GR.
3, A 21. (a) Give the largest subgraph of G that does not con
t5
tain /.
6< > —^ >7 (b) Give the largest subgraph of G that does not con
tain a.
Figure 8.20 Figure 8.21
22. Let e\ be the edge between c and /. Draw the graph of
(a) Ge (b) G*'
5. Give two subgraphs with three vertices for the graph
ForExercises 23 and 24, use the graph G in Figure 8.23.
shown in Figure 8.20.
11
6. Give three subgraphs with four vertices and four edges for
the graph shown in Figure 8.21.
7. Draw a picture of the graph G = (V, E,y), where
V = {a,b,c,d,e}9 E = {e\,e2,e3,e4,e5,e6}, and
1 Yie\) = yie5) = [a,c}9 yie2) = {a,d}9 yie3) = {e, c},
yie4) = {b9 c}, and yie6) = {e, d}.
8. Draw a picture of the graph G = {V,E9y)9 where
V = {a9b9c,d,e, f,g,h}9 E = {eu e2,..., e9}9 and
yie{) = {a,c}9 yie2) = {a,b}9 yie3) = {d,c}, yie4) = Figure 8.23
[b,d}9 yie5) = [e,a}9 yie6) = {e,d}9 yie7) = {/,*},
Yie%) = {e, g}, and y(e9) = {/, g). 23. Let R = {(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7),
(8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13),
9. Give the degree of each vertex in Figure 8.18. (14, 14), (15, 15), (16, 16), (1, 10), (10, 1), (3, 12),
10. Give the degree of each vertex in Figure 8.20. (12, 3), (5, 14), (14, 5), (2, 11), (11, 2), (4, 13), (13,4),
(6, 15), (15, 6), (7, 16), (16, 7), (8, 9), (9, 8)}. Draw the
11. List all paths that begin at a in Figure 8.19.
quotientgraph GR.
12. List three circuits that begin at 5 in Figure 8.21.
24. Let R = {(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7),
13. Draw the complete graph on seven vertices. (8, 8), (9, 9), (10, 10), (11,11), (12, 12), (13, 13),
(14,14), (15, 15), (16, 16), (1, 2), (2,1), (3,4), (4, 3),
14. Consider Kni the complete graph on n vertices. What is
(5, 6), (6, 5), (7, 8), (8, 7), (9, 16), (16, 9), (10, 11),
the degree of each vertex?
(11, 10), (12, 13), (13, 12), (14, 15), (15, 14)}. Draw the
15. Which of the graphs in Exercises 1 through4 are regular? quotientgraph GR.
16. Give an example of a regular,connected graph on six ver 25. Complete the following statement. Every linear graph on
tices that is not complete. n vertices must have edges. Explain your answer.
17. Give an example of a graph on five vertices with exactly 26. What is the total number of edges in Kn, the complete
two components. graph on n vertices? Justify your answer.
18. Give an example of a graph that is regular, but not com 27. Restate the definition of isomorphic trees to define iso
plete, with each vertex having degree three. morphic graphs.
8.2 Euler Paths and Circuits 311

(a) (b) (d)


Figure 8.24

28. Prove or disprove that the graphs shown in Figures 8.24(a) from the definition of graph in this section.
and (b) are isomorphic. 32. Prove that if a graph G has no loops or multiple edges,
29. Prove or disprove that the graphs shown in Figures 8.24(a) then twice the number of edges is equal to the sum of the
and (c) are isomorphic. degrees of all vertices.
30. Prove or disprove that the graphs shown in Figures 8.24(a) 33. Use the result of Exercise 32 to prove that if a graph G has
and (d) are isomorphic. no loops or multiple edges, then the number of vertices of
31. Explain how the definition of digraph in Chapter 4 differs odd degree is an even number.

So2 Euler Paths and Circuits


In this section and the next, we consider broad categories of problems for which
graph theory is used. In the first typeof problem, the task is to travel a path using
each edge of the graph exactly once. It may or may not be necessary to begin and
end at the same vertex. A simple example of this is the common puzzle problem
that asks the solver to trace a geometric figure without lifting pencil from paper or
tracing an edge more than once.
A path in a graph G is called an Euler path if it includes every edge exactly
once. An Euler circuit is an Euler path that is a circuit. Leonhard Euler (1707-
1783) worked in many areas of mathematics. The names "Eulerpath" and "Euler
circuit" recognize his work with the Konigsberg Bridge problem.
1 Figure 8.25 shows thestreet map of a small neighborhood. A recycling ordinance
has been passed, and those responsible for picking up the recyclables must start
and end each trip by having the truck in the recycling terminal. They would like

Figure 8.25
312 Chapter 8 Topics in Graph Theory
to plan the truck route so that the entire neighborhood can be covered and each
street need be traveled only once. A graph can be constructed having one vertex
for each intersection and an edge for each street between any two intersections.
The problem then is to find an Euler circuitfor this graph. ♦

Example 2 (a) AnEuler path in Figure 8.26 is tt: E9 D9 B9 A, C, D.


(b) One Euler circuit in the graph of Figure 8.27 is n : 5, 3, 2, 1, 3, 4, 5. ♦

Figure 8.26 Figure 8.27

A little experimentation will show that no Euler circuit is possible for the
graph in Figure 8.26. We also see that an Euler path is not possible for the graph
in Figure 8.6 in Section 8.1. (Why?)

j: Room A RoomB
±

RoomC

D (Outside)
u
Figure 8.28 Figure 8.29

Example 3 Consider the floor plan of a three-room structure that is shown in Figure 8.28.
Each room is connected to every room that it shares a wall with and to the outside
along each wall. The problem is this: Is it possible to begin in a room or outside
and take a walk that goes through each door exactly once? This diagram can also
be formulated as a graph where each room and the outside constitute a vertex and
an edge corresponds to each door. A possible graph for this structure is shown in
Figure 8.29. The translation of the problem is whether or not there exists an Euler
path for this graph. We will solve this problem later. ♦

Two questions arise naturally at this point. Is it possible to determine whether


an Euler path or Euler circuit exists without actually finding it? If there must be an
Euler path or circuit, is there an efficient way to find one?
Consider again the graphs in Example 2. In Figure 8.26 the edge {D9 E] must
be either the first or the last traveled, because there is no other way to travel to or
from vertex E. This means that if G has a vertex of degree 1, there cannot be an
8.2 Euler Paths and Circuits 313

Euler circuit, and if there is an Euler path, it must begin or end at this vertex. A
similar argument applies to any vertex v of odd degree, say 2n + 1. We may travel
in on one of these edges and out on another one n times, leaving one edge from v
untraveled. This last edge may be used for leaving v or arriving at v9 but not both,
so a circuit cannot be completed. We have just shown the first of the following
results.

THEOREM 1 (a) If a graph G has a vertex of odd degree, there can be no Euler circuit in G.
(b) If G is a connected graph and every vertex has even degree, then there is an
Euler circuit in G.

Proof
(b) Suppose that there are connected graphs where every vertex has even de
gree, but there is no Euler circuit. Choose such a G with the smallest
numberof edges. G must have more than one vertex since, if there were
only one vertex of even degree, there is clearly an Euler circuit.
We show first that G must have at least one circuit. If v is a fixed
vertex of G, then since G is connected and has more than one vertex,
there must be an edge between v and some other vertex v\. This is a
simple path (of length 1) and so simple paths exist. Let 7r0 be a simple
path in G having the longest possible length, and let its vertex sequence
be v\, v29..., vs. Since vs has even degree and it0 uses only one edge
that has vs as a vertex, there must be an edge e not in 7r0 that also has vs
as a vertex. If the other vertex of e is not one of the vi9 then we could
construct a simple path longer than it0, which is a contradiction. Thus e
has some vt as its other vertex, and therefore we can construct a circuit
Vi,Vi+u...,vS9Vi inG.
Since we now know that G has circuits, we may choose a circuit it in
G that has the longest possible length. Since we assumed that G has no
Euler circuits, it cannot contain all the edges of G. Let Gi be the graph
formed from G by deleting all edges in it (but no vertices). Since it is a
circuit, deleting its edges will reduce the degree of every vertex by 0 or
2, so G\ is also a graph with all vertices of even degree. The graph G{
may not be connected, but we can choose a largest connected component
(piece) and call this graph G2 (G2 may be G{). Now G2 hasfewer edges
than G, and so (becauseof the way G was chosen), G2 must have an Euler
path it'.
If it' passes through all the vertices on G, then it andit' clearly have
vertices in common. If not, then there must be an edge e in G between
some vertex vf in it'9 and some vertex v not in it'. Otherwise we could
notgetfrom vertices in it' to the othervertices in G, and G would not be
connected. Since e is not in it'9 it must have been deleted when G\ was
created from G, and so must be an edge in it. Then v' is also in the vertex
sequence of it9 and so in any case it and it' have at least onevertex v' in
common. We can then construct a circuit in G that is longer than it by
combining it and it' at i/. This is a contradiction, since it was chosen to
be the longest possible circuit in G. Hence the existence of the graph G
always produces a contradiction, and so no such graph is possible. •

The strategy of this proof is one we have used before: Suppose there is a
largest (smallest) object and construct a larger (smaller) object of the same type
thereby creating a contradiction. Here we have it, the longest possible circuit that
314 Chapter 8 Topics in Graph Theory
begins and ends at v9 in G, and we construct a longer circuit that begins and ends
at v.
We have proved that if G has vertices of odd degree, it is not possible to
construct an Euler circuit for G, but an Euler path may be possible. Our earlier
discussion noted that a vertex of odd degree must be either the beginning or the
end of any possible Euler path. We have the following theorem.

THEOREM 2 (a) If a graph G has more than two vertices of odd degree, then there can be no
Euler path in G.
(b) If G is connected and has exactly two vertices of odd degree, there is an Euler
path in G. Any Euler path in G must begin at one vertex of odd degree and
end at the other.

Proof
(a) Let v\9 v29 v3 be vertices of odd degree. Any possible Euler path must
leave (or arrive at) each of v\, v2, v3 with no way to return (or leave) since
each of these vertices has odd degree. One vertex of these three vertices
may be the beginning of the Euler path and another the end, but this leaves
the third vertex at one end of an untraveled edge. Thus there is no Euler
path.
(b) Let u and v be the two vertices of odd degree. Adding the edge {u9 v} to
G produces a connected graph G' all of whose vertices have even degree.
By Theorem 1(b), there is an Euler circuit it' in G'. Omitting {w, v] from
it' produces an Euler path that begins at u (or v) and ends at v (or u). •

Example 4 Which of thegraphs in Figures 8.30, 8.31, and8.32 have an Eulercircuit, an Euler
path but not an Euler circuit, or neither?

^^ T

O —^>

Figure 8.30 Figure 8.31 Figure 8.32

Solution
(a) In Figure 8.30, each of the four vertices has degree 3; thus, by Theorems
1 and 2, there is neither an Euler circuit nor an Euler path.
(b) The graph in Figure 8.31 has exactly two vertices of odd degree. There is
no Euler circuit, but there must be an Euler path.
(c) In Figure 8.32, every vertex has even degree; thus the graph must have an
Euler circuit. ♦

Example 5 Let us return to Example 3. We see that the four vertices have degrees 4, 4, 5, and
7, respectively. Thus the problem can be solved by Theorem 2; that is, there is an
Euler path. One is shown in Figure 8.33. Using the labels of Figure 8.29, this path
it is specified by Vn : C, D, C, A, £>, A, fi, £>, B9 C and En : /, h9 f9 c, a9 d9 b9 e9
gj- ♦

Theorems 1 and 2 are examples of existence theorems. They guarantee the


existence of an object of a certain type, but they give no information on how to
8.2 Euler Paths and Circuits 315

D (Outside)

Figure 8.33

produce the object. There is one hint in Theorem 2(b) about how to proceed. In
Figure 8.34, an Euler path must begin (or end) at B and end (or begin) at C. One
possible Euler path for this graph is specified by Vn: B, A, D,C, A, B,C and
En : a, c, d, /, b, e.
We next give an algorithm that produces an Euler circuit for a connected graph
with no vertices of odd degree. We require an additional definition before stating
the algorithm. An edge is a bridge in a connected graph G if deleting it would
create a disconnected graph. For example, in the graph of Figure 8.4, Section 8.1,
Figure 8.34 {B, E) is a bridge.

Algorithm FLEURY'S ALGORITHM


Let G = (V, E, y) be a connected graph with each vertex of even degree.
Step 1 Select an edge e\ that is not a bridge in G. Let its vertices be v\9V2. Let n
be specified by Vn: v\9 v2 and En: e\. Remove e\ from E and let G\ be
the resulting subgraph of G.
Step 2 Suppose that V„: v\, v2, •• •» vk and En: e\, e-i,..., ek-\ have been con
structed so far, and that all of these edges and any resulting isolated ver
tices have been removed from V and E to form G*_i. Since y* has even
degree, and e*_i ends there, there must be an edge eu in Gk-\ that also has
Vk as a vertex. If there is more than one such edge, select one that is not a
bridge for G*_i. Denote the vertex of e* other than u* by u*+i, and extend
V* and En to V* : vu v2,..., u*, u*+i and £„ : eue2,..., e*_i, e*. Then
delete eu and any isolated vertices from Gk-\ to form G*.
Step 3 Repeat Step 2 until no edges remain in E. •

Example 6 Use Fleury's algorithm to construct an Euler circuitfor the graphin Figure8.35.

Figure 8.35
316 Chapter 8 Topics in Graph Theory
Solution
According to Step 1, we may begin anywhere. Arbitrarily choose vertex A. We
summarize the results of applying Step 2 repeatedly in Table 8.1.

Current Path Next Edge Reasoning


7t: A {A, 5} Noedge iiipi^Aisa bridgeS|p^e anyone^
7t: A,B I/:-;-... ,,;.,-• t « l !
it: A, J?, C illftill
n: A9B,C,A Jp&if tSMfc
n: A,B,CiA,D !*• v {D,m Only one ii^S from ©tenialiK
it: A,B, C,A, D, C {C,E\ Only cmee^
n: A, B, C, A, D, C, E •tv- :'• . •':
:::::MMM: I^Na^dg^^
7t: A, J?, C,A,D, C, E, G i|I||| lltlgitll
:-:|fJ|:l;s.
n: A^BX.A.D.C.E.G.F ""'Iffltl
n: A,B,CiA,D,C,E,G,F,E {E,mm Onlyone^^M
it: A, B, C, A, D, C, E, G, F, E, H IV _ {H,m Only one i^efcom Hrenm$^
it : A, 5, C, A, Z), C, E, G, F, £, #, GIife ^m:m& Only pi^^
7t: A, 5, C, A, Z), C, £, G, F, £, #, G|||l

The edges in Figure 8.36 have been numbered in the order of their choice in
applying Step 2. In several places, other choices could have been made. In general,
if a graph has an Euler circuit, it is likely to have several different Euler circuits.^

Figure 8.36

8.2 Exercises

In Exercises 1 through 8, (Figures 8.37 through 8.44), tell


whether the graph has an Euler circuit, an Euler path but no T T
Euler circuit, or neither. Give reasons for your choice.
si ,*±- .
b 2.

6(1 —^i

Figure 8.39 Figure 8.40


6
Figure 8.37 Figure 8.38
8.2 Euler Paths and Circuits 317

12. Use Fleury's algorithm to produce an Euler circuit for the


graph in Figure 8.45.
13. An art museum arranged its current exhibit in the five
rooms shown in Figure 8.48. Is there a way to tour the
exhibit so that you pass through each door exactly once?
If so, give a sketch of your tour.
Figure 8.41
h
6.

Figure 8.42 Figure 8.48


14. At the door of an historical mansion, you receive a copy
of the floor plan for the house (Figure 8.49). Is it possible
to visit every room in the house by passing through each
door exactly once? Explain your reasoning.
H h
Figure 8.43
"1
iZ

H h

Figure 8.44
H h
In Exercises 9 and 10, (Figures 8.45 and 8.46), tell if it is pos
sible to trace thefigure without lifting thepencil. Explain your Figure 8.49
reasoning.
In Exercises 15 through 18 (Figures 8.50 through 8.53), no
9. Euler circuit is possible for the graph given. For each graph,
show the minimum numberofedges that would need to be trav
eled twice in order to travel every edge and return to the start
ing vertex.

Figure 8.45 16. <i—i

10.

a ii ii 1

Figure 8.50
9 • • (

Figure 8.46 Figure 8.51


11. Use Fleury's algorithm to produce an Euler circuit for the 17. i a a a a

graph in Figure 8.47.


<» <> 1> a a u

i 1> (i ii

O O O i>

Figure 8.52
Figure 8.47
318 Chapter 8 Topics in Graph Theory

18. circuit for the modified version of the graph. Begin at A.


r ;;a 21. For which values of n does the complete graph on n ver
tices, Kn, have an Euler circuit?
A1 22. Let G and H be a pair of isomorphic graphs. Prove or
disprove that if there is an Euler circuit in G, then there is
one in H also.
(

v 1 1 1 1 i 1i i \) 23. Consider the Hasse diagram of the Boolean algebra Bn as


an undirected graph with the vertices labeled as usual by
Figure 8.53 strings of 0's and l's of length n. (See Section 6.4.) Prove
19. Modify the graph in Figure 8.52 by adding the minimum that there is an edge between two vertices in this graph
number of duplicate edges needed to make all vertices if and only if the strings labeling the end points differ in
have even degree. Use Fleury's algorithm to find an Euler exactly one position.
circuit for the modified version of the graph. Begin at the 24. With Bn as described in Exercise 23, which of the follow
upper-left corner. ing graphs have an Euler circuit?
20. Modify the graph in Figure 8.53 by adding the minimum (a) B2 (b) B3 (c) B4 (d) B5
number of duplicate edges needed to make all vertices 25. In general, the Hasse diagrams of which Bn have an Euler
have even degree. Use Fleury's algorithm to find an Euler circuit? Justify your answer.

8.3 Hamiltonian Paths and Circuits

We turn now to the second category of graph problems in which the task is to visit
each vertex exactly once, with the exception of the beginning vertex if it must also
be the last vertex. For example, such a path would be useful to someone who must
service a set of vending machines on a regular basis. Each vending machine could
be represented by a vertex.
A Hamiltonian path is a path that contains each vertex exactly once. A
Hamiltonian circuit is a circuit that contains each vertex exactly once except for
the first vertex, which is also the last. This sort of path is named for the mathemati
cian Sir William Hamilton, who developed and marketed a game consisting of a
wooden graph in the shape of a regular dodecahedron and instructions to find what
we have called a Hamiltonian circuit. A planar version of this solid is shown in
Figure 8.54(a), with a Hamiltonian circuit (one of many) shown in Figure 8.54(b)
by the consecutively numbered vertices.
It is clear that loops and multiple edges are of no use in finding Hamiltonian
circuits, since loops could not be used, and only one edge can be used between
any two vertices. Thus we will suppose that any graph we mention has no loops
or multiple edges.
8.3 Hamiltonian Paths and Circuits 319

Example 1 Consider the graph in Figure 8.55. The path a, b, c, d, e is a Hamiltonian path
because it contains each vertex exactly once. It is not hard to see, however, that
there is no Hamiltonian circuit for this graph. For the graph shown in Figure 8.56,
the path A, D, C, B, A is a Hamiltonian circuit. In Figures 8.57 and 8.58, no
Hamiltonian path is possible. (Verify this.) ♦

o
a

Figure 8.55 Figure 8.56 Figure 8.57 Figure 8.58

Example 2 Any complete graph Kn has Hamiltonian circuits. In fact, starting at any vertex,
you can visit the other vertices sequentially in any desired order. ♦

Questions analogous to those about Euler paths and circuits can be asked about
Hamiltonian paths and circuits. Is it possible to determine whether a Hamiltonian
path or circuit exists? If there must be a Hamiltonian path or circuit, is there an
efficient way to find it? Surprisingly, considering Theorems 1 and 2 of Section 8.2,
the first question about Hamiltonian paths and circuits has not been completely an
swered and the second is still unanswered as well. However, we can make several
observations based on the examples.
If a graph G on n vertices has a Hamiltonian circuit, then G must have at least
n edges.
We now state some partial answers that say if a graph G has "enough" edges, a
Hamiltonian circuit can be found. These are again existence statements; no method
for constructing a Hamiltonian circuit is given.

THEOREM 1 Let G be a connected graph with n vertices, n > 2, and no loops or multiple
edges. G has a Hamiltonian circuit if for any two vertices u and v of G that are
not adjacent, the degree of u plus the degree of v is greater than or equal to n. M
We omit the proof of this result, but from it we can prove the following:

Corollary 1 G has a Hamiltonian circuit if each vertex hasdegree greater than or equal to n/2.

Proof
The sumof thedegrees of anytwovertices is at least | +§ = n, so the hypotheses
of Theorem 1 hold. •

THEOREM 2 Let the number of edges of G be m. Then G has a Hamiltonian circuit if m >
\{n2 —3n + 6) (recall that nisthe number ofvertices).
Proof
Suppose that u and v are any two vertices of G that are not adjacent. We write
deg(w) for the degree of u. Let H be the graph produced by eliminating u and v
from G along with any edges that have u or v as end points. Then H has n —2
320 Chapter 8 Topics in Graph Theory

vertices and m —deg(w) —deg(v) edges (one fewer edge would have been removed
if u and v had been adjacent). The maximum number of edges that H could
possibly have is n-2C2 (see Section 3.2). This happens when there is an edge
connecting every distinct pair of vertices. Thus the number of edges of H is at
most
n (n-2)(n-3) 1 2
n-iCi = or -(nz -5/2 + 6).

We then have m—deg(w) - deg(v) < \{n2 —5n + 6). Therefore, deg(w) +
deg(v) > m—\{n2 —5n + 6). By the hypothesis ofthe theorem,
1 9 1 9
deg(w) + deg(u) > -(n2 - 3n + 6) - -(n2 -5n + 6)=n.

Thus the result follows from Theorem 1. •

Example 3 The converses of Theorems 1 and 2 given previously are not true; that is, the
conditions given are sufficient, but not necessary, for the conclusion. Consider the
graph represented by Figure 8.59. Here n, the number of vertices, is 8, each vertex
has degree 2, and deg(w) + deg(u) = 4 for every pair of nonadjacent vertices u
and v. The total number of edges is also 8. Thus the premises of Theorems 1 and
uC 2 fail to be satisfied, but there are certainly Hamiltonian circuits for this graph. ♦

D The problem we have been considering has a number of important variations.


In one case, the edges may have weights representing distance, cost, and the like.
The problem is then to find a Hamiltonian circuit (or path) for which the total sum
of weights in the path is a minimum. For example, the vertices might represent
Figure 8.59 cities; the edges, lines of transportation; and the weight of an edge, the cost of
traveling along that edge. This version of the problem is often called the traveling
salesperson problem. Another important category of problems involving graphs
with weights assigned to edges is discussed in Section 7.5.

8.3 Exercises

In Exercises 1 through 6 (Figures 8.60 through 8.65), deter


mine whether the graph shown has a Hamiltonian circuit, a
Hamiltonian path butno Hamiltonian circuit, or neither. If the
graph has a Hamiltonian circuit, give the circuit.
Figure 8.64
Figure 8.65

7. Give two Hamiltonian circuits in K5 that have no edges in


common.

Figure 8.60 Figure 8.61 In Exercises 8 through 11 (Figures 8.66 through 8.69), find a
Hamiltonian circuit for the graph given.
8.

T T

64 ^1 7 Figure 8.63

Figure 8.62 Figure 8.66


8.4 Transport Networks 321

In Exercises 12 through 15, find a Hamiltonian circuit ofmin


imal weight for the graph represented by the given figure.
12, Figure 8.66 13. Figure 8.67
14 Figure 8.68 15. Figure 8.69
16, Find a Hamiltonian circuit of minimal weight for the
graph represented by Figure 8.66 if you must begin and
end at D.
Figure 8.67 17, Find a Hamiltonian circuit of minimal weight for the
graph represented by Figure 8.67 if you must begin and
10. end at F.

18. For the complete graph on n vertices, Kn, n > 3,


(a) how many edges must a Hamiltonian circuit have?
(b) how many different Hamiltonian circuits, beginning
at a fixed vertex, are there?
19, Prove that Kn, the complete graph on n vertices with
n > 3, has (n — 1)! Hamiltonian circuits.
20, Give an example of a graph with at least four vertices with
a circuit that is both an Euler and a Hamiltonian circuit.

21. Give an example of a graph that has an Euler circuit and


Figure 8.68 a Hamiltonian circuit that are not the same.

22, Let G = (V, E, y) be a graph with \V\ = n that has no


11. multiple edges. The relation R on V defined by G can be
represented by a matrix, MR. Explain how to use MRoo
(see Section 4.3) to determine if G is connected.
23. Using the usual vertex labels of strings of 0's and 1's, give
a Hamiltonian circuit for the Hasse diagram of £3.
24, Using the usual vertex labels of strings of 0's and l's, give
a Hamiltonian circuit for the Hasse diagram of B4.
25, The problem of finding a Hamiltonian circuit for the
Hasse diagram of Bn is equivalent to a problem about
Figure 8.69 strings of 0's and l's of length n. State this problem.

8.4 Transport Networks


We have previously examined several uses of labeled graphs. In this section we
return to the idea of a directed graph (digraph). An important use of labeled di
graphs is to model what are commonly called transport networks. Consider the
labeled digraph shown in Figure 8.70. This might represent a pipeline that carries
water from vertex 1 to vertex 6 as part of a municipal water system. The label on
an edge represents the maximum flow that can be passed through that edge and is
Figure 8.70 called the capacity of the edge. Many situations can be modeled in this way. For
instance, Figure 8.70 might as easily represent an oil pipeline, a highway system,
a communications network, or an electric power grid. The vertices of a network
are usually called nodes and may denote pumping stations, shipping depots, relay
stations, or highway interchanges.
More formally, a transport network, or a network, is a connected digraph N
with the following properties:
(a) There is a unique node, the source, that has in-degree 0. We generally label
the source node 1.
322 Chapter 8 Topics in Graph Theory

(b) There is a unique node, the sink, that has out-degree 0. If N has n nodes, we
generally label the sink as node n.
(c) The graph N is labeled. The label, C/7, on edge (/, j) is a nonnegative number
called the capacity of the edge.
For simplicity we also assume that all edges carry material in one direction only;
that is, if (i, j) is in N, then (j, i) is not.

Flows

The purpose of a network is to implement a flow of water, oil, electricity, traffic,


or whatever the network is designed to carry. Mathematically, a flow in a network
N is a function that assigns to each edge (i, j) of N a. nonnegative number Ftj
that does not exceed Qj. Intuitively, F/y represents the amount of material passing
through the edge (i, j) when the flow is F. Informally, we refer to Fy as the flow
through edge (/, j). We also require that for each node other than the source and
sink, the sum of the f}* on edges entering node k must be equal to the sum of
the Fkj on edges leaving node k. This means that material cannot accumulate, be
created, dissipate, or be lost at any node other than the source or the sink. This is
called conservation of flow. A consequence of this requirement is that the sum
of the flows leaving the source must equal the sum of the flows entering the sink.
This sum is called the value of the flow, written value(F). We can represent a flow
F by labeling each edge (i, j) with the pair (C//, F/y). A flow F in the network
represented by Figure 8.70 is shown in Figure 8.71.

Example 1 In Figure 8.71, flowis conserved at node 4 since there are input flows of size 2 and
1, and an output flow of size 3. (Verify that flow is conserved properly at the other
(3,3) nodes.) Here value(F) = 5. ♦

Maximum Flows

For any network an important problem is to determine the maximum value of a


(3,2) flow through the network and to describe a flow that has the maximum value. For
obvious reasons this is commonly referred to as the maximum flow problem.
Figure 8.71
Example 2 Figure 8.72(a) shows a flow that has value 8. Three of the five edges are carrying
their maximum capacity. This seems to be a good flow function, but Figure 8.72(b)
shows a flow with value 10 for the same network. ♦

Example 2 shows that even for a small network, we need a systematic pro
cedure for solving the maximum flow problem. Examining the flow in Figure
8.72(a) shows that using the edge from node 3 to node 2 as we did was a mistake.
We should reduce flow in edge (3, 2) so that we can increase it in other edges.
Suppose that in some network N we have an edge (i, j) that is carrying a flow
of 5 units. If we want to reduce this flow to 3 units, we^can imagine that it is
8.4 Transport Networks 323

combined with a flow of two units in the opposite direction. Although edge (j, i)
is not in N, there is no harm in considering such a virtualflow as long as it only
has the effect of reducing the existing flow in the actual edge (i, j). Figure 8.73
displays a portion of the flow shown in Figure 8.72(a).
The path n: 1, 2, 3,4 is not an actual path in this network, since (2, 3) is not
an actual edge. However, n is a path in the symmetric closure of the network.
(Refer to Section 4.7 for symmetric closure.) Moreover, if we consider a virtual
Figure 8.73 flow of two units through n, the effect on the network is to increase the flows
through edges (1,2) and (3,4) by two units and decrease the flow through edge
(3, 2) by two units. Thus, the flow of Figure 8.72(a) becomes the flow of Figure
8.72(b).
We now describe this improvement in general terms. Let N be a network and
let G be the symmetric closure of N. Choose a path in G and an edge (/, j) in this
path. If (/, j) belongs to N, then we say this edge has positive excess capacity if
etj = dj —Ftj > 0. If (/, j) is not an edge of N, then we are traveling this edge
in the wrong direction. In this case we say (/, j) has excess capacity etj = Fji if
Fji > 0. Then increasingflow through edge (/, j) will have the effect of reducing
Fji. We now give a procedure for solving a maximum flow problem.

A Maximum Flow Algorithm


The algorithm we present is due to Ford and Fulkerson and is often called the
labeling algorithm. The labeling referred to is an additional labeling of nodes.
We have used integer capacities for simplicity, but Ford and Fulkerson show that
this algorithm will stop in a finite number of steps if the capacities are rational
numbers.
Let N be a network with n nodes and G be the symmetric closure of N. All
edges and paths used are in G. Begin with all flows set to 0. As we proceed, it
will be convenient to track the excess capacities in the edges and how they change
rather than tracking the increasing flows. When the algorithm terminates, it is easy
to find the maximum flow from the final excess capacities.

Algorithm THE LABELING ALGORITHM


Step 1 Let N\ be the set of all nodes connected to the source by an edge with
positiveexcess capacity. Label each j in N\ with [Ej, 1], where Ej is the
excess capacity e\j of edge (I, j). The 1 in the label indicates that j is
connected to the source, node 1.
Step 2 Let node j in N\ be the node with smallest node number and let N2(j) be
the set of all unlabeled nodes, other than the source, that are joined to node
j and have positive excess capacity. Suppose that node k is in N2(j) and
(j, k) is the edge with positive excess capacity. Label node k with [£*, j],
where £* is the minimumof Ej and the excess capacity e/& of edge (j, k).
When all the nodes in N2(j) are labeled in this way, repeat this process for
the other nodes in N\. Let N2 = {JjeN N2(j).
Note that after Step 1, we have labeled each node j in N\ with Ej, the amount
of material that can flow from the source to j through one edge and with the
information that this flow came from node 1. In Step 2, previously unlabeled
nodes k that can be reached from the source by a path n : 1, j, k are labeled with
[Ek, j]. Here E* is the maximum flow that can pass through n since it is the
smaller of the amount that can reach j and the amount that can then pass on to
k. Thus when Step 2 is finished, we have constructed two-step paths to all nodes
in N2. The label for each of these nodes records the total flow that can reach the
324 Chapter 8 Topics in Graph Theory
node through the path and its immediate predecessor in the path. We attempt to
continue this construction increasing the lengths of the paths until we reach the
sink (if possible). Then the total flow can be increased and we can retrace the path
used for this increase.

Step 3 Repeat Step 2, labeling all previously unlabeled nodes N3 that can be
reached from a node in N2 by an edge having positive excess capacity.
Continue this process forming sets N4iN5,... until after a finite number
of steps either
(i) the sink has not been labeled and no other nodes can be labeled. It can
happen that no nodes have been labeled; remember that the source is not
labeled,
or

(ii) the sink has been labeled.


Step 4 In case (i), the algorithm terminates and the total flow then is a maximum
flow. (We show this later.)
Step 5 In case (ii) the sink, node n, has been labeled with [En, ra], where En is
the amount of extra flow that can be made to reach the sink through a path
it. We examine it in reverse order. If edge (/, j) e N, then we increase
the flow in (i, j) by En and decrease the excess capacity etj by the same
amount. Simultaneously, we increase the excess capacity of the (virtual)
edge (j, i) by En since there is that much more flow in (/, j) to reverse.
If, on the other hand, (j, j) <£ N, we decrease the flow in (j, i) by En and
increase its excess capacity by En. We simultaneously decrease the excess
capacity in (/, j) by the same amount, since there is less flow in (j, j) to
reverse. We now have a new flow that is En units greater than before and
we return to Step 1. $

Example 3 Use the labeling algorithm tofind a maximum flow forthe network in Figure 8.70.
Solution
Figure 8.74 shows the network with initial capacities of all edges in G. The initial
flow in all edges is zero.

Figure 8.74

Step 1 Starting at the source, we can reach nodes 2 and 4 by edges having excess
capacity, so N\ = {2,4}. We label nodes 2 and 4 with the labels [5,1] and
[4, 1], respectively, as shown in Figure 8.75.
Step 2 From node 2 we can reach nodes 5 and 3 using edges with positive excess
capacity. Node 5 is labeled with [2, 2] since only two additional units of
flow can pass through edge (2, 5). Node 3 is labeled with [3, 2] since
8.4 Transport Networks 325

[4,1]
e45 = 3 e54 = 0
^56 = 4
^65 = 0

^36 = 3
^63 = 0

[5,1]

Figure 8.75

only 3 additional units of flow can pass through edge (2, 3). The result
of this step is shown in Figure 8.76. We cannot travel from node 4 to any
unlabeled node by one edge. Thus, N2 = {3, 5} and Step 2 is complete.

^36 = 3
*63 = 0

[5,1]

Figure 8.76

Step 3 We repeat Step 2 using N2. We can reach the sink from node 3 and 3 units
through edge (3,6). Thus the sink is labeled with [3,3].
Step 5 We work backward through the path 1, 2, 3, 6 and subtract 3 from the ex
cess capacity of each edge, indicating an increased flow through that edge,
and adding an equal amount to the excess capacities of the (virtual) edges.
We now return to Step 1 with the situation shown in Figure 8.77.

e45 = 3 e54 = 0
<?56 = 4
e4l=0 *65 = 0

Figure 8.77

Proceeding as before, nodes 2 and 4 are labeled [2, 1] and [4, 1], respec
tively. Note that E2 is now only 2 units, the new excess capacity of edge
(1,2). Node 2 can no longer be used to label node 3, since there is no
excess capacity in the edge (2, 3). But node 5 now will be labeled [2, 2].
Once again no unlabeled node can be reached from node 4, so we move
326 Chapter 8 Topics in Graph Theory
to Step 3. Here we can reach node 6 from node 5 so node 6 is labeled
with [2,5]. The final result of Step 3 is shown in Figure 8.78, and we have
increased the flow by 2 units to a total of 5 units.

el4 = 4
e4l=0

*36 = 0
*63 = 3

Figure 8.78

We move to Step 5 again and work back along the path 1, 2,5, 6, sub
tracting 2 from the excess capacities of these edges and adding 2 to the
capacities of the corresponding (virtual) edges. We return to Step 1 with
Figure 8.79. This time Steps 1 and 2 produce the following results. Only
node 4 is labeled from node 1, with [4,1]. Node 5 is the only node labeled
from node 4, with [3,4]. Step 3 begins with Figure 8.80. At this point,
node 5 could label node 2 using the excess capacity of edge (5,2). (Verify
that this would label node 2 with [2, 5].) However, node 5 can also be used
to label the sink. The sink is labeled [2,5] and the total flow is increased to
7 units. In Step 5, we work back along the path 1,4, 5, 6, adjusting excess
capacities. We return to Step 1 with the configuration shown in Figure
8.81.

*45 = 3 e54 = 0
el4 = 4
e4l=0 *65 = 2

el2 = 0 e36 = 0
e2l = 5 *63 = 3
e23 = 0 e32 = 3

Figure 8.79

*36 = 0
*63 = 3

Figure 8.80
8.4 Transport Networks 327

*56 = 0
*65 = 4

e23 = 0 e32 = 3

Figure 8.81

Verify that after Steps 1, 2, and 3, nodes 4, 5, and 2 have been labeled
as shown in Figure 8.82 and no further labeling is possible. The final
labeling of node 2 uses the virtual edge (5, 2). Thus, the final overall flow
has value 7. By subtracting the final excess capacity e,y of each edge (/, j)
in N from the capacity Q,, the flow F that produces the maximum value
7 can be seen in Figure 8.83. ♦

[2,1] [1,4]

*23 = 0 ^32 = 3
[1,5]

Figure 8.82

Figure 8.83

There remains the problem of showing that the labeling algorithm produces a
maximum flow. First, we define a cut in a network N as a set K of edges having
the property that every path from the source to the sink contains at least one edge
from K. In effect, a cut does "cut" a digraph into two pieces, one containing the
Cut*:,
CutAT2 source and one containing the sink. If the edges of a cut were removed, nothing
could flow from the source to the sink. The capacity of a cut K, c(K), is the sum
Figure 8.84 of the capacities of all edges in K.

Example 4 Figure 8.84 shows two cuts for the network given by Figure 8.70. Each cut is
marked by a jagged line and consists of all edges touched by the jagged line.
Verify that c(Kx) = 10 and c(K2) = 1. #
328 Chapter 8 Topics in Graph Theory

If F is any flow and K is any cut, then value(F) < c(K). This is true because
all parts of F must pass through the edges of K, and c{K) is the maximum amount
that can pass through the edges of K. Now suppose for some flow F and some
cut K, value(F) = c(K)\ in other words, the flow F uses the full capacity of all
edges in K. Then F would be a flow with maximum value, since no flow can have
value bigger than c(K). Similarly, K must be a minimum capacity cut, because
every cut must have capacity at least equal to value(F). From this discussion we
conclude the following.

THEOREM 1 A maximum flow F in a network has value equal to the capacity of a minimum
The Max Flow cut of the network. •

Min Cut Theorem


We now show that the labeling algorithm results in a maximum flow by finding
a minimum cut whose capacity is equal to the value of the flow. Suppose that the
algorithm has been run and has stopped at Step 4. Then the sink has not been
labeled. Divide the nodes into two sets, M\ and M2, where M\ contains the source
and all nodes that have been labeled, and M2 contains all unlabeled nodes, other
than the source. Let K consist of all edges of the network N that connect a node
in M\ with a node in M2. Any path it in N from the source to the sink begins with
a node in M\ and ends with a node in M2. If / is the last node in it that belongs
to M\ and j is the node that follows i in the path, then j belongs to M2 and so by
definition (i, j) is in K. Therefore, K is a cut.
Now suppose that (i, j) is an edge in K9 so that i e M\ and j e M2. The final
flow F produced by the algorithm must result in (i, j) carrying its full capacity;
otherwise, we could use node / and the excess capacity to label j\ which by defi
nition is not labeled. Thus the value of the final flow of the algorithm is equal to
the capacity c(K), and so F is a maximum flow.

Example 5 The minimum cut corresponding to the maximum flow found in Example 3 is
K = {(5, 6), (3, 6)} with c(K) = 7 = value(F). ♦

8.4 Exercises

In Exercises 1 through4 (Figures 8.85 through 8.88), label the


network in the given figure with a flow that conserves flow at
each node, exceptthesource and the sink. Each edge is labeled
with its maximumcapacity.
1.

Figure 8.87

Figure 8.85

Figure 8.86
8.5 Matching Problems 329

In Exercises 5 through 11, find a maximumflow in the given 11. The network shown in Figure 8.91
network by using the labeling algorithm.
5. The network shown in Figure 8.85 3 ^n\ 4

6. The network shown in Figure 8.86


7. The network shown in Figure 8.87
8. The network shown in Figure 8.88
9. The network shown in Figure 8.89

, 9_
Is Figure 8.91

12. Give two cuts and their capacities for the network in Fig
ure 8.87.

13. Give two cuts and their capacities for the network in Fig
ure 8.89.

14. Give three cuts and their capacities for the network in Fig
Figure 8.89
ure 8.91.
10. The network shown in Figure 8.90 In Exercises 15 through 21, find the minimum cut that corre
3
sponds to the maximumflow for the given network.
15. The network of Exercise 5

16. The network of Exercise 6

17. The network of Exercise 7


18. The network of Exercise 8

19. The network of Exercise 9


20. The network of Exercise 10
Figure 8.90
21. The network of Exercise 11

8.5 Matching Problems


The definition of a transport network can be extended, and the concept of a max
imal flow in a network can be used to model situations that, at first glance, do
not seem to be network problems. Compare this situation with that in Section 2.6
where a variety of seemingly unrelated problems could be modeled by the open
cover problem. We consider two examples in this section.
The first example is to allow a network to have multiple sources or multiple
sinks as many real networks do. In the network N shown in Figure 8.92, nodes
1, 2, and 3 are all sources, and nodes 6 and 7 are sinks. For example, the sources
could carry water from different pumping stations on a lake to two tanks (nodes 6
and 7) that supply two towns' drinking water.
In a case like this, we want to maximize the flow from all sources taken to
gether to all the sinks taken together. As before, a flow F consists of the quantities
Fij assigned to each edge (7, j). We require that flow be conserved at each node
that is not a source or a sink and that the flow in each edge not exceed the capac
Figure 8.92 ity of that edge. The value of the flow F, value(F), is the sum of the flows in
all edges that come from any source. It is not hard to show that this value must
equal the sum of flows in all edges that lead to any sink. To find the maximal flow
in a general network N9 we change the problem into a single-source, single-sink
network problem by enlarging N to N' as follows. We add two nodes, which we
call a and b. Node a is the source for Nf and is connected to all nodes that are
sources in N. Similarly, node b is the sink for N\ and all nodes that were sinks in
330 Chapter 8 Topics in Graph Theory

N are connected to it. Nodes a and b are called, respectively, a supersource and a
supersink. To completethe new network we set the capacities of all new edges to
some number Co that is so large that no real flow through N' can pass more than
Co units through any of the new edges. Some authors choose Co to be infinity.
Example 1 An enlarged network N' for the network of Figure 8.92 is shown in Figure 8.93.
We have set Co to be 11, the sum of all capacities leaving sources of N. ♦

Figure 8.93

By adding a supersource and a supersink (if necessary) to a network, we can


apply the labeling algorithm to find a maximal flow for the enlarged network. This
flow will also be maximal for the original network.

Example 2 Find the maximal flow forthe network N given in Figure 8.92.
Solution
Applying the labeling algorithm to the enlarged network N' given in Figure 8.93
produces the result shown in Figure 8.94. (Verify.) The value of this flow is 9.
This is the maximal flow from nodes 1, 2, and 3 to nodes 6 and 7 in N. ♦

(11,2)
(11,6)

(11, 3)
(11,4)

Figure 8.94

The Matching Problem


We consider now an important class of problems, matching problems, that can also
be modeled by network flows. We begin with two finite sets A and B and a relation
R from A to B. A matching function M is a one-to-one function from a subset of
A to a subset of B. We say a is matched with b if M(a) = b. A matching function
M is compatible with R if M c /?; that is, if M(a) = ft, then a R b.

Example 3 Let A be a setof girls and B a setof boys attending a school dance. Define R by
a R b if and only if a knows b. A matching function M is defined from A to B by
M(a) = b if a and b dance the third dance together. M is compatible with R if
each girl knows her partner for the third dance. ♦
8.5 Matching Problems 331

Example 4 Let A = {s\, s2,53,$4,55} be a set of students working on a research project and
B = [b\, b2, £3, 64, bs) be a set of reference books on reserve in the library for the
project. Define R by ay # ft* if and only if student St wants to sign out book ft*.
A matching of students to books would be compatible with R if each student is
matched with a book that he or she wants to sign out. ♦

Given any relation R from A to B, a matching M that is compatible with R is


called maximal if its domain is as large as possible and is complete if its domain is
A. In general, a matching problem is, given A, 5, and R, find a maximal matching
from A to B that is compatible with R. Somewhat surprisingly, matching problems
can be solved using networks. We create a network to model the situation by using
the elements of A as sources and the elements of B as sinks. There is a directed
edge (a, b) if and only if a R b. To complete the network, each edge is assigned
capacity 1.

Example 5 Let A, B, and R be as in Example 4. Suppose student s\ wants books b2 and 63;
s2 wants b\, b2j £3, 64; S3 wants b2,by9 S4 wants b2,b^b^\ £5 wants b2, b^. Then
the network N that represents this situation is given in Figure 8.95. ♦

For the network in Figure 8.95, one maximal matching M can be found by
inspection: M(s\) = b2, M{s2) = b\, Mfe) = £3, M(^) = b±. It is easy to see
that no complete matching is possible for this case. Usually it can be very difficult
to find a maximal matching, so let us examine a network solution to the matching
problem. In Figure 8.96, a supersource x and a super sink y have been provided
and new edges have been assigned capacity 1 to create N'.

Figure 8.95

Figure 8.96

Every flow in N provides a matching of students to books that is compatible with


R, and every compatible matching arises from a flow in N. To see this, suppose
that F is a flow in N. If the flow into node sm is 1, then the flow out must be 1,
so the flow from sm (if any) can go to only one node, say bn. Similarly, flow can
enter a node bn from at most one sm since the flow out of bn is 1. We match sm
to bn if and only if there is flow between these two nodes. The matching func
tion M that we construct is clearly compatible with R. Conversely, if we have
an ^-compatible matching M, we can define a flow F by letting the flow be 1
between any two matched nodes, 1 from x to each student matched with a book,
and from each matched book to y, and 0 on all other edges. This flow yields the
matching M again. Hence, there is a one-to-one correspondence between flows
in N and matching functions compatible with R. This means that we can use the
labeling algorithm to solve the matching problem by constructing N and Nf as in
this example.
332 Chapter 8 Topics in Graph Theory

We saw that no complete matching is possible in the student-book example,


but whether or not there is a complete matching for a particular problem is gen
erally not obvious. A condition that will guarantee the existence of a complete
matching was first found for the matching problem for a set of men and a set of
women with the relation "suitable for marriage." Because the question posed was
"Is it possible for each man to marry a suitable woman?" this is often referred to
as the marriage problem.
The notion of an J?-relative set defined in Section 4.2 simplifies the statement
of the next theorem.

THEOREM 1 Let R be a relation from A to B. Then there exists a complete matching M if and
Hall's Marriage Theorem onlyif for each x £ A> \x\ < \R(X)\-
Proof
If a complete matching M exists, then M(X) c R(X) for every subset X of A.
But M is one to one, so |X| = \M(X)\ < \R(X)\.
Conversely, suppose that for any X c A, |X| < \R(X)\. Construct the net
work N that corresponds to R. Suppose \A\ = n. We want to show that there is a
flow in N with value n, which will correspond to a complete matching. We know
by the Max Flow Min Cut Theorem that it is sufficient to show that the minimal
cut in N has value n. A typical situation is shown in Figure 8.97, with the wavy
line representing a cut in N.

Figure 8.97

Remember that all edges are directed to the right and have capacity 1. We say that
two vertices of AT are connected if there is a path from one to the other; if not,
the two vertices are disconnected. With this language, a cut in N is a set of edges
whose removal will make the supersource x and the supersink y disconnected.
Let n = \A\ and p = |B|. Suppose K is a minimal cut of N. Divide the
edges of K into three sets: S\ contains the edges that begin at jc, S2 contains
the edges that correspond to pairs in R, S3 contains the edges that end with y.
Consider removing the edges of K one set at a time. Suppose that |5i | = k so x
is connected to k elements of A. Let A\ be this subset of A. When the edges in
S\ are removed, no path from x to y can pass through an element of A\. Since
K is minimal, we can suppose that no edges in K begin with elements in A\. Let
A2 = A - A\ so \A2\ = n - k. Let B2 = R(A2). Thus each element of B2
labels the terminal node of an edge that begins in A2. Since the supersource x is
connected to each element in A2, x is also connected to each element in B2. We
know that \A2\ < \R(A2)\ = \B2\so there are at least n —k elements in B2.
Let 1521 = r. Each of these edges connects some element a € A2 to some
element b e B2. Removing an edge in S2 may or may not disconnect x from any
element of B2, but it certainly cannot disconnect x from more than one element
8.5 Matching Problems 333

of B2. Thus, when the edges in S2 are removed, x is still connected to at least
(n —k) —r elements of B2. These elements must then be disconnected from y to
ensure there is no path from x to y, and so 53 must contain at least (n —k) —r
edges. Hence the capacity of K = the number of edges in K = \S\ \+ \S2\+| S31 >
k + r + {(n —k) —r) = n.
Since the cut that removes all edges beginning at x has capacity n, we see that
the minimal cut, and therefore the maximum flow, is exactly n. •

Note that this is an example of an existence theorem; no method is given for


finding a complete matching, if one exists.

Example 6 Let MR be the matrix of a marriage suitability relation between five men andfive
women. Can each man marry a suitable woman?

110 0 0"
0 0 0 11
MR= 10 10 0
0 0 10 1
0 10 10

Solution
We could construct an enlarged network Nf to model this problem and apply the
labeling algorithm in order to answer the question. Instead, we use Hall's marriage
theorem. Note that each man considers exactly two women suitable and each
woman is considered suitable by exactly two men. Consider the network that
represents this problem. Let 5 be any subset of the men and E be the set of edges
that begin in S. Clearly |£| = 2|5|. Each edge in E must terminate in a node
of R(S). But we know the number of edges terminating at elements of R(S) is
exactly 2\R(S)\. Thus, 2|5| < 2|/?(S)|, and so |5| < \R(S)\. By Hall's marriage
theorem, a complete match is possible. ♦

8.5 Exercises
1. For Example 5, find a different maximal matching. Is it
possible to find a maximal matching where s5 is matched
with a book?

2. Verify that the labeling algorithm used on the network


of Figure 8.96 gives the maximal matching M{s\) = bi,
M(s2) = bu M(s3) = 63, M(s4) = bA.

In Exercises 3 through 5 (Figures 8.98 through 8.100), find a


maximumflow through the network. Figure 8.99

Figure 8.98
334 Chapter 8 Topics in Graph Theory
In Exercises 6 through 10, the matrix MRfor a relationfrom 14. Let R be a relation from A to B with \A\ = \B\ = n.
A to B is given. Find a maximal matchingfor A, B, and R. Prove that if the number of ones in each column of MR
is k and the number of ones in each row of MR is k, then
-10 10" "I 0 1 0"
there is a complete matching for A, B9 and R.
0 0 10 0 1 0 1
7.
10 0 0 1 0 0 1 15. Let R be a relation from A to B with \A\ = \B\ = n. Let
_1 1 0 1„ _0 1 1 0_ j be the maximum number of ones in any column of MR
-10 10 1" -10 1 0 1"
and k be the minimum number of ones in any row of MR.
0 110 0 0 1 1 0 1
Prove that if j < k, then there is a complete matching for
0 0 10 0
A, 5, and R.
9. 1 0 1 1 0
110 11 1 1 0 1 0 16. Let R be a relation from A to B with \A\ = \B\ = n.
_0 0 1 0 0_ _0 1 0 1 1_ Prove that a complete matching exists for A, B, and R if
-10 10 11" each node in the network corresponding to A, B, and R
0 110 10 has degree at least |. (Hint: Use a result from Section
10 110 0 8.3.)
10.
110 10 1
Figure 8.95 is an example ofa bipartite graph; there is a two-
0 10 111
set partition of the set of vertices such that all edges in the
_0 0 1 0 0 1_
graph connect membersfrom different sets in thepartition.
11. Which of the matchings found in Exercises 6 through 10
are complete matchings? 17. Which of the following graphs are bipartite? If the graph
is bipartite, give a partition to show this. If not, explain
12. Ann, Bing, Carmen, D' Andrea, Emilio, and Henri have
why this is not possible.
inherited six paintings (of roughly equal value). Each heir
has written on a slip of paper the letters that identify the (a)
paintings he or she would like to have. Ann: E; Bing: B,
D; Carmen: A, E; D'Andrea: B, D; Emilio: C; Henri: A,
D, F. As the executor of the estate, can you give each heir
a painting he or she wants using the information on the
slips of paper? If so, give the matching of heir to paint
ing.
13. Eight friends are taking a dog-sledding trip with four Figure 8.101
sleds. Of course, not everyone is a good partner for ev
eryone else. Here is a list of the friends each with the
people with whom they can be paired.
(W 3. .4
Sam: Jane, Gail
Jane: Sam, Kip, Rufus
Kip: Kirk, Jane, Gail
Gail: Sam, Kip, Rufus
Homer: Kirk, Rufus, Stacey
Stacey: Homer, Kirk
Kirk: Kip, Homer, Stacey
Rufus: Sam, Homer, Jane, Gail Figure 8.102
(a) Give a set of four good partnerships for the trip.
(b) A mistake was made and you've been given the list 18. Prove that the Hasse diagram of the Boolean algebra Bn
with n vertices, n > 2, is bipartite.
of people with whom people cannot be paired. Is a
matching of good partners still possible? If so, give 19. Prove that if an undirected graph contains a triangle, then
one. the graph is not bipartite.

8.6 Coloring Graphs


Suppose that G = (V, £, y) is a graph with no multiple edges, and C = {c\, c2,
..., cn) is any set of n "colors." Any function /: V -> C is called a coloring of
the graph G using n colors (or using the colors of C). For each vertex v, f(v)
is the color of v. As we usually present a graph pictorially, so we also think of a
coloring in the intuitive way of simply painting each vertex with a color from C.
8.6 Coloring Graphs 335

However, graph-coloring problems have a wide varietyof practical applications in


which "color" may have almost any meaning. For example, if the graph represents
a connected grid of cities, each city can be marked with the name of the airline
having the most flights to and from that city. In this case, the vertices are cities and
the colors are airline names. Other examples are given later.
A coloring is proper if any two adjacent vertices v and w have different colors.

Example 1 Let C = {r, w, b, y] so that n = 4. Figure 8.103 shows a graph G properly colored
with the colors from C in two different ways, one using three colors from C and
one using all four. We show the colors as labels, which helps to explain why we
avoid giving names to vertices. There are many ways to color this graph properly
with three or four colors, but it is not hard to see that this cannot be done with two
or fewer colors. (Experiment to convince yourself that this is true.) ♦

The smallest number of colors needed to produce a proper coloring of a graph


G is called the chromatic number of G, denoted by x(G). For the graph G of
Figure 8.103 Figure 8.103, our discussion leads us to believe that x (G) = 3.
Of the many problems that can be viewed as graph-coloring problems, one of
the oldest is the map-coloring problem. Consider the map shown in Figure 8.104.

Figure 8.104

A coloring of a map is a way to color each region (country, state, county,


province, etc.) so that no two distinct regions sharing a common border have the
same color. The map-coloring problem is to find the smallest number of colors
that can be used. We can view this problem as a proper graph-coloring problem as
follows. Given a map M, construct a graph GM with one vertex for each region and
an edge connecting any two vertices whose corresponding regions share a common
boundary. Then the proper colorings of Gm correspond exactly to the colorings
of M.

Example 2 Consider the map M shown in Figure 8.104. Then GM is represented by Figure
8.105. ♦

The map-coloring problem dates back to the mid-nineteenth century and has
been an active subject of research at various times since then. A conjecture was
that four colors are always enough to color any map drawn on a plane. This con
jecture was proved to be true in 1976 with the aid of computer computations per
formed on almost 2000 configurations of graphs. There is still no proof known
Figure 8.105 that does not depend on computer checking.
The graph corresponding to a map is an example of a planar graph, meaning
that it can be drawn in a plane so that no edges cross except at vertices. Figure
8.105 illustrates the planarity of the graph corresponding to the map of Figure
8.104. The complete graph K5 is not planar, so graph-coloring problems are more
336 Chapter 8 Topics in Graph Theory
general than map-coloringproblems. Later, we will see that fivecolors are required
to color £5.
Graph-coloring problems also arise from counting problems.

Example 3 Fifteen different foods are tobeheld inrefrigerated compartments within the same
refrigerator. Some of them can be kept together, but other foods must be kept
apart. For example, spicy meats and cheeses should be kept separate from bland
meats and vegetables. Apples, eggs, and onions should be isolated or they will
contaminate many other foods. Butter, margarine, and cream cheese can be kept
together, but must be separated from foods with strong odors. We can construct
a graph G as follows. Construct one vertex for each food and connect two with
an edge if they must be kept in separate compartments in the refrigerator. Then
X(G) is the smallest number of separate containers needed to store the 15 foods
properly. ♦

A similar method could be used to calculate the minimum number of labora


tory drawers needed to store chemicals if we need to separate chemicals that will
react with one another if stored close to each other.

Chromatic Polynomials
Closely related to the problem of computing x (G) is the problem of computing
the total number of different proper colorings of a graph G using a set C = {c\, c2,
..., cn] of colors.
If G is a graph and n > 0 is an integer, let Pdn) be the number of ways to
color G properly using n or fewer colors. Since Pdn) is a definite number for
each rc, we see that Pq is a function. What may not be obvious is that Pq is a
polynomial in n. This can be shown in general and is clearly seen in the examples
of this section. We call PG the chromatic polynomial of G.

Example 4 Consider the linear graph L4 defined inSection 8.1 and shown inFigure 8.9. Sup
pose that we have x colors. The first vertex can be colored with any color. No
matter how this is done, the second can be colored with any color that was not
chosen for vertex 1. Thus there are x —1 choices for vertex 2. Vertex 3 can then be
colored with any of the x —1 colors not used for vertex 2. A similar result holds
for vertex 4. By the multiplication principle of counting (Section 3.1), the total
number ofproper colorings isx(x - l)3. Thus PLa = x(x - l)3. ♦

We can see from Example 4 that PL4(0) = 0, PL4(1) = 0, and PLa(2) = 2.


Thus there are no proper colorings of L4 using zero colors (obviously) or one
color, and there are two using two colors. From this we see that x (£4) = 2. This
connection holds in general, and we have the following principle: If G is a graph
with no multiple edges, and Pq is the chromatic polynomial of G, then xiQ) is
the smallest positive integer x for which PgM # 0.
An argument similar to the one given in Example 4 shows that for Ln, n > 1,
PLn(x) = x(x - l)n~l. Thus, x(Ln) = 2 for every n.
Example 5 Forany n > 1, consider the complete graph Kn defined in Section 8.1. Suppose
that we again have x colors to use in coloring Kn. If x < n, no proper coloring
is possible. So let x > n. Vertex v\ can be colored with any of the x colors.
For vertex v2, only x —1 remain since v2 is connected to v\. We can only color
V3 with x —2 colors, since V3 is connected to v\ and v2 and so the colors of v\
and v2 cannot be used again. Similarly, only x —3 colors remain for V4 and so
on. Again using the multiplication principle of counting, we find that PKn (x) =
8.6 Coloring Graphs 337

x(x - l)(x - 2) • • • (jc - n + 1). This shows that x(%n) = n. Note that if there
are at least n colors, then PKn (jc) is the number of permutations of x objects taken
n at a time (see Section 3.1). ♦

Suppose that a graph G is not connected and that G\ and G2 are two compo
nents of G. This means that no vertex in Gi is connected to any vertex in G2. Thus
any coloring of Gi can be paired with any coloring of G2. This can be extended to
any number of components, so the multiplication principle of counting gives the
following result.

THEOREM 1 If G is a disconnected graph with components G\, G2,..., Gm, then Pg(x) =
Pg1(*)Pg2(x) '' *pGm(x)> theproduct ofthechromatic polynomials foreachcom
ponent. •

Example 6 Let G be the graph shown in Figure 8.6. Then G has two components, each of
which is K3. The chromatic polynomial of K3 is x(x - l)(x —2), x > 3. Thus,
by Theorem 1, PG(x) = x2(x - l)2(x - 2)2. We see that x(G) = 3 and that the
number of distinct ways to color G using three colors is PgO) = 36. If x is 4,
then the total number of proper colorings of G is 42 •32 •22 or 576. ♦

Example 7 Consider the discrete graph Un ofSection 8.1, having n vertices and noedges. All
n components are single points. The chromatic polynomial of a single point is x,
so, by Theorem l9PUn(x)=xn. Thus x(Ai) = 1 as can allso be seen directly. ♦
There is a useful theorem for computing chromatic polynomials using the sub
graph and quotient graph constructions of Section 8.1. Let G = {V\ £, y) be a
graphwith no multiple edges, and let e e E, say e = {a, b}. As in Section 8.1, let
Ge be the subgraph of G obtained by deleting e, and let Ge be the quotient graph
of G obtainedby merging the end points of e. Then we have the following result.

THEOREM 2 With the preceding notation and usingx colors,


PG(x) = PGe(x)-PGe(x). (1)

Proof
Consider all the proper colorings of Ge. They are of two types, those for which
a and b have different colors and those for which a and b have the same color.
Now a coloring of the first type is also a proper coloring for G, since a and b are
connected in G, and this coloring gives them different colors. On the other hand,
a coloring of Ge of the second type corresponds to a proper coloring of Ge. In
fact, since a and b are combined in Ge, they must have the same color there. All
other vertices of Ge have the same connections as in G. Thus we have proved that
PGe(X) = PG(X) + PGe(x) Or PG(X) = PGe(x) - PGe(x). •
Example 8 Let us compute Pg(x) for the graph G shown in Figure 8.106, using the edge e.
Then Ge is K3 and Ge has two components, one being a single point and the other
being K3. By Theorem 1,
PGe(x) = x(x(x - l)(x - 2)) = x2(x - l)(x - 2),
if x > 2. Also,
PGe(x)=x(x-l)(x-2).
Thus, by Theorem 2, we see that
Figure 8.106 0
PG(x) = x2(x - l)(x - 2) - x(x - 1)(jc - 2)
338 Chapter 8 Topics in Graph Theory

or

x(x-ly(x-2).
Clearly, PG(\) = PG{2) = 0, and PG(3) = 12. This shows that x(G) = 3. ♦

In Section 2.6, the problem of solving a Sudoku puzzle is modeled as an open-


cover problem. AlgorithmX produces a complete grid, if one exists. The question
of whether an initial Sudoku grid can be successfully completed can also be mod
eled as a graph-coloring problem. Using this model allows us to use chromatic
polynomials as tools for counting the number of solutions and to answer the ques
tion of whether there is a unique solution.

8.6 Exercises

In Exercises I through 4 (Figures 8.107 through 8.110), con


Vi
struct a graphfor the map given as done in Example 2.
Vo
1.
A - C
B
1 E
D

Figure 8.107 V*
Va

Figure 8.108 Figure 8.113 Figure 8.114


In Exercises 9 through 12, find the chromatic polynomialfor
the graph represented by the givenfigure. Confirm each of
these by using the results of Exercises 5 through 8.
9. Figure 8.111 10. Figure 8.112
11. Figure 8.113 12. Figure 8.114
InExercises 13 through 16 (Figures 8.115 through 8.118),find
the chromatic polynomial PG for the given graph and use PG
tofindX{G).
13. 14.

Figure 8.110

Figure 8.115
Figure 8.109 Figure 8.116

15. 16.
In Exercises 5 through 8 (Figures 8.111 through 8.114), deter
mine the chromatic number ofthe graph by inspection.

Figure 8.117 Figure 8.118

17. Find PG and x(G) for the graph G of the map in Exer
Figure 8.111 cise 1.

_. 18. Find PG and x (G) for the graph G of the map in Exer-
Figure8.112 cise3
Key Ideas for Review 339

19. Find PG and x (G) for the graph G of the map in Exercise (a) What do the edges represent?
4. Consider using Theorem 2 to do this.
(b) What should the colors represent?
20. Let G be the graph represented by Figure 8.64, in Section
8.3, Exercise 5. Find PG and compute x(G). (c) What question does x (G) answer for the graph con
structed?
21. Let G be a bipartite graph. What is x(G)? Explain your
answer. 27. The Pet Fishe Store has 20 species of fish in stock. Since
some species eat others, the store owners would like to
22. Prove that if G is a graph where the longest cycle has odd
know the minimum number of tanks needed to prevent
length n and n is greater than 2, then x (G) < n + 1.
any fish tragedies. Model this problem for them as a
23. Prove by mathematical induction that graph-coloring problem.
Pl„(x) = x(x - l)B-\ /!> 1.
28. Tomodelann2xn2 Sudokugrid as a graph-coloring prob
24. (a) Give an example of a connected graph with five ver lem, choose the vertices to represent the cells of the grid.
tices that is planar. To color a vertex means to fill the corresponding cell with
(b) Give an example of a connected graph with five ver a digit.
tices that is not planar. (a) How many vertices does the graph have?
25. Show that the graph given is planar,
(b) In order to represent the requirements that each digit
(a) K y\ 0>) appears once in each row, column, and subgrid, what
should the edges represent?
(c) How many colors are needed for a solution to the
puzzle?
Figure 8.119 29. (a) For the model described in Exercise 28, explain why
Figure 8.120 the graph produced is regular.
(b) For n = 2 what is the degree of each vertex in the
26. The problem of constructing a final exam schedule with model described in Exercise 28?
a minimum number of time slots so that students do not
have time conflicts can be modeled as a graph-coloring (c) For n = 3 what is the degree of each vertex in the
problem. If the vertices represent the courses, model described in Exercise 28?

Tips for Proofs


No new proof techniques are introduced in this chapter, but most of those used
previously make an appearance—direct, indirect by contradiction, mathematical
induction. For statements about graphs, a typical structure for a contradiction
proof is to examine the largest (or smallest) object with certain properties and
show that if the statement were not true, then a larger (or smaller) object with the
same propertiescould be constructed. This is the structure of the proof of Theorem
1(b), Section 8.2. Often indirect proofs are also existence proofs since they tell us
only that an object with certain properties must exist, but not how to construct
one. The proofs of Theorems 1 and 2 in Section 8.2 are of this type. Induction
proofs are common in graphtheory, becausemany theorems are stated in terms of
the number of vertices or the number of edges. Analysis of all possible cases is
also common; the proof of the four-color theorem that was mentioned earlier is an
extreme case of this technique.

Key Ideas for Review


• Graph: G = (V, E, y), where V is a finite set of objects, • Circuit: path that begins and ends at the same vertex
called vertices, E is a set of objects, called edges, and y is
• Simple path or circuit: see page 307
a function that assigns to each edge a two-element subset of
V. • Connected graph: There is a path from any vertex to any
• Degree of a vertex: number of edges at the vertex other vertex.

• Path: see page 307 • Subgraph: see page 308


340 Chapter 8 Topics in Graph Theory

Euler path (circuit): path (circuit) that contains every edge Flow in a network: function that assigns a flow to each edge
of the graph exactly once of a network
Theorem: (a) If a graph G has a vertex of odd degree, there Value of a flow: the sum of flows entering the sink
can be no Euler circuit in G. (b) If G is a connected graph
Labeling algorithm: see page 323
and every vertex has even degree, then there is an Euler cir
cuit in G. Cut in a network: set of edges in a network such that every
Theorem: (a) If a graph G has more than two vertices of
path from the source to the sink contains at least one edge
in the set.
odd degree, then there can be no Euler path in G. (b) If G is
connected and has exactly two vertices of odd degree, there Capacity of a cut: see page 327
is an Euler path in G. Max Flow Min Cut Theorem: A maximum flow in a net
Bridge: edge whose deletion would cause the graph to be work has value equal to the capacity of a minimum cut of
come disconnected the network
Fleury's algorithm: see page 315 Matching (function) M compatible with a relation R: one-
Hamiltonian path: path that includes each vertex of the to-one function such that M c. R.
graph exactly once Hall's Marriage Theorem: Let R be a relation from A to B.
Hamiltonian circuit: circuit that includes each vertex ex There exists a complete matching M if and only if for each
actly once except for the first vertex, which is also the last XC A, |X| < \R(X)\.
Theorem: Let G be a graph on n vertices with no loops or Coloring of a graph using n colors: see page 334
multiple edges, n > 2. If for any two vertices u and v of G,
Proper coloring of a graph: adjacent edges have different
the degree of u plus the degree of v is at least n, then G has
colors.
a Hamiltonian circuit.
Theorem: Let G be a graph on n vertices that has no loops Chromatic number of a graph G, x (G): smallest number of
or multiple edges, n > 2. If the number of edges in G is at colors needed for a proper coloring of G
least j(n2 —3n + 6),then Ghas a Hamiltonian circuit. Planar graph: graph that can be drawn in a plane with no
Transport network: see page 321 crossing edges
Capacity: maximum flow that can be passed through an Chromatic polynomial of a graph G, PG: number of proper
edge colorings of G in terms of the number of colors available

I Chapter 8 Self-Test
1. What is the relationship between a quotient graph and a
quotient set?

2. What is the difference between an Euler circuit and a


Hamiltonian circuit?

3. What is needed for a subset of vertices and a subset of


edges to form a subgraph?
4. How are maximum flow problems related to matching
problems?

5. How does the chromatic polynomial of a graph aid us in Use Figures 8.122 and 8.123 for Problems 9 and 10.
finding the chromatic number of the graph?
6. Draw a picture of the graph G = (V, £, y), where
V = {j,k,l,m,n}, E = {eu e2, e3, e4,e5], and

y(e{) = {m, *}, y(e2) = {j, /}, y(e3) = {n, jfc},


y(eA) = {m, ;}, and y(e5) = {n, /}.

7. Give an example of a graph with seven vertices and ex Figure 8.122 Figure 8.123
actly three components.

8. If R is the equivalence relation defined by the partition 9. Tell whether the graph in the specified figure has an Euler
{{v2, i>4, v5}, [vu v3}, {v7, v8}, {t>6, v9}}, find the quotient circuit, an Euler path but no Euler circuit, or neither.
graph GR of the graph G represented by Figure 8.121. (a) Figure 8.122 (b) Figure 8.123
Experiment 8 341

10. Tell whether the graph in the specified figure has a Hamil 1 2 c. 5 _
tonian circuit, a Hamiltonian path but no Hamiltonian cir
cuit, or neither. 2 3\ /*
(a) Figure 8.122 (b) Figure 8.123 . 2\/ 2 ,fc

11. (a) The graph represented by Figure 8.124 does not have 1 3/ \4
an Euler circuit. Mark the minimal number of edges / 2 \
<H O HI
that would have to be traveled twice in order to travel
every edge and return to the starting vertex.
Figure 8.126
(b) For each edge you marked in part (a), add an edge 15. Find a maximal flow in the network shown in Figure
between the same vertices. Use Fleury's algorithm 8.127.
to find an Euler circuit for the modified version of
Figure 8.124.
3/ \1

Figure 8.127
Figure 8.124 16. (a) Construct a graph for the map given in Figure 8.128.
(b) Determine the number of colors required for a proper
12. Give an Euler circuit, by numbering the edges, for the coloring of the map.
graph represented by Figure 8.125. Begin at A.

Figure 8.125

13. Give a Hamiltonian circuit, by numbering the edges, for


the graph represented by Figure 8.125. Figure 8.128
17. Compute the chromatic polynomial for the graph con
14. Find a Hamiltonian circuit of minimal weight for the structed in Problem 16(a) and use it to prove the result
graph represented by Figure 8.126. of Problem 16(b).

| Experiment 8
Suppose that there are n individuals Pi, P2,..., Pn some of whom can influence
each other in makingdecisions. If P3 influences P5, it may or may not be true that
P5 influences P3. In Figure 1 we have drawn a digraph to describe the influence
relations among the six members of a design team. Notice that the digraph has no
loops; an individual does not influence herself or himself.
1. (a) Give the matrix for this relation.
(b) Is there a leader in this design group? Justify your answer.
Figure 1 The relation described by the digraph in Figure 1 is not transitive, but we can
speak of two-stage influence. We say P/ has two-stage influence on Pj if there
is a path of length 2 from P, to Pj. Similarly, P, has r-stage influence on Pj if
thereis a pathof length r from P, to Pj. In Section 4.3, a method for determining
whether a path of length r exists from P, to Pj is presented.
342 Chapter 8 Topics in Graph Theory

2. Use the matrix for the relation described by Figure 1 to determine whether P,
has two-stageinfluence on Pj for each ordered pair of distinct members of the
design team.
3. Consider a communication network among five sites with matrix

0 10 0 0"
0 0 10 1
0 0 0 10
0 0 0 0 0
,00110.

(a) Can P3 get a message to P5 in at most two stages?


(b) What is the minimum number of stages that will guarantee that every site
can get a message to any other different site?
(c) What is the minimum number of stages that will guarantee that every site
can get a message to any site including itself?
A dictionary definesa clique as a small exclusive group of people. In studying
organizational structures, we often find subsets of people in which any pair of
individuals is related, and we borrow the word clique for such a subset. A clique
in an influence digraph is a subset S of vertices such that
(1) |5| > 3.
(2) If Pi and Pj are in 5, then P, influences Pj and Py influences P/.
(3) S is the largest subset that satisfies (2).
Figure 2 4. Identify all cliques in the digraph in Figure 2.
If the digraph is small, cliques can be identified by inspection of the digraph.
In general, it can be difficult to determine cliques using only the digraph. The
algorithm CLIQUE identifies which vertices belong to cliques for an influence
relation given by its matrix.

Algorithm CLIQUE
1 IfA = [ a{j ] is the matrix ofthe influence relation, construct the matrix
S = [stj ] as follows: sy = sjt = 1 if and only if atj = ctji = 1.
Otherwise, sy = 0.
2 Compute S©SOS = C = [ cu ].
3 Pi belongs to a clique if and only if c/,- is positive. •

5. Use CLIQUE and the matrix for the digraph in Figure 2 to determine which
vertices belong to a clique. Verify that this is consistent with your results for
Question 4 above. Explain why CLIQUE works.
6. Five people have been stationed on a remote island to operate a weather sta
tion. The following social interactions have been observed:
P\ gets along with P2, P3, and P4.
P2 gets along with Pj, P3, and P5.
P3 gets along with Pu P2, and P4.
P4 gets along with P3 and P5.
P5 gets along with P4.
Identify any cliques in this set of people.
Experiment 8 343

7. Another application of cliques is in determining the chromatic number of a


graph. (See Section 8.6.) Explain how knowing the cliques in a graph G can
be used to find xiQ).
CHAPTER

9 Semigroups and Groups


Prerequisites: Chapters 4, 5, and 6

The notion of a mathematical structure was introduced in Section 1.6. In the fol
lowing chapters, other types of mathematical systems were developed; some, such
as (propositions, A, v, ~), were not given specific names; but others, such as B„,
the Boolean algebraon n elements, were named. In this chapter, we identify more
types of mathematical structures, namely, semigroups, groups, rings, and fields.
Semigroups will be used in our study of finite state machines in Chapter 10. We
also develop the basic ideas of groups, rings, and fields, which we will apply to
coding theory in Chapter 11.

Looking Back
The term group was applied by Evariste Galois (1811-1832) in mial in terms of their coefficients were discovered in the 1500s.
1830 to a set of permutations of a finite set that satisfies certain
For the next300 years, mathematicians tried, unsuccessfully, to
properties. Galois was bom and died in Paris. He was educated Solve the general fifth-degree polynomial by radicals. The Nor
by his motherat homeuntilthe age of 12. He attended a presti wegian mathematician Niels Henrik Abel (1802-1829) showed
giouslyceein Parisand by the age of 16 became fullyabsorbed at the age of 19that the generalpolynomialof degree5 or higher
in the studyof mathematics, even neglecting other subjects. He cannot be solved by radicals. Since many special polynomials
failedin his two tries at admission to the highly regarded Ecole of degree 5 or higher can be solved by radicals, it became im
Polytechnique and enrolled in the Ecole Normale, a lesser insti portantto determinewhich polynomialshave this property. Ga
tutionof higher learning. In his firstyear there he publishedfour lois characterized polynomials that are solvable by radicals by
papers. Three additionalpapers that he wrote shortly thereafter studying the properties of a group (now called a Galois group)
were lost by the distinguished mathematicians that he had asked that is associated with the polynomial.
to present his papers to the Academy of Sciences. In 1831, Ga
lois wrote another paper carefully presenting the results of his
research. This paper was rejected as being "incomprehensible."
During the 1830 revolution, Galois criticized the director of his
school and was expelled. He also spent some time in jail be
cause of his political activities. On May 30, 1832 he was mor
tally woundedin a duel and died the next day at the age of 20.
Before his duel, Galois left a letter to a friend detailing the re
sults of his research. His results were so advanced for his time
that a full exposition of this work did not appear until 1870.
We are all familiar with the quadratic formula for the roots
of a quadraticpolynomial. It uses arithmeticoperationsand rad
icals, and so a quadratic is said to be solvable by radicals. Sim
ilar formulas for the roots of a cubic and fourth-degreepolyno Evariste Galois

344
9.1 Binary Operations Revisited 345

9.1 Binary Operations Revisited


We defined binary operations earlier (see Section 1.6) and noted in Section 5.2
that a binary operation may be used to define a function. Here we turn the process
around and define a binary operation as a function with certain properties.
A binary operation on a set A is an everywhere defined function /: Ax A ->
A. Observe the following properties that a binary operation must satisfy:
1. Since Dom(/) = A x A, / assigns an element f(a, b) of A to each ordered
pair (a, b) in A x A. That is, the binary operation must be defined for each
ordered pair of elements of A.
2. Since a binary operation is a function, only one element of A is assigned to
each ordered pair.
Thus we can say that a binary operation is a rule that assigns to each ordered
pair of elements of A a unique element of A. The reader should note that this
definition is more restrictive than that given in Chapter 1, but we have made the
change to simplify the discussion in this chapter. We shall now turn to a number
of examples.
It is customary to denote binary operations by a symbol such as *, instead of
/, and to denote the element assigned to (a, b) by a * b [instead of *(a, b)]. It
should be emphasized that if a and b are elements in A, then a * b e A, and this
property is often described by saying that A is closed under the operation *.

Example 1 Let A = Z. Define a * b as a + b. Then * is a binary operation on Z. ♦

Example 2 Let A = R. Define a * b as a/b. Then * is not a binary operation, since it is not
defined for every ordered pair of elements of A. For example, 3 * 0 is not defined,
since we cannot divide by zero. ♦

Example 3 Let A = Z+. Define a*b as <z —b. Then * is not a binary operation since it does
not assign an element of A to every ordered pair of elements of A; for example,
2*5 £ A. ♦

Example 4 Let A = Z. Define a *b as a number less than both a andb. Then * is nota binary
operation, since it does not assign a unique element of A to each ordered pair of
elements of A; for example, 8*6 could be 5,4, 3, 1, and so on. Thus, in this case,
* would be a relation from A x A to A, but not a function. ♦

Example 5 Let A = Z. Define a * b as max{a, b}. Then * is a binary operation; for example,
2*4 = 4, -3*(-5) = -3. ♦

Example 6 Let A = P(S), for some set S. If V and W are subsets of 5, define V * W as
V U W. Then * is a binary operation on A. Moreover, if we define V *' W as
VOW, then *' is another binary operation on A. ♦

As Example 6 shows, it is possible to define many binary operations on the


same set.

Example 7 Let M be the set of alln x n Boolean matrices for a fixed n. Define A*B as A v B
(see Section 1.5). Then * is a binary operation. This is also true of A A B. ♦

Example 8 Let L be a lattice. Define a * b as a a b (the greatest lower bound of a and b).
Then * is a binary operation on L. This is also true of a v b (the least upper bound
of a and b). ♦
346 Chapter 9 Semigroups and Groups
Tables
If A = {ai, a2,..., an] is a finite set, we can define a binary operation on A by
means of a table as shown in Figure 9.1. The entry in position /, j denotes the
element«/ *ay.

ax a2

a2

Figure 9.1

Example 9 Let A = {0,1}. We define binary operations v and a by the following tables:
V 0 1 A 0 1
0 0 1 0 0 0
1 1 1 1 0 1

For A = {a, b}, we shall determine the number of binary operations that can
be defined on A. Every binary operation * on A can be described by a table

Since every blank can be filled in with the element a or b, we conclude that there
are 2 •2 •2 •2 = 24 or 16 ways to complete the table. Thus, there are 16 binary
operations on A.

Properties of Binary Operations


Several of the properties defined for binary operations in Section 1.6 are of partic
ular importance in this chapter. We repeat them here.
A binary operation on a set A is said to be commutative if
a *b = b *a

for all elements a and bin A.

Example 10 The binary operation ofaddition on Z (as discussed inExample 1) iscommutative.

Example 11 The binary operation of subtraction onZ is notcommutative, since


2-3^3-2. ♦

A binary operation that is described by a table is commutative if and only if


the entries in the table are symmetric with respect to the main diagonal.
9.1 Binary Operations Revisited 347

Example 12 Which ofthe following binary operations on A = {a, b, c,d] are commutative?
* a b c d * a b c d
a a c b d a a c b d
b b c b a b c d b a

c c d b c c b b a c

d a a b b d d a c d

(a) (b)

Solution
The operation in (a) is not commutative, since a * b is c while b * a is b. The
operation in (b) is commutative, since the entries in the table are symmetric with
respect to the main diagonal. ♦

A binary operation * on a set A is said to be associative if


a * (b * c) = {a * b) * c
for all elements a, ft, and c in A.

Example 13 The binary operation of addition on Z is associative. ♦

Example 14 Thebinary operation of subtraction on Z is not associative, since


2 - (3 - 5) / (2 - 3) - 5. ♦

Example 15 Let L be a lattice. The binary operation defined bya*b = a Ab(see Example 8)is
commutative and associative. It also satisfies the idempotent property a A a = a.
A partial converse of this example is also true, as shown in Example 16. ♦

Example 16 Let * be a binary operation on a set A, and suppose that * satisfies the following
properties for any a, b, and c in A.
1. a = a * a Idempotent property
2. a*b = b*a Commutative property
3. a * (b * c) = (a * b) * c Associative property
Define a relation < on A by
a < b if and only if a = a*b.
Show that (A, <) is a poset, and for all a, b in A, GLB(a, b) =a*b.

Solution
We must show that < is reflexive, antisymmetric, and transitive. Since a = a * a,
a < a for all a in A, and < is reflexive.
Now suppose that a < b and b < a. Then, by definition and property 2,
a = a*b = b*a = b, so a = b. Thus < is antisymmetric.
If a < b and b < c, then a = a*fe = a*(fc*c) = (a*fe)*c = a*c, so
a < c and < is transitive.
Finally, we must show that, for all a and b in A, a*b = aAb (the greatest
lower bound of a and b with respect to <). We have a * b = a * (b* b) = (a *fc) *b,
so 0 * b < b. In a similar way, we can show that a * & < a, so a * 2? is a lower
bound for a and &. Now, if c < a and c < b, then c = c * a and c = c * £ by
definition. Thus c = (c * a) * fc = c * (a * &), so c < a * b. This shows that a * b
is the greatestlowerboundof a and b. ♦
348 Chapter 9 Semigroups and Groups

9.1 Exercises
In Exercises 1 through8, determine whether the description of 24. Consider the binary operation * defined on the set
* is a valid definition ofa binary operation on the set. A = [a, ft, c] by the following table.

1. On R, where a * b is ab (ordinary multiplication). * a ft c

2. On Z+, where a * b is a/b. a ft c ft


ft a ft c
3. OnZ, wherea*bisab.
c c a ft
4. On Z+, where a * b is «fe.
5. On Z+, where <z * ft is a —b. (a) Is * a commutative operation?
6. On R, where« * ft is a Vft. (b) Compute a * (ft * c) and {a * ft) * c.
7. On R, where a * ft is the largest rational number that is (c) Is * an associative operation?
less than ab. 25. Consider the binary operation * defined on the set
8. On Z, where a * ft is 2a + ft. A = [a, ft, c, d] by the following table.
/« Exercises 9 through 19, determine whether the binary op * a ft c d
eration * is commutative and whether it is associative on the
a a c ft d
set.
ft d a ft c

9. On Z+, where a*ftisa + ft + 2. c c d a a

d d ft a c
10. On Z, where a * ft is ab.
11. On R, where a * ft is a x |ft|. Compute
12. On the set of nonzero real numbers, where a * ft is a /ft. (a) c * d and J * c. (b) ft * d and d * ft.
13. On R, where a * ft is the minimum of a and ft. (c) a * (ft * c) and (a * ft) * c.
14. On the set of nxn Boolean matrices, where A * B is A O B (d) Is * commutative? associative?
(see Section 1.5).
In Exercises 26 and 27, complete the given table so that the
15. On R, where a * ft is aft/3. binary operation * is associative.
16. On R, where a * ft is ab + 2ft.
26. * a ft c d 27. * a ft c d
17. On a lattice A, where a * ft is a v ft. a a ft c d a ft a c d
18. On the set of 2 x 1 matrices, where ft ft a d c ft ft a c d
c c d a ft c

d d d c c d
Uj*l^J~l^+^+1J' 28. Let A be a set with n elements. How many binary opera
a + b tions can be defined on A?
19. On the set of rational numbers, where a * ft =
29 Let A be a set with n elements. How many commutative
20. Prove or disprove that the binary operation on Z+ of binary operations can be defined on A?
a * ft = GCD(a, ft) has the idempotent property. 30. Let A = {a, ft).
21. Prove or disprove that the binary operation in Exercise 19 (a) Make a table for each of the 16 binary operations that
has the idempotent property. can be defined on A.
22. Fill in the following table so that the binary operation * is (b) Using part (a), identify the binary operations on A
commutative. that are commutative.
* a ft c

a ft
31. Let A = {a, ft}.
ft c ft a (a) Using Exercise 30, identify the binary operations on
c a c A that are associative.

23. Fill in the following table so that the binary operation * is (b) Using Exercise 30, identify the binary operations on
commutative and has the idempotent property. A that satisfy the idempotent property.
32. Let * be a binary operation on a set A, and suppose that
* a ft c
* satisfies the idempotent, commutative, and associative
a c
properties, as discussed in Example 16. Define a relation
ft
< on A by a < ft if and only if ft = a * ft. Show that
c c a
(A, <) is a poset and, for all a and ft, LUB(a, ft) = a * ft.
9.2 Semigroups 349

33. Describe how the definition of a binary operation on a set the earlier definition.
A is different from the definition of a binary operation
given in Section 1.6. Explain also whether a binary oper 34. Define a binary operation on a set S by a * ft = ft. Is *
ation on a set is or is not a binary operation according to associative? commutative? idempotent?

9.2 Semigroups
In this section we define a simple mathematical structure, consisting of a set to
gether with a binary operation, that has many important applications.
A semigroup is a nonempty set 5 together with an associative binary opera
tion * defined on S. We shall denote the semigroup by (5, *) or, when it is clear
what the operation * is, simply by S. We also refer to a * ft as the product of a and
ft. The semigroup (5, *) is said to be commutative if * is a commutative operation.

Example 1 It follows from Section 9.1 that (Z, +) is a commutative semigroup. ♦

Example 2 The set P(S), where S is a set, together with the operation of union is a commuta
tive semigroup. ♦

Example 3 The set Z with the binary operation of subtraction is not a semigroup, since sub
traction is not associative. ♦

Example 4 Let 5 be a fixed nonempty set, and let Ss be the set of allfunctions /: 5 -> 5. If
/ andg areelements of Ss, wedefine / *g as / og, the composite function. Then
* is a binary operation on S5, andit follows from Section 4.7 that* is associative.
Hence (S5,*) is a semigroup. The semigroup Ss is not commutative. ♦

Example 5 Let (L, <) be a lattice. Define a binary operation on L by a * ft = a v ft. Then L
is a semigroup. ♦

Example 6 Let A = {a\,a2,..., an] be a nonempty set. Recall from Section 1.3 that A* is
the set of all finite sequences of elements of A. That is, A* consists of all words
that can be formed from the alphabet A. Let a and /} be elements of A*. Observe
that catenation is a binary operation • on A*. Recall that if a = a\a2 --an and
P = b\b2 -"h, then a*P = a\a2 •••anb\b2 --bk. It is easy to see that if a, ft,
and y are any elements of A*, then

a-08-y) = (a-jS)-y

so that • is an associative binary operation, and (A*, •) is a semigroup. The semi


group (A*, •) is called the free semigroup generated by A. ♦

In a semigroup (5, *) we can establish the following generalization of the


associative property; we omit the proof.

THEOREM 1 If a\, a2,..., an,n > 3, are arbitraryelements of a semigroup,then all products of
the elements a\, a2,..., an that can be formed by inserting meaningful parentheses
arbitrarily are equal. •

Example 7 Theorem 1 shows that theproducts


((a\ * a2) * a^) * #4, a\ * (a2 * (#3 * #4)), (a\ * (a2 * 03)) * a$

are all equal. ♦


350 Chapter 9 Semigroups and Groups
If a\, a2,..., an are elements in a semigroup (5, *), we shall write their prod
uct as
a\ * a2 * • • • * an,

omitting the parentheses.


An element e in a semigroup (5, *) is called an identity element if
e *a = a*e = a

for all a e S. As shown by Theorem 1, Section 1.6, an identity element must be


unique.

Example 8 Thenumber 0 is an identity in thesemigroup (Z, +). ♦

Example 9 The semigroup (Z+, +) has noidentity element. ♦

A monoid is a semigroup (5, *) that has an identity.

Example 10 The semigroup P(S) defined in Example 2 has the identity 0, since
0*A=0UA=A=AU0=A*0

for any element A e P(S). Hence P(S) is a monoid. ♦

Example 11 Thesemigroup Ss defined in Example 4 has the identity 1$, since


U*f = Uof = fols=:f*ls

for any element f e Ss. Thus, we see that Ss is a monoid. ♦

Example 12 The semigroup A* defined in Example 6 is actually a monoid with identity A, the
empty sequence, since a-A = A- a = a for all a e A*. ♦

Example 13 The set ofall relations on a set Ais a monoid under the operation ofcomposition.
The identity element is the equality relation A (see Section 4.7). ♦

Let (5, *) be a semigroup and let T be a subset of S. If T is closed under the


operation * (that is, a * ft e T whenever a and ft are elements of T), then (7\ *)
is called a subsemigroup of (5, *). Similarly, let (5, *) be a monoid with identity
e, and let T be a nonempty subset of S. If T is closed under the operation * and
e € T, then (7\ *) is called a submonoid of (5, *).
Observe that the associative property holds in any subset of a semigroup so
that a subsemigroup (7\ *) of a semigroup (5, *) is itself a semigroup. Similarly,
a submonoid of a monoid is itself a monoid.

Example 14 If T is the set of all even integers, then (7\ x) is a subsemigroup of the monoid
(Z, x), where x is ordinary multiplication, but it is not a submonoid since the
identity of Z, the number 1, does not belong to T. ♦

Example 15 If (5, *) is a semigroup, then (S, *) is a subsemigroup of (5, *). Similarly, let
(5, *) be a monoid. Then (5, *) is a submonoid of (5, *), and if T = {e}, then
(7\ *) is also a submonoid of (5, *). ♦

Suppose that (5, *) is a semigroup, and let a e S. For n £ Z+, we define the
powers of an recursively as follows:

a]=a, a" = an~l *a, n>2.


9.2 Semigroups 351

Moreover, if (5, *) is a monoid, we also define

a° = e.

It can be shown that if m and n are nonnegative integers, then

am*an=am+n.

Example 16 (a) If (5, *) is a semigroup, a e\ 5, and

T = {a1 | i GZ+},
then (7\ *) is a subsemigroup of (5, *).
(b) If (5, *) is a monoid, a e 5, and

r = {a' | i eZ+or/ =0},


then (7\ *) is a submonoid of (5, *). ♦

Isomorphism and Homomorphism


An isomorphism between two posets was defined in Section 6.1 as a one-to-one
correspondence that preserved order relations, the distinguishing feature of posets.
We now define an isomorphism between two semigroups as a one-to-one corre
spondence that preserves the binary operations. In general, an isomorphism be
tween two mathematical structures of the same type should preserve the distin
guishing features of the structures.
Let (5, *) and (7\ *') be two semigroups. A function f:S-+Tis called an
isomorphism from (5, *) to (T, *') if it is a one-to-one correspondence from 5 to
7\ and if
f(a*b) = f(a)*' f(b)
for all a and ft in 5.
If / is an isomorphism from (5, *) to (7\ *'), then, since / is a one-to-one
correspondence, it follows from Theorem 1ofSection 5.1 that f~l exists and isa
one-to-one correspondence from TtoS. We now show that f~l is an isomorphism
from (J, *') to (5, *). Let a' and ft' be any elements of T. Since / is onto, we can
find elements a and ft in 5 such that f(a) = a! and /(ft) = ft'. Then a = f~l {a')
and ft = /"1 (ft'). Now
/-1(fl,*,*/) = /"1 (/(«)*'/(«)
= /"1(/(fl*«)
= (rlof)(fi*b)
= a*ft = /-1(a,)*/-l(ft/).
Hence f~l is an isomorphism.
We now say that the semigroups (5, *) and (7\ *;) are isomorphic and we
write 5 ~ T.
To show that two semigroups (5, *) and (7\ *') are isomorphic, we use the
following procedure:
Step 1 Define a function f:S^T with Dom(/) = 5.
Step 2 Show that / is one-to-one.
Step 3 Show that / is onto.
Step 4 Show that f(a * ft) = f(a) *' /(ft).
352 Chapter 9 Semigroups and Groups
Example 17 Let T be the set of all even integers. Show that the semigroups 5, +) and (T, +)
are isomorphic.

Solution

Step 1 We define the function f:Z->Tbyf(a) = 2a.


Step 2 We now show that / is one to one as follows. Suppose that f(a\) = f(a2).
Then 2a\ =2a2,soa\ = a2. Hence / is one to one.
Step 3 We next show that / is onto. Suppose that ft is any even integer. Then
a = ft/2 G Z and

f(a) = /(ft/2) = 2(ft/2) = ft,

so / is onto.
Step 4 We have

f(a + ft) = 2{a + b) = 2a + 2b = f(a) + /(ft).

Hence (Z, +) and (7\ +) are isomorphic semigroups. ♦

In general, it is rather straightforward to verify that a given function


/: 5 -• T is or is not an isomorphism. However, it is generally more difficult
to show that two semigroups are isomorphic, because one has to create the iso
morphism /.
As in the case of poset or lattice isomorphisms, when two semigroups (S, *)
and (7\ *') are isomorphic, they can differ only in the nature of their elements;
their semigroup structures are identical. If 5 and T are finite semigroups, their
respective binary operations can be given by tables. Then 5 and T are isomorphic
if we can rearrange and relabel the elements of S so that its table is identical with
that of T.

Example 18 Let S = {a, ft, c] and T = {x, y, z}. Itis easy to verify that the following operation
tables give semigroup structures for 5 and T, respectively.

* a ft c * x y z
a a ft c x z x y
ft ft c a y x y z
c c a ft z y z x

Let

f(a) = y
f(b) = x
fie) = z.

Replacing the elements in S by their images and rearranging the table, we obtain
exactly the table for T. Thus S and T are isomorphic. ♦

THEOREM 2 Let (5, *) and (7, *') be monoids with identities e and ef, respectively. Let
/: 5 -> T be an isomorphism. Then f(e) = ef.
9.2 Semigroups 353

Proof
Let ft be any element of T. Since / is onto, there is an element a in 5 such that
f(a) = ft. Then
a = a *e

b = f(a) = f(a*e) = f(a)*'f(e)


= ft *'/(*)•
Similarly, since a = e * a, ft = f(e) *' ft. Thus for any ft € 7\

* = **'/(*) = /(*)*'&,
which means that /(e) is an identity for T. Thus since the identity is unique, it
follows that f(e) = e'. •

If (5, *) and (7\ *') are semigroups such that S has an identity and T does
not, it then follows from Theorem 2 that (5, *) and (7\ *') cannot be isomorphic.

Example 19 Let T be thesetof alleven integers andlet x be ordinary multiplication. Then the
semigroups (Z, x) and (7\ x) are not isomorphic, since Z has an identity and T
does not. ♦

By dropping the conditions of one to one and onto in the definition of an


isomorphism of two semigroups, we get another important method for comparing
the algebraic structures of the two semigroups.
Let (5, *) and (7, *') be two semigroups. An everywhere-defined function
/: S -> T is called a homomorphism from (5, *) to (7\ *') if
f(a*b) = f(a)*'f(b)

for all a and ft in 5. If / is also onto, we say that T is a homomorphic image of


5.

Example 20 Let A = {0,1} and consider the semigroups (A*, •) and (A, +), where • is the
catenation operation and + is defined by the table

+ 0 1
0 0 1
1 1 0

Define the function /: A* -• A by

1 if or has an odd number of 1 's


/(«) =
0 if or has an even number of 1 's.

It is easy to verify that if a and ft are any elements of A*, then

f{a-P) = f(a) + /OS).

Thus / is a homomorphism. The function / is onto since

/(0) = 0
/(I) = 1

but / is not an isomorphism, since it is not one to one.


354 Chapter 9 Semigroups and Groups
The difference between an isomorphism and a homomorphism is that an iso
morphism must be one to one and onto. For both an isomorphism and a homomor
phism, the image of a product is the product of the images.
The proof of the following theorem, which is left as an exercise for the reader,
is completely analogous to the proof of Theorem 2.

THEOREM 3 Let (S, *) and (T, *') be monoids with identities e and e\ respectively. Let
/: 5 -> T be a homomorphism from (5, *) onto (T, *'). Then f(e) = e'. •
Theorem 3 is a stronger, or more general, statement than Theorem 2, because
it requires fewer (weaker) conditions for the conclusion.
Theorem 3, together with the following two theorems, shows that, if a semi
group (7\ *') is a homomorphic image of the semigroup (5, *), then (7\ *') has a
strong algebraic resemblance to (5, *).

THEOREM 4 Let / be a homomorphism from a semigroup (5, *) to a semigroup (7\ *'). If S'
is a subsemigroup of (5, *), then

f(Sf) = {teT\t = f(s) for some s e S'},


the image of S" under /, is a subsemigroup of (7\ *').

Proof
If t\ and t2 are any elements of /(S;), then there exist s\ and s2 in Sf with

h = f(s\) and t2 = f(s2).


Then
tx *' h = f(S]) *' f(s2) = f(sx * S2) = f(s3),
where s3 = s{ * s2 e S'. Hence t\ *' t2 e f(S').
Thus f(S') is closed under the operation *'. Since the associative property
holds in 7\ it holds in f(S'), so f(S') is a subsemigroup of (7, *'). •

THEOREM 5 If / is a homomorphism from a commutative semigroup (5, *) onto a semigroup


(7\ *0, then (7\ *') is also commutative.

Proof
Let t\ and ^ be any elements of T. Then there exist si and ^2 in S with

h = /C*i) and t2 = f(s2).


Therefore,

'1 *' h = f(si) *' f(s2) = f(s{ * s2) = f(s2 * ^1) = f(s2) *' /(sO = t2 *' fi.
Hence (7, *') is also commutative. •

9.2 Exercises

1. Let A = [a, ft}. Which of the following tables define a 2. Let A = {a, ft}. Which of the following tables define a
semigroup on A? Which define a monoid on A? semigroup on A? Which define a monoid on A?
(a) * a ft (b) * <2 ft (a) * a ft (b) * a ft
a a ft a (2 ft a ft a a a ft
ft a <2 ft ft ft ft a ft ft ft a
9.2 Semigroups 355

3. Let A = {a, ft}. Which of the following tables define a 20. Complete the following table so that it defines a monoid.
semigroup on A? Which define a monoid on A?
* a ft C J
(a) * a ft (b) * a ft
a c J fl ft
a a a a ft ft
ft (2 ft
ft ft ft ft a <z
c C

In Exercises 4 through 16, determine whether the set together d ft J a

with the binary operation is a semigroup, a monoid, or neither.


If it is a monoid, specify the identity. If it is a semigroup or a 21. Let S = {a,b}. Write the operation table for the semi
monoid, determine if it is commutative. group Ss. Is the semigroup commutative?
22. Let S = {a, ft}. Write the operation table for the semi
4. Z+, where * is defined as ordinary multiplication. group (P(S), U).
5. Z+, where a * ft is defined as max{a, ft}. 23. Let A = {a, ft, c] and consider the semigroup (A*, •)>
6. Z+, where a * ft is defined as GCD{<z, ft}. where • is the operation of catenation. If a = flftac,
P = cfta, and y = babe, compute
7. Z+, where a *ft is defined as a.
(a) (a-pyY (b) Y<a-a) (c) (y •£)•<*
8. The nonzero real numbers, where * is ordinary multipli 24. What is required for a subset of the elements of a semi
cation.
group to be a subsemigroup?
9. P(S), with S a set, where * is defined as intersection. 25. What is required for a subset of the elements of a monoid
to be a submonoid?
10. A Boolean algebra B, where a * ft is defined as a a ft.
26. Prove or disprove that the intersection of two subsemi-
11. 5 = {1,2, 3, 6,12}, where a * ft is defined as GCD(a, ft).
groups of a semigroup (S, *) is a subsemigroup of (S, *).
12. 5 = {1,2,3,6,9,18}, where a * ft is defined as 27. Prove or disprove that the intersection of two submonoids
LCM(a,ft). of a monoid (S, *) is a submonoid of (S, *).
13. Z, wherea*b = a + b —ab. 28. Let A = {0, 1}, and consider the semigroup (A*, •)»
ab where • is the operation of catenation. Let T be the subset
14. The even integers, where a * ft is defined as —. of A* consisting of all sequences having an odd number
of l's. Is (7\ •) a subsemigroup of (A, •)?
15. The set of 2 x 1 matrices, where
29. Let A = {#,ft}. Are there two semigroups (A,*) and
a + c (A, *') that are not isomorphic?

[:]•[;]-[ ft + d+1 30. An element x in a monoid is called an idempotent if


jc2 = jc * x = jc. Show that the set of all idempotents
16. The set of integers of the form 3/:+ 1, k e Z+, where * is in a commutative monoid S is a submonoid of S.
ordinary multiplication. 31. Let (Si,*i), (S2,*2), and (S3, *3) be semigroups and
17. Does the following table define a semigroup or a monoid? /: Si —• S2 and g: S2 —> 53 be homomorphisms. Prove
that g o / is a homomorphism from Si to S3.
* a ft c
32. Let (Si, *), (S2, *'), and (S3, *") be semigroups, and let
a c ft a /: Si -> S2 and g: S2 -» S3 be isomorphisms. Show
ft ft c ft that g o /: Si -> S3 is an isomorphism.
c a ft c
33. Which properties of / are used in the proof of Theorem 2?
18. Does the following table define a semigroup or a monoid? 34. Explain why the proof of Theorem 1 can be used as a
proof of Theorem 3.
* a ft c 35. Let R+ be the set of all positive real numbers. Show that
a a c ft the function /: R+ -* R defined by /(jc) = hue is an
ft c ft a isomorphism of the semigroup (R+, x) to the semigroup
c ft a c (E, +), where x and + are ordinary multiplication and
addition, respectively.
19. Complete the following table to obtain a semigroup. 36. Let (S, *) be a semigroup and A, a finite subet of S. De
fine A to be the set of all finite products of elements in A.
* a ft c

a c a ft (a) Prove that A is a subsemigroup of (S, *).


ft a ft c (b) Prove that A is the smallest subsemigroup of (S, *)
c a
that contains A.
356 Chapter 9 Semigroups and Groups

9.3 Products and Quotients of Semigroups


In this section we shall obtain new semigroups from existing semigroups.

THEOREM 1 If (S, *) and (T, *') are semigroups, then (S x 7, *") is a semigroup, where *" is
defined by (s\, t\) *" (s2i t2) = (s\ * s2, t\ *' t2).

Proof
The proof is left as an exercise. •

It follows at once from Theorem 1 that if S and T are monoids with identities
es and ej, respectively, then S x T is a monoid with identity (e$, ej).
We now turn to a discussion of equivalence relations on a semigroup (S, *).
Since a semigroup is not merely a set, we shall find that certain equivalence rela
tions on a semigroup give additional information about the structure of the semi
group.
An equivalence relation R on the semigroup (S, *) is called a congruence
relation if

a R a! and b R b' imply (a*b) R (a' * b').

Example 1 Consider the semigroup (Z, +) and the equivalence relation RonZ defined by
a Rb if and only if a = b (mod 2).

Recall that we discussed this equivalence relation in Section 4.5. Remember that
ifa = b (mod 2), then 2 | (a —b). We now show that this relation is a congruence
relation as follows.
If
a = b (mod 2) and c = d (mod 2),
then 2 divides a—b and 2 divides c - d, so

a - b = 2m and c —d = 2n,

where m and n are in Z. Adding, we have


(a - b) + (c - d) = 2m + 2n

or

(a + c)-(b + d) = 2(m + n),


so

a + c = b + d (mod 2).
Hence the relation is a congruence relation. ♦

Example 2 LetA = {0,1} and consider the free semigroup (A*, •) generated by A. Define the
following relation on A:

a R ft if and only if a and /3 have the same number of 1's.

Show that R is a congruence relation on (A*, •)•

Solution
We first show that R is an equivalence relation. We have
1. a R a for any a e A*.
9.3 Products and Quotients of Semigroups 357
2. If a R fi, then a and ft have the same number of l's, so P R a.
3. IfaRfi and p R y, then a and p have the same number of l's and p and y
have the same number of l's, so a and y have the same number of l's. Hence
a R y-
We next show that R is a congruence relation. Suppose that a Rot' and
P R P'. Then a and a! have the same number of l's and P and pf have the same
number of 1's. Since the number of 1's in a*P is the sum of the number of 1's in a
and the number of l's in jS, we conclude that the number of l's in ct*p is the same
as the number of l's in a'-/}'. Hence
(a-p) R (a'-pf)
and thus R is a congruence relation. ♦

Example 3 Consider the semigroup (Z, +), where + is ordinary addition. Let f(x) =
x2 —x —2. We now define the following relation on Z:
a Rb if and only if f(a) = f(b).
It is straightforward to verify that R is an equivalence relation on Z. However, R
is not a congruence relation since we have
-1 R2 since/(-l) = /(2) = 0
and
-2 R 3 since f{-2) = f(3) = 4
but
(_l + (-2))*(2 + 3)
since /(-3) = 10 and /(5) = 18. ♦

Recall from Section 4.5 that an equivalence relation R on the semigroup (S, *)
determines apartition of5. We let [a] = R(a) be the equivalence class containing
a and S/R denote the set of all equivalence classes. The notation [a] is more
traditional in this setting and produces less confusing computations.

THEOREM 2 Let R be a congruence relation on the semigroup (5, *). Consider the relation ®
from S/R x S/R to S/R in which the ordered pair ([a], [b]) is, for a and b in 5,
related to [a*b].
(a) ® is a function from S/R x S/R to S/R, and as usual we denote ®([a], [b])
by [a] ® [b]. Thus [a] ® [6] = [a * &].
(b) (5//?, ®) is a semigroup.

Suppose that ([a], [£]) = ([a7], [&']). Then a R a; md b R b\ so we must have


a*b R af *b\ since # is a congruence relation. Thus [a * &] = [<z' * Z/]; that is,
® is a function. This means that ® is a binary operation on S/R.
Next, we must verify that ® is an associative operation. We have
[a] ® ([b] ® [c]) = [a] ® [b * c]
= [a * (b * c)]
= [(a * £) * c] by the associative property of * in 5
= [a * b] ® [c]
= ([a] ® [&]) ® [c].
358 Chapter? Semigroups and Groups
Hence S/R is a semigroup. We call S/R the quotient semigroup or factor semi
group. Observe that ® is a type of "quotient binary relation" on S/R that is
constructed from the original binary relation * on S by the congruence relation R.

Corollary 1 Let R be a congruence relation on themonoid (S, *). If wedefine the operation ®
in S/R by [a] ® [b] = [a* b], then (S/R, ®) is a monoid.

Proof
If e is the identity in (S, *), then it is easy to verify that [e] is the identity in
(S/R, ®). •

Example 4 Consider the situation in Example 2. Since R is a congruence relation on the


monoid S = (A*, •), we conclude that (S/R, O) is a monoid, where

m © m = [<*-Pl ♦

Example 5 As has already been pointed out in Section 4.5, we can repeat Example 4 of that
section with the positive integer n instead of 2. That is, we define the following
relation on the semigroup (Z, +):

a Rb if and only if a = b (mod n).

Using exactly the same method as in Example 4 in Section 4.5, we show that R
is an equivalence relation and, as in the case of n = 2, a = b (mod n) implies
n | (a —b). Thus, if n is 4, then

2 = 6 (mod 4)

and 4 divides (2-6). We also leave it for the reader to show that = (mod n) is a
congruence relation on Z.
We now let n = 4 and we compute the equivalence classes determined by the
congruence relation = (mod 4) on Z. We obtain

[0] = {..., -8, -4, 0,4, 8, 12,...} = [4] = [8] = • • •


[1] = {..., -7, -3, 1,5,9, 13, ...} = [5] = [9] = ..
[2] = {..., -6, -2, 2, 6,10, 14,...} = [6] = [10]
[3] = {..., -5, -1, 3, 7, 11, 15,...} = [7] = [11] = • •. .

These are all the distinct equivalence classes that form the quotient set Z/ =
(mod 4). It is customary to denote the quotient set Z/ = (mod n) by Z„; Zw is
a monoid with operation © and identity [0]. We now determine the addition table
for the semigroup Z4 with operation ©.

e [0] [1] [2] [3]


[0] [0] [1] [2] [3]
[i] [1] [2] [3] [0]
[2] [2] [3] [0] [1]
[3] [3] [0] [1] [2]

The entries in this table are obtained from

[a] © [b] = [a + b].


9.3 Products and Quotients of Semigroups 359
Thus

[1]© [2] = [1+2] = [3]


[1]0[3] = [1+3] = [4] = [O]
[2]©[3] = [2 + 3] = [5] = [l]
[3] ©[3] = [3+ 3] = [6] = [2].

It can be shown that, in general, Zn has the n equivalence classes


[0],[l],[2]f...,[n-l]
and that
[a] © [ft] = [r],
where r is the remainder when a + b is divided by n. Thus, if n is 6,
[2] © [3] = [5]
[3] © [5] = [2]
[3] © [3] = [0]. ♦

We shall now examine the connection between the structure of a semigroup


(5, *) and the quotient semigroup (S/R, ®), where R is a congruence relation on
(5, *).

THEOREM 3 Let R be a congruence relation on a semigroup (S, *), and let (S/R, ®) be the
corresponding quotient semigroup. Then the function fR: S -> S/R defined by
fn(a) = [a]
is an onto homomorphism, called the natural homomorphism.

Proof
If [a] € S/R, then fR(a) = [a], so fR is an onto function. Moreover, if a and b
are elements of S, then

fR(a * ft) = [a * ft] = [a] ® [ft] = fR(a) ® /*(&),


so //? is a homomorphism. •

THEOREM 4 Let /: S -* T be a homomorphism of the semigroup (S, *) onto the semigroup


Fundamental (T> *')• Let ^ be the relation on s defined by a R b if and only if f(a) = f(b),
Homomorphism Theorem for * and bin 5- Then
(a) R is a congruence relation.
(b) (T, *') and the quotient semigroup (S/R, ®) are isomorphic.

(a) We show that R is an equivalence relation. First, a R a for every a e S,


since /(a) = /(a). Next, if a R b, then /(a) = f(b), sob Ra. Finally,
if a R b and ft /? c, then /(a) = /(ft) and f(b) = /(c), so /(a) = /(c)
and a R c. Hence # is an equivalence relation. Now suppose that a Ra\
and b # ft,. Then

f(a) = f(ax) and f(b) = f(bx).


Multiplying in T, we obtain
/(«)*' f(b) = f(al)*ff(bl).
360 Chapter 9 Semigroups and Groups
Since / is a homomorphism, this last equation can be rewritten as

/(a*ft) = f(a{ *fti).

Hence
(a*b) R (a\ *fti)
and R is a congruence relation.
(b) We now consider the relation / from S/RtoT defined as follows:

7={([alf(a))\[a]eS/R}.
We first show that / is a function. Suppose that [a] = [a']. Then a R a',
so f(a) = f(a'), which implies that / is a function. We may now write
/: S/R -> T, where J([a\) = f(a) for [a] € S/R.
We next show that / is one to one. Suppose that f([a]) = f([a']).
Then
f(a) = f(af).
So a R a!, which implies^that [a] = [a']. Hence / is one to one.
Now we show that / is onto. Suppose that ft e T. Since / is onto,
f(a) = ft for some element a in 5. Then

Ida]) = f(a) = ft.


So / is onto.
Finally, _ _
f([a]®[b]) = f([a*b])
= f(a*b) = f(a)*'f(b)
= 7(M)*'7(M)-
Hence / is an isomorphism. •

Example 6 Let A = {0,1}, and consider the free semigroup A* generated by A under the
operation of catenation. Note that A* is a monoid with the empty string A as its
identity. Let N be the set of all nonnegative integers. Then N is a semigroup under
the operation of ordinary addition, denoted by (N, +). The function /: A* -> N
defined by
f(a) = the number of l's in a
is readily checked to be a homomorphism. Let R be the following relation on A*:
ot R P if and only if f(a) = f(P).

That is, a R p if and only if a and P have the_same number of l's. Theorem 4
implies that A*/R ~ N under the isomorphism /: A*/R ->• N defined by
f([a]) = f(a) = the number of l's in a. ♦

Theorem 4(b) canbe described by the diagram shown in Figure 9.2._Here fR


is the natural homomorphism. It follows from the definitions of fR and / that

JofR = f
since
(fofR)(a) = J(fR(a)) = J([a]) = f(a).
9.3 Products and Quotients of Semigroups 361
9.3 Exercises

1. Let (S, *) and (7\ *') be commutative semigroups. Show 20. Describe the quotient semigroup for S and R given in Ex
that S x T (see Theorem 1) is also a commutative semi ercise 10.
group.
21. Describe the quotient semigroup for S and R given in Ex
2. Let (5, *) and (T, *') be monoids. Show that S x T is also ercise 11.
a monoid. Show that the identity of S x T is (es, eT). 22. Describe the quotient semigroup for S and R given in Ex
3. Let (S, *) and (T, *') be semigroups. Show that the ercise 12.
function f:SxT^>S defined by f(s, t) = s is a 23. Describe the quotient semigroup for S = Z with ordinary
homomorphism of the semigroup S x T onto the semi addition and R defined by a R b if and only if
group S. a = b (mod 5).
4. Let (S, *) and (T, *') be semigroups. Show that S x T 24. Consider the semigroup S = {a, b, c, d] with the follow
and T x S are isomorphic semigroups. ing operation table.
5. Prove Theorem 1.
* a b c d
In Exercises 6 through 16, determine whether the relation R a a b c d
on the semigroup S is a congruence relation. b b a d c

c c d a b
6. S = Z under the operation of ordinary addition; a R b if
d d c b a
and only if 2 does not divide a —b.
7. S = Z under the operation of ordinary addition; a Rb\i Consider the congruence relation R = {(a,a),(a,b),
and only if a -f b is even. (b, a), (b, b), (c, c), (c, d), (d, c), (d, d)} on S.
8. 5 is any semigroup; a R b if and only ifa = b. (a) Write the operation table of the quotient semigroup
S/R.
9. 5 is the set of all rational numbers under the operation of
addition; a/b R c/d if and only if ad = be. (b) Describe the natural homomorphism fR: S -> S/R.
10. S is the set of all rational numbers under the operation of 25. Consider the monoid S = {e, a, b, c] with the following
multiplication; a/b R c/d if and only if ad = be. operation table.
11. S = Z under the operation of ordinary addition; a R b if * e a b c
and only ifa = b (mod 3). e e a b c

12. 5 = Z under the operation of ordinary addition; a R b if a a e b c

and only if a and &are both even or a and b are both odd. b b c b c

c c b b c
13. S = Z+ under the operation of ordinary multiplication;
a R b if and only if |<z —&| < 2. Consider the congruence relation R = {(e,e),(e,a),
14. A = {0, 1} and S = A*, the free semigroup generated by (a, e), (a, a), (b, b), (b, c), (c, b), (c, c)} on S.
A under the operation of catenation; a R p if and only if (a) Write the operation table of the quotient monoid
a and /J both have an even number of l's or both have an S/R.
odd number of 1 's.
(b) Describe the natural homomorphism fR: S -» S/R.
15. S = {0, 1} under the operation * defined by the table
26. Let A = {0, 1} and consider the free semigroup A* gener
* 0 1
ated by A under the operation of catenation. Let N be the
0 0 1
semigroup of all nonnegative integers under the operation
1 1 0
of ordinary addition.
(a) Verify that the function /: A* -+ N, defined by
a R b if and only if a * a = b * b. (Hint: Observe that if /(or) = the number of digits in a, is a homomor
x is any element in S, then x * x = 0.) phism.
16. S = {3k + 1, k e Z+) under the operation of ordinary (b) Let R be the following relation on A*: a R P if and
multiplication; a R b if and only if a = b (mod 5). only if f(a) = f(P). Show that R is a congruence
17. Describe the quotient semigroup for S and R given in Ex relation on A*.

ercise 16. (c) Show that A*/R and N are isomorphic.


18. Show that the intersection of two congruence relations on 27. Prove or disprove that Z2 is isomorphic to the semigroup
a semigroup is a congruence relation. in Exercise 22.

19. Show that the composition of two congruence relations on 28. Prove or disprove that Z4 is isomorphic to the semigroup
a semigroup need not be a congruence relation. in Exercise 24.
362 Chapter 9 Semigroups and Groups
29. Describe the strategy of the proofof Theorem 4. Outline 30. Let S be a nonempty set witha*b —b. Prove that any
theproof. equivalence relation on S is a congruence relation.

9.4 Groups
In this section we examine a special type of monoid, called a group, that has ap
plications in every area where symmetry occurs. Applications of groups can be
found in mathematics, physics, and chemistry, as well as in less obvious areas
such as sociology. Recent and exciting applications of group theory have arisen in
fields such as particle physics and in the solutions of puzzles such as Rubik's cube.
In this book, we shall present an important application of group theory to binary
codes in Section 11.2.
A group (G, *) is a monoid, with identity e, that has the additional property
that for every element a e G there exists an element a' e G such that a * a' =
af *a = e. Thus a group is a set together with a binary operation * on G such that
1. (a * b) * c = a * (b * c) for any elements a, b, and c in G.
2. There is a unique element e in G such that

a *e = e*a for any a G G.

3. For every a e G, there is an element a! e G, called an inverse of a, such that

a *af = a1 *# = e.

Observe that if (G, *) is a group, then * is a binary operation, so G must be


closed under *; that is,

a*b e G for any elements a and b in G.

To simplify our notation, from now on when only one group (G, *) is under
consideration and there is no possibility of confusion, we shall write the product
a * b of the elements a and b in the group (G, *) simply as ab, and we shall also
refer to (G, *) simply as G.
A group G is said to be Abelian if ab = ba for all elements a and b in G.

Example 1 The set of all integers Z with the operation of ordinary addition is an Abelian
group. If a e Z, then an inverse of a is its opposite —a. ♦

Example 2 The setZ+ under the operation ofordinary multiplication is not a group since, for
example, the element 2 in Z+ has no inverse. However, this set together with the
given operation is a monoid. ♦

Example 3 The set ofall nonzero real numbers under the operation ofordinary multiplication
is a group. An inverse of a ^ 0 is 1/a. ♦

Example 4 Let G be the set of all nonzero real numbers and let

ab
a*b = —.
2

Show that (G, *) is an Abelian group.


9.4 Groups 363

Solution
We first verify that * is a binary operation. If a and b are elements of G, then ab/2
is a nonzero real number and hence is in G. We next verify associativity. Since

. „ . (ab)c
=(f)*c=
(a * 6) * c = I — I * c =

and since
(bc\ o(
j(fcc) (a&)c
tf*(b*c)=#*( — ) = —-— = ,

the operation * is associative.


The number 2 is the identity in G, for if a e G, then

. (a)(2) (2)(a)
a*2 = —-— = a = —-— = 2 *a.
2 2

Finally, if a e G, then a! = A/a is an inverse of a, since


4 a(4/a) (A/a)(a) 4
a*a = # * - = = 2 = = —* a = a * a.
a 2 2 a

Since a * b = b * a for all a and b in G, we conclude that G is an Abelian group.

Before proceeding with additional examples of groups, we develop several


important properties that are satisfied in any group G.

THEOREM 1 Let G be a group. Each element a in G has only one inverse in G.

Proof
Let a! and a" be inverses of a. Then

a'{aa") = a'e = a'

and
(a'a)a" = ea" = a".
Hence, by associativity,

a' = a".

From now on we shall denote the inverse of a by a . Thus in a group G we


have
aa { = a la = e.

THEOREM 2 Let G be a group and let a, b, and c be elements of G. Then


(a) ab = ac implies that b = c (left cancellation property).
(b) ba = ca implies that b = c (right cancellation property).

Proof
(a) Suppose that

ab = ac.
364 Chapter 9 Semigroups and Groups
Multiplying both sides of this equation by a xon the left, we obtain
a~x(ab) = a~x(ac)
(a~xa)b = (a~la)c by associativity
eb = ec by the definition of an inverse
b= c by definition of an identity.

(b) The proof is similar to that of part (a). •

Corollary 1 Let G be a group and a e G. Define a function Ma: G -> G by the formula
Ma(g) = ag. Then Ma is one to one.

Proof
This is a direct consequence of Theorem 2. •

THEOREM 3 Let G be a group andleta and b be elements of G. Then


(a) (a~xyx=a.
(b) (ab)~l =b-la~l.

Proof
(a) We show that a acts as an inverse for a~x:
a~xa —aa~x = e.
Since the inverse of an element is unique, we conclude that (a-1)-1 = a.
(b) We easily verify that
(ab)(b~xa~x) = a(b(b-xa~x)) = a((bb~x)a-x) = a(ea~x) = aa~l = e
and, similarly,
(b-xa~x)(ab) = e,
so

(ab)~x =b-xa~x. M

THEOREM 4 Let G be a group, and leta and b be elements of G. Then


(a) The equation ax = b has a unique solution in G.
(b) The equation ya = b has a unique solution in G.

Proof
(a) The element x = a~xb is a solution of the equation ax = b, since
a(a~xb) = (aa~x)b = eb = b.
Suppose now that x\ and x-i are two solutions of the equation ax = b.
Then
ax\ = b and ax2 = b.
Hence
ax\ — ax2.

Theorem 2 implies that x\ =xi.


(b) The proof is similar to that of part (a). •
9.4 Groups 365

From our discussion of monoids, we know that if a group G has a finite


number of elements, then its binary operation can be given by a table, which
is generally called a multiplication table. The multiplication table of a group
G = [a\, a2, •••, an] under the binary operation * must satisfy the following prop
erties:

1. The row labeled by e must be

a{,a2, ,an

and the column labeled by e must be

a2

TABLE 9.1

e a
2. From Theorem 4, it follows that each element b of the group must appear
exactly once in each row and column of the table. Thus each row and column
e e a
is a permutation of the elements a\, a2,..., an of G, and each row (and each
a a
column) determines a different permutation.
If G is a group that has a finite number of elements, we say that G is a finite
TABLE 9.2 group, and the order of G is the number of elements |G| in G. We shall now
e a
determine the multiplication tables of all nonisomorphic groups of orders 1, 2, 3,
and 4.
e e a
If G is a group of order 1, then G = {e}, and we have ee = e. Now let
a \ a e G = [e, a] be a group of order 2. Then we obtain a multiplication table (Table
9.1) where we need to fill in the blank. The blank can be filled in by e or by a.
Since there can be no repeats in any row or column, we must write e in the blank.
3IPI$^ The multiplication table shown in Table9.2 satisfies the associativity propertyand
e a b the otherproperties of a group, so it is the multiplication tableof a groupof order2.
Next, let G = [e, a, b) be a group of order 3. We have a multiplication table
e e a b
(Table 9.3) where we must fill in four blanks. A little experimentation shows that
a a
we can only complete the table as shownin Table9.4. It can be shown (a tedious
b b task) that Table 9.4 satisfies the associative property and the other properties of a
group. Thus it is the multiplication table of a group of order 3. Observe that the
groups of orders 1, 2, and 3 are also Abelian and that there is just one group of
H^HI^ each order for a fixed labeling of the elements.
e a b We next come to a group G = [e, a, b, c] of order 4. It is not difficultto show
e e a b that the possible multiplication table for G can be completed as shown in Tables
a a be 9.5 through 9.8. It can be shown that each of these tables satisfies the associative
b b e a
property and the other properties of a group. Thus there are four possible multi
plication tables for a group of order 4. Again, observe that a group of order 4 is
Abelian. We shall return to groups of order 4 toward the end of this section, where

iMifili liliipfiiii; :mmmM^ ^^B*iiill


mmsmi 3E3BES

e a b c e a b c e a b c e a b c

e e a b c e e a b c e e a b c e e a b c

a a e c b a a e c b a a b c e a ace b

b b c e a b b c a e b b c e a b bee a

c c b a e c c b e a c c e a b c c b a e
366 Chapter 9 Semigroups and Groups
we shall see that there are only two and not four different nonisomorphic groups
of order 4.

Example 5 Let B = {0, 1}, andlet + be the operation defined on B as follows:


+ 0 1
0 0 1
1 1 0

Then B is a group. In this group, every element is its own inverse. ♦

We next turn to an important example of a group.

Example 6 Consider the equilateral triangle shown in Figure 9.3 with vertices 1, 2, and 3. A
symmetry of the triangle (or of any geometrical figure) is a one-to-one correspon
dence from the set of points forming the triangle (the geometrical figure) to itself
that preserves the distance between adjacent points. Since the triangle is deter
mined by its vertices, a symmetry of the triangle is merely a permutation of the
vertices that preserves the distance between adjacent points. Let l\, l2, and h be
the angle bisectors of the corresponding angles as shown in Figure 9.3, and let O
be their point of intersection.
We now describe the symmetries of this triangle. First, there is a counterclock
wise rotation f2 of the triangle about O through 120°. Then f2 can be written (see
Section 5.3) as the permutation

h
-0 3 0-
We next obtain a counterclockwise rotation /3 about O through 240°, which can
be written as the permutation
Figure 9.3
h
-G?0
Finally, there is a counterclockwise rotation f\ about O through 360°, which can
be written as the permutation

/i
-(in)
Of course, f\ can also be viewed as the result of rotating the triangle about O
through 0°.
We may also obtain three additional symmetries of the triangle, g\, g2, and
g3, by reflecting about the lines l\, l2, and /3, respectively. We may denote these
reflections as the following permutations:

(I 2 3\ /l 2 3\ (\ 2 3\
gx ={l 3 2)> g2=\3 2 lj' g3 ={2 1 ?>)'
Observe that the set of all symmetries of the triangle is described by the set of
permutations of the set {1, 2, 3}, which is considered in Section 5.3 and is denoted
by 53. Thus
S3 = [fu h* /3, gi, gi, g3>}-
We now introduce the operation *, followed by, on the set S3, and we obtain
the multiplication table shown in Table 9.9. Each of the entries in this table can
be obtained in one of two ways: algebraically or geometrically. For example,
9.4 Groups 367

TABLE 9.9

* A h h g\ g2 gi

7i /l h h g\ g2 gi

h h h fi gi g\ g2

h h /i h g2 gi gl

g\ g\ gi g% /l /2 fi
82 g2 gi g\ h /l /2
S3 gi gl gi /2 fi /l

suppose that we want to compute f2 * g2. Geometrically, we proceed as in Figure


9.4. Note that "followed by" here refers to the geometric order. To compute f2 *g2
algebraically, we compute f2 o g2,
(\ 2 3\ (I 2 3\ (I 2 3\
\2 3 lj°^3 2 1y= V1 3 2)=8x
and find that f2 * g2 = g\.

Given triangle Triangle resulting after Triangle resulting after applying


applying/2 g2 to the triangle at the left

Figure 9.4

Since composition of functions is always associative, we see that * is an as


sociative operation on S3. Observe that f\ is the identity in 53 and that every
element of 53 has a unique inverse in S3. For example, /2_1 = ^3- Hence S3 is a
group called the group of symmetriesof the triangle. Observe that S3 is thefirst
example that we have given of a group that is notAbelian. ♦

Example 7 Thesetof allpermutations ofn elements is a group of ordern! under theoperation


of composition. This group is called the symmetric group on n letters and is
denoted by Sn. We have seen that S3 also represents the group of symmetries of
the equilateral triangle. ♦

As in Example 6, we can also consider the group of symmetries of a square.


However, it turns out that this group is of order 8, so it does not agree with the
group 54, whose order is 4! = 24.

Example 8 In Section 9.3 we discussed the monoid Zn. We now show that Zn is a group
as follows. Let [a] € Zn. Then we may assume that 0 < a < n. Moreover,
[n —a] e Zn and since
[a] 0 [n - a] = [a + n - a] = [n] = [0],
we conclude that [n - a] is the inverse of [a]. Thus, if n is 6, then [2] is the inverse
of [4]. Observe that Z„ is an Abeliangroup. ♦
368 Chapter 9 Semigroups and Groups
We next turn to a discussion of important subsets of a group. Let H be a subset
of a group G such that
(a) The identity e of G belongs to H.
(b) If a and b belong to H, then ab e H.
(c) If a <e if, then a"1 gH.
Then H is called a subgroup of G. Parts (a) and (b) say that H is a submonoid
of G. Thus a subgroup of G can be viewed as a submonoid having properties (a)
and (c).
Observe that if G is a group and H is a subgroup of G, then H is also a group
with respect to the operation in G, since the associative property in G also holds
inH.

Example 9 Let G be a group. Then G and H = {e} are subgroups of G, called the trivial
subgroups of G. ♦

Example 10 Consider 53, the group of symmetries of the equilateral triangle, whose multipli
cation table is shown in Table 9.9. It is easy to verify that H = [f\, f2, /3} is a
subgroup of 53. ♦

Example 11 Let An be the set of all even permutations (see Section 5.4) in the group Sn. It
can be shown from the definition of even permutation that An is a subgroup of Sn,
called the alternating group on n letters. ♦

Example 12 Let G be a group and let a e G. Since a group is a monoid, we have already
defined, in Section 9.2, an for rc e Z+ as aa •••a (n factors), and a0 as e. If n is a
negative integer, we now define a~n as a~xa~x •••a~x (n factors). Then, if n and
m are any integers, we have
anam =an+m.

It is easy to show that


H = {a1 I i e

is a subgroup of G.

Let (G, *) and (G', *') be two groups. Since groups are also semigroups, we
can consider isomorphisms and homomorphisms from (G, *) to (Gf, *').
Since an isomorphism must be a one-to-one and onto function, it follows that
two groups whose orders are unequal cannot possibly be isomorphic.

Example 13 Let G be the group of real numbers under addition, and let G' be the group of
positivereal numbers undermultiplication. Let /: G -> G' be definedby f(x) =
ex. We now show that / is an isomorphism.
If f(a) = f(b), so thatea = eb, thena = b. Thus / is one to one. If c e G',
then Inc e G and
f(lnc) = eXnc = c,
so / is onto. Finally,

f(a + b) = ea+h = eaeb = f(a)f(b).


Hence / is an isomorphism. ♦
9.4 Groups 369

Example 14 Let G be the symmetric group ofn letters, and let G' be the group B defined in
Example 5. Let /: G -> G' be defined as follows: for p e G,

f 10 if pe An (the subgroup of all even permutations in G)


HP)~\l iipiAn.
Then / is a homomorphism. ♦

Example 15 Let G be the group of integers under addition, and let Gf be the group Z„ as
discussed in Example 8. Let /: G —• G' be defined as follows: If m g G, then
f(m) = [r], where r is the remainder when m is divided by n. We now show that
/ is a homomorphism of G onto G'.
Let [r] € Z„. Then we may assume that 0 < r < n, so
r = 0 - n -\- r,

which means that the remainder when r is divided by n is r. Hence


fir) = [r]
and thus / is onto.
Next, let a and b be elements of G expressed as
a = q\n + n, where 0 < r\ < n, and r\ and <?i are integers (1)
b = q2n + r2, where 0 < r2 < n, and r2 and #2 are integers (2)
so that
/(fl) = [r,] and /(*) = [r2].
Then
/(0) + /(« = [ri] + [r2] = [r,+r2].
To find [n + r2], we need the remainder when n + r2 is divided by /i. Write
n + r2 = #3ft + /*3, where 0 < r3 < n, and r3 and (73 are integers.
Thus
/(*) + fib) = [r3].
Adding, we have
a + Z? = qxn + ^2n + n + r2 = ((71 + q2 + ^3)^ + ^3,
so

/(a + fe) = [r1+r2] = [r3].


Hence
/(fl+ « = /(«) +/(ft),
which implies that / is a homomorphism.
Note that when n is 2, / assigns each even integer to [0] and each odd integer
to [1]. ♦

THEOREM 5 Let (G, *) and (Gf, *') be two groups, and let /: G -> G' be a homomorphism
from G to G'.
(a) If e is the identity in G and e?' is the identity in G', then f(e) = ef.
(b) IfaeG, then f(a~x) = (f(a))~x.
(c) If H is a subgroup of G, then
/(//) = {f(h) \heH]
is a subgroup of G'.
370 Chapter 9 Semigroups and Groups
Proof
(a) Let* = f(e). Then

x *' x = /(*) *' /(e) = /(e * e) = f(e) = x,


so x *' jc = x. Multiplying both sidesby jc-1 on the right, we obtain
x *' x *' x I = jc *' x x — e',

Thus f(e) = e'.


(b) a *a_1 = e, so
f(a * a x) = f(e) = e1 bypart (a)
or

/(fl) *' /(<* l) = e' since / is a homomorphism.


Similarly,
f(a~x)*ff(a) = e'.
Hence f(a~x) = (f(a))-x.
(c) This follows from Theorem 4 of Section 9.2 and parts (a) and (b). •

Example 16 The groups S3 and Z6 are both of order 6. However, S3 is not Abelian and Z6
is Abelian. Hence they are not isomorphic. Remember that an isomorphism pre
serves all properties definedin terms of the group operations. ♦

Example 17 Earlier in this section we found four possible multiplication tables (Tables 9.5
through 9.8) for a groupor order4. Wenow showthat the groups with multiplica
tion Tables 9.6, 9.7, and 9.8 are isomorphic as follows. Let G = {e, a, b, c) be the
group whose multiplication table is Table 9.6, and let G' = {ef, a!, b', cf} be the
group whose multiplication table is Table 9.7, where we put primes on every entry
in this last table. Let /: G -• G' be defined by f(e) = e', f(a) = bf, f(b) = a',
f(c) = d. We can then verify that under this renaming of elements the two ta
bles become identical, so the corresponding groups are isomorphic. Similarly, let
G" = {e", a", b", c"\ be the group whose multiplication table is Table 9.8, where
we put doubleprimeson everyentry in this last table. Let g: G -• G" be defined
by g(e) = e", g(a) = c", g(b) = b", g(c) = a". We can then verify that under
this renaming of elements the two tables become identical, so the corresponding
groups are isomorphic. That is, the groups given by Tables 9.6, 9.7, and 9.8 are
isomorphic.
Now, how can we be sure that Tables 9.5 and 9.6 do not yield isomorphic
groups? Observe that if x is any element in the group determined by Table 9.5,
then x2 = e. If the groups were isomorphic, then the group determined by Table
9.6 would have thesame property. Sinceit doesnot,we conclude thatthese groups
are not isomorphic. Thus thereare exactly two nonisomorphic groups of order4.
The group with multiplication Table 9.5 is called the Klein 4 group and it is
denoted by V. The one with multiplication Table 9.6, 9.7, or 9.8 is denotedby Z4,
since a relabelingof the elementsof Z4 results in this multiplication table. ♦
9.4 Groups 371

9.4 Exercises

In Exercises 1 through 11, determine whether the set together 19. Consider the square shown in Figure 9.5.
with the binary operation is a group. If it is a group, determine
if it is Abelian; specify the identity and the inverse ofa generic 4 3

element.
^\ v dy/
1. Z, where * is ordinary multiplication.
/ h
2. Z, where * is ordinary subtraction.
3. Q, the set of all rational numbers under the operation of
addition.
\'

4. Q, the set of all rational numbers under the operation of


multiplication. Figure 9.5
5. R, under the operation of multiplication.
The symmetries of the square are as follows:
6. R, where a*b = a + b + 2.
Rotations /,, f2, /3, and f4 through 0°, 90°, 180°,
7. Z+, under the operation of addition.
and 270°, respectively
8. The real numbers that are not equal to —1, where a * b =
f5 and f6, reflections about the lines v and h, respec
a + b + ab.
tively
9. The set of odd integers under the operation of multiplica
fj and f%, reflections about the diagonals d\ and d2,
tion.
respectively
10. The set of all m x n matrices under the operation of matrix
Write the multiplication table of D, the group of symme
addition.
tries of the square.
11. IfS is anonempty set, the set P(S), where A*£ = AQB.
20. Let G be a group. Prove that if g e G has the property
(See Section 1.2.)
gg = g, then g is the identity element of G.
12. Let S = {x | x is a real number and i / 0 , ^ -1}.
21. Let G be a finite group with identity e, and let a be an ar
Consider the following functions f •: S -> S, i = 1, 2,
bitraryelementof G. Provethat there existsa nonnegative
..., 6:
integer n such that a" = e.

fi(x)=x, f2(x) =l-x, Mx) =^ 22. Let G be the nonzero integers under the operation of
multiplication, and let H = {3" | n e Z). Is H a subgroup
ofG?
A(x) =7^—,
1 — JC
AW =1- -,
x
fe(x) =-^-r.
x — I 23. Let G be the group of integers under the operation of ad
dition, and let H = {3k \ k e Z). Is H a subgroup of
Show that G = {f, f2, /3, /4, /5, fe) is a group under G?
the operation of composition. Give the multiplication ta
24. Let G be an Abelian group with identity e, and let H —
ble of G.
{x | x2 = e\. Show that H is a subgroup of G.
13. Consider S3, the group of symmetries of the equilateral
25. Let G be a group, and let H = {x \ x e G and xy = yx
triangle, and the group in Exercise 12. Prove or disprove
for all y € G). Prove that H is a subgroup of G.
that these two groups are isomorphic.
26. Let G be a group and let a e G. Define Ha = {x \ x e G
14. Show that the mapping in Example 14 is a homomor
and xa = ax}. Prove that Ha is a subgroup of G.
phism.
27. Let An be the set of all even permutations in Sn. Show
15. Let G be the group defined in Example 4. Solve the fol
that An is a subgroup of S„.
lowing equations:
(a) 3 * x = 4 (b) y * 5 = -2 28. Let H and £ be subgroups of a group G.
16. Let i = <sT-i. Prove that S = {1,-1,/,-/} with (a) Prove that // D K is a subgroup of G.
complex number multiplication is a group. Is this group (b) Show that H U K need not be a subgroup of G.
Abelian? 29. Find all subgroups of the group given in Exercise 19.
17. Find all subgroups of the group in Exercise 16. 30. Let G be an Abelian group and n sl fixed integer. Prove
18. Let G be a group with identity e. Show thatif a2 = e for that the function f:G-+G defined by f(a) = an, for
all a in G, then G is Abelian. a € G, is a homomorphism.
372 Chapter 9 Semigroups and Groups

31. Prove that the function f(x) = |jc| is a homomorphism 35. Let G be a group and let a be a fixed element of G. Show
from the group G of nonzero real numbers under multi that the function fa: G -> G defined by fa(x) = axa~x,
plication to the group G' of positive real numbers under for jc e G, is an isomorphism.
multiplication. 36. Let G = {e, a, a2, a3, a4, a5} be a group under the opera
32. Let G be a group with identity e. Show that the func tion of alaj = ar, where i + j = r (mod 6). Prove that
tion f:G->G defined by f(a) = e for all a e G is a G and Z^ are isomorphic.
homomorphism. 37. Let G be a group. Show by mathematical induction that
33. Let G be a group. Show that the function f:G->G if ab = ba, then (ab)n = anbn for n e Z+.
defined by f(a) a2 is a homomorphism if and only if 38. Prove that in the multiplication table of a group every
G is Abelian. element appears exactly once in each row and column.
34. Let G be a group. Show that the function f:G->G 39 Prove that the condition in Exercise 38 is necessary, but
defined by f(a) = a~l is an isomorphism if and only if not sufficient, for a multiplication table to be that of a
G is Abelian. group.

9.5 Products and Quotients of Groups


In this section, we shall obtain new groups from other groups by using the ideas
of product and quotient. Since a group has more structure than a semigroup, our
results will be deeper than analogous results for semigroups as discussed in Section
9.3.

THEOREM 1 If Gj and G2 are groups, then G = G\ x G2 is a group with binary operation


defined by
(aubi)(a2, b2) = (a{a2, bxb2). (1)

Proof
By Theorem 1, Section 9.3, we have that G is a semigroup. The existence of an
identity and inverses is easy to verify. •

Example 1 Let Gi and G2_be thegroup Z2. For simplicity of notation, we shall write the ele
ments of Z2 as 0 and 1,respectively, instead of [0] and [1]. Thenthe multiplication
table of G = Gi x G2 is given in Table 9.10.

(0,0) (1,0) (5.1) (i.D


(0,0) (0,0) (1,0) (0,T) (T.T)
(1,0) (1,0) (0,0) (T.T) (0.1)
(o,T) (0,T) (T,T) (0,0) (1,0)
(T,T) (T,T) (0,1) (1,0) (0,0)

Since G is a group of order 4, it must be isomorphic to V or to Z4 (see Section


9.4), the only groups of order 4. By looking at the multiplication tables, we see
that the function /: V -> Z2_x Z2 defined by f(e) = (0, 0), f(a) = (1, 0),
/(b) = (0, 1), and f(c) = (1, 1) is an isomorphism. ♦

If we repeat Example 1 with Z2 and Z3, we find that Z2xZ3~Z6. It can be


shown, in general, that Zm x Zn ~ Zmn if and only if GCD(ra, n) = 1, that is, if
and only if m and n are relatively prime.
Theorem 1 can obviously be extended to show that if G\,G2,... ,Gn are
groups, then G = Gi x G2 x ••• x Gn is also a group.
9.5 Products and Quotients ofGroups 373
Example 2 Let B —{0, 1} be the group defined in Example 5 of Section 9.4, where + is
defined as follows:
+ 0 1
0 0 1
1 1 0

Then Bn = BxBx-xB(n factors) is a group with operation © defined by

(x{,x2,...,xn) ® (yu y2,..., yn) = (xx + y\,x2 +y2,... ,xn + yn).

The identity of Bn is (0, 0,..., 0), and every element is its own inverse. This
group is essentially the same as the Boolean algebra Bn defined in Section 6.4, but
the binary operation is very different from A and v. ♦

A congruence relation on a group is simply a congruence relation on the group


when it is viewed as a semigroup. We now discuss quotient structures determined
by a congruence relation on a group.

THEOREM 2 Let R be a congruence relation on the group (G, *). Thenthe semigroup (G/R, ®)
is a group, where the operation ® is defined on G/R by

[a] ® [b] = [a * b] (see Section 9.3). (2)

Proof
Since a group is a monoid, we know from Corollary 1 of Section 9.3 that G/R
is a monoid. We need to show that each element of G/R has an inverse. Let
[a] € G/R. Then [a~x] e G/R, and

[a]®[a~x] = [a*a~x] = [e].

So [a]~l = [a~x]. Hence (G/R, ®) is a group. •

Since the definitions of homomorphism, isomorphism, and congruence for


groups involve only the semigroup and monoid structure of groups, the following
corollary is an immediate consequence of Theorems 3 and 4 of Section 9.3.

Corollary 1 (a) If R is a congruence relation on a group G, then the function fR: G -» G/R,
givenby fR(a) = [a], is a group homomorphism.
(b) If /: G -• G' is a homomorphism from the group (G, *) onto the group
(G', *'), and R is the relation defined on G by a R b if and only if f(a) =
f(b), for a and b in G, then
1. R is a congruence relation.
2. The function/: G/R -» G', given byJ ([a]) = f(a), is anisomorphism
from the group (G/R, ®) onto thegroup (G', *')• •
Congruence relations on groups have a very special form, which we will now
develop. Let H be a subgroup of a group G, and let a e G. The left coset of H
in G determined by a is the set a if = {ah \ h e H}. The right coset of H in
G determined by a is the set i/a = {ha \ h e H}. Finally, we will say that a
subgroup HofGis normal if aH = Ha for all a in G.
Warning If Ha = aH, it does not follow that, for h e H and a eG,ha= ah.
It does follow that ha = aft', where ft' is some element in H.
374 Chapter 9 Semigroups and Groups

If H is a subgroup of G, we shall need in some applications to compute all


the left cosets of H in G. First, suppose that a e H. Then aH c H, since H is a
subgroup of G; moreover, ifheH, thenh = aft', where h! = a~xh e H, so that
H c. aH. Thus, if a £ H, then aH = H. This means that, when finding all the
cosets of i/, we need not compute aH for a e H, since it will always be H.

Example 3 Let G be the symmetric group 53 discussed in Example 6 of Section 9.4. The
subset H = {/1, g2} is a subgroup of G. Compute all the distinct left cosets of H
inG.

Solution
IfaeH, then <z# = H. Thus

Also,

hH = {f3,g3)
g\H = [gu h) = f2H
gzH = {g3, f3} = f3H.
The distinct left cosets of H in G are #, /2tf, and f3H. ♦

Example 4 Let Gand # be as in Example 3. Then the right coset Hf2 = {/2, g3}. In Example
3 we saw that f2H = {/2,gx). It follows that # is not a normal subgroup of G.

Example 5 Show that if G is an Abelian group, then every subgroup of G is a normal sub
group.

Solution
Let H be a subgroup of G andlet a € G and/* e H. Then/ia = ah, so Ha = aH,
which implies that // is a normal subgroup of G. ♦

THEOREM 3 Let Rbe a congruence relation on a group G, and let H = [e], the equivalence
class containing the identity. Then AT is a normal subgroup of G and, for each
a e G, [a] = aH = //a.

Proof
Let a and fc be any elements in G. Since R is an equivalence relation, b e [a] if
and only if [b] = [a]. Also, G/i? is a group by Theorem 2. Therefore, [b] = [a]
if and only if [e] = [a]~x[b] = [a~xb]. Thus &e [a] if and only if H = [e] =
[a~xb]. That is, b e [a] if and only if a~xb e H or b e aH. This proves that
[a] = aH for every a e G. We can show similarly that b e [a] if and only if
H = [e] = [b][a]~x = [ba~1]. This is equivalent to the statement [a] = #0.
Thus [a] = aH = //a, and # is normal. •

Combining Theorem 3 with Corollary 1, we see that in this case the quotient
group G/R consists of all the left cosets of N = [e]. The operation in G/R is
given by
(aN)(bN) = [a] ® [b] = [ab] = abN
and the function fR: G -» G/R, defined by fR(a) = aN, is a homomorphism
from G onto G/R. For thisreason, we willoften write G/R as G/N.
9.5 Products and Quotients of Groups 375
We next consider the question of whether every normal subgroup of a group
G is the equivalence class of the identity of G for some congruence relation.

THEOREM 4 Let N be a normal subgroup of a group G, and let R be the following relation on
G:
a R b if and only if a~xbeN.
Then

(a) R is a congruence relation on G.


(b) N is the equivalence class [e] relative to R, where e is the identity of G.

Proof
(a) Let a e G. Then a R a, since a~xa = e e N, so R is reflexive. Next,
suppose that a R b, so that a~xb G N. Then (a~lb)~x = b~xa e N,
sob R a. Hence R is symmetric. Finally, suppose that a R b and b R c.
Then a~xb e N and b~lc e N. Then (a~xb)(b~xc) = a~xc e N, so
a R c. Hence R is transitive. Thus R is an equivalence relation on G.
Next we show that R is a congruence relation on G. Suppose that
a R b and c R d. Then a~xb G N and c~xd G N. Since N is normal,
Nd = dN\ that is, for any n\ G N, flid = drc2 for some n2 e Af. In
particular, since a~xb G N, we have a-1fo/ = dn2 for some rc2 G N.
Then (ac)~xbd = (c-[a~x)(bd) = c~x(a~xb)d = (c~xd)n2 e N, so
ac R bd. Hence R is a congruence relation on G.
(b) Suppose that x G N. Then x~xe = x~x € N since AT is a subgroup, so
x R e and therefore x £ |>]. Thus AT c [e]. Conversely, if x e [e], then
x R e, so jc"1^ = x~l G N. Then x G N and |>] c N. Hence N = [e].

We see, thanks to Theorems 3 and 4, that if G is any group, then the equiva
lence classes with respect to a congruence relation on G are always the cosets of
some normal subgroup of G. Conversely, the cosets of any normal subgroup of
G arejust theequivalence classes with respect to some congruence relation on G.
We maynow, therefore, translate Corollary 1(b) as follows: Let / be a homomor
phism from a group (G, *) onto a group (G', *'), and let the kernel of /, ker(/),
be defined by
ker(/) = {fl€G|/(fl) = e,l.
Then

(a) ker(/) is a normal subgroup of G.


(b) The quotient group G/ ker(/) is isomorphic to G'.
Thisfollows from Corollary 1andTheorem 3, sinceif R is the congruence relation
on G given by
a Rb if and only if f(a) = f(b),
then it is easy to show that ker(/) = [e].

Example 6 Consider the homomorphism / from Z onto Z„ defined by


f(m) = [r],

where r is the remainder when m is divided by n. (See Example 15 of Section


9.4.) Find ker(/).
376 Chapter 9 Semigroups and Groups
Solution
An integer m in Z belongs to ker(/) if and only if f(m) = [0], that is, if and only
if m is a multiple of n. Hence ker(/) = nZ. ♦

9.5 Exercises

1. Write the multiplication table for the group Z2 x Z3. 21. Let Z be the group of integers under the operation of
addition, and let G = Z x Z. Consider the subgroup
2. Prove that if G and G are Abelian groups, then G x G' is
H = {(x, y) \ x = y} of G. Describe the left cosets of H
an Abelian group.
inG.
3. Let G i and G2 be groups. Prove that G\xG2 and G2xG\ 22. Let N be a subgroup of a group G, and let a e G. Define
are isomorphic.
4. Let Gi and G2 be groups. Show that the function a~xNa = {a~lna \n e N}.
f:G\xG2^>G\ defined by f(a, b) = a, for a G G\
Prove that Af is a normal subgroup of G if and only if
and & g G2, is a homomorphism.
a~lNa = AT for all a eG.
5. Determine the multiplication table of the quotient group 23. Let A" be a subgroup of group G. Prove that N is a normal
Z/3Z, where Z has operation +.
subgroupof G if and only if a~lNa c Af for all a G G.
6. Let Z be the group of integers under the operation of ad 24. Find all the normal subgroups of S3.
dition. Prove that the function /: Z x Z -> Z defined by
25. Find all the normal subgroups of D. (See Exercise 19 of
f(a, b) = a + b is a homomorphism.
Section 9.4.)
7. What is ker(/) for the function / in Exercise 4? 26. Let G be a group, and let H = {x \ x e G and xa = ax
8. What is ker(/) for the function / in Exercise 6? for all a g G}. Show that H is a normal subgroup of G.
9. Let G = Z4. Determine all the left cosets of H = {[0]} 27. Let // be a subgroup of a group G. Prove that every left
inG. coset aH of H has the same number of elements as H
by showing that the function fa: H -> aH defined by
10. Let G = Z4. Determine all the left cosets of fa(h) = ah, for h g H, is one to one and onto.
H = {[0], [2]} in G.
28. Let H and K be normal subgroups of G. Show that HDK
11. Let G = Z4. Determine all the left cosets of is a normal subgroup of G.
# = {[0],[l],[2],[3]}inG.
29. Let G be a group and H a subgroup of G. Let 5 be the
12. Let S = {1, -1, i, -i], i = J=\, and G = (S,complex set of all left cosets of H in G, and let T be the set of all
number multiplication). right cosets of H in G. Prove that the function f:S^T
(a) Show that H = {1, -1} is a subgroup of G. defined by f(aH) = Ha~x is one to one and onto.
(b) Determine all left cosets of H.
30. Let Gi and G2 be groups. Let /: Gi x G2 -• G2
be the homomorphism from G\ x G2 onto G2 given by
13. Prove or disprove that G in Exercise 12 is isomorphic to /((gi, £2)) = gi- Compute ker(/).
Z4.
31. Let / be a homomorphism from a group Gi onto a group
14. Let G = S3. Determine all the left cosetsof H = {/,, gx} G2, and suppose that G2 is Abelian. Show that ker(/)
inG. contains all elements of Gi of the form aba~lb~l, where
15. Let G = 53. Determine all the left cosetsof H = {f, g3] a and b are arbitrary in G1.
inG. 32. Let G be an Abelian group and N a subgroup of G. Prove
that G/N is an Abelian group.
16. Let G = S3. Determine all the left cosets of
H = {fuf2,f3)inG. 33. Let H be a subgroup of the finite group G and suppose
that there are only two left cosets of H in G. Prove that
17. Let G = S3. Determine all the left cosets of // = {/,} H is a normal subgroup of G.
inG.
34. Let // and N be subgroups of the group G. Prove that if
18. Let G = S3. Determine all the left cosets of N is a normal subgroup of G, then H H N is a normal
H = {/1, /2, /3, g\,g2, g3) in G. subgroup of //.
19. Let G = Z8. Determine all the left cosets of 35. Let /: G -• G' be a group homomorphism. Prove that
H = {[0], [4]} in G. / is one to one if and only if ker(/) = {e}.
20. Let G = Z8. Determine all the left cosets of 36. Let S = {1, 3, 7, 9} and G = (5, multiplication mod 10).
H = {[0], [2], [4], [6]} in G. (a) Show that G is a group.
9.6 Other Mathematical Structures 377

(b) Determine all left cosets of the subgroup {1,9}. 38. Use the results of Exercises 27 and 37 to describe the re
37. Let G be a finite group and H a subgroup of G. Prove lationship between the order of H and the order of G.
that the set of distinct left cosets of H is a partition of G.

9.6 Other Mathematical Structures

Rings
In earlier sections, we have seen many cases where a set 5 has two binary oper
ations defined on it. Here we study such structures in more detail. In particular,
let 5 be a nonempty set with two binary operations + and * such that (S, +) is an
Abelian group and * is distributive over +. (The operation symbols are the same
as those for the most well-known such structure, the real numbers.) The structure
(5, +, *) is called a ring if * is associative. If * is associative and commutative,
we call (5, +, *) a commutative ring. If (S, *) is a monoid, then (5, +, *) is a
ring with identity. The identity for * is usually denoted by 1; the identity for + is
usually denoted by 0.

Example 1 Let S = Z, the integers, and let + and * be the usual addition and multiplication
of integers. Then (S, +, *) is a commutative ring with identity. ♦

Example 2 Let S be thesetof all2 x 2 matrices, andlet + and* be theoperations of addition


and multiplication of matrices defined in Section 1.5. Then it follows from theo
rems proved in Section 1.5 that 5 is a noncommutative ring. Let / = q ^
then / is an identity for matrix multiplication, that is, AI = IA = A for all A in
5. This means that (S, +, *) is a ring with identity that is not commutative. ♦

Recall that if a, b, and n are integers, with n > 1, then we say that a is
congruent to b mod n, written a = b (mod n), if a - b is a multiple of n, or,
alternatively, if a and b have the same remainder when divided by n. We showed
in Section 9.4 that congruence mod n is an equivalence relation on the integers
and that the set Z„ consisting of all equivalence classes is an Abelian group with
respect to addition mod n. If we denote the equivalence class of an integer a by
the expression a, then Zn = {6, 1, 2,..., n - 1}, and a + b = a + b.
We now definea multiplication in Zn. Suppose that a, b, x, and y are integers
and that a = x (mod n) and b = y (mod n). These assumptions imply that
for some integers s and t, we have a = x + sn and b = y + tn. Then ab =
xy + xtn + ysn + stn2, which means that ab - xy = n(xt + ys + stn), so
ab = Xy (mod n). Thus we can define a*btobtab and the definition does not
dependon the integers pickedto represent each equivalence class.

Example 3 The set Z„ with addition mod n and the multiplication defined previously is a
commutative ring with identity. The computations

(a * b) * c = ab * c = (ab)c = a(bc) = a *bc = a * (b * c)

and

a * (b + c) = a * (b + c)
= a(b + c) =ab + ac = ab + ac = (a*b) + (a*c)
378 Chapter 9 Semigroups and Groups
show that multiplication is associative and distributive over addition. In a similar
way we can prove that multiplication is associative and that 1 is the identity for
multiplication. ♦

Generally, we will refer to + and * as addition and multiplication even when


they are not the usual operations with these names.
Many properties of the ring of integers are true for any commutative ring with
identity. Two examples are given in the next theorem.

THEOREM 1 Let R be a commutativering with additive identity 0 and multiplicative identity 1.


Then

(a) For any x in R, 0 * x = 0.


(b) For any x in R, —x = (—1) * x.

Proof
(a) Let y denote the element 0 * x. Since R is a ring, we have
j + 3; = 0*x + 0*a: = (0-|-0)*x = 0*jc = j.
But (R, +) is an Abelian group, so
0 = (-y) + y = (-y) + (y + y) = [(-y) + y] + y = 0 + y = y,
which shows part (a).
(b) Sincejc + ((-1)*jc) = (1*jc) + ((-1)*jc) = (l + (—1))*jc = 0*jc = 0,
part (b) follows. •

In the proof of Theorem 1(b), we use the fact that an inverse in an Abelian
group is unique, so that if an element behaves as an inverse, then it must be an
inverse.
A nonzero element x of a commutative ring R with identity 1 is said to have
a multiplicative inverse yifx*y = y*x = l. If such a y exists, it is unique
(Theorem 1 in Section 1.6). We therefore speak of the multiplicative inverse of x
anddenote it by x"1, or sometimes by l/x.
The only integers with inverses in Z are 1 and -1, but the situation in the
rings Zn is different. We can show that if a is relatively prime to n, that is, if
GCD(a, n) = 1, then a has a multiplicative inverse in Z„. In fact, it follows from
Theorem 4(a) of Section 1.4 that there are integers fc_and s satisfying the equation
ak + ns = 1, or 1 - ak = ns. This means that 1 = ak = a * k, and we see that a
has the multiplicative inverse k.

Example 4 The integer 25 is relatively prime to 384, so 25 has amultiplicative inverse inZ384.
To find it, we use the Euclidean algorithm developed in Section 1.4.
384= 15x25 + 9
25 = 2 x 9 + 7
9=1x7+2
7 = 3 x2+l

By successive substitutions, we get


1 = 7 - 3 • 2 = 7 - 3(9 - 7) = (4 • 7) - (3 • 9)
= 4(25 - 2 • 9) - (3 • 9) = (4 • 25) - (11 • 9)
= (4 • 25) - 11(384 - 15 • 25) = (169 • 25) - 11 . (384).
9.6 Other Mathematical Structures 379

This shows that 169 •25 = 1 (mod 384), so the multiplicative inverse of 25 in Z384
is 169. ♦

Fields
Suppose that F is a commutative ring with identity. We say that F is a field if
every nonzero element x in F has a multiplicative inverse. In the following table,
we summarize the properties of a field F.

F has two binary operations: an addition + and a multiplication *,


and two special elements denoted 0 and 1, so that for all x, y, and z in F,

(1) x + y = y + x (2) x*y = y*x


(3) (jc + y) + z = x + (y + z) (4) (x * y) * z = x * (y * z)
(5) jc + 0 = x (6) * * 1 = jc
(7) jc*(y + z) = (jc*y) + Cx*z) (8) (y + z) *x = (y *x) + (z*x)
(9) For each xinF there is a unique element in F denoted by —x so that
x + (-jc) = 0.
(10) For each x ^ 0 in F there is a unique element in F denoted by*_1 so
thatx*jc_1 = 1.

Example 5 The collection R of all real numbers, with ordinary addition and multiplication, is
a field. Here x~x = \/x. The field properties shownin the preceding table are the
standard rules of arithmetic. ♦

Example 6 Thecollection Q ofallrational numbers, with ordinary addition andmultiplication,


is a field. *

The preceding examples are typical of fields. Fields obey virtually all the
familiar rulesof arithmetic andalgebra, and most algebraic techniques canbe used
in any field. Remarkably, there are fields with only a finite number of elements.
The following theorem introduces the finite fields most important to our future
discussions.

THEOREM 2 The ring Zn is a field when n is a prime.

Proof
Recall that n is a prime if it has no divisors other than itself and 1. If a is any
nonzero element of Z„, then a is not divisible by n, so GCD(a, n) = 1. It follows
fromthe discussion preceding Example 4 that a has a multiplicative inverse, so Zn
is a field. *

Example 7 By Theorem 2,_Z5 = {0,1,2, 3,4}_is afield. Since 2+3 = 5, we have 2+3 = 0, so
-2 = 3 and -3 = 2. Similarly, -4 = 1 and -1 = 4. For notational convenience,
we denote the multiplicative inverse of a nonzero element a in this field by 3, and
the product of elements a and b by a •b. Then, since2 •3 = 6 = 1 •5 + 1, we see
that 2 3 = 1. Thus = = 3 and •= = 2. Similarly, since 4 •4 = 16 = 3 • 5 + 1, we
2 3
380 Chapter 9 Semigroups and Groups

have - = 4 and, as in the real number field, 1 is also its own multiplicative inverse.
4
We can use these facts in the same way we would for real numbers. For example,
suppose we want to solve the following system of equations simultaneously:

J3x +2y =4
[2x +4y =2.
We could begin by multiplying the first equation by - = 2, to obtain x + 4y = 3
(since 2 • 4 = 3), or x = 3 - Ay = 3 + (-4)y = 3 + y, using Theorem 1(b). We
then substitute for x in the second equation and obtain

2-(3 + y)+4y = I + y = 2,
where we have used the facts that 2-3 = 1 and 2 + 4 = 1. We see that y = 1, so
;c = 4. ♦

The reader is invited to check this result by substituting into the system of
equations.

Fermat's Little Theorem


An important property of any field F is that the set F' of nonzero elements of F
is an Abelian group under multiplication. We need to show that F' is closed under
multiplication, that is, that the product of nonzero elements of F is nonzero. Then
the result will follow from properties (2), (4), (6), and (10) of fields. Supposethat
a * b = 0 in F. If a is not 0, then we can multiply both sides of the equation
a * b = 0 by a~x and obtain
b = a~x *0 = 0

by Theorem 1(a). Thus either a or b must be 0. It follows that the product of


nonzero elements in F is nonzero, and thus F' is closedunder multiplication and
is therefore an Abelian group.
The following result has many mathematical uses and parts (b) and (c) will be
used for our treatmentof public key cryptology in Chapter 11.

THEOREM 3 (a) If G = {g\, g2,..., gn] is a finite Abelian group with identity denoted by e,
and a is any element of G, then an = e.
(b) Fermat's Little Theorem: If p is a prime number, andGCD(a, p) = 1,then
ap~x = 1 (mod p).
(c) If p is a prime number, and a is any integer, then ap = a (mod p).

Proof
(a) Corollary 1 in Section 9.4 shows that multiplication by an element in a
group is a one-to-one function. Therefore, the products ag\, ag2, ...,agn
are all distinct, and are simply the elements gugi,...,gn possibly ar
ranged in a differentorder. It follows from this and the commutativity of
multiplication in G that

g\gi '"gn = (agi)(qg2) • • • (agn) = gxg2 • • •gn(an).


Part (a) results from multiplying each side of this equation on the left by
(glg2'-gn)~X-
9.6 Other Mathematical Structures 381

(b) If p is a prime, then Zp is a field by Theorem 2, so the nonzero elements


form an Abelian group under multiplication. The identity of this group is
1. Since this group has p —\ elements, part (a) implies that if a ^ 0, then
[a]p~] = 1. This is equivalent to part(b).
(c) If a is not divisible by p, then we can apply Fermat's Little Theorem, and
the result follows by multiplying both sides of the congruence by a. If a
is divisible by p, then ap = 0 (mod p) and a = 0 (mod p), so ap and a
are congruent to one another. •

Example 8 ByFermat's Little Theorem, 1230 = 1 (mod 31) and 7483 = 74 (mod 83). ♦

Example 9 What is the remainder when 4900 is divided by 53?


Solution
We know by Fermat's Little Theorem that 452 = 1 (mod 53). Since
900 = (17x52)+ 16,

we have
4900 = 4(17x52)+16 = (452^7416 _ 4I6 (m0(j 53^
Now
43 = 64= 11 (mod 53)
46 = ll2 = 15 (mod 53)
412 = 152 = 13 (mod 53)
4i6 = 412 . 128 = 13 . 22 = 21 (mod 53).

Thus the remainder afterdividing 4900 by 53 is 21.

9.6 Exercises
In Exercises 1 through 6, determine if the mathematical struc An element of a ring R is called a unit of R if r has a multi
ture given is a ring, a commutative ring, or a ring withidentity. plicative inverse, r~l, in R. InExercises 9 through 12, give all
units of the given ring.
1. (2x2 matrices, +, *)
10. Z7 11. 12.
2. (n x n diagonal matrices, +, *)
3. n x n Boolean matrices, where + is v and * is A. T is a subring of a ring R if (T, +) is a subgroup of (R, +)
and (T, *) is a subsemigroup of(R,*).
5 = {0, 1} where + and * are defined by the following
tables:
13. Show that the set of 2 x 2 matrices of the form
0 a]
+ 0 1 * 0 1 0 b\
0 0 1 0 0 0 is a subring of the ring in Exercise 1.
1 1 0 1 0 1
14. Show that the integers form a subring of the ring given in
5. S = {a + by/2, a,b € Z}, where + and * are ordinary Exercise 5.
addition and multiplication.
15. For each of the structures in Exercises 1 through 6, deter
6. S = {a + b\f5, a,b e Z), where + and * are ordinary mine if the structure is a field. Explain your decisions.
addition and multiplication.
16. In the field Z7, find each of the following,
A ring R has zero divisors if there exist elements a and b in R (a) -3 (b) -2 (c) -6
such that a ^ 0, b 7^ 0, and a * b = 0.
I

7. Show that (2x2 matrices, +, *) is a ring with zero divi


«i) 1 of
sors.
17. Find the multiplicative inverse of 55 in Zi96.
8. Show that Z10 is a ring with zero divisors. 18. Find the multiplicative inverse of 29 in Zi%.
382 Chapter 9 Semigroups and Groups

19. Solve the following system of equations in Z5. 24. What is the remainderwhen 5219 is dividedby 17?
25. The field Z2 can be identified with the finite Boolean alge
j4x - 3y =I bra B defined in Section 6.5, where + and * are given by
[2jc+ y = 3 the tables in Exercise 4. If these tables are viewed as truth
tables, then each has a Boolean function that represents it.
20. Solve the following system of equations in Z7.
(a) Find the Boolean function / such that f(x, y) =
4jc - 3y = I x + y.

2x + 4y = 2 (b) Find the Boolean function g such that g(x, y) =


x * y.
21. Find all solutions of each equation in Z7. 26. Prove that a field cannot have any zero divisors.
(a) x2 + 2x + 3 = 4 (b) x2 + Ax + I = 3 27. What condition on the set of units of a ring R will guar
22. Find all solutions of each equation in Z5. antee that R is a field?

(a) x2 + 2x + 3 = 4 (b) *2 + 4x + I = 3 28. Prove that if n is not a prime, then Z„ is not a field.
23. Whatis the remainder when3850 is divided by 17? 29. Prove that Z„ is a field if and only if n is a prime.

Tips for Proofs


The proofs in this chapter are mostly simple direct proofs, in part because we have
introduced several new mathematical structures (semigroup, monoids, groups,
Abelian groups,rings, and fields). With a new structure we first explore the simple
consequences of the definitions; for example, Theorem 1, Section 9.2. However,
proofs of uniqueness are frequently indirect as in Theorems 1 and 4 in Section 9.4.
The idea of a substructure appears several times in this chapter. In general,
to prove that a subset forms a substructure of a mathematical structure, we show
that the subset together with the operation(s) satisfy the definition of this type of
structure. But any global property such as associativity is inherited by the subset so
we need only check closure properties and properties involving special elements.
Thus, to show that a subsetis a subgroup, we check closure for the multiplication,
that the identity belongs to the subset, and that the inverse of each element in the
subset belongs to the subset.
Isomorphismis a powerful tool for proving statements, since, roughly speak
ing, establishing an isomorphism between two structures allows us to transfer
knowledge about one structure to the other. This can be seen in Theorem 4, Section
9.2.

I Key Ideas for Review


Binary operation on A: everywhere defined function Theorem: Let (S, *) and (T, *') be monoids with identities
f:AxA^A e and e', respectively, and suppose that f:S-> T is an
Commutative binary operation: a*b = b*a isomorphism. Then f(e) = e'.
Associative binary operation: a * (b * c) = (a * b) * c Theorem: If (S, *) and (7\ *') are semigroups, then
(S x T, *") is a semigroup, where *" is defined by
Semigroup: nonempty set S together with an associative bi
nary operation * defined on S (suti) *" (s2, t2) = (si * s2, tx *' t2).
Monoid: semigroup that has an identity Congruence relation R on semigroup (S, *): equiva
Subsemigroup (T, *) of semigroup (S, *): T is a nonempty lence relation R such that a R a! and b R b' imply that
subset of S and a*b eT whenever a and b are in T.
(a*b) R (a' * b')
Theorem: Let R be a congruence relation on the semigroup
Submonoid (T, *) of monoid (S, *): T is a nonempty sub
(S, *). Define the operation ® in S/R as follows:
set of S, e € T, and a *b e T whenever a and b are
in 7. [a]® [b] = [a*b].
Isomorphism: see page 351 Then (S/R, ®) is a semigroup.
Homomorphism: see page 353 Quotient semigroup or factor semigroup S/R: see page 358
Chapter 9 Self-Test 383

• Z„: see page 358 • Theorem: Let R be a congruence relation on a group G, and
• Theorem (Fundamental Homomorphism Theorem): Let let // = [e], the equivalence class containing the identity.
/: S —• T be a homomorphism of the semigroup (5, *) Then H is a normal subgroup of G and, for each a e G,
onto the semigroup (7\ *')• Let R be the relation on S de [a] = aH = Ha.
fined by a R b if and only if f(a) = f(b), for a and b in S. • Theorem: Let N be a normal subgroup of a group G, and
Then let R be the following relation on G:
(a) R is a congruence relation.
(b) T is isomorphic to S/R. a /? & if and only if a~lb e N.
• Group (G, *): monoid with identity e such that for ev
Then
ery a e G there exists a' e G with the property that (a) R is a congruence relation on G.
a * a' — a' * a = £.
(b) N is the equivalence class [e] relative to /?, where e is
• Theorem: Let G be a group, and let a, b, and c be elements the identity of G.
of G. Then
• Ring (5, -h *): nonempty set 5 such that (5, +) is an
(a) ab = ac implies that b = c (left cancellation property).
Abelian group, * is associative, and * distributes over +.
(b) ba = ca implies that b — c (right cancellation prop
• Commutative ring: ring in which the operation * is commu
erty).
tative.
• Theorem: Let G be a group, and let a and b be elements of
• Theorem: Let R be a commutative ring with additive iden
G.Then
tity 0 and multiplicative identity 1. Then
(a) (a-1)-1 =a.
(a) For any x in R, 0 * x = 0.
(b) (ab)~x =b~la~l.
(b) For any x in R, —x = (—1) * x.
• Order of a group G: |G |, the number of elements in G
• Field: commutative ring with identity in which every
• Sn: the symmetric group on n letters
nonzero element has a multiplicative inverse
• Subgroup: see page 368
• Theorem: The ring Zn is a field when n is a prime.
• Theorem: Let R be a congruence relation on the group
• Theorem:
(G, *). Then the semigroup (G/R, <§) is a group, where
(a) If G = {gi, g2, •.., gn] is a finite Abelian group with
the operation ® is defined in G/R by
identity denoted by e, and a is any element of G, then
[a]® [b] = [a*b]. an = e.
(b) (Fermat's Little Theorem) If p is a prime number, and
• Left coset aH of H in G determined by a: {ah \ h e H] GCD(a, p) = 1, then ap~l = 1 (mod p).
• Normal subgroup: subgroup H such that aH = Ha for all (c) If p is a prime number and a is any integer, then
a in G ap = a (mod p).

I Chapter 9 Self-Test
1. What does it mean to say a set is closed with respect to a 7. Complete the table so that * is a commutative and idem-
binary operation? potent binary operation.
2. How does an isomorphism of semigroups differ from an * a b c

isomorphism of posets? How are an isomorphism of a c

groups and an isomorphism of posets alike? b


c b
3. What are the properties that define a congruence relation?
8. Let Q be the set of rational numbers and define a * b =
4. Why are groups said to have more structure than semi a-\-b — ab.
groups?
(a) Is (Q, *) a monoid? Justify your answer.
5. How does a field differ from a ring? (b) If (Q, *) is a monoid, which elements of Q have an
6. For each of the following, determine whether the descrip inverse?

tion of * is a valid definition of a binary operation on the 9. Determine whether the set together with the operation is
given set. a semigroup, a monoid, or neither for each of the pairs
(a) On the set of 2 x 2 Boolean matrices, where A * B = given in Exercise 1.
[(atj+bij) (mod 2)] 10. Let A = {0, 1}, and consider the semigroup (A*, •)»
where • is the operation of catenation. Define a relation R
(b) On the set of even integers, where a * b = a + b
on this semigroup by a R ft if and only if a and {$ have
(c) On Z+, where a * b = 2ab the same length. Prove that R is a congruence relation.
384 Chapter 9 Semigroups and Groups
11. Let G be a group and define /: G ->» G by f(a) = a~l. group of Gj, show that its image f(N) is a normal sub
Is / a homomorphism? Justify your answer. group of G2.
12. Let G be the group whose multiplication table is given 14. Let G be a group with identitye. Showthat if x2 = x for
below and let H be the subgroup {c, d, e}. some jc in G, then x = e.
* e a b c d f 15. Let G be the group of integers under the operation of ad
e e a b c d f dition and G' be the group of all even integers under the
a a e c b f d operation of addition. Show that the function f'.G^-G'
b b d e f a c defined by f(a) = 2a is an isomorphism.
c c f a d e b 16. Let H\, H2,..., Hk be subgroups of a group G. Prove
d d b f e c a k

f f c d a b e
that p| Hi is also a subgroupof G.
/=!

Find the right cosets of H in G. 17. Prove that if «Jn is an irrational number, then the set of
13. Let /: G\ -> G2 be a homomorphism from the group numbers of the form a + b+Jn, a, b integers, togetherwith
(Gi, *0 onto the group (G2, *2). If N is a normal sub ordinary addition and multiplication, is a field.

| Experiment 9
The purpose of this experiment is to investigate relationships among groups, sub
groups, and elements. Five groups are given as examples to use in the investiga
tion. You may decide to look at other groups as well to test your conjectures.
53 is the group of permutations of {1, 2, 3} with the operation of compo
sition. It is also the group of symmetries of a triangle. (See Section
9.4.)
D is the group of symmetries of a square. (This group is presented in
Exercise 19, Section 9.4.)
54 is the groupof permutations of {1, 2, 3,4} with the operation of compo
sition.

Gi is the group whose multiplication table is given in Table 1.


G2 is the group whose multiplication table is given in Table 2.
You may find it helpful to write out the multiplication tables for S3, D, and 54.

TABLE 1

1 2 3 4 5 6 7 8

l 1 2 3 4 5 6 7 8
TABLE 2
2 2 5 4 7 6 1 8 3
3 3 8 5 2 7 4 1 6 1 2 3

4 4 3 6 5 8 7 2 1 1 1 2 3 4 5
5 5 6 7 8 1 2 3 4 2 2 3 4 5 1
6 6 1 8 3 2 5 4 7 3 3 4 5 1 2
7 7 4 1 6 3 8 5 2 4 4 5 1 2 3
8 8 7 2 1 4 3 6 5 5 5 1 2 3 4

1. Identify the identity element e for each of the five groups.


2. For each of the five groups, do the following. For each elementg in the group,
find the smallest k for which gk = e, the identity. This number k is calledthe
order of g.
Experiment 9 385

3. What is the relationship between the order of an element of a group and the
order of the group? (The order of a group is the number of elements.)
4. For each of the five groups, find all subgroups of the group.
5. A group is called cyclic if its elements are the powers of one of the elements.
Identify any cyclic groups among the subgroups of each group.
6. What is the relationship between the order of a subgroup and the order of the
group?
7. The groups G\ and D are both of order 8. Are they isomorphic? Explain your
reasoning.
CHAPTER

Languages and
Finite-State Machines
Prerequisites: Chapters 7 and 9

Whenever we tell a modern-day digital computer to perform a task, we must trans


mit a set of precise step-by-step instructions to the computer that will instruct it
how to carry out this task. What language do we use to communicate with the
computer? In the early days of computers, the language used was machine lan
guage, which was labor intensive, clumsy to use, and prone to clerical errors. It
was soon realized that the ideal programming language is a natural language such
as English, Spanish, or French. Although much research has been done in this
area, it is still very difficult to have a computer understand everyday language.
Computer scientists and linguistshave developedthe field of formal language the
ory to obtain mathematical models of our natural languages. These models can
then be used to develop formal languages to communicate with a computer. In this
chapter we introduce the study of formal languages and develop another mathe
matical structure, phrase structure grammars, a simple device for the construction
of useful formal languages. We also examine several popular methods for rep
resenting these grammars. Finally, we provide an introduction to the notion of a
finite-state machine, an abstract mathematical model of a computer that is able to
recognize elements of a formal language.

Looking Back
The first computer program was written in 1843 by Ada Byron
King, Countess of Lovelace (1815-1852), who was the daugh
ter of Lord Byron, the great British poet. This computer pro
gram is contained in a translation and extensive supplement of
a publication in Italian dealing with the operation of the analyt
ical engine. This was a computer designed by Charles Babbage
(1791-1871), a Bristish mathematician who at an early age de
signed, but never built, a computer that shares many properties
with computers being used today. The computer programming
language Ada is named in honor of Lady Lovelace.
Lady Lovelace

386
10.1 Languages 387

10.1 Languages
In Section 1.3, we considered the set 5* consisting of all finite strings of elements
from the set 5. There are many possible interpretations of the elements of 5*,
depending on the nature of 5. If we think of 5 as a set of "words," then S* may
be regarded as the collection of all possible "sentences" formed from words in
5. Of course, such "sentences" do not have to be meaningful or even sensibly
constructed. We may think of a language as a complete specification, at least in
principle, of three things. First, there must be a set S consisting of all "words"
that are to be regarded as being part of the language. Second, a subset of 5* must
be designated as the set of "properly constructed sentences" in the language. The
meaning of this term will depend very much on the language being constructed.
Finally, it must be determined which of the properly constructed sentences have
meaning and what the meaning is.
Suppose, for example, that S consists of all English words. The specification
of a properly constructed sentence involves the complete rules of English gram
mar; the meaning of a sentence is determined by this construction and by the
meaning of the words. The sentence

"Going to the store John George to sing."


is a string in 5*, but is not a properly constructed sentence. The arrangement of
nouns and verb phrases is illegal. On the other hand, the sentence
"Noiseless blue sounds sit cross-legged under the mountaintop."
is properly constructed, but completely meaningless.
For another example, 5 may consist of the integers, the symbols +, —, x, and
^-, and left and right parentheses. We will obtain a language if we designate as
proper those strings in 5* that represent unambiguously parenthesized algebraic
expressions. Thus
((3 - 2) + (4 x 7))-=-9 and (7 - (8 - (9 - 10)))
are properlyconstructed "sentences" in this language. On the other hand, the three
strings (2 - 3)) + 4, 4 - 3 - 2, and )2 + (3 - ) x 4 are not properly constructed.
The first has too many parentheses, the second has too few (we do not know which
subtraction to perform first), and the third has parentheses and numbers completely
out of place. All properly constructed expressions have meaning except those
involvingdivisionby zero. The meaning of an expression is the rational number it
represents. Thus the meaning of ((2 - 1) ^ 3) + (4 x 6) is 73/3, while 2 + (3 -^ 0)
and (4 + 2) —(0 -r- 0) are not meaningful.
The specification of the proper construction of sentences is called the syn
tax of a language. The specification of the meaning of sentences is called the
semantics of a language. Among the languages that are of fundamental impor
tance in computer science are the programming languages. These include BASIC,
FORTRAN, JAVA, PASCAL, C++, LISP, ADA, FORTH, and many other general
and special-purpose languages. When they are taught to program in some pro
gramming language, people are actually taught the syntax of the language. In a
compiled language such as FORTRAN, most mistakes in syntax are detected by
the compiler, and appropriate error messages are generated. The semantics of a
programming language forms a much more difficult and advanced topic of study.
The meaning of a line of programming is taken to be the entire sequence of events
that takes place inside the computer as a result of executing or interpreting that
line.
388 Chapter 10 Languages and Finite-State Machines

We will not deal with semantics at all. We will study the syntax of a class of
languages called phrase structure grammars. Although these are not nearly com
plex enough to include natural languages such as English, they are general enough
to encompass many languages of importance in computer science. This includes
most aspects of programming languages, although the complete specification of
some higher-level programming languages exceeds the scope of these grammars.
On the other hand, phrase structure grammars are simple enough to be studied
precisely, since the syntax is determined by substitution rules. The grammars that
will occupy most of our attention lead to interesting examples of labeled trees.

Grammars

A phrase structure grammar G is defined to be a 4-tuple (V, 5, vo, h>), where


V is a finite set, 5 is a subset of V, vq e V — 5, and h^ is a finite relation on V*.
The idea here is that 5 is, as discussed previously, the set of all allowed "words" in
the language, and V consists of S together with some other symbols. The element
vo of V is a starting point for the substitutions, which will shortly be discussed.
Finally, the relation i-> on V* specifies allowable replacements, in the sense that,
if w \-^ w\ we may replace w by u/ whenever the string w occurs, either alone
or as a substring of some other string. Traditionally, the statement w \-> wf is
called a production of G. Then w and u/ are termed the left and right sides of
the production, respectively. We assume that no production of G has the empty
string A as its left side. We will call i-> the production relation of G.
With these ingredients, we can introduce a substitution relation, denoted by
=>>, on V*. We let x =$> y mean that x = / • w • r, y = I • wf • r, and w h> w'9
where / and r are completelyarbitrary strings in V*. In other words, x => y means
that y resultsfrom x by using one of the allowedproductions to replace part or all
of*. The relation => is usually called direct derivability. Finally, we let =^°° be
the transitive closure of => (see Section 4.3), and we say that a string w in S* is
a syntactically correct sentence if and only if v0 =^°° w. In more detail, this says
that a string w is a properlyconstructedsentence if w is in S*, not just in V*9 and
if we can get from u0 to w by making a finite number of substitutions. This may
seem complicated, but it is really a simple idea, as the following examples will
show.
If G = (V, 5, vo, h-») is a phrase structure grammar, we will call 5 the set of
terminal symbols and N = V - S the set of nonterminal symbols. Note that
V = SUN.
The reader should be warned that other texts have slight variations of the def
initions and notations that we have used for phrase structure grammars.

Example 1 Let S = {John, Jill, drives, jogs, carelessly, rapidly, frequently}, N = {sentence,
noun, verbphrase, verb, adverb}, and let V = 5 U N. Let vo = sentence, and
suppose that the relation h* on V* is described by

sentence h-> noun verbphrase


noun h^ John
noun !-)• Jill
verbphrase i-* verb adverb
verb h^ drives
verb I-** jogs
adverb h-> carelessly
adverb h-> rapidly
adverb \-^ frequently
10.1 Languages 389

The set S contains all the allowed words in the language; N consists of words that
describe parts of sentences but that are not actually contained in the language.
We claim that the sentence "Jill drives frequently," which we will denote by
w, is an allowable or syntactically correct sentence in this language. To prove this,
we consider the following sequence of strings in V*.

noun verbphrase
Jill verbphrase
Jill verb adverb
Jill drives adverb
Jill drives frequently

Now each of these strings follows from the preceding one by using a production
to make a partial or complete substitution. In other words, each string is related
to the following string by the relation =», so sentence =>°° w. By definition then,
w is syntactically correct since, for this example, vo is sentence. In phrase struc
ture grammars, correct syntax simply refers to the process by which a sentence is
formed, nothing else. ♦

It should be noted that the sequence of substitutions that produces a valid


sentence, a sequence that will be called a derivation of the sentence, is not unique.
The following derivation produces the sentence w of Example 1 but is not identical
with the derivation given there.

noun verbphrase
noun verb adverb
noun verb frequently
noun drives frequently
Jill drives frequently

The set of all properly constructed sentences that can be produced using a
grammar G is called the language of G and is denoted by L(G). The language
of the grammar given in Example 1 is a somewhat simple-minded sublanguage of
English, and it contains exactly 12 sentences. The reader can verify that "John
jogs carelessly" is in the language L(G) of this grammar, while "Jill frequently
jogs" is not in L(G).
It is also true that many different phrase structure grammars may produce the
same language; that is, they have exactly the same set of syntactically correct
sentences. Thus a grammar cannot be reconstructed from its language. In Section
10.2 we will give examples in which different grammars are used to construct the
same language.
Example 1 illustrates the process of derivation of a sentence in a phrase struc
ture grammar. Another method that may sometimes be used to show the derivation
process is the construction of a derivation tree for the sentence. The starting sym
bol, t>o, is taken as the label for the root of this tree. The level-1 vertices correspond
to and are labeled in order by the various words involved in the first substitution
for vo. Then the offspring of each vertex, at every succeeding level, are labeled
by the various words (if any) that are substituted for that vertex the next time it is
subjected to substitution. Consider, for example, the first derivation of sentence w
in Example 1. Its derivation tree begins with "sentence," and the next-level ver
tices correspond to "noun" and "verbphrase" since the first substitution replaces
the word "sentence" with the string "noun verbphrase." This part of the tree is
390 Chapter 10 Languages and Finite-State Machines

shown in Figure 10.1(a). Next, we substitute "Jill" for "noun," and the tree be
comes as shown in Figure 10.1(b). The next two substitutions, "verb adverb" for
"verbphrase" and "drives" for "verb," extend the tree as shown in Figures 10.1(c)
and (d). Finally, the tree is completed with the substitution of "frequently" for
"adverb." The finished derivation tree is shown in Figure 10.1(e).

sentence sentence

noun* verbphrase noun • verbphrase verbphrase

Jill* Jill* verb* >adverb


(a) (c)

sentence sentence

noun verbphrase noun verbphrase

Jill* verb • adverb Jill • verb • adverb

drives • drives • frequently


(d) (e)

Figure 10.1

The second derivation sequence, following Example 1 for the sentence w,


yieldsa derivation tree in the stagesshownin Figure 10.2on page 391. Notice that
the same tree results in both figures. Thus these two derivations yield the same
tree, and the differing orders of substitution simply create the tree in different
ways. The sentence being derived labels the leaves of the resulting tree.

Example 2 Let V = {d0, w, a, b, c}, S = {a, b, c), and let i->- be the relation on V* given by
1. Vo i-> aw. 2. w \-+ bbw. 3. w h> c.

Consider the phrase structure grammar G = (V7, S, v0, i-^). To derive a sen
tence of L(G), it is necessary to perform successive substitutions, using (1), (2),
and (3), until all symbols are eliminated other than the terminal symbols a, b, and
c. Since we begin with the symbol i>o, we must first use production (1), or we could
never eliminate urj. This first substitution results in the string aw. We may now
use (2) or (3) to substitute for w. If we use production (2), the result will contain
a w. Thus one application of (2) to awproduces the string ab2w (here bn means n
consecutive fc's). If we use (2) again, we will have the string ab4w. We may use
production (2) any number of times, but we will finally have to use production 3
to eliminate the symbol w. Once we use (3), only terminal symbols remain, so the
process ends. We may summarize this analysis by saying that L(G) is the subset
of 5* corresponding to the regular expression a(bb)*c (see Section 1.3). Thus the
word ab6c is in the language of G, and its derivation tree is shown in Figure 10.3.
Note that, unlike the treeof Example 1, the derivation treefor ab6c is not a binary
tree. ♦
10.1 Languages 391

sentence noun verbphrase

noun* verbphrase noun • verbphrase verb • • adverb

verb * • adverb • frequently


(a) (b) (c)

sentence
sentence

noun* verbphrase noun verbphrase

verb adverb Jill • verb adverb

drives* • frequency drives* frequently


(d) (e)

Figure 10.2 Figure 10.3

Example 3 Let V = {v0, w, a, b,c}, 5 = {a,b, c}, andlet \-+ be a relation on V* given by

1. vq \-> avob. 2. vob \-> bw. 3. abw \-+ c.

Let G = (V, 5, vo, h>) be the corresponding phrase structuregrammar. As we did


in Example 2, we determinethe form of allowable sentences in L(G).
Since we must begin with the symbol v0 alone, we must use production (1)
first. We may continue to use (1) any number of times, but we must eventually
use production (2) to eliminate v0. Repeated use of (1) will result in a string of
the form anvobn, n > 1; that is, there are equal numbers of a's and ib's. When
(2) is used, the result is a string of the form am(abw)bm with m > 0. At this
point the only production that can be used is (3), and we must use it to remove
the nonterminal symbol w. The use of (3) finishes the substitution process and
produces a stringin S*. Thus the allowable sentences L(G) of the grammarG all
have the form w = ancbn, where n > 0. In this case it can be shown that L(G)
does not correspond to a regular expression over S. ♦

Another interesting feature of the grammar in Example 3 is that the deriva


tions of the sentences cannot be expressed as trees. Our construction of derivation
trees works only when the left-hand sides of all productions used consist of single,
nonterminal symbols. The left-hand sides of the productions in Example 3 do not
have this simple form. Although it is possible to construct a graphical represen
tation of these derivations, the resulting digraph would not be a tree. Many other
problems can arise if no restrictions are placed on the productions. For this reason,
a classification of phrase structure grammars has been devised.
392 Chapter 10 Languages and Finite-State Machines

Let G = (V, S, vo, h>) be a phrase structure grammar. Then we say that G is
TYPE 0: if no restrictions are placed on the productions of G
TYPE 1: if for any production w\ \-+ w2, the length of w\ is less than or equal
to the length of w2 (where the length of a string is the number of words in that
string)
TYPE 2: if the left-hand side of each productionis a single, nonterminal symbol
and the right-hand side consists of one or more symbols
TYPE 3: if the left-hand side of each production is a single, nonterminal symbol
and the right-hand side has one or more symbols, including at most one nontermi
nal symbol, which must be at the extreme right of the string
In each of the precedingtypes, we permit the inclusionof the trivialproduction
vo \-> A, where A represents the empty string. This is an exception to the defining
rule for types 1, 2, and 3, but it is included so that the empty string can be made
part of the language. This avoids constant consideration of unimportant special
cases.

It follows from the definition that each type of grammar is a special case of
the type preceding it. Example 1 is a type 2 grammar, Example 2 is type 3, and
Example 3 is type 0. Grammars of types 0 or 1 are quite difficultto study and little
is known about them. They include many pathological examples that are of no
known practical use. We will restrict further consideration of grammars to types
2 and 3. These types have derivation trees for the sentences of their languages,
and they are sufficiently complex to describemany aspectsof actual programming
languages. Type 2 grammarsare sometimes called context-free grammars, since
the symbols on the left of the productions are substitutedfor whereverthey occur.
On the other hand, a production of the type / • w • r i-> I • w' • r (which could
not occur in a type 2 grammar) is called context sensitive, since wf is substituted
for w only in the context where it is surrounded by the strings I and r. Type 3
grammars have a very close relationship with finite-state machines. (See Section
10.3.) Type 3 grammarsare also called regular grammars.
A language will be called type 2 or type 3 if there is a grammar of type 2
or type 3 that produces it. This concept can cause problems. Even if a language
is produced by a non-type-2 grammar, it is possible that some type 2 grammar
also produces this same language. In this case, the language is type 2. The same
situation may arise in the case of type 3 grammars.
The process we have considered in this section, namely deriving a sentence
within a grammar, has a converse process. The converse process involves taking
a sentence and verifying that it is syntactically correct in some grammar G by
constructing a derivation tree that will produce it. This process is called parsing
the sentence, and the resulting derivation tree is often called the parse tree of the
sentence. Parsing is of fundamental importance for compilers and other forms of
language translation. A sentence in one language is parsed to show its structure,
and a tree is constructed. The tree is then searched and, at each step, corresponding
sentences are generated in another language. In this way a C++ program, for ex
ample, is compiled into a machine-language program. The contents of this section
and the next two sections are essential to the compiling process, but the complete
details must be left to a more advanced course.
10.1 Languages 393

10.1 Exercises

In Exercises 1 through 7, a grammar G is specified. In is given by


each case describe precisely the language, L(G), produced by
1. I \-+ L 8. Lv-*b
this grammar; that ist describe all syntactically correct "sen
2. I h+ LW 9. L\-+ c
tences."
3. W\-+ LW 10. D h O
1. G = (V, 5, v0, h>) 4. W\-+ DW 11. Dh+ 1
V = {v0, v\,x, y,z], S = {*,y,z} 5. Wh> L
\-> : vo !-• xvo 6. W\-+ D 19. D k 9
vo >-• yvi 7. L h> a
Vi i-> yvj
Which of the following statements are true for this gram
Vi H* Z
mar?
2. G = (V, 5, v0, h>) (a) 0^092 g L(G) (b) 2a?>b e L(G)
V = {v0,a}, S = {a]
(c) aaaa e L(G) (d) / => a
h> : vo h> aavo
vo i-* aa (e) I^°°ab (f) M=^2

3. G = (V, 5, v0, !-•) (g) DW =>°° 2 (h) W =J>°° 2abc


y = {v0,a,^}, s = {«,*} (i) W=*°°fca2c
h> : v0 m> flav0 10. Draw a derivation tree for a£3 in the grammar of Exer
v0 i-* a cise 9.
Vo i-> ^
11. If G is the grammar of Exercise 9, describe L(G).
4. G = (V, S, v0, h+) 12. Let G = (V, 5, v0, h>), where
V = {v0,A;,y,z}, S = {A;,y,z} V7 = {vo, ui, v2, <z, fc, c}, S = {a, b, c]
!-• : Vo H* XVo i-> : vo \-> aavo
vo h^ y^o Vo h^ &V]
V0\-+ z Vj H» cvib
5. G = (V, 5, v0, i->) Vi »-> c&
V = {v0, vi,v2, a, +,(,)}, V2 h-> &&V2
5 = {(,),«,+} V2 h* fefc.
»-> : vo h> (vo) (where left and right parentheses State which of the following are in L(G).
are symbols from S) (a) aabcb (b) abbcb
vo i-+ a + vi (c) aaaabcbb (d) aaaabcbbb
Vi H» <2 + V2
(e) abcbbbbb
v2 h* a -f v2
v2 h* a 13. If G is the grammar of Exercise 12, describe L(G).

6. G = (V, 5, v0, h>)


14. Draw a derivation tree forthe string as in thegrammar of
Exercise 2.
V = {v0, vua,b], S = {a,b}
h^ : Vo i-^ av\ 15. Give two distinct derivations (sequences of substitutions
V\ !->• Z?Vo that start at v0) for the string xyz e L(G), where G is the
vi h> a grammar of Exercise 7.
7. G = (V, 5, vo, h>) 16. Let G be the grammar of Exercise 5. Can you give
V = {v0, vi, v2, x, y, z}, 5 = {x, y, z} two distinct derivations (see Exercise 15) for the string
I-* : Vo !-• VoVi
((a + a + a))l
V0Vi h^ v2v0 17. Let G be the grammar of Exercise 9. Give two distinct
v2v0 !-• xy derivations (see Exercise 15) of the string a 100.
v2 h^ x 18. Let G = (V, 5, v0, •->), where V = {v0, vi}, 5 = {a, Z?},
Vi h^ z and
8. For each grammar in Exercises 1 through 7, state whether H* : Vo H->* &Vo
the grammar is type 1, 2, or 3. Vo i-* av\
v0\-+ b
9. Let G = (V, S, It h>), where
vi h* avo
Vi I-* &Vi
V = {/, L, D, W, a, fc, c, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
vj !-• a.
S = {a, b, c, 0,1, 2, 3,4, 5, 6,7, 8, 9} Describe L(G).
394 Chapter 10 Languages and Finite-State Machines

19. Let G = (V, 5, v0, h*)» where V = {v0, Vi, v2), P(k + 1): (aaa)M is in L(G). If (aaa)k = a3k is in
S = {<z, b], and L (G), then we must have applied. to Instead
»-)• : vo h> vjViVo we may use production rule to produce a3k'av?>.
V0 H* V2V2Vj (Complete the derivation of aaa3k+3.) Hence (aaa)3{k+{)
Vi h->- a is in L(G).
v2 h+ b.
30. Complete the following proof that any string in L(G) is
Prove or disprove that L(G) is the same as the language
of the form (aadf.
described in Exercise 18.
Proof: Clearly all strings in L(G) are of the form a1,
In Exercises 20 through26, construct a phrase structuregram 1 < /, because Let P(n): If a1 is in L(G) and
mar G such that the language, L(G), ofG is equal to the lan 3n < i < 3(n + 1), then i = 3(n + 1).
guage L. Basis Step: For n = 0, suppose a1 is in L(G) and
20. L = {anbn | n > 1}
It is easy to see that the smallest possible i with these pro
duction rules is 3. Hence P(0) is true.
21. L = {strings of 0's and l's with an equal number n > 0 Induction Step: Let k > 1. We use P(k): to show
ofO'sandl's} P(k + 1): Suppose 3(k + 1) < i < 3(k + 2).
22. L = {anbm \n> l,m> 1} We know that a1 must have been produced from
23. L = {aMfcn | n > 3} by production rule But at the step just before that
we must have usedproduction rule on al~2v\. The
24. L = {0wfcm \n> l,m>3}
stringa'~2v\ couldnot havebeenproduced usingproduc
25. L = {jc^y"1 | n > 2, m nonnegative and even} tion rule 1, because , but was produced from
26. L = {xnym \n even, m positive and odd} Since 3(fc+l) < i < 3(fc+2), we have 3k < i < 3(fc+l).
27. A palindrome is a string that reads the same from right to ByP(*),
left as it does from left to right. Construct a phrase struc 31. Let G\ and G2 be regular grammars with languages L\
ture grammar G such that L(G) is the set of palindromes and L2 respectively. Define a new language L3 =
using {a, b}. {w\ - vj2 I w\ e L\ and vj2 e L2}. Describe how to create
28. Construct a phrase structure grammar G such that L(G) a regular grammar for L3 from G\ and G2.
is the set of Boolean polynomials in x\, jc2, ..., xn. (See 32. Complete the following proof that no regular grammar G
Section 6.5.) can produce the language of Exercise 20.
In Exercises 29 and30, let V = {vo, Vi, v2, V3}, S = {a}, and Proof: Suppose that there is a regular grammar G =
let h» be the relation on V* given by (V, 5, v0,1-*) with n nonterminals. L(G) must contain
exactlythe stringsof the form albx'. But since G is regular,
1. vo \-+ av\ 2. Vi H> <2V2 3. v2 h^ avz
in the derivation of a'b' we must have with some
4. v21-> a 5. V3 j-> avj nonterminal v,. But with only n nonterminals, there must
be at least two strings <*> and (2) with the same
LetG = (V,S,v0,h+). nonterminals. (Why?) There is no way to guarantee that
29. Complete the following proof that each (aaa)*, n > 1 using the production rules on (1) and (2) will produce ex
belongs to L(G). actly _&'s from (1) and exactly fr's from (2).
Hence there is no such regular grammar G.
Proof: Basis Step: For n = 1, aaa is produced by
Hence aaa e L(G) 33. Show that [amban, m > 0, n > 1} is a context-free lan
Induction Step: Weuse P(k): (aaa)k is in L(G) to show guage.

10.2 Representations of Special Grammars and Languages

BNF Notation

For type 2 grammars (which include type 3 grammars), there are some useful,
alternative methods of displaying the productions. A commonly encountered al
ternative is called the BNF notation (for Backus-Naur form). We know that the
left-hand sides of all productions in a type 2 grammar are single, nonterminal
symbols. For any such symbol w, we combine all productions having w as the
left-hand side. The symbol w remains on the left, and all right-hand sides associ
ated with w are listed together, separated by the symbol |. The relational symbol
10.2 Representations of Special Grammars and Languages 395

h> is replaced by the symbol ::=. Finally,the nonterminal symbols, whereverthey


occur, are enclosed in pointed brackets ( ). This has the additional advantage that
nonterminal symbols may be permitted to have embedded spaces. Thus (wordl
word2) shows that the string between the brackets is to be treated as one "word,"
not as two words. That is, we may use the space as a convenient and legitimate
"letter" in a word, as long as we use pointed brackets to delimit the words.

Example 1 In BNFnotation, theproductions of Example 1 of Section 10.1 appear as follows.


(sentence) ::= (noun) (verbphrase)
(noun) ::= John | Jill
(verbphrase) ::= (verb) (adverb)
(verb) ::= drives | jogs
(adverb) ::= carelessly | rapidly | frequently ♦

Example 2 In BNFnotation, theproductions of Example 2 of Section 10.1 appear as follows.


(v0) ::=a{w)
(w) ::= bb(w) \ c ♦

Note that the left-hand side of a production may also appear in one of the
strings on the right-hand side. Thus, in the second line of Example 2, (w) appears
on the left, and it appears in the string bb(w) on the right. When this happens,
we say that the corresponding production w h* bbw is recursive. If a recursive
production has w as left-hand side, we will say that the production is normal if
w appears only once on the right-hand side and is the rightmost symbol. Other
nonterminal symbols may also appear on the right side. The recursive production
w h-> bbw given in Example 2 is normal. Note that any recursive production that
appears in a type 3 (regular) grammar is normal, by the definition of type 3.

Example 3 BNF notation is often used to specify actual programming languages. PASCAL
and many other languages had their grammars given in BNF initially. In this ex
ample, we consider a small subset of PASCAL'S grammar. This subset describes
the syntax of decimal numbers and can be viewed as a mini-grammar whose cor
responding language consists precisely of all properly formed decimal numbers.
Let 5 = {0,1,2, 3,4, 5,6,7, 8,9,.}. Let V be the union of 5 with the set
N = {decimal-number, decimal-fraction, unsigned-integer, digit}.
Then let G be the grammar with symbol sets V and 5, with starting symbol
"decimal-number" and with productions given in BNF form as follows:
1. (decimal-number) ::= (unsigned-integer) | (decimal-fraction) |
(unsigned-integer) (decimal-fraction)
2. (decimal-fraction) ::= .(unsigned-integer)
3. (unsigned-integer) ::= (digit) | (digit) (unsigned-integer)
4. (digit) ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Figure 10.4 shows a derivation tree, in this grammar, for the decimal number
23.14. Notice that the BNF statement numbered 3 is recursive in the second part
of its right-hand side. That is, the production "unsigned-integer h> digit unsigned-
integer" is recursive, and it is also normal. In general, we know that many different
grammars may produce the same language. If the line numbered 3 were replaced
by the line
396 Chapter 10 Languages and Finite-State Machines
^decimal-number

unsigned-integer

digit

Figure 10.4

3'. (unsigned-integer) ::= (digit) | (unsigned-integer) (digit)


we would have a different grammar that produced exactly the same language,
namely the correctly formed decimal numbers. However, this grammar contains a
production that is recursive but not normal. ♦

Example 4 As in Example 3, we give a grammar that specifies a piece of several actual pro
gramming languages. In these languages, an identifier (a name for a variable,
function, subroutine, and so on) must be composed of letters and digits and must
begin with a letter. The following grammar, with productions given in BNF, has
precisely these identifiers as its language.

G = (V, 5, identifier, !-•)


N = {identifier, remaining, digit, letter}
5 = {a,fe,c,...,z,0,1,2, 3,..., 9},
V = NUS

1. (identifier) ::= (letter) | (letter) (remaining)


2. (remaining) ::= (letter) | (digit) | (letter) (remaining) | (digit) (remaining)
3. (letter) ::= a \ b | c- •• | z
4. (digit) ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Again we see that the productions "remaining h> letter remaining" and "remaining
i-> digit remaining," occurring in BNF statement 2, are recursive and normal. ♦

Syntax Diagrams
A second alternative method for displaying the productions in some type 2 gram
mars is the syntax diagram. This is a pictorial display of the productions that
allows the user to view the substitutions dynamically, that is, to view them as
movement through the diagram. We will illustrate, in Figure 10.5, the diagrams
that result from translating typical sets of productions, usually all the productions
appearing on the right-hand side of some BNF statement.
A BNF statement that involves just a single production, such as (w) ::=
(wi)(w2)(w3>> Wni result in the diagram shown in Figure 10.5(a). The symbols
(words) that make up the right-hand side of the production are drawn in sequence
from left to right. The arrows indicate the direction in which to move to accom
plish a substitution, while the label w indicates that we are substituting for the
symbol w. Finally, the rectangles enclosing w\, w2, and w?> denote the fact that
10.2 Representations of Special Grammars and Languages 397

w J
-V
w
*• W\ —»- w2 u *3 *" *" x *" ^1 —©
^ -0 -0 • U)2 J
(a) (b)

M&-<b)—-
w

-~0-
-G>~) T^ "T
(c) (d) (e)

Figure 10.5

these are nonterminal symbols. If terminal symbols were present, they would in
stead be enclosed in circles or ellipses. Figure 10.5(b) shows the situation when
there are several productions with the same left-hand side. This figure is a syntax
diagram translation of the following BNF specification:

(w) ::= {w{){w2) | (w\)a \ bc(w2)

(where a, b, and c are terminal symbols). Here the diagram shows that when
we substitute for w, by moving through the figure in the direction of the arrows,
we may take any one of three paths. This corresponds to the three alternative
substitutions for the symbol w. Now consider the following normal, recursive
production, in BNF form:
(w) ::= ab(w).
The syntax diagram for this production is shown in Figure 10.5(c). If we go
through the loop once, we encounter a, then b, and we then return to the start
ing point designated by w. This represents the recursive substitution of abw for
w. Several trips around the diagram represent several successive substitutions.
Thus, if we traverse the diagram three times and return to the starting point, we
see that w will be replaced by abababw in three successive substitutions. This
is typical of the way in which movement through a syntax diagram represents the
substitution process.
The preceding remarks show how to construct a syntax diagram for a normal
recursive production. Nonnormal recursive productions do not lead to the simple
diagrams discussed, but we may sometimes replace nonnormal, recursive produc
tions by normal recursive productions and obtain a grammar that produces the
same language. Since recursive productions in regular grammars must be normal,
syntax diagrams can always be used to represent regular grammars.
We also note that syntax diagrams for a language are by no means unique.
They will not only change when different, equivalent productions are used, but
they may be combined and simplified in a variety of ways. Consider the following
BNF specification:
{w) ::= ab \ ab{w).
If we construct the syntax diagram for w using exactly the rules presented, we
will obtain the diagram of Figure 10.5(d). This shows that we can "escape" from
w, that is, eliminate w entirely, only by passing through the upper path. On the
other hand, we may first traverse the lower loop any number of times. Thus any
movement through the diagram that eventually results in the complete elimination
398 Chapter 10 Languages and Finite-State Machines
of w by successive substitutions will produce a string of terminal symbols of the
form(tffcy\n > 1.
It is easily seen that in the simpler diagram of Figure 10.5(e), produced by
combining the paths of Figure 10.5(d) in an obvious way, is an entirely equivalent
syntax diagram. These types of simplifications are performed whenever possible.

Example 5 The syntax diagrams of Figure 10.6(a) represent the BNF statements of Example
2, constructed with our original rules for drawing syntax diagrams. A slightly
more aesthetic version is shown in Figure 10.6(b). ♦

vo
*®. <D-
<£>
<£>

(a) (b)

Figure 10.6

Example 6 Consider the BNF statements 1, 2, 3, and 4 of Example 4. The direct translation
into syntax diagrams is shown in Figure 10.7. In Figure 10.8 we combine the first
two diagrams of Figure 10.7 and simplify the result. We thus eliminate the symbol
"remaining," and we arrive at the customary syntax diagrams for identifiers. ♦

identifier

letter
digit

Figure 10.7

identifier
letter

letter

digit

letter

Figure 10.8
10.2 Representations of Special Grammars and Languages 399
Example 7 The productions of Example 3, for well-formed decimal numbers, are shown in
syntax diagram form in Figure 10.9. Figure 10.10 shows the result of substituting
the diagram for "unsigned-integer" into that for "decimal-number" and "decimal-
fraction." In Figure 10.11 the process of substitution is carried one step further.
Although this is not usually done, it does illustrate the fact that we can be very
flexible in designing syntax diagrams. ♦

unsigned-integer
decimal-number
decimal-fraction

•[ unsigned-integer |—>\ decimal-fraction

decimal-number , (?y—»\ unsigned-integer |

unsigned-integer digit

Figure 10.9

digit
T j
decimal-number.
decimal-fraction

digit decimal-fraction

x 7
decimal-fraction
digit
-O-
c 7

Figure 10.10

If we were to take the extreme case and combine the diagrams of Figure 10.11
into one huge diagram, that diagram would contain only terminal symbols. In
that case a valid "decimal-number" would be any string that resulted from moving
through the diagram, recording each symbol encountered in the order in which it
was encountered, and eventually exiting to the right.

Regular Grammars and ReguBar Expressions


There is a close connection between the language of a regular grammar and a
regular expression (see Section 1.3). We state the following theorem without proof.
400 Chapter 10 Languages and Finite-State Machines
j-*\ qigu |—y

decimal-number
digit

7—1 aig" 0-7—ESO-


Y-^r\\)-r

Figure 10.11

THEOREM 1 Let 5 be a finite set, and L c 5*. Then L is a regular set if and only if L = L(G)
for some regular grammar G = (V, 5, i>o, *-*). *

Theorem 1 tells us that the language L(G) of a regular grammar G must be the
set corresponding to some regular expression over 5, but it does not tell us how to
find such a regular expression. If the relation I-*- of G is specified in BNF or syntax
diagram form, we may compute the regular expression desired in a reasonably
straightforward way. Suppose, for example, that G = (V, S, uq, h>) and that i-> is
specified by a set of syntax diagrams. As we previously mentioned, it is possible
to combine all the syntax diagrams into one large diagram that represents vo and
involves only terminal symbols. We will call the result the master diagram of G.
Consider the following rules of correspondence between regular expressions and
parts, or segments, of the master diagram of G.
1. Terminal symbols of the diagram correspond to themselves, as regular expres
sions.
2. If a segment D of the diagram is composed of two segments D\ and D2 in
sequence, as shown in Figure 10.12(a), and if D\ and D2 correspond to regular
expressions a\ and a2, respectively, then D corresponds to a\ • a2.
3. If a segment D of the diagram is composed of alternative segments D\ and
D2, as shown in Figure 10.12(b), and if D\ and D2 correspond to regular
expressions ct\ and a2, respectively, then D corresponds to ct\ v a2.
4. If a segment D of the diagram is a loop through a segment D\, as shown in
Figure 10.12(c), and if D\ corresponds to the regular expression a, then D
corresponds to a*.

<£?>—C5

(a) (b) (c)

Figure 10.12

Rules 2 and 3 extend to any finite number of segments Dt of the diagram.


Using the foregoing rules, we may construct the single expression that corresponds
to the master diagram as a whole. This expression is the regular expression that
corresponds to L(G).
10.2 Representations of Special Grammars and Languages 401

Example 8 Consider the syntax diagram shown in Figure 10.13(a). It is composed of three
alternative segments, the first corresponding to the expression a, the second to the
expression b, and the third, a loop, corresponding to the expression c*. Thus the
entire diagram corresponds to the regular expression av bv c*.
The diagram shown in Figure 10.13(b) is composed of three sequential seg
ments. The first segment is itself composed of two alternative subsegments, and it
corresponds to the regular expression a vb. The second component segment of the
diagram corresponds to the regular expression c, and the third component, a loop,
corresponds to the regular expression d*. Thus the overall diagram corresponds to
the regular expression (a V b)cd*.
Finally, consider the syntax diagram shown in Figure 10.13(c). This is one
large loop through a segment that corresponds to the regular expression a v be.
Thus the entire diagram corresponds to the regular expression (a v be)*. ♦

(b)

Figure 10.13

Example 9 Consider the grammar G given in BNF in Example 2. Syntax diagrams for this
grammar were discussed in Example 5 and shown in Figure 10.6(b). If we sub
stitute the diagram representing w into the diagram that represents i>o, we get the
master diagram for this grammar. This is easily visualized, and it shows that L(G)
corresponds to the regular expression a(bb)*c, as we stated in Example 2 of Sec
tion 10.1. ♦

Example 10 Consider the grammar G of Examples 4 and 6. Then L(G) is the set of legal
identifiers, whose syntax diagrams are shown in Figure 10.8. In Figure 10.14 we
show the master diagram that results from combining the diagrams of Figure 10.7.
It follows that a regular expression corresponding to L(G) is

(a v b v ••• v z)(a v&v-.-vzv0vlv---v 9)*. ♦

The type of diagram segments illustrated in Figure 10.12 can be combined to


produce syntax diagrams for any regular grammar. Thus we may always proceed
as just illustrated to find the corresponding regular expression. With practice one
can learn to compute this expression directly from multiple syntax diagrams or
BNF, thus avoiding the need to make a master diagram. In any event, complex
cases may prove too cumbersome for hand analysis.
402 Chapter 10 Languages and Finite-State Machines
identifier

Figure 10.14

10.2 Exercises

In each of Exercises I through 5, we have referenced a gram- 12.


mar described in the exercises of a previous section. In each
case, give the BNF and corresponding syntax diagrams for the
productions of the grammar.
1. Exercise 1 of Section 10.1

2. Exercise 2 of Section 10.1

3. Exercise 6 of Section 10.1


4. Exercise 9 of Section 10.1 Figure 10.16
5. Exercise 12 of Section 10.1

6. Give the BNF for the productions of Exercise 3 of Section


10.1.

7. Give the BNF for the productions of Exercise 4 of Section


10.1. 13. •<2>y - —*»-
*>i >-

8. Give the BNF for the productions of Exercise 5 of Section


10.1. h- —>• u2 >-

9. Give the BNF for the productions of Exercise 6 of Section


10.1. v2 *> 1»

10. Let G = (V, 5, v0, i-»), where V = {v0, vi, 0,1}, y-


)
S = {0,1}, and £> —*-
v\

h» : vo m> Ovi
Figure 10.17
V\ \-+ llui
v\ \-> 010t>i
Vi h-> 1.
Give the BNF representation for the productions of G.
In Exercises 11 through 16, give the BNF representation for
the syntax diagram shown. The symbols a, b, c, and d are 14. ^^a) Hj>
terminal symbols of some grammar. You may provide nonter
minal symbols as needed (inaddition to Vo), to usein theBNF Vl
productions. Youmay use several BNF statements if needed. *>2

11. ^-^0 ^0_ <*> —©


V2
<£> Vl

Figure 10.15 Figure 10.18


10.3 Finite-State Machines 403

15. In each of Exercises 17 through 21, we have referenced a


grammar G, described in the exercises of a previous section.
In each case find a regular expression that corresponds to the
language L(G).

t>i 17. Exercise 2 of Section 10.1


^o
18. Exercise 3 of Section 10.1

19. Exercise 5 of Section 10.1

20. Exercise 6 of Section 10.1


Figure 10.19 21. Exercise 9 of Section 10.1

22. Find the regular expression that corresponds to the syntax


16. ^ ^\ „ *>i diagram of Exercise 11.
23. Find the regular expression that corresponds to the syntax
*>2
diagram of Exercise 12.
24. Find the regular expression that corresponds to the syntax
V2 diagram of Exercise 13.
25. Find the regular expression that corresponds to the syntax
diagram of Exercise 14.
*>0
26. Find the regular expression that corresponds to the syntax
diagram of Exercise 15.
^2
27. Find the regular expression that corresponds to the syntax
^0 diagram of Exercise 16.
28. Find the regular expression that corresponds to L(G) for
Figure 10.20 G given in Exercise 10.
29. Give the syntax diagram for the grammar in Exercise 10.

10.3 Finite-State Machines

The question of whether a certain string belongs to the language of a given gram
mar is, in general, a difficult one to answer. In fact, in some cases it cannot be
answered at all. Regular grammars and regular languages, though, have properties
that enable us to construct a "recognizer" (or acceptor) for strings that belong to a
given regular grammar. We lay the foundation for this construction in this section.
We think of a machine as a system that can accept input, possibly produce
output, and have some sort of internal memory that can keep track of certain in
formation about previous inputs. The complete internal condition of the machine
and all of its memory, at any particular time, is said to constitute the state of the
machine at that time. The state in which a machine finds itself at any instant sum
marizes its memory of past inputs and determines how it will react to subsequent
input. When more input arrives, the given state of the machine determines (with
the input) the next state to be occupied, and any output that may be produced. If
the number of states is finite, the machine is a finite-state machine.
Suppose that we have a finite set S = {so, s\,..., sn], a finite set /, and for
each x e /, a function fx: S -• S. Let F = {fx \ x e I}. The triple (5, /, $)
is called a finite-state machine, S is called the state set of the machine, and the
elements of S are called states. The set / is called the input set of the machine.
For any input x e /, the function fx describes the effect that this input has on
the states of the machine and is called a state transition function. Thus, if the
machine is in state si and input x occurs, the next state of the machine will be
Msi).
404 Chapter 10 Languages and Finite-State Machines

Since the next state fx(st) is uniquely determined by the pair (s,-, x), there is
a function F: 5 x / -> S given by

F(st,x) = fx(Si).

The individual functions fx can all be recovered from a knowledge of F. Many


authors use a function F: S x / -» 5, instead of a set {/*!*€ /}, to define a
finite-state machine. The definitions are completely equivalent.

Example 1 Let S = {so, s\) and / = {0,1}. Define f0 and f\ as follows:

/o(so) = ^o, /i(so) =*i.


/ofa) = Ji, /iC*i) = s0.

This finite-state machine has two states, so and s\, and accepts two possible
inputs, 0 and 1. The input 0 leaves each state fixed, and the input 1 reverses states.

We can think of the machine in Example 1 as a model for a circuit (or logical)
device and visualize such a device as in Figure 10.21. The output signals will,
at any given time, consist of two voltages, one higher than the other. Either line
1 will be at the higher voltage and line 2 at the lower, or the reverse. The first
set of output conditions will be denoted so and the second will be denoted s\. An
input pulse, represented by the symbol 1, will reverseoutput voltages. The symbol
0 represents the absence of an input pulse and so results in no change of output.
This device is often called a T flip-flop and is a concrete realization of the machine
in this example.

Line 1

0 1
Output signal
•*o *0 *1
Input signal
Line 2 *1 *1 *0

Figure 10.21 Figure 10.22

We summarize this machine in Figure 10.22. The table shown there lists the
states down the side and inputs across the top. The column under each input gives
the values of the function corresponding to that input at each state shown on the
left.
The arrangement illustrated in Figure 10.22 for summarizing the effect of in
puts on states is called the state transition table of the finite-state machine. It
can be used with any machine of reasonable size and is a convenient method of
specifying the machine.

Example 2 Consider the state transition table shown in Figure 10.23. Here a and b are the
a b
possible inputs, and there are three states, sq9 s\9 and 5-2. The table shows us that
so so si
S.
fa(So) = So, fa(Si) = S2, fa(s2) = S\
S2 so
S2 Sl S2
and

Figure 10.23
fb(so) = S\9 fb(S\) = So, Ms2) = S2.
10.3 Finite-State Machines 405

If M is a finite-state machine with states 5, inputs /, and state transition


functions {fx \ x e /}, we can determine a relation RM on S in a natural way.
If si, Sj € 5, we say that si Rm Sj if there is an input x so that fx(st) = Sj.
Thus si Rm Sj means that if the machine is in state St, there is some input
x e I that, if received next, will put the machine in state Sj. The relation Rm
permits us to describe the machine M as a labeled digraph of the relation Rm on
5, where each edge is labeled by the set of all inputs that cause the machine to
Figure 10.24 change states as indicated by that edge.

Example 3 Consider themachine ofExample 2. Figure 10.24 shows thedigraph of therelation


Rm, with each edge labeled appropriately. Notice that the entire structure of M
can be recovered from this digraph, since edges and their labels indicate where
each input sends each state. ♦

Example 4 Consider themachine M whose table is shown in Figure 10.25(a). Thedigraph of


Rm is then shown in Figure 10.25(b), with edges labeled appropriately. ♦

a, b, c
a b c
so) * \Si
*0 so so so

*1 s2 S3 s2
s2 S\ so S3
s3 S3 s2 S3

(a)

Figure 10.25

Note that an edge may be labeled by more than one input, since several inputs
may cause the same change of state. The reader will observe that every input must
be part of the label of exactlyone edge out of each state. This is a general property
that holds for the labeled digraphs of all finite-state machines. For brevity, we will
refer to the labeled digraph of a machine M simply as the digraph of M.
It is possible to add a variety of extra features to a finite-state machine in order
to increase the utility of the concept. A simple, yet very useful extension results in
what is often called a Moore machine, or recognition machine, which is defined
as a sequence (5, /, F, so, T), where (5, /, 30 constitutes a finite-state machine,
so e S and T c 5. The state s0 is called the starting state of M, and it will be
used to represent the condition of the machine before it receives any input. The set
T is called the set of acceptance states of M. These states will be used in Section
10.4 in connection with language recognition.
When the digraph of a Moore machine is drawn, the acceptance states are
a,c
indicated with two concentric circles, instead of one. No special notation will be
used on these digraphs for the starting state, but unless otherwise specified, this
Figure 10.26 state will be named so-

Example 5 Let M be the Moore machine (5, /, !F, s0, T), where (5, /, £) is the finite-state
machine of Figure 10.25 and T = {s\, S3}. Figure 10.26 shows the digraph of M.

406 Chapter 10 Languages and Finite-State Machines

Machine Congruence and Quotient Machines


Let M = (S, /, 30 be a finite-state machine, and suppose that R is an equivalence
relation on 5. We say that R is a machine congruence on M if, for any s,t e S,
s R t implies that fx(s) R fx(t) for all x e /. In other words, R is a machine
congruence if ^-equivalent pairs of states are always taken into /?-equivalent pairs
of states by every input in /. If R is a machine congruence on M = (S, /, 50,
we let S = 5/7? be the partition of 5 corresponding to R (see Section 4.5). Then
S = {[s] \seS}.
For any input x e I, consider the relation fx on 5 defined by

7x = {([s],[fAs)])}.
If [s] = [t], then* R v, therefore, fx(s)_ R fx(t), so [fx(s)] = [4(0]. This shows
that the relation fx is a function from 5 to S, and we may write fx([s]) = [fx(s)]
for all equivalence classes [s] in 5. If we let F = [fx \x e i), then the triple
M = (S, /, 50 is a finite-state machine called the quotient of M corresponding
to R. We will also denote M by M/R.
Generally, a quotient machine will be simpler than the original machine. We
will show in Section 10.6 that it is often possible to find a simpler quotient machine
that will replace the original machine for certain purposes.

Example 6 Let M be the finite-state machine whose state transition table is shown in Figure
10.27. Then 5 = {so,s\,s2,S3,s4, S5}. Let R be the equivalence relation on S
a b
whose matrix is
sA 10 10 0 0"
*0 so
0 10 10 1
*1 S\ so 10 10 0 0
MR =
*2 Sl 54 0 10 10 1

s2
0 0 0 0 10
*3 S5
0 10 10 1
54 S4 S3
Then we have S/R = {[s0], [s\], [54]}, where
*5 S3 s2

l>o] = {^0,^2} = |>2L


Figure 10.27 [si] = {^ ^ ,5, = fo] = fcL
and

[s4] = {54}.
a b

[*J [s0] w We check that R is a machine congruence. The state transition table in Figure
10.27 shows that fa takes each element of [>,•] to an element of [s,-] for i = 0,
[*l] [*il tod 1, 4. Also, fb takes each element of [50] to an element of [54], each element of
w W M [s\] to an element of |>oL and each element of [>4] to an element of [s\]. These
observations show that R is a machine congruence; the state transition table of the
Figure 10.28 quotient machine M/R is shown in Figure 10.28. ♦

Example 7 Let / = {0,1}, 5 = {so, su s2, s3i s4, s5, s6,57}, andM = (5, /, 50, thefinite-state
machine whose digraph is shown in Figure 10.29.
Suppose that R is the equivalence relation whose corresponding partition of
5, S/R, is {{so, S4}, {s\,s2, S5}, {se}, {S3, s-j}}. Then it is easily checked, from the
digraph of Figure 10.29, that R is a machine congruence. To obtain the digraph of
the quotient machine M, draw a vertex for each equivalence class, |>o] = fao> ^4},
L*i] = {^1,^2,S5}, [st] = {st}, [s^] = {S3, sj}, and construct an edge from [.$,•] to
10.3 Finite-State Machines 407

Figure 10.29 Figure 10.30

[sj] if there is, in the original digraph, an edge from some vertex in [s,-] to some
vertex in [sj]. In this case, the constructed edge is labeled with all inputs that take
some vertex in [>/] to some vertex in [sj]. Figure 10.30 shows the result. The
procedure illustrated in this example works in general. ♦

If M = (S, I, 7, so, T) is_a Moore machine, and R is a machine congru


ence on M, then we may let T = {[t] \ t e T}. Here, the sequence M =
(5, /, T, \so\, T) is a Moore machine. In other words, we compute the usual quo
tient machine M/R; then we designate |>o] as a starting state, and let T be the
set of equivalence classes of acceptance states. The resulting Moore machine M,
Figure 10.31 constructed this way, will be called the quotient Moore machine of M.

Example 8 Consider the Moore machine (5, /, 5% so, T), where (S, I, 50 is the finite-state
machine of Example 6 and T is the set {s\,S3, s4}. The digraph of the resulting
quotient Moore machine is shown in Figure 10.31. ♦

10.3 Exercises

In Exercises 1 through 6, draw the digraph of the machine In Exercises 7 through 12 (Figures 10.32 through 10.37), con
whose state transition table is shown. Remember to label the struct the state transition table of the finite-state machine
edges with the appropriate inputs. whose digraph is shown.
0 1 0 1 2 a

so Jo S\ so S\ so si

S\ S\ Si S\ so so S\
si Si so Si Si so si

Figure 10.32
3. a b 4. a b
*0 S\ so so Sl so
S\ Sl so Sl Sl Sl u 1
Si Sl so Sl S3 Sl
S3 S3 S3

a b c 0 1 2 0,1

so so S\ Sl so so $2 Sl
S\ Sl S\ Sl Sl Sl S3 s2
Sl S\ S\ Sl Sl Sl Sl S3
S3 Sl so Sl S3 S3 S3 Sl Figure 10.33
408 Chapter 10 Languages and Finite-State Machines
15. Consider a finite group (S, *) and let (5, 5, !F) be the
finite-state machine constructed in Exercise 14. Show that
if R is the relation defined in Exercise 14, then R is an
equivalence relation.
16. Let / = {0,1} and S = {a, b}. Construct all possible state
transition tables of finite-state machines that have
S as state set and / as input set.
17. Consider the machine whose state transition table is

0 1

10. 1 1 4
2 3 2
3 2 3
4 4 1

Here S = {1,2, 3,4}.


Figure 10.35
(a) Show that R = {(1,1), (1,4), (4,1), (4,4), (2,2),
11.
(2, 3), (3, 2), (3, 3)} is a machine congruence.
(b) Construct the state transition table for the corre
sponding quotient machine.
18. Consider the machine whose state transition table is

a b c

so so Sl S3
a,b
Sl so Sl Sl
Sl Sl S3 so
S3 Sl Sl so
Figure 10.36
Let R = {(so, si), (s0, s0), (si,s{), (sus0), (s3, s2),
12. i o (Sl,Si),(s3,S3),(S2,S3)}.
(a) Show that R is a machine congruence.
Q-^^Q (b) Construct the digraph for the corresponding quotient
machine.

19. Consider the machine whose state transition table is

0 1
so Sl $2
Sl so ^2
Sl S3 so
S3 Sl S3

Let R = {(so, s0), (susi), (s2, s2), (s3, s3), (s0, s{),
(si,s0)}.
Figure 10.37 (a) Show that R is a machine congruence.
13. Let M = (S, I, T) be a finite-state machine. Define (b) Construct the digraph for the corresponding quotient
a relation R on / as follows: xx R x2 if and only if machine.

fXl (s) = fX2 (s) for every s in S. Show that R is an equiv 20. Consider the Moore machine whose digraph is shown in
alence relation on /. Figure 10.38.
14. Let (5, *) be a finite semigroup. Then we may consider
the machine (S, S, $), where F = [fx \ x e S], and
fx(y) = x * v for all jc, v 6 5. Thus we have a finite-state
machine in which the state set and the input are the same.
Define a relation R on S as follows: x R y if and only if
there is some z € S such that fz(x) = y. Show that R is
transitive. Figure 10.38
10.4 Monoids, Machines, and Languages 409
(a) Show that the relation R on S whose matrix is 22. Consider the Moore machine whose digraph is shown in
Figure 10.40. Show that the relation R on S whose matrix
1 0 0 0 0
is
0 1 0 0 0 -10 0 0 0"
M* = 0 0 1 1 1 0 10 0 0
0 0 1 1 1 0 0 111
0 0 1 1 1 0 0 111
0 0 111
is a machine congruence.
(b) Draw the digraph of the corresponding quotient ma is a machine congruence. Draw the digraph of the corre
chine. sponding quotient Moore machine.
21. Consider the Moore machine whose digraph is shown in
Figure 10.39. Show that the relation R on S whose matrix
is
1 0 0 0 1 0
0 1 0 0 0 1
0 0 1 1 0 0
MR =
0 0 1 1 0 0
1 0 0 0 1 0
Figure 10.40
0 1 0 0 0 1

is a machine congruence. Draw the digraph of the corre 23. Let M' = (S', /, F\ s'0, V) and M" = (S"', /, F\ s'0\ T")
sponding quotient Moore machine. be two Moore machines with the same input set. De
fine S = S' x S", s0 = (s'0, s%)9 T = V x T", and
F by fx(s',s») = (/;(*'),/>")). Show that M =
(S, /, F, so, T) is a Moore machine.
24. LetM' = (S'» /, T, s0, T) andM" = (S", /, F\ *£', T")
be two Moore machines with the same input set. Define
S = S' x S", s0 = (s0,s'Q% T = {(t',t") \t' eV or
t" e T"), and ^by fx(s',s") = (f'x(sf), f'x'(s")). Show
that M = (S, I, !F, s0, T) is a Moore machine.
25. Using the definition of M in Exercise 23, give its state
transition table if M' is the machine in Exercise 1 and M"
is the machine in Exercise 8.

10.4 Monoids, Machines, and Languages


Let M = (S, I, 50 be a finite-state machine with state set S = {s^,s\, ...,sn),
input set /, and state transition functions 3r= {fx \ x € /}.
We will associate with M two monoids, whose construction we recall from
Section 9.2. First, there is the free monoid /* on the input set /. This monoid
consists of all finite sequences (or "strings" or "words") from /, with catenation
as its binary operation. The identity is the empty string A. Second, we have the
monoid Ss, which consists of all functions from 5 to 5 and which has function
composition as its binary operation. The identity in Ss is the function 1$ defined
by 15(5") = s, for all s in S.
lfw = xxx2 •••xn e I*, we let /„, = fXn o fXn_{ o ••. o fxi, the composition
of the functions fXn, fXfl_x,..., fXx. Also, we define fA to be 15. In this way we
assign an element fw of Ss to each element w of /*. If we think of each fx as
the effect of the input x on the states of the machine M, then fw represents the
combined effect of all the input letters in the word w, received in the sequence
specified by w. We call fw the state transition function corresponding to w.
410 Chapter 10 Languages and Finite-State Machines
Example 1 Let M = (S, I, !F), where 5 = {s0, s\, s2}, I = {0, 1}, and ,Fis given by the
following state transition table.
0 1
so so S\
S\ s2 Sl
Sl s\ so

Let w = Oil G /*. Then

/«,(*>) = (/i o /i o f0)(so) = MMMso)))


= MMso)) = Msi) = s2.
Similarly,

fw(Si) = fl(MMSi))) = Mfds2)) = fX(So) = S{


and

fw(s2) = /i(/i(/ofe))) = fdfdsi)) = fi(s2) = s0. ♦

Example 2 Let us consider the same machine M as in Example 1 and examine the problem of
computing fw a little differently. In Example 1 we used the definition directly, and
for a large machine we would program an algorithm to compute the values of fw
in just that way. However, if the machine is of moderate size, we may find another
procedure to be preferable.
We begin by drawing the digraph of the machine M as shown in Figure 10.41.
We may use this digraph to compute word transition functions by just following
the edges corresponding to successive input letter transitions. Thus, to compute
fw(so), we start at state so and see that input 0 takes us to state so. The input 1
that follows takes us on to state s\, and the final input of 1 takes us to s2. Thus
Figure 10.41 fw(so) = ^2, as before.
Let us compute fwt9 where wf = 01011. The successive transitions of so are
0 10 11
so —• so —> S\ —> s2 —• So —> S\,

so fw>(so) = si. Similar displays show that fw'(si) = s2 and fw>(s2) = so. ♦

This method of interpreting word transition functions such as fw and fw' is


useful in designing machines that have word transitions possessing certain desired
properties. This is a crucial step in the practical application of the theory and we
will consider it in the next section.
Let M = (5, /, 5) be a finite-state machine. We define a function T from /*
to Ss. If w is a string in /*, let T(w) = /„; as defined previously. Then we have
the following result.

THEOREM 1 (a) If w\ and w2 are in /*, then T(wi • w2) = T(w2) o T(w{).
(b) If M = T(/*), then M is a submonoid of Ss.

Proof
(a) Let wi = xix2 --Xk and w2 = yiy2 • • •ym be two strings in /*. Then
T(w{ -w2) = T(xix2--xkyiy2->ym)
= (fym ° fym-i °"'0fyi)°(fxko fXk_, o ••• o fX{)
= T(w2)oT(wi).
Also, T(A) = Is by definition. Thus T is a monoid homomorphism.
10.4 Monoids, Machines, and Languages 411

(b) Part (a) shows that if / and g are in M, then fog and g of are in M. Thus
M is a subsemigroup of Ss. Since 1$ = T(A), I5 e M. Thus M is a
submonoid of S5. The monoid M is called the monoid of the machine M.

Example 3 Let S = {sq, si, s2} and / = {a,b, d}. Consider the finite-state machine M =
(S, I, T) defined by the digraph shown in Figure 10.42. Compute the functions
a,2> h a had, fadd, and fbadadd, andverify that
-1 fadd ° fbad = fbadadd-
?2)
b,d
Solution
Figure 10.42 fbad is computed by the following sequence of transitions:
b a

so so so si
b a

s\ S\ s2 si
b a

Sl S\ Sl

Thus fbadiso) = su fbad(s\) = su and fbad(si) = sx.


Similarly, for fadd,
a d d
so so S\ so
a d d
S\ Sl S\ so
a d d
Sl Sl S\ so,

so fadd(sd = so for i = 0,1, 2. A similar computation shows that

fbadadd(So) = So, fbadadd(S\) = So, fbadadd(Sl) = So

and the same results hold for fadd o fbad- In fact,

(fadd O fbad)(So) = fadd(fbadiSo)) = fadd(S\) = ^0


(fadd Ofbad)(S\) = fadd(fbad(S\)) = fadd(S\) = ^0
(fadd O fbad)(Sl) = fadd(fbad(Sl)) = fadd(S\) = Sq> #

Example 4 Consider the machine whose graph is shown in Figure 10.43. Show that fw(so) =
so if and only if w has 3/2 l's for some n > 0.

Solution
From Figure 10.43 we see that fo = Is, so the O's in a string w e I* have no effect
on /„;. Thus, if w is w with all O's removed, then fw = f^. Let l(w) denote the
length of w, that is, the number of digits in w. Then l(w) is the number of l's in
w, for all w € /*. For each n > 0, consider the statement

P(n): Let w € /* and let l(w) = m.


(a) If m = 3n, then fw(so) = so-
(b) If m = 3ft + 1, then fw(so) = s\.
(c) If m = 3ft + 2, then /^Oso) = ^2.
Figure 10.43 We prove by mathematical induction that P(ft) is true for all n > 0.
412 Chapter 10 Languages and Finite-State Machines

Basis Step
Suppose that n = 0. In case (a), m = 0; therefore, w has no l's and fw(so) =
lsfao) = s0. In case (b), m = 1, so w = 1 and /u,(s0) = /urC^o) = /iOo) = s\.
Finally, in case (c), m = 2, so w = 11, and /w(^o) = /urfao) = /nOo) =
f\(S\) = *2-

Induction Step
We must use P(k) to show F(k + 1). Let w e I*, and denote l(w) by m. In
case (a), m = 3(k + 1) = 3k + 3; therefore, W = u/ • 111, where /(u/) = 3&.
Then fw'(so) = so by P(&), part (a), and fm(so) = so by direct computation, so
fyj(so) = fw'(fm(so)) = /u/C?o) = so- Cases (b) and (c) are handled in the same
way. Thus P(k + 1) is true.
By mathematical induction, P(ft) is true for all n > 0, so fw(so) = so if and
only if the number of 1's in w is a multiple of 3. ♦

Suppose now that (5, /, 5% so, T) is a Moore machine. As in Section 10.1,


we may think of certain subsets of /* as "languages" with "words" from /. Using
M, we can define such a subset, which we will denote by L(M), and call the
language of the machine M. Define L(M) to be the set of all w e I* such that
fw(so) € 7\ In other words, L(M) consists of all strings that, when used as input
to the machine, cause the starting state so to move to an acceptance state in T.
Thus, in this sense, M accepts the string. It is for this reason that the states in T
were named acceptance states in Section 10.3.

Example 5 Let M = (S, I, !F, so, T) be the Moore machine in which (5, /, 3^) is the finite-
state machine whose digraph is shown in Figure 10.43, and T = {si}. The discus
sion of Example 4 shows that fw(s0) = si if and only if the number of l's in w
is of the form 3ft + 1 for some n > 0. Thus L(M) is exactly the set of all strings
with 3ft + 1 l's for some n > 0. ♦

Example 6 Consider the Moore machine M whose digraph is shown in Figure 10.44. Here
state so is the starting state, and T = {^2}. What is L(M)1 Clearly, the input set
a a a,b is I = {a,b}. Observe that, in order for a string w to cause a transition from so
8 to si, w must contain at least two fe's. After reaching s2, any additional letters
have no effect. Thus L(M) is the set of all strings having two or more b's. We
see, for example, that faabaa(so) = si, so aabaa is rejected. On the other hand,
Figure 10.44 fabaab(so) = s2, so abaab is accepted. ♦

10.4 Exercises

In Exercises 1 through 5, we refer to the finite-state machine 2. List the values of the transition function /„, for
whose state transition table is w = 11100.

0 1 3. Describe the set of binary words (sequences of O's and


so •so *1 l's) w having the property that fw(so) = s0.
Sl Sl ^2
Sl S2 *3 4. Describe the set of binary words w having the property
S3 •*3 so that fw = /bio.

1. List the values of the transition function fw for 5. Describe the set of binary words w having the property
w = 01001. that/„(so) = s2.
10.4 Monoids, Machines, and Languages 413

In Exercises 6 through 10, we refer to the finite-state machine 14. 1 0,1


whose digraph is shown in Figure 10.45.
3 o Q
•MS)

Figure 10.49

Figure 10.45 15. a


6. List the values of the transition function fw for w = abba.
7. List the values of the transition function /„; for
w = babab.

8. Describe the set of words w having the property that Figure 10.50
fw(So) =S2.
9. Describe the set of words w having the property that In Exercises 16 through 22, describe (in words) the language
accepted by the Moore machine whose state table is given. The
fw(so) = so-
starting state is sq, and the set T ofacceptance states is shown.
10. Describe the set of words w having the property that
Jw = J aba' 16. 0 1

so Sl Sl
In Exercises 11 through 15, describe (in words) the language
Sl Sl Sl T = [s2]
accepted by the Moore machines whose digraphs are given in
Sl Sl Sl
Figures 10.46 through 10.50.
11. 17. 0 1
so S\ so
Sl Sl Sl T = {s2}
Sl Sl so

18. 0 1
so so Sl T = {si)
Sl so Sl

19. X y z

so Sl S3 s4
Sl s4 Sl s4 T = [s2]
Figure 10.46 s4
Sl s4 s4
12. 0 0 S3 s4 s4 Sl
S4 s4 s4 s4

). X y
so Sl Sl
Sl S3 Sl T = {Sl,s2}
Sl Sl Sl
S3 S3 S3

21. 0 1
so *2 Sl
Sl Sl Sl T = [so,Si]
Figure 10.47
Sl Sl Sl
13. i
0
22. 0 1
so so Sl
1
Sl Sl Sl T = {Sl]
Figure 10.48 Sl Sl Sl
414 Chapter 10 Languages and Finite-State Machines

23. Let M = {S, /, F, sq, T] be a Moore machine. Suppose 25. Let M be as constructed in Exercise 24 of Section 10.3.
that if s e T and w € I*, then fw(s) e T. Prove that Show that L(M) = L(M') U L(M").
L(M) is a subsemigroup of (/*, •)» where • is catenation.
24. Let M be as constructed in Exercise 23 of Section 10.3. 26. Let M be a Moore machine such that L(M) is finite. De-
Show thatL(M) = L(M') DL(M"). scribe a Moore machine M' thataccepts /* —L(M).

10o5 Machines and Regular LciBiguciiges


Let M = (5, /, 3% so, T) be a Moore machine. In Section 10.4 we defined the
language L(M) of the machine M. It is natural to ask if there is a connection
between such a language and the languages of phrase structure grammars, dis
cussed in Section 10.1. The following theorem, due to S. Kleene, describes the
connection.

Let / be a set and let L c /*. Then L is a type 3 language; that is, L = L(G),
where G is a type 3 grammar having / as its set of terminal symbols, if and only
if L = L(M) for some Moore machine M = (S, I, F, so, T). •
We stated in Section 10.2 that a set L c /* is a type 3 language if and only if
L is a regular set, that is, if and only if L corresponds to some regular expression
over /. This leads to the following corollary of Theorem 1.

Let / be a set and let L c /*. Then L = L(M) for some Moore machine M =
(S, I, 3r, so, T) if and only if L is a regular set. •
We will not give a complete and detailed proof of Theorem 1. However, it is
easy to give a construction that produces a type 3 grammar from a given Moore
machine. This is done in such a way that the grammar and the machine have the
same language. Let M = (S, I, 3T, so, T) be a given Moore machine. We construct
a type 3 grammar G = (V, I, so, i->) as follows. Let V = I U S; that is, / will be
the set of terminal symbols for G, while 5 will be the set of nonterminal symbols.
Let St and Sj be in S, and x e I. We write st \-+ xsJ9 if fx(st) = Sj9 that is, if the
input x takes state Si to Sj. We also write si \-> x if fx (si) e T, that is, if the input
x takes the state Sj to some acceptance state. Now let h-> be the relation determined
by the preceding two conditions and take this relation as the production relation of
G.
The grammar G constructed previously has the same language as M. Suppose,
for example, that w = x 1X1X3 e I*. The string w is in L(M) if and only if
fw(so) = fx3(fx2(fx}(so))) € T. Let a = fX{(s0), b = fX2(a), and c = fX3(b),
where c = fw(so) is in T. Then the rules given for constructing h> tell us that
1. So H^ Xid
2. a h^ xib
3. b h> JC3

are all productions in G. The last one occurs because c G T. If we begin with so
and substitute, using (1), (2), and (3) in succession, we see that so =^* xix2x^ = w
(see Section 10.1), so w e L(G). A similar argument works for any string in
L(M), so L(M) c L(G). If we reverse the argument, we can see that we also
have L(G) c L(M). Thus M and G have the same language.

ixeainniple 1 Consider the Moore machine M shown in Figure 10.44. Construct a type 3 gram
mar G such that L(G) = L(M). Also, find a regular expression over / = {a, b]
that corresponds to L(M).
10.5 Machines and Regular Languages 415

Solution
Let / = {a,b}, S = {so,si,si}, and V = I U 5. We construct the grammar
(V, I, so, i->), where \-+ is described as follows:

hk so \-^ aso S2 h> bsi


so h> bsi Si i-* b
si i-* a5"i S2 \-^ a
Si h->> Z?^2 ^2 *-• 6
52 H> «^2.

The production relation h* is constructed as we indicated previously; therefore,


L(M) = L(G).
If we consult Figure 10.44, we see that a string w e L(M) has the following
properties. Any number n > 0 of a's can occur at the beginning of w. At some
point, a b must occur in order to cause the transition from so to s\. After this b,
any number k > 0 of <z's may occur, followed by another b to cause transition to
$2. The remainder of w, if any, is completely arbitrary, since the machine cannot
leave si after once entering this state. From this description we can readily see that
L(M) corresponds to the regular expression

a*ba*b(avb)*. ♦

Example 2 Consider theMoore machine whose digraph is shown in Figure 10.51. Describe in
words the language L(M). Then construct the regular expression that corresponds
to L(M) and describe the production of the corresponding grammar G in BNF
form.

Solution
0 0 It is clear that O's in the input string have no effect on the states. If aninput string
/^S i r*\ w has an odd number of l's, then fw(so) = s\. If w has an even number of l's,
(xj^~~^ then fw(so) = so. Since T= {si}, we see that L(M) consists of all win /* that
have an odd number of 1 's.
Figure 10.51 We now find the regular expression corresponding to L(M). Any input string
corresponding to the expression 0*10* will be accepted, since it will have exactly
one 1. If an input w begins in this way, but has more l's, then the additional ones
must come in pairs, with any number of O's allowed between, or after each pair
of l's. The previous sentence describes the set of strings corresponding to the
expression (10*10*)*. Thus L(M) corresponds to the regular expression
0*10*(10*10*)*.
Finally, the type 3 grammar constructed from M is G = (V, I, so, *-+) with
V = I U 5. The BNF of the relation \-> is

(so) ::= 0(s0) \ l(sx) \ 1


<*) ::=<><*!> | lfa>> 10. ♦

Occasionally, we may need to determine the function performed by a given


Moore machine, as we did in the preceding examples. More commonly, however,
it is necessary to construct a machine that will perform a given task. This task may
be defined by giving a verbal description, a regular expression, or an equivalent
type 3 grammar, perhaps in BNF or with a syntax diagram. There are system
atic, almost mechanical ways to construct such a machine. Most of these use the
concept of nondeterministic machines and employ a tedious translation process
from such machines to the Moore machines that we have discussed. If the task
416 Chapter 10 Languages and Finite-State Machines

of the machine is not too complex, we may use simple reasoning to construct the
machine in steps, usually in the form of its digraph. Whichever method is used,
the resulting machine may be quite inefficient; for example, it may have unneeded
states. In Section 10.6, we will give a procedure for constructing an equivalent
machine that may be much more efficient.

Example 3 Construct a Moore machine M that will accept exactly the string 001 from input
strings of O's and l's. In other words, / = {0,1} and L(M) = {001}.

Solution

We must begin with a starting state so. If w is an input string of O's and l's and
if w begins with a 0, then w may be accepted (depending on the remainder of its
components). Thus one step toward acceptance has been taken, and there needs to
be a state si that corresponds to this step. We therefore begin as in Figure 10.52(a).
If we next receive another 0, we have progressed one more step toward acceptance.
We therefore construct another state si and let 0 give a transition from si to si.
State si represents the condition "first symbol of input is a 0," whereas state si
represents the condition "first two symbols of the input are 00." This situation is
shown in Figure 10.52(b). Finally, if the third input symbol is a 1, we move to an
acceptance state, as shown in Figure 10.52(c). Any other beginning sequence of
input digits or any additional digits will move us to a "failure state" s4 from which
there is no escape. Thus Figure 10.52(d) shows the completed machine. ♦

(a) (b)

(§>-2_^_2_^
(c)

Figure 10.52

The process illustrated in Example 3 is difficult to describe precisely or to


generalize. We try to construct states representing each successive stage of input
complexity leading up to an acceptable string. There must also be states indicating
the ways in which a promising input pattern may be destroyed when a certain
symbol is received. If the machine is to recognize several, essentially different
types of input, then we will need to construct separate branches corresponding to
each type of input. This process may result is some redundancy, but the machine
can be simplified later.

Example 4 Let / = {0,1}. Construct a Moore machine that accepts those input sequences w
that contain the string 01 or the string 10 anywhere within them. In other words,
we are to accept exactly those strings that do not consist entirely of O's or entirely
of l's.
10.5 Machines and Regular Languages 417

Solution
This is a simple example in which, whatever input digit is received first, a string
will be accepted if and only if the other digit is eventually received. There must be
a starting state so, states si and S2 corresponding respectively to first receiving a 0
or 1, and (acceptance) states S3 and s4, which will be reached if and when the other
digit is received. Having once reached an acceptance state, the machine stays in
that state. Thus we construct the digraph of this machine as shown in Figure 10.53.

Figure 10.53
In Example 3, once an acceptance state is reached, any additional input will
cause a permanent transition to a nonaccepting state. In Example 4, once an ac
ceptance state is reached, any additional input will have no effect. Sometimes
the situation is between these two extremes. As input is received, the machine
may repeatedly enter and leave acceptance states. Consider the Moore machine M
whose digraph is shown in Figure 10.54. This machine is a slight modification of
the finite-state machine given in Example 4 of Section 10.4. We know from that
example that w e L(M) if and only if the number of l's in w is of the form 3n,
n > 0. As input symbols are received, M may enter and leave so repeatedly. The
conceptual states "one 1 has been received" and "four l's have been received" may
both be represented by s\. When constructing machines, we should keep in mind
the fact that a state, previously defined to represent one conceptual input condi
tion, may be used for a new input condition if these two conditions represent the
Figure 10.54 same degree of progress of the input stream toward acceptance. The next example
illustrates this fact.

Example 5 Construct a Moore machine that accepts exactly those input strings of x's and y's
that end in yy.

Solution
Again we need a starting state so. If the input string begins with a y, we progress
one step to a new state s\ ("last input component received is a y"). On the other
hand, if the input begins with an x, we have made no progress toward acceptance.
Thus we may suppose that M is again in state so. This situation is shown in Figure
10.55(a). If, while in state s\9 a y is received, we progress to an acceptance state
s2 ("last two symbols of input received were j's"). If instead the input received is
an x, we must again receive two y's in order to be in an acceptance state. Thus we
may again regard this as a return to state so. The situation at this point is shown
in Figure 10.55(b). Having reached state s2, an additional input of y will have no
effect, but an input of x will necessitate two more y's for acceptance. Thus we can
again regard M as being in state so. The final Moore machine is shown in Figure
10.55(c). ♦

K5) va y ^ y

(a) (b)

Figure 10.55

We have not mentioned the question of implementation of finite-state ma


chines. Indeed, many such machines, including all digital computers, are imple
mented as hardware devices, that is, as electronic circuitry. There are, however,
418 Chapter 10 Languages and Finite-State Machines

many occasions when finite-state machines are simulated in software. This is fre
quently seen in compilers and interpreters, for which Moore machines may be
programmed to retrieve and interpret words and symbols in an input string. We
provide just a hint of the techniques available by simulating the machine of Ex
ample 2 in pseudocode. The reader should refer back to Example 2 and Figure
10.51 for the details of the machine. The following subroutine gives a pseudocode
program for this machine.
This program uses a subroutine INPUT to get the next 0 or 1 in variable X
and assumes that a logical variable EOI will be set true when no further input is
available. The variable RESULT will be true if the input string contains an odd
number of l's; otherwise, it will be false.

SUBROUTINE ODDONES (RESULT)


1. EOI «- F
2. RESULT «- F
3. STATE «- 0
4. UNTIL (EOI)
a. CALL INPUT (X, EOI)
1. IF (EOI = F) THEN
a. IF (STATE = 0) THEN
1. IF (X = 1) THEN
a. RESULT «- T
b. STATE «- 1
b. ELSE
1. IF (X = 1) THEN
a. RESULT «- F
b. STATE <- 0
5. RETURN
END OF SUBROUTINE ODDONES

In this particular coding technique, a state is denoted by a variable that may


be assigned different values depending on input and whose values then determine
other effects of the input. An alternative procedure is to represent a state by a
particular location in code. This location then determines the effect of input and
the branch to a new location (subsequent state). The following subroutine shows
the same subroutine ODDONES coded in this alternative way.

SUBROUTINE ODDONES (RESULT) version 2


1. RESULT <r- F
SO: 2. CALL INPUT (X, EOI)
3. IF (EOI) THEN
a. RETURN
4. ELSE
a. IF (X = 1) THEN
1. RESULT «- T
2. GO TO Sl
b. ELSE
1. GO TO SO
10.5 Machines and Regular Languages 419

Sl: 5. CALL INPUT (X, EOI)


6. IF (EOI) THEN
a. RETURN
7. ELSE
a. IF (X = 1) THEN
1. RESULT <- F
2. GO TO SO
b. ELSE
1. GO TO Sl
END OF SUBROUTINE ODDONES version 2

It is awkward to avoid GO TO statements in this approach, and we have used


them. In languages with multiple GO TO statements, such as FORTRAN'S in
dexed GO TO or PASCAL'S CASE statement, this method may be particularly
efficient for finite-state machines with a fairly large number of states. In such
cases, the first method may become quite cumbersome.

10.5 Exercises
Let M be the Moore machine of Figure 10.56. Con
struct a type 3 grammar G = (V, /, so, \-+), such that
L(M) = L(G).

Figure 10.58
Let M be the Moore machine of Figure 10.59. Con
struct a type 3 grammar G = (V, I, so, t-+), such that
L(M) = L(G). Describe h+ in BNF.

Figure 10.59
Figure 10.56
In Exercises 6 through 20, construct the digraph of a Moore
machine that accepts the input strings described and no oth
Let M be the Moore machine of Figure 10.57. Give a reg ers.

ular expression over / = {0,1}, which corresponds to the


6. Inputs a, b: strings that end in ab
language L(M).
7. Inputs a, b: strings where the number of b's is divisible
1 by 3
-1*0 8. Inputs a, b: strings where the number of a's is even and
the number of b's is a multiple of 3

Figure 10.57 9. Inputs x, y: strings that have an even number of y's


10. Inputs 0, 1: strings that contain 0011
3. Let M be the Moore machine of Exercise 18, Section
11. Inputs 0, 1: strings that end with 0011
10.4. Give a regular expression over / = {0, 1}, which
corresponds to the language L(M). 12. Inputs •, A: strings that contain DA or AD
13. Inputs +, x: strings that contain + x x or x + +
4. Let M be the Moore machine of Figure 10.58. Con
struct a type 3 grammar G = (V, /, s0, \-+), such that 14. Inputs w, z: strings that contain wz or zzw
L(M) = L(G). Describe h+ in BNF. 15. Inputs a, b: strings that contain ab and end in bbb
420 Chapter 10 Languages and Finite-State Machines

16. Inputs +, x: strings that end in+x x Regular expressions are defined recursively in Section 1.3. Ex
17. Inputs w, z: strings that end in wz or zzw ercises 26 through 30 explore the related Moore machines. Let
I = {a,b}.
18. Inputs 0,1, 2: the string 0120
19. Inputs a, b, c: the strings aab or abc 26. Draw the digraph of a Moore machine that accepts the
empty string A.
20. Inputs jc, y, z: the strings xzx or yx or zyx
27. Draw the digraph of a Moore machine that accepts the
In Exercises 21 through 25, construct the state table ofa Moore string a.
machine that recognizes the given input strings and no others.
28. Let Ma be a Moore machine that accepts the string a in
21. Inputs 0,1: strings ending in 0101 /* and Mp, a Moore machine that accepts the string fi in
22. Inputs a, b: strings where the number of &'s is divisible /*. Describe the digraph of a Moore machine that accepts
by 4 afi.
23. Inputs x, y: strings having exactly two jc's 29. Let Ma be a Moore machine that accepts the string a in
24. Inputs a, b: strings that do not have two successive b's /* and Mp, a Moore machine that accepts the string fi in
/*. Describe the digraph of a Moore machine that accepts
25. Let M = (S, /, ¥, so, T) be a Moore machine. Define a
a v p.
relation R on S as follows: st R Sj if and only if fw(si)
and fw(Sj) either both belong to T or neither does, for 30. Let Ma be a Moore machine that accepts the string a in
every w e I*. Show that R is an equivalence relation on /*. Describe the digraph of a Moore machine that accepts
S. the string (a)*.

10.6 Simplification of Machines


As we have seen, the method in Section 10.5 for the construction of a finite-state
machine to perform a given task is as much an art as a science. Generally, graph
ical methods are first used, and states are constructed for all intermediate steps in
the process. Not surprisingly, a machine constructed in this way may not be ef
ficient, and we need to find a method for obtaining an equivalent, more efficient
machine. Fortunately, a method is available that is systematic (and can be com
puterized), and this method will take any correct machine, however redundant it
is, and produce an equivalent machine that is usually more efficient. Here we will
use the number of states as our measure of efficiency. We will demonstrate this
technique for Moore machines, but the principles extend, with small changes, to
various other types of finite-state machines. Let (S, I, !F, so, T) be a Moore ma
chine. We define a relation R on 5 as follows: For any s, t e S and w e I*, we
say that s and t are u -compatible if fw(s) and fw(t) both belong to T, or neither
does. Let s R t mean that s and t are ^-compatible for all w e I*.

THEOREM 1 Let (S, I, F, so, T) be a Moore machine, and let R be the relation defined previ
ously.
(a) R is an equivalence relation on S.
(b) R is a machine congruence (see Section 10.3).

Proof
(a) R is clearly reflexive and symmetric. Suppose now that s R t and t R u
for s, t, and u in 5, and let w e I*. Then s and t are ^-compatible, as
are t and u, so if we consider fw(s), fw(t), fw(u), it follows that either
all belong to T or all belong to T, the complement of T. Thus s and u
are w-compatible, so R is transitive, and therefore R is an equivalence
relation.
(b) We must show that if s and t are in S and x e I, then s R t implies that
fx(s) R fx(t). To show this, let w e /*, and let w' = x • w (• is the
operation of catenation). Since s R t, fw'(s) and fw'(t) are both in T or
10.6 Simplification of Machines 421

both in T. But fw,(s) = fx.w(s) = fw(fx(s)) and fw>(t) = fx.w(t) =


fw(fx(t))> so fx(s) and fx(t) are ^-compatible. Since w is arbitrary in
I*,fx(s)Rfx(t). •

Since R is a_machine congruence, we may form the quotien^Moore machine


M = (S/R, I, F, [s0]9 T/R) as in Section 10.3. The machine M is the efficient
version of M that_we have promised. We will show that M is equivalent to M,
meaning that L(M) = L(M).

Example 1 Consider the Moore machine whose digraph is shown in Figure 10.60. In this
machine / = {0, lJ^The starting state is so, and T = {si, S3}. Let us compute the
quotient machine M. First, we see that so R s\. In fact, fw(so) e T if and only
if w contains at least one 1, and fw(si) € T under precisely the same condition.
Thus so and si are w-compatible for all w e /*. Now si ft so and 53 ft so, since
fo(s2) e T, f0(s3) € T, but f0(s0) i T. This implies that {s0,s{} is one in
equivalence class. Also, si R S3, since fw(si) € T and fw(s3) e T for all w e /*.
This proves that
S/R = {{s0, si), {s2, s3}} = {[s0], [s2]}.
Also note that T/R = {fo]}- The resulting quotient Moore machine M is equiva
lent to M and its digraph is shown in Figure 10.61. ♦

v0, 1

Figure 10.60 Figure 10.61

In this case it is clear that M and M are equivalent since each accepts a word
w if and only if w has at least one 1. In general, we have the following result.

THEOREM 2 Let M = (S, I, F, s0, T) be a Moore machine, let R be the equivalence relation
defined previously, and let M = (S/R, I, F, [s0], T/R) be the corresponding quo
tient Moore machine. Then L(M) = L(M).

Proof _
Suppose that uus accepted by M so that fw(so) € T. Then fw([so]) = [fw(so)] €
T/R; that is, M also accepts wh_ _
Conversely, suppose that M accepts w so that fw([so]) = [fw(so)] is in T/R.
This means that t R fw(so) for some element t in T. By definition of R, we know
that t and fw(so) are u/-compatible for every w' e I*. When wf is A, the empty
string, then /„,/ = ls, so t = fw>(t) and fw(s0) = fw>(fw(s0)) are both in T or
both in T. Since t e T, we must have fw(so) € T, so M accepts w. •

Thus we see that after initially designingjhe Moore machine M, we may


compute R and pass to the quotient machine M = M/R, thereby obtaining an
equivalent machine that may be considerably more efficient, in the sense that it
may have many fewer states. Often the quotient machine is one that would have
been difficult to discover at the outset.
422 Chapter 10 Languages and Finite-State Machines

We now need an algorithm for computing the relation R. In Example 1 we


found R by direct analysis of input, but this example was chosen to be particularly
simple. In general, a direct analysis will be very difficult. We now define and
investigate a set of relations that provides an effective method for computing /?.
If k is a nonnegative integer, we define a relation Rk on S, the state set of
a Moore machine (S, I, !F, s0, T). If w e I*, recall that l(w) is the length of
the string w, that is, the number of symbols in w. Note that 1(A) = 0. Now, if
s and t € 5, we let s Rk t mean that s and t are ^-compatible for all w € /*
with l(w) < k. The relations Rk are not machine congruences but are successive
approximations to the desired congruence R.

THEOREM 3 (a) RM c Rk for all k > 0.


(b) Each Rk is an equivalence relation.
(c) R c Rk for all k > 0.

Proof
If s, t e S, and s and f are ^-compatible for all w e I* or for all w with Z(w) <
fc + 1, then in either case s and t are compatible for all w with Z(w) < k. This
proves parts (a) and (c). The proof of part (b) is similar to the proof of Theorem
1(a), and we omit it. •

The key result for computing the relations Rk recursively is the following
theorem.

THEOREM 4 (a) S/R0 = {T, T}, where T is the complementof T.


(b) Let k be a nonnegative integer and s,t e S. Then s Rk+i t if and only if
(1) s Rk t.
(2) fx(s)Rkfx(t)fox*\\xeL

Proof
(a) Since only A has lengthO, it follows that s Rot if and only if both s and
t are in T or both are in T. This proves that S/R0 = {T, T}.
(b) Let w e I* be such that l(w) < k + 1. Then w = x • w\ for some x e I
and for some w1 e /* with l(wf) < k. Conversely, if any x e I and
wr e I* with l(wf) < k are chosen, the resulting string w = x • u/ has
length less than or equal to k + 1.
Now /„,(*) = fx.w,(s) = fw>(fx(s)) and fw(t) = fw>(fx(t)) for
any s, t in 5. This shows that s and f are w-compatible for any w e I*
with l(w) < k + 1 if and only if fx(s) and /*(0 are, for all x e /,
u/-compatible, for any w/ with /(it/) < k. That is,.? T^+i t if and only if
fx(s)Rkfx(t)foxz\\xeI.
Now either of these equivalent conditions implies that s Rk t, since
#*+i ^ Rk, so we have proved the theorem. •

This result says that we may find the partitions Pk, corresponding to the rela
tions Rk, by the following recursive method:

Step 1 Begin with P0 = {T,T}.


Step 2 Having reached partition Pk = {Ai, A2,..., Am}, examine each equiva
lence class A( and break it into pieces where two elements s and t of A,-
fall into the same piece if all inputs x take both s and t into the same subset
Aj (depending on x).
10.6 Simplification ofMachines 423

Step 3 The new partition of S, obtained by taking all pieces of all the A/, will be
P*+i-

The final step in this method, telling us when to stop, is given by the following
result.

THEOREM 5 If Rk = Rk+\ for any nonnegative integer k, then Rk = R.

Proof
Suppose that Rk = Rk+\> Then, by Theorem 4, s Rk+it if and only if
fx(s) Rk+i fx(t) for all x e I,or (since Rk = RM) if and only if fx(s) Rk fx(t)
for all x € /. This happens if and only if s P*+i t. Thus P*+2 = Rk+\ = Rk>
By induction, it follows that Rk = Rn for all n > k. Now it is easy to see
00

that R = f)Rn, since every string w in /* must have some finite length. Since
n=0

R\ 2 Ri 2 Rk = Rk+i = • • •, the intersection of the P„'s is exactly Rk, so


R = Rk-

A procedure for reducing a given Moore machine to an equivalent machine is


as follows.

Step 1 Start with the partition P0 = {T,T}.


Step2 Construct successive partitions Pi, Pi,... corresponding to the equiva
lence relations Pi, Ri,... by using the method outlined after Theorem
4.
Step 3 Whenever Pk = JVh, stop. The resulting partition P = Pk corresponds
to the relation R.
Step 4 The resulting quotient machine is equivalent to the given Moore machine.

Example 2 Consider the machine of Example 1. Here S = {so, s\, s2,S3} and T = {s2, S3}.
We use the preceding method to compute an equivalent quotient machine. First,
P0 = {{s0, si}, {s2, S3}}. We must decompose this partition in order to find P\.
Consider first the set {so,s\ }• Input 0 takes each of these states into {50, si}. Input
1 takes both so and s\ into {s2, £3}- Thus the equivalence class {so, si} does not
decompose in passing to Pi. We also see that input 0 takes both s2 and S3 into
{s2, S3} and input 1 takes both $2 and S3 into {$2, S3}. Again, the equivalence class
{s2, S3} does not decompose in passing to Pi. This means that Pi = Po, so Po
corresponds to the congruence R. We found this result directly in Example 1. ♦

Example 3 Let M be the Moore machine shown in Figure 10.62. Find the relation R and draw
the digraph of the corresponding quotient machine M.

Solution
The partition P0 = {T, T} = {{so, S5}, {si, $2,^3,54}}. Consider first the set
{so, S5}. Input 0 carries both so and S5 into T, and input 1 carries both into T.
Thus {so, £5} does not decompose further m passing to P\. Next consider the set
T = {si,s2, S3, S4}. State si is carried to T by input 0 and to T by input 1. This
is also true for state £4, but not for s2 and S3', so the equivalence class of si in Pi
will be {si, £4}. Since states £2 and 5*3 are carried into T by inputs 0 and 1, they
will also form an equivalence class in Pi. Thus T has decomposed into the subsets
{si, s4} and {s2, s3} in passing to Pi, and Pi = {{s0, s5}, {sus4}, {s2, S3}}.
To find P2, we must examine each subset of Pi in turn. Consider {so, S5}. Input
Figure 10.62 0 takes so and s$ to {so, S5}, and input 1 takes each of them to {si, S4}. This means
424 Chapter 10 Languages and Finite-State Machines

that {so, ss} does not further decompose in passing to P2. A similar argument
shows that neither of the sets {si, 54} and {s2, S3} decomposes, so that P2 = Pi.
Hence Pi corresponds to R. The resulting quotient machine is shown in Figure
10.63. It can be shown (we omit the proof) that each of these machines will accept
a string w = bib2 • • •bn in {0,1}* if and only if w is the binary representation of a
Figure 10.63 number that is divisible by 3. ♦

10.6 Exercises

In Exercises 1 through 8, find the specified relation Rk for the


Moore machine whose digraph is given.
1. Find#o.

Figure 10.64

2. Find Ri for the Moore machine depicted by Figure 10.64.

3. Find Ri for the Moore machine depicted by Figure 10.65.

Figure 10.67
9. Find R for the machine of Exercise 1.

10. Find R for the machine of Exercise 3.

11. Find R for the machine of Exercise 6.


12. Find R for the Moore machine depicted by Figure 10.68.

Figure 10.65

4. Find R2 for the machine of Exercise 3.

5. Find #127 for the machine of Exercise 3. Figure 10.68


6. Find R\ for the Moore machine depicted by Figure 10.66. 13. Find the relation R and construct the digraph of the corre
sponding equivalent quotient machine for the Moore ma
chine whose digraph is shown in Figure 10.67.
0,1 In Exercises 14 through 17, draw the digraph of the quotient
machine M for the given machine.
14. The machine of Exercise 1

15. The machine of Exercise 3

16. The machine of Exercise 6

Figure 10.66 17. The machine of Exercise 12

In Exercises 18 through 21, find the partition corresponding to


7. Find R2 for the machine of Exercise 6. the relation R, and construct the state table ofthe correspond
ing quotient machine that is equivalent to the Moore machine
8. Find R{ for the Moore machine depicted by Figure 10.67. whose state table is shown.
Key Ideas for Review 425
18. 0 1 21. 0 1
Jo *5 s2 so S\ s4

S\ *6 Sl Sl s4 Sl
Sl so s4 T = {s2} Sl S3 Sl T = {s3}
S3 S3 ss S3 S3 Sl
S4 S6 Sl s4 S4 s4
S5 S3 so
S6 S3 Sl

19. 0 1 22. Draw the digraph of the Moore machine whose state ta
a a c ble is given in Exercise 18. Also, draw the digraph of the
b 8 d quotient machine M.
c f e sQ = a
d a d T = {d, e] 23. Draw the digraph of the Moore machine whose state ta
e a d ble is given in Exercise 19. Also, draw the digraph of the
f 8 f quotient machine M.
g 8 c
24. Draw the digraph of the Moore machine whose state ta
20. 0 1 ble is given in Exercise 20. Also, draw the digraph of the
so Sl $2 quotient machine M.
Sl Sl •*3
Sl Sl s4 T = {s5} 25. Draw the digraph of the Moore machine whose state ta
S3 Sl S3 ble is given in Exercise 21. Also, draw the digraph of the
S4 ss S4 quotient machine M.
ss ss S5
26. Describe L(M) for M in Exercise 25.

Tips for Proofs


The proof techniques of Chapter 2 are sufficient to handle all the proofs we have
presented up to this point. These techniques should be very familiar to you by
now. Direct proofs using definitions and previously proven results are usually the
first strategy to try. Example 4, Section 10.4, uses an induction proof, because
the statement to be proved is of the form P(rc), n > 0. The form of the statement
is often a clue to what proof strategy to choose. As another example, you should
recognize that phrases such as "at least two" in the theorem or statement may make
it a good candidate for a pigeonhole proof. (See Exercise 32, Section 10.1.) Even
when you have a good idea which proof technique will be useful, there is still
likely to be some trial and error involved in developing the proof. Just how to use
a definition or which previous theorem is applicable is not always obvious, but
persistence is also a powerful tool for producing a proof.

I Key Ideas for Review


• Phrase structure grammar (V, S, v0, k>): see page 388 Types 0, 1, 2, 3 phrase structure grammars: see page 392
• Production: a statement w h> w', where (w, u/) e h* Context-free grammar: type 2 grammar
• Direct derivability: see page 388 Regular grammar: type 3 grammar
• Terminal symbols: the elements of S Parsing: process of obtaining a derivation tree that will pro
• Nonterminal symbols: the elements of V —S duce a given sentence
• Derivation of a sentence: substitution process that produces BNF notation: see page 394
a valid sentence Syntax diagram: see page 396
• Language of a grammar G: set of all properly constructed Theorem: Let S be a finite set, and L c S*. Then L is a reg
sentences that can be produced from G ular set if and only if L = L(G) for some regular grammar
• Derivation tree for a sentence: see page 389 G = (V, S, v0, h>).
426 Chapter 10 Languages and Finite-State Machines

• Finite-state machine: (S, I, !F), where S is a finite set of fine T: /* -> Ss by T(w) = fw,w^ A, and T(A) = ls.
states, / is a set of inputs, and F= {fx \ x e /} Then

• State transition tables: see page 404 (a) Ifwi andu;2arein/*,then7(u;i-u;2) = T(w2)oT(wi).

• RM: si RM Sj, if there is an input jc so that fx(si) = Sj (b) If M = T(F), then M is a submonoid of Ss.
• Moore machine: M = (S, I, &, So, T), where so £ S is the • Monoid of a machine: M in the preceding theorem
starting state and T c S is the set of acceptance states • w-compatible: see page 420
• Machine congruence R on M: For any s, t e S, s R t im • Equivalent machines M and N: L(M) = L(N)
plies that fx(s) R fx(t) for all x el. • l(w): length of the string w
• Quotient of M corresponding to R: see page 406 • Language accepted by M: L(M) = {w e I* \ fw(s0) e T]
• State transition function /„,, w = x\x2 • • •xn: • Theorem: Let / be a set and L c /*. Then L is a type 3
fw = fxn OfXn_x O••• OfXl, /A = 15 language, that is, L = L(G) if and only if L = L(M) for
• Theorem: Let M = (S, I, 3^ be a finite-state machine. De some Moore machine M.

I Chapter 10 Self-Test
1. Can every phrase structure grammar be given in BNF? 11. Consider the finite-state machine whose state transition
table is
2. What types of phrase structure grammars can be repre a b
sented by a syntax diagram? so so Sl
S\ S\ Sl
3. Whatis the type of the language {0*1*, k > 1}?
Sl Sl S3
4. What does it mean for a machine to accept or recognize a S3 S3 so
language? Construct the digraph of this machine.
5. What is the connection between regular languages and 12. Describe the language accepted by the Moore machine
Moore machines? whose digraph is given in Figure 10.69.
U
6. Let G = (V, 5, v0, »->•) be a phrase structure grammar , v II /^-^\

with V = {v0, Vi,a, b, c, d}, S = {a, b, c, d}, and

i->-: vo •->• CLVob vo i-> V\ v\\-+ cv\ v\ \-> d.

Tell whether each of the following is true or false.


(a) abed e L(G)
Figure 10.69
(b) aaavibbb=>>* aaaccv\bbb
13. Consider the Moore machine M whose digraph is given
(c) ccccd e L(G) in Figure 10.70.
(d) avib^acdb a, c a, b, c

7. Describe precisely L(G), the language of G as given in


Problem 1.

8. Let G = (V, 5, i>0, h->) be a phrase structure grammar


with V = {v0, vi, 1, 2, 3,4, 5}, S = {1, 2, 3,4, 5} and

h-^: vo !->• lv\ vo h-> 3ui vo h* 5vi


Vj h* lvi Vi i-> 2vi Vj i-> 3vi
v\ h^ 4vi Vi h* 5vi vi h^ 2.

(a) Draw the syntax diagram for the productions of G.


Figure 10.70
(b) Give the BNF for the productions of G.
9. Describe the language of G as given in Problem 8. (a) Show that R = {(j0,Jo). (s\,s\), (s2,s2), (s3,s3),
(s4, s4), (s5, s5), (s6, s6), (57, s7), (sus2), (sus4),
10. Construct a phrase structure grammar G such that (si, si), (s2, s4), O4, $1), (s4, s2), (s5, s6), (s6, s5)} is
L(G) = {0n10m |n >0,m> 1}. a machine congruence.
Experiment 10 427

(b) Draw the digraph of the corresponding quotient (a) Find the smallest k such that Rk = Rk+i.
Moore machine. (b) Let R = Rk for the k found in part (a) and draw the
14. For the machine described in Problem 11, describe all digraph of M/R.
words w in {a, b}* such that fw(so) = so.
15. Construct a Moore machine that accepts a string of O's
and 1's if and only if the string has exactly two 1's.
16. Consider the Moore machine M whose digraph is given
in Figure 10.71. Define Rk, k = 0, 1,2,..., as fol
lows: s Rk t if and only if s and t are w-compatible for
all w e {0,1}* with length of w < k.
(a) Give the matrix of 7?o-
(b) List the elements of Ri.
17. Using the machine M and the definitions in Problem 16, Figure 10.71

| Experiment 10
Moore machines (Section 10.3) are examples of finite-state machines that recog
nize regular languages. Many computer languages, however, are not regular (type
3), but are context free (type 2). For example, a computer language may include
expressions using balanced parentheses (a right parenthesis for every left paren
thesis). A Moore machine has no way to keep track of how many left parentheses
have been read to determine if the same number of right parentheses have also been
read. A finite-state machine that includes a feature to do this is called a pushdown
automaton.
A pushdown automaton is a sequence (S, I, F, so, T) in which 5 is a set of
states, T is a subset of S and is the set of final states, so e S is the start state, 7 is
the input set, and F is a function from 5x/x/* to 5x/*. Roughly speaking, the
finite-state machine can create a string of elements from the input set to serve as
its memory. This string may be the empty string A. The transition function F uses
the current state, the input, and the string to determine the next state and the next
string. For example, F(s3, a, w) = (s2, wf) means that if the machineis in state S3
with current memory string w and a is read, the machine will move to state $2 with
new string wr. In actual practice there are only two ways to change the memory
string:
(1) From w to bw for some bin I', this is called pushing b on the stack.
(2) From bw to w for some bin I', this is called popping b off the stack.
A pushdownautomatonaccepts a string v if this input causes the machine to move
from so with memory string A to a final state Sj with memory string A.
1. Construct a Moore machine that will accept strings of the form 0ml\
m > 0, n > 0, and no others.
2. Explain why the Moore machine in Question 1 cannot be modified to accept
strings of the form 0n \n, n > 0, and no others.
3. Let P = (S, I, F, s0, T) with S = {s0, s{}, I = {0, 1}, T = {sx}, and

F(s0, 0, w) = (so, 0w), F(s0, 1, 0w) = (su w),


F(si, 1, Ow) = (si, w),

where w is any string in 7*. Show that P accepts strings of the form 0nl",
n > 0, and no others.
428 Chapter 10 Languages and Finite-State Machines

4. Let 7 = {a, b, c} amd w € {a, b}*. We define wR to be the string formed


by the elements of w in reverse order. For example, if w is aabab, then wR
is babaa. Design a pushdown automaton that will accept strings of the form
wcwR, and no others.
5. Let G = (V, S, so, !-•) be a phrase structure grammar with

V = {vo, w, a, b, c}, S = {a, b, c},

and
i-^: vo h> 0i>o£, fob i->- bw, abw i-> c.
(a) Describe the language L(G).
(b) Design a pushdown automaton whose language is L(G). That is, it only
accepts strings in L(G).
CHAPTER

11 Groups and Coding


Prerequisites: Chapter 9

In today's modern world of communication, data items are constantly being trans
mitted from point to point. This transmission may result from the simple task of
a computer terminal interacting with the mainframe computer 200 feet away via a
satellite that is parked in an orbit 20,000 miles from the earth, or from a telephone
call or letter to another part of the country. The basic problem in transmission of
data is that of receiving the data as sent and not receiving a distorted piece of data.
Distortion can be caused by a number of factors.
Coding theory has developed techniques for introducing redundant informa
tion in transmitted data that help in detecting, and sometimes in correcting, errors.
Some of these techniques make use of group theory.
Another entirely different problem that arises frequently in the transmission
of data is that of modifying the data being sent so that only the intended recipi
ent is able to reconstitute the original data. This problem dates back to the days
of the early Greeks. Cryptology is the discipline that studies techniques, called
cryptosystems, for the secure transmission of data. With the widespread use of
e-commerce and ATMs, cryptology has become of vital importance in today's so
ciety. We have presented many examples from cryptology in previous chapters. In
this chapter, we present a brief introduction to the important topic of public key
cryptology.

Looking Back
The American mathematician Claude E. Shannon (1916-2001), which was widely used. Today, the most widely used system is
who worked at the Bell Laboratories, published a paper in 1948 known as the DES system, a private key system.
that described a mathematical theory of communication and
thereby founded the field of information theory. Shortly there
after, Richard Hamming and his colleagues at Bell Laboratories
laid the foundations for error-correcting codes.
During the first half of the twentieth century, most of the
work in cryptology was carried out by and for the military. In
1949, Shannon published the paper "The Communication The
ory of Secrecy Systems," which broke new ground in the field
of cryptology. The field was dormant until 1975, when two re
searchers at Stanford University discovered public key cryptol
ogy, which resulted in a burst of activity in this area. In 1976,
three researchers at M.I.T. discovered a public key cryptosys-
tem, known as the RSA (Rivest, Shamir, and Adelman) system, Claude E. Shannon

429
430 Chapter 11 Groups and Coding

11.1 Coding of Binary Information and Error Detection


The basic unit of information, called a message, is a finite sequence of characters
from a finite alphabet. We shall choose as our alphabet the set B = {0,1}. Every
character or symbol that we want to transmit is now represented as a sequence of
m elements from B. That is, every character or symbol is represented in binary
form. Our basic unit of information, called a word, is a sequence of m O's and 1's.
TABLE 11.1 j The set B is a group under the binary operation + whose table is shown in
Table 11.1. (See Example 5 of Section 9.4.) If we think of B as the group Z2,
+ I 0 1 then + is merely mod 2 addition. It follows from Theorem 1 of Section 9.5 that
o 0 1 Bm = BxBx--xB(m factors) is a group under the operation © defined by
1 1 0 (xi,x2, ...,xm)®(yuy2,..., ym) = (x{ + yu x2 + y2,..., xm + ym).
This group has been introduced in Example 2 of Section 9.5. Its identity is 0 =
(0, 0,..., 0) and every element is its own inverse. An element in Bm will be
written as (bi, b2,..., bm) or more simply a.sbib2> •'bm. Observe that Bm has 2m
elements. That is, the order of the group Bm is 2m.
Figure 11.1 shows the basic process of sending a word from one point to
another point over a transmission channel. An element x e Bm is sent through the
transmission channel and is received as an element xt £ Bm. In actual practice, the
transmission channel may suffer disturbances, which are generally called noise,
due to weather interference, electrical problems, and so on, that may cause a 0 to
be received as a 1, or vice versa. This erroneous transmission of digits in a word
being sent may give rise to the situation where the word received is different from
the word that was sent; that is, x ^ xt. If an error does occur, then xt could be any
element of Bm.

Word Word
xeB™ xte£m
transmitted Transmission channel received

Figure 11.1

The basic task in the transmission of information is to reduce the likelihood of


receiving a word that differs from the word that was sent. This is done as follows.
We first choose an integer n > m and a one-to-one function e: Bm -^ Bn. The
function e is called an (m, n) encoding function, and we view it as a means of
representing every word in Bm as a word in Bn. If b e Bm, then e(b) is called
the code word representing b. The additional O's and l's can provide the means to
detect or correct errors produced in the transmission channel.
We now transmit the code words by means of a transmission channel. Then
each code word x = e(b) is received as the word xt in Bn. This situation is
illustrated in Figure 11.2.

Word beBm Encoded word Word xt e Bn


to be sent x = e{b) e Bn received
Transmission channel

Figure 11.2

Observe that we want an encoding function e to be one to one so that different


words in Bm will be assigned different code words.
11.1 Coding of Binary Information and Error Detection 431

If the transmission channel is noiseless, then xt = x for all x in Bn. In this


case x = e(b) is received for each b € Bm, and since e is a known function, b may
be identified.
In general, errors in transmission do occur. We will say that the code word
x = e(b) has been transmitted with k or fewer errors if x and xt differ in at least
1 but no more than k positions.
Let e: Bm -* Bn be an (m, n) encoding function. We say that e detects k
or fewer errors if whenever x = e(b) is transmitted with k or fewer errors, then
xt is not a code word (thus xt could not be x and therefore could not have been
correctly transmitted). For x e Bn, the number of l's in x is called the weight of
x and is denoted by |*|.

Example 1 Find theweight of each of thefollowing words in B5:


(a) x = 01000 (b) x = 11100 (c) x = 00000 (d) jc = 11111

Solution
(a) |*| = 1 (b) |x| = 3 (c) |x|=0 (d) |*|=5

Example 2 The following encoding function e: Bm -> 5m+1 is called the parity (hi, m + 1)
Parity Check Code check code: Ifb = bib2--bmeBm, define

e(b) = bib2- - 'bmbm+i,

where
10 if \b\ is even
bm+\ =
1 if |*| is odd.
Observe that bm+i is zero if and only if the number of l's in b is an even number.
It then follows that every code word e(b) has even weight. A single error in the
transmission of a code word will change the received word to a word of odd weight
and therefore can be detected. In the same way we see that any odd number of
errors can be detected.
For a concrete illustration of this encoding function, let m = 3. Then
e(000) = 0000
e(001)=0011
e(010) = 0101
e(011) = 0110
code words.
e(100) = 1001
e(101) = 1010
e(110) = 1100
e(lll) = llll

Suppose now that b = 111. Then * = e(b) = 1111. If the transmission channel
transmits * as *, = 1101, then \xt| = 3, and we know that an odd number of errors
(at least one) has occurred. ♦

It should be noted that if the received word has even weight, then we cannot
conclude that the code word was transmitted correctly, since this encoding function
does not detect an even number of errors. Despite this limitation, the parity check
code is widely used.

Example 3 Consider the following (m, 3m) encoding function e: Bm -> B3m. If
b = bib2--bmeBm,
432 Chapter 11 Groups and Coding

define
e(b) = e(bxb2 -"bm) = bxb2 • • •bmbib2 • • • bmbib2 >-bn

That is, the encoding function e repeats each word of Bm three times. For a con
crete example, let m = 3. Then

^(000) = 000000000
€(001) = 001001001
^(010) = 010010010
€(011) = 011011011
code words.
€(100) = 100100100
€(101) = 101101101
€(110) = 110110110
€(111) =111111111

Suppose now that b = Oil. Then €(011) = 011011011. Assume now that the
transmission channel makes an error in the underlined digit and that we receive
the word 011111011. This is not a code word, so we have detected the error. It is
not hard to see that any single error and any two errors can be detected. ♦

Let * and y be words in Bm. The Hamming distance S(x, y) between * and
y is the weight, |* © y |, of * © y. Thus the distance between * = xix2 • • •*m and
y = yiy2 • •*ym is the number of values of i such that */ ^ yi9 that is, the number
of positions in which * and y differ. Using the weight of * © y is a convenient way
to count the number of different positions.

Example 4 Findthe distance between * andy:


(a) * = 110110, y = 000101
(b) * = 001100, y = 010110

Solution
(a) x®y = 110011, so |* ©y | =4
(b) * © y = 011010, so |* © y\ = 3 ♦

THEOREM 1 Let *, y, and z be elements of Bm. Then


Properties of the (a) S(x,y) = S(y,x)
Distance Function (b) S(x,y)>0
(c) S(x, y) = 0 if and only if * = y
(d) S(x,y)<8(x,z) + S(z,y)

Proof
Properties (a), (b), and (c) are simple to prove and are left as exercises.

(d) For a and 6 in £m,


\a®b\< \a\ + \b\,
since at any position where a and b differ one of them must contain a 1.
Also, if a € Bm, then a © a = 0, the identity element in Bm. Then

S(x, y) = |* © y\ = |* © 0 © y\ = |* © z © z © y\
<\x®z\ + \z®y\
= 8(x,z) + 8(z,y). M
11.1 Coding of Binary Information and Error Detection 433

The minimum distance of an encoding function e: Bm -> Bn is the mini


mum of the distances between all distinct pairs of code words; that is,

min{8(e(x),e(y)) \x,y eBm}.

Example 5 Consider thefollowing (2,5) encoding function e:


€(00) = 00000
€(10) = 00111
code words.
€(01) = 01110
€(11) = 11111

The minimum distance is 2, as can be checked by computing the minimum of the


distances between all six distinct pairs of code words. ♦

THEOREM 2 An (m,n) encoding function e: Bm -> Bn can detect k or fewer errors if and only
if its minimum distance is at least k + l.

Proof
Suppose that the minimum distance between any two code words is at least k + l.
Let b e Bm, and let * = e(b) e Bn be the code word representing b. Then * is
transmitted and is received as *,. If xt were a code word different from *, then
8(x, xt) > k + 1, so * would be transmitted with k + 1 or more errors. Thus, if*
is transmitted with k or fewer errors, then *, cannot be a code word. This means
that € can detect k or fewer errors.
Conversely, suppose that the minimum distance between code words is r < k,
and let* and y be code words with 8(x, y) = r. If xt = y, that is, if* is transmitted
and is mistakenly received as y, then r < k errors have been committed and have
not been detected. Thus it is not true that e can detect k or fewer errors. •

Example 6 Consider the (3, 8) encoding function e: B3 -> fi8 defined by


e(000) = 00000000
€(001) = 10111000
€(010) = 00101101
€(011) = 10010101
code words.
€(100) = 10100100
€(101) = 10001001
€(110) = 00011100
€(111) = 00110001

How many errors will e detect?

Solution
The minimum distance of € is 3, as can be checked by computing the minimum of
the distances between all 28 distinct pairs of code words. By Theorem 2, the code
will detect k or fewer errors if and only if its minimum distance is at least k + l.
Since the minimum distance is 3, we have 3>k + lork<2. Thus the code will
detect two or fewer errors. ♦

Group Codes
So far, we have not made use of the fact that (Bn, ffi) is a group. We shall now
consider an encoding function that makes use of this property of Bn.
434 Chapter 11 Groups and Coding
An (m, n) encoding function e: Bm -• Bn is called a group code if

e(Bm) = {e(b) \ b e Bm} = Rm(e)

is a subgroup of Bn.
Recall from the definition of subgroup given in Section 9.4 that N is a sub
group of Bn if (a) the identity of Bn is in N, (b) if * and y belong to N, then
* © y € N, and (c) if * is in N, then its inverse is in N. Property (c) need not be
checked here, since every element in Bn is its own inverse. Moreover, since Bn is
Abelian, every subgroup of Bn is a normal subgroup.

Example 7 Consider the (3, 6) encoding function e: B3 -> B6 defined by


€(000) = 000000
€(001) = 001100
€(010) = 010011
€(011) =011111
code words.
€(100) = 100101
€(101) = 101001
€(110) = 110110
€(111) =111010

Show that this encoding function is a group code.

Solution
We must show that the set of all code words

N = {000000,001100,010011,011111,100101,101001,110110,111010}

is a subgroup of B6. This isdone by first noting that the identity of B6 belongs to
N. Next we verify, by trying all possibilities, that if * and y are elements in N,
then * ©y is in N. Hence N is a subgroup of B6, and thegiven encoding function
is a group code. ♦

The strategy of the next proof is similar to the way we often show two sets A
and B are the same by showing that A c. B and B c. A. Here we show that 8 = rj
by proving 8 < rj and rj < 8.

THEOREM 3 Let e: Bm -> Bn be a group code. The minimum distance of e is the minimum
weight of a nonzero code word.

Proof
Let 8 be the minimum distance of the group code, and suppose that 8 = 8(x, y),
where * and y are distinct code words. Also, let rj be the minimum weight of a
nonzero code word and suppose that rj = \z\ for a code word z. Since € is a group
code, * © y is a nonzero code word. Thus

8 = 8(x,y) = \x®y\ >rj.

On the other hand, since 0 and z are distinct code words,

y) = \z\ = \z®0\ = 8(z,0)>8.

Hence rj = 8. •

One advantageof a group code is given in the following example.


11.1 Coding of Binary Information and Error Detection 435

Example 8 The minimum distance of the group code in Example 7 is 2, since by Theorem
3 this distance is equal to the smallest number of 1's in any of the seven nonzero
code words. To check this directly would require 28 different calculations. ♦

We shall now take a brief look at a procedure for generating group codes.
First, we need several additional results on Boolean matrices. Consider the set B
with operation + defined in Table 11.1. Now let D = [ dy ] and E = [ €/7 ] be
m x n Boolean matrices. We define the mod-2 sum D © E as the m x n Boolean
matrix F = [///], where
fa = d{j + eij, 1 < i < m, 1 < j < n. (Here + is addition in B.)
Example 9 We have
i o i r 1 1 0 l~j [1 + 1 0+1 1+0 1+ 1
0 110 e 110 1 = 0+1 1+ 1 1+0 0+1
10 0 1 0 1 1 lj [_l+0 0+1 0+1 1+1
0 110^
10 11
1110

Observe that if F = D © E, then fy is zero when both du and ey are zero or both
are one. ♦

TABLE 11.2 : Next, consider the set B = {0,1} with the binary operation given in Table
11.2. This operation has been seen earlier in a different setting and with a different
• 0 1 symbol. In Chapter6 it was shown that B is the unique Boolean algebra with two
0 0 0 elements. In particular, J? is a lattice with partial order < defined by 0 < 0, 0 < 1,
0 1
1 < 1. Then the reader may easily check that if a and b are any two elements of
i
B,
a • b = a Ab (the greatest lower bound of a and b).
Thus Table 11.2 for • is just a copy of the table for A.
Let D= [dij ] be an mx p Boolean matrix, and let E = [ el3 ] be a p x n
Boolean matrix. We define the mod-2 Boolean product D * E as the m x n matrix
F= [ fu ]> where
fij =di{ >e\j +di2-e2j + + dip
iP • *pj,
€ I < i < m, 1 < j < n.
This type of multiplication is illustrated in Figure 11.3. Compare this with similar
figures in Section 1.5.

Example 10 We have
"l 0"
+ 1-1+0 0+1-1+0
* 1
0
1
1 -[i:i + 1-1 + 1 0+1-1 + 1

-[?i
The proof of the following theorem is left as an exercise.

THEOREM 4 Let D and E be m x p Boolean matrices, and let F be a p x n Boolean matrix.


Then
(D © E) * F = (D * F) © (E * F).
That is, a distributiveproperty holds for © and *. •
436 Chapter 11 Groups and Coding

—1

011 an •• a\p

a2\ a22 •• "2p bn ^12 ' '•• b\n ^l„


»v -11 c12

b2\ Z?22 • ••• ^2*


** c21 c22 c2n
4

«/l ai2 . .. <*ip -

*P1 bpl ** pn

am\ «m2 •" amp

' ' ' '

Ail
If an odd number of

0/2 ^2i corresponding pairs consists


of two l's, thenctj = 1,
and if an even number
consists of two l's, then
ai P *rf Cij = 0.

Figure 11.3

We shall now consider the element x = xix2 • • •xn e Bn as the 1 x n matrix


[xi x2 ••• xn\

THEOREM 5 Letmandn be nonnegative integers with m <n,r = n —m, andlet H be an n x r


Boolean matrix. Then the function fH: Bn -> Br defined by

/W(x)=x*H, xgB"

is a homomorphismfrom the group Bn to the group Br.

Proof
If x and y are elements in Bn, then

/tf(*©30 = (*©)0*H
= (x * H) © (y * H) by Theorem 4
= /*(*) ©ywoo.

Hence /# is a homomorphism from #" to Br. •

Corollary 1 Letm, n, r, H, and fH beasinTheorem 5. Then

N = {xeBn \x*H = 0}

is a normal subgroup of J971.

Proof
It follows from the resultsin Section9.5 that N is the kernel of the homomorphism
fa, so it is a normal subgroup of Bn. •
11.1 Coding of Binary Information and Error Detection 437

Let m < n and r = n — m. An n x r Boolean matrix

hu hX2 • •• hXr
h2i h22 •- h2r

hmi hm2 •- hmr


H =
1 0 • •• 0

0 1 •• 0
n — m = r rows

0 0 1

whose last r rows form the r x r identity matrix, is called a parity check matrix.
We use H to define an encoding function eH: Bm -> Bn. If b = bib2 • • •bm, let
x = eji(b) = bib2 - - •bmxix2 • • •xr, where

xi = bx - hu + b2 • h2i H h bm • AOTi
a:2 = Z?i • /in + &2 • ^22 H \-bm' hm2
(1)

Xr = 6l • hXr + b2 • h2r H h *m *A/nr.

THEOREM 6 Let x = yiy2 •••ymx\ -xr e Bn. Then x * H = 0 if and only if x = eH(b) for
some fee J5m.

Proof
Suppose that x * H = 0. Then

y\ -An +^2 -^21 + + ym - hm\ + x\ = 0


y\ -h\2 + y2 -h22 + + ym - hm2 + x2 = 0

y\ ' hlr + y2 ' h2r H h ym • ^mr + *r = 0.

The first equation is of the form

a + xi =0, where a = yi • hn + y2 • h2X -\ \-ym • hm\.

Adding a to both sides, we obtain

a + (a + xi) = a + 0 = a
(a + a) + xi = a
0 + xi = a since a + a = 0
xi = a.

This can be done for each row; therefore,

xi = y\ • hu + y2-h2i-\ h ym • ^m/, 1 < i < r.

Letting fei = yx, b2 = y2, •••, bm = ym, we see that xi, x2,..., xr satisfy the
equations in (1). Thus b = b{b2 • ••fem e Bm and x = eH(b).
438 Chapter 11 Groups and Coding

Conversely, if x = €#(&), the equations in (1) can be rewritten by adding x/


to both sides of the /th equation, / = 1, 2,..., n, as
bi • hu + b2 -h2i + h bm • hmi + xx = 0
bi • hX2 + b2 • h22 + • • • + bm • hm2 + x2 = 0

6i • Air + b2 • /*2r + • - • + bm • hmr + xr = 0,

which shows x * H = 0. •

Corollary 2 €H(Bm) = {€//(&) | b e Bm} is a subgroup of £".

The result follows from the observation that

eH(Bm) = ktr(fH)
and from Corollary 1. Thus €# is a group code.

Example 11 Letm = 2, n = 5, and


1 1 o-
0 1 1
H = 1 0 0
0 1 0
0 0 1

Determine the group code€#: B2 -> B5.


Solution
We have B2 = {00,10,01,11}. Then
e(00) = 00xix2x3,

where x\, x2, and X3 are determined by the equations in (1). Thus
xi = x2 = X3 = 0

and
€(00) = 00000.
Next
€(10) = 10xiX2X3.
Using the equations in (1) with bi = 1 and b2 = 0, we obtain
xi = 1.1+0-0=1
x2 = 1 • 1 + 0 - 1 = 1
x3 = 1 • 0 + 0 - 1 = 0.

Thus xi = 1, x2 = 1, and X3 = 0, so

€(10) = 10110.
Similarly (verify),
€(01) = 01011
€(11) = 11101.
11.1 Coding of Binary Information and Error Detection 439

11.1 Exercises
In Exercises 1 and 2, find the weight of the given words. 15. Prove Theorem 1(c).

1. (a) 1011 (b) 0110 (c) 1110 16. Find the minimum distance of the (2,4) encoding func
tion e.
2. (a) 011101 (b) 11111 (c) 010101
3. Consider the (3,4) parity check code. For each of the re e(00) = 0000 ^(10) =0110
ceived words, determine whether an error will be e(0\) = 1011 e(\l) = 1100
detected.

(a) 0100 (b) 1100 17. Find the minimum distance of the (3, 8) encoding func
tion e.
4. Consider the (3,4) parity check code. For each of the re
ceived words, determine whether an error will be
e(000) = 00000000 ^(100) = 01100101
detected.
^(001) =01110010 e(101) = 10110000
(a) 0010 (b) 1001
e(010) = 10011100 e(110) = 11110000
5. Consider the (6,7) parity check code. For each of the re
ceived words, determine whether an error will be ^(011) = 01110001 £?(111) = 00001111
detected.
18. Consider the (2, 6) encoding function e.
(a) 1101010 (b) 1010011
(c) 0011111 (d) 1001101 e(00) = 000000 e(10) = 101010

In Exercises 6 through 8, use the (m, 3m) encodingfunction of ^(01) =011110 e(ll) = 111000
Example 3 for the given value ofm. For each of the received
(a) Find the minimum distance of e.
words, determine whether an error will be detected.
(b) How many errors will e detect?
6. m = 3
19. Consider the (3, 9) encoding function e.
(a) 110111110 (b) 110011011
7. m = 4 e(000) = 000000000 e(100) = 010011010
(a) 011010011111 (b) 110110010110 ^(001) = 011100101 e(101) = 111101011
8. m = 4 e(010) = 010101000 e(110) = 001011000
(a) 010010110010 (b) 001001111001 e(011) = 110010001 <?(111) = 110000111
9. The ISBN system is also an error-detecting code. In Exer
(a) Find the minimum distance of e.
cise 51 of Section 5.2, it is shown that one error in trans
mission will be detected, but two may not be. Show, how (b) How many errors will e detect?
ever, that any transposition of adjacent digits before the 20. Show that the (2, 5) encoding function e: B2 B5
check digit will be detected. defined by
10. Twelve-digit bar codes use the twelfth digit as a check
digit by choosing it so that the sum of the digits in even- e(00) = 00000 e(\0) = 10101
numbered positions and three times the sum of the dig ^(01) = 01110 e(U) = 11011
its in odd-numbered positions is congruent to 0 mod 10.
Show that this code will detect a single error in an even- is a group code.
numbered position but may not detect two errors in even- 21. Show that the (3,7) encoding function e: B3 B1
numbered positions. defined by
11. Explain how |jc 0 y| counts the number of positions in
which jc and y differ. 6?(000) = 0000000 e(100) = 1000101

12. Find the distance between x and y. e(001) =0010110 <?(101) = 1010011
(a) x = 1100010, y = 1010001 e(010) = 0101000 <?(110) = 1101101

(b) x = 0100110, y = 0110010 ^(011) = 0111110 e{\\\) = 1111011

13. Find the distance between x and y. is a group code.


(a) x = 00111001, y = 10101001 22. Find the minimum distance of the group code defined in
(b) x = 11010010, y = 00100111 Exercise 20.
14. (a) Prove Theorem 1(a). 23. Find the minimum distance of the group code defined in
(b) Prove Theorem 1(b). Exercise 21.
440 Chapter 11 Groups and Coding

24. Compute 29. Which of the following properties does the structure
(n x n Boolean matrices, *) have?

[o i iJe[o 1 lj (a) Associative (1 [>) Commutative


(c) Identity (d) Inverses
25. Compute
30. Let
-0 11"
-10 1" "10 1
0 1 1
1 1 0 0 1 0
© H = 1 0 0
0 1 0 1 1 1
0 1 0
_0 1 1. _0 0 1
.0 0 1.
26. Compute be a parity check matrix. Determine the (2, 5) group code
"1 0" function eH: B2 -> B5.
1
0
1
1 [i : ?]• 31. Let
1 0 0
27. Compute 0 1 1
1 1 1
10 1" 1 1 0 H =
1 0 0
0 1 1 * 0 1 1
0 1 0
1 0 1 1 0 1
0 0 1

28. Which of the following properties does the structure be a parity check matrix. Determine the (3,6) group code
(m x n Boolean matrices, 0) have? eH: B3 -• B6.
(a) Associative (b) Commutative 32. Prove Theorem 4.
(c) Identity (d) Inverses 33. Outline the structure of the proof given for Theorem 2.

11.2 Decoding and Error Correction


Consider an (m,n) encoding function e: Bm -> Bn. Once the encoded word
x = e(b) e Bn,forb e Bm, is received as the word xt, we are faced with the
problemof identifying the wordb that was the originalmessage.
An onto function d: Bn -> Bm is called an (n, m) decoding function associ
ated with e ifd(xt) =b' e Bm is such that when the transmission channel has no
noise, then V = b, that is,
d o e = 1sm,
where lBm is the identity function on Bm. The decoding function d is required to
be onto so that every received word can be decoded to give a word in Bm. It de
codes properly received words correctly, but the decoding of improperly received
words may or may not be correct.

Example 1 Consider the parity check code that is defined in Example 2 of Section 11.1. We
now define the decoding function d: Bm+l -> Bm. If y = y{y2- •-ymym+i
€ flm+1,then
d(y) = yiy2--ym-
Observe that ifb = bib2--bmeBm, then
(doe)(b)=d(e(b)) = b,
sod o e = lflm.
For a concrete example, let m = 4. Then we obtain d (10010) = 1001 and
rf(HOOl) = 1100. ♦

Let e be an (m,n) encodingfunction and let d be an (n, m) decoding function


associated with e. We say that the pair (e, d) corrects k or fewer errors if when
ever x = e(b) is transmitted correctly or with k or fewer errors and xt is received,
then d{xt) = b. Thus xt is decoded as the correct message b.
11.2 Decoding and Error Correction 441

Example 2 Consider the (m,3m) encoding function defined inExample 3 ofSection 11.1. We
now define the decoding function d: B3m -• Bm. Let
y = y\y2 • • • ymym+\ • • • y2my2m+\ • • • yim-

Then
d(y) =ZlZ2'"Zm,
where
II if {yt, yi+m, y/+2m} has at least two 1's
0 if {yi, yi+m, yi+2m} has less than two 1's.
That is, the decoding function d examines the i th digit in each of the three blocks
transmitted. The digit that occurs at least twice in these three blocks is chosen as
the decoded ith digit. For a concrete example, let m = 3. Then

e(100) = 100100100
*(011) = 011011011
^(001) = 001001001.

Suppose now that b = Oil. Then e(011) = 011011011. Assume now that the
transmission channel makes an error in the underlined digit and that we receive
the word xt = 011111011. Then, since the first digits in two out of the three
blocks are 0, the first digit is decoded as 0. Similarly, the second digit is decoded
as 1, since all three second digits in the three blocks are 1. Finally, the third digit
is also decoded as 1, for the analogous reason. Hence d(xt) = 011; that is, the
decoded word is 011, which is the word that was sent. Therefore, the single error
has been corrected. A similar analysis shows that if e is this (m, 3m) code for any
value of m and d is as defined, then (e, d) corrects any single error. ♦

Given an (m, n) encoding function e: Bm -> #", we often need to determine


an (n, m) decoding function d: Bn -> Bm associated with e. We now discuss a
method, called the maximum likelihood technique, for determining a decoding
function d for a given e.
Since Bm has 2m elements, there are 2m code words in Bn. We first list the
code words in a fixed order:

xw,x^\...,x^n\
If the received word is xt, we compute 8(x^\xt) for I < i < 2m and choose the
first code word, say it is x^s\ suchthat
min {8(x{i),xt)} = 8(x{s\xt).
\<i<2m

That is, x^s) is a codewordthat is closestto xt and the firstin the list. If xis) = e(b),
we define the maximum likelihood decoding function d associated with e by

d(xt) = b.

Observe that d depends on the particular order in which the code words in e(Bn)
are listed. If the code words are listed in a different order, we may obtain a different
maximum likelihood decoding function d associated with e.

THEOREM 1 Suppose that e is an (m, n) encoding function and d is a maximum likelihood


decoding function associated with e. Then (e, d) can correct k or fewer errors if
and only if the minimum distance of e is at least 2k + 1.
442 Chapter 11 Groups and Coding
Proof
Assume that the minimum distance of e is at least 2k + 1. Let b e Bm and
x = e(b) € Bn. Suppose that x is transmitted with k or fewer errors, and xt is
received. This means that 8(x, xt) < k. If z is any other code word, then

2k + 1 <8(x,z) <8(x,xt) + 8(xt,z) <k + d(xt,z).


Thus 8(xt, z) >2k+l —k = k + l. This means that x is the unique code word
that is closest to xt, so d(xt) = b. Hence (e, d) corrects k or fewer errors.
Conversely, assume that the minimum distance between code words is r < 2k,
and let x = e(b) and xf = e(b') be code words with 8(x, xr) = r. Suppose that
x' precedes x in the list of code words used to define d. Write x = bib2 • • •bn,
x' = b\bf2 •••b'n. Then bt ^ fej for exactly r integers / between 1 and n. Assume,
for simplicity, that bi ^ b\,b2 ^ b'2, ..., br ^ b'r, but bi = fy when i > r. Any
other case is handled in the same way.

(a) Suppose that r < k. If x is transmitted as xt = x', then r <k errors have
been committed, but d(xt) = b'\ so (e, d) has not corrected the r errors.
(b) Suppose that k + 1 < r < 2k, and let
y = b\bf2--'brkbk+i--bn.
If x is transmitted as xt = y, then 5(jcr, x') = r —k < k and 8(xt, x) > k.
Thus xf is at least as close to xt as x is, and jc7 precedes x in the list of code
words; so d(xt) ^ b. Then we have committed k errors, which (e, d) has
not corrected. •

Example 3 Let e be the (3, 8) encoding function defined in Example 6 of Section 11.1, and
let d be an (8, 3) maximum likelihood decoding function associated with e. How
many errors can (e, d) correct?

Solution
Since the minimum distance of e is 3, we have 3>2fc + l, sofc<l. Thus (e, d)
can correct one error. ♦

We now discuss a simple and effective technique for determining a maximum


likelihood decoding function associated with a given group code. First, we prove
the following result.

THEOREM 2 If AT is a finite subgroup of a group G, then every leftcoset of K in G has exactly


as many elements as K.

Proof
Let a K be a left coset of AT in G, where a € G. Consider the function
/: if -> a K defined by

f(k) = ak, forkeK.

We show that / is one to one and onto.


To show that / is one to one, we assume that

f(ki) = f(k2), kuk2eK.

Then
aki = ak2.
By Theorem 2 of Section 9.4, k\ = k2. Hence / is one to one.
11.2 Decoding and Error Correction 443

To show that / is onto, let b be an arbitrary element in aK. Then b = ak for


some k e K. We now have
f(k) = ak = b,

so / is onto. Since / is one to one and onto, K and aK have the same number of
elements. •

Let e\ Bm -> Bn be an (m, n) encoding function that is a group code. Thus


the set N of code words in Bn is a subgroup of Bn whose order is 2m, say N =
{x^,x^,...,x^}.
Suppose that the code word x = e(b) is transmitted and that the word xt is
received. The left coset of xt is

Xt®N = {€i,€2, ...,€2m},

where€,- = xtffix(/). The distance fromxt to code wordjc(/) is just |e,-|, the weight
of €/. Thus, if €j is a coset member with smallest weight, then xij) must bea code
word that is closest toxt. Inthis case, x(y) = 0®x^j)=xt®xt® x{j) = xt ©€j.
An element€j, having smallest weight, is called a coset leader. Note that a coset
leader need not be unique.
If e: Bm -> Bn is a group code, we now state the following procedure for
obtaining a maximum likelihood decoding function associated with e.
Step 1 Determine all the left cosets of N = e(Bm) in Bn.
Step 2 For each coset, find a coset leader (a word of least weight). Steps 1 and
2 can be carried out in a systematic tabular manner that will be described
later.
Step 3 If the word xt is received, determine the coset of N to which xt belongs.
Since N is a normal subgroup of Bn, it follows from Theorems 3 and 4 of
Section 9.5 that the cosets of N form a partition of Bn, so each element
of Bn belongs to one and only one coset of N in Bn. Moreover, there are
2n/2m or 2r distinct cosets of N inBn.
Step 4 Let € be a coset leader for the coset determined in Step 3. Compute x =
xt © e. If x = e(b), we let d(xt) = b. That is, we decode xt as b.
To implementthe foregoing procedure,we must keep a complete list of all the
cosets of N in Bn, usually in tabular form, with each row of the table containing
one coset. We identify a coset leader in each row. Then, when a word xt is re
ceived, we locate the row that contains it, find the coset leader for that row, and
add it to xt. This gives us the code word closest to xt. We can eliminate the need
for these additions if we construct a more systematic table.
Before illustrating with an example, we make several observations. Let

N = {x^,x^,...,x^m)},
wherex(1) is 0, the identity of Bn.
Steps 1 and 2 in the preceding decoding algorithm are carried out as follows.
First, list all the elements of AT in a row, starting with the identity 0 at the left.
Thus we have
0 x™ *(3) ... *(2m).
This row is the coset [0], and it has 0 as its coset leader. For this reason we will
also refer to 0 as €i. Now choose any word y in Bn that has not been listed in the
first row. List the elements of the coset y © N as the second row. This coset also
444 Chapter 11 Groups and Coding
has 2m elements. Thus we have the two rows
,(2) ,0) A2>»)
0
y©0 y © x{Z) y®xr(3) r(2w)

In the coset y © N, pick an element of least weight, a coset leader, which we denote
by e(2). In case of ties, choose any element of least weight. Recall from Section
9.5 that, since e(2) e y © AT, we have y © N = e(2) © N. This means that every
word in the second row can be written as e(2) © v, v e N. Now rewrite the second
row as follows:

,(2) M) r(2) AT) ©JC (3) .(2) ©JC (2m)

with €(2) in the leftmost position.


Next, choose another element z in Bn that has not yet been listed in either of
the first two rows and form the third row (z © x^), 1 < j < 2m (anothercoset of
N in Bn). This row can be rewritten in the form
<r(3) 6(3) 0 x(2) e(3) ^ XQ) . . . ^(3) ^ x(2m)^

where e(3) is a coset leader for the row.


Continue this process until all elements of Bn have been listed. The resulting
Table 11.3 is called a decoding table. Notice that it contains 2r rows, one for each
coset of N. If we receive the word xt, we locate it in the table. If x is the element
of N that is at the top of the column containing xt, then x is the code word closest
to xt. Thus, if x = e(b), we let d(xt) = b.

^^^^^^^^^^^^^^WW^Mf^l
TAB

3 x® X® ...
X(2™-1)
;6(2) e&®xW e<2>©*<3> 6(2)ejr(2-»-l)

6(2r) e(2r>0*<2> e<2r>©*<3> eor)@xV-\)

Example 4 Consider the (3,6) group code defined in Example 7 of Section 11.1. Here
N = {000000,001100,010011,011111,100101, 101001,110110,111010}
(1) ^.(2)
= {x(i>,x ,*(8)}
as defined in Example 1. We now implement the decoding procedure for e as
follows.

Steps 1 and 2: Determine all the left cosets of Af in B6, as rows of a table. For
each row /, locate the coset leader et, and rewrite the row in the order

e(, 6/ ©001100, €i ©010011, 6/ ©111010.

The result is shown in Table 11.4.

Steps 3 and 4: If we receive the word 000101, we decode it by first locating it


in the decoding table; it appears in the fifth column, where it is underlined. The
word at the top of the fifth column is 100101. Since e(100) = 100101, we decode
000101 as 100. Similarly, if we receive the word 010101, we first locate it in the
third column of the decoding table, where it is underlined twice. The word at the
top of the third column is 010011. Since e(010) = 010011, we decode 010101 as
010.
11.2 Decoding and Error Correction 445

MsMm ;i-5ISfc|
000000 001100 010011 011111 100101 101001 110110 111010
000001 001101 010010 011110 100100 101000 110111 111011
000010 001110 010001 011101 100111 101011 110100 111000
000100 001000 010111 011011 100001 101101 110010 111110
010000 011100 000011 001111 110101 111001 100110 101010
100000 101100 110011 111111 000101 001001 010110 011010
000110 001010 010101 011001 100011 101111 110000 111100
010100 011000 000111 001011 110001 111101 100010 101110

We make the following observations for this example. In determining the


decoding table in Steps 1 and 2, there was more than one candidate for coset leader
of the last two cosets. In row 7 we chose 00110 as coset leader. If we had chosen
001010 instead, row 7 would have appeared in the rearranged form

001010 001010 ©001100 001010© 111010

or

001010 000110 011001 010101 101111 100011 111100 110000.

The new decoding table is shown in Table 11.5.

$3Mtk IllB \ '•' - "'. , ; ' '- fi'

000000 001100 010011 011111 100101 101001 110110 111010


000001 001101 010010 011110 100100 101000 110111 111011
000010 001110 010001 011101 100111 101011 110100 111000
000100 001000 010111 011011 100001 101101 110010 111110
010000 011100 000011 001111 110101 111001 100110 101010
100000 101100 110011 111111 000101 001001 010110 011010
001010 000110 011001 010101 101111 100011 111100 110000
010100 011000 000111 001011 110001 111101 100010 101110

Now, if we receive the word 010101, we first locate it in the fourth column of
Table 11.5. The word at the top of the fourth column is 011111. Since e(011) =
011111, we decode 010101 as 011. ♦

Suppose that the (m, n) group code is eH: Bm -> Bn, where H is a given
parity check matrix. In this case, the decoding technique above can be simplified.
We now turn to a discussion of this situation.
Recall from Section 11.1 that r = n - m,

hu h\2
h2\ h22 h2r

hm\ hm2 Jlmr


H =
1 0 o
0 1 o
446 Chapter 11 Groups and Coding
and the function fH: Bn -> Br defined by
fH(x) = x*H
is a homomorphism from the group Bn to the group Br.

THEOREM 3 If m, n, r, H, and fH are as defined, then fH is onto.

Proof
Let b = bib2" -brbt any element in Br. Letting
x = 00--'0b{b2--br
m O's

we obtain x * H = b. Thus ///(jc) = b, so fn is onto. •

It follows from Corollary 1 of Section 9.5 that Br and Bn/N are isomorphic,
where N = ker(/#) = eu(Bm), under the isomorphism g: Bn/N -> Br defined
by
g(xN) = fH(x)=x*n.
The element jc * H is called the syndrome of jc. We now have the following
result.

THEOREM 4 Let x and y be elements in Bn. Then x and y lie in the same left coset of N in Bn
if and only if fH (x) = fu (y), that is, if and only if they have the same syndrome.

Proof
It follows from Theorem 4 of Section 9.5 that x and y lie in the same left coset of
AT in Bn if and only if x © y = (-x) © y e N. Since AT = ker(fH), x © y € N if
and only if
fH(x®y) = 0Br
fH(x)®fH(y)=0Br
Mx) = fH(y). m

In this case, the decoding procedure given previously can be modified as fol
lows. Suppose that we compute the syndrome of each coset leader. If the word xt
is received, we also compute fn(xt), the syndrome of xt. By comparing ///(jc,)
and the syndromes of the coset leaders, we find the coset in which xt lies. Suppose
that a coset leader of this coset is 6. We now compute jc = xt © e. If jc = e(b), we
then decode xt as b. Thus we need only the coset leaders and their syndromes in
order to decode. We state the new procedure in detail.
Step 1 Determine all left cosets of N = eH(Bm) in Bn.
Step 2 For each coset, find a coset leader, and compute the syndrome of each
leader.
Step 3 If jc/ is received, compute the syndrome of jc, and find the coset leader e
having the same syndrome. Then jc, © e = jc is a code word eH(b), and
d(xt) = b.
For this procedure, we do not need to keep a table of cosets, and we can avoid
the work of computing a decoding table. Simply list all cosets once, in any order,
and select a coset leader from each coset. Then keep a table of these coset leaders
and their syndromes. The foregoing procedure is easily implemented with such a
table.
11.2 Decoding and Error Correction 447

Example 5 Consider theparity check matrix


1 1 0
1 0 1
0 1 1
H =
1 0 0
0 1 0
0 0 1

and the (3, 6) group eH: B3 -> B6. Then


e(000) = 000000
e(001) = 001011
e(010) = 010101
^(011) = 011110
code words.
^(100) = 100110
e(101) = 101101
^(110) = 110011
e(lll) = 111000
Syndrome Thus
of Coset Coset
Leader Leader N = {000000,001011,010101,011110, 100110,101101, 110011,111000}.

000 000000 We now implement the decoding procedure as follows.


001 000001 In Table 11.6 we give only the coset leaders together with their syndromes.
010 000010 Suppose now that we receive the word 001110. We compute the syndrome of
jc, = 001110, obtaining ///(jc,) = jc, * H = 101, which is the sixth entry in the
011 001000
first column of Table 11.6. This means that jc, lies in the coset whose leader is
100 000100
e = 010000. We compute
101 010000
110 100000 jc=jc, @e = 001110 ©010000 = 011110.
111 001100 Since e(011) = 011110, we decode 001110 as 011. ♦

11.2 Exercises
1. Let d be the (4, 3) decoding function defined by letting m AT = {0000, 1011,0110, 1101}. Place the coset leader at
be 3 in Example 1. Determine d(y) for the wordy in B4. the beginning of each row.
(a) )> = 0110 (b) y = 1011 6. Let e be the (2, 5) encoding function defined in Exercise
2. Let d be the (6, 5) decoding function defined by letting m 20 of Section 11.1. Construct a table of left cosets in B4
be 5 in Example 1. Determine d(y) for theword y'mB6. for N = e(B2). Place the coset leader at the beginningof
each row.
(a) y = 001101 (b) y = 110100
3. Let d be the (6, 2) decoding function defined in Ex In Exercises 7 through12, let e be the indicated encodingfunc
ample 2. Determine d(y) for the wordy'mB6. tion and let d be an associated maximum likelihood decoding
(a) y = 111011 (b) y = 010100
function. Determine the number of errors that (e, d) will cor
rect.
4. Let d be the (9, 3) decoding function defined in the same
way as the decoding function in Example 2. Determine 7. e is the encoding function in Exercise 16 of Section 11.1
d(y) for the word y'mB9. 8. e is the encoding function in Exercise 17 of Section 11.1
(a) y = 101111101 (b) y= 100111100
9. e is the encoding function in Exercise 18 of Section 11.1
5. Let e: B2 -* B4 be the (2,4) encoding function de
10. e is the encoding function in Exercise 19 of Section 11.1
fined by <?(00) = 0000, e(01) = 1011, e(10) = 0110,
e(ll) = 1101. Construct a table of left cosets in B4 for 11. e is the encoding function in Exercise 20 of Section 11.1
448 Chapter 11 Groups and Coding
12. e is the encoding function in Exercise 21 of Section 11.1. 0 11
1 1"
1 0 1
13. Consider the group code defined in Exercise 20 of Sec 1 0
20. H = 21. H = 1 0 0
tion 11.1 Decode the following words relative to a maxi 1 0
0 1 0
mum likelihood decoding function. 0 1_
0 0 1
(a) 11110 (b) 10011 (c) 10100
1 0 0
14, Consider the (2,4) group encoding function e\ B2 -> B4 1 1 0
defined by 0 1 1
22. H =
1 0 0
e(00) = 0000 e(\0) = 1001 0 1 0
e(01) = 0111 e(l\) = 1111. 0 0 1

Decode the following words relative to a maximum like In Exercises 23 through 25, compute the syndromefor each
lihood decoding function. coset leader found in the specified exercise.

(a) 0011 (b) 1011 (c) 1111 23. Exercise 20 24. Exercise 21

15. Consider the (3, 5) group encoding function e: B3 -> B5 25. Exercise 22
defined by 26. Let
-1 1"
e(000) = 00000 e(100) = 10011 1 0
H
^(001) = 00110 e(101) = 10101 1 0
_0 1_
e(010) = 01001 e(110) = 11010
^(011) = 01111 e(lll) = 11100. be a parity check matrix. Decode the following words rel
ative to a maximum likelihood decoding function.
Decode the following words relative to a maximum like (a) 0101 (b) 1010 (c) 1101
lihood decoding function. 27. Let
(a) 11001 (b) 01010 (c) 00111 "0 1 1-
1 0 1
16. Considerthe (3, 6) group encoding function e: B3 -> B6
H = 1 0 0
defined by
0 1 0

e(000) = 000000 e(100) = 100101 _0 0 1_

^(001) = 000110 ^(101) = 100011 be a parity check matrix. Decode the following words
relative to a maximum likelihood decoding function asso
e(010) = 010010 <?(110) = 110111
ciated with eH.
^(011) = 010100 <?(111) = noooi.
(a) 10100 (b) 01101 (c) 11011
Decode the following words relative to a maximum like 28. Let
lihood decoding function. 1 0 0"
1 1 0
(a) 011110 (b) 101011 (c) 110010
0 1 1
H =
17. Let G be a group and H a subgroup of G. 1 0 0
(a) Prove that if g\ and g2 are elements of G, then either 0 1 0
gxH = g2H or giH H g2H = { }. 0 0 1.
(b) Use the result of part (a) to show that the left cosets be a parity check matrix. Decode the following words
of H form a partition of G. relative to a maximum likelihood decoding function asso
ciated with eH.
18. Let e: Bm -> Bn be a group encoding function.
(a) 011001 (b) 101011 (c) 111010
(a) How many code words are there in Bnl
29. Let e be the (2, 5) encoding function defined in Exercise
(b) Let N = e(Bm). What is \N\1
20 of Section 11.1 and d an associated maximum likeli
(c) How many distinct left cosets of N are there in Bnl hood decoding function.
19. Let e be as in Exercise 18. Give conditions on m and n so (a) Give an example that verifies that (e, d) corrects one
that coset leaders are of weight less than or equal to 1. error.

In Exercises 20 through 22, determine the coset leaders for (b) Give an example that verifies that (e, d) does not al
N = eH(Bm)for the given parity check matrix H. ways correct two errors.
11.3 Public Key Cryptology 449

11.3 Public Key Cryptology


In 1978, Ronald Rivest, Adi Shamir, and Leonard Adelman published "A Method
for Obtaining Digital Signatures and Public Key Cryptosystems." In this paper,
the authors describe a method of sending coded messages using a pair of publicly
available integers. This method is widely called the RSA public key cryptosys-
tem. We begin with a result on congruences that extends Fermat's Little Theorem
(Theorem 3(b) of Section 9.6).

THEOREM 1 Suppose that p andq are distinct primes and k is any integer. Then
(a) For any integer a with GCD(a, pq) = I,
ak{p-\){q-\) ^ j (m0(j pq) (1)

(b) For any integer a,


fl*(P-i)fa-i)+isfl (mod/??) (2)

Proof
(a) If GCD(a, pq) = 1, then a is not divisible by p or q; it is relatively prime
to both. Thus by Fermat's Little Theorem, Theorem 3(b), Section 9.6, we
have ap~x = 1 (mod p), and so
ak{p-\){q-\) ^ Xk{q-\) = j (mod p)

Similarly, ak(p~l)iq~l) = 1 (mod q). Thus there exist integers r and s


with
ak(p-l)(q-{) = l+rp=l+sq.
It follows that rp = sq, and since q is not divisible by p, s must be, say,
s = pt. Then
ak(p-\){q-\) = l+pqt

and

ak(p-\)(q-l) ^ j (moj pq)

(b) If a is relatively prime to pq, the result follows from (1) by multiplying
both sides by a. If not, then a is divisible by either p or q or both. If a is
divisible by pq, then both sides of (2) are congruent to 0 mod pq and are
therefore congruent to each other. In the remaining case, a is divisible by
exactly one of the integers p or q, and without loss of generality, we may
suppose that it is p. Then a = bps, with s > 1 and b relatively prime to
pq. We note for later reference that b must satisfy (2).
Since p is relatively prime to q, we can show as in the proof of part
(a) that for some integer r, ^(p-Dte-D = \+rq. Multiplying by p then
shows that
pk{p-l)(q-l)+l ^ p (mod pq^

and therefore

(pj)*(P-i)(*-D+i = (pkiP-i)ig-i)+iy s ps (mod pq)m


We see that both b and ps satisfy (2), and therefore so does their product
a. •
450 Chapter 11 Groups and Coding
Example 1 Let p = 5 and q = 13. Since 28 is relatively prime to 5 : 13 = 65 and
48 = 4 x 12 = (5 - 1) x (13 - 1), 2848 = 1 (mod 65).

Example 2 Compute the remainder of7293 after division by65.


Solution
We use Theorem 1(a), with p = 5 and q = 13, so that 65 = pq.

293 = (48x6)+ 5,

and since 7 is relatively prime to 65,


7293 748x6
1™ = (74T xT5 =
_ n5
T (mod 65).

But 73 = 343 = 18 (mod 65) and therefore


75 = 18 x 49 = 882 = 37 (mod 65).
The remainder of 7293 afterdivision by 65 is 37. ♦
We now construct a system in which we can make public a method of encoding
messages to us (called a public key), but nevertheless be relatively sure that only
we can decode these messages. Theorem 1 will play a major role in this effort. As
a first step, we note that any message can be turned into a string of integers using
a variety of methods. One way is to use the letters of the alphabet to represent
a number base 26. Let A, B, ..., Z stand for the integers 0, 1, ..., 25. Then
any pair of letters af} can be regarded as the base 26 representation of the number
(26a) + p. In this way numbers in the range 0 to 675 can be used in place of
any two-letter pair, and any message, when divided into two-letter pairs, can be
represented by a sequence of integers in this range.

Example 3 Consider the message ACT FIRST. Separate the letters into pairs, and replace
each pair with the number it represents in base 26. The pairs AC, TF, IR, and
ST become, respectively, the integers 2, 499, 225, and 487. If a message has an
odd number of letters, we can add an agreed upon filler letter, say X, at the end.
A variation of this method would be to replace triples of letters by the base 26
numberthey represent. Then we woulduse numbers in the range 0 to 25 x 262 +
25 x 26 + 25 = 17575. ♦

We now describe a method of encoding messages. Select two primes, p and


q, and let m = pq and n — (p — l)(q — 1). Now choose any integer s that
is relatively prime to n. We "publish" the integers m and s (that is, make them
publicly available) and instruct anyone wishing to send us a secret message to
proceed as follows: Divide the message into letter pairs a/3 and represent each
pair as a number x = (26a) + fi in the range 0 to 675. Then replace each
of these numbers x by the unique integer y between 0 and m — 1 for which
y = xs (mod m), and send us the resulting number sequence. For this procedure
to produce unique results, m must be at least 675.

Decoding
Since s is chosen to be relatively prime to n, s, the remainder class of s mod n, has
a multiplicative inverse t in the ring Z„. (See Section 9.6.) Thus for some integer t
we have st = 1 (mod n) or st = 1 + k(p —l)(q- 1) for some integer k. We can
find t by using the Euclidean algorithm, as illustrated in Example 4 of Section 9.6.
11.3 Public Key Cryptology 451
If we receive the integer y = xs (mod m), we compute / (mod m) and apply
Theorem 1. Since m = pq, Theorem 1(a) guarantees that
/ = xst = jci+'Cp-Dfo-D = x (mod m).
Since x does not exceed m, we have yt (mod m) = x, so we have recovered the
original integer x. We do this to all received integers, and thus decode the message.

Example 4 Letp = 19and q = 37. Since m = pq = 703 > 675, wecanusetheRSA method
to encode messages in groups of two letters. Here n = 18 • 36 = 648. Choose
s = 25, which is relatively prime to 648. Now we publish the integers 703 and 25
as our public key. If someone wants to send us the message GO, she first computes
6 x 26 + 14 = 170 and then 17025 (mod 703). Note that 1702 = 28900 =
77 (mod 703). So

1704 = 772 = 305 (mod 703)


1708 = 3052 = 229 (mod 703)
17016 = 2292 = 419 (mod 703)
It follows that

17025 = 170161708170 = 419 •229 • 170 = 16311670 = 664 (mod 703),


so she sends 664.
To decode the message, we first find t. Using the Euclidean algorithm, we
compute

648 = 25 x 25 + 23
25 = 1 x 23 + 2
23 = 11 x2+l.

Thus

1 = 23 - 11 • 2 = 23 - 11(25 - 23) = 12-23 — 11-25


= 12(648 - 25 • 25) - 11 • 25 = 12 • 648 - 311 • 25.

Thus / = -311 = 337 (mod 648).


Now we compute 664337 (mod 703). A series of computations such as those
used previously to find 664shows that664337 = 170 (mod 703). Since 6 x 26 +
14 = 170, we can then recover the original message GO. ♦

Security
In the discussion of Bacon's code (Section 1.4), we noted that this method of
coding is vulnerable to an attack based on an analysis of the frequency with which
letters appear in ordinary language. By encoding pairs or triples of letters as we
do with the public key method of this section, an attack by frequency analysis is
much more difficult. But there are also other methods of attack on a public key
cryptosystem.
In order to decode the message, someone must know t, which means that he
must know n. This in turn requires him to know p and q. Thus the problem is
to factor a number m, known to be the product of two primes. In Section 1.4, we
showed that we can find the prime factors of m by trial and error if we divide n by
all primes less than +Jm. In Example 4, m = 703, and the square root of 703 is
less than 27. Thus we need only divide by 2, 3, 5, 7, 11, 13, 17,19, and 23, at most
452 Chapter 11 Groups and Coding
9 divisions, to find the prime factors. In practice, one chooses p and q to have
something like 100 digits, that is, to be of the order of magnitude 10100, so that
m is about 10200. A famous theorem about prime numbers, called appropriately
the Prime Number Theorem, states that the number of primes less than or equal to
m
an integer m is approximately , and this approximation gets better as m gets
ln(ra)
larger. Thus, the number of primes less than *Jm = 10100 is about
100 100 100
10 10 10 »97
> 10
ln(10100) 1001n(10) 230
Presently, the fastest known computer has a speed of about 36,000 gigaflops a
second. With this computer it would take about 1083 seconds, or about 1066 billion
years to do the required number of divisions. A similar enormous number of the
world's largest hard drives would be required to just store these prime divisors, if
we even knew what they all were.
The difficulty of factoring extremely large numbers provides some level of
security, but even so, messages can be decoded if additional information leaks out.
For example, the factorization can be found if n = (p —l)(q —l) becomes known.
This follows from the fact that p and q are roots of the quadratic equation

0 = (x - p)(x - q) = x2 - (p + q)x + pq = x2 - (p + q)x + m.


On the other hand,

n = (p- l)(q - 1) = pq - (p + q) + I = m - (p + q) + I,

so

(p + q) = m - n + 1.
We cantherefore find p andq by solving the equation 0 = x2+ (n—m—l)x + m.
Methods of coding for efficiency, for error detection and correction, or for se
curity are an active area of mathematical research. In this book we have presented
only some of the basic ideas and procedures.

11.3 Exercises

1. Verify that 12704 = 1 (mod 391). In Exercises 10 through 12, use the RSA method, pairs of let
2. Verify that 10577 = 10 (mod 221). ters, and the public key m = 779, s = 49.

In Exercises 3 through 6, compute the remainder when ak is 10. Encode the message STOP.
divided by cfor the given values.
11. Encode the message NO.
3. a = 9, k = 199, c = 221
12. Encode the message EXIT.
4. a = 17,*= 1123, c= 1189
5. a = 23, k = 3750, c = 3869 In Exercises 13 through 15, use the RSA method, triples of let
ters, and the public key m = 19781, s = 19.
6. a = \2,k= 1540, c= 1649
7. Let/7 = 23 andq =41. 13. Encode the message RUN.

(a) Compute m = pq and n = (p — \){q — 1). 14. Encode the message YES.
(b) Let s = 41. Find t such that st = 1 (mod n).
15. Encode the message END.
8. Using m and s from Exercise 7 and pairs of letters, apply
the RSA method to encode the message BEAR. 16. The public key m = 779, s = 49 has been published.
9. Using m and s from Exercise 7 and pairs of letters, apply Suppose you discover that n for this cryptosystem is 720.
the RSA method to decode the message 371, 640. Find p and q.
Key Ideas for Review 453
17. The public key m = 19781, s = 19 has been pub 19. Use the information from Exercise 17 to decode the mes
lished. Suppose you discover that n for this cryptosystem sage 14032.
is 19500. Find p and q.
18. Use the information from Exercise 16 to decode the mes
sage 142, 525.

Tips for Proofs


The proofs in this chapter rely heavily on earlier results. Many of the concepts
developed throughout the book are applied here to the problems of coding and
decoding. In Section 11.1, we pointed out the similarity of proving two numbers
equal to proving two sets are the same. Analogous proofs could be developed for
any relation that has the antisymmetric property such as "is less than" and "is a
subset of."
In Section 11.2, Theorem 2 we use a one-to-one, onto function to "match"
the elements of two sets in order to show that they have the same number of ele
ments. This is also a technique that can be used in solving counting problems if
the cardinality of one of the sets used is known.

I Key Ideas for Review


• Message: finite sequence of characters from a finite alpha Mod-2 Boolean product of Boolean matrices D and E, D*E:
bet see page 435
• Word: sequence of O's and 1's Theorem: Let m and n be nonnegative integers with m < n,
r = n —m, and let H be an n xr Boolean matrix. Then the
• (m, n) encoding function: one-to-one function
function fH: Bn -+ Br defined by
e: Bm -+ Bn,m <n
• Code word: element in Ran(e) /„(jt)=x*H, xeB"
• Weight of jc, |jc|: number of l's in x
is a homomorphism from the group Bn to the group Br.
• Parity check code: see page 431 Group code eH corresponding to parity check matrix H: see
• Hamming distance between x and y, 8(x, y): \x © y| page 437
• Theorem (Properties of the Distance Function): Let x, y, (n, m) decoding function: see page 440
and z be elements of Bm. Then Maximum likelihood decoding function associated with e:
see page 441
(a) 8(x,y) = 8(y,x).
Theorem: Suppose that e is an (m, n) encoding function
(b) 8(x,y)>0.
and d is a maximum likelihood decoding function associ
(c) 8(x, y) = 0 if and only if jc = y. ated with e. Then (e, d) can correct k or fewer errors if and
(d) 8(x,y)<8(x,z) + 8(z,y). only if the minimum distance is at least 2k + 1.
• Minimum distance of an (m, n) encoding function: min
Decoding procedure for a group code: see page 443
imum of the distances between all distinct pairs of code Decoding procedure for a group code given by a parity
words check matrix: see page 446
• Theorem: An (m,n) encoding function e: Bm —• Bn can RSA public key cryptosystem: see page 450
detect k or fewer errors if and only if its minimum distance Theorem: Suppose that p and q are distinct primes and k is
is at least k + 1. any integer. Then
• Group code: (m,n) encoding function e. Bm -» Bn such (a) For any integer a with GCD(a, pq) = 1,
that e(Bm) = {e(b) \ b € Bm} is a subgroup of Bn
ak{p-\){q-\) ^ ! (mod pq)
• Theorem: The minimum distance of a group code is the
minimum weight of a nonzero code word. (b) For any integer a,
• Mod-2 sum of Boolean matrices D and E, D 0 E: see page
fl*(p-l)fo-I)+l ^ a (mod pqy
435
454 Chapter 11 Groups and Coding
Chapter 11 Self-Test
1. What is the relationship between the minimum distance How many errors will e detect?
of an (m, n) encoding function and the number of errors
it can detect? 8. Show that the (3, 5) encoding function in Problem 7 is a
2. Why is it important that the left cosets of e(Bm) form a group code.
partition of Bnl
9. Let e be the encoding function defined in Problem 7
3. What is the maximum likelihood referred to in the name
and let d be an associated maximum likelihood decoding
of the decoding functions in this chapter? function. Determine the number of errors that (e, d) will
4. What are three general reasons for encoding a message? correct.

5. Consider the (3,4) parity check code. For each of the


received words, determine whether an error will be de
tected.

(a) 1101 (b) 1010 (c) 1111 (d) 0011


10. Let
6. Consider the (m, 3m) encoding function with m = 4. For
-1 1-
each of the received words, determine whether an error
0 1
will be detected. H =
1 0
(a) 001100100011 (b) 110111001101 _0 1.
(c) 010111010011
be a parity check matrix. Decode 0110 relative to a max
7. Let e be the (3, 5) encoding function defined by
imum likelihood decoding function associated with eH.
e(000) = 00000 e(100) = 0101°
e(001) = 11110 e(101) = 10100 11. Compute the remainder when581226 is dividedby 91.
^(010) = 01101 ^(110) = 00111
12. Use the RSA method, pairs of letters, and the public key
e(011) = 10011 e(U\) = 11001. m = 91, s = 25 to encode the message LAST.
Appendix A
Algorithms and Pseudocode
Algorithms
An algorithm is a complete list of the steps necessary to perform a task or compu
tation. The steps in an algorithm may be general descriptions, leaving much detail
to be filled in, or they may be totally precise descriptions of every detail.

Example 1 A recipe for baking a cake can be viewed as an algorithm. It might be written as
follows.

1. ADD MILK TO CAKE MIX.


2. ADD EGG TO CAKE MIX AND MILK.
3. BEAT MIXTURE FOR 2 MINUTES.
4. POUR MIXTURE INTO PAN AND COOK IN OVEN FOR 40
MINUTES AT 350° F. •

The preceding algorithm is fairly general and assumes that the user under
stands how to pour milk, break an egg, set controls on an oven, and perform a host
of other unspecified actions. If these steps were all included, the algorithm would
be much more detailed, but long and unwieldy. One possible solution, if the added
detail is necessary, is to group collections of related steps into other algorithms that
we call subroutines and simply refer to these subroutines at appropriate points in
the main algorithm. We hasten to point out that we are using the term "subroutine"
in the general sense of an algorithm whose primary purpose is to form part of a
more general algorithm. We do not give the term the precise meaning that it would
have in a computer programming language. Subroutines are given names, and
when an algorithm wishes the steps in a subroutine to be performed, it signifies
this by calling the subroutine. We will specify this by a statement CALL NAME,
where NAME is the name of the subroutine. ♦

Example 2 Consider thefollowing version ofExample 1,which uses subroutines to adddetail.


Let us title this algorithm BAKECAKE.

Algorithm BAKECAKE
1. CALL ADDMILK.
2. CALL ADDEGG.
3. CALL BEAT(2).
4. CALL COOK(OVEN, 40, 350). •

The subroutines of this example will give the details of each step. For exam
ple, subroutine ADDEGG might consist of the following general steps.

455
456 Appendix A Algorithms and Pseudocode
SUBROUTINE ADDEGG
1. Remove egg from carton.
2. Break egg on edge of bowl.
3. Drop egg, without shell, into bowl.
4. RETURN
END OF SUBROUTINE ADDEGG

Of course, these steps could be broken into substeps, which themselves could
be implemented as subroutines. The purpose of Step 4, the "return" statement, is
to signify that one should continue with the original algorithm that "called" the
subroutine. ♦

Our primary concern is with algorithms to implement mathematical computa


tions, investigate mathematical questions, manipulate strings or sequences of sym
bols and numbers, move data from place to place in arrays, and so on. Sometimes
the algorithms will be of a general nature, suitable for human use, and sometimes
they will be stated in a formal, detailed way suitable for programming in a com
puter language. Later in this appendix we will describe a reasonable language for
stating algorithms.
It often happens that a test is performed at some point in an algorithm, and
the result of this test determines which of two sets of steps will be performed
next. Such a test and the resulting decision to begin performing a certain set of
instructions will be called a branch.

Example 3 Consider the following algorithm for deciding whether to study for a "discrete
structures" test.

Algorithm FLIP
1. Toss a coin.
2. IF the result is "heads," GOTO 5.
3. Study for test.
4. GOTO 6.
5. See a show.
6. Take test next day. •

Note that the branching is accomplished by GO TO statements, which direct


the user to the next instruction to be performed, in case it is not the next instruction
in sequence. In the past, especially for algorithms written in computer program
ming languages such as FORTRAN, the GO TO statement was universally used
to describe branches. Since then there have been many advances in the art of al
gorithm and computer program design. Out of this experience has come the view
that the indiscriminate use of GO TO statements to branch from one instruction to
any other instruction leads to algorithms (and computer programs) that are diffi
cult to understand, hard to modify, and prone to error. Also, recent techniques for
actually proving that an algorithm or program does what it is supposed to do will
not work in the presence of unrestricted GO TO statements.
In light of the foregoing remarks, it is a widely held view that algorithms
should be structured. This term refers to a variety of restrictions on branching,
which help to overcome difficulties posed by the GO TO statement. In a structured
branch, the test condition follows an IF statement. When the test is true, the in
structions following a THEN statement are performed. Otherwise, the instructions
following an ELSE statement are performed.
Algorithms 457

Example 4 Consider again the algorithm FLIP described in Example 3. The following is a
structured version of FLIP.

Algorithm FLIP
1. Toss a coin.
2. IF (heads) THEN
a. Study for test.
3. ELSE
a. See a show.
4. Take test next day. •

This algorithm is easy to read and is formulated without GO TO statements.


In fact, it does not require numbering or lettering of the steps, but we keep these to
set off and emphasize the instructions. Of course, the algorithm FLIP of Example
3 is not very different from that of Example 4. The point is that the GO TO
statement has the potential for abuse, which is eliminated in the structured form.

Another commonly encountered situation that calls for a branch is the loop,
in which a set of instructions is repeatedly followed either for a definite number of
times or until some condition is encountered. In structured algorithms, a loop may
be formulated as shown in the following example.

Example 5 Thefollowing algorithm describes theprocess of mailing 50 invitations.

Algorithm INVITATIONS
1. COUNT «- 50
2. WHILE (COUNT > 0)
a. Address envelope.
b. Insert invitation in envelope.
c. Place stamp on envelope.
d. COUNT ^- COUNT - 1
3. Place envelopes in mailbox. •

In this algorithm, the variable COUNT is first assigned the value 50. The
symbol «— may be read "is assigned." The loop is handled by the WHILE state
ment. The condition COUNT > 0 is checked, and as long as it is true, statements
a through d are performed. When COUNT = 0 (after 50 steps), the looping stops.

Later in this appendix we will give the details of this and other methods of
looping, which are generally considered to be structured. In structured algorithms,
the only deviations permitted from a normal, sequential execution of steps are
those given by loops or iterations and those resulting from the use of the IF-
THEN-ELSE construction. Use of the latter construction for branching is called
selection.
In this book we will need to describe numerous algorithms, many of which
are highly technical. Descriptions of these algorithms in ordinary English may be
feasible, and in many cases we will give such descriptions. However, it is often
easier to get an overview of an algorithm if it is presented in a concise, symbolic
form. Some authors use diagrammatic representations called flow charts for this
purpose. Figure A.l shows a flow chart for the algorithm given in Example 4.
458 Appendix A Algorithms and Pseudocode
These diagrams have a certain appeal and are still used in the computer program
ming field, but many believe that they are undesirable since they are more in accord
with older programming practice than with structured programming ideas.

( BEGIN "*)

( STOP )
Figure A.l

The other alternative is to express algorithms in a way that resembles a com


puter programming language or to use an actual programming language such as
PASCAL. We choose to use a pseudocode language rather than an actual pro
gramming language, and the earlier examples of this section provide a hint as
to the structure of this pseudocode form. There are several reasons for making
this choice. First, knowledge of a programming language is not necessary for the
understanding of the contents of this book. The fine details of a programming
language are necessary for communication with a computer, but may serve only
to obscure the description of an algorithm. Moreover, we feel that the algorithms
should be expressed in such a way that an easy translation to any desired computer
programming language is possible. Pseudocode is very simple to learn and easy
to use, and it in no way interferes with one's learning of an actual programming
language.
The second reason for using pseudocode is the fact that many professional
programmers believe that developing and maintaining pseudocode versions of a
program, before and after translation to an actual programming language, encour
age good programming practice and aid in developing and modifying programs.
We feel that the student should see a pseudocode in use for this reason. The
pseudocode described is largely taken from Rader (Advanced Software Design
Techniques, Petrocelli, New York, 1968) and has seen service in a practical pro
gramming environment. We have made certain cosmetic changes in the interest of
pedagogy.
Pseudocode 459

One warning is in order. An algorithm written in pseudocode may, if it is


finely detailed, be very reminiscent of a computer program. This is deliberate,
even to the use of terms like SUBROUTINE and the statement RETURN at the
end of a subroutine to signify that we should return to the steps of the main algo
rithm. Also, the actual programming of algorithms is facilitated by the similarity
of pseudocode to a programming language. However, always remember that a
pseudocode algorithm is not a computer program. It is meant for humans, not ma
chines, and we are only obliged to include sufficient detail to make the algorithm
clear to human readers.

Pseudocode

In pseudocode, successive steps are usually labeled with consecutive numbers. If


a step begins a selection or a loop, several succeeding steps may be considered
subordinate to this step (for example, the body of a loop). Subordinate lines are
indented several spaces and labeled with consecutive letters instead of numbers.
If these steps had subordinates, they in turn would be indented and labeled with
numbers. We use only consecutive numbers or letters as labels, and we alternate
them in succeeding levels of subordination. A typical structuring of steps with
subordinate steps is illustrated in the following.

1. line 1
a. line 2
b. line 3
1. line 4
2. line 5
c. line 6
2. line 7
3. line 8
a. line 9
1. line 10
b. line 11
4. line 12

Steps that have the same degree of indentation will be said to be at the same
level. Thus the next line at the level of line 1 is line 7, while the next line at the
level of line 3 is line 6, and so on.
Selection in pseudocode is expressed with the form IF-THEN-ELSE, as fol
lows:

1. IF (CONDITION) THEN
true-block

ELSE

false-block

The true- and false-blocks (to be executed respectively when CONDITION is


true and CONDITION is false) may contain any legitimate pseudocode including
selections or iterations. Sometimes we will omit statement 2, the ELSE statement,
and the false-block. In this case, the true-block is executed only when CONDI
TION is true and then, whether CONDITION is true or false, control passes to the
next statement that is at the same level as statement 1.

Example 6 Consider the following statements in pseudocode. Assume that X is a rational


number.
460 Appendix A Algorithms and Pseudocode

1. IF (X > 13,000) THEN


a. Y <- X + 0.02(X - 13,000)
2. ELSE
a. Y <r- X + 0.03X

In statement 1, CONDITION is: X > 13,000. If X is greater than 13,000,


then Y is computed by the formula

X + 0.02(X-13,000),

while if X < 13,000, then Y is computed by the formula

X + 0.03X. ♦

We will use the ordinary symbols of mathematics to express algebraic rela


tionships and conditions in pseudocode. The symbols +, —, x, and / will be used
for the basic arithmetic operations, and the symbols <,>,<,>,=, and ^ will be
used for testing conditions. The number X raised to the power Y will be denoted
by Xy, the square of a number A will be denoted by A2, and so on. Moreover,
products such as 3 x A will be denoted by 3A, and so on, when no confusion is
possible.
We will use a left arrow, «-, rather than the equal sign, for assignments of
values to variables. Thus, as in Example 6, the expression Y «<— X + 0.03X
means that Y is assigned the value specified by the right-hand side. The use of =
for this purpose conflicts with the use of this symbol for testing conditions. Thus
X = X + 1 could either be an assignment or a question about the number X. The
use of <- avoids this problem.
A fundamental way to express iteration expressions in pseudocode is the
WHILE form:

1. WHILE (CONDITION)
repeat-block

Here CONDITION is tested and, if true, the block of pseudocode following


it is executed. This process is repeated until CONDITION becomes false, after
which control passes to the next statement that is at the same level as statement 1.

Example 7 Consider the following algorithm in pseudocode; N is assumed to be a positive


integer.

1. X <- 0
2. Y <r- 0
3. WHILE (X < AQ
a. X <- X + 1
b. Y <- Y + X
4. Y <- Y/2

In this algorithm, CONDITION is X < N. As long as CONDITION is true,


that is, as long as X < N, statements a and b will be executed repeatedly. As soon
as CONDITION is false, that is, as soon as X = N9 statement 4 will be executed.
This means that the WHILE loop is executed N times and the algorithm computes
1+2 + ... + W

which is the value of variable Y at the completion of the algorithm.


Pseudocode 461

A simple modification of the WHILE form called the UNTIL form is useful
and we include it, although it could be replaced by completely equivalent state
ments using WHILE. This construction is

1. UNTIL (CONDITION)

repeat-block

Here the loop continues to be executed until the condition is true; that is, continues
only as long as the condition is false. Also, CONDITION is tested after the repeat-
block rather than before, so the block must be repeated at least once.

Example 8 The algorithm given inExample 7 could also be written with anUNTIL statement
as follows:

1. X <- 0
2. Y <- 0
3. UNTIL (X > AQ
a. X 4- X + 1
b. Y <r- Y + X
4. Y <r- Y/2

In this algorithm, the CONDITION X > N is tested at the completion of


Step 3. If it is false, the body of Step 3 is repeated. This process continues until
the test reveals that CONDITION is true (when X = N). At that time Step 4 is
immediately executed. ♦

The UNTIL form of iteration is a convenience and could be formulated with


a WHILE statement. The form

1. UNTIL (CONDITION)

block 1

is actually equivalent to the form

1. block 1

2. WHILE (CONDITION = FALSE)


block 1

In each case, the instructions in block 1 are followed once, regardless of CON
DITION. After this, CONDITION is checked, and, if it is true, the process stops;
otherwise, block 1 instructions are followed again. This procedure of checking
CONDITION and then repeating instructions in block 1 if CONDITION is false is
continued until CONDITION is true. Since both forms produce the same results,
they are equivalent.
The other form of iteration is the one most like a traditional DO loop, and we
express it as a FOR statement:

1. FOR VAR = X THRU Y [BY Z]


repeat-block

In this form, VAR is an integer variable used to count the number of times the
instructions in repeat-block have been followed. X, Y, and Z, if desired, are either
integers or expressions whose computed values are integers. The variable VAR
begins at X and increases Z units at a time (Z is 1 if not specified). After each
increase in X, the repeat-block is executed as long as the new value of X is not
462 Appendix A Algorithms and Pseudocode
greater than Y. The conditions on VAR, specified by X, Y, and Z, are checked
before each repetition of the instructionsin the block. The block is repeated only if
those conditions are true. The brackets around BY Z are not part of the statement,
but simply mean that this part is optional and may be omitted. Note that the repeat-
block is always executed at least once, since no check is made until X is changed.

Example 9 Thepseudocode statement


FOR VAR = 2 THRU 10 BY 3

will cause the repeat-block to be executed three times, corresponding to VAR = 2,


5, 8. The process ends then, since the next value of VAR would be 11, which is
greater than 10. ♦

We will use lines of pseudocode by themselves to illustrate different parts of


a computation. However, when the code represents a complete thought, we may
choose to designate it as an algorithm, a subroutine, or a function.
A set of instructions that will primarily be used at various places by other
algorithms is often designated as a subroutine. A subroutine is given a name for
reference, a list of input variables, which it will receive from other algorithms, and
output variables, which it will pass on to the algorithms that use it. A typical title
of a subroutine is

SUBROUTINE NAME (A, B, ; x, y, ...)

The values of the input variables are assumed to be supplied to the subroutine
when it is used. Here NAME is a name generally chosen as a memory aid for the
task performed by the subroutine; A, B, and so on, are input variables; and X, Y,
and so on, are output variables. The semicolon is used to separate input variables
from output variables.
A subroutine will end with the statement RETURN. As we remarked earlier
in this section, this simply reminds us to return to the algorithm (if any) that is
using the subroutine.
An algorithm uses a subroutine by including the statement
CALL NAME (A, B, ...; X, Y, ...)

where NAME is a subroutine and the input variables A, B, and so on have all been
assigned values. This process was also illustrated in earlier examples.

Example 10 The following subroutine computes the square of a positive integer N by succes
sive additions.

SUBROUTINE SQR(N; X)
1. X <- N

2. Y <- 1

3. WHILE (Y # JV)
a. X <e- X + N
b. Y «- Y + 1
4. RETURN
END OF SUBROUTINE SQR ♦

If the result of the steps performed by a subroutine is a single number, we may


call the subroutine FUNCTION. In this case, we title such a program as follows:
FUNCTION NAME (A, B, C, )
Pseudocode 463

where NAME is the name of the function and A, B, C,... are input variables. We
also specify the value to be returned as follows:
RETURN (7)

where Y is the value to be returned.


The name FUNCTION is used because such subroutines remind us of familiar
functions such as sin(jc), log(jc), and so on. When an algorithm requires the use
of a function defined elsewhere, it simply uses the function in the familiar way
and does not use the phrase CALL. Thus, if a function FNl has been defined, the
following steps of pseudocode will compute 1 plus the value of the function FNl
at3X + l.

1. Y <r- 3X + 1
2. Y <- 1 + FNl(iO

Example 11 The program given in Ex*

FUNCTION SQR(Af)
1. X <- N
2. Y <r- 1
3. WHILE (F ^ N)
a. X <- X + N
b. Y <r- Y + 1
4. RETURN (X)
END OF FUNCTION SQR ♦

Variables such as Y in Examples 10 and 11 are called local variables, since


they are used only by the algorithm in its computations and are not part of input or
output.
We will have many occasions to use linear arrays, as we need to be able to
incorporate them into algorithms written in pseudocode. An array A will have lo
cations indicated by A[l], A[2], A[3],... (as we noted in Section 1.3) and we will
use this notation in pseudocode statements. Later, we will introduce arrays with
more dimensions. In most actual programming languages, such arrays must be
introduced by dimension statements or declarations, which indicate the maximum
number of locations that may be used in the array and the nature of the data to be
stored. In pseudocode we will ^iot require such statements, and the presence of
brackets after a variable will indicate that the variable names an array.

Example 12 Suppose that X[l], X[2],..., X[N] contain real numbers andthatwe want to ex
hibit the maximum such number. The following instructions will do that.

1. MAX «- X[l]
2. FOR 1 = 2 THRU N
a. IF (MAX < X[J]) THEN
1. MAX ^- X[I]
3. RETURN (MAX) ♦

Example 13 Suppose that A[l], A[2],..., A[N] contain 0's and l's so that A represents a sub
set (which we will also call A) of a universal set U with N elements (see Section
1.3). Similarly, a subset B of U is represented by another array, B[l], B[2], ...,
B[N]. The following pseudocode will compute the representation of the union
C = A U B and store it in locations C[l], C[2],..., C[N] of an array C.
464 Appendix A Algorithms and Pseudocode
1. FOR J = 1 THRU N
a. IF ((All] = 1) OR (B[J] = D) THEN
1. CHI <r- 1
b. ELSE
1. C[J] <r- 0

We will find it convenient to include a PRINT statement in the pseudocode.


The construction is

1. PRINT ('message')

This statement will cause 'message' to be printed. Here we do not specify whether
the printing is done on the computer screen or on paper.
Finally, we do include a GO TO statement to direct attention to some other
point in the algorithm. The usage would be GO TO LABEL, where LABEL is
a name assigned to some line of the algorithm. If that line had the number 1, for
example, then the line would have to begin
LABEL: 1 ...

We avoid the GO TO statement when possible, but there are times when the
GO TO statement is extremely useful, for example, to exit a loop prematurely if
certain conditions are detected.

Exercises

In Exercises 1 through 8, write the steps in pseudocode needed 5. Suppose that the array X consists of real numbers X[l],
to perform the task described. X[2], X[3] and the array Y consists of real numbers Y[l],
Y[2], y [3]. Write an algorithm to compute
1. In a certain country, the tax structure is as follows. An in
come of $30,000 or more results in $6000 tax, an income X[l]Y[\] + X[2]Y[2] + X[3]Y[3].
of $20,000 to $30,000 pays $2500 tax, and an income of
less than $20,000 pays a 10% tax. Write a function TAX 6. Let the array A[l], A[2],..., A[N] contain the coeffi
that accepts a variable INCOME and outputs the tax ap cients a\,a2,..., aN ofa polynomial YlfLi atx'- Write a
propriate to that income. subroutine that has the array A and variables N and X as
2. Table A. 1 shows brokerage commissions for firm X based inputs and has the value of the polynomial at X as output.
on both price per share and number of shares purchased. 7. Let A[l], A[2], A[3] be the coefficients of a quadratic
Write a subroutine COMM with input variables NUM equation ax2 + bx + c = 0 (that is, A[l] contains a,
BER and PRICE (giving number of shares purchased and A[2] contains b, and A[3] contains c). Write an algorithm
price per share) and output variable FEE giving the total that computes the roots R1 and R2 of the equation if they
commission for the transaction (not the per share commis are real and distinct. If the roots are real and equal, the
sion). value should be assigned to Rl and a message printed.
If the roots are not real, an appropriate message should be
printed and computation halted. You may use the function
SQRT (which returns the square root of any nonnegative
number X).
Less Than $150/Share
$150/Share or More 8. Let [a\, a2), [a2, a3),..., [aN_\, aN] be N adjacent inter
vals on the real line. If A[l],..., A[N] contain the num
Less than 100 shares $3.25 $2.75 bers a\,..., an, respectively, and X is a real number, write
100 shares or more $2.75 $2.50 an algorithm that computes a variable INTERVAL as fol
lows: If X is not between a\ and aN, INTERVAL = 0;
Let X], X2,..., XN be a set of numbers. Write the steps however, if X is in the /th interval, then INTERVAL = /.
needed to compute the sum and the average of the num Thus INTERVAL specifies which interval (if any) con
bers. tains the number X.

Write an algorithm to compute the sum of cubes of all In Exercises 9 through 12, let A and B be arrays of length N
numbers from 1 to N (that is, l3 + 23 + 33 + h N3). that contain 0's and Ys, and suppose they represent subsets
Pseudocode 465

(which we also call A and B) of some universalset U with N 24. FUNCTION F(X)
elements. Write algorithms thatspecify an array C represent 1. IF (X < 0) THEN
ing the set indicated. a. R +- X2 + 1
2. ELSE
9. C = A®B 10. C = A n B
a. IF (X < 3) THEN
11. C = AOB 12. C = AC\(A®~B) 1. R <- 2X + 6
b. ELSE
In Exercises 13 through 20, write pseudocode programs to 1. i? <- X + 7
compute the quantityspecified. Here N is a positive integer. 3. RETURN (i?)
13. The sum of the first N nonnegative even integers END OF FUNCTION F

25. 1. IF (M < AO THEN


14. The sum of the first N nonnegative odd integers
a. i? <r- 0
15. The product of the first N positive even integers 2. ELSE
a. K <- N
16. The product of the first N positive odd integers
b. WHILE (K < AO
17. The sum of the squares of the first 77 positive integers 1. K +- K + AT
c. IF (X = AO THEN
18. The sum of the cubes of the first 23 positive integers
1. i? <- 1
19. The sum of the first 10 terms of the series 3. ELSE
0
1
E 3n + l
In Exercises 26 through 30, give the value of all variables at
the time when the given set of instructions terminates. N al
ways represents a positive integer.
20. The smallest number of terms of the series
26. 1. I <- 1
^ 1
2. X <- 0
^ n+ 3. WHILE (I < AO
a. X <- X + 1
whose sum exceeds 5 b. J <- I + 1

27. 1. J 4- 1
In Exercises21 through 25, describe what is accomplishedby
2. X <- 0
the pseudocode. Unspecified inputs or variables X and Y rep
3. WHILE (J < AO
resent rational numbers, while N and M represent integers.
a. X <- X + J
21. SUBROUTINE MAX(X, Y; Z) b. J <- I + 1
1. Z <r- X 28. 1. A <- 1
2. IF (X < Y ) THEN 2. B <- 1
a. Z <- Y 3. UNTIL (E > 100)
3. RETURN a. B <- 2A - 2
END OF SUBROUTINE MAX b. A <- A + 3

22. 1. X <- 0 29. 1. FOR J = 1 THRU 50 BY


2. I <- 1 a. X <- 0
3. WHILE (X < 10) b. X ^- X + X
a. X <- X + (1/J) 2. IF (X < 50) THEN
b. I <- I + 1 a. X <- 25
3. ELSE
23. FUNCTION .F(X)
a. X <- 0
1. IF (X < 0) THEN
a. R < X 30. 1. X <- 1

2. ELSE 2. y <- ioo

a. R <- X 3. WHILE (X < Y)


3. RETURN (20 a. X <- X + 2
END OF FUNCTION F b. Y <- Iy
Appendix B
Additional Experiments in
Discrete Mathematics

I Experiment A
In this experiment you will investigate a family of mathematical structures and
classify family members according to certain properties that they have or do not
have. In Section 4.5, we define x = r (mod n) if x = kn + r with 0 < r < n —1.
This idea is used to define operations in the family of structures to be studied.
There will be one member of the family for each positive integer n. Each member
of the family has two operations defined as follows:

a®nb = a + b (mod n), a®nb = ab (mod n).

For example, 5 ©3 8 = 13 (mod 3) = 1, because 13 = 4 • 3 + 1 and 4 <g)5 8 =


32 (mod 5) = 2. The result of each operation mod n must be a number between
0 and n — 1 (inclusive), so to satisfy the closure property for each operation we
restrict the objects in the structure based on mod n to 0, 1, 2,..., n — 1. Let
Zn = ({0, 1, 2, 3,..., n - 1}, ©„, ®n). The Zn are the family of structures to be
studied.

Part I. Some examples need to be collected to begin the investigation.


1. Compute each of the following.
(a)7ffi85 (b) 4©62
(c) 2©43 (d) 1053
(e) 6 ©7 6 (f) 7 ®8 5
(g)4®62 (h) 2<g)43
(i) 1®53 (j) 6(8)76
2. Construct an operation table for ©„ and an operation table for ®n for n = 2,
3,4, 5, 6. There will be a total of 10 tables. These will be used in Part II.

Part II. Properties that a mathematicalstructure can have are presented in Sec
tion 1.6. In this part you will see if these properties are satisfied by Zn for selected
values of n.

1. Is ffi„ commutative for n = 2, 3, 4, 5, 6? Explain how you made your deci


sions.
2. Is ffi„ associative for n = 2, 3,4, 5, 6? Explain how you made your decisions.
3. Is there an identity for ©„ in Zn for n = 2, 3, 4, 5, 6? If so, give the identity.
4. Does each element of Zn have an ©„-inverse for n = 4, 5, 6? If so, let —z
denote the ©„ -inverse of z and define aQnb = a®n (—b) and construct a Qn
table.
5. Solve each of the following equations.
(a) 3 ©4 x = 2 (b) 3 ©5 x = 2 (c) 3 ©6 x = 2
6. Is ®„ commutative for n = 2, 3, 4, 5, 6? Explain how you made your deci
sions.

467
468 Appendix B Additional Experiments in Discrete Mathematics

7. Is (g>n associative for n = 2, 3,4, 5, 6? Explain how you made your decisions.
8. Is there an identity for <8>n in Zn forn = 2, 3, 4, 5, 6? If so, give the identity.
9. Does each element of Zn have an ®n-inverse for n = 4, 5, 6? If so, let 1/z
denote the ®n-inverse of z and define a0nb = a®n (\/b) and construct a 0n
table.
10. Solve each of the following equations.
(a) 2 ®n x = 0 for rc = 3, 4, 5, 6
(b) x ®n 3 = 2 for rc = 4, 5, 6, 7
(c) 2 <g)„ jc = 1 for n = 3, 4, 5, 6
Part III. Here you will develop some general conclusions about the family of

1. Let a eZn and a^O. Tell how to compute —a using /i and a.


2. For which positive integers k does a ®* jc = 1 have a unique solution for each
a, 0 < a < k — 1?
3. For which positive integers k does a <g)* jc = 1 not have a unique solution for
each a, 0 < a < k — 1?
4. Test your conjectures from Questions 2 and 3 for k = 9, 10, and 11. If
necessary, revise your answers for Questions 2 and 3.
5. If a ®ic x = 1 does not have a unique solution for each a, 0 < a < k — \,
describe the relationship between a and k that guarantees that
(a) There are no solutions to a ®* x = 1.
(b) There is more than one solution to a ®k x = 1.
6. Describe k such that the following statement is true for Z*.

a ®u b = 0 only if a = 0 or b = 0
Experiment B 469

I Experiment B
An old folktale says that in a faraway monastery there is a platform with three
large posts on it and when the world began there were 64 golden disks stacked on
one of the posts. The disks are all of different sizes arranged in order from largest
at the bottom to smallest at the top. The disks are being moved from the original
post to another according to the following rules:
1. One disk at a time is moved from one post to another.
2. A larger disk may never rest on top of a smaller disk.
3. A disk is either on a post or in motion from one post to another.
When the monks have finished moving the disks from the original post to one
of the others, the world will end. How long will the world exist?
A useful strategy is to try out smaller cases and look for patterns. Let Afc be
the minimum number of moves that are needed to move k disks from one post to
another. Then N\ is 1 and N2 is 3. (Verify this.)
1. By experimenting, find N3, N4, N5.
2. Describea recursive processfor transferringk disks from post 1 to post 3. Write
an algorithm to carry out your process.
3. Use the recursive process in Question 2 to develop a recurrence relation for A^.
4. Solve the recurrence relation in Question 3 and verify the solution by comparing
the results produced by the solution and the valuesfound in Question 1.
5. From Question 4 you have an explicit formula for Nk. Use mathematical in
duction to prove that this statement is true.
6. If the monks moveone disk per second and never make a mistake, how long (to
the nearest year) will the world exist?
470 Appendix B Additional Experiments in Discrete Mathematics

Modeling a situation or problem so that it can be analyzed and solved is a powerful


tool of mathematics and computer science. Often situations that appear to be very
different can be modeled in the same way. And when one such problem is solved,
they all are. In this experiment, you will investigate the modeling process and gain
more experience in creating proofs.

Part I. Thefirst problem to examine is the following. Howmanysequences of n


ones and n negative ones are there such that adding term by term from left to right
gives a nonnegative sum at each step? We often begin the process of developing
a model by considering specific small cases. For example, if n = 1, there is only
one such sequence 1,-1.
1. For n = 2, how many such sequences are there? List each one.
2. Describe in words the condition the sequence must satisfy in order to guaran
tee that the sum at each step is nonnegative.
3. The description in Question 2 is like that of an earlier problem. Modify the
problem analysis and solution given in Section 5.2, Exercises 43-49, to ana
lyze and solve this sequence problem.
(a) Restate Exercises 43-48 of Section5.2 in terms of the sequence problem.
(b) Give the solutions for the restated exercises.

Part II. Here is another situation to model. Each afternoon an Acian philoso
pher walks from her home to the park. Of course, she has wondered how many
different ways there are to do this walk. Here is a map of the relevant portion of
town.

Park

Home

1. If she does not walkanyblock twice,describein wordsthe conditionrequired


for any path the philosopher can take from home to the park.
2. The description in Question 1 is like that of an earlier problem. Modify the
problem analysis and solution given in Section 5.2, Exercises 43-^4-9, to ana
lyze and solve this path problem.
(a) Restate Exercises 43-48 of Section 5.2 in terms of the path problem.
(b) Give the solutions for the restated exercises.

Part III. Discuss the similarities between thethree problems (parentheses, se


quences, and paths). Describe the common structure of these problems and how
to recognize another instance of this model.
The power of modeling lies in the fact that if a situation has the characteristics
described in Part III, we can use the solution developed in Section 5.2 without
carrying out the full analysis again. This is very similar to having a formula to find
the solution to a problem.
Experiment C 471

Part IV. The parenthesesproblem in Section 5.2 was originally described by a


recurrence relation. This provides another way that we can recognize this model
and obtain a solution.

1. Describe how to model the parentheses problem in order to develop the recur
rence relation. State the recurrence relation for the parentheses problem. Give
the solution of this recurrence relation.
2. Consider the problem of counting the number of nonisomorphic binary trees
with n vertices.
(a) Draw and count the nonisomorphic binary trees with one vertex, two ver
tices, and three vertices.
(b) Explain how this recurrence relation is related to that of the parentheses
problem and give the explicit solution for the tree problem.
3. Here is another counting problem. Consider a convex polygon with n + 2
edges and n + 2 vertices like that in Figure 1. The problem is to count the
maximum number of triangles created by dividing the polygon by drawing
lines between nonadjacent vertices such that the lines do not intersect. For
example, Figure 2 shows the cases of n = 2 and n = 3.

n = 3

(a) Give a recurrence relation for the number of triangles that can be created
in this way. Clearly identify the variables in the relation.
(b) Explain how this recurrence relation is related to that of the parentheses
problem and give the explicit solution for the triangle problem.
Discuss the similarities of the parentheses, tree, and triangle counting prob
lems. Describe how to recognize another instance of this model.
Appendix C
Coding Exercises
For each of the following, write the requested program or subroutine in pseu
docode (as described inAppendixA) or in a programminglanguage thatyou know.
Testyour code either with a paper-and-pencil trace or with a computer run.

Chapter 1
In Exercises 1 through 3, assume that A and B are finite sets of integers. Write a
subroutine to compute the specified set.
1. AUB 2. AHB 3. A- B

4. Consider the sequence recursively defined by g(0) = 1, g(l) = —l,g(n) =


3g(n-l)-2g(n-2).
(a) Write a subroutine that will print the first 20 terms of the sequence.
(b) Write a subroutine that will print the first n terms of the sequence. The
user should be able to supply the value of n at runtime.
5. Write a subroutine to find the least common multiple of two positive integers.

Chapter 2
1. Write a program that will print a truth table for p A^q.
2. Write a program that will print a truth table for
(pyq)^ r.
3. Write a program that will print a truth table for any two-variable propositional
function.

4. Write a subroutine EQUIVALENT that determines if two logical expressions


are equivalent.
5. Write a subroutine that determines if a logical expression is a tautology, a
contingency, or an absurdity.

Chapter 3
1. Write a subroutine that accepts two positive integers n and r, and if r < n,
returns the number of permutations of n objects taken r at a time.
2. Write a program that has as input positive integers n and r and, if r < n, prints
the permutations of 1, 2, 3,..., n taken r at a time.
3. Write a subroutine that accepts two positive integers n and r and, if r < n,
returns the number of combinations of n objects taken r at a time.
4. Write a program that has as input positive integers n and r and, if r <n, prints
the combinations of 1, 2, 3,..., n taken r at a time.
5. (a) Write a recursive subroutine that with input k prints the first k Fibonacci
numbers.

(b) Write a nonrecursive subroutine that with input k prints the kth Fibonacci
number.
473
474 Appendix C Coding Exercises

Chapter 4
1. Write a program CROSS with input positive integers m and n and output the
set A x B where A = {1, 2, 3,... ,m} and B = {1, 2, 3,..., n}.
2. (a) Write a subroutine that has as input the matrix of a relation and determines
whether the relation is reflexive.

(b) Write a subroutine that has as input the matrix of a relation and determines
whether the relation is symmetric.
3. Write a program that has as input the matrix of a relation and determines
whether the relation is an equivalence relation.
4. Let R and S be relations represented by matrices MR and Ms, respectively.
Write a subroutine to produce the matrix of
(a) R U S (b) R fl S (c) R o S
5. Let R be a relation represented by the matrix MR. Write a subroutine to
produce the matrix of
(a) /T1 (b) R

Chapter 5
1. Let U = {u\, «2, •••, wn} be the universal set for possible input sets. Write a
function CHARFCN that given a set as input returns the characteristic function
of the set as a sequence.
2. Write a function TRANSPOSE that, given anwxn matrix, returns its trans
pose.

3. Write a programthat writesa givenpermutationas a product of disjoint cycles.


4. Write a program that writes a givenpermutation as a product of transpositions.
5. Use the program in Exercise 4 as a subroutine in a program that determines
whether a given permutation is even or odd.

Chapter 6
1. Write a subroutine that determines if a relation R represented by its matrix is
a partial order.
For Exercises 2 through 4, let

Bn = {(xux2,x3,...,xn) | xi e {0, 1}} andx, y € Bn.

2. Write a subroutine that determines if x < y.


3. (a) Write a function that computes x Ay.
(b) Write a function that computes x v y.
(c) Write a function that computes xf.
4. Write a subroutine that given x produces the corresponding minterm.
5. Let B = {0, 1}. Write a program that prints a truth table for the function
f:B3-^B defined by p(x, y, z) — (x A y') v (y a (xf V y)).
Coding Exercises 475

Chapter 7
1. Use the arrays LEFT, DATA, RIGHT (Section 7.2) in a program to store letters
so that a postorder traversal of the tree created will print the letters out in
alphabetical order.
2. Write a program that with input an ordered tree has as output the correspond
ing binary positional tree (as described in Section 7.3).
3. Write a subroutine to carry out the merging of vertices as described in Prim's
algorithm on page 293.
4. Write code for the second version of Prim's algorithm (Section 7.5).
5. Write code for Kruskal's algorithm.

Chapter 8
1. Write a function that given G and an element v of V will return the degree of
v.

2. Write a subroutine that will determine if two vertices of G are adjacent.


3. Write code for Fleury's algorithm.
4. Write a subroutine that, with input a list of vertices of G, reports whether or
not that list defines a valid path that is a Hamiltonian path.
5. Modify yourcodefor Exercise 4 so thatthe subroutine checks for Hamiltonian
circuits.

Chapter 9
Let Zn be as defined in Section 9.3.
1. Write a function SUM that takes two elements of Z„, [x] and [y] and returns
their sum [jc] © [y]. The user should be able to input a choice for n.
2. Let H = {[0], [2]}. Write a subroutine that computes the left cosets of H in
Z6.
3. Let H = {[0], [2], [4], [6]}. Write a subroutine that computes the right cosets
of H'mZs.
4. Write a program that given a finite operation table will determine if the oper
ation satisfies the associative property.
5. Write a program that given a finite group G and a subgroup H determines if
H is a normal subgroup of G.

Chapter 10
1. Let M = (5, /, !F) be a finite state machine where 5 = {s0, s\), I = {0, 1},
and ^is given by the following state transition table:

0 1
so so S\
S\ S\ so

Write a subroutine that given a state and an input returns the next state of the
machine.
2. Write a function ST_TRANS that takes a word w, a string of 0's and l's, and
a state s and returns fw(s), the state transition function corresponding to w
evaluated at s.
476 Appendix C Coding Exercises

3. Let M = (5, /, 50 be a Moore machine where S = {so, su S2}, I = {0,1),


T = fo} and ^is given by the following state transition table:

0 1
so ^0 S\
s\ Sl Si
S2 S\ so

Write a program that determines if a given word w is in L(M).


4. Write a subroutine that simulates the Moore machine given in Exercise 2,
Section 10.5.
5. Write a subroutine that simulates the Moore machine given in Exercise 4,
Section 10.5.

Chapter 11
1. Write a function that finds the weight of a word in Bn.
2. Write a subroutine that computes the Hamming distance between two words
mBn.

3. Let M and N be Boolean matrices of size n x n. Write a program that given


M and N returns their mod-2 Boolean product.
4. Write a subroutine to simulate the (m, 3m)-encoding function e: Bm -> B3m
described in Example 3, Section 11.1.
5. Write a subroutine to simulate the decoding function d for the encoding func
tion of Exercise 4 as described in Example 2, Section 11.2.
Answers to Odd-Numbered Exercises

Note: We have not included "solutions" for Coding Exercises for several reasons. We believe each department (or instructor)
should have very specific programming standards and any code we presented would certainly violate someone's standards and set
up unnecessary conflicts. More importantly, different programming languages support different constructions and what is a good
choice in one can be a very bad one in another.

Chapter 1 Exercise Set 1.2, page 11


(a) a,b, c, d, e, f g}. (b) a,c,d,e, fg}.
Exercise Set U, page 4
(c) a, c}. (d) /}.
1. (a) True. (b) False, (c) False,
(e) b,g,d,e). (0 a,b, c}.
(d) False, (e) True. (f) False.
(g) d,e,fh,k). (h) a, b, c, d, e, f).
3. (a) {A, R, D, V, K}. (b) {B, O, K}.
(i) b,g,f}. (I) g).
(c) {M,I,S,P}.
(a) a,b,c,dte,f,g}. (b) }•
5. (a) False, (b) True. (c) False.
(c) a,c,g). (d) a,c,f).
(d) True. (e) False, (f) False. a,b,c,d,e, f,h,k}.
(e) h,k}. (D
7. [x | x is a vowel}. 1,2,4,5,6,8,9}. 1,2,3,4,6,8}.
(a) (b)
9. {x | x € Z and*2 < 5). (c) 1,2,4,6,7,8}. (d) 1,2,3,4,5,9}.
11. (b),(c),(e). (e) 1,2,4}. 8}.
(f)
13. { }, {JAVA}, {PASCAL}, {C++}, {JAVA, PASCAL},
(g) 2,4}. (h) }•
{JAVA, C++}, {PASCAL, C++}, {JAVA, PASCAL, C++}.
(a) 1,2,3,4,5,6,8,9}. b) {2,4}.
15. (a) True. (b) False, (c) False.
(c) 1,2,4}. (d) 8}-
(d) True. (e) True. (f) True.
(e) 3,7}. (f) 1,3,5,6,7,8,9}.
(g) True. (h) True.
(a) b,d,e,h). (b) b,c,d,f,g,h}.
17. (a) c. (b) c. (c) £. b,d,h}. (d) b,c,d,e,f,g,h}.
(c)
(d) c. (e) £ (f) c. (e) (I) cf,g).
19. {1,2,3} 11. (a) All real numbers except—1 and 1.
21. Yes, Yes, the complement of a set would not be defined (b) All real numbers except and 4.
unambiguously.
(c) All real numbers except—1 , l,and4.
23. (a) False. (b) False. (c) Insufficient information.
(d) All real numbers except
(d) False. (e) True. (f) True.
13. (a) True. (b) True. (c) False, (d) False.
25. Eight. There are three parts that represent what is left of
15. 1.
each set when common parts are removed, three regions
that each represent the part shared by one of the three pairs 17. (a) \AUB\ = 10, |A| = 6, \B\ =7,\AHB\ = 3. Hence
of sets, a region that represents what all three sets have in \AUB\ = \A\ + \B\-\ADB\.
common, and a region outside all three sets. (b) |AU£| = 11,|A| =5, \B\ =6, \AC\B\ = 0. Hence
27. B = {m,n}. 29. B = {a, b, c}. \A\JB\ = \A\ + \B\-\AHB\.
31. /—x—n. is one solution. 19. B must be the empty set.
21. The complement of the intersection of two sets is the union
of the complements of the two sets.
23. |A| = 6, \B\ = 5, \C\ = 6, \A 0 B\ = 2, \ADC\ = 3,
|flnC| =3, \ADBDC\ =2, \AUBUC\ = 11. Hence
\A U B U C\ = \A\ + |5| + \C\ -\AnB\-\AC\C\-
33. 0 c Z+ c N c Z c Q c E. \Bnc\ + \AnBnc\.
35. B; B. 37. 4; 8. 25. (a) 106. (b) 60.

477
478 Answers to Odd-Numbered Exercises

27. 16; 23. 51. The cardinality of the union of n sets is the sum of the car
dinalities of each of the n sets minus the sum of the cardi
29. (a) 162. (b) 118. (c) 236.
nalities of the nC2 different intersections of two of the sets
(d) 290, (e) 264. plus the sum of the nC^ different intersections of three of
31 the sets and so on, alternating plus and minus the sum of
the nCk fc-set intersections, k = 4,... ,n.
D/ « \ \ U
Exercise Set 1.3, page 19
392 \ / 36
1. {1,2}.

3. {a,b,c, ...,z}.
245 158
5. Possible answers include xyzxyz..., xxyyzzxxyyzz, and
yzxyzx—

143 / \ 289 7. 5, 25, 125, 625.

9. 1,2,6,24.

11. 2.5, 4, 5.5, 7.


33. (a) True. (b) True. (c) False, (d) False.
13. 0, -2, -4, -6.
35. (a) Not possible to decide, (b) Not possible to decide.
15. an —an_\ + 2, ax = 1, recursive; an = 2n —1, explicit.
(c) Not possible to decide, (d) Not possible to decide.
(e) Not possible to decide, (f) Not possible to decide. 17. cn = (-l)rt+1, explicit.
37. (a) Not possible to decide, (b) Not possible to decide. 19. en = en-\ + 3, e\ — 1, recursive.
(c) Not possible to decide, (d) Not possible to decide. 21. an =2 + 3(n-1).
(e) Not possible to decide.
23. A, uncountable; B, finite; C, countable; D, finite;
39. A and to B. E, finite.
41. (a) c (b) A U B.
25. (a) Yes. (b) No. (c) Yes.
(d) Yes. (e) No. (f) No.

27. (a) 1. (b) 0.


(c) Let x e A U B. Then x e Aovx e B. Since A c C (c) fB: 10000000, fc: 01010011, fD: 01000101.
and B c C, x e A ovx € B means that jc e C. Hence
AU5CC. (d) 11010011,01010111,01000001.

43. Yes. Suppose* e B. Either x e A or x <£ A. If jc e A, 29. fA®B)®c = fA@B + fc- 2fA@Bfc by Theorem 4
then x $ A 0 B = A © C. But then jc must be in C. If = (fA + fB-2fAfB)
x £ A, then jceA0£ = A©C, and again x must be in + fc-2(fA + fB-2fAfB)fc
C. So B c C. A similar argument shows that C c B, so = fA + (fB + fc-2fBfc)
£ = C. -2fA(fB + fc-2fBfc)
45 No. Let A = {1,2,3}, B = {4}, and C = {3,4}. Then = fA + /b©c —2fA fBec
A U B = A U C and B £ C. = fA®(B@C)
Since the characteristic functions are the same, the sets
47. (a) Let x e A U C. Then x € A or jc g C, so x e B or must be the same.
x € Dmdx e BUD. Hence A U C c B U D.
31. (a) Yes. (b) Yes. (c) Yes.
(b) Let x e A n C. Then jc e A and * € C, so x g 5 and
xeD. Hence x e BHD. Thus A n C c 5 n D. 33. Possible answers include v ac av ab(.
49. We must subtract |5 n C\, because each element in B n C
35. (a) 01*0. (b) 0(00)* v (00)*1.
has been counted twice in|A| + |2?| + |C|. But when we
subtract both \B C\C\ and \A n C|, we have "uncounted" 37. By (1), 8 is an 5-number. By (3), 1 is an 5-number. By
all the elements of C that also belong to B and A. These (2), all multiples of 1, that is, all integers are 5-numbers.
(and the similar elements of A and B) are counted again
by adding \AnBDC\. 39. 1,2,3,7,16.
Answers to Odd-Numbered Exercises 479

Exercise Set 1.4, page 30 45. (a) Answers will vary, but the pattern of italicized and
nonitalized letters should match
1. 20 = 6 • 3 + 2.
AAAAAAAAAAAA4AAAAAAAAAAAAA
3. 3 = 0 • 22 + 3.
AAAAAAAAA.
5. (a) 828 = 22 • 32 •23. (b) 1666 = 2 •72 • 17. (b) STUDY WELL.
(c) 1781 = 13 • 137. (d) 1125 = 32 •53. 47. BUS.
(e) 107.
Exercise Set 1.5, page 39
7. d = 3; 3 = 3 • 45 - 4 . 33. 1. (a) -2,1,2. (b)3,4. (c)4,-l,8.
9. d=l; 1=5-77-3. 128. (d) 2, 6, 8.
11. 1050. 13. 864. 3. a is 3, b is 1, c is 8, and d is -2.
15. (a) 6. (b) 1. (c) 0. '4 0 2"
5. (a) 9 6 2
(d) 1. (e) 20. (f) 14.
3 2 4
17. (a) 10. (b) 22. (c) 2. (d) 14.
19. f(a)-\-f(b) may be greater than n.
21. (a) {2,7,12,17,...}. (b) {1,6,11,16,...}.
(b) AB
=l-i 1}
(c) Not possible.
23. If a I b, then b = ka, for some k e Z. Thus, mZ? =
m(£fl) = (mk)a and m£ is a multiple of a.
(d)
[-J "1
(a) EB is 3 x 2 and FA is 2 x 3; the sum is undefined.
25. The only divisors of p are ±p and ±1, but /? does not di (b) B + D does not exist.
vide a. (Multiply both sides by b.) p \ sab and p \ tpb. If
p divides the right side of the equation, then it must divide <CM 40 14 "12 ' ^ DE does not exist-
the left side also.
22 34
27. Because a | m, ac \ mc and because c \ m, ac \ am. 9. (a) 3 11 (b) BC is not defined.
If GCD(a, c) = 1, there are integers sy t such that 1 = -31 3
sa + tc. Thus m = sam + tcm. But ac divides each term
on the left so ac \ m. [25
25 55 26
26 ]
(c)
[20
20 -3
-3 32
32 J*
29. Let d = GCD(a, b). Then cd \ ca and cd \ cb\ that is, cd
is a common divisor of ca and c&. Let e = GCD(ca, a/). (d) DT + E is not defined.
Then cd \ e and e = cdk is a divisor of ca and d?. But 11. Let B = [ bjk ] = IWA. Then bjk = Y!L\ haik> for
then dk \ a and dk \ b. Because d is the greatest common 1 < j < m and \ < k < n. But in = 1 and /,/ = 0 if
divisor of a and b, k must be 1 and e = cd. j # /. Hence bjk = ijjajk, l<j<m,l<k<n. This
31. By Theorem 6, GCD(a, b) • LCM(a, b) = ab. Since
means B = ImA = A. Similarly, if C = AI„ = [ cjk ],
GCD(a, b) = 1, we have LCM(a, 6) = a/?. cjk = XXi ajilik = <*jkikk = ajk for 1 < j < m,
1 < k <n.
33. a I fr means £ = <zm. & | a means a = bn. Thus
"27 0 0" 33 0 0"
b = am = bnm. Hence nm = 1 and n = m = 1, be
13. A3 0-8 0 or 0 (-2)3 0 A' =
cause a and b are positive. 43
0 0 64 0 0
35. No; consider a = 6, 6 = 4, c = 3. 3* 0 Ol
37. Yes. Using the same reasoning as in Exercise 36, m and n 0 (-2)* 0
share no prime factors, so for mn to be a perfect rth power, 0 0 4*
each prime in the factorizations of m and n must appear a 15. The entries of1^ satisfy i'kj = ijk. But iJk = 1 if j = k
multiple of f times. But this means each of m and n are and is 0 otherwise. Thus i'kj = \ifk = j and is 0 if A: ^ j
also perfect rth powers. for 1 < j < n, 1 < k < n.
39. (a) 112. (b) 10. (c) 30. 17. The 7th column of AB has entries c,7 = YH=\ atkbkj- Let
41. (a) (i) (104)5. (ii) (243)5. (IB) (1330)5. (iv) (10412)5. D = [ dij ] = AB7, where By is the y'th column of B.
Then 4; = ELi Hm^mj — C/y.
(b) (i) 49. (ii) 85. (iii) 197. (iv) 816.
43. (a) (11101)2. (1001001)2.
(1011011100)2.
(11010111)2. 19,
*-[; ?]- I2

21, (a) (A + B)r = Ar + Br by Theorem 3. Since A and B


(b) (131)4. (1021)4. (3113)4. (23130)4. are symmetric, Ar + Br = A + B and A + B is also
(c) (1D),6. (49)16. (D7)i6. (2DC)16. symmetric.
480 Answers to Odd-Numbered Exercises

(b) (AB)7 = B7Ar = BA, but this may not be AB, so 1 if mlk = pkj = 1 for some k
37. (a)
l~l 2^ 0 otherwise.
AB may not be symmetric. Let A = 9 . and

1 if pik = mkj = 1 for some k


(b)
•-[-? i] Then AB is not symmetric.

23. (a) The /, 7th element of (Ar)r is the 7, /th element of


0 otherwise.

1 if mlk = nki = pij = 1 for some £, /


AT. But the 7, /th element of Ar is the /, 7th element (c)
0 otherwise.
of A. Thus (AT)T =A.
(b) The /, 7th element of (A + B)r is the 7, /th element 39. Let C = [ Cij ]=AvBandD = [^]=BvA.
of A + B, aji + bjj. But this is the sum of the 7, /th
entry of A and the 7, /th entry of B. It is also the sum 1 iffl;, loTbu = 1 _
of the /, 7th entry of Ar and the /, 7th entry of Br. 0 if afy = 0:
Thus(A + B)r = Ar+Br.
Hence C = D.
(c) Let C = [ Cij ] = (AB)7. Then cu = ELi «;**«.
the 7,/thentry ofAB. Let D = [ du ] = BrAr,then 41. Let [ du ] = BvC, [ eu ] = Av(BvC), [ fu ] = AvB,
and [ gij ] = (A v B) v C. Then
dU = Ylbikakj = YlbkiaJk = YlaJkbki
k=\ k=\
k=
= .1 ifZ?;7 = lore,, = 1
*=i
10 otherwise
Hence (AB)r = B^A7.
9 4 2 5 1 if aij 1 or d^
27 27 32 32 en =
25. (a) (b) (c) 0 otherwise.
0 3 4 6
27 27 32 32
But this means dtj = 1 if a{j —1 or btj = 1 or c,y = 1 and
27. (a) C = A1 since CA = I3. di} = 0 otherwise.
(b) D = B"' since DB = I3.
29. Since (B"lA"1)(AB) = B" (A" 1A)B B^B = 1 if aij = 1 or bij = 1
B,B = In,(B A ') = (AB) -1 fu = 0 otherwise
'1 1 1 1 0 0
31. (a) A v B = 0 1 1 A aB = 0 0 1
1 if fij = 1 or Cij = 1
gij =
1 0 1 1 0 0 0 otherwise.

1 1 1" But this means gij = 1 if atj = 1 or b{j = 1 or ci} —1 and


A0B = 0 0 1 gu = 0 otherwise. Hence A v (B v C) = (A v B) v C.
1 1 1
43. Let [ du ] = BOC, [ eu ] = AO(BOC), [ ftj ] = AQB,
0 0 1 and [ gij ] = (A OB) O C. Then
(b) A v B = ; A A B = 1 1 0
1 0 0 1 if b{k = ckj for some k
dij =
1 0 1 0 otherwise
AOB = 1 1 1
and
0 1 1

"1 1 1 1 0 0 1 if an = 1 = dij for some /


(c) A v B = 1 1 1 A aB = 0 0 1 0 otherwise.
1 0 1 1 0 0
But this means
1 1 1"
AOB = 1 0 0
1 if an = 1 = bik = ckj for some k, I
1 1 1 en =
0 otherwise.
33 (a) /„. (b) /„. (c) fpq.
(d) fXq. (e) flr. (f) fa if p = q. 1 if aik = 1 = bkj for some k
fu = 0 otherwise
35. (a) pnmij + Pi2m2j H h PitmtJ.
(b) ntapij + mi2p2j H h rnitptj. and

(c) Pi\(mij+n\j) + pi2(m2j+n2j) + --- + ph(mtJ+ntj).


1 if fu = 1 = cij for some /
(d) (mnnXj +mi2n2j-\ Ymltntf) + (pnnXj+ pi2n2j + 8u =
0 otherwise.
1- Puntj).
Answers to Odd-Numbered Exercises 481

But then

1 if aik = 1 = bki = cij for some k, I


8U =
0 otherwise
"•[0 0] or[o S]belo"ss",M-
and A O (B O C) = (A O B) O C.
45. An argument similar to that in Exercise 44 shows that
A v (B A C) = (A v B) A (A v C). " I 0"
n
23. If a ^0, then A"1 = a

0 0
47. Sincec/y = ^aitbtj and k \ ait for any / and t, k divides
25. Yes. 27. No.
each term in c/7, and thus k \ ctj for all / and 7.
29. (a) Yes. (b) Yes. (c) Yes.
6 -9 -3"
49. (a) 0 15 6 (d) Yes
12 -12 18
31. (a) Yes. (b) Yes. (c) No.
10 20 -30"
(b) 20
35 -5
0 45
15
3Ma>*([;]v[»]H4;]v^]).
(b) No.
-4
-3
°1
-1 35. Let C = [ cu ] = comp(A v B) and D = [ du ] =
(c)
2 -5 comp(A) A comp(B). Then

51 Let A = [ a{j ] and B = [ bXj ] be two m x n matri 0 if aXj = 1 or ^7 = 1


ces. Then k(A + B) = k[ au + bXj ] = [ k(au + bu) ] = ca =
1 if aij = 0 = b^
[ katj + kbij ] = [ kau ] + [ kbu ] = kA + kB.
53. Let K be the m x m diagonal matrix with each diagonal and
entry equal to k. Then KA = kA. 0 iffl.1 or b^ = 1
dij =
1 if aXj = 0 = bij.
Exercise Set 1.6, page 44
Hence, C = D. Similarly, we can show that comp(A A
1. (a) Yes. (b) Yes.
B) = comp(A) v comp(B).
3. (a) No. (b) Yes.
37. AH B. 39. {}.
5. A © B = {jc I (x e A U B) and (jc i A n B)} =
{x I (jc e 5 U A) and (jc £ 5 n A)} = 5 0 A. Chapter 2
7. x j z y • z x V (y • z) jc V y x V z (x V y) • (x V z)
Exercise Set 2.1, page 55
000 0 0 0 0 0
1. (b), (d), and (e) are statements.
00 1 1 0 0 0 0
0 1 0 1 0 0 0 0 3. (a) It will not rain tomorrow and it will not snow tomor
0 1 1 0 0 0 0 0 row.

1 00 0 0 0 0 0 (b) It is not the case that if you drive, I will walk.


1 0 1 1 1 0 1 1
5. (a) I will drive my car and I will be late.
1 1 0 1 1 1 0 1
I will drive my car or I will be late.
1 1 1 0 0 1 1 0
(b) 10 < NUM < 15. NUM > 10 or NUM < 15.
(A) (B)
7. (a) True. (b) True. (c) True. (d) False.
Since columns (A) and (B) are identical, the distributive
9. (a) False, (b) True. (c) True. (d) False.
property jc V (y • z) = (jc V y) D (x V z) holds.
11. (d) is the negation.
9. 5 x 5 zero matrix for v; 5 x 5 matrix of l's for a; I5 for
O.
13. (a) The dish did not run away with the spoon and the grass
is wet.
11. Let A, B be n x n diagonal matrices. Let [ c/y ] = AB.
Then c/y = Yll=i atkbkj, but aik = 0 if / ^ k. Hence (b) The grass is dry or the dish ran away with the spoon.
ay = aubij. But bij = 0 if / ^ 7. Thus cu = 0 if / #7 (c) It is not true that today is Monday or the grass is wet.
and AB is an n x n diagonal matrix. (d) Today is Monday or the dish did not run away with
13. Yes, the n x n zero matrix, which is a diagonal matrix. the spoon.
15. —A is the diagonal matrix with /, /th entry —an. 15. (a) For all x there exists a y such that x + y is even.
482 Answers to Odd-Numbered Exercises

(b) There exists an jc such that, for all y, x + y is even.


• P q (P^q) A/7
17. (a) It is not true that there is an jc such that jc is even, T T T F
T F F T
(b) It is not true that, for all jc, jc is a prime number.
F T T T
F F F F
19. 14: (a) False. (b) True.
15: (a) True. (b) False.
16: (a) False. (b) True. 37. (jc = max) or (v < 4).
17: (a) False. (b) True. 39. WHILE (item = sought or index > 101) take action
18: (a) False. (b) False. (c) False. (d)
Exercise Set 2.2, page 60
21. (a) 5 + 3 = 6. (b) m + 3 = 6. 1. (a) p =*• q. (b) r => p.
23. (a) 0 < 3°. (b) 2 < 32. (c) k < 3k. (c) q => p. (d) ~r =$• p.
3. (a) If I am not the Queen of England, then 2 + 2 = 4.
25. VAVB(A UB) = AHB; VAV5(A HB) = AUB.
(b) If I walk to work, then I am not the President of the
United States.
• p q iyp A q) v p
(c) If I did not take the train to work, then I am late.
T T F F T
T F F F T
(d) If I go to the store, then I have time and I am not too
tired.
F T T T T
F F T F F (e) If I buy a car and I buy a house, then I have enough
(1) (2) money.

5. (a) True. (b) False.


29.
*y- p q r (pyq) Ar
(c) True. (d) True.
T T T T T 7. (a) Ifl do not study discrete structures and I go to a movie,
T T F T F then I am in a good mood.
T F T T T
(b) Ifl am in a good mood, then I will study discrete struc
T F F T F
tures or I will go to a movie.
F T T T T
F T F T F (c) If I am not in a good mood, then I will not go to a
F F T F F movie or I will study discrete structures.
F F F F F (d) I will go to a movie and I will not study discrete struc
(1) tures if and only if I am in a good mood.
9. (a) If 4 > 1 and 2 > 2, then 4 < 5.
31. p q r (p iq) jr
(b) It is not true that 3 < 3 and 4 < 5.
T T T F F (c) If3>3,then4> 1.
T T F F T
11. (a) p q P =» (q^p)
T F T F F
T F F F T T T T T
F T T F F T F T T
F T F F T F T T F
F F T T F F F T T
F F F T F
(1) tautology

33' p q (Pir)
(Wp q q =• (q=>p)
r (p iq) 1
T T T T
T T T F T F
T F T T
T T F F T F
F T F F
T F T F T F
F F T T
T F F F T F
F T T F T F t
F T F F F T
contingency
F F T T F F 13. Yes. If p =>> q is false, then p is true and q is false. Hence
F F F T F T p A q is false, ~(p A q) is true, and (~(p Aq)) =$> q is
(1) (2) false.
Answers to Odd-Numbered Exercises 483

15. No, because if p => q is true, it may be that both p and q 35


**• p q r ((P =• q) A (q =» r)) => (P^r)
are true, so (p A q) =$> —q is false. But it could also be
that p and q are both false, and then (p Aq) =» ~g is true. T T T T T T T T
T T F T F F T F
17. The solultions are self-checking.
TFT F F T T T
19. The solution is self-checking. T F F F F T T F
21. (a) False, (b) True, (c) False, (d) True. F T T T T T T T
F T F T F F T T
Lp q (p^q) (P 1 P) 1 (q iq) F F T T T T T T
T T T F T F F F F T T T T T
T F F F F T (1) (3) (2) t (4)
F T F T F F 37. Because (pAq) = (qAp), parts (a) and (b) of Theorem 4
F F F T F T say the same thing; that is, either p or q can be considered
(A) (B) the first statement.
Since columns (A) and (B) are the same, the statements
are equivalent.
25. (a) Jack did eat fat or he did not eat broccoli. Exercise Set 2.3, page 67
(b) Mary did not lose her lamb and the wolf did not eat 1. Valid: ((d => t) A -W) => ^d.
the lamb.
3. Invalid.
(c) Tom stole a pie and ran away and the three pigs have
5. Valid: ((/ v ~iy) a«i)^/.
some supper.
7. Valid: [(ht => m) A (m => hp)] => [~hp => ^ht].
27.
(qVr) (pAr) 9. Invalid.
P q r
P A (P^q) V

T T T T T T T T
11. (a) ((p Vq)A ~q) => p.
T T F T T T T F (b) ((/? =* q) A -p) => ~q.
T F T T T F T T
13. (a) (((/? =• q) A (q => r)) A «~q) A r)) => p.
T F F F F F F F
F T T F T F F F (b) (y(p => q) A p) => -q.
F T F F T F F F 15. Suppose m and n are odd. Then there exist integers j and
F F T F T F F F k such that m = 2j + 1 and n = 2k+l.m+n =
F F F F F F F F (2j +1) + (2*+ 1) = 2j+2Jc + 2 = 2(j+k+l). Since
(A) (B) j + k + 1 is an integer, m + n is even.
Because (A) and (B) are the same, the statements are
17. Suppose that m and az are odd. Then there exist inte
equivalent. gers j and k such that m = 2y + 1 and n = 2k + 1.
m-n = 2j-2k + 2j + 2k + l = 2(2jk + j +k) +1. Since
29« p q <"V^
(p&q) (p A ~ q) V (q a - p) 2jk + j +k is an integer, m • n is odd and the system is
T T F T F F F closed with respect to multiplication.
T F T F T T F 19. If A = B, then, clearly, A c B and 5 c A. If A c B and
F T T F F T T KA, then A c 5 c A and 5 must be the same as A.
F F F T F F F
21. (a) If A c 5, then A U 5 c 5. But B c A U fl. Hence
(A) (B)
A U 5 = B. If A U B = B, then since A c A U 5, we
Because columns (A) and (B) are the same, the statements
have ACB.
are equivalent.
31. The statement Vjc(P(jc) a Q(x)) is true if and only if (b) If A c £, then A c A n 5. But A n £ c A. Hence
Vjc both P(jc) and Q(jc) are true, but this means VjcP(jc) ADB = A.If ADB = A, then since A n B c 5, we
is true and VjcQCx) is true. This holds if and only if have A c fi.

VjcP(jc) A VjcQ(jc) is true. 23. For n = 41, we have a counterexample. 412 H-41 -41 +41
is41(41+41 + l)or41 -83.
33. p q q =* (pvq) 25. n3 - n = n(n —\)(n + 1), the product of three consec
T T T T utive integers. One of these must be a multiple of 3, so
T F T T 3U3 n.
F T T T
27. Invalid. Multiplying by jc—1 may or may not preserve the
F F T F
order of the inequality.
29. Valid.
484 Answers to Odd-Numbered Exercises

31. Let x and y be prime numbers, each larger than 2. Then 11. Basis step: n = 2 P(2): 2 < 22 is true.
x and y are odd and their sum is even (Exercise 15). The Induction step: LHS of P(fc + 1): fc + 1 < 2* + 1 <
only even prime is 2, so jc + y is not a prime. 2*+ 2* = 2-2* =2*+1. RHSofP(fcH-l).
33. Suppose x + y is rational. Then there are integers a and 13. Basis step: n = 5 P(5): 1 + 52 < 25 is true.
b such that jc + y = |. Since jc is rational, we can write Induction step: LHS of P(ft + 1): 1 + (ft+ 1)2 = ft2 + 1 +
x = £ with integers c and d. But now y = x -\- y —x = 2ft+l < 2^+2ft+l < 2*+fc2+l < 2*+2* = 2-2* = 2k+l.
b ~ d- y = ^m1' Both ad ~ bc and bd are integers- RHSofP(fc+l).
This is a contradiction since y is an irrational number and
15. Basis step: n = 0 A = { } and P(A) = {{ }}, so
cannot be expressed as the quotient of two integers.
|P(A)|=2°andP(0)istrue.
Exercise Set 2.4, page 73 Induction step: Use P(fc): If \A\ = ft, then \P(A)\ = 2k to
Note: Only the outlines of the induction proofs are given.
showP(ft + 1): If \A\ = ft + 1, then \P(A)\ = 2k+l. Sup
pose that |A| = ft + 1. Set aside one element jc of A. Then
These are not complete proofs.
|A —{x}\ = ft and A —{x} has 2k subsets. These subsets
1. Basis step: n = 1 P(l): 2(1) = 1(1 + 1) is true. are also subsets of A. We can form another 2k subsets of
Induction step: P(ft): 2 + 4 H h 2k = k(k + 1). A by forming the union of {jc} with each subset of A —{jc}.
P(ft + 1): 2 + 4 + • • • + 2(k + 1) = (k + \)(k + 2). None of these subsets are duplicates. Now A has 2k + 2*,
LHS of P(ft + 1): 2 + 4 + • • • + 2k + 2(ft + 1) = or2*+I, subsets.
k(k + 1) + 2(k + 1) = (ft + l)(ft + 2)
17. Basis step: n = 1 P(l): A\ = A\ is true.
RHSofP(ft-M).
Induction step: LHS of P(ft + 1):
3. Basisstep: w= 0 P(0): 2° = 20+I - 1 is true.
Induction step: LHS of P(ft+ 1): 1+ 21 + 22 + •••+ 2* +
2*+i = (2*+i _ i) + 2*+1 = 2 •2*+1 - 1 = 2*+2 - 1. DA;
i—\
(AA,.)n. ljfc+1
RHSofP(ft-hl).
1(1 + 1)(2+1) = n Ai U Ajt+i (De Morgan's laws)
5. Basis step: n = 1 P(l): l2 = is true.

Induction step: LHS of P(ft + 1):


=fuA/jUA,+1
l2 + 22 + ... + ft2 + (ft+l)2
k+i.
fc(fc+l)(2fc + l) UAi. RHSofP(ft-j-l).
+ (fc + l)z /=i
6

_„+„ (***+»+(t+1; 19. Basis step: n = 1 P(l): A\ U B = Ax U B is true.


Induction step: LHS of P(ft -f-1):
fc-f-1
6
(2fc2 + fc + 6(fc+l))
(knlAi jub=((n a^ nam\ ub
ft+1
(2fc2 + 7ft + 6)
6
(ft+l)(ft + 2)(2ft + 3)
=(fnA,JuiiJn(AwuB)
(distributive property)
(* + l)((*+l) + l)(2(* + l) + l)
= (n(AiVB)\n(Ak+lUB)
RHSofP(ft + l).
= *n(A, UB). RHS of P(fc + 1).
1=1
a(\ —r{)
7. Basis step: n = 1 P(l): a = is true.
1 —r 21. (a) (ft + l)2 + (ft + 1) = ft2 + 2ft + 1 + ft + 1 =
Induction step: LHS of P(ft + 1): a + ar + ••• + ark~l + ft2 + ft + 2(fc -I-1). Using P(ft), ft2 + ft is odd; 2(fc + 1)
k a(\-rk) a —ark + #r* —ark+l is clearly even. Hence their sum is odd.
+ ark =
\-r \-r
a(l-rk+l) (b) No, P(l) is false.
RHSofP(ft-hl).
23. The flaw is that to carry out the procedure in the induction
9. (a) LHSofP(ft-hl): 1 +5 + 9 + • • • + (4(ft + 1) - 3) = step, you must have at least three trucks, but the basis step
(2ft + l)(ft - l) + 4(ft + 1) - 3 = 2ft2 + 3ft = was done for one truck.
(2ft + 3)(ft) = (2(ft + 1) + l)((ft + 1) - 1).
25. Basis step: n = 1 P(l): A2 •A = A2+l is true.
RHSofP(ft-hl). Inductionstep: LHSofP(ft-j-l): A2-A*+1 = A2(A*-A) =
(b) No; P(l): 1 = (2 • 1 + 1)(1 - 1) is false. (A2 •A*) •A = A2+* . A = A2+*+1. RHS of P(ft+ 1).
Answers to Odd-Numbered Exercises 485

27. Basis step: n = 5 P(5): A restaurant bill of $5 can be Loop invariant check:
paid exactly with a $5 bill. Basis step: n = 0 P(0): Z0 + (K x W0) = X2 + Y2 is
Induction step: We use P(j): A restaurant bill of $j can true, because Z0 = K + X2 and W0 = Y - 1.
be paid exactly using $2 and $5 bills for j = 5, 6,..., ft Induction step: LHS of P(ft + 1): Z*+1 + (Y x Wk+l) =
to show P(ft + 1). Write ft + 1 as 2m + r, 0 < r < 2. If Zk + Y + Y x (Wk - I) = Zk + Y x Wk = X2 + Y2.
r = 0, then the bill can be paid with m $2 bills. If r = 1, RHSofP(ft + l).
then 2m + r = 2m + 1 = 2(m - 2) + 5. Since ft + 1 > 7, Exit condition check: W = 0 Z + YxW = X2 + Y2
m > 2, and m —2 > 0. Thus a bill of ft + 1 dollars can be yields Z = X2 + y2.
paid exactly with (m —2) $2 bills and a $5 bill.
Exercise Set 2.5, page 78
29. Basis step: n = 1 P(l): If p is prime and /? | a\ then 1. Let 2ft be any even number. (2ft)3 = 8ft3 = 2(4ft3) is
/? | a is true.
clearly an even number.
Induction step: If p \ ak+\ thenp \ ak -a andeither /? | ak
or p \a.If p \ ak, then (usingP(ft)), p \ a. 3. (a) Let n, n + 1, and n + 2 be any three consecutive inte
gers, n -I- (n + 1) + (n + 2) = 3n + 3 = 3(n + 1),
31. (a) 5. which is clearly divisible by 3.
(b) Basisstep: n = 5 P(5): 25 > 52 is true. (b) Let«, n + 1, n + 2, and n + 3 be any four consecutive
Induction step: LHS of P(fc + 1): 2M =22* = integers, n + (n + 1) + (n + 2) + (n + 3) = 4rc + 6,
2k + 2k > ft2 + ft2 > ft2 + 3ft > ft2 + 2ft + 1 (since which is not divisible by 4.
ft > 5) = (ft+1)2. RHSofP(ft-l-l).
5. The quotient of a nonzero rational number and an irra
33. Basis step: n = \ P(l): jc —y divides jc —y is true. tional number is irrational.
Induction step: jc*+i —yk+l = x -xk —y - yk = jc •xk — Proof: Let r = |, a 7^ 0, represent a rational number and
x • yk + jc • yk —y • yk = x(xk —yk) + yk(x —v). This 7, an irrational number. Suppose that ^ is rational, then
rewriting gives an expression where each term is divisible
by jc —y and so the sum is as well.
3c, d € Zsuch that 7 = § = f//. But then ^ = 7; this
is a contradiction.
35. Loop invariant check:
7. A fl B HC = AU 5 U C
Basis step: n = 0 P(0): X - Z0 + W0 = Y is true, be
Proof: A H B O C
cause Z0 = X and W0 = Y.
= A n (B n C) by the associative property of U.
Induction step: LHS of P(ft + 1): X - Zk+l + WM =
X - (Zk - 1) + (Wk - 1) = X - Zk + Wk = Y. = A U (7Tn~C) by De Morgan's law
RHSofP(ft-hl). = ~AU(BUC) by De Morgan's law
Exit condition check: W = 0 X - Z + W = Y yields = AU5 UC by the associative property of U
X-Z = YovZ = X-Y. 9. Let Aj, A2,..., A,„ be m Boolean matrices of the same
37. Loop invariant check: size. Then

Basis step: n = 0 P(0): Z0 + (XxW0) = XxFis true, A, A(A2 v...vAm)


because Z0 = 0 and W0 = K. = (A! a A2) v (A, a A3) v ... v (A! a Am).
Induction step: LHS of P(ft -f 1): Zk+l + (X x Wk+l) =
Proof (by induction):
Zk + X + (X x (Wit - i)) = z* + (X x Wk) = X x y.
Basis Step: n = 3 This is Theorem 5, part 3(a) of Sec
RHSofP(ft-H).
tion 1.5.
Exit condition check: W = 0 Z + (IxW) = Xxr
Induction Step: LHS of P(ft + 1):
yields Z = X x K.
Loop invariant check: A, A(A2v...vAtvAw)
Basis step: n = 0 P(0): Z0 + (X x Y x IV0) = X + K2 = A, A((A2v...vA*)vA*+i)
is true, because Z0 = X x Y and W0 = Y — 1. = ((Aj A A2) v (A, a A3) v • • •
Induction step: LHS of P(fc+1): Zk+l+ (X x Y x Wk+\) = v(Aj AAft))v(A,AAw)
Zk + XxY + (XxYx(Wk-l)) = Zk + XxYxWk = = (Ai a A2) v (Aj A A3) v ... v (Ai a Aft+i).
X + Y2. RHSofP(ft+l). RHSofP(ft-M).
Exit condition check: W = 0 Z + XxKxW = X + y2
yields Z = X + K2. 11. (a) ~(p A q A r) = ^p v ~q V ~r.
39. Loop invariant check: Proof: ^(p A q A r) = ^(p A (q A r))
Basis step: n = 0 P(0): Z0 + (X x W0) = Y + X2 is since a is associative

true, because Z0 = Y and Wo = X. = ^p v ~(q A r)


Induction step: LHS of P(ft + 1): Z*+I + (X x Wk+l) = = ~p V (^q V ~r)
(Zk + X) + (X x (Wi - 1)) = Zk + X x Wk = Y + X2 = ~^p v r^q V /nt
RHSofP(ft-M). (b) ~(pi A p2 A • • • A pn) = ^px V -p2 V • • • V -/?n
Exit condition check: W = 0 Z + (XxW) = y + X2 Basis step: n = 2 ^(pAq) = ~"pv~q by Theorem
yields Z = Y + X2. l,part 11, Section 2.2.
486 Answers to Odd-Numbered Exercises

Induction step: LHS of P(ft + 1): 110 10 0 0 Ax


~(Pi A/?2 A--- Apk Apk+l) 5. Pick A4. 0 0 110 1 1 A2
= ~((/>i A p2 A ••• A pk) A pM) 110 0 1 0 0 A6
= ~(p{ A p2 A -.. A pk) V -p^i Pick A2. [ 1 1 1] A6
= (~/>, v ~/?2 v ... V ~p*) V ~*pM An exact cover is A4, A2, A$.
= -/?! v ^p2 v ... v ~p*+i- RHS of P(ft + 1). 7. [ 1 0 0 0 0 0 0 0 0 0

13. Let A = [ a{j ] and B = [ b{j ] be two r x r diagonal 0 10 0 0 0 0 0 o]


matrices; thus, atj = 0ifi ^ j and bu = 0ifi ^ j. The 9. [ 0 0 0 0 0 0 0 1 0 0
(/-entry in AB is anbij + ai2b2j + ••• + airbrj, but this 0 0 0 0 0 10 0 o]
sum is aubu. Similarly, the (/-entry in BA is haan. Hence,
1 2 3 4
AB = BA.
2 3 4 1
11. One possible solution is
15. recursive dn = dn_\ + 6, d\ = 3; explicit dn = 3(2« - 1) 3 4 1 2
4 1 2 3
17. Basis step: n = 1 3 = 3(2(1) - 1) = 3 • l2 is true.
13. (a) 1. Each of the 81 cells must contain a digit.
Induction step: LHSofP(ft-fl): 3+9+15 + -•-+3(2(ft+
2. Each digit 1 through 9 must appear in each of the
1) - 1) = 3 + 9 + 15 + • • • + 3(2ft - 1) + 3(2ft + 1) =
nine columns.
3ft2 + 6ft + 3 = 3(ft-I-1)2 RHS of P(ft + 1).
3. Each digit 1 through 9 must appear in each of the
19. 1,3,4,7,11,18,29,47,76,123. nine rows.
4. Each digit 1 through 9 must appear in each of the
21. The sums are 1, 4, 8, 15, 26, 44, 73, 120. A reasonable nine 3x3 blocks.
conjecture would be gx + g2 + • • • + gn = gn+2 - 3.
(b) 81; 9 x 9; 9 x 9; 9 x 9 for a total of 324 columns.
23. Proof: Basisstep: n = 1 g2 = 3 = g3 —1 = g2(i)+i —1. (c) 1.(1,1), (1,2), (1,3),..., (1,9), (2,1),..., (9,9)
Induction step: LHS of P(ft + 1): 2. a 1 in column 1, a 1 in column 2,..., a 1 in column
gl + #4 H h g2it + g2(*+l) 9, a 2 in column 1,..., a 9 in column 9
= to+1 _ 1 + g2(JH-l) = g2k+\ + to+2 - 1 3. a 1 in row 1, a 1 in row 2, ..., a 1 in row 9, a 2 in
= to+3 ~ 1 = *2<*+l)+l " I- RHS OfP(ft + 1). row 1,..., a 9 in row 9
25. Proof: Basis step: « = 1 g1 = l=g2-2 = g2(1) - 2 4. a 1 in block 1, a 1 in block 2,..., a 1 in block 9, a
Induction step: LHS of P(ft + 1): 2 in block 1,..., a 9 in block 9
gl + g3 H h g2*-l + g2(*+l)-l 15. (a) (5, 7); 4 in column 7; 4 in row 5; 4 in block 6 (using
= to - 2 + g2(it+i)-i = to + to+i - 2 the numbering of Exercise 13(c) 4)
= to+2 - 2 = ft(t+I) - 2. RHS of P(* + 1). (b) (4,4); 6 in column 4; 6 in row 4; 6 in block 5
27. Further experimentation suggests the conjecture that the 17. (a) A move consists of placing F, I, L, N, P, T, U, V, W,
sum of ft consecutive integers is divisible by ft if and only X, Y, or Z in fi\Q specified squares. Squares may
ifftisodd. be labelled by their positions (1, 1), (1, 2),..., (1, 6),
(2,1),..., (5,6).
Exercise Set 2.6, page 86 (b) One solution is F, I, L, N, P, T, U, V, W, X, Y, Z,
(1, 1), (1, 2),..., (1, 6), (2, 1),..., (5, 6) for a total
1 10 0 10 0 0 0 0
of 42 columns.
0 0 10 10 0 11 0
10 0 0 0 0 0 10 1 19. 2 by 4 21. (a) 6 (b) 4
1. A2, A6, A4. 3.
0 0 0 10 0 10 0 1 23. A move is placing U, D, R, or L in two specified squares.
0010001000 Squares may be labelled by position: (1,1), (1,2),
1 10 0 0 10 0 0 0 (2,1),..., (4, 2).

U D R L (1,1) (1,2) (1,3) (1,4) (2,1) (2,2) (2,3) (2,4)


1 " 1 0 0 0 1 0 0 0 1 0 0 0
2 1 0 0 0 0 1 0 0 0 1 0 0
3 1 0 0 0 0 0 1 0 0 0 1 0
4 1 0 0 0 0 0 0 1 0 0 0 1
5 0 1 0 0 1 0 0 0 1 0 0 0
25.
6 0 1 0 0 0 1 0 0 0 1 0 0
7 0 1 0 0 0 0 1 0 0 0 1 0
8 0 1 0 0 0 0 0 1 0 0 0 1
9 0 0 1 0 0 0 0 0 0 0 1 1
10 0 0 0 1 1 1 0 0 0 0 0 0
Answers to Odd-Numbered Exercises 487

27. Use the matrix from Exercise 25 and choose row 9 for Al 27. (a) 1 5 10 10 5 1
gorithm X.
1 6 15 20 15 6 1
1 10 0 10 0 0 10-
1 7 21 35 35 21 7 1
2 10 0 0 10 0 0 1
5 0 10 10 0 0 10 (b) Begin the row with a 1; write the sum of each consec
6 0 10 0 10 0 0 1 utive pair of numbers in the previous row, moving left
10 0 0 1110 0 0 0. to right; end the row with a 1.
29. Exercise 19 shows another way to express the results of
The two columns of zeros signal that there is no solution Exercise 27(b) and Exercise 28.
using row 9, but row 9 represents an initial placement.
31. (a) 2. (b) 4. (c) 8. 33. 15.
Hence, there is no solultion with this initial placement.
Exercise Set 3.3, page 103
Chapter 3 1. Let the birth months play the role of the pigeons and the
calendar months, the pigeonholes. Then there are 13 pi
Exercise Set 3.1, page 95 geons and 12 pigeonholes. By the pigeonhole principle, at
1. 67,600. 3. 16. 5. 1296. least two people were born in the same month.
7. (a) 0. (b) 1.
1. 3.
n\
9. (a) n\. (b)Y. (O 2
11. 120. 13. 4! or 24. 15. 30.
17. (a) 479,001,600. (b) 1,036,800.
19. 240. 21. 360. mi, m2, m3 are the midpoints of sides AC, AB, and BC,
23. 39,916,800. 25. (n - 1)!. 27. 67,200. respectively. Let the four small triangles created be the pi
geonholes. For any five points in or on triangle ABC, at
29. n . n-{Pn-i =n-(n- \)(n - 2) • • • 2 • 1 = n\ = nPn.
least two must be in or on the same small triangle and thus
31. 190. 33. 2; 6; 12. are no more than | unit apart.
35. (a) 14. (b) 11. 37. 16. (b) 12. 5. By the extended pigeonhole principle, at least [(50 —
Exercise Set 3.2, page 99 1)/7J + 1 or 8 will be the same color.

1. (a) 1. (b) 35. (c) 4368.


7. Let 2161 cents be the pigeons and the six friends, the pi
geonholes. Then at least one friend has [(2161- 1)/6J +1
n\
^ C — —

r
n^n— /-• or 361 cents.
r\(n-r)\ (n - (n - r))\(n - r)\
9. If repetitions are allowed, there are \6C5 or 4368 choices.
5. 20,358,520.
At least [4367/175J -I- 1, or 25, choices have the same
7. (a)l. (b)360. cost.

9. (a) One of size 0, four of size 1, six of size 2, four of size 11. You must have at least 49 friends.
3, and one of size 4.
13. Consider the first eight rows; one row must have at least
(b) For each r, 0 < r < n, there are nCr subsets of size r. 7 ones since there are 51 ones in all. Similarly, there is a
11. (a) 980. (b)1176. column with at least 7 ones. The sum of the entries in this
row and this column is at least 14.
13. 2702.
15 Label the pigeonholes with 1, 3, 5,..., 25, the odd num
15. Because three people can be arranged in only one way
bers between 1 and 25 inclusive. Assign each of the se
from youngest to oldest, the problem is to count the num
lected 14 numbers to the pigeonhole labeled with its odd
ber of ways to choose three people from seven.
part. There are only 13 pigeonholes, so two numbers must
17. 177,100 (repeats are allowed). have the same odd part. One is a multiple of the other.
n\ n\
19. nCr.l+nCr = + • 17, Using an argument similar to that for Exercise 16, the sub
(r-l)\(n-(r-l))\ r\(n-r)\ set must contain atleast L^J + 1elements.
n\r + n\ (n - r + 1) _ n\ (n + 1)
19. No. At least one pair of the 12 disks must add up to 21.
r!(w-r + l)! " r\(n + \-r)\
(n + D! _ r 21, Consider the six sums c\, c\ + c2, c\ + c2 + c3, ...,

r!(rc + l -r)!
— w+1 W« c\ + c2 + c3 + C4 + c5 + C6. If one of these has remainder
0 when divided by 6, then we are done. If none have re
21. (a) 32. (b) 5. (c) 10.
mainder 0 when divided by 6, then two of them must give
23. (a) 2\ (b) „C3 (C) nCk. the same remainder. The positive difference of these two
25. 525. is a subsequence whose sum is divisible by 6.
488 Answers to Odd-Numbered Exercises

23. We consider the cases of 3 or more ones, 2 ones, 1 one, and Exercise Set 3.5, page 117
no ones. If there are at least 3 ones, we are done. If there
1. 4,10, 25, 62.5. Yes, degree 1.
are 2 ones and no two, then the sum is at least 1 + 1+4-3,
but this is not possible. So if there are 2 ones, there is at 3. 3, 12, 24,48. No.
least 1 two and we are done. If there is 1 one and no twos, 5. 1,8,43,216. No.
then the sum is at least 1+53. This is impossible. If
7. si =2,s2 = 3, sn = sn-i + 1.
there are no ones and no three, then the sum is 6 • 2 or at
least 5-2 + 5. But again, neither of these is possible. 9. A, = 100 (1 + ^f), An = (1 + ^f) (A„_! + 100).
25. There need to be at least 40 connections. If one printer has 11. Cn = Cn_2 + C„_3, C\ = 0, C2 = 1, C3 = 1.
seven or fewer connections to PCs, then there can be a set 13. ^=3-5w-1 + |(5w-1-l).
of 5 PCs requesting printer access, but only four printers
are available.
15. dn=5(-l.l)n-1.
17. g„=n!-6.
Exercise Set 3.4, page 110
19. bn = (-2)".
1. {HHH, HHT, HTH, THH, HTT, THT, TTH, TTT}.
21.dB = -|-2» + f -n-2\
3. {sb, sr, sg, cb, cr, eg}.
23. gn = =1=2(1 +i)» + =!±2(1 - i)\
5. (a) { }, {1}, {2}, {3}, {2,3}, {1, 2}, {1,3}, {1,2, 3}.
27. (a) an = 2aB_i + 1, ax = 0. (b) a„ = 2n~l - 1.
(b) 2\
7. (a) The card is a red ace.
'. a=2, c2 =3, cn =i< (i±^)n +v(^)", n=
29, 5+3V5
10 '

(b) The card is black or a diamond or an ace. u 10 •


31. For n > 2, /„2+1 - /n2 = (/B+1 - /B)(/B+1 + /„) =
9. (a) {(5,1), (5,2), (5, 3), (5,4), (5, 5), (5, 6),
fn-ifn+2, by the definition of fk.
(1,5), (2, 5), (3, 5), (4, 5), (6, 5)}.
33. Ai = 100.5.
(b) { }.
An = (LOOSy-'dOaS) + 20,100[(1.005r-1 -1]-
11. (a) No, 3 satisfies both descriptions.
(b) No, 2 satisfies both descriptions.
35. an =-2(-2)"+(| - V2) (V2)n+(| +V2) (-V5)".
37. Basis step: n = 0 P(0): 5 | «i is clearly true.
(c) Yes, £UF = {3,4,5, 1,2,3}.
Induction step: We use P(&): 5 | a3k+l to show P(k + 1):
(d) No, E H F = {3}. 5 I fl3(ik+i)+i. Consider a3(jk+1)+1 = 2a3(k+l) + a3k+2 =
13. (a) No. (b) No. (c) No. (d) Yes. 2(2a3k+2 + a3k+{) + a3Jfc+2 = 5a3k+2 + 2a3Jk+1. Clearly
5 I 5a3k+2 and P(^) guarantees 5 | a3M.
15. (a) {dls,dln,dms,dmn,dus,dun,als,aln}.
39. Cn = CC^! + C2C„_2 + - - - + Cn-xCu d = 1.
(b) {als,aln}.
(c) {dls,dln,als}. Chapter 4
17. E U F = {2, 6, 3}, F n G = {4}. Exercise Set 4.1, page 126
19. {club}, {spade}, {diamond}, {heart}. 1. (a) jc is 4. (b) y is 3.
21. (a) if. (b) ii. (c) |f. (d) ±. 3. (a) x is 4; y is 6. (b) x is 4; y is 2.
23. (a) 0.7. (b) 0. (c) 0.7. (d) 1. 5. (a) {(a, 4), (a, 5), (a, 6), (*, 4), (*, 5), (*, 6)}.
25. p(A) = £, p(B) = ±, p(C) = ± p(D) = i (b) {(4, a), (5, a), (6, a), (4, b), (5, b), (6, *)}.

27. g. 7. (a) {(Fine, president), (Fine, vice-president),


(Fine, secretary), (Fine, treasurer), (Yang, president),
29. (a) |. (b)l. (Yang, vice-president), (Yang, secretary),
(Yang, treasurer)}.
31. (a) |i. «!• (0 £. (d)
21
36-
(b) {(president, Fine), (vice-president, Fine),
33. (a) ||. (b)l- V.V 220' (d)
210
220 (secretary, Fine), (treasurer, Fine), (president, Yang),
35. (a) £. (vice-president, Yang), (secretary, Yang),
(b)|- (treasurer, Yang)}.
37. " + 1. 39. -ii dollars. (c) {(Fine, Fine), (Fine, Yang), (Yang, Fine),
(Yang, Yang)}.
41.(a)A.i (b)i.A 9. gs, ds, gc, dc, gv, dv.
Answers to Odd-Numbered Exercises 489

11. (Outline) Basis step: n = 1. P(l): If \A\ = 3 and \B\ = 39. Let {#i, #2, - - -, Bm] be a partition of 5. Form the set
1, then \A x B\ = 3. A x B = {(ax,bx), (a2, bx), (a3, bx)}. [Bx O A, 52 H A,..., Bm O A}. Delete any empty inter
Clearly, |Ax B\ = 3. sections from this set. The resulting set is a partition of A.
Induction step: Suppose \B\ = k > 1. Let jc g B and If a g A, then a e B. We know that as an element of B,a
C = B - {jc}. Then \C\ = k - 1 > 1 and using P(fc), is in exactly one of the #, and hence in exactly one of the
we have \A x C\ = 3(A: - 1). |A x {jc}| = 3. Since Bi fl A.
(AxC)D(Ax{jc}) = { }and(AxC)U(Ax{jc}) = AxB, 41. (a) Number of subsets in partition
\AxB\ = 3(k-l) + 3or3k. # of elements 12 3 4 5 6
13. 1
2 1 1
(3,5) 3 1 3 1
4 1 7 6 1
(2, 1 5 1 15 25 10 1

C) 6 1 31 90 65 10 1
(2, C) (b) It appears that each entry in the S(n, 2)-column can
be calculated as 2n~l — 1.

(3,-4) Exercise Set 4.2, page 134


1. (a) No. (b) No. (c) Yes.
15.
(d) Yes. (e) Yes. (f) Yes.
3. (a) No. (b) No. (c) Yes.
(d) Yes. (e) No. (f) Only if 7i = 1
5. Domain: {daisy, violet, rose, daffodil},
Range: {red, pink, purple, white};
10 0 0 0 0 0
0 0 10 0 0 0
0 0 0 0 0 10
0 10 0 0 0 0
17. Let (jc, y) e Ax B, then x e A and y e B. Since A c C 0 0 0 0 0 0 0
and 5 c D, x e C and y e D. Hence (jc, y) g C x D. 7. Domain: {1, 2, 3,4, 8}, Range: {1, 2, 3,4, 8};
19. One answer is project(select Employees [Department =
Human Resources]) [Last Name]. 0
10
10
0 0
0
0
0
(9 (9
0 0 10 0
21. One answer is project(select Employees[Department =
0 0 0 10
Research]) [Years with Company].
0 0 0 0 1
23. (a) Yes. (b) No.
9. Domain: {1,2, 3,4,6}, Range: {1,2, 3,4, 6};
25. An exact cover of T must consist of subsets chosen from
a specified collection of subsets of T. A partition of T
may use any subsets of T. In both cases, the union of the 10 0 0 0
subsets must form T. 110 0 0

27. Answers will vary. 10 10 0


110 10
29. No. |A|=26. 1110 1

31. {{1},{2},{3}}, {{1}, {2,3}}, {{2}, {1,3}}, {{3}, {1,2}},


{{1,2,3}}.
11. Domain: {3, 5, 7,9}, Range: {2,4, 6, 8};
33. 3. There are three 2-element partitions listed in the solu ro o 0 01
tion to Exercise 31. 1 0 0 0
35. 6. l l 0 0
l l 1 0
37. Let (jc, y) e Ax (BUC). Then jc g A, y e BUC. Hence Li i 1 1_
(jc, y) G A x B or (jc, y) G AxC. Thus A x (B U C) C
. (a) No. (b) No. (c) Yes
(A x B) U (A x C). Let (jc, y) G (A x B) U (A x C).
Then xe A, yeB or yeC. Hence y g B U C and ( d) Yes. (e ) No. (f) No.
(jc, y) G A x (BUC). So, (A x £)U(A x C) c A x (BUC). 15. Dom(R) = [-5, 5], Ran(fl) = [-5, 5].
490 Answers to Odd-Numbered Exercises

17. (a) {1,3}. (b) {1,2,3,6}. (c) {1,2,4,3,6}. 11. (a) a, c, d, c a, c, d, b a, c, e, f a, b, b, b


19. (a) {3}. (b){2,4}. (c){3,2,4}. (d){2,4). a,b,b,f a,b,f,d.

21. a R b if and only if 0 < a < 3 and 0 < b < 2. (b) In addition to those in part (a), b, b, b, b
b,b,b,f b,b,f,d b,f,d,b b,f,d,c
23. R = {(1,1), (1,2), (1,4), (2,2), (2,3), (3,3),
c,d,c,d c,d,c,e c,d,b,b c,d,b,f
(3,4), (4,1)}.
c, e, f d d, c, d, c d, c, e, f d,b,b,b
d,b,b,f d,b,f,d d,c,e,f e, f d, b
e, f, d, c f, d, c, d f, d, c, e fd,b,b
fd,b,f.
13. One is d, b, f, d.
15.

25. * = {(!, 2), (2, 2), (2, 3), (3,4), (4,4), (5, 1), (5,4)}.
0 1 0 0 0
0 1 1 0 0
0 0 0 1 0
0 0 0 1 0
1 0 0 1 0

27. Vertex 1 2 3

In-degree 12 13 0
Out-degree 12 112 ro i l 1 1 1

29. The in-degree of a vertex is the number of ones in the col 0 l l 1 1 1

umn labeled by that vertex. The out-degree of a vertex is 0 l l 1 1 1


17. (a)
the number of ones in the row labeled by that vertex. 0 l i 1 1 1
0 i l 1 1 1
31. {(2, 3), (3, 6)}.
l_o i i 1 1 1
33. Delete any vertex labeled by an element of A —B. Then
(b) {(a, c), (a, d), (a, b), (a, e), (a, f), (b, b),
delete any edges that do not point to a vertex.
(b,c),(b,d),(b,e),(b,f),(c,b),(c,c),
35. (a) The elements of R(ak) are those elements of A that (c, d), (c, e), (c, f), (d, b), (d, c), (d, d),
can be reached from ak in one step. (d,e),(d,f),(e,b),(e,c),(e,d),(e,e),
(b) The elements of R({ax, aj,an}) are those elements of (e, f), (/, b), (f, c), (f d), (f e), (/, /)}.
A that can be reached from ax, aj-, or a„ in one step.
19. X( R* Xj if and only if jc, = jc, or jc/ Rn xj for some n.
37. 2mn. The /, jth entry of MR* is 1 if and only if / = j or the
Exercise Set 4.3, page 140 /, jth entry of MRn is 1 for some n. Since R°° = U Rk,
1. 1,2 1,6 2,3 3,3 3,4 4,3 4,5 4,1 6,4. the /, jth entry of MR* is 1 if and only if / = j or the
3. (a) 3, 3, 3, 3 3, 3,4, 3 3,3,4,5 3,4,1,6
/, yth entry of M^oo is 1. Hence MR* = I„ v M/?oo.
3,4,1,2 3,4,3,3 3,4,3,4 3,3,4,1 21. 1,7,5,6,7,4,3.
3, 3, 3, 4.
23. 2, 3, 5, 6, 7, 5, 6,4.
(b) In addition to those in part (a), 1, 2, 3, 3
1,2,3,4 1,6,4,1 1,6,4,5 2, 3, 3, 3 25. 7,4, 3, 5, 6,7 is an answer.
2,3,3,4 2,3,4,3 2, 3, 4, 5 4,1,2,3 27. The ij -entry of MR • MR is the number of paths from i to
4,1,6,4 6,4,3,3 6, 4, 3, 4 6,4, 1,2 j of length two, because it is also the number of £'s such
6,4,1,6 1,6,4,3 2,3,4,1 4, 3, 3, 3 that aik = bkj = 1.
4, 3,4, 3 4, 3, 4, 1 4, 3, 4, 5 4, 3, 3, 4.
29. Direct; Boolean multiplication.
5. One is 6, 4, 1, 6.
31. Suppose each vertex has out-degree at least one. Choose a
"0 0 1 10 0"
0 0 110 0
vertex, say u,-. Construct a path R u,, vi+x, vi+2, — This
10 1110
is possible since each vertex has an edge leaving it. But
7. there are only a finite number of vertices so for some k
0 1110 1
0 0 0 0 0 0
and j, Vj = vk and a cycle is created.
_1 0 1 0 1 0_ 33. The essentials of the digraph are the connections made by
9. a,c a,b b,b b, f c, d c,e d,c d, the arrows. Compare the arrows leaving each vertex in
t ?,/ fd. turn to pairs in R with that vertex as first element.
Answers to Odd-Numbered Exercises 491

Exercise Set 4.4, page 146 17. {{..., -3, -1, 1, 3, 5,...},{..., -4, -2, 0, 2,4,...}}.
1. Reflexive, symmetric, transitive. 19. (a) R is reflexive because a2 + b2 = a2 + b2. Ris clearly
3. None. symmetric. R is transitivebecauseif a2+b2 = c2-\-d2
5. Irreflexive, symmetric, asymmetric, antisymmetric, transi and c2 + d2 = e2 + /2, certainly a2 + b2 = e2 + f2.
tive. (b) The equivalence classes ofA/R are circles with center
7. Transitive. at (0, 0), including the circle with radius 0.
9. Antisymmetric, transitive. 21. (a) (a, b) R (a, b) because ab = ba. Hence R is reflex
11. Irreflexive, symmetric. ive. If (a, b) R (a', V), then aV = ba!. Then a'b =
b'a and (af, b') R (a,b). Hence R is symmetric. Now
17. Symmetric. suppose that (a, b) R (af, b') and (a', b') R (a", b").
19. Reflexive, symmetric, transitive. Then ab' = ba! and a'b1' = b'a".
21. Reflexive, symmetric, transitive.
b'a" a" a"
23.
ab» = a°±- = ab>°- = te'i. = ba".
a' a' a'
[5) -^ r,
Hence (a, b) R (a", b") and R is transitive.
(b) {{(1, 1), (2, 2), (3, 3), (4,4), (5, 5)}, {(1, 2), (2,4)},
{(1,3)}, {(1,4)}, {(1,5)}, {(2,1), (4, 2)},
25. {(1, 5), (5, 1), (1, 6), (6, 1), (5, 6), (6, 5), (1, 2), {(2, 3)}, {(2, 5)}, {(3,1)}, {(3, 2)}, {(3,4)},
(2,1), (2, 7), (7, 2), (2, 3), (3, 2)}. {(3, 5)}, {(4,1)}, {(4, 3)}, {(4, 5)}, {(5,1)},
27. Let ax, a2,..., an be the elements of the base set. The {(5, 2)}, {(5, 3)}, {(5,4)}}.
graph of R is connected if for each a,, there is a 1 in the
23. Let R be reflexive and circular. If a R b, then a R b and
/thcolumn of (M/?)^ for some k. b R b, so b R a. Hence R is symmetric. If a R b and
29. Let R be transitive and irreflexive. Suppose a R b and b Re, then c R a. But R is symmetric, so a R c, and R is
b R a. Then a R a since R is transitive. But this contra transitive.
dicts the fact that R is irreflexive. Hence R is asymmetric.
Let R be an equivalence relation. Then R is reflex
31. Let R ^ { } be symmetric and transitive. There exists ive. IfaRb and b R c, then a R c (transitivity) and c R a
(jc, y) e R and (y, x) e R. Since R is transitive, we have (symmetry), so R is also circular.
(jc, jc) g R, and R is not irreflexive.
25. a R b if and only if ab > 0.
33. (Outline) Basis step: n = 1 P(l): If R is symmetric,
then Rl is symmetric is true. 27. If z is even (or odd), then R(z) is the set of even (or odd)
Induction step: Use P(&): If R is symmetric, then Rk is integers. Thus, if a and b are both even (or odd), then
symmetric to show P(k +1). Suppose thata Rk+] b. Then R(a) + R(b) = {jc \x = s + t,s € R(a),t e R(b)} = {jc |
there is a c e A such that a Rk c and c R b. We have jc is even} = R(a + b). If a and b have opposite parity,
b R c and c Rk a. Hence b Rk+l a. then R(a) + R(b) = {x \x =s + t, s e R(a), t e R(b)}
= {jc I jcisodd} = R(a + b).
35. (a) One answer is {(a, a), (b, b), (c, c), (d, d)}.
(b) One answer is {(a, a), (b, b), (c, c), (d, d), (a, b)}. 29. (1, 2) R (2,4) and (1, 3) R (1, 3), but
((1, 2) + (1, 3)) g ((2, 4) + (1, 3)) so the set R((a, b)) +
37. (a) One answer is {(a, a), (b, b), (c, c), (d, d)}.
R((a',b')) is not an equivalence class.
(b) One answer is {(a, b), (b, c), (a, c)}.
Exercise Set 4.6, page 158
Exercise Set 4.5, page 151
1. Yes. 3. Yes. 5. No. 1. VERTfl] = 9 (1,6) NEXT[9] = 10 (1,3)
NEXT[10] =1 (1,2) NEXT[1] = 0
7. No. 9. Yes. 11. Yes.
VERT[2] = 3 (2,1) NEXT[3] = 2 (2,3)
13. {(a, a), (a, c), (a, e), (c, a), (c, c), (c, e), (e, a), NEXT[2] = 0
(e, c), (e, e), (b, b), (b, f), (b, d), (d, b), (d, d), VERT[3] = 6 (3,4) NEXT[6] = 4 (3,5)
(d,f),(fb),(fd),(ff)}. NEXT[4] = 7 (3,6) NEXT[7] = 0
15. {(1, 1), (2, 2), (3, 3), (4,4), (5, 5), (6, 6), (7, 7), (8, 8), VERT[4] = 0
(9, 9), (10, 10), (1, 3), (3, 1), (1, 5), (5,1), (1, 7), (7, 1), VERT[5] = 5 (5,4) NEXT[5] = 0
(1, 9), (9, 1), (3, 5), (5, 3), (3, 7), (7, 3), (3, 9), (9, 3), VERT[6] = 8 (6, 1) NEXT[8] = 0
(5, 7), (7, 5), (5, 9), (9, 5), (7, 9), (9, 7), (2,4), (4, 2), 3. On average, EDGE must look at the average number of
(2, 6), (6, 2), (2, 8), (8, 2), (2, 10), (10, 2), (4, 6), (6, 4), edges from any vertex. If R has P edges and N vertices,
(4, 8), (8, 4), (4, 10), (10, 4), (6, 8), (8, 6), (6, 10), y\ p.. p
(10, 6), (8, 10), (10, 8)}. then EDGE examines — = — edges on average.
492 Answers to Odd-Numbered Exercises

VERT TAIL HEAD NEXT (c) {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4),
1110 1 1 1 2 (3,1), (3,2), (3,4), (4,1), (4,4)}.
0 0 11 4 1 2 3 (d) {(1,1), (2,1), (2,2), (1,4), (4,1), (2,3), (3,2),
10 0 1 6 1 3 0 (1,3), (4,2), (3,4), (4,4)}.
0 10 0 8 2 3 5
2 4 0 (a) {(1,1), (1,4), (2,2), (2,3), (3,3), (3,4)}.
3 1 7 (b) {(1,2), (2,4), (3,1), (3,2)}.
3 4 0
4 2 0 (c) {(1,1), (1,2), (1,3), (1,4), (2,1), (2,4), (3,1),
(3,2), (3,3)}.
(d) {(1,1), (2,1), (4,1), (4,2), (1,3), (2,3), (3,3)}.
ro o on rl i in
0 110 0 0 1 l i l
11. (a) (b)
0 110 0 0 0 1 i l
7.
0 0 0 1 Li o lJ Li i lJ
10 11
-i 0 l-
"l o o r
0 1 0
(c) 0 110 • (d)
0 1 0
9. VERT TAIL HEAD NEXT 110 1
.0 0 0.
1 1 2
ro o o on ri 1 i on
1 4 0
0 0 10 0 0 1 0
2 2 4 13. (a) • (b)
10 0 0 l 1 0 0
2 3 0
3 4 0
Lo o o oj Lo 1 i i J
4 1 7 ri o 1 on ri 0 l in
4 3 8 0 0 0 1 l 1 0 1
4 5 0
(c) . (d)
110 0 0 0 l l
5 2 10 Lo 0 0 l j Li 1 0 lJ
5 5 0
15. RDS = {(a, a), (b, b), (b, c), (c, b), (c, c), (d, d), (e, e)},
11. VERT TAIL HEAD NEXT {{a},{b,c},{d},{e}}.
a a 2 17. (a) {(a, a), (a, d), (a, e), (b, b), (b, c), (b, e), (c, a),
a b 3 (c, b), (c, c), (d, b), (d, c), (d, d), (e, c), (e, e)}.
a d 0
(b) {(a, a), (a, d), (d, a), (a, e), (e, a), (b, c), (c, b),
b b 5
(b, e), (e, b), (c, a), (a, c), (c, c), (d, b), (b, d), (d, c),
b c 0
(c,d), (e,c), (c,e),(e,e)}.
c b 7
c c 8 19. The definitions of irreflexive, asymmetric, and antisym
c d 0 metric each require that a certain pair does not belong to
d a 10 R. We cannot "fix" this by including more pairs in R.
d b 11
21. (a) Yes. (b) Yes.
d c 12
d d 0 (c) x (S o R) y if and only if x < 6y.

Exercise Set 4.7, page 167 23. (a) Reflexive, a R a A a S a => a S o R a.


Irreflexive. No. li?2A2Sl=>lSoi?l.
1. (a) {(1,3), (2,1), (2,2), (3,2), (3, 3)}.
Symmetric. No. 1 R 3, 3 R 1, 3 S 2, 2 S 3 =>
(b) {(3,1)}. 1 S oR 2, but 2S*rfC\.
(c) {(1,1), (1, 2), (2,1), (2, 3), (3, 1), (3,2), (3, 3)}. Asymmetric. No. R = {(1,2), (3,4)} and S =
(d) {(1,2), (1,3), (2,3), (3,3)}. {(2, 3), (4,1)} provide a counterexample.
Antisymmetric. No. R = {(a, b), (c, d)} and S =
{(a, b) | a, b are sisters or a, b are brothers}.
{(b, c), (d, a)} provide a counterexample.
a (R U S) b if and only if a is a parent of b. Transitive. No. R = {(a, d), (b, e)} and S =
(a) {(2,1), (3,1), (3,2), (3,3), (4,2), (4,3), {(d, b), (e, c)} provide a counterexample.
(4,4), (1,4)}. (b) No, symmetric and transitive properties are not pre
(b) {(1, 1), (1,2), (2,2), (2, 3), (2,4), (4,1), (3,4)}. served.
Answers to Odd-Numbered Exercises 493

1 1 0 1 1 (c) Suppose R is asymmetric. Let (jc,y) e R D R~l.


0 1 0 1 1 This contradicts the fact that R is asymmetric. Hence
25. (a) 1 0 1 1 RDR-1 = 0. Let jc R y and y R jc. Then (jc, y) e
1 0 1 1 R n R~] =0. Hence R is asymmetric.
1 0 0 1

0 1 1 1
Exercise Set 4.8, page 174
1 0 1 1
(b) 0 1 1 1 1 1 1
1 1 1 1 1. (a) 1 1 1
0 0 0 1 1 1 1 1

1 0 1 1 (b) {(1,1), (1,2), (1,3), (2,1), (2, 2), (2, 3),


1 0 0 1 (3,1), (3, 2), (3, 3)}.
(c) 0 1 0 1 1
1 0 1 1 10 0 10
1 0 0 1 0 10 0 0
3. Wx = 0 0 0 11 , w2 = w, = w3.
1 1 1 1
10 0 10
0 1 1 1
0 10 0 1
(d) 1 0 1 1
1 1 1 1
5. a R°° b if and only ifb>a.
0 1 0 1 1

27. RDS is antisymmetric. If a(R n S)b and b(R 0 S)a, then 7. Let R be reflexive and transitive. Suppose that x Rn y.
a R b and b R a. Hence a = b because R is antisymmet Then x,ax,a2,..., an-X, y is a path of length n from jc
ric. R U S may not be antisymmetric. Let R = {(1,2)}, to y. x R ax A ax R a2 =$> x R a2. Similarly, we have
S = {(2,1)}. x R ak A ak R ak+x => x R ak+x and finally jc R an-X A
an-x Ry =» x Ry. Hence Rn c R. If jc R y, then
29. Let R = {(jc, z), (jc,m)}, S = {(z, y)}, and T = {(m, y)}.
since R is reflexive we can build a path of length n,
Then (jc, y) € (S o R) 0 (T o R), but (S D T) o R = { }.
jc, jc, jc, ..., x, y from jc to y and jc Rn y.
31. (a) Let MRns = [m,7 ], MR = [ ru ], M5 = [ sy ].
mu = 1 if and only if (/, j) e R n S. (i, j) e R 10 0 1
if and only if r/y = 1 and (i, j) e S if and only if 110 1
S{j = 1. But this happens if and only if the /, jth entry 0 0 10
ofM/? aM5 is 1. 0 0 0 1

(b) Let MRUS = [mu ], MR = [ru ], Ms = [su ]. 10 0 1


ntij = 1 if and only if (/, j) e RU S. (i, j) e R if and 0 110
only if rtj = 1 or (/, j) e S if and only if s{j = 1. But 11.
0 110
this happens if and only if the i, jth entry of M^ VMs 10 0 1
isl.

(c) The i, jth entry of M^-i is 1 if and only if (/, j) e 13. The sets are the same. This can be shown by computing
R~l if and only if (j, i) € R if and only if the j, ith each set.
entry of MR is 1 if and only if the /, 7th entry of MTR
15. Ax A.
isl.

(d) The i, jth entry of Mj is 1 if and only if (/, j) € R if 17. A/R = {{1,2, 3}, {4, 5}}, A/S = {{1}, {2, 3,4}, {5}},
and only if (i, j) £ r if and only if the i, jth entry of A/(R U S)°° = {A}.
MR is 0 if and only if the /, yth entry of M^ is 1.
33. To form the digraph of R~\ reverse the arrows in the di 19. The collection of elements in A/R and A/S can be sepa
graph of R. rated into subcollections of nondisjoint sets. Each element
of A/(R U S)°° is the union of the sets in one of these
35. The edges of the digraph of RUS are the edges that appear subcollections.
on either the digraph of R or the digraph of S.
37. (a) R is symmetric if and only ifjc/?y=^y/?jcif and 21. {(1, 1), (1, 2), (1,4), (2, 2), (3, 2), (3, 3), (4, 2),
only if R c R~l c R. (4, 3), (4, 4), (1,3)}.

(b) Suppose R is antisymmetric. Let (jc,y) e R Pi R~l, 23. We first show R°° is transitive. Then we show it is the
then x = y and (jc, y) € A. Suppose R D R~l c A. smallest relation that contains R. It is a direct proof.
If jc R y and y R x, then x R y and jc R~{ y. Thus
(x, y) € A, sojc = y. 25. R x E.
494 Answers to Odd-Numbered Exercises

Chapter 5 Exercise Set 5.2, page 197

Exercise Set 5.1, page 188 1. (a) 7. (b) 8. (c) 3.


1. (a) Yes. Ran(#) = {1,2}. (b) No.
3. Yes.
3. (a) 1. (b) 0. (c) 1.

5. Each integer has a unique square that is also an integer.


5. (a) 2. (b) -3. (c) 14.
7. Each r e R is either an integer or it is not.
(d) -18. (e) 21.
9. (a) 3. (b) 1. (c) (x-\)2.
(d)*2-l. (e) y-2. (I) /. 7. n — ak + r,0 < r < n. Since/: < 2k < 3k < • • • < ak <
11. (a) Both. (b) Neither. n the number of multiples of k between 1 and n is a. But
13. (a) Both. (b) Onto. f=a + ^withO<^<lsoL?J=«.
15. (a) Both. (b) Onto.
9. (a) 26. (b) 866. (c) 74. (d) 431.
17. Neither.

19.W(go/)(fl) =g(i^)=2(i±l)-l=«. 11. (a) 2. (b) 8. (c) 32. (d) 1024

(b) (g o f)(a) = g(a2 - 1) = J a2 + 1 - 1 = \a\ = a, 13. (a) 4. (b) 7. (c) 9. (d) 10.
since a > 0.

21. (a) /"• (*) = b2 - 1. (b) f~x(b) = ^^T. 15. (a) 5; 6. (b) 6; 7.

23. (a) Suppose f(x, y) = /(w, z). Then 2jc —y = 2w —z


andjc—2y = w—2z. Solving this system of equations 17. For any 2x2 matrix M, MT exists so t is everywhere de
gives x = w, y = z. Therefore, / is one to one. fined. If M is a 2 x 2 matrix, then t(MT) = M, so t is
onto. SupposeMT = Nr. Then (MT)T = (NT)T; that is,
(2x
f2x —y x —2yN
—2y \ M = N and / is one to one.
(b) f~l(x,y)
3

25. Yes. 27. nn. 29. nm. 19. Every relation R on A defines a unique matrix MR so / is
31. C; B; because g is onto; A; because / is onto. everywhere defined and one to one. Any n x n Boolean
matrix M defines a relation on A so / is onto.
33. Suppose g o f is onto. Let c e C. Then 3a e A such that
(8 o /)(a) = c. But (* o f)(a) = g(/(fl)), /(«) € B, so
g is onto. . JC y z f(x,y,z)
T T T T
35. (a) Let Dom(/) = {ax,a2,... ,an}. Then Ran(/) = T T F F
{/(^i), /(fl2>. • • • >f(a„)}. Since / is one to one, the T F T T
f(a{) are all distinct, so Ran(/) has n elements. Thus T F F F
m = n.
F T T T

(b) If / is not one to one, some f(a{) = f(aj) and F T F T


m < n. F F T T
F F F F
37. One one-to-one correspondence is /: Z+ -• 5, where
f(z) = 2z.
23. (a) True. (b) False, (c) False, (d) True.
39. Yes, the cardinality of a set is determined by creating a
one-to-one correspondence between the set and a subset
25. (a) 31. (b) 0. (c) 36.
of Z+. Here we use all of Z+.

41. (a) and (b). Consider the table for o.

o 0 1
0 0 1
1 1 0 29. /"' (1) is the set of elements of A.

Since f(0) = true and f(\) = false, we see this is not the 31. (a) |. (b) if.
table for either v or A.
W *>•
43. JCCGKFMNUQPJKNFEQKJUM. 33. (a) 3 and 9. (b) 4 and 8.
Answers to Odd-Numbered Exercises 495

35. with N > c- lg(N). Then N2 < c >N - lg(N) < N2, a
f or 0 < jc < 2
contradiction.
iJC - 1 for 2 < jc < 2 -j- V3
(x-3)2 9. |5n2 + 4/2 + 3| < \5n2 + 500/11, n > 1; |5n2 + 500n| <
1-
4
for 2 + V3 < x < 5 5|/z2 + 100n|. We have \n2 + 100/i| = \n2 + 4 . 25n| <
0 f or 5 < jc < 7 |/i2 + 4n2|, n > 25. But |5n2| < |5n2 + An + 3|.
(x- 7)2
for 7 < jc < 6 + yfi 11. {/si, {/6, /io, ful {fil Ml {/g}, {/iK [fi], {/sK {/<>},
\x + 5 for6 + \/7 <jc < 10 {/12}.
13. /,, ®(nlgn); f2, 0(n2); /4, G(lgn); f5, 0(1); /6, 0(n);
/io,e(n);/n,©(n).
15. f(n) = 2 + 4 • 5 + 1 or f(n) = 23. 0(1).
17. /(/i) = l+n-2. 0(n).
19. /(n) = 2+ 2n + 5^. 0(n2).
21. f(n,m,q) = \+nq+3nmq+\. Let Af = max(n,m, q),
then/is0(N3).
23. (a) Pn = Pn-X + (n-2) + (n-3),P3 = l,P4=4.
(b) 0(n2).
37. (_2 +4V2,^). 25. Suppose h(n) > 0, Vn, 0(/) lower than (or the same as)
©(*). I/(«)I < c • |g(n)|, n > * (and |g(n)| < <* • |/(n)|,
39. (a) §. (b) I. « > /)• h(n)\f(n)\ < c • A(/i) • |g(n)|, n > * (and
41. (a) Proof: IfxeAHB, then /An*(*) = 1 and fA(x) = A(n)l*(n)l < d-h(ny\f(n)\,n > I). Hence |/(n)-n(n)| <
1 = fB(x) = min{/A(jc), fB(x)}. But if jc i A n £, c-te(n)-A(n)|,/i>ifc(and|^(/i).A(n)l<rf-l/(n)-AWI,
then /^niK*) = 0 and either fA(x) = 0 or /s(jc) = 0. n > /). Hence 0(//i) is lower than (or the same as)
Thus, vmn{fA(x), fB(x)} = 0 = /W*). S(gh). Note that if 0(/) is strictly lower than 0(g), then
0(/n) must be strictly lower than S(gh).
(b) Proof: If jc e A U B, then fAUB(x) = 1
and either fA(x) = 1 or fB(x) = 1. Hence, 27. There exist cx, kx such that |/(n)| < cx\g(n)\, Vn > &i,
max{/A(x), fB(x)} = 1 = /W*). If x $ A U B, so |c/(n)| = |c| • \f(n)\ < cx\c\ . |g(n)|, Vn > *,. Also,
then fAUB(x) = 0 and fA(x) = /*(*) = 0 = there exist c2, k2 such that \g(n)\ < c2\f(n)\, Vn > k2 and
max{fA(x), fB(x)}. so |g(n)| < c2\f(n)\ = g . |c/(n)|f yn > fe.
(c) Proof: If jc € A, then fA(x) = 1 and fA(x) = 0. So 29. |r/(n)| < \r\-\f(n)\,n > l,sor/is 0(/). Choosecsuch
jfrto = 1 - fA(x). If jc i A, then yftjc) = 0 and thatc- \r\ > 1, then \f(n)\ < c- \r\ • |/(n)| = c- |r/(n)|,
/4(jc) = land/x(jc) = l-/A(jc). n > land/isO(r/).
43. (); (()), ()(); ((())), (())(), (()()), ()(()), ()()(); Exercise Set 5.4, page 211
d = 1, C2 = 2, C3 = 5.
1. (a) Yes. (b) No. 3. (a) Yes. (b) No.
45. Because there are more right than left parentheses; one 2 3 4 5 6'
less; n left and n right. sxs2 • • •s2n is not well formed since
in sxs2 • ••,?* there are more right than left parentheses.
"0
5. (j
3 4 12 6 5 >
47. 2nCn —2nCn-X. (b)
49. (a) 0 + 2 + 9 + 0 + 40 + 18 + 7 + 32 + 27 = 135;
135 + 30= 165 or 0 (mod 11).
(b) (i) 9. (ii) X. (iii) 5. (iv) 3.
7. (a)
(I ?>
Exercise Set 5.3, page 204 (!
1. (a) The number of steps remains 1001. 9. (a) (1,5, 7, 8, 3, 2). (b) (2, 7, 8, 3,4,6).
(b) The number of steps doubles. 11. (a) (a, f, g) o (*, c, d, e). (b) (a, c) o (fc, g, /).
(c) The number of steps quadruples. 13. (a) (1,6,3,7,2,5,4,8).
(d) The number of steps increases eightfold. (b) (5,6,7,8)o(l,2,3).
|n!| = |/i(n-l)(w-2)...2.1| < 1 • \n • n • • -n\, n > 1. 15. (a) (2, 6) o (2, 8) o (2, 5) o (2,4) o (2, 1).
18/i+ lg(n)\ < 18/i + n\ = 9|n|, n > 1. (b) (3, 6) o (3, 1) o (4, 5) o (4, 2) o (4, 8).

Mg(w)| < \n - n\ = n2, n > 1. Suppose there exist c 17. I AM NOT AT HOME.

and £ such that n2 < c • n /g(n), n > k. Choose N > k 19. (a) EOXMEFKNRAAEMFX.
496 Answers to Odd-Numbered Exercises

2 3 4 5 6 7 8 9 10 11 12 13 14 7. The structure of the proof is to check directly each of the


(b)
(i
21. (a) Even.
4 10 7 1 13 5 11 8 2 14 6

(b) Odd.
12 9 3
s> three properties required for a partial order.
9.
23. Suppose px is the product of 2kx + 1 transpositions and p2
is the product of 2k2 -f 1 transpositions. Then p2 o px can
be written as the product of 2(fci + k2) + 2 transpositions.
By Theorem 3, p2 o px is even.
25. (a) (1,5,2,3,4). (b) (1,4,2,5,3).
27. (a) (1,2,4). 11. {(1, 1), (2, 2), (3, 3), (4,4), (1, 3), (1,4), (2, 3), (2,4),
(3,4)}.
2 3
(b)
(i 4 1 3
)• 13. „ 15. f 5
4
(c)

(d) 3.
0 3

2
29. (a) Basis step: n = 1. If p is a permutation of a finite set
A, then pl is a permutation of A is true.
Induction step: The argument in Exercise 26 also 1 1 1 1 1
showsthat if pn~] is a permutation of A, then pn~x op 0 10 0 0
is a permutation of A. Hence /?" is a permutation of
17. 0 0 10 0
A.
0 0 0 10
(b) If |A| = n, then there are n! permutations of A. 0 0 0 0 1
Hence, the sequence 1A, p, p2, p3,... is finite and 19. ACE, BASE, CAP, CAPE, MACE, MAP, MOP, MOPE.
pl = pi for some / ^ j. Suppose i < j. Then
p l o p1 = \A = p '' o pJ. So p^*-' = U J - i eZ. 21.
i30

31. 1a Pi Pi P?> Pa Ps &\


• 15
U IA P\ Pi Pz Pa Ps 101
P\ P\ Ia Pa Ps Pi p-h
2< •3
Pi Pl P3 U P\ Ps Pa \5
Pi Pi> Pi Ps Pa 1a P\
P4 Pa P5 P\ 1a Pi Pi 1

P5 Ps Pa Pz Pi P\ 1a 23. Linear. - • 72
33. {lA 1, {1a, Pi), {1a, Pi), {1a, Psl {1a P3 >Pa)>
Pi, Pi, P3, Pa, /bl 36

35. There is exactly one of each kind. ( • 12

37. (a) 3. (b) 6. < . 6


39. For each increasing sequence oflength \\\ there is ex- < i 3
actly one associated up-down permutation of A, because
there is just one way to arrange the remaining elements 25. If the main diagonal of MR is all l's, then R is reflexive. If
of A in decreasing order and insert them to fill the even MR OM/? = MR, then R is transitive. If atj = 1, / ^ j, in
positions. MR, then ayx must be 0 in order for R to be antisymmetric.
27. (a) {2,3}. (b) {b,c, d}. (c) {3}. (d) {2,3}.
Chapter 6 (e) {2,3,7,8}.
29.
Exercise Set 6.1, page 226
1. (a) No. (b) No.
3. (a) Yes. (b) Yes.
5. {(a,a),(b,b),(c,c),(a,b)},
{(a,a),(b,b),(c,c),(a,b),(a,c)},
{(a,a),(b,b),(c,c),(a,b),(c,b)},
{(a, a), (b, b), (c, c), (a, b), (b, c), (a, c)},
{(a, a), (b, b), (c, c), (a, b), (c, b), (c, a)},
{(a, a), (b, b), (c, c), (a, c), (c, b), (a, b)}.
Answers to Odd-Numbered Exercises 497

31. a < a gives a <' a for all a e A'. <' is reflexive. 21. Suppose a and b are least elements of (A, <). Then a < b
Suppose a <' b and b <' a. Then a < b, b < a, and and b < a. Since < is antisymmetric, a = b. Note: This
a —b. Hence <' is antisymmetric. is a restatement of Theorem 2.
Suppose a <' b and b <' c. Then a < b, b < c, and 23. (a) /, g, h. (b) a, b, c (d) c.
(c) /.
a < c. Hence a <f c and <' is transitive.
25. (a) d, e, f. (b) b, a (c) d. (d) b.
33. Suppose U CT andT cV. Then £/ c V and /? is tran
sitive. No set is a proper subset of itself so R is irreflexive. 27. (a) None. (b) b. (c) None. (d)*.
Hence R is a quasiorder. 29. (a) x e [2, oo). (b) x e (-oo, 1].
35. Suppose a R~l b and b R~[ c. Then c R b, b R a, and (c) 2. (d) 1.
c /? a. Hence a R~l c and /?_I is transitive. Suppose that
x R~l x. Then x R x, but this is a contradiction. Hence
7?"1 is irreflexive and a quasiorder.
31. (a)
» [o I]
37. (a, b) < (a, b) since a | (3 and b < b. Thus < is reflexive.
Suppose (tf, Z?) < (c, d) and (c, d) < (a,b). Then a | c
(c)
1] «[2 !!]•
and c | a. This means c = ka = k(mc) and for a and c 33.
in B, km = 1 implies £ = m = 1. Hence a = c. Also,
b < d and d < b so b = d. Thus -< is antisymmetric.

39- ™ {«,/,*}

35. The least element of A is the label on the row that is all
Define F as follows: F(l) = { }; F(2) = {e}; F(5) = ones. The greatest element of A is the label on the column
{/}; FQ) = {g}\ F(10) = {*,/}; F(6) = [e, g); that is all ones.
F(\5) = lfgY,F(30) = {e,fg}.
37. (a) 49. (b) {2,4, 8, 16, 32, 64}.
41. Let U = {a, fr, c, d}, S a subset of J7, and fs be the char
acteristic function of S (relative to U). Define Exercise Set 6.3, page 241
1. Yes, all the properties are satisfied.
fs(a) fs(b)
8(S)
•[ fs(c) fs(d) 3. No, GLB({e, b}) does not exist.
5. Yes, all the properties are satisfied.
Then g is a one-to-one correspondence between P(U) and
A. If S < T in (£/, c), then fs(x) < fT(x) for all jc in U. 7. No.
Hence g(S)<g(T). 9. Yes, LUB(M, N) = [ au = max{/w,7, nu} ] and
Exercise Set 6.2, page 232 GLB(M, N) = [ bu = min{m0, nu] ]
1. Maximal: 3, 5; minimal: 1, 6. 11.
0i, h)
3. Maximal: e, f; minimal: a.
5. Maximal: none; minimal: none. (fli, bi) (bx, a2)
7. Maximal: 1; minimal: none.
9. Greatest: /; least: a.
11. No greatest or least. 13. For each TX,T2 C. T,Txf)T2, and Tx U T2 are subsets of T
13. Greatest: none; least: none. so P(7) is a sublattice of P(S).
15. Greatest: 72; least: 2. 15. For any elements jc, y of a linearly ordered poset, x < y or
y < x. Say x < y. Then jc = jc a y and y = xv y. Hence
17. No, a may be maximal and there exists an element of A,
b, such that a and b are incomparable. any subset of a linearly ordered poset is a sublattice.

19 (a) True. There cannot be ax < a2 < • • • since A is finite. 17. • | t o


(b) False. Not all elements have to be comparable. 1 H **

(c) True. There cannot be • • • < a2 < ax since A is finite.


(d) False. Not all elements have to be comparable.
498 Answers to Odd-Numbered Exercises

19. SupposeaAfc = a. a < avb = (aAb)vb = (avb)Ab < Suppose (a Ab') v (a' Ab) = 0. ThenaAb' = 0and
b. Thus a < b. a! a b = 0. We have / = 0' = (aa V)' = a! v 6. So ^ is
Suppose a < b. a Ab < a and a < a, a < b gives the complement of b;bf = af.
a < a A b. Hence a A b — a.
15. Suppose a < b. Then a Ac < a < b and a A c < c so
21. (a) 12. a A c < ^ A c.

(b) Figure 6.44(a): 3; Figure 6.44(b): 3. 17. (a A fc) V (fl A V) = a A (& v V) = a A / = a.


23. (ax,a2) A((bx,b2)y (cx,c2)) 19. (flAfcAc)V(fcAc) = (avI)A(bAc) = lA(bAc) = bAC.
= (ax,a2) A (bx v cx,b2v c2) 21. Suppose a < b. Then a v (fc A c) = (a v b) A (a v c) =
= (axA(bx vcx),a2A(b2vc2)) b A(av c).
= ((ax A bx) v (ax A cx), (a2 A b2) v (a2 A c2))
= ((ax,a2) A (bx,b2)) v ((ax,a2) A (cx,c2)). 23. # is reflexive because m„ = 1, i = 1, 2,..., 8. /? is anti
symmetric since if mi} = 1 and / ^ j, then myi = 0. R is
A similar argument establishes the other distributive prop
transitive, because MR O M/? shows that R2 c #.
erty.
25. Complement pairs are a, h; fc, g; c, /; J, e. Since each el
25. Suppose a ax = a Ay and a v jc = a v y. Then
ement has a unique complement, (A, #) is complemented.
y < yv (y s^a) = (y Ay)V (y Aa)
27. (A, /?) is not a Boolean algebra; complements are not
= yA(yVa) unique.
= y A (a V jc) 29. (a) {a}, {fc}, {c}. (b) 2, 3, 5.
= (yAa)v(yAx) 31. Matrices with exactly one 1.
= (a A x) V (y A jc)
Exercise Set 6.5, page 253
= jc A (a V y) < x.
1.
Hence y < x. A similar argument shows x < y. Thus JC
y z JC A (y v zf)
x = y.
0 0 0 0 l
27. 1' = 42, 42' = 1, 2! = 21, 21' = 2, 3' = 14, 14' = 3, 0 0 1 0 0
7' = 6, 6' = 7. 0 l 0 0 1
0 l 1 0 1
29. Neither.
1 0 0 1 1
31. Distributive, but not complemented. 1 0 1 0 0
33. If jc = jc', then jc = jc v jc = / and x—xax —0. But by 1 1 0 1 1
Exercise 18, 0 ^ /. Hence, x ^ x'. 1 1 1 1 1

35. Suppose Px < P2. Then Rx c R2. Let jc e A,. Then


A/ = {y | (2 /?i y} and A/ c {y | jc R2 y] = #,, where x y z (x v /) V (y a (*' v y)
jr e Bj. Suppose each A, c Bj. Then x Rx y implies
x R2y and 7?i c R2. Thus ^i < P2. 0 0 0 0 0 0 1
0 0 1 0 0 0 1
37. The sublattice {a,b,d\ of Figure 6.57 is not comple 0 1 0 0 l 1
mented.
0 1 1 0 l 1
39. For any a, b, c in the sublattice with a <c,av (b Ac) = 1 0 0 1 0 0
(a v b) A c, because this is true in the full lattice. 1 0 1 1 0 0
1 1 0 0 1 1
Exercise Set 6.4, page 248 1 1 1 0 1 1
1. No, it has 6 elements, not 2" elements. (1) (4) (3) (2)
3. No, it has 6 elements, not 2n elements. 5. (jc V y) A (x' V y) = (jc A jc') V y = 0 V y = y.
5. Yes, it is B$. 7. (zf Vx)A ((x Ay)vZ)A (zf V y)) =
(zf v(xa y)) A ((x Ay)vZ) = (xAy)v (z' Az) =
7. Yes, it is Bx.
(jc A y) V 0 = jc A y.
9. Yes; 385 = 5 -7 -11.
9. (x'Vy)'vzVxA((yAz)v(yfAz')) = (jca/)Vzv(jca^a
11. No, each Boolean algebra must have 2n elements. z)v(xAy'Az') = ((xAy')A(\Vz'))VzA(lv(xAy)) =
13. Suppose a = b. (a A b') V (a' A b) = (b A b') V (a' A a) (JC A /) V Z.
= 0v0 = 0. 11. jc A z. 13. y V jc'.
Answers to Odd-Numbered Exercises 499

15. (a)
(XV y) A (Jt' V Z)
^o
X V z

(xv(yv zO)
A((Z AjO' A
V V 0))

(y'vO)

Z AX'

19. ((lAy)v(yAz))'. 3.
. 1 y
V -\

21. ((jc v y) A z)'.


x1 1 1 0 0

Jy^r^)xs/yA y*vv)az-r>o((xVy)AzY x 1 0 0 i

5. /
< *
r -v -\

±] 0 0 1

Exercise Set 6.6, page 263


0
• 0 1
y y
11 0 0 1
1.
y y
0 0 0 0
• 0

w
0
• w'-
500 Answers to Odd-Numbered Exercises

(b)

X* 0 1 1 0

x 0 1 1 0

9. (jc' A y') V (jc A y).

11. z' V (jc' A z). 13. (T, v0) may be an n-tree for n > 3. It is not a complete
3-tree.
13. (zf Ay)V(x A y') V (/ A z). 15. (a) vx,v3.
15. (z A JC') V (w' A X A y) V (w A X A /). (b) v6, v7, vs, vX3, VX4, l>i6, V\0.

17. (jc'Ay') V (jc Ay). 17. (a) 4. (b) 2.


19. /TN
19. (jc' a /) v (jc A z'). © © (^
21. z.

23. (jc' A y' A w') V (y A z A w') V (jc' A z! A y A w). © © ©


25. (a) jc' a y', x' A y, x A y'
(b) Since A is commutative and associative, we need
only consider the case (wx A w2 A • • • A wn A y) v
(wx A w2 A • • • A wn Ay'). But this is equivalent to
wx a w2 a • • • a wn.

27. x' A zl, y' Az!,y a z', x a z', x a y.

29. (a) (x A y) v z!.


21. Basis step: n = 1. An n-tree of height 1 can have at most
(b) A simple check of the values of /(jc, y, z) will verify
n leaves by definition.
this.
Induction step: Use P(/): An n-tree of height i has at most
n' leaves to show P(/ +1): An n-tree of height / +1 has at
Chapter 7 most n'+l leaves. The leavesof a tree T of height i +1 be
long to the subtrees of T whose roots are at level 1. Each
of these subtrees has height at most /, and there are at most
Exercise Set 7.1, page 274
n of them. Hence the maximum number of leaves of T is
1. Yes, the root is b. n • n' orn/+1.

3. Yes, the root is /. 23. The total number of vertices is 1 + kn, where k is the
number of nonleaves and 1 counts the root, because every
5. No. vertex except the root is an offspring. Since / = m —k,
l=l+kn-korl+k(n-l).
7. Yes, the root is t.
25. If both v T u and uT v , then v, u, v is a cycle in T. Thus
9. (a) VX2,VXQ,VXX,VU, Ul4- v T u implies u f v. T is asymmetric.
(b) vXQ, vxx, v5, vX2, u7, vX5, vX4, v9. 27. Each vertex except the root has in-degree 1. Thus s =
r - 1.
11. (a) 29. 4. The tree of maximum height has one vertex on each
level.

31. Assume that the in-degree of Vq ^= 0. Then there is a cycle


that begins and ends at v0. This is impossible. Hence the
in-degree of v0 must be 0.
33. (a) 2 < n. (b) 1 < k < 7.
Answers to Odd-Numbered Exercises 501

Exercise Set 7.2, page 279


1.

6 2 y 15. 721.

17.

X* >x

<x.4
19.

5.

21.
2 jc 2 x
2 0
3 4
5 _+ 6
9 10
0 7 0
7 8
0 6 0
0 2 0
0 JC 0
11 12
0 y 0
0 4 0

23. LEFT DATA RIGHT

2 0
3 4
5 6
9 10
7 + 8
11 X 12
0 2 0
0 JC 0
0 JC 0
0 2 0
0 2 0
4 jc 0 0

11. 6. 25. (a) CAR. (b) SEAR, (c) RACE, (d) SCAR.
502 Answers to Odd-Numbered Exercises

27.

Exercise Set 7.3, page 286


33. B(T)
1. xysztuv.

3. ab c gh idkejf.

5. TSAMZWEDQMLCKFNTRGJ.

7. 2 + 3 - 1 x 2. . A\
9. 6 4 2 1 3 5 7. i h

11. syvutzx.

13. ghcibkjfeda.
35.
15. ZWMADQESCNTFKLJGRMT.

17. NEVER I COW A SAW PURPLE ONE SEE I NEVER


HOPE I.

19. 4.

21 -^
Z1- 16-
8 i
23. 37. (a) . Vq (b)
25.

27.
39. AVLn = AVLn-X + AVLn_2 + 1. Let v be a new root. Let
T(vL) be an AVL tree of height n — 1 using a minimal
number of vertices. Let T(vR) be an AVL tree of height
n — 2 using a minimal number of vertices. Then T(v),
where the left offspring of v is vL and its right offspring is
vR, is an AVL tree of height n using a minimal number of
vertices.

Exercise Set 7.4, page 294


29. (a) The root must be labeled J; if J has a left offspring,
1. „ 3.
it must be labeled B, otherwise the right offspring is
labeled B.

(b) The root must be labeled G; if G has a left offspring,


k:
it must be labeled Af, otherwise the right offspring is
labeled N.
Answers to Odd-Numbered Exercises 503

B C

•D

G F E

'IS

13.
b e

b e

d/

11.
15. There are 5 spanning trees.

13.
1

Allendale
4

17. !

5 4

• *l — —»H >A2 i »y42


15.

44 1«i Allendale

i4 r

t
i

—»A3 A4 . • i

. Five. 23. n.

25. There is only one. Any spanning tree is formed by omit Atlanta 147
ting one edge from the graph. A clockwise shift of the It would be 81 miles longer.
labels gives an isomorphism between any spanning tree
17.
and the tree formed by omitting the edge (vn, vx). A*0.5 ~H
Exercise Set 7.5, page 300
504 Answers to Odd-Numbered Exercises

19. 21. (a)

23. {3, 12}


21. The maximal spanning tree is the same as that in Exercise
19. >13}

23. If each edge has a distinct weight, there will be a unique {1, 10) {5, 14}
maximal spanning tree since only one choice can be made
at each step. ,15}
25. One example is the sum 50. The greedy algorithm would
select four 11-xebec coins and then six 1-xebec coins for a {7, 16}
total of 10 coins. But the amount can be made from seven
7-xebec coins and one 1-xebec coin, a total of eight coins. 25. n —1. The two "endpoints" have degree 1; the other n —2
vertices each have degree 2. Hence the number of edges is
Chapter 8
2(l) + 2(n-2)
Exercise Set 8.1, page 310
l.V = [a, b, c, d], E = {{a, b], [b, c), {b, d], [c, c}}. or n - 1, since each edge is counted twice in the sum of
3. V = {a,b,c,d},E = {{a,b},lb,c},{d,a},{d,c}}. All the degrees.
edges are double edges. 27. Two graphs, Gx and G2, are isomorphic if there is a
5. Possible answers are one-to-one correspondence / between the vertices of Gx
and G2 and (vt,Vj) is an edge in Gi if and only if
|6 ,7. *c
(/(Vi). fivj)) is an edge in G2.
29. The graphs in Figures 8.24(a) and 8.24(c) are not isomor
phic, because one has a vertex of degree four and the other
does not.

31. In a digraph there are no multiple edges between vertices.


In a graph, the edges are not directed.
33. The sum of the degrees of all vertices with even degree is
clearly even. Thus the sum of the degrees of all vertices
9. Degree of a is 2; degree of b is 3; degree of c is 3; degree of odd degree must also be even (using Exercise 32). But
oft/ is 1.
if there were an odd number of vertices of odd degree, the
11. a, c\ a, b, c\ a, c, d; a, c, e. sum of their degrees would be odd, a contradiction.
13.
Exercise Set 8.2, page 316
1. Neither. There are 4 vertices of odd degree.
3. Euler circuit. All vertices have even degree.
5. Euler path only, since exactly two vertices have odd de
gree.

7. Neither. The graph is disconnected.

15. Only the graph given in Exercise 3 is regular. 9. Yes, all vertices have even degree.
11.

17. One possible solution is


19.
{«,/}
[e, b, d]

M
is one answer.
Answers to Odd-Numbered Exercises 505

13. Yes. Note that if a circuit is required, it is not possible. Exercise Set 8.3, page 320
1. Neither.

3. Hamiltonian path, but no Hamiltonian circuit.


5. Hamiltonian circuit.

15. One more edge.

9. A, B, D, H, G, E, F, C, A.
17. Seven edges. One solution.
28 11. A, G, B, C, F, E, D, A.
< i (
f ^ p •
1 2 3 / 4 13. A, B, D, H, G, E, F, C, A.
37 29 27 14! 13
15. A, G, B, C, F, E, D, A.
, 18 ,• 17 •, 16 15 \ 12

19 30 26 9 To Ti 17. F, E, G, H, D, B, A, C, F.
5!
\
> 20 ,• 21 ., 22 , 19. Choose any vertex, vx, in Kn, n > 3. Choose any one of
35 31 25 23 :8
the n —1 edges with vx as an endpoint. Follow this edge to
v2. Here we have n —2 edges from which to choose. Con
32
i i ' >

24
ih
tinuing in this way we see there are (n —l)(n—2) • • •3-2-1
34 33 Hamiltonian circuits we can choose.
19. See the solution for Exercise 17. The consecutively num 21. One example is
bered edges are one possible circuit.
21. If n is odd, each vertex in Kn has degree n — 1, an even
number. In this case, K„ has an Euler circuit. If n is even,
then each vertex of Kn has odd degree; Kn does not have
an Euler circuit.
23. One solution is 000, 100, 110, 111, 101, 001, 011, 010,
000.
23. Suppose the strings axa2• • •an and bxb2- - -bn differ only
in the ith position. Then a, or b-t is 1 (and the other is 0); 25. Construct a sequence of 2n + 1 strings of 0's and l's of
say a{• = 1. Let A be the subset represented by axa2 • • •an length n such that the first and the last terms are the same,
and B, the one represented by bxb2 • • •bn. Then B is a sub and consecutive terms differ in exactly one position.
set of A, and there is no proper subset of A that contains
B. Hence there is an edge in Bn between these vertices. Exercise Set 8.4, page 328
Suppose there is an edge between the vertices labeled 1. One solution is
axa2- -an and bxb2 • • -bn. Then a, < bi, 1 < i < n
(or vice versa). Hence there are at least as many l's in
bxb2- • -bn as in axa2- • -an. If the strings differ in two
or more positions, say aj = a* = 0 and bj = bk = 1,
consider the label cxc2- • -cn with c, = bi9 i ^ j, and
Cj = 0. Then cxc2- •-cn represents an subset between
those represented by axa2 • • •a„ and bxb2- • -bn. But this
is not possible if there is an edge between the vertices la 3. One solution is
beled axa2 • • ♦ an and bxb2 • • • bn. (4,4)
^2
25. If n is even, there is an Euler circuit. Each vertex is labeled
with a string of even length. Hence it must have even de
gree as the value of each position could be changed in turn
to create the label of a vertex connected to the original
one. If n is odd, by the same reasoning every vertex has
odd degree and there is no Euler circuit. (5,3)
506 Answers to Odd-Numbered Exercises

5. value(F) = 6. 5. value(F) = 17.


(8,7) (5,5)

(3,3) ^ (4,0)
7. {(a,\),(b,2), (c, 4), (d, 3)} is a maximal matching.
9. {(a, 5), (b, 2), (c, 3), (d, 1), (e, 4)} is a maximal match
ing.
11. The matchings in Exercises 7, 9, and 10 are complete.
13. (a) One set of pairings is Sam-Jane, Kip-Gail,
Homer-Rufus, and Kirk-Stacey.
(b) Yes, one such pairing is Sam-Stacey, Kip-Rufus,
Homer-Jane, and Kirk-Gail.
15. Let S be any subset of A and E the set of edges that begin
in S. Then k\S\ < \E\. Each edge in E must terminate
in a node of R(S). There are at most </|/?(5')| such nodes.
Since j < k, j\S\ < k\S\ < j\R(S)\ and \S\ < \R(S)\.
By Hall's Marriage theorem, there is a complete matching
for A, B, and R.
(8,5)
17. (a) No, vertices 1, 2, and 6 must be in different subsets,
11. value(F) = 1. but there are only two sets in the partition.
(b) Yes, {{1,3, 5, 7}, {2,4, 6, 8}}.
19. A triangle is formed by edges (u, v), (v, w), and (w, u).
If u and v are placed in different subsets by a two-set par
tition, neither subset can contain w.

Exercise Set 8.6, page 338


1.

13. Possible cuts include Cx = {(2, 6), (5, 6), (5, 8), (4, 7)}
with capacity 34 and C2 = {(6, 8), (7, 8)} with capacity 8.
15. {(1,2), (1,3)}.

17. {(2,4), (3, 6), (5, 6)}.


ME

19. {(2, 5), (3, 5), (6, 8), (7, 8)}. JMH MA
RI
21. {(2,4), (5, 7)} with capacity 7.
CT
VT
Exercise Set 8.5, page 333
1. Yes. M(s2) = bx, M(s3) = b3, M(s4) = bA, M(s5) = b2.

3. value(F) = 9. 9. PG(x) = x(x - i)(x2 - 3x + 3); Pc(0) = Pc(l) = 0,


Pg(2) = 2.
(4,3) ^n (3,3)
11. PG(x) = x(x - l)(x4 - 5x3 + 10x2 - 10* -I- 5); PG(0) =
PC(1) = 0,PC(2) = 2.
13. PG(x) = x(x - l)(x - 2)2; X(G) = 3.
15. PG(x) = x(x - l)(x - 2)(x - 3); x(G) = 4.
17. PG(x) = x(x - l)(x - 2)3; X(G) = 3.
(2,2) (3,2) 19. PG(x) = x(x - \)2(x - 2)(x2 - 3x + 3); x(G) = 3.
Answers to Odd-Numbered Exercises 507

21. x (G) = 2. Let A and B be the subsets that partition the 31. (a) Associative: (1), (5), (8), (9), (10), (11), (15), (16).
vertices. Color vertices in A one color and those in B the (b) Idempotent: (5), (10), (11), (15).
other. It is easy to see that this will give a proper coloring
33. A binary operation on a set S must be defined for every a,
ofG.
b in S. According to the earlier definition, a * b may be
23. (Outline) Basis step: n = 1 P(l): Pl{(x) = x is true, undefined for some a, b in S. Any binary operation on a
because Lx consists of a single vertex. set S is a binary operation in the sense of Section 1.6.
Induction step: We use P(k) to show P(k + 1). Let
G = Lk+X and e be an edge {u, v] with deg(v) = 1. Then Exercise Set 9.2, page 354
Ge has two components, Lk and v. Using Theorem 1 and 1. Semigroup: (b). monoid: (b).
P(k), wehave PGe (x) = x •x(x - l)k~l. Merging v with u 3. Semigroup: (a). monoid: neither.
gives Ge = Lk. Thus PG<(*) = x(x - 1)*_1. By Theorem
5. Monoid: identity is 1; commutative.
2, PLa+1(x) = *2(* ~ I)*"1 - x(x - l)*"1 =
jtOc-l^-'Qc-^orjcOc-l)*. 7. Semigroup.
25. These are possible answers, 9. Monoid: identity is 5; commutative.
(a) 11. Monoid: identity is 12; commutative.
13. Monoid: identity is 0; commutative.

15. monoid; identity *[_!} commutative.

17. Neither.
27. Label the vertices with the fish species. An edge connects
19. * a b c
two vertices if one species eats the other. The colors rep
a c a b
resent the tanks, so x (G) will be the minimum number of
b a b c
tanks needed.
c b c a
29. (a) Each row, column, and subgrid has the same number
21. Let Ma) = a, Mb) = a; Ma) = a, Mb) = b;
of elements.
Ma) = b, Mb) = a; Ma) = b, Mb) = b. These
(b) 7. (c) 20. are the only functions on S. It is not commutative.
o
/. fl h h
Chapter 9 /. /. /. f* /4
fl /. fl fi /4
Exercise Set 9.1, page 348 h /. h fl /l
1. Yes. 3. No. 5. No. 7. No. u /. u u u
9. Commutative, associative. 23. (a) abaccbababc.
(b) babcabacabac.
11. Not commutative, associative.
(c) babccbaabac.
13. Commutative, associative.
25. The subset must form a subsemigroup and the identity el
15. Commutative, associative.
ement must belong to the subset.
17. Commutative, associative.
27. By Exercise 26, we need only check that e e Sx H S2. But
19. Commutative; not associative e e Sx and e € 52, because each is a submonoid of (S, *).
21. The operation has the idempotent property, because a*a = 29. Yes. Refer to Exercise 1.
31. Let*, y e Sx.
23. One solution is
(g o f)(x *! y) = g(f(x *i y))
* a b c
= g(f(x) *2 f(y))
a a c c

b c b a
= g(f(x))*3g(f(y))
c c a c = (gof)(x)*3(gof)(y).
25. (a) a, a. (b)c,b. (c)c,a. (d) Neither. Hence g o / is a homomorphism from (Sx, *i) to (S3, *3).
27. * a b c d 33. Onto; homomorphism.
a a b c d
35. Let x, y e R+. ln(x * y) = ln(jt) + ln(y) so In is a
b b a c d
homomorphism. Suppose x e R. Then ex € R+ and
c c d c d
ln(e*) = x so In is onto R+. Suppose ln(;t) = ln(y); then
d d c c d
elnix) = elniy) and x = y. Hence In is one to one and an
29. n commutative operations. isomorphism between (R+, x) and (R, +).
508 Answers to Odd-Numbered Exercises

Exercise Set 9.3, page 361 Exercise Set 9.4, page 371
1. Let (sx,tx), (s2,t2) e S x T. (sx,tx) *" (s2,t2) = 1. No.
(sx * s2,tx *' t2), so *" is a binary operation. Consider 3. Yes; Abelian; identityis 0; a-1 is —a.
(sx,tx)*"((s2,t2)*"(s3,t3)) = (sx,tx)*"(s2*s3,t2*'t3) =
(sX*(s2*S3),tX*'(t2*'t3)) = ((5i*^2)*-S3,(^l*^2)*^3) = 5. No. 7. No. 9. No.
((si,tx) *" fe, r2)) *" fe, f3). Thus (5 x T, *") is a semi 11. Yes; Abelian; identity is { };a l is a.
group. (sx, tx) *" (s2, t2) = (^] *s2, tx *' f2) = (s2*sx,t2 *'
^) = (s2, t2) *" (51, tx). Hence *" is commutative. 13. Since gx, g2, g3 in S3 each have order 2, they must be
paired somehow with f2, f3, /4 of Example 12 if the
3. Let (sx,tx), (s2, t2)eSx T. Then f((sx,tx) *" (s2, t2)) = groups are isomorphic. But no rearrangement of the
f(sx *s2,tx *' t2) =sx *s2 = /(Ji,ri)*/(j2,^). /is a columns and rows labeled f2, f3, f4 in Example 12 will
homomorphism. give the "block" pattern shown by gx, g2, g3 in the table
5. *" is a binary operation, because both * and *' are. Con for S3. Hence the groups are not isomorphic.
sider (sx, tx) *" (fe, t2) *" fe, r3)). 15.
<»)§• 0»)-5-
(5,,rO *" (fe,r2) *" (53,f3)) = tei, *i) *" te *s3,t2*'r3)
17. Hx = (1), H2 = {1, -1}, H3 = {1, -1, i, -/}.
= (SX *(s2*S3),tX *' (t2*' t3))
= (($! *52)*53,(fi */f2)*/ft)
19. 0 /. fl h U fs h fi h
/. /l fl h h fs u fi h
= ((^^l)*,'fe,r2))*,,fe,r3)
fi h h U A ft h fs u
h h U /. h h fs h h
Thus, *" is associative.
u n A h h fi h h fs
7. Yes. 9. Yes. 11. Yes. 13. No. 15. Yes. fs h fi h h f\ h h u
u h h fs fi h A n fl
17. S/R = {[4], [7], [10], [13], [16]}. fl fl h fs h h h
u n
19. By Exercise 23, Section 4.7, we have that the composition h h h fi fe h U h fl
of two equivalence relations need not be an equivalence 21. Consider the sequence e, a, a2,a3, Since G is finite,
relation. not all terms of this sequence can be distinct; that is, for
21. S/R = {[0], [1], [2]}. [0] = {0,±3,±6, ..}, [1] some 1 < j, a1 = aj. Then (a-1)'V = (a_1)'V and
{±1, ±4, ±7,...}, [2] = {±2, ±5, ±8,...}. e = aj~l. Note that j -i > 0.
23. Yes.
e [0] [1] [2]
[0] [0] [1] [2] 25. Clearly, e g H. Let a,b e H. Consider (ab)y = a(by) =
[i] [1] [2] [0] a(yb) = (ay)b = (ya)b = y(ab) Vy e G. Hence H is
[2] [2] [0] [1] closed under multiplication and is a subgroup of G.
23. S/R = {[0], [1], [2], [3], [4]), 27. The identity permutation is an even permutation. If px and
[a] = {z I z = 5k + a, k e Z}, a = 0, 1,2,3,4. p2 are even permutations, then each can be written as the
product of an even number of transpositions. Then pxop2
e [0] [1] [2] [3] [4]
can be written as the product of these representations of
[0] [0] [1] [2] [3] [4]
px and p2. But this gives px o p2 as the product of an even
[i] [1] [2] [3] [4] [0] number of transpositions. Thus px o p2 e An and An is a
[2] [2] [3] [4] [0] [1] subgroup of Sn.
[3] [3] [4] [0] [1] [2]
[4] [4] [0] [1] [2] [3] 29. {/,}, {/,,/2,/3,/4}, {/l,/3,/5,/6h {/l,/3,/7,/8},
{fufsl {fu fel [fu /3K {/., fil {/., M D4.
25. (a) ® la] [b]
[a] [b]
31. \xy\ = \x\ • \y\. Thus f(xy) = f(x)f(y).
[a]
[b] [b] [b] 33. Suppose f:G-+G definedby f(a) = a2 is a homomor
(b) Me) = [a] = fR(a), fR(b) = [b] = fR(c). phism. Then f(ab) = f(a)f(b) or (ab)2 = a2b2. Hence
a~l(abab)b~l = a~l(a2b2)b~l and ba = ab. Suppose G
27. An examination of the two multiplication tables shows that is Abelian. By Exercise 37, f(ab) = f(a)f(b).
they are identical and so Z2 is isomorphic to S/R.
35. Let x, y € G. fa(xy) = axya~x = axa~xaya~x =
29. This is a direct proof. For part (a), we check the three prop fa(x)fa(y)> fa is a homomorphism. Suppose x e G.
erties for an equivalence relation and then the propertyfor Then fa(a~lxa) = aa~lxaa~l = jc so /fl is onto.
a congruence relation. In part (b), we first check that / is Suppose fa(x) = fa(y), then axa~l = aya~l. Now
a function and then the properties of an isomorphism are a~x(axa~x)a = a~x(aya~x)a and x = y. Thus fa is one
confirmed. to one and an isomorphism.
Answers to Odd-Numbered Exercises 509

37. (Outline) Basisstep: n = 1 P(l): (ab)1 = albx is true. 29. Suppose f(aH) = f(bH). Then Ha~x = //Z?"1 and
Induction step: LHS of P(* + 1): (ab)k+x = (abfab = a~x = /ib~\ h € H. Hence a = &/*"1 e &// so
akbkab = akabkb = ak+xbk+x aH c fc//. Similarly, Z?# c a// so a// = bH. This
RHSofP(*+l). means / is one to one. If He is a right coset of H, then
f(c~xH) = He so / is also onto.
39. One table is
* a b c
31. Consider f(aba~xb~x) = f (a)f (b)f (a~x)f (b~x) =
a b a c
f(a)f(a-x)f(b)f(b~x) = f(aKf(a)rlf(bKf(b))-{
b c b a
(by Theorem 5, Section 9.4) = ee = e. Hence
c a c b
{aba~xb~x \a,binGx] c ker(/).
33. Let a £ //. The left cosets of // are # and aH. The
* has no identity element.
right cosets are H and //a. H OaH = H D Ha = { }
and H U aH = H U //a. Thus a// = //a. Since
Exercise Set 9.5, page 376
a e H => a// = //, we have x// = HxVx e G. H
(0,0) (0,1) (0,2) (1,0) (1.1) (1,2) is a normal subgroup of G.

(0,0) (0,0) (T.0) (T.T) (1,2) 35. Suppose /: G —• G' is one to one. Let jc 6 ker(/).
(0.T) (0.2)
Then f(x) = e' = f(e). Thus jc = e and ker(/) = {e}.
(0,1) (0,1) (0,2) (0,0) (1.1) (1,2) (1,0)
Conversely, suppose ker(/) = {e}. If f(gx) = /(g2)»
(0,2) (0,2) (0,0) (0,1) (1,2) d.O) (1,1) then f(gxg2l) = f(gi)f(g2l) = f(gi)(f(gi)rl =
(1.0) (1,0) (1.1) (1,2) (0,0) (0,1) (0,2) f(gi)(f(g\))-1 = e. Hence gxg2x e ker(f). Thus
(1,1) (1.1) (1.2) (1,0) (0,1) (0,2) (0,0) gxg2x = e and gi = g2. Hence / is one toone.
(1,2) (1,2) (1.0) (l.D (0,2) (0,0) (0,1) 37. Since H is a subgroup of G, the identity element e belongs
to H. For any g e G, g = g *e € gH, so every element
3. Define /: G, -»• G2 by /((g,, g2)) = (gi, gi). By Exer of G belongs to some left coset of H. If aH and bH are
cise 4, Section 9.3, / is an isomorphism. distinct left cosets of //, this means that aH fl bH = { }.
5. [01 [2] Hence the set of distinct left cosets of H forms a partition
[1]
ofG.
[0] [0] [1] [2]
[1] [1] [2] [0] Exercise Set 9.6, page 381
[2] [2] [0] [1]
1. Noncommutative ring with identity.
7. ker(/) = {(ex,g2), ex, identity of G,, g2 e G2}.
3. Not a ring.
9. f[0]}, {[1]}, {[2]}, {[3]}. 5. Commutative ring with identity.
11. {[0], [1], [2], [3]}. 7. This is a ring from Exercise 1. An example of zero divisors
13. The groups are isomorphic. Define f:G -> Z4 by are the matrices

/(I) = [0], /(/) = [1], /(-l) = [2], /(-i) = [3].


A comparison of the multiplication tables shows that /
preserves the operation.
[l 2] and [ 1 l]-
15. {/,,g3M/2,g2M/3,g.}. 9. I, 3.
17. {fiUMAtihigihlgihlg*}. 11. I, 3,7, 9.
19. {[0], [4]}, {[1], [5]}, {[2], [6]}, {[3], [7]}. 13. This subset is a subgroup with respect to + since it con
tains the zero element and A - B belongs to the subset if
21. {(m + jc, n + x) | x e Z} for (m, n) eZx Z. A and B do. This subset is a subsemigroup with respect to
23. If N is a normal subgroup of G, Exercise 22 shows that * since if A and B are in the subset so is A * B.

a~xNa c AT for all a e G. 15. The structures in Exercises 1 and 2 are not fields, because
Suppose a~xNa c N for all a e G. Again the proof they lack multiplicative inverses. The structure in Exer
in Exercise 22 shows that Af is a normal subgroup of G. cise 3 is not a ring so it is not a field. The structures in
Exercises 4, 5, and 6 are fields.
25. {/,}, {/,,/3}, {/|,/3,/5,/6}, {/l,/2,/3,/4}, {/l,/3,
/7, /sK zx 17. 55*57 = TinZ,96.
27. Suppose fa(hx) = fa(h2). Then ahx = a/i2 and 19. (4,0).
a~x(ahx) = a~x(ah2). Hence h\ = h2 and fa is one to 21. (a) 2, 3. (b) There are no solutions.
one. Let x e aH. Then jc = ah, h € H and /fl(/0 = x. 23. 9.
Thus /fl is onto and since it is everywhere defined as well,
fa is a one-to-one correspondence between H and aH. 25. (a) (jc v y) a ~-(jc a y). (b) x Ay.
Hence |//| = |a//|. 27. The set of units must contain all nonzero elements of R.
510 Answers to Odd-Numbered Exercises

29. The statement Z„ is a field implies n is prime is proven 33. Vo H-> flV0 Vi h* flVi
in Exercise 28. The converse is shown by using Theorem vo *-• fcvi vx \-+ a
4(a), Section 1.4. Any a e Zn is relatively prime to n so The language is in fact regular.
we have 1 = sa + tn for some integers s, t and s is the
multiplicative inverse of a. Exercise Set 10.2, page 402
1. (vo) ::=x(v0> | y{vx)
Chapter 10 (vj) ::=y(vx) \z

Exercise Set 10.1, page 393 14 ^^—E


1. {xmynz,m >0,n> 1}.
3. {a2n+l,n>0}U{a2nb,n>0}.
5. {(... (g + fl + ---+g)...), k > 0, n > 3}.
3. (v0> ::=«(vi)
k na's k
(vi> ::=fc(v0> | a
7. [xmyzn,m >l,n> 0}.
"o
9. (a),(c),(e),(h),(i).
11. L(G) is the set of strings from {a, b, c, 1, 2,..., 9,0}*
that begin with a,b,or c.
13. L(G) = {(aa)nbck(bbybk, n>0,k>l,j> 0}.
15. vo vo 5. (v0> ::=aa(v0) \ b{vx)
v0vx vQvx
(vi) ::=c(v2)fc \ cb
VqVXVX V2V0VX
(v2> ::= bb(v2) \ bb
v2v0z xyvx ^q
0—B
xyz xyz

17. / I
LW LW
<£> 0-
aW
aDW
LDW m^Hj
LDDW
alW LDDD v2
alDW aDDD
alDD alDD
Z
alOD alOD 7. (u0> ::= x(vo) | y(u0) | z
a 100 alOO
9. {vo) ::=a(u,)
19. The languages are not the same; here L(G) contains {vi): := b{v0) | a
aabba.
11. («o> ::=ab(vi)
21. G = (V, S, v0, h>), V = {vo, vx,0,1}, S = {0, 1} {vi): :=c{Vi) | <u2)
!->-: vo i-* Ovil, vo •->• lviO, Vi i-> OVjl, Vi \-+ lVjO, {vi): := dd(v2) | d
vi h-> 01, vi \-> 10.
13. (uo) :
23. G = (V, 5, v0, i-O, V = {v0, v,, a, b], S = {a, b]
<wi>::=a(u2)
\-+: Vo h* aavxbb, vx i-» avi&, vi h-» <z&.
ivi): :=a(v{) \a
25. G = (V, S, v0, h+), V = {v0,jc, y}, 5 = {jc, y}
15. <t>0> ::= b{v0) \ a(Vl) \ b
\-+: vo !-• v0yy, vo h> jcvo, vo h> jcjc.
:=a{v0) \b{v\) \a
27. vo h+ flVofl Vo i-* bvob Vq i-> a
17. (aa)* a a .
Vo i-> aavo !-• fc Vo i->- fcfc.
19. (Q*(a+a + (a + )*a())*. Note: Right and left parentheses
29. By using production rules 1, 2, and 4; production rule 4 to
must be matched.
a3* xv2; 3; a3*av3 =>• a3*+1vi 03*+2V2 : „3(*+l)
21. (avbv c)(a vfcvcvOvlv- •v9)\
31. Let Gi = (Vi, Si, v0, h*i) and G2 = (V2, 52, v0, h>2).
Define G = (Vx U V2, Si U 52, v0, h>) as follows. If 23. ab(d v (d(c v </)</))*.
v/ h>i ivvjt, then v,- h* vjv*. If V; i-^-i iv where iv consists
25. ab(abc)nb,n> 1.
of terminal symbols, then v, \-+ wv'0. All productions in
h>2 become productions in i-k 27. (aafc v afc)*.
Answers to Odd-Numbered Exercises 511

29.
vo
y = z* x => z ]*y = jc and thus fz-\ (y) = jc. Hence
<2> y R x and R is symmetric.
17. (a) Inspection of MR shows that R is reflexive and sym
metric. Since MR O MR = MR, R is transitive. Thus
R is an equivalence relation. The table below shows
that it is a machine congruence.
(b) 0 1
<D—<D K2K [1] [1] [1]
[2] [2] [2]
Exercise Set 10.3, page 407 19. (a) R is clearly an equivalence relation, so R sx and
fo(so) = sx, f0(sx) = s0, fx(sQ) = s2 = f(sx) so

(b)

oQ^^^^-^-^rl
0

21. Inspection of MR shows that R is reflexive and symmet


ric. Since MR O MR = M/?, R is transitive. Thus /? is an
equivalence relation. The digraph below shows that it is a
machine congruence.
0 1 Q

23. fx, x e /, is a function on S so fx is a state transition


function. T c. S so the conditions for a Moore machine
are met.

. 0 1
(so, So) (so, so) (si,sx)
(so, sx) (so, s2) (S\,S\)
(so, s2) (so, s2) (si,s3)
7. a fc (si,s3)
(so, s3) (so, s3)
*0 S\ Si (si,s0) (si,s0) (s2,sx)
Si S\ s2 (Sl,SX) (si,s2) (s2,sx)
Si so s2 (sx,s2) (si,s2) (s2,s3)
T F (si,s3) (si,s3) (s2,s3)
(s2, So) (s2,s0) (so,sx)
so S\ so
(s2,sx) (s2,s2) (so,sx)
S\ S\ sx
s2 S\ s2
(s2, s2) to, s2) (so, s3)
(s2, s3) (s2,s3) (so, s3)
a fc c

so so Si s2
Exercise Set 10.4, page 412
S\ s2 Si s3 1. fw(So) = S2, fw(sX) = 5-3, fw(s2) = So, fw(s3) = SX.
s2 s3 s3 Si 3. The number of l's in w is divisible by 4.
s3 s3 s3 s2
5. The number of l's in w is 2 + Ak, k > 0.
13. Let x e I. Certainly fx(s) = fx(s) for all s € S. Thus
7. fw(s0) = s0, fw(sx) = so, fw(s2) = s0.
jc R x and R is reflexive.
Suppose x Ry. Then fx(s) = fy(s) "is e S. But then 9. All words ending in fc.
y R x and R is symmetric. 11. Strings of 0's and l's with 3 + 5k l's, k > 0.
Suppose x Ry, y Rz. Then fx(s) = fy(s) = fz(s),
13. Strings of 0's and 1's that end in 0.
V.s e S. Hence x R z and R is transitive.
15. Strings of a's and fc's that do not contain fcfc.
15. Using Exercise 14, we need only show that R is reflexive
and symmetric. Let s e S. s = e * s so fe(s) = s and 17. Strings of 0's and 1's that end in 01.
s R s. Suppose x R y. Then fz(x) = y for some z e S. 19. Strings jcy and yz.
512 Answers to Odd-Numbered Exercises

21. Strings that begin 1 or 00. 19.

23. Let w, u e L(M). Then fw(s0) = s e T, fu(s) e T.


Hence fw.u(so) eT,sowue L(M).
25. w € L(M') U L(M") if and only if w e L(M') or
w e L(M"). Say w e L(M"). But w e L(M") if
and only if />0') e T" if and only if fw(s'0,s'0f) =

Exercise Set 10.5, page 419


G = (V, I, so, m>), V = {j0, sx, s2, s3, 0, 1}, / = {0, 1} 21. 0 1 T = {s,}
H> : So H* Oso, So \~> \S\, SX h-^ 0sX, SX h-f 1^2, ^2 H-> OS2, ^0 S| so
^2 H* 1^3, ^2 I-* 1, ^3 I—^ 0^3, S3 h->> 0, S3 h-> 1Sq- S\ S\ s2

(0vl)*l. s2 s3 so
s3 Si s4
G = (V, /, so, h+), V = {so, *i, *2, a, fc}, / = {fl, fc). s4 s3 so
(so) = a{s0) | b{sx) | a | fc
(si) = a(s0) l^2) l«
X y T = {s2}
(s2) = a(s2) I fc(s2)
so Si so
Si s2 Si
s2 s3 s2
s3 s3 s3

25. R is reflexive because fw(x) = fw(x). R is symmetric


becauseif fw(Sj), fw(Sj) areboth (not) in T, then fw(Sj),
fw(Si) are both (not) in T. R is transitive because s,- R Sj,
Sj R sk if and only if fw(si), fw(Sj), fw(sk) are all in (or
not in) T.
27. a,b

29. The construction of Exercise 24 of Section 10.3 gives a


machine that accepts a v p.

Exercise Set 10.6, page 424


1. Ro = {(s0, s0), (s0,sx), (sx,s0), (sx,sx), (s2,s2)}.
3. Rx = {(so, s0), (sx, sx), (s2, s2), (s3, s3),
(s4, s4), (so, s3), (s3, So), (sx,s2), (s2, sx)}.
5. RX21 = Rx.
7. R2 = /?,.
9. R = {(so,s0),(sx,sx),(s2,s2)}.
11. R = Rx as given in Exercise 6.
13. /? = {(So, So), (si, s,), (s2, s2), (s3, s3), (s4, s4), (s4, s5),
(s5, s4), (s5, s5), (s6, s6), (s3, s6), (s6, s3)}.

0
Answers to Odd-Numbered Exercises 513

Chapter 11

Exercise Set 11.1, page 439


1. (a) 3. (b) 2. (c) 3.
3. (a) Yes. (b) No.

5. (a) No. (b) No. (c) Yes. (d) No.


7. (a) Yes. (b) Yes.

9. Let axa2...axo be an ISBN. Suppose 0, and ai+x are


distinct and are transposed in transmission. Consider
ax+2a2 + 3a3-{ h*0/ + (/ +1H+H \-\OaXo-(ax +
0 1 2a2+3a3-\ h/fl/+i+(/ + l)aH HO0io) = ai+x-a,.
[a] [a] [c] Because 0 < 0/, 0,+i < 9, ai+x —ax cannot be congruent
lb] la] [d] to 0 (mod 11) and neither can ax+ 2a2+3a3 -\ hiai+x +
[c] [/] [d] (i + I)*,- + • • • + lO^io = ax + 2a2 + 3a3 -}- • • • + ia{ +
[d] [a] [d] (/ + \)ai+x + • • • + lO^io — (tf/+i —ai). Hence an error
if] la][/] would be detected.

21. The equivalence classes each contain a single state, so the 11. By definition, x®y = (xx+yx,x2 +y2,... ,xn+ yn) and
table is essentially that given in the statement of the exer Xj + y, = 1 if and only if jc,- ^ yt.
cise.
13. (a) 2. (b) 6.
23.
15. If jc = y, they differ in 0 positions and 8(x,y) = 0. Con
versely, if 8(x,y) = 0, then jc and y cannot differ in any
position and x = y.
17. 1.

19. (a) 3. (b) 2 or fewer.

21. Let 0 = 0000000, fc = 0010110, c = 0101000, d =


0111110, e = 1000101, / = 1010011, g = 1101101,
h = 1111011.

e a fc c d e f 8 h
0 a fc c d e f 8 h
fc fc 0 d c f e h 8
c c d a fc 8 h e f
d d c b 0 h 8 f e

e e f 8 h a fc c d
f f e h 8 fc 0 d c

8 g h e f c d a fc
h h 8 f e d c fc 0

25. M 23. 2.

0 0 0
0 1 1
1 0 0
25. 27. 1 1 0
1 0 1
0 1 1
0 1 0

29. (a) Yes. (b) No. (c) Yes. (d) No.

31. ew(000) = 000000 e„(100) = 100100


M ^(001) = 001111 e„(101) = 101011
ew(010) = 010011 £7/(110) = 110111
ew(011) = 011100 eH(\\\) = 111000
33. The statement of Theorem 2 is of the form p <$> q. Part
one of the proof shows that q =$> p. The second part estab
lishes p => 0 by showing —q=^^p (the contrapositive).
514 Answers to Odd-Numbered Exercises

Exercise Set 11.2, page 447 1. TAXDUE <- INCOME x 0.1

1. (a) Oil. (b) 101. 3. RETURN (TAXDUE)


END OF FUNCTION TAX
3. (a) 11. (b) 01.
3. 1. SUM <- 0
5. 00 01 10 11
2. FOR 1 = 1 THRU N
0000 1011 0110 1101 a. SUM «- SUM + X[I]
1000 0011 1110 0101 3. AVERAGE <- SUM/N
0100 1111 0010 1001
5. 1. DOTPROD <e- 0
0001 1010 0111 1100
2. FOR 1 = 1 THRU 3
7. 0. 9. 0. 11. 1. a. DOTPROD <- DOTPROD +
13. (a) 01. (b) 11. (c) 10. (X[J])(Y[I])
15. Possible answers: (a) 010. (b) 110. (c) 001. 7.1. RAD <- (A[2])2 - 4(A[1])(A[3])
17. (a) Suppose x € gxH 0 g2H. Then jc = gxhx = g2h2, 2. IF (RAD < 0) THEN
for some hx,h2 e H. We have gx = g2h2h\~l e g2H a. PRINT ('ROOTS ARE IMAGINARY')
since H is a subgroup. Hence gxH c g2H. Similarly, 3. ELSE

g2 = gihxh2l andg2H c gxH. Thus, gxH = g2H. a. IF (RAD = 0) THEN


1. RI < A[2]/(2A[1])
(b) Each element g of G belongs to gH. Part (a) guar
2. PRINT ('ROOTS ARE REAL
antees that there is a set of disjoint left cosets whose
AND EQUAL')
union is G.
b. ELSE
19. Since we want errors to be detected, no code word should 1. RI *- (-A[2] +
have weight 1. If 1 + n > 2n~m, coset leaders of weight SQ(RAD))/(2A[1])
< 1 can be chosen. 2. i?2 ^ (-A[2] -
21. 00000, 00001, 00010, 00100, 01000, 10000, 01010 (or SQ(RAD))/(2A[1])
10100), 00110 (or 11000). 9. 1. FOR 1 = 1 THRU N
23. 00,01, 10, 11. Same order as in Exercise 20. a. IF (A[I] # B[J]) THEN
1. C[J] <- 1
25. 000, 001, 010, 100, 011, 110, 011, 111. Same order as in
b. ELSE
Exercise 22.
1. C[J] «- 0
27. Possible answers: (a) 00. (b) 01. (c) 10.
11. 1. FOR 1 = 1 THRU N
29. e(01) = 01110. a. IF (A[I] = 0 AND B[J] = 0)
(a) Suppose 01010 is received when 01 is sent. This THEN
string is in the column headed 01 so it will be decoded 1. C[X] ^ 1
correctly. b. ELSE
(b) Suppose 01011 is received when 01 is sent. This 1. C[I^ *- 0
string is in the column headed 11 so it will be decoded 13. 1. SUM <- 0
incorrectly. 2. FOR J = 0 THRU 2 (N - 1) BY 2
a. SUM <- SUM + I
Exercise Set 11.3, page 452
15. 1. PROD <- 1
1. Since 391 = 17 • 23 and 12 is relatively prime to 391,
12702 = 122(17-.)(23-I) _ X(mod 391) 2. FOR 1 = 2 THRU 2N BY 2
a. PROD ^ (PROD) x I
3. 87. 5. 211.
17. 1. SUM <- 0
7. (a) m = 943, n = 880. (b) 601.
2. FOR J = 1 THRU 77
9. ACED. 11. 507. 13. 11463. a. SUM «- SUM + J2
15. 6095. 17. 151, 131. 19. CAN. 19. 1. SUM ^ 0
2. FOR 1 = 1 THRU 10
Appendix A, page 464 a. SUM «- SUM + (1/(31 + D)

1. FUNCTION TAX (INCOME)


21. MAX returns the larger of X and Y.
1. IF (INCOME > 30,000) THEN 23. F returns |X| .
a. TAXDUE <- 6000 25. Assigns \to Rii N \ M and assigns 0 otherwise.
2. ELSE
a. IF (INCOME > 20,000) THEN 27. X= £/;/istf + l.
1. TAXDUE <- 2500 7=1

b. ELSE 29. X = 25; / = 49.


Answers to Chapter Self-Tests
CHAPTER 1 SELF-TEST, page 47
(c)
1. P(A) is a set of sets.
2. | P (A)| is a counting number or infinity.
17. A has a A-inverse if and only if A = . - , the
3. LCM(<z, b) is a positive integer.
4. kA is a matrix of the same size as A. A-identity.
5. A mathematical structure consists of a set of objects,
CHAPTER 2 SELF-TEST, page 88
operations on those objects, and the properties of those
operations. 1. The converse is not equivalent to the original statement,
6. (a) (i) False. (ii) True. (iii) False. but the contrapositive is. In some cases, the contrapositive
(iv) True. (v) True. may be easier to prove than the original statement.
(b) (i) False. (ii) True. (iii) False, 2. In the strong form of induction all statements
(iv) False. (v) True. P(n0), P(n0 + 1),..., P(k) may be used to show
P(k + \), not just P(k).
7. (a) {1,2,3,4,...,}. (b) {..., -3, -2, -1,0} U B.
3. The mathematical structure of sets, union, intersection,
(c) {2,4}. (d) A.
and complement has the same properties as (logical
(e) {2,6,10,14,...}. statements, v, a, ~).
8. (a) 4. An indirect proof proves the contrapositive of the
statement or assumes the statement is false and derives a
contradiction.

5. A proof by contradiction proceeds by assuming the


negation of the conclusion of the statement to be proved.
9. Ad Bis always a subset of A U B. A U B c A n B if and Then definitions, previous theorems, and commonly
only if A = B. known facts are used to derive a contradiction.
10. (a) 6. (b) 18. (c) 41. 6. (a) False. (b) True.
11. 0, 0,1, -2, 9, -30. 7. (a) False. (b) True.
12. (a) 1 1 1 1 0 1 0 1 0 1
8- p q r (p A ^p) V (~ (q A r))
(b) 1 1 0 0 0 0 0 0 0 0
T T T F F F T
(c) 1 1 0 0 0 1 0 0 0 0 T T F F T T F

(d) 0 0 1 0 0 0 1 1 0 1 TFT F T T F
T F F F T T F
13. (a) Yes. (b) Yes. (c) No. (d) No.
F T T F F F T
14. 33 = 65(7293) - 108(4389). T T F
F T F F
15. (a) AB does not exist. F F T F T T F
12 F F F F T T F
(b) BA =
-U -15
-J]- 9. (a) q => p.
(1)
~q => ~p.
t (3) (2)

(c)
[o ii (d) A 4
(b) q =*• (~r) V (^s).
(c) (p V s) => q.
-q => (r A s).
(~p A ^s) =$- ~*q.
-1
(e) 3 (I) L0. (a) If |2| = |—2|, then 1 < -1.
2 If |2| £ |—2|, then 1 >-1.
ri 3 2i (b) If |2| = |-2|, then either -3 > -1 c>r 1 > 3.
(g) [2 12 8J' If |2| ^ |-2|, then -3 < -1 and 1 <c3.
1 1 0 1 1 1 (c) If 1 < -1 or 1 < 3, then |2| = |-2|.
16. (a) 1 1 0 (b) 1 1 0 If 1 > —1 and 1 > 3, then |2| # |-2 1.
1 1 0 1 1 1 LI. (a) False; 1 rue.

515
516 Answers to Chapter Self-Tests

(b) False; True. CHAPTER 3 SELF-TEST, page 119


(c) True; True.
1. If all items to be chosen are not from the same set, then
. p 4 P xor q the problem is not a simple combination or permutation
T T F problem. If the items to be chosen are from the same set,
T F T and if the order in which they are chosen matters,
F T T permutations should be counted; otherwise,
F F F combinations.

13. (a) If an Internet business makes less money, then if I 2. Pigeons can often be identified by the phrases "at least k
start an Internet business, then an Internet business is items have the property P(jc)" and the corresponding
cheaper to start. An Internet business is not cheaper pigeonholes are the possible values for P(x).
to start. Therefore, either an Internet business does
not make less money or I do not start an Internet 3. The recursive form may be easier to find or to justify, but
business. Valid.
this form may be difficult to evaluate for large n.

(b) If an Internet business is cheaper to start, then I will 4. The solution form may be more efficient to evaluate for
start an Internet business. If I start an Internet large n, but this form may be difficult to find.
business, then an Internet business will make less
5. The counting rules from Sections 3.1 and 3.2 are the
money. An Internet business is cheaper to start.
primary tools needed to answer the probability questions
Therefore, an Internet business will make less money.
presented in this chapter.
Valid.

14. No, consider 6 | —6and —6 | 6. If both m and n are 6. (a) 32. (b) 2,598,960. (c) 20,160.
positive (or negative), then n \ m and m | n guarantees 7. (a) 165,765,600. (b) 118,404,000.
thatfi = m.
8. (a) 7776. (b) 216.
15. Consider 7, 9, and 11. These are three consecutive odd
integers whose sum is not divisible by 6. 9. 560.

16. Basisstep: n = 0. P(0): 4° —1 is divisible by 3 is true 10. 15,173,928.


since 3 | 0.
Induction step: We use P(k): 3 divides4k —1 to show n\ 2-n\ + 2\(n-2)\n2
11. 2 + rc2 =
P(k + 1): 3 divides 4*+1 - 1. Consider (n-2)!2! (n-2)\2\
4*+1 - 1 = 4(4* - 1) + 3. By P(k), 3 | (4* - 1) and we (n-2)\n(n- 1 +/z)
have 4*+l - 1 = 3(a + 1) where a = 4k - 1. So
(n-2)!
3 | (4*+1 - 1).
(2n-2)!
= n(2n - 1)
17. Basis step: n = 1. P(l): 1 < is true. (2n-2)\
Induction step: We use P(k): (2/2)!
2! (2n 2)!
(k+\)2
1+2 + 3 + -.. + k <
= 2nC2.

toshowP(&+ 1): 12. L^J + 1=7 pieces, assuming the pepperoni slices are
not cut.
(k + 2)2
1+2 + ..• + (*+!)< 13. At least two months must begin on the same day of the
week. Let the seven days of the week be the pigeonholes
LHSofP(fc+l): and the twelve months of the year, the pigeons. Then by
the pigeonhole principle, at least |_yj + 1, or 2, months
1+2 +3+... +£+(fc+l)< (*+1} +(k+l) begin on the same day of the week.
K)
14.
k2+4k + 3 32*

15. No, p(A HB) = p(A) + p(B) - p(A U5) =


k2 + 4k + 4 0.29 + 0.41 - 0.65 = 0.05.
2 16. bn = -3"+4\
(k + 2)2
17. an =m"-lai - m"'2 - m"'3 m 2-l =
n
mn
™n~l ~ l .
RHSofP^+1). m — 1
Answers to Chapter Self-Tests 517

CHAPTER 4 SELF-TEST, page 177 13. Sincea R b implies b $ a,a Rb /\b R a is always false.
Hence a R b /\b R a =$> a = b is always true. R must be
1. A x B is a set of ordered pairs. antisymmetric.
2. A partition of A is a set of nonempty subsets of A. 14. (a) (u, v) R (u, v) since u — v = u —vis true. Thus R is
3. A relation may be given by a verbal description, a set of reflexive. If (u, v) R (x, y), then u — v = x —y and
ordered pairs, a digraph (in some cases) and as a matrix (x, y) R (u,v). Thus R is symmetric.
(in some cases). If ((u, v) R (jc, y)) A ((jc, y) R (w, z)), then
u — v = x —y = w —z and (u, v) R (w, z). Hence,
4. Unless \R\ is very small, using the matrix representation
R is transitive.
will be the most efficient way to determine if R is
transitive. (b) [(2, 3)] = {(2, 3), (1,2), (3,4), (4, 5)}.
5. The transitive closure of R is the connectivity relation (c) A/R = {[(2, 3)], [(2,4)], [(2, 5)], [(2, 2)], [(2,1)],
R°°; it is also the smallest transitive relation containing R. [(3,1)], [(4,1)], [(5,1)], [(1,5)]}.
6. (a) 12. 0 110

(b) {(2,1), (2, 2), (2, 3), (2,4), (5, 1), (5, 2), (5, 3), 15. Mr =
(5,4), (7,1), (7, 2), (7, 3), (7,4)}.
7. Let U = {1,2,3,4, 5}, A = {1, 2,_3), B = {2,3}. Then
16. (a) ZT' = {(a, a), (a, e), (b, a), (c, a), (c, b),
(2,5) € A x B, but (2, 5) £ A x 5.
(c,d),(e,c)}.
8. {{a, b, c], {d, e}}, {{a, b, d], {c, e}}, {{a, b, e], {c, d}},
(b) RoS = {(a, a), (a, b), (a, c), (b, b), (b, a), (b, c),
{{b, c, d], {a, e}}, {{b, c, e], {a, d}}, {{b, d, e), {a, c}},
(c, e), (c, c), (d, a), (e, c)}.
{{c, d, e), {a, b}}, {{a, c, d), {b, e}}, {{a, c, e), {b, d}},
{{a, d, e], {b, c}}, {{a, b, c, d}, {e}}, {{a, b, d, e], {c}}, 11111

{{b, c, d, e), {a}}, {{a, b, c, e), {d}}, {{a, c, d, e], {b}}. 11111
17. MUoo = 1 1 1 1 1
0 0 0 0'
11111
0 0 0
9. (a) 11111
1 0 0
1 0 0
CHAPTER 5 SELF-TEST, page 214

1. Let /: A -» B be a function, then \f(a)\ < l,a e A.


2. Assume that f(ax) = f(a2) and show that ax = a2.

10. (a)
3. Let /: A -* B. Choose b e B and find a e A such that
f(a) = b.
4. A hashing function is designed to assign items to a
limited number of storage places, and any mod-n function
has only n outputs.
5. The 0-class of a function / represents an approximation
of how values f(n) grow as n grows.
6. (a) Yes, \R(x)\ = \,x eA.
(b) No, (l,b),(\,d) e/T'.
(b) M* =
7. Suppose f(a) = f(b), then -5a + 8 = -5b + 8. But
then a = b so / is one to one. Let r eR. Then

M*2 = /(^H(^)« : r - 8 + 8 = r.

So / is onto.
riii i 8. (a) 16. (b) -2.
0 111
(C) Mfloc = 9. (a) 17. (b) -1.
0 111
.0111 10. (a) 0. (b) 6.

11. Reflexive, not irreflexive, not symmetric, not asymmetric, 11. True; false.
not antisymmetric, not transitive. 12. (a) 89. (b) 107. (c) 30; 4; 88.
12. Not reflexive, not irreflexive, not symmetric, not 13. 2n2 + 9n + 5 < 2n2 + n2 + n2,n> 9. Choose 4 for c and
asymmetric, antisymmetric, not transitive. 9 for A:. Then |2n2 + 9n + 5| <4\n2\,n > 9.
518 Answers to Chapter Self-Tests
14. 0(2n). 11. 1' = 105; 3' = 35; 5' = 21; 7 = 15; 15' = 7; 21' = 5;
35' = 3; 105' = 1.
15. /(AO = 2+ 5[fJ + l;0(n).
16. (a) (1,4, 5) o (2, 3, 6); (1, 5) o (1,4) o (2, 6) o (2, 3). 12. (a) R is reflexive, because the main diagonal of M/? is all
ones. R is antisymmetric, because if m,-y- = 1, then
(b) (2,6,3)o(l,5,4).
rriji —0. MRi = MR, so R is transitive.
/1
1223
3 4
4 567\
17, w \55 22 33 1 4 1 6/
(\ 2 3 4 5 6 7\
w \4 3 2 5 6 7 I)'
(c) Pl = (1,7, 6,5,4)o(2,3) =
(1,4) o (1,5) o (1,6) o (1,7) o (2,3); odd.
13. Since a <b <bv d and c <d <bv d,we have
CHAPTER 6 SELF-TEST, page 266 a v c < fc v J. (a v c is the LUB of a and c.) Also,
a Ac <a <b and a Ac <c <d since a A c is the GLB
1. Partial order is a generalization of less than or equal for of a and c. Thus, a A c < b A d.
the real numbers.
14. (a) (1) is not a lattice; fc v c does not exist.
2. In a partial order not every pair of elements must have a (2), (3), and (4) are lattices.
least upper bound and a greatest lower bound.
(b) (1), (2), and (3) are not Boolean algebras; the number
3. A model for any Boolean algebra is the power set of a set of vertices is not a power of 2. (4) is B3.
and the subset relation.
15. (a)
4. The Karnaugh map of a function is an n x n array of 0's
and 1's used to create a Boolean expression that produces
the function.

5. Every Boolean function can be produced by a Boolean


expression; every Boolean expression produces a Boolean
function.

6. (a) R is reflexive, antisymmetric, and transitive. Hence, (b) D63 is not a Boolean algebra; there are 6 elements.
R is a partial order on A. 16. (a) ((jc A y) v (y A z'))'. (b) (y A (jc v *'))'•
(b) R is reflexive and transitive, but not antisymmetric.
(c)
R is not a partial order.
(a) ^ (b) f4DH>>--

17. (jc A /) V (y A z').

CHAPTER 7 SELF-TEST, page 302

8. (a) Minimal: d, e; maximal: a. 1. A tree is a relation with certain conditions.

(b) Least: none; greatest: a. 2. The only change in performing a preorder, inorder, or
postorder search is when the root is visited.
9. (a) Upper bounds: 12,24,48.
(b) Lower bounds: 2.
3. The other three sequences are (i) right, root, left,
(ii) right, left, root, and (iii) root, right, left.
(c) LUB(fl) = 12. (d) GLB(B) = 2.
4. A complete n-tree usually has smaller height than a
•in / ^ A/l v, x
10. (a) a A (b v c) = { ,
fa if a < b v c or a. ~< b, c (I)
.r , ~ )' general n-tree with the same number of vertices. This
w v } \ bv c if bvc <aorb,c < a (2) would shorten a search of the tree that begins at the root.
) a y a or a (1) 5. An estimate of how many vertices and edges the graph
Thus, (a A b) v (a A c)
bvc (2) has would help in the decision process.
a if (b A c) < « or b, c < a (3) 6. It is not a tree; deleting either (2, 3) or (5, 3) will give a
(b) aV(bAc) =
b Ac if a < (b A c) or a < b, c (4) tree with root 4.

7. (a) 4. (b) t>4, vio, v6, v9, vs.


{ a A a or a (3)
Thus, (a v fc) a (a v c)
b AC (4) (c) 4. (d) v6, vs.
Answers to Chapter Self-Tests 519

8. Every edge (v{, Vj) in (T, v0) belongs to a uniquepath


from vo to Vj. Hence removing (i;,, Vj) would mean there
is no path from v0 to Vj.
9.

17. GC, AD, GB, GA, BF, AE.


A

CHAPTER 8 SELF-TEST, page 340

x 3 x 3 x 2 x 2 1. A quotient graph is a quotient set of the vertices with a


10.
graph structure of inherited edges.

2. An Euler circuit must use all edges exactly once; a


Hamiltonian circuit must use all vertices exactly once
except for the starting vertex, which is also the ending
vertex.

3. The subset of edges cannot contain edges whose end


points do not belong to the subsets of vertices.
R T
4. Any matching problem can be converted to a maximum
11. (a) UCRETSURT. (b) ERCRTUSTU.
flow problem by adding to the graph a supersource and a
supersink, and giving each edge capacity 1.
^5,
5. Since the chromatic polynomial counts the number of
ways the graph can be colored with x colors, the smallest
value of x for which P(x) j^O is the minimum number
of colors needed; that is, the chromatic number.

6.

13.

7. One solution is

14.

8. [v2]
\v{\

[v-j]

15. One solution is 9. (a) Neither an Euler circuit nor path. There are more
than 2 vertices of odd degree.
A B H
(b) An Euler circuit. All vertices have even degree.

10. (a) A Hamiltonian circuit.

16. EA, AD, AG, GC, GB, BF. (b) A Hamiltonian path, but not a circuit.
520 Answers to Chapter Self-Tests

11. (a) fT T T T 17. Pg(jc)=jc(jc- 1)(jc-2)3


Pg(0) = Pc(l) = ^g(2) = 0, />c(3) = 6.

n—x—<>—x—<>—x—"
CHAPTER 9 SELF-TEST, page 383

• o n •
1. A set is closed with respect to a binary operation if using
the operation with any two elements of the set yields an
element that belongs to the set.
n o
2. An isomorphism between two semigroups must preserve
(b) One solution is the operations, but an isomorphism between posets must
preserve the orders. In each case the mapping must be a
i l i i 10 •
one-to-one correspondence and preserve the defining
22 2 11
structure, multiplications for groups and orders for posets.
14
* 21 4 l 12 4> 3. The relation must be reflexive, symmetric, and transitive
20 r 15 " 13
19 3 16 and preserve the binary operations.
4. Groups are said to have more structure than semigroups,
^ 18 ( 17 17* because they must satisfy more conditions.
4 6

<> <>
5. A field must contain a multiplicative inverse for each
nonzero element; this is not required in a ring.
12. One solution is 6. (a) Yes, A * B is well defined for all 2 x 2 Boolean
matrices.
5
(b) Yes, this is ordinary addition for even numbers.
(c) Yes, 2ab is defined uniquely for all a, fc in Z+.
* a fc c where • represents a, fc, or c.
a a c a

fc c fc fc
13. One solution is
c • fc c

2/ 8. (a) If a, fc e Q, then a * fc is also a rational number.

a * (fc* c) = a * (fc-1- c —be)


= a + (b + c-bc)-a(b + c-bc)
= a + b + c — be — ab — ac + abc.
14.
(a * fc) * c = (a + fc —ab) * c
= a + b —ab + c —(a + b —ab)c
= a+b + c — ab — ac — bc + abc.

Hence, * is associative. Zero is the identity for


(Q, *), which is a monoid.
5 2 (b) Ifa# l,then
15. value(F) = 6.
a * =a+-?—-a(-?—)
a —I \a — \ J
a2 —a + a —a2

= 0.

Thus all rational numbers except 1 have a *-inverse.


9. (a) and (b) are monoids, (c) is neither.
16. (a) 10. R has previously been shown to be an equivalence
relation, because it is equality for the string lengths.
Suppose a R fc and a R fi, then length(a • a) =
length(a) + length(a) = length(fc) + length(£) =
C D
length (fc • fi). Thus a • a R fc • fi and R is a congruence
(b) 3. relation.
Answers to Chapter Self-Tests 521
11. No, f(ab) = (ab)~l = fc-1*-1 / f(a) • /(fc). 8. (a)
12. {c, d,e} = H = He = Hc = Hd;
Ha = {a, fc, f} = Hb = Hf.
13. Let g e G2 and n e f(N). Since / is onto, there is a
g' € Gi such that f(g') = g. Since « e f(N), there is an
n' eN such that /(w') = n. Then
£« = f(g')f(n') = f(g'n'). N is normal in Gx so
gV = n"g' for some n" e N. Then
/(*'»') = /W) = f(n")f(g') = f(n")g e f(N)g.
Thus g - f(N) c f(N) • g. Similarly, we can show
/(AO • g c g • /(AO and hence g . /(tf) = /(AT) • g for
all g e G2.
14. Suppose jc2 = jc. Then jc-1 (jcjc) = x~lx and (b) <!*)::= 1<W!> | 3<«i> | 5<«i>
(jc_ijc)jc = e. Sox = e. (vx)::=l(vx)\2(vx)\3(vx)\4(vx)\5(vx)\2

15. f(a + b) = 2(a + fc) = 2a +2fc = /(a) + /(fc) so / is a 9. L(G) = {(1 v 3 v 5)(1 v 2 v 3 v 4 v 5)rt2, n > 0}.
homomorphism. For any even integer n,n = 2k,k eZ, 10. G = (V, S, v0, h*) with V = {v0, vx,0, 1}, S = {0,1},
and f(k) = nsof is onto. Suppose f(a) = f(b). Then and h^ : vo \-+ 0v0, vq\-+ \vx,vx h^ 0t>i, vx \-+ 0.
2a = 2fc and a —b. Hence / is one to one. 11.
it
16. Since the identity e belongs to every subgroup, e e f^Hj.
i=l
k

Supposeh and h! belong to f] Ht. Then h, h!,and hb!


/=i
k k

belong to each Ht and hh' e f)Hj. Let h e f]Hi. Then


/=i 1=1

h and /z_1 belong to each //,, since each Hi is a subgroup


k
of G and so h~l e f\Hs. 12. Strings of 0's and l's with 3k zeros, k > 0.
/=i
13. (a) R is easily seen to be an equivalence relation with
17. The inverseof a + fcV« must be of the form equivalence classes {so}, teh {•?!> ^2* &*}, {ss, s^}, and
{s7}.
a —bsfn
a b c
a2 - nb2'
[sol [Si] [sx] [S3]
But thisexists in the set if and only if a2 —nb2 ^ 0 if and [Si] [Sl] [ss] [sx]
only ifn ^ (f) ifand only if *Jn ^ f. [S3] [S3] [sx] [S3]
[ss] [Sl] [ss] [Sl]
[Si] [Sl] [Sl] [Sl]
CHAPTER 10 SELF-TEST, page 426

1. No, type 0 and type 1 languages cannot be given in BNF.


2. Some type 2 and type 3 grammars can be represented by
a syntax diagram.
3. This language is type 2, context-sensitive, but importantly a, fc, c
it is not regular.
4. A machine accepts or recognizes a language if and only if 14. Strings with exactly 4k b's,k > 0.
every string in the language leads from the starting state
to an acceptance state; that is, fw(so) is an acceptance
state.

5. A language L is regular if and only if L = L(M) for 0 0 0,1


some Moore machine M. 110 0"
110 0
6. (a) False, (b) True. (c) True. (d) False. 16. MRo =
0 0 11
7. L(G) = {ancmdbn, n > 0, m > 0}. 0 0 11.
522 Answers to Chapter Self-Tests

Ri = {(so, so), (sx,sx), (s2, s2), (s3, s3), (s2, s3), (s3, s2)}. 5. (a) Yes. (b) No. (c) No. (d) No.
17. (a) k = 1. 6. (a) Yes. (b) Yes. (c) Yes.
(b) R = {(so, s0), (sx,sx), (s2, s2), (s3, s3), (s2, s3), 7. One.
(s3,s2)}.
8. Letc, = 00000, c2= 11110, c3 = 01101, c4 = 10011,
c5 = 01010, c6 = 10100, c7 = 00111, c8 = 11001.

e Cl c2 c3 ca c5 ce Cl eg
C\ Cl c2 c3 ca cs ce Cl eg
c2 c2 Cl ca c3 ce c5 cs Cl
c3 c3 ca Cl c2 Cl c8 c5 ce
ca ca c3 c2 Cl c8 Cl ce c5
c$ c5 ce Cl c% Cl c2 c3 ca
CHAPTER 11 SELF-TEST, page 454
ce ce c5 c% Cl c2 cx ca c3

1. An (m, n) encoding function can detect at most Cl Cl c% C5 ce c3 ca cx c2

(minimum distance minus 1) errors. eg c% Cl Q> c5 ca c3 c2 C]

2. Every possible string that could be received must belong The table shows this subset is closed for ©, contains the
to exactly one coset. identity for B5, and containsthe inverse of each element.
3. A maximum likelihood decoding function will choose the 9. 0.
most likely original word by choosing one that produces a
10. 11.
string closest to that received.
11. 88.
4. Messages are encoded for efficiency, error-detection, and
security purposes. 12. 13,32.
Glossary
algorithm: An algorithm is a complete set of steps necessary group: A group is a mathematical structure with an associative
to perform a task. binary operation, an identity element, and an inverse for each
big O: If / and g are functions whose domains are subsets element.

of Z+ and there exist constants c and k such that \f(n)\ < group code: An (m, n)-encoding function, e: Bm -> Bn, is a
c • \g(n)\ for all n > k, then / is big-0 of g, or / is 0(g). group code if e(Bm) is a subgroup of Bn.
binary operation: A binary operation on a set A is an every integer: An integer is one of the numbers ..., —3, —2, —1,0,
where defined function from A x A to A. 1,2,3,....
binary tree: A tree is binary if each vertex has at most two isomorphism: An isomorphism between two mathematical
offspring. structures A and B is a one-to-one correspondence between
Boolean algebra: A finite lattice is a Boolean algebra if it is A and B that preserves all the properties of the operations of
isomorphic to the lattice (P(S), C) for some finite set S. the mathematical structure.

Boolean matrix: A Boolean matrix is a matrix whose entries language accepted by a Moore machine: For a Moore ma
are either zero or one.
chine M the language accepted by M is the set of all input
strings that cause the start state to move to an acceptance state.
chromatic number: The chromatic number of a graph is the
smallest number of colors needed to color the vertices of a
language of a grammar: The language of a grammar G is
graph so that adjacent vertices have different colors. the set of all strings that can be properly constructed using the
productions of G.
circuit: A path that begins and ends at the same vertex is a
circuit.
lattice: A lattice is a partial order such that every two-element
subset has both a greatest lower bound and a least upper bound.
combination: A combination of n items taken r at a time is an
r-element subset of a set of n items.
least upper bound (greatest lower bound): An element a of
a lattice is the least upper bound (greatest lower bound) of a
congruence relation: An equivalence relation on a semigroup subset B if b < a (a < b) for all b e B and if a' is an upper
is a congruence relation if products of related items are also (lower) bound for B, then a < a' (a' < a).
related.
loop invariant: A loop invariant for a programming loop is
conjecture: A mathematical statement obtained by observa a statement that is true before and after each pass through the
tion and guesswork, which has not been proved or disproved. loop.
contrapositive: The contrapositive of a conditional statement matching problem: Given two sets A and B and a relation R
of the form if p, then q is the equivalent statement if not q, from A to B, a matching problem is to find a one-to-one func
then not p. tion M from the largest possible subset of A to a subset of B
converse: The converse of a conditional statement of the form such that M c R.
if p, then q is the statement if q, then p. mathematical induction: Mathematical induction is a tech
cryptology: Cryptology is the science and study of coding niquefor provingstatementsthat involve the natural numbers;
messages for security purposes. this method has two parts, a basis step and an induction step.
digraph: A digraph is a pictorial representation of a finite re mathematical structure: A mathematical structure consists
lation using vertices and directed edges. of a set of mathematical objects, operations on those objects,
equivalence relation: An equivalence relation is a relation that and the properties of the operations.
is reflexive, symmetric, and transitive. matrix: A matrix is a rectangular array of numbers.
Euler (Hamiltonian) path (circuit): An Euler (Hamiltonian) minimal spanning tree: A minimal spanning tree of a
path (circuit) is a path (circuit) that includes every edge (ver weighted graph is an undirected spanning tree for which the
tex) exactly once (except for the first and last vertex in a cir total edge weight is least.
cuit). (iw, w)-encoding function: An (m, /t)-encoding function is a
field: A field is a ring in which every element except the one-to-one function from the group Bm to the group B".
+-identity has a *-inverse. monoid: A semigroup with an identity element is called a
finite-state machine: A finite state machine is a set of states monoid.
S, a set of inputs /, and a set of functions /, i e I from S to Moore machine: A Moore machine is a finite-state machine
S. in which there is a start state and some states are distinguished
function: A function is a relation from A to B for which as acceptance states.
|/(fl)|<l,fl€A. multiplicative property: The multiplicative property is a
graph: A graph is a set of vertices, a finite set of edges, and a counting method for the number of ways a sequence of tasks
function that assigns to each edge a pair of vertices. can be performed.
G-l
G-2 Glossary

one-to-one function: A function / is one to one if regular grammar: A grammar is regular if the left-hand side
f(a) = f(b) implies a = b. of each production is a single nonterminal symbol and the
operation: A mathematical operation is a process for produc right-hand side has one or more symbols, with at most one
ing a mathematical object from one or more mathematical ob nonterminal that must occur at the right end of the string.
jects. relation: A relation from set A to set B is a subset of A x B.
partial order: A relation is a partial order if it is reflexive, ring: A ring is a mathematical structure S with two binary op
antisymmetric, and transitive. erations -I- and * such that (S, +) is an Abelian group, (S, *)
path: A path in a graph is a sequence of vertices vx,v2, ...,vn is a semigroup, and * distributes over +.
and a sequence of distinct edges ex,e2,..., en-X such that each RSA public key cryptosystem: The RSA public key cryp-
successive pair of vertices v{, vi+x are adjacent and are the end tosystem is a method of coding and decoding messages using
points of et. a pair of published integers.
partition: A partition of a nonempty set is a set of nonempty, search of a tree: A search of a tree is a procedure for visiting
disjoint subsets whose union is the full set. each vertex of the tree in some specific order.
permutation: A permutation of n items taken r at a time is a semigroup: A semigroup is a mathematical structure with an
sequence of r items chosen from the set of n items. associative binary operation.
permutation function: A permutation function is a one-to- sequence: A sequence is a list of objects arranged in a definite
one function from a finite set to itself. order.
phrase structure grammar: A phrase structure grammar con set: A set is a well-defined collection of objects.
sists of a set V containing terminal symbols, nonterminal sym statement: A statement is a declarative sentence that is either
bols, and a start symbol along with a relation on V* that spec true or false, but not both.
ifies allowable replacements.
0-class: © is an equivalence relation on the set of functions
pigeonhole principle: The pigeonhole principle is the state whose domains are subsets of Z+ defined by / © g if and only
ment that if m < n and n pigeons are assigned to m pigeon if/isO(g)andgistf(/).
holes, then at least one pigeonhole contains two or more pi
transport network: A transport network is a connected di
geons.
graph with a unique vertex of in-degree 0 and a unique vertex
power set: The power set of A is the set of all subsets of A. of out-degree 0 and whose edges are labeled with nonnegative
probability: The probability of an event is a numerical mea numbers.
sure of the likelihood of the event. tree: A tree is a relation on A such that there is a distinguished
proof: A proof is a sequence of statements leading to a valid element vq, the root, from which there is a unique path to every
conclusion. other element in A.
proof by contradiction: A proof by contradiction is an indi undirected spanning tree: An undirected spanning tree for a
rect proof technique based on using the negation of the desired relation is an undirected tree with exactly the same vertices as
conclusion to produce a contradiction. the relation.
recurrence relation: A recurrence relation is a recursive for weighted graph: A weighted graph is a graph whose edges
mula for a sequence. have been labeled with a number, its weight.
Index
Banzhaf power index, 49
Base, 27
Abelian group, 362 CALL statement, 455, 462
Base b expansion, 27
Absorption properties of a lattice, 237 Cancellation property
Base 10 expansion, 27
Absurdity, 58 left, 363
Base 2 exponential function, 191
Acceptance state, 405 right, 363
Basis step of induction, 68
Acyclic symmetric relation, 289 Capacity
Biconditional statement, 57
Addition principle, 9 of a cut, 327
Bijection, 184 of an edge, 321
Adjacent vertices, 144, 288, 306
Binary operation, 41, 345 Cardinality of a set, 4
Algorithm(s), 21,455
associative, 42, 347
branch of, 456 Cartesian product, 123, 124
commutative, 42, 346 Catalan numbers, 118, 199, 469-470
Euclidean, 23
idempotent property of, 347 Catenation of strings, 17
Fleury's, 315
identity for, 43, 350 Cayley, Arthur, 1,270
greedy, 296
on a set, 345 Ceiling function, 190
Kruskal's, 299
Binary tree, 273
labeling, 323-324 Cell
complete, 273 of a partition, 125
Prim's, 293,296,298
positional, 276 storage, 152,277
running time of, 203, 215
Bipartite graph, 334 Central operator, 275
structured, 456
Block Certain event, 105
subroutine of, 455
maximal compatibility, 178 Chain, 219
Warshall's, 171-172
of a partition, 125 Markov, 119
X, 80, 338
BNF notation, 394 Characteristic equation, 115
Alphabet, 17
Boole, George, 50 Characteristic function of a set, 15,
Alternating group on n letters, 368
Boolean algebra, 244 190, 195
And gate, 251
atom of, 249 Check digit, 199
Antecedent statement, 57
De Morgan's laws for, 246 Chosen at random, 108
Antisymmetric relation, 142
involution property of, 246 Chromatic number, 335
Appel, Kenneth, 305
Argument of a function, 181 properties of, 247 Chromatic polynomial, 336
substitution rule for, 246 Circuit, 307
Array
of dimension two, 34
Boolean expression, 251 Euler, 311
Boolean function, 191 Hamiltonian, 318
linear, 14
m x n, 34
Boolean matrices simple, 307
Associative operation, 42, 347 join of, 37 Circular relation, 152
meet of, 37 Class
Associative property, 8, 42, 347
Associative properties mod-2 product of, 435 lower, of functions, 201
of a Boolean algebra, 247 mod-2 sum of, 435 Clique, 342
of a lattice, 237
product of, 38 Closed with respect to an operation, 42,
Boolean matrix, 37 345
of logical operations, 59
of set operations, 8 complement of, 161 Closure

Asymmetric relation, 141 Boolean polynomial, 250 of an operation, 42


Atom of a Boolean algebra, 249 Boolean product, 38 reflexive, 164
mod-2, 435 of a relation, 164
Attribute, 124
Automaton, pushdown, 427 Boolean sum (mod 2) of matrices, 435 symmetric, 164
Bound transitive, 164, 169
AVL tree, 288
Axioms for probability space, 107 greatest lower, 230 Coalition, 48
least upper, 230 Code
lower, 230 bar, 439
B
upper, 230 group, 434
Backtracking, 79, 113 Bounded lattice, 238 Huffman, 278
Backus-Naur notation, 394 Branch of an algorithm, 456 keyword columnar transposition, 208
Bacon's code, 29-30 Bridge, 315 parity check, 431
Balanced n tree of height k, 275 J5-tree of degree k, 303 substitution, 187
Banzhaf power distribution, 49 BY statement, 461 transposition, 208
ii
1-2 Index

Code word, 430 Congruence Deadlock, 269


Collision, 192 machine, 406 Decimal expansion, 27
Coloring of a graph, 334 mod a, 148 Decoding function, 440
proper, 335 relation, 356, 373 maximum likelihood, 441
Column of a matrix, 32 Congruent to r mod a, 148 Decoding table, 444
Combination of n objects taken r at a Conjecture, 75 Degree of a vertex, 306
time, 97 Conjunction of statements Derivation of a sentence, 389
number of, 97 (propositions), 52 Derivation tree, 389
with repeats, 98 Connected graph, 308 Descendants of a vertex, 273
Common divisor, 22 Connected symmetric relation, 144 Detect k or fewer errors, 431
greatest, 22 Connected vertices, 332 Deterministic, 104
Common multiple, 25 Connective, 52 Diagonal
least, 25 Connectivity relation, 136 main, of a matrix, 32
Commutative operation, 42, 346 Consequent statement, 57 matrix, 32
Commutative properties Conservation of flow, 322 Diagram
of a lattice, 237 Constructive proof, 101 Hasse, 222
of logical operations, 59 Context-free grammars, 392 logic, 252
of set operations, 8 Context-sensitive grammars, 392 master, 400
Commutative ring, 377 Contingency, 58 syntax, 396
Comparable elements of a poset, 218 Contradiction, 58 Venn, 3
Compatibility proof by, 65 Dictator, 48
maximal block, 178 Contrapositive of an implication, 57 Digraph, 132
relation, 178 Converse of an implication, 57 cycle in, 136
Compatible matching, 330 Corrects k or fewer errors, 440 edge of, 132
Compatible strings, 420 Correspondence of a finite-state machine, 405
Complement one to one between A and B, 184 labeled, 182
of a Boolean matrix, 161 principle, 225 path in, 136
of an element of a lattice, 240 Coset
of a relation, 132
of a fuzzy set, 195 leader, 443
vertex of, 132
of a fuzzy set B with respect to A, left, of a subgroup, 373 Direct derivability, 388
195 right, of a subgroup, 373 Directed graph; see Digraph
properties of, 9 Countable set, 16
Disconnected graph, 308
of a set, 7 Counterexample, 66
Disconnected vertices, 332
of a set B with respect to A, 7 Counting
Discrete graph, 308
Complementary relation, 159 multiplication principle of, 92
Disjoint
Complemented lattice, 241 Covering of a set, 178
cycles, 207
Complete binary tree, 273 Cryptology, 27,429
events, 106
Complete graph, 308 Cut, 327
sets, 6
Complete matching, 331 capacity of, 327
Disjunction of statements
Complete n-tree, 273 Cycle(s), 136
(propositions), 52
Component of a graph, 308 disjoint, 207
Distance
Composition as a permutation, 206
function, 432
of paths, 139 simple, 289
Hamming, 432
of permutations, 206 Cyclic
minimum, of an encoding function,
of relations, 164
group, 385
433
Compound statement, 51 permutation, 206
between vertices, 295
Computer representation Distributive lattice, 239
D
of a digraph, 153-154 Distributive properties
of a positional binary tree, 277-278 Data structure, 153 of a lattice, 239
of a relation, 153-154 Database, 124 of logical operations, 59
of a set, 16 relational, 124 of set operations, 8
of a tree, 285 De Morgan, Augustus, 50, 122 Distributive property, 42
Conclusion, 63 De Morgan's laws Divides, 21
of an implication, 57 for Boolean algebras, 246 Divisor
Conditional statement, 57 for mathematical structures, 43 common, 22
Conditions for a recurrence relation, for sets, 9 greatest common, 22
113 for statements, 59 zero, 381
Index 1-3

Domain of a relation, 130 Euler, Leonhard, 180, 305 Formula


Doubly linked list, 277 Euler circuit, 311 explicit, 13
Dual partial order, 218 Euler path, 311 recursive, 13
Dual poset, 218 Even permutation, 210 Free semigroup, 349
Event(s), 105 Frequency of occurrence of E in n
E certain, 105 trials, 106
disjoint, 106 Function, 181
Edge, 132, 306
elementary, 107 argument of, 181
capacity of, 321
frequency of occurrence, 106 base 2 exponential, 191
end points of, 306
impossible, 105 Boolean, 191
undirected, 144, 288
mutually exclusive, 106 ceiling, 190
weight of, 295, 320
probability of, 106 characteristic, of a set, 190, 193
Eight queens puzzle, 85 Every where-defined function, 183 decoding associated with e, 440
Element
Exact cover, 79 distance, 432
complement of, 240
Existence proof, 101 encoding, 430
greatest, of a poset, 229 Existential quantification, 54 everywhere defined, 183
idempotent, 355
Expected value, 110 floor, 190
identity, 43, 350 Experiment hashing, 192
inverse of, 362
deterministic, 104 identity, 183
least, of a poset, 229 expected value of, 110 invertible, 185
of a matrix, 32
probabilistic, 104 log base n, 191
maximal, of a poset, 228 Explicit formula, 13
minimal, of a poset, 228 matching, 330
Exponential function maximum likelihood decoding, 441
order of, 384
base 2, 191 membership, for a fuzzy set, 193
of a set, 2
Expression mod n, 26, 190,466
syndrome of, 446 Boolean, 251
unit, of a poset, 230 one to one, 183
regular, 18 onto, 183
zero, of a poset, 230 over A, 17
Elementary event, 107 permutation, 205
Elementary probability, 107 propositional, 53
Empty relation, 141 state transition, 403,409
Empty sequence, 17 Factor semigroup, 358 corresponding to a string, 409
Empty set, 3 Factorial n, 94 value of, 181
properties of, 9 Fermat, Pierre de, 91 FUNCTION statement, 462^163
Empty string, 17 Fermat's Little Theorem, 380, 449 Fundamental homomorphism theorem,
Enabled transition, 268 Fibonacci sequence, 113, 116 359
Encoding function, 430 Field, 379 Fuzzy logic, 196
minimum distance of, 433 properties of, 379 Fuzzy predicate, 196
End points, 306 Finite group, 365 Fuzzy set(s), 193
Entry Finite sequence, 13 complement of, 195
of a matrix, 32 Finite set, 4 complement of B with respect to A,
Equality Finite-state machine, 403 195
of matrices, 33 congruence on, 406 intersection of, 195
relation, 141 digraph of, 405 membership function for, 193
of sets, 3 input set of, 403 symmetric difference of, 195
Equally likely outcomes, 108 monoid of, 411 union of, 195
Equivalence, 57 quotient of, 406
Equivalence classes of an equivalence state of, 403
relation, 150 state set of, 403
Equivalence relation, 148 state transition table of, 404 Galois, Evariste, 344
determined by a partition, 149 Firing a transition, 268 Gate
Equivalent machines, 421 Fleury's algorithm, 315 and, 251
Equivalent statements, 58 Floor function, 190 or, 251
Errors Flow, 322 GO TO statement, 456,464
corrects k or fewer, 440 conservation of, 322 Grammar, 388
detects k or fewer, 431 value of, 322 context-free, 392
k or fewer, 431 Flow chart, 457 context-sensitive, 392
Euclidean algorithm, 23 FOR statement, 461-462 phrase structure, 388
1-4 lnd«ex

Grammar (Continued) fundamental theorem, 359 Invariant


regular, 392 kernel of, 375 of a loop, 72
Typen(n=0, 1,2, 3), 392 natural, 359 Inverse
Graph, 306 of semigroups, 353 of a binary operation, 43
bipartite, 334 Huffman code, 278 of an element, 362
chromatic number of, 335 tree, 278 of a matrix, 36
coloring of, 334 Hypotheses, 63 relation, 159
complete, 308 Hypothesis, 57 Inverter, 251
components of, 308 Invertible function, 185
connected, 308 I Involution property in a Boolean
disconnected, 308 algebra, 246
Idempotent element, 355
discrete, 308 Irreflexive relation, 141
edges of, 306
Idempotent properties
ISBN, 199,439
isomorphic, 310
of a binary operation, 347
Isolated vertex, 306
of a lattice, 237
linear, 308 Isomorphic graphs, 310
path in, 307 of logical operations, 59
Isomorphic lattices, 236
planar, 335 of set operations, 9
Isomorphic posets, 224
quotient, 309 Identity
Isomorphic semigroups, 351
regular, 308 of a binary operation, 43, 350
element, 350
Isomorphic trees, 294
sub-, 308 Isomorphism, 224, 351
function, 183
of a symmetric relation, 144
matrix, 35
weighted, 295
Greatest common divisor, 22
ring with, 377
Greatest element of a poset, 229 IF-THEN-ELSE statement, 456,459 Join of two Boolean matrices, 37
Image
Greatest lower bound, 230 Join of two elements in a lattice, 233
Greedy algorithm, 296 homomorphic, 353
Group(s), 362 Image of a, 181
K
Abelian, 362 implication, 57
alternating, on n letters, 368 contrapositive of, 57 k or fewer errors, 431,440
code, 434 converse of, 57 Karnaugh map, 257
cyclic, 385 Impossible event, 105 Kernel, 375
finite, 365 Inclusion-exclusion principle, 9 Key, 124, 192
inverse in, 362 Incomparable elements of a poset, 225 public, 450
Klein 370
In-degree of a vertex, 133 Keyword columnar transposition, 208
normal subgroup of, 373 Indirect method of proof, 64 Klein 4 group, 370
Induction Kruskal's algorithm, 299
order of, 365
product of, 372 principle of mathematical, 68
quotient, 373 strong form of, 73
subgroup of, 368 Induction step, 68
Inequality relation, 141 Labeled digraph, 182
symmetric, on n letters, 367
Inference Labeled tree, 275
of symmetries of the triangle, 367
rules of, 63 Labeling algorithm, 323-324
Group code, 434
Infinite sequence, 13 Language
Guard, 53
Infinite set, 4 of a Moore machine, 412
Infix notation, 284 of a phrase structure grammar, 389
H
Influence semantics of, 387
Haken, Wolfgang, 305 two-stage, 341 syntax of, 387
Hall's Marriage theorem, 332 Initial conditions for a recurrence Type n(n = 0,1, 2, 3), 392
Hamiltonian circuit, 318 relation, 113 Lattice(s), 233
Hamiltonian path, 318 Inorder search of a tree, 283 absorption properties of, 237
Hamming distance, 432 Input of a machine, 403 associative properties of, 237
Hashing function, 192 Input-output relation, 182 commutative properties of, 237
Hasse diagram, 222 Input set of a machine, 403 bounded, 237
Height of a tree, 272 Interior vertices of a path, 171 complemented, 241
Homogeneous linear relation of degree Intersection distributive, 239
k,\\4 of sets, 6 distributive properties of, 239
Homomorphic image, 353 of fuzzy sets, 195 idempotent properties of, 237
Homomorphism, 353 Interval in a lattice, 241 isomorphic, 236
Index 1-5

modular, 242 M column of, 32


nondistributive, 239 diagonal, 32
m x n, 32
sub-, 235 element of, 32
Machine(s)
Laws identity, 35
acceptance state, 405
De Morgan's, 9,43, 59, 246 (/, 7*)th element of, 32
congruence, 406
Least common multiple, 25 (/, j) entry of, 32
digraph of, 405
Least element of a poset, 229 inverse of, 36
equivalent, 421
Least upper bound, 230 m x n, 32
finite-state, 403
Leaves of a tree, 272 main diagonal of, 32
input(s) of, 403
Left cancellation property, 363 parity check, 437
input set of, 403
Left coset of a subgroup, 373 regular, transition, 121
language of, 412
Left pointer, 277 monoid of, 411
of a relation, 130
Left side of production, 388 Moore, 405
row of, 32
Left subtree, 280 output of, 403 square, 32
Leibniz, G. W., 180 quotient, 406 symmetric, 36
Lemma, 149 transition, 120
quotient Moore, 407
Length recognition, 405 transpose of, 35
of a path, 135 starting state of, 405 of weights, 298
of a string, 191,392,411 state of, 403 zero, 33
Less than relation, 142 Max Flow Min Cut Theorem, 328
state set of, 403
Level state transition function of, 403 Maximal compatibility block, 178
same, 459 state transition table of, 404 Maximal element of a poset, 228
in a tree, 271 Main diagonal of a matrix, 32 Maximal matching, 331
Level n vertices, 271 Map Maximum likelihood decoding
Lexicographic order, 220 Karnaugh, 257 function, 441
Ig, log base 2 function, 191, 197 Mapping, 181 Maximum likelihood technique, 441
Likelihood Marking of a Petri net, 268 Meet
maximum decoding function, 441 Markov chain, 119 of two Boolean matrices, 37
maximum technique, 441 state vector of, 120 of two elements in a lattice, 233
Linear array, 14 Master diagram of a regular grammar, Message, 430
Linear graph, 308 400 Minimal element of a poset, 228
Linear homogeneous relation of degree Matching Minimal spanning tree, 296
it, 114 compatible with a relation, 330 Minimum distance of an encoding
Linear order, 219 complete, 331 function, 433
Linearly ordered set, 219 function, 330 Minterm, 255
Linked-list representation maximal, 331 Mod n, 28
of a relation, 153-154 problem, 330 Mod-n function, 26, 190
of a sequence, 152 Mathematical induction Mod-2 Boolean product, 435
of a tree, 285 principle of, 68 Mod-2 sum, 435
List, 14 strong form of, 73 Modular lattice, 242
doubly linked, 277 Mathematical statement, 75 Modulus, 148
linked, 152 Mathematical structure, 41, 344 Modus ponens, 64
Live Petri net, 269 Mathematical system, 41 Monoid, 350
Local variable, 463 Matrices free, 409
Log base n function, 191 Boolean product of, 38 idempotent element in, 355
Logic diagram, 252 equal, 33 of a machine, 411
Logic gate, 251 join of, 37 sub-, 350
Logical connectives, 52-54 meet of, 37 Moore machine, 405
Logically equivalent propositions mod-2 Boolean product of, 435 acceptance state of, 405
(statements), 58 mod-2 sum of, 435 language of, 412
Logically follows, 62 product of, 33 quotient, 407
Loop, 306, 457 scalar multiplication of, 41 starting state of, 405
Loop invariant, 72 sum of, 33 Multiple
Lovelace, Lady, 386 Matrix, 32 common, 25
Lower bound, 230 Bit, 37 ; see also Boolean matrix least common, 25
Lower class, 201 Boolean, 37 Multiplication principle of counting, 92
Lower order, 201 complement of, 161 Multiplication table, 365
1-6 Index

Mutually exclusive events, 106 same, 201 terminal symbol of, 388
Ordered pair, 123 Type n(n = 0,1, 2, 3), 392
N Ordered tree, 272 Pigeonhole principle, 101
Outcome(s), 104 extended, 102
Natural homomorphism, 359 equally likely, 108 Places of a Petri net, 268
Negation Out-degree of a vertex, 133 Planar graph, 335
properties of, 59 Output of a machine, 403 Pointer, 152
of a statement, 51
left, 277
Neighbor, nearest
right, 277
of a set of vertices, 296
Polish form, 282
of a vertex, 295 Palindrome, 100, 394
reverse, 284
Network, 321 Parent, 271
Polynomial
cut in, 327 Parity check code, 431
Boolean, 250
flow in, 322 Parity check matrix, 437
chromatic, 336
transport, 321 Parse tree, 392
Poset(s), 218
Noise, 430 Parsing a sentence, 392
dual, 218
Nondistributive lattice, 239 Partial order, 218
dual, 218
greatest element of, 229
Nonterminal symbol, 388
product, 219 Hasse diagram of, 222
Normal production, 395
Partially ordered set, 218 isomorphic, 224
Normal subgroup, 373
Partition, 125 least element of, 229
Notation
block of, 125 linearly ordered, 219
Backus-Naur, 394
cell of, 125 maximal element of, 228
infix, 284
Pascal, Blaise, 91 minimal element of, 228
postfix, 284
Pascal's triangle, 100 unit element of, 230
prefix, 282
Path(s) zero element of, 230
n-tree, 273
composition of, 139 Positional tree, 276
balanced of height k, 275
Euler, 311 binary, 276
complete, 273
in a graph, 307 Postfix form, 284
Hamiltonian, 318 Postorder search, 283
O
interior vertices of, 171 Power set of a set, 4
O (big oh), 200 length of, 135 Predicate, 53
Odd permutation, 210 in relations, 135 Prefix form, 282
Offspring of a vertex in a tree, 271 simple, 289, 307 Premises, 63
One-to-one correspondence between A Pentomino, 85 Preorder search of a tree, 280-281
and B, 184 Permutation(s), 94 Prime
One-to-one function, 183 cyclic, 206 relatively, 23, 147
Onto function, 183 even, 210 Prime number, 21
Open cover problem, 86, 338 function, 205 Prim's algorithm, 293, 296, 298
Operation, 41, 345 with limited repeats, 95 Principle
associative, 42, 347 of n objects taken r at a time, addition, 9
binary, 42 number of, 94 of correspondence, 225
on a set, 345 odd, 210 extended pigeonhole, 102
commutative, 42, 346 product of, 206 of mathematical induction, 68
idempotent property of binary, 347 up down, 213 multiplication, of counting, 92
project, 125 Petri net, 268 pigeonhole, 101
select, 125 deadlock in, 269 PRINT statement, 464
table, 346 live, 269 Probabilistic, 104
unary, 42 marking of, 268 Probability
Or gate, 251 places of, 268 elementary, 107
Order transitions of, 268 of an event, 106
of an element in a group, 384 Phrase structure grammar, 388 space, axioms for, 107
of a group, 365 derivation in, 389 transition, 120
lexicographic, 220 language of, 389 Product
linear, 219 nonterminal symbol of, 388 Boolean, of two matrices, 38
lower, 201 production of, 388 Cartesian, 123, 124
partial, 218 production relation of, 388 mod-2 Boolean, 435
product partial, 219 regular, 392,400 partial order, 219, 235
Index 1-7

in a semigroup, 349 semigroup, 358 partial order, 218


set, 123 set, 125, 150 path in, 135
of two groups, 372 constructed from an equivalence production, 388
of two matrices, 33 relation, 150 quasiorder, 227
of two permutations, 206 Quota, 48 range of, 130
of two semigroups, 356 reachability, 139
Production, 388 R recurrence, 113
left side of, 388 reflexive, 141
Random selection, 108
normal, 395 reflexive closure of, 164
Range of a relation, 130
recursive, 395 restriction of, 134
Reachability relation, 139
right side of, 388 on a set, 128
Recognition machine; see Moore
Production relation, 388 symmetric, 141
machine
Project, 125 symmetric closure of, 164
Recurrence relation, 113
Proof transitive, 144
characteristic equation of, 115
constructive, 101 transitive closure of, 164, 169
linear homogeneous of degree k, 114
by contradiction, 65 Relational database, 124
Recursive formula, 13 ; see also
existence, 101 attribute, 124
Recurrence relation
indirect method, 64 Relatively prime, 23, 147
Recursive production, 395
steps in, 65 Restriction of a relation, 134
Reflexive closure of a relation, 164
Proper coloring of a graph, 335 RETURN statement, 459,462
Reflexive relation, 141
Property Reverse Polish form, 284
Regular expression, 18,400
absorption, 237 Right cancellation property, 363
over A, 17
associative, 8, 42, 59, 237, 247 Right coset of a subgroup, 373
Regular grammar, 392, 400
cancellation, 363 Right pointer, 277
Regular graph, 308
closure, 42 Right side of a production, 388
Regular set, 18,400
commutative,8, 42, 59, 237 Right subtree, 280
Regular subset, 18
of the complement, 9 Ring, 377
Regular transition matrix, 121
of the distance function, 432 commutative, 377
Relation(s),
distributive, 8,42, 59, 239 with identity, 377
on A, 128
of the empty set, 9 subring, 381
from A to B, 128
idempotent, 9, 59, 237, 347 unit of, 381
acyclic symmetric, 289
involution, 246 zero divisors of, 381
antisymmetric, 142
Proposition(s), 51 Root of a tree, 271
asymmetric, 141
conjunction of, 52 Rooted tree, 271
circular, 152
disjunction of, 52 Row of a matrix, 32
closure of, 164
equivalent, 58 R-relative set
compatibility, 178
logically equivalent, 58 of A, 130,332
complementary, 159
negation of, 51 of x, 130
composition of, 164
Propositional function, 53
computer representation of, 153-154 Rules of inference, 63
Propositional variable, 51 Running time of an algorithm, 203, 215
congruence, 356, 373
Prove a theorem, 63
connected symmetric, 144 Russell, Bertrand, 122
Pseudocode, 26, 458,459-460
connectivity, 136
Public key, 450
digraph of, 132
RSA cryptosystem, 449
domain of, 130
Pushdown automaton, 427 Same level, 459
empty, 141
equality, 141 Same order, 201
equivalence, 148 Sample space, 104
Quantification classes of, 150 Scalar multiplication, 41
existential, 54 determined by partition, 149 Search

universal, 54 graph of symmetric, 144 inorder, 283


Quantifiers, 54 inequality, 141 postorder, 283
Quasiorder, 227 input-output, 182 preorder, 280-281
Quotient inverse, 159 tree, 280
finite-state machine, 406 irreflexive, 141 Searching a tree, 273
graph, 309 less than, 142 Select, 125
group, 373 linear homogeneous, of degree k, 114 Selection, 459
Moore machine, 407 matrix of, 131 random, 108
1-8 Index

Semantics of a language, 387 uncountable, 16 catenation of, 17


Semigroup(s), 349 union of, 5 compatible, 420
factor, 358 universal, 3 empty, 17
free, 349 Venn diagram of, 3 length, 191,392,411
homomorphism, 353 Shannon, Claude, 217,429 Strong form of mathematical induction,
isomorphic, 351 Sibling of a vertex, 272 73
isomorphism, 351 Simple circuit, 307 Structure, mathematical, 41, 344
product of, 356 Simple cycle, 289 Structured algorithm, 456
quotient, 358 Simple path, 289, 307 Subgraph, 308
sub-, 350 Sink, 322 Subgroup, 368
Sentence parsing, 392 Sorting coset of, 373
Sequence, 13 topological, 223 normal, 373
empty, 17 Source, 321 trivial, 368
Fibonacci, 113,116 Space Sublattice, 235
finite, 13 probability, 107 Submonoid, 350
infinite, 13 axioms for, 107 Subring, 381
initial conditions for, 113 sample, 104 Subroutine, 455,462
set corresponding to, 14 Spanning tree, 290 SUBROUTINE statement, 459, 462
of values, 15 minimal, 296 Subsemigroup, 350
Set(s), 2 undirected, 290 Subset, 3
alphabet, 17 Square matrix, 32 regular, 18
binary operation on, 345 Starting state, 405 Substitution code, 187
cardinality of, 4 State(s), 120,403 Substitution rule for Boolean algebras,
characteristic function of, 15 acceptance, 405 246
closed, 345 of a finite-state machine, 403 Subtree, 273, 280
combination of, taken r at a time, 97 set of a machine, 403 corresponding to a vertex, 273
complement of, 7 starting, 405 left, 280
complement of B with respect to A, transition function, 403,409 right, 280
7 transition table, 404 of a tree, 273, 280
contained in, 3 vector, of a Markov chain, 120 Sudoku, 84-85, 338, 339
corresponding to a sequence, 14 Statement(s), 51 Sum
countable, 16 BY, 461 of matrices, 33
disjoint, 6 CALL, 455,462 mod-2,435
element of, 2 compound, 51 Supersink, 330
empty, 3 conditional, 57 Supersource, 330
equal, 3 conjunction of, 52 Sylvester, James Joseph, 1
finite, 4 contradiction of, 58 Symmetric closure of a relation, 164
infinite,4 contrapositive of, 57 Symmetric difference,
input, of a machine, 403 converse of, 57 of two sets, 7
intersection of, 6 disjunction of, 52 of two fuzzy sets, 195
linearly ordered, 219 equivalent, 58 Symmetric group on n letters, 367
member of, 2 FOR, 461-462 Symmetric matrix, 36
mutually exclusive, 106 GO TO, 456,464 Symmetric relation, 141
operations, properties of, 8-9 IF-THEN-ELSE, 456,459
acyclic, 289
partially ordered, 218 logically equivalent, 58 graph of, 144
partition of, 125 logically following from, 62 Symmetry of a figure, 366
permutation of, 94 Syndrome of an element, 446
mathematical, 75
power set of, 4 Syntax
negation of, 51
product, 123 diagram, 396
PRINT, 464
quotient, 125, 150 of a language, 387
RETURN, 459,462
regular, 18 System, mathematical, 41
UNTIL, 461
regular expression over, 17,400 WHILE, 457,460
/^-relative, 130 Steady-state vector, 120
state, of a machine, 403 Steganography, 30 T flip-flop, 404
strings from, 14 Steps in proof, 65 Table
subset of, 3 Storage cell, 152 binary operation, 346
symmetric difference of, 7 String(s), 14, 17 decoding, 444
Index 1-9

multiplication, 365 ordered, 272 local, 463


state transition, 404 parse, 392 propositional, 51
truth, 51,250 positional, 276 Vector
Tautology, 58 positional binary, 276 state, 120
Terminal symbol, 388 postorder search of, 283 steady-state, 120
Theta class, 201 preorder search of, 280-281 Venn, John, 3
Time root of, 271 Venn diagram, 3
running, of an algorithm, 203, 215 rooted, 271 Vertex, 132, 306
Token of a Petri net, 268 search, 273 degree of, 306
Topological sorting, 223 searching, 273 descendants of, 273
Towers of Hanoi, 468 spanning, 290 in-degree of, 133
Transformation, 181 subtree of, 273, 280 isolated, 306
Transition function traversing, 280 level n, 271
state, 403,409 undirected, 288 nearest neighbor of, 295
state corresponding to a string, 409 edge in, 288 offspring of, 271
Transition matrix, 120 spanning, 290 out-degree of, 133
regular, 121 vertex in, 271 subtree beginning with, 273
Transition of a Petri net, 268 walking, 280 in a tree T, 271
enabled, 268 Truth table, 51, 250 visiting, 273
firing of, 268 Two-stage influence, 341 Vertices
Transition probability, 120 Typew(n = 0, 1,2,3) adjacent, 144, 288, 306
Transitive closure of a relation, 164, language, 392 connected, 332
169 phrase structure grammar, 392 disconnected, 332
Transitive relation, 144 distance between, 295
Transport network, 321 interior, of a path, 171
U
Transpose of a matrix, 35 nearest neighbor of, 296
Transposition, 209 Unary operation, 42 Veto power, 49
code, 208 Uncountable set, 16
Traveling Salesperson Problem, 320 Undirected edge, 144, 288
W
Traversing a tree, 280 Undirected spanning tree, 290
Tree(s), 271 Undirected tree, 288 Walking a tree, 280
AVL, 288 Union Warshall's algorithm, 171-172
balanced n-tree of height k, 275 of sets, 5 Weight, 48
binary, 273 of fuzzy sets, 195 of an edge, 295, 320
B-tree of degree k, 303 Unit of a word, 431
complete binary, 273 element of a poset, 230 Weighted graph, 295
complete n-tree, 273 of a ring, 381 Weighted voting system, 48
computer representation of positional Universal quantification, 54 Well defined, 2
binary, 277 Universal set, 3 WHILE statement, 457,460
derivation, 389 properties of, 9 Word, 17, 430
height of, 272 UNTIL statement, 461 code, 430
Huffman code, 278 Up-down permutation, 213 weight of,431
inorder search of, 283 Upper bound, 230
isomorphic, 294 Z
labeled, 275
leaves of, 272 Zero
linked list representation of, 285 Value of a flow, 322 divisors of a ring, 381
minimal spanning, 296 Value of a function, 181 element of a poset, 230
n-tree, 273 Variable matrix, 33
Photo Credits

Chapter 1
Page 1
James Joseph Sylvester: Library of Congress
Arthur Cayley: CORBIS BETTMANN

Chapter 2
Page 50
Augustus De Morgan: CORBIS BETTMANN
George Boole: Mary Evans Picture Library Ltd.

Chapter 3
Page 91
Blaise Pascal: Academie des Sciences
Pierre de Fermat: Photo Researchers, Inc.

Chapter 4
Page 122
Bertrand Russell: Getty Images Inc.-Hulton Archive Photos

Chapter 5
Page 180
Gottfried Wilhelm Leibniz: Library of Congress
Leonhard Euler: Bavarian State Library, Munich

Chapter 6
Page 217
Printed Circuit Board: Printed Circuit Board Repair Specialists

Chapter 7
Page 270
Family Tree of Johann Sebastian Bach: Bernard Kolman

Chapter 8
Page 305
Wolfgang Haken and Kenneth Appel: Kenneth Appel

Chapter 9
Page 344
Evariste Galois: CORBIS BETTMANN

Chapter 10
Page 386
Lady Lovelace: Getty Images Inc.-Hulton Archive Photos

Chapter 11
Page 429
Claude Shannon: M.I.T. Museum and Historical Collections

P-l
Sudoku Puzzle

1 4 1 4 1 2 3 13 4
1 4 2 3

1 1 4
2 3 2 3 2 3 1 4

1 3 1
4 2 4 2 3 1 4 2

1 3 4 1 2 4 1 3 1 3
4 2 3 1

(a) (b) (c)

Labeled Trees

11 12 13
A Maximum Flow Network Problem

[2,1] [1,4]
e4S = 1 eS4 = 2 ../'"
4
e 14= 2 eS6 =0
e4 1= 2 e6S = 4
e24=2 e2S =0
1
e42 = 0 eS2 = 2

e l 2= 0 e36 = 0
e2 1= 5 e63 = 3
2 3
e23 =0 e32 = 3
[1,5]

A Moore Machine

a, c a, h, C

a, C a, C

You might also like