CS101 - Discrete Math

Robert Batzinger
Dec 2 17

Unit 1 - Sets

Unit 1
Sets

\[ \]

Contents

Unit 1: Assignments

\[ \]

Software Installation

yEd Work Space

Namecards

yEd installation

  • Download and install yEd from https://www.yworks.com/products/yed
  • Watch the video and do the tutorial
  • Use yEd to draw a modified version of this diagram where all to 5 objects are located on a single plane and no edges intersect.
  • Label the objects 1 to 5
  • Save the diagram file to your course Git project and update your GitLab site
  • Export the diagram as a PNG image file and upload it to Google classroom.

5pts This version cannot be drawn on a single plane without the edges intersecting

LaTeX Features

  • XeLaTeX (Unicode) or LaTeX (European Languages)
  • Markup Language built on TeX
  • Tags: \tag
  • Environments: \begin{..} ... \end{..}
  • Grouping: {...}
  • Math mode: $$d = \sqrt{a_0^2 + a_1^2}$$
  • Spacing: \vfil \hfil \bigskip \smallskip

Useful LaTeX markup tags

  • Font size: \tiny \small \normalsize \large \huge
  • Font families: \bf \tt \sl \it
  • Document segments: \section \subsection \subsubsection
  • Graphics: \includegraphics{width=\columnwidth}{pic.png}
  • Tables: \begin{tabular}{lr} aa & 3.5\\ b & 17.2\\ \end{tabular}
  • Footnotes: \footnote{This is a note}
  • Citations: \cite{Knuth:1970}
  • Cross links: \label{id} .. As seen in \ref{id}

Overleaf Dashboard

Namecards

Overleaf Document Development Platform

Namecards

Namecard example

\addresslabel[\fboxsep=5mm]{\vbox to 75mm{%
    \hbox to 40mm{\kern-5pt
      $\vcenter{\hbox to 1.7cm{%
        \includegraphics[width=1.7cm]{payap.png}\hss}}\
        \vcenter{\raggedright
          Payap University\\ Faculty of Sci\\
          Amphur Muang\\  Chiang Mai 50000\\ 
          Thailand\\}$\hss}%
    \vfill{\centering {\Large\scshape 
       \textbf{Dr.~Robert~P.~Batzinger}\\}\medskip
       \textit{Instructor Emeritus}\\}
    \vfill{\raggedleft \small
        \textit{Office: \phonei}\\%
        \textit{LinkedIn: robert-batzinger}\\%
        \textit{Email: \emaili}\\}}}

Namecard Output

Namecards

LaTeX installation

  • Log into Overleaf
  • Create a project
  • Copy the namecard.tex file from the git subdirectory
  • Modify the particular to suit your namecard
  • Create a pdf file
  • Upload to the Google Classroom
  • Skim through the LaTeX manual at the Google Classroom
  • Try a couple of the exercises from that tutorial.
  • Create a second project
  • Copy the report template, cls and graphic files to the project
  • Compare the output to the sample PDF

Definition

A set is a collection of objects, which are called elements. The order of the elements does not matter, and each element may occur no more than once. An element may be atomic or molecular.

\[ \]

Notation

Notation

Notation \( \LaTeX \) Explanation
\( X = \{a,b,c\} \) X = \{a,b,c\} \( X \) is a set that contains \( a,b,c \)
\( Y = \{b,c,d\} \) Y = \{b,c,d\} \( Y \) is a set that contains \( b,c,d \)
\( Z = \{X, Y\} \) Z = \{X, Y\} \( Z \) is a set of Sets \( X \) and \( Y \)
\( A \subset X \) A \subset X Set \( A \) is a subset of \( X \)
\( B \subseteq X \) B \subseteq X Set \( B \) is a subset or equals to Set \( X \)
\( a \in X \) a \in X \( a \) is an element of Set \( X \)
\( d \not\in X \) d \not\in X \( d \) is not an element of Set \( X \)

Special Sets

\( \LaTeX \) Definition Explanation
\emptyset \( \emptyset \) \( \emptyset \) is a set with no elements
\mathbb{P} \( \mathbb{P} = \{2,3,5,7,11,...\} \) \( \mathbb{P} \) is a set of Prime Numbers
\mathbb{W} \( \mathbb{W} = \{1,2,3,4,...\} \) \( \mathbb{W} \) is a set of Whole Numbers
\mathbb{N} \( \mathbb{N} = \{0,1,2,3,4,...\} \) \( \mathbb{N} \) is a set of Natural Numbers
\mathbb{Z} \( \mathbb{Z} = \{...,-3,-2,-1,0,1,2,3,...\} \) \( \mathbb{Z} \) is a set of all Integers
\mathbb{Q} \( \mathbb{Q} = \{x \in \mathbb{R} : x = n/m : \forall n,m \in \mathbb{Z}\} \) \( \mathbb{Q} \) is a set of all Rational Numbers
\mathbb{R} \( -\infty < \mathbb{R} < \infty \) \( \mathbb{R} \) is a set of all Real Numbers
\cal U \( \cal U \) Set of all elements in the domain

Rules concerning the elements of a set

  • The order of the elements is meaningless.
    Given \( A = \{1,2,3\} \) and \( B = \{2,3,1\}: \) \( A = B \)
  • There are no duplicate elements in a set.
  • Given \( A = {1,2,3}: \) \( {\cal P}(A) = \) \( \{\emptyset,\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}\} \)

Elements of Sets

\( \LaTeX \) Notation Description
\{ ,\} \( \{ ,\} \) The elements of a set. \( \{1, 2, 3\} \) is the set containing 1, 2, and 3.
: \( : \) \( \{x : x > 2\} \) is the set of all \( x \) where \( x > 2 \)
\in \( \in \) \( 2 \in \{1, 2, 3\} \) asserts that \( 2 \) is an element of the set
\not\in \( \not\in \) \( 4 \not\in \{1,2,3\} \) asserts that \( 4 \) is not an element of the set
{\cal P}(A) \( {\cal P}(A) \) \( {\cal P}(A) \) is a power set of \( A \) containing all the subsets of \( A \)

Ex. Some statements

Please note which of these is true

  • Given \( A=\{1,2,3\}, X = {\cal P}(A): \)
    \( \qquad\exists y \in X: y \subseteq A, y = A \)
    Hint (What is the value of \( y \) ?)

  • Given \( A = \emptyset, X = {\cal P}(A):X = A \)
    Hint: (What is the value of \( X \) ?)

  • Given $A = \emptyset, X = \

\[ \]

Relationships

Between Sets

Ex.1: Relationships between Sets

Which are true, false, or meaningless?

Given \( A=\{1,2,3,4,5,6\}, \) \( B=\{2,4,6\}, \) \( C=\{1,2,3\}, \) and \( D=\{7,8,9\} \)

\[ \begin{array}{ll|ll} * & $A \subset B$ & * & $B \subset A$ \\ * & $B \in C$ & * & $A > D$ \\ * & $\emptyset \in A$ & * & $\emptyset \subset A$ \\ * & $3 \in C$ & * & $3 \subset C$ \\ * & $\{3\} \subset C$ & * & $\{3,3,2,1,1\} = C$ \\ \end{array} \]

\[ \]

Operations On Sets

Cardinality

Definition

Cardinality of a set equals the number of unique elements of a set.

\[ A = \{1,2,3\} \implies |A| = 3 \]

Find the cardinality of the following sets

  • \( \{23,24,...,37,38\} \)
  • \( \{1,\{2,3,4\},\emptyset\} \)
  • \( {\cal P}(\{1,2,3\}) \)

Set operators

\( \LaTeX \) Math Description
\subseteq \( \subseteq \) \( A \subseteq B \) asserts that \( A \) is either a subset of \( B \) or \( A = B \).
\subset \( \subset \) \( A \subset B \) asserts that \( A \) is subset of \( B \): every element of \( A \) is also in \( B \) but \( A \neq B \).
\cap \( \cap \) \( A\cap B \) is the intersection of \( A \) and \( B \): elements existing in both \( A \) and \( B \).
\cup \( \cup \) \( A \cup B \) is the union of \( A \) and \( B \): all elements in either \( A \) or \( B \) or both
\times \( \times \) \( A \times B \) is a Cartesian product: the set of all pairs \( (a, b) \) with \( a \in A \) and \( b \in B \).
\backslash \( \backslash \) \( A\backslash B \) is Set \( A \) minus Set \( B \): all elements of \( A \) which are not elements of \( B \).
\bar{A} \( \bar{A} \) The complement of \( A \) is the set of everything except elements of \( A \)
\( |A| \) \( |A| \) The cardinality of A is the number of elements in \( A \).

Cardinality of Power Sets

\[ \small\begin{array}{|c|c|c|c|c|} \hline A & |A| & {\cal P}(A) & count({\cal P}(A)) & |{\cal P}(A)| \\ \hline \emptyset & 0 & \{\emptyset\} & (1) & 1 \\ \hline \{1\} & 1 & \{\{\emptyset\},\{1\}\} & (1+1) & 2 \\ \hline \{1,2\} & 2 & \{\{\emptyset\}, \{1\}, \{2\}, \{1,2\}\} & (1+2+1) & 4 \\ \hline \{1,2,3\} & 3 & \{\{\emptyset\}, \{1\}, \{2\}, \{3\}, \{1,2\}, \{1,3\}, \{2,3\}, \{1,2,3\}\} & (1+3+3+1) & 8 \\ \hline \{1,2,3,4\} & 4 & \{\{\emptyset\}, \{1\}, \{2\}, \{3\}, \{4\}, \{1,2\}, \{1,3\}, \{1,4\}, & (1+4+6+4+1) & 16 \\ & & \{2,3\}, \{2,4\}, \{3,4\}, \{1,2,3\}, \{1,2,4\}, &&\\ & & \{1,3,4\}, \{2,3,4\}, \{1,2,3,4\}\} & & \\ \hline \{1,2,3,4,5\} & 5 & \{\{\emptyset\}, \{1\}, \{2\}, \{3\}, \{4\}, \{5\}, \{1,2\}, \{1,3\}, \{1,4\}, \{1,5\}, &(1+5+10+10+5+1) & 32 \\ & & \{2,3\}, \{2,4\}, \{2,5\}, \{3,4\}, \{3,5\}, \{4,5\}, \{1,2,3\}, & & \\ & &\{1,2,4\}, \{1,2,5\}, \{1,3,4\}, \{1,3,5\}, \{1,4,5\}, \{2,3,4\}, & & \\ & & \{2,3,5\}, \{2,4,5\}, \{3,4,5\}, \{1,2,3,4\}, \{1,3,4,5\}, & & \\ & &\{1,2,4,5\}, \{1,2,3,5\}, \{2,3,4,5\}, \{1,2,3,4,5\}\}& & \\ \hline \end{array} \]

Ruby Set Class

require 'set'

setA = Set.new(1..3); 
setB = Set.new([2,3])
setC = Set.new([2,3,4]); 
setU = Set.new(1..4)
  • Class supports Sets as a data type
  • Handles atomic elements of all typese

Ruby Set Class Demonstration

puts <<endmsg
A:#{setA.inspect} B:#{setB.inspect} 
C:#{setC.inspect} 
B subset A:    #{setB.subset?(setA)}
A superset B:  #{setA.superset?(setB)}
A union B:     #{setA.union(setC).inspect}
A intersect C: #{setA.intersection(setC).inspect}
A intersect C: #{(setA & setC).inspect}
A intersect C?:#{setA.intersect?(setC)}
A subtract C:  #{setA.difference(setC)}
Complement(B): #{setU.subtract(setB).inspect}
Cardinality(A):#{setA.size}
4 member of C?:#{setC.include?(4)
endmsg

Output

A:#<Set: {1, 2, 3}>  B:#<Set: {2, 3}> 
C:#<Set: {2, 3, 4}> 
B subset A:     true
A superset B:   true
A union B:      #<Set: {1, 2, 3, 4}>
A intersect C:  #<Set: {2, 3}>
A intersect C:  #<Set: {2, 3}>
A intersect C?: true
A subtract C:   #<Set: {1}>
Complement(B):  #<Set: {1, 4}>
Cardinality(A): 3
4 member of C?: true

\[ \]

Venn Diagrams

Venn Diagrams

  • A Venn diagram displays sets as intersecting circles.
  • Each circle represents a set.
  • The rectangle containing the circles represents the universe.
  • Areas can be shaded to highlight combinations
  • LaTeX supports the drawing of Venn Diagram

Venn

LaTeX Venn Diagram

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{venndiagram}
\usepackage{xcolor}
\begin{document}\Large
\begin{venndiagram3sets}[labelOnlyA={1},
labelOnlyB={2},labelOnlyC={3},
labelOnlyAB={4},labelOnlyAC={5},
labelOnlyBC={6},labelABC={7},
labelNotABC={8},shade=orange]
\fillACapB \fillBCapC \fillACapC
\end{venndiagram3sets}
\end{document}

Create Venn Diagram

  • Use the Venn.tex to create a PDF that displays the following

    • \( A \cap B \cup C \)
    • \( A \cup B \cup C \)
    • \( \neg(A \cap B \cap C) \)
  • Upload the diagram to the Google Classroom

Ex. 2: A Color Challenge

colorvenn

Determine set expressions required to fill each of the colored areas

\[ \begin{array}{ll|ll} * & Red - $A / (B \cup C)$ & * & Yellow - $(A \cup B)/ C$ \\ * & Green & * & Cyan\\ * & Blue & * & Purple\\ * & White & * & Grey\\ \end{array} \]

Ex.3 Relationships between Standard Sets

Create a Venn Diagram in yEd to represent the relationships between these standard sets:

\[ \mathbb{N}, \mathbb{P}, \mathbb{Q}, \mathbb{R}, \mathbb{W}, \mathbb{Z} \]

Unit 1 Experiment:

Identifying Important Factors

Background

  • In America politics, there is much talk about women making less money than men.
  • But there are some wealthy women, so how bad is the problem.
  • It would be good to know what characteristics contribute to income.
  • Data from an on-line survey about IT usage in the work place will be used to determine which factors or combination of factors contribute most to the income level of American women

Factors known to contribute to the American gender income gap:

  • Education and experience
  • Child-bearing and nursing
  • Male dominance and competitiveness
  • Gender barriers and activities
  • Cultural norms and traditional roles
  • Female CEO tend to invest in their committee and their workers

Dataset Source

Data Analysis

maleincome

femaleincome

The Raw Data

Sex Age Low Inc (%) Mid Inc (%) High Inc (%) Sum
F 18-24 36 (44.4%) 34 (27.1%) 11 (7.2%) 81
M 18-24 24 (37.5%) 25 (24.6%) 15 (11.9%) 64
F 25-44 25 (12.6%) 113 (53.6%) 60 (22.7%) 198
M 25-44 49 (20.0%) 117 (44.2%) 79 (25.6%) 245
F 45-64 58 (19.8%) 124 (39.6%) 111 (31.5%) 293
M 45-64 32 (13.3%) 83 (32.8%) 125 (43.7%) 240
F 65-older 0 (0.0%) 3 (37.5%) 5 (11.0%) 8
M 65-older 0 (0.0%) 7 (50.0%) 7 (10.9%) 14
F All ages 119 (20.5%) 274 (45.6%) 187 (28.9%) 580
M All ages 105 (18.7%) 232 (39.9%) 226 (36.4%) 563

Fields of the Dataset

DATASET FACTORS: region: location within the USA
gender: declared gender education: level of education
age: age group education_group: type of education
race: declared race ithealth: Uses IT for medicine/health
income: annual salary level itwealth: Uses IT for finance/banking
employment: type of work itcivic: Uses IT as a citizen
job_role: role at work itwork: Uses IT at work

Research questions

  • Which factors are most associated with the highest female income level?

  • Which factors related with the lowest female income?

  • Which factors have the most impact on income?

  • Which pair of factors has the most impact?

Research Procedure

  1. Use Git to pull the latest copy of the software
  2. Adjust the software to look at the factors as binary values.
  3. Use the ruby software to obtain counts.
  4. Create a 3-factor Venn diagram of the top two factors most associated with high income in women.
  5. Create a 3-factor Venn diagram of the factors whose lack is associated with the lowest income.
  6. Determine the scaling factor for the factors and if there is a combination of factors that synergize the likelihood of high income.
  7. Submit a research report of your findings in IEEE template format using LaTeX.

Profiles of Female Respondents by Income

AGE

Income level 18-24 25-44 45-64 65-older
low Income 36 87 58 0
middle Income 34 113 124 3
high Income 11 60 111 5

RACE

Income level Asian Colored White
low Income 7 57 126
mid Income 6 60 257
high Income 10 26 184

Factor analysis

Group Income 18to24 25to44 45to64 65andMore All
Female High 11 (14%) 60 (23%) 111 (38%) 5 (63%) 187 (29%)
Other 70 (86%) 200 (77%) 182 (62%) 3 (38%) 455 (71%)
All 81 260 293 8 642
Male High 15 (23%) 79 (32%) 125 (52%) 7 (50%) 226 (40%)
Other 49 (77%) 166 (68%) 115 (48%) 7 (50%) 337 (60%)
All 64 245 240 14 563
All High 26 (18%) 139 (28%) 236 (44%) 12 (55%) 413 (34%)
Other 119 (82%) 366 (72%) 297 (56%) 10 (45%) 792 (66%)
All 145 505 533 22 1205

Factor analysis

The ratio of the percentage of high income individuals between subgroups represents the magnitude of the effect. Combinations of factors identify whether the combined effects are additive or synergistic.

Factor Transition Ratio Effect
\( Gender \) \( F\Rightarrow M \) 40/29 1.38
\( Age_M \) \( M18to24\Rightarrow M45to64 \) 52/23 2.26
\( Age_F \) \( F18to24\Rightarrow F45to64 \) 38/14 2.71
\( Age\cap Gender \) \( F18to24\Rightarrow M45to64 \) 52/14 3.71

Your task is to compare how factors or pairs of factors effect the percentage of female respondent receiving high incomes.

Profiles of Female Respondents by Income

EDUCATION: (Highest level attained)

Income level Primary High School Undergrad Studies Undergrad Degree Grad Studies Grad Degree
low Income 1 61 83 28 5 12
mid Income 2 58 100 114 17 32
high Income 1 11 49 71 23 65

Profiles of Female Respondents by Income

EDUCATION_GROUP

Income level No College Some College Undergrad Graduate
low Income 62 83 28 17
mid Income 60 100 114 49
high Income 12 49 28 88

Profiles of Female Respondents by Income

INCOME:

Income level Number
low Income 190
mid Income 323
high Income 220

EMPLOYMENT

Income level Student Not Working Part-time Full-time
low Income 20 70 35 65
mid Income 19 90 49 165
high Income 8 61 23 128

Profiles of Female Respondents by Income

JOB_ROLE

Income level Admin Artist Free- lance Logis- tics Mngmt Profess Sales Skilled Other Unem- ployed
low Income 11 2 3 2 8 9 39 7 40 69
mid Income 42 5 6 2 23 45 50 12 57 81
high Income 31 5 6 2 40 52 12 7 23 42

Profiles of Female Respondents by Income

REGION: (location)

Income level Northeast Central South Mountain Pacific Other
low Income 28 44 77 13 23 5
mid Income 53 130 75 24 39 2
high Income 41 43 73 11 52 0

Profiles of Female Respondents by Income

ITWEALTH

Income level Low Use mid Use High Use
low Income 49 73 68
mid Income 62 122 139
high Income 42 93 85

ITHEALTH

Income level Low Use mid Use High Use
low Income 62 98 30
mid Income 83 183 57
high Income 45 127 48

Profiles of Female Respondents by Income

ITCIVIC

Income level Low Use mid Use High Use
low Income 67 38 85
mid Income 84 68 171
high Income 47 32 141

ITWORK

Income level Low Use mid Use High Use
low Income 58 90 42
mid Income 84 177 62
high Income 59 114 42

\[ \]

Functions

Definition

A function is a rule that assigns each input exactly one output.

Domain is the set of all possible inputs.

Range is the set of all possible outputs.

Ex.4 Identify the functions

Given the following mappings, which would qualitfy as functions?

\[ \]

Surjections, Injections, Bijections and Inverse

Surjections

Surjection where the elements of the domain cover the full range of value in the range.

\[ f : \{1, 2, 3, 4, 5, 6\} \Rightarrow \{a,b,c\} \]

\[ \begin{array}{|c|c|c|c|c|c|c|} \hline Original\ domain & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline Outcomes\ value & a & a & b & b & b & c \\ \hline \end{array} \]

Injections

Injection where the elements of the domain map to unique values in the range (No duplicates).

\[ f : \{1, 2, 3, 4, 5\} \Rightarrow \{a,b,c, d, e, f\} \]

\[ \begin{array}{|c|c|c|c|c|c|c|} \hline Original\ domain & 1 & 2 & 3 & 4 & 5 \\ \hline Outcomes\ value & e & c & b & d & a \\ \hline \end{array} \]

Bijections

Bijection where the all elements of the domain map to unique values which cover the entire range.

\[ f : \{1, 2, 3, 4, 5, 6\} \Rightarrow \{a,b,c, d, e, f\} \]

\[ \begin{array}{|c|c|c|c|c|c|c|} \hline Original\ domain & 1 & 2 & 3 & 4 & 5 & 6\\ \hline Outcomes\ value & f & c & b & d & a & e\\ \hline \end{array} \]

Inverse Function

inverse

\[ f : \{1, 2, 3, 4, 5, 6\} \Rightarrow \{a,b,c, d, e, f\} \]

\[ f : \{a,b,c, d, e, f\} \Rightarrow \{1, 2, 3, 4, 5, 6\} \]

\[ \]

Counting:

Introduction to counting collections of things

Ex.5 - Counting examples

  • In a group of 10 people, if everyone shakes hands with everyone else exactly once, how many handshakes took place?

  • If there are 10 people and 3 chairs, how many groups of 3 are possible?

  • How many ways can you distribute 10 cookies to 7 students?

Additive Principle

The additive principle states that if event \( A \) can occur in \( m \) ways, and event \( B \) can occur in \( n \) disjoint ways, then the event \( A \cup B \) can occur in \( m + n \) ways.

  • For 2 sets: \( |A \cup B| = |A| + |B| - |A \cap B| \)

  • For 3 sets: \( \small|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| +|A \cap B \cap C| \)

Cartesian Product

For given sets \( A \) and \( B \), the set of all ordered pairs \( \{x,y\} \) where \( x \in A \) and \( y \in B \)

\[ \hbox{For}\ A = \{1,2,3\}\ \hbox{and}\ B = \{A,B,C,D\} \]

\[ A \times B= \left\{ \begin{array}{ccc} \{1,A\} & \{2,A\} & \{3,A\}\\ \{1,B\} & \{2,B\} & \{3,B\}\\ \{1,C\} & \{2,C\} & \{3,C\}\\ \{1,D\} & \{2,D\} & \{3,D\}\\ \end{array} \right\} \]

Multiplicative Principle

If event \( A \) can occur in \( m \) ways, and each possibility for \( A \) allows for exactly \( n \) ways for event \( B \), then the event \( A \cup B \) can occur in \( m \times n \) ways

For sets: \( |A \times B| = |A| \cdot |B| \)

Applications to programming

# MULTIPLICATIVE
x = 0
for i in 1..10
  for j in 1..10
    for k in 1..10
      x = x + 1
    end
  end
end
puts x
1000
# ADDITIVE
x = 0
for i in 1..10
  x = x + 1
end
for j in 1..10
  x = x + 1
end
for k in 1..10
  x = x + 1
end
puts x
30

Applications to programming

def try(n)
  x = 0
  for i in 1..n
    for j in 1..i
      for k in 1..j
        x = x + 1
      end
    end
  end
  puts x
end

n x \( \sum_{x=1}^n\ x \)
1 1 1
2 4 3
3 10 6
4 20 10
5 35 15
6 56 21
7 84 28
8 120 36
9 165 45
10 220 55

Sums of arithmetic series

\[ \small\begin{array}{cccc} \textbf{n} & \textbf{Sequence} &\textbf{Sum} &\textbf{Equiv}\\ \hline 1 & \small 1 & 1 & 1{(1+1)\over 2} \\ 2 & \small 1+2 & 3 & 2{(1+2)\over 2} \\ 3 & \small 1+2+3 & 6 & 3{(1+3)\over 2} \\ 4 & \small 1+2+3+4 & 10 & 4{(1+4)\over 2} \\ 5 & \small 1+2+3+4+5 & 15 & 5{(1+5)\over 2} \\ 6 & \small 1+2+3+4+5+6 & 21 & 6{(1+6)\over 2} \\ 7 & \small 1+2+3+4+5+6+7 & 28 & 7{(1+7)\over 2} \\ 8 & \small 1+2+3+4+5+6+7+8 & 36 & 8{(1+8)\over 2} \\ \hline \end{array} \]

Formula for this function

\[ \begin{array}{rcc} count & = & \sum{\{1 .. n\}} + \sum{\{1 .. (n-1)\}} + ... + \{1\} \\ & = & {x(x+1)\over 2} + {(x-1)((x-1)+1)\over 2} + ... + 1 \\ & = & {x_n + x_n^2\over 2} + {x_{n-1} + x_{n-1}^2\over 2} + ... + {x_{1} + x_{1}^2\over 2}\\ & = & {\sum_{i=1}^{n}\ x_i + \sum_{i=1}^{n}\ x_i^2\over 2} \\ \end{array} \]

Ex. Determine the value of k

x = 0
for i in 1..10
  for j in 1..10
      x = x + 1
  end
  for k in 1..10
      x = x + 1
  end
end
puts x
x = 0
for i in 1..10
  for j in 1..10
    for k in 1..10
      x = x + 1
    end
  end  
  x = x + 1
end
puts x

Pigeonhole Principle

If \( N \) objects are placed in \( K \) boxes, then there is at least one box containing at least \( \lceil N/K \rceil \) objects.

Example:

Among 100 people, there are at least \( \lceil 100 / 12 \rceil = 9 \) who were born in the same month.

Ex.6 Pigeonhole examples

  • A drawer contains a dozen brown socks and a dozen black sock, all unmatched. A man takes socks out at random in the dark.

    • How many socks must he take out to be sure that he has at least 2 socks of the same Color?
    • How many socks must he take out to be sure that he has at least two black socks?
  • If there are five possible grades (i.e., A, B, C, D, F), what is the minimum number of students needed to Ensure that at least six students get the same grade.

Ex.7 - Counting at the Restaurant

Given a restaurant offers 8 appetizers and 14 entrées.

How many choices do you have if:

  • You will eat one dish, either an appetizer or an entrée?
  • You are extra hungry and want to eat both an appetizer and an entrée?

Ex.8 Counting examples

  • A palindrome is a string that is identical to the string in reverse order. How many bit strings of length \( n \) are palindromes?

  • How many licence plates can be made using either two letters followed by 4 digits or four letters followed by 2 digit is?

  • How many books can be identified using the 12 digit ISBN?

Binomial Coefficients

Subsets of A = {1,2,3,4,5}

  • Total number of subsets:

\[ |{\cal P}(A)| = 2^5 = 32 \]

  • Total number of subsets of size \( n \) :

\[ \left({|A|\over n!\ (|A| - n)!}\right) \]

Subsets of A = {1,2,3,4,5} by size

\[ \small\begin{array}{|c|c|c|c|c|} \hline n=0 & n=1 & n=2 & n=3 & n=4 & n=5 \\ \hline \left({5\atop 0}\right) & \left({5\atop 1}\right) & \left({5\atop 2}\right) & \left({5\atop 3}\right) & \left({5\atop 4}\right) & \left({5\atop 5}\right) \\ \hline \left({5!\over 0!\ 5!}\right) & \left({5!\over 1!\ 4!}\right) & \left({5!\over 2!\ 3!}\right) & \left({5!\over 3!\ 2!}\right) & \left({5!\over 4!\ 1!}\right) & \left({5!\over 5!\ 0!}\right) \\ \hline {5\cdot4\cdot3\cdot2\cdot1\over (5\cdot4\cdot3\cdot2\cdot1)} & {5\cdot4\cdot3\cdot2\cdot1\over (1)(4\cdot3\cdot2\cdot1)} & {5\cdot4\cdot3\cdot2\cdot1\over (2\cdot1)(3\cdot2\cdot1)} & {5\cdot4\cdot3\cdot2\cdot1\over (3\cdot2\cdot1)(2\cdot1)} & {5\cdot4\cdot3\cdot2\cdot1\over (4\cdot3\cdot2\cdot1)(1)} & {5\cdot4\cdot3\cdot2\cdot1\over (5\cdot4\cdot3\cdot2\cdot1)} \\ \hline {1 \over 1} & {5 \over 1} & {5\cdot4 \over 2\cdot1} = {5\cdot2\over 1} & {5\cdot4\cdot3 \over 3\cdot2\cdot1} = {5\cdot 2\over 1} & {5 \over 1} & {1 \over 1}\\ \hline 1 & 5 & 10 & 10 & 5 & 1 \\ \hline \emptyset & \{1\}, & \{1,2\}, \{2,3\}, &\{1,2,3\}, \{2,3,4\}, & \{1,2,3,4\}, & \{1,2,3,4,5\}\\ & \{2\}, &\{3,4\}, \{4,5\},& \{3,4,5\}, \{1,2,4\}, & \{1,2,3,5\}, & \\ &\{3\}, & \{1,3\}, \{1,4\}, &\{2,3,5\}, \{1,2,5\}, & \{1,2,4,5\}, & \\ &\{4\}, &\{1,5\}, \{1,4\}, &\{1,3,4\}, \{1,3,5\},&\{1,3,4,5\},&\\ &\{5\} &\{2,5\}, \{1,5\} & \{1,4,5\}, \{2,4,5\} & \{2,3,4,5\} & \\ \hline 00000 & 10000, & 11000,01100, & 11100, 01110, & 11110, & 11111 \\ & 01000, & 00110, 00011, & 00111, 11010, & 11101, & \\ & 00100, & 10100, 10010, & 01101, 11001, & 11011, & \\ & 00010, & 10001, 10010, & 10110, 10101, & 10111, &\\ & 00001 & 01001, 10001 & 10011, 01011 & 01111 & \\ \hline \end{array} \]

Bit Strings

  • An \( n \) - bit string is a bit string of length n. That is, it is a string containing \( n \) symbols, each of which is a bit, either 0 or 1.
  • The weight of a bit string is the number of 1’s in it.
  • \( B^n \) is the set of all \( n \) - bit strings, \( B^n_k \) is the set of all \( n \) - bit strings of weight \( k \) .

\[ \small\begin{array}{|l|c|c|c|c|c|} \hline weight: & k=0 & k=1 & k=2 & k=3 & k=4 & k=5 \\ \hline B^5_k & 00000 & 10000, & 11000, 01100, & 11100, 01110, & 11110,& 11111 \\ & & 01000, & 00110, 00011, & 00111, 10110, & 11101, & \\ & & 00100, & 10100, 01010, & 01011, 10011, & 11011, & \\ & & 00010, & 00101, 10010, & 10101, 11001, & 10111, & \\ & & 00001 & 01001, 10001 & 11010, 01101 & 01111 & \\ \hline B^5_k& 1 & 5 & 10 & 10 & 5 & 1 \\ \hline \end{array} \]

Recursive Relationship in Bit Strings

  • Recursively break the problem down by imposing a value of the first digit of the unknown set and solving the problem for the resulting subsets:

    \[ \{?????\}_{k=3} = 0\{????\}_{k=3} + 1\{????\}_{k=2} \]

  • Once the problem has been reduced to a simple subset, the values are back substituted.

\[ \begin{array}{rcccccl} |B^5_3| & = & |B^4_3| + |B^4_2| &=& 4 + 6 & = & 10 \\ |B^4_3| & = & |B^3_3| + |B^3_2| &=& 1 + 3 & = & 4 \\ |B^4_2| & = & |B^3_2| + |B^3_1| &=& 3 + 3 & = & 6 \\ \end{array} \]

Lattice Points

  • Movement through a lattice is like Bitstrings
  • Shortest paths are restricted to 2 moves: Up or Right
  • Thus all possible paths (0,0) to (3,2) must go through points \( A \) or \( B \)
  • \( B \) can be reached via \( \{RRRU, RRUR, RURR, URRR\} \)
  • \( A \) can be reached via \( \{RRUU, RURU,RUUR,URRU,UURR\} \)
  • Recursive relationships also apply

lattice

Binomial Coefficients

\[ \begin{array}{c} (x + y)^1 = x + y\\ (x + y)^2 = x^2 + 2xy + y^2\\ (x + y)^3 = x^3 + 3x^2y + 3xy^2 + y^3\\ (x + y)^4 = x^4 + +4x^3y + 6x^2y^2 + 4xy^3 + y^4\\ (x + y)^5 = x^5 + 5x^4y + 10x^3y^2 + 10x^2y^3 + 5xy^4 + y^5\\ \end{array} \]

Binomial Coefficients

\[ \begin{array}{c} \exists n,k: n \ge 0, 0 \le k \le n \Rightarrow\\ \left({n \atop k}\right)\\ \end{array} \]

  • Read as n choose k.
  • Equals \( |B^n_k| \) the number of \( n \) - bit strings of weight \( k \)
  • Equals the number of subsets of size \( n \) with cardinality \( k \)
  • Equals the number of lattice paths of length \( n \) with \( k \) steps to the right.
  • Equals the coefficient of \( x^k y^{n−k} \) in the expansion of \( (x + y)^n \)
  • Equals the number of ways to select \( k \) objects from a total of \( n \) objects

Recurrence Relationship

\[ \left({n \atop k}\right) =\left({n-1 \atop k-1}\right) + \left({n-1 \atop k}\right) \]

Pascal Triangle

Ex. 9: TERMS

Define these terms:

  • Principles:
    • Additive Principle
    • Multiplicative Principle
    • Pigeonhole Principle
  • Operators:
    1) \( A \subseteq B \), 2) \( A\cap B \), 3) \( A \cup B \),
    4) \( A\backslash B \), 5) \( \bar{A} \), 6) \( |A| \)
  • Function
    • Cartesian Product
    • Inverse Function
    • Bijections
    • Injections
    • Surjection

Unit 2: Assignments