0 ratings0% found this document useful (0 votes) 28 views11 pagesGrimaldi Chap1
Unix shell programming language
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Fundamental
Principles of
Counting
numeration, oF counting, may strike one as an obviots process that a student learns
when first studying arithmetic. But then, it seems, very ite attention is paid to further
development in counting ashe student turns to “more difficult” areas in mathematics, such
as algebra, geometry, tigonometry, and calculus. Consequently, this first chapter should
‘provide some warning about the seriousness and difficulty of "mere" counting.
Enumeration doesnot end witharthmetic, Ialso has applications in uch areas ascoding
theory, probability and statistics, and inthe analysis of algorithms. Later chapters will offer
some specific examples ofthese applications.
‘As weenter this fascinating eld of mathematics, we shall come upon many problems that
are very simple o state but somewhat “sticky” to solve. Ths, besureto lear andunderstand
the basic formulas — but do nor rely on them too heavily. For without an analysis ofeach
problem, a mere knowledge of formulas is next to scless. Instead, welcome the challenge
te solve unusual problems or those that are different from problems you have encountered
inthe past. Seek solutions based en your own scrutiny, regardless of whether it reproduces
‘what the author provides. There are often several ways to solve a given problem.
1
The Rules of Sum and Product
Our study of discrete and combinatorial mathematics begins with two basic principles of|
counting: the rules of sum and product. The statements and inital appliations of these
rules appear quite simple. In analyzing more complicated problems, one is often able to
‘break down such problems into pars that can be solved using these basic principles. We
want to develop the ability 1 “decompose” such problems and piece together our paral
solutions in order to ative atthe final answer. A good way to do this isto analyze and solve
‘many diverse enumeration problems, taking note ofthe principles being used. Tis isthe
approach we shall follow here.
‘Our first principle of counting can be stated as follows:
a ftst task can be performed in m ways, while second tas can
in m ways, and the two tasks cannot be pecormed simultaneouly, thea
ther task can be accomplished in any one of m +n ways,4 hope 1 Fndamenal Pils of Counting
(eames
EXAMPLE 12
EXAMPLE 13,
EXAMPLE Us
EXAMPLE 15
EXAMPLE 16
[Note that when we say that apatcular occurrence, such a a first task, can come about in m
ways, these m ways are assumed tobe distinct, unless a statement is made tothe contrary.
‘This willbe tre throughout the entire text.
‘college ubrary has 40 textbooks on sociology and 30 textbooks dealing widrantrupoluyy.
By the rule of sum, a student at this college can select among 40-+ 50 = 90 textbooks in
‘order to learn more about one o the other ofthese two subjects.
‘The rule can be extended beyond two task as long as no par of tasks can occur simultane
‘ously. For instance, acomputer science instructor who has, sty, seven different introductory
‘books each on Ci, Java, and Perl can recommend any one ofthese 21 books toa student
‘ho is interested in learning a first programming language
“The computer Science instructor of Example 12 has two colleagues. One of these col
leagues has three textbooks on the analysis of algorithms, and the other hes five such
textbooks. If n denotes the maximum numberof diferent books on this topic that this
instructor ean borow from them, then $< <8, for here both colleagues may own copies
of the same textbook(s).
‘The following example introduces ou second principle of counting.
nteyingtoreachadecisiononplantexpansion, an administrator assigns 12ofheremployees
to two committees. Committe A consists of five members and is to investigate possible
favorable results from such an expansion. The other seven employees, committee B, will
scrutinize possible unfavorable repercussions. Should the administrator decide to speak to
just one committee member before making her decision, then by the rule of sum there are
‘2employees she can cll upon for input. However, tobe bit more unbiased, she decides,
{ospeak with a member of committee Aon Monday, and then witha member of committee
Bon Tuesday, before reaching a decision. Using the following principe, we find that she
can select wo such employees to speak with in 5 X 7 = 35 ways
‘The Rule of Product: If « procedure canbe broken down into fist and second stages,
sod if there sre m possible outcomes fr the fist stage and if, foreach of these outcomes,
ther aren possible outcomes forthe second stage, then the otal procedure can be carried
cout, in the designated ora, in mm ways.
‘The drama cub of Central Univesity is holding tryouts Fora spring play. With six men and
ight women auditioning forthe leading male and female roles, by the rule of product the
director can cast his leading couple in 6 X 8 = 48 ways.
Here various extensions of the rule are ilustrated by considering the manufacture of lense
plates consisting of two letters followed by four digits.EXAMPLE U7.
EXAMPLE 18
1 The Rules of Sum and Produ 5
a) If no letter or digit can be repeated, there are 26 X25 x 10X9X 8X7
3,276,000 different possible plates.
) With repetitions of letters and digits sllowed, 26 X 26 x 10x 10% 10x 10
6,760,000 different license plates are possible.
©) frepatitons are allowed, asin part (b), how many ofthe plates have only vowels (A,
E,1, 0, U)and even digits? (0 is an even integer)
Inorderto store data, computers main memory contains a larg collection of circuits, each
of which is capable of storing a bit —that is, one of the binary digits Oor 1. These storage:
ereuits are arranged in units called (memory) cells. To identify the cell in a computer's
‘main memory, each is assigned a unique name called is address. For some computers,
such as embeded microcontrollers (as Found in the ignition system for an automobile), an
address is represented by an ordered list of eight bits, collectively refered toas byte. Using
the rule of product, there are 2 X 2X 2% 2X 2X 2%2X2.= 2! = 256 such bytes. So
we have 256 addresses that may be used for cells where certain information maybe stored.
‘A-itchen appliance, such as a microwave oven incorporates an embedded microcon-
woller These “small computers” (suchas the PICmicro microconvoller contain thousands
‘of memory cells and use two-byte addresses to identify these cells in their main memory.
‘Such addresses are made up of two consecutive bytes, or 16 consecutive bits Thus there
se 256 X 256 = 28 x 2! = 26 m 65,536 avalable addresses that could be wed lo iden-
tify cells in the main memory. Other computers use addressing systems of four byes. Tis
32-bit architecture is presently used inthe Pentium’ processor, where there area many
as 2 x 28 X 28 x 2! = 2 = $,294,967,296 addresses for use in identifying the cells in
‘main memory. When a programmer deals with he UltraSPARC? or Itanium! processors, he
or she considers memory ces with eight-byte addresses. Each ofthese addresses comprises
8x 8 = 64 bits, and there are 2% = 18, 446,744,073, 709,551,616 possible addresses for
this architecture. (Of couse, not al ofthese possibilities are actually used)
‘A times it is necessary to combine several different counting principles inthe solution of |
‘one problem, Here we find that the rules of both sum and product are needed wo attain the
‘At the AWL corporation Mars. Foster operates the Quick Snack Coffee Shop. The menu
athe shop is limite: six kinds of muffins, eight kinds of sandwiches, and fie beverages
(ot coffe, hot tea, iced tea, cola, and orange juice). Ms, Dodd, an editor at AWL, sends
her assistant Caro the shop to gether lunch —either a muffin and a hot beverage or a
sendvich and a cold beverage
By the rule of product, there are6 X 2 = 12 ways in which Carlean purchase muffinand
hot beverage. A second application ofthis rle shows tht there are 8 X 3.
fr a sandwich and cold beverage. So by the rule of sum, there are 12 + 24
which Carl can purchase Ms. Doda's lunch.
"atom (Ria reper ademark of ene Corporion
‘the UtaSPARC proceso i manafictred by Sun) Miron, Is,
Stason (M0 i enenark of he inl Caeration.6 Copter Fundarenta Pipes of Counting
iF
Permutations
Continuing to examine applications of the rule of product, we turn now to counting linear
arrangements of objects. These arrangements are often called permutations wien the objets,
snc distint, Weshall develop some systematic methods fr dealing with ineararangements,
starting with atypical example.
In aclass of 10 students, five are tobe chosen and seated ina row for a picture. How many
such linear arrangements are posible?
‘The key word here is arrangement, which designates the importance of order. IFA, B,
C,.--shJ denote the 10 stadens, then BCEFI, CEFIB, and ABCFG are three such different
szrangements, even though te ist two involve the same five students.
‘To answer this question, we consider the postions and possible numbers of students we
‘an choose from in order to fil each positon. The filling of a position is stage of our
procedure,
wx 9 x 8 x 7 x 6
im a me a Ps
peste pn pation pen pn
Each ofthe 10 students can occupy the 1st position inthe row. Because repetitions are
sot possible here, we can select only one ofthe nine remaining students to fl the 2nd
postion. Continuing in this way, we find only six students to select from in oder to fll the
‘Sth and fnal position. This yields atta of 30,240 possible arrangements of five students
selected from the lass of 10,
Exactly the same answer is obtained if the postions are filled from sight to left —
ramely, 6 x7 X B X 9 X 10. If the 3d postion is filled first, te Ist postion second, the
‘tn positon third, the th position fourth, andthe 2nd position fifth, then the answer is.
9x 6 x 10 x 8X 7, sil the same value, 30,240,
‘As in Example 1.9, the product of certain consecutive postive integers often comes
into play inenumeration problems. Consequently, the following notation proves tobe quite
sweful when we are dealing with such counting problems, It will frequently allow us to
express our answers in a more convenient form.
Definition 1 Foran integer n > 0, factorial (denoted n!}) is defined by
ot,
b= (a= De) GAM), for_mEL
One finds that 11 = 1,2! = 2, 3! = 6,41 = 24, and 5!
G#D!= (e+ Den).
120, In addition, foreach n> 0,
Before we proceed any futher, lt us try to get a somewhat better appreciation for how
fast n! grows. We can calculate that 10! = 3,628,800, and it just so happen that this is
‘xacily the number of seconds in six weeks. Consequently, 11! exceeds te number of
seconds in one year, 12! exceeds the number in 12 years, and 13! surpasses the number of|
seconds in a century,EXAMPLE 110
EXAMPLE 111
12. Permutations 7
If we make use ofthe factorial not
the folowing more compact form:
tion, the answer in Example 1.9 can be expressed in
SR4X3X2X1_ 10!
1X9 8X76 = 10x9XEX TX 6x PAE RE RES =
Given a collection ofm distinct objects, any (linea) arrangement of these object is called
permutation of the collection.
Starting with the leters a b,c thee are six ways to arrange or permte al ofthe letters
abe, acb, bac, ba, cab, cba If we are interested in arranging only two ofthe letters at 8
time, there are six such sie-2 permutations: ab, ba, ac, ea,be, cb
I there ae n distinct objects andr is an integer, with I <7 2, then P(n, 2) = nl/(n—2)! = n(n ~ 1). When n > 3
fone finds that (n,n ~3) = nl [in — (x = 3]! = nl/3! = (aya — IY(a = 2) + (5).
‘The number of permutations of size r, where O 0.
‘The number of permutations ofthe ltrs inthe word COMPUTER is 8. If only five ofthe
letters are used, the numberof permutations (of size 5)is P(B, 5) = 81/(8 ~ 5)! = 81/3! =
6720. If repetitions of letiers are allowed, the number of possible 12-eter sequences is
8 26872 x 10"!
Unlike Example 1.1, the numberof (linear) arrangement ofthe four letters in BALL is
12, not 4! (= 24). Te reason is that we do not have four distinct letters to arrange. To get
the 12 arrangements, we can lst them asin Tele 1.1(3)..
"re rybol "2" adi apprimaaly ilo"8 ‘apter1 Fundamental Pips of Courng
Table 1
ABLLJABLL ABLLY
ALBLIAU BG ALB
ALLB|A ULB Al B
BALCL|BAYH BALL
BLAL|B LA BLA
BLLA/BuULA BLUA
LABL|UA BL LAB L
cCavcsa|o ALB LAB
Cepatl|uBAL GBA L
LBLA|/G BLA bBLA
cCLrasply RA B Lo AB
crealuuBaA Lu Ba
« »
Ifthe two L's are distinguished as Li, La then we can use our previous ideas on per-
‘mutations of distinct objects; wit the four distinct symbols B, A, Ly, La, we have 4! = 24
permutations. These ae listed in Tale I.1(b). Table 11 reveals that for each arrangement
in which the L's ar inistinguishable there coresponds pair of permutations with distinct
Lis. Consequently,
2 (Number of arrangements of the letters B, A, L,L)
= (Number of permutations ofthe symbolsB, A Ly, La).
and the answer tothe original problem of finding al the arrangements ofthe four letters in
BALLis 472 = 12
Using the idea developed in Example 1.11, we now consider the arangemens of all nine
letters in DATABASES.
‘There aze 31 6 arrangements with the A's distinguished for each amangement in
which the A's are not distinguished. For example, DAyTABA;SES, DA/TASBALSES,
DAgTA) BASES, DAyTAsBA)SES, DAyTA;BAQSES, and DAxTA;BASES il corespond
to DATABASES, when we remove the subsrips on the A's. In addition, tothe arange-
‘ment DA;TAgBAySES there comesponds the pair of permutations DA;TABA;S}ES; and
DA,TABAsS2ES}, when te S's ae distinguished, Consequently,
(2) Gb (umber of arrangements ofthe leters in DATABASES)
(Sumber of permutations ofthe symbols D, As, T, A, By As, Sis E,S3)-
0 the numberof arrangements ofthe nine letters in DATABASES is $1/(231) = 30,240.
Before stating a general principle forarrangements with repeated symbols, note hatin ur
prior two examples we solved a new typeof problem by relating tto previous enumeration
Drinciples. This practice is common in mathematics in general, and often occurs inthe
ele oes ofe A
c ele ale c |e c
F ® F 7
o » © Ol
Figure 12
‘We shall ty o relate this problem to previous ones we have already encountereé. Con-
side Figs. 1.2(a) and (b). Stating atthe top of the circle and moving clockwise, we list
the distinc linear arrangements ABERCD and CDABEF, which corespond to the same
circular arangement. In addition to these two, four other linear arrangements —BEFCDA,
DABEFC. EFCDAB, and FCDABE—are found to correspond to the same eirelar ar
rangemen:as in (a) or (b). So inasmuch as each circular arrangement corresponds to six
linear arrengemens, we Rave 6 x (Number of circular arrangements of A, B, ....F)
(Number of linear arrangements ofA, B,.....F) = 61
Consecuently, there are 61/6 = 5! = 120arrangements ofA, B,...,Faround he circular
table,
‘Suppose now thatthe sx people of Example 1.16 are three married couples and that A, B,
‘and Care the females, We want to srrange the six people around the table so thatthe sexes
alternate (Once agua, arrangements are considered identical if one can be obtained from
the other by rotation.)
Before we solve this problem, let us solve Example 1.16 by an alternative method,
‘which will assist usin solving our present problem. If we place Aa the table as shown in
Fig. 1.3, five locations (clockwise from A) remain tobe filled. Using B,C, ..., Fto ill12 Permtatons n
a a
5 1 | ag, mi
‘ 2] 8 a
3 Me
@ »
Fire 13
these five postions is the problem of permuting B, C,..., Fin linear manner, and this,
can be done in 5! = 120 ways,
‘To solve the new problem of alternating the sexes, conser the method shown in
Fig. 13(t). A (a female) is placed as before. The next positon, clockwise from A, i marked
‘MI (Male 1) and can be filled in three ways. Continuing clockwise from A, position F2
(Female 2) can be filled in two ways. Proceeding in this manner, by the role of product,
there are 3 X 2% 2 % 1 X 1 = 12 ways in which these sixpeople can be arranged with no
{wo men or women seated next to each other
EXERCISES 1.1 AND 1.2
1. During alocal ampa'ga, ight Republican nd ve Demo-
cratic candidates are nominated for president of the school
boa
4) If the president iso be one of these candidates, how
‘any posible are here forthe eventual winner?
1b) How many posites exist fora pair of candidates
(ove from each party)to oppose each othe or the event
lection?
©) Which counting principle is used in part (0)? in
an 0)?
2, Answer part (6) of Example 16
3. Buick automobiles come in four models, 12 colors, three
engin ies, andtwotrananission types (2) How many dst.
Buicks canbe manufacued? () Ifans ofthe availble colors
Is blue, how many diflere blue Buick ean be manufactures?
4. The board of drecton ofa pharmaceuteal corporation hs
10 members. An upcoming stockholder’ meting ir ached
to approve anew slate of company officers (chosen rom the 10
board member)
1) How many differen sates consisting of «president, vce
resident secretary, and easurer can the bard present ©
‘he sioctholser for heir approval?
by Thre members othe board of directors are physicians.
ow many slaes from par (a) have (i) physkeian nomi
red forthe presideney’ (i) exsely one physician appear.
ing om the sate?
the ate?
‘5. While ona Ssturday shopping spree Jenifer and ifany
witnessed tw men diving way from the fot ofa jewelry
shop, jst before a burglar alarm stadt sound. Although e¥-
erything happened rather quickly, when the two young ladies
were questioned they were dbl to ge te police the following
Information sbout the license pate (wbich consisted of wo lee
tes followed by four digi) on the getanay ca. Tifany was
sure that he second leteronthe plate washer an ora Qand
‘he last digit was ethers eran 8 Jenifer told the inventor
hat the fst eter onthe plate waster aC or Gand tha the
frst gc was definitely a7. How many diferent cease plates
wil the police ave to che ou?
6. To rsise money for anew municipal pool, the chamber of
then
net
rrsiine (cE) rar
25, Find the values) of min ech ofthe falling:
(@) Pn, 2) = 90,00) Pla, 3) = 3 (0,2), 208
(© 2P(H,2)+ 50 PRN, 2).
26, How many diferent paths in the xy-plne ae there from
(©.0) 10 0,7) if a path proceeds one step a atime by Bo-
Angele one space to be rgh (R) or one space upward (U)?
ow many such pas ae tere frm 2,710, 14)?Can any
_seneralstdement be made tht incorporates te to result?
27, a) How many distinct paths are there fam (1, 2,0)
(2, 3,7) im Boliean thee-space i each move is one of
the following types?
ls, 9.9 GFL yt
eG, 72> Cyt hth
kG nas Ge netl)
1) How many such paths are there fom (1.0.5)
GLD?
©) Generalize the ress in prs (3) ad (0)
26, a) Determine the value ofthe integer varie coumier f=
ter exeetion of the follwing program segment. (Here i,
fad kare integer variables)
for 4 :=1t012 do
counter := counter + 2
tor js=5t01040
‘counter := counter'+ 2
for k i= 15 downto 8 de
1b) Which counting principles at play npr (0)?
29, Consider the following program segment wher , and k
se imeger variables,
for {1 t012 40
for j 12 5t010 do
for k = 15 downto & do
eine (1° J)
18) How many timesis the pein statemen executed?
'b) Which counting principle is sedi par (a)?
30, Asequence of lees ofthe frm abcbs, where the expres
‘Sion i unchanged upon reversing order, ism example of a
palindrome (of ive lees). a) eter may appear more than
twice, how many palindromes of ive lees a there? of sx
Teuers? (0) Repeat part (2) under the conn that no Iter
‘sppests more than tice.