. + DISCRETE MATHEMATICS AND ITS APPLICATIONS FOR COMPUTER SCIENCE 110 100 111 101 010 111 011 001 DR. AWATIF MOHAMMED ALI ELSIDDIEG SALMAN BIN ABDULAZIZ UNIVERSITY FACULTY OF SCIENCE AND HUMANITY STUDIES HOTAT BANI TAMIM 2015 1 Dedecated to: my family , my mother and friends 2 List of symbols symbol meaning ¬p Negation of p p˄ q Conjunction of p and q P˅q Disjunction of p and q p⊕𝒒 Exclusive of p and q p→ q The implication of p and q p↔ q Biconditional of p and q P≡q Equivalence of p and q T Tautology F Contradiction P(𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 , … , 𝒙𝒏 ) Propositional function ∀𝒙 p(𝒙) Universal quantification of 𝒑(𝒙) ∃𝒙 𝒑(𝒙) Existential quantification of 𝒑(𝒙) 𝒙∈𝑺 𝒙 is a member of 𝑺 𝒙∉𝑺 𝒙 is not a member of 𝑺 ℕ Set of natural numbers ℤ Set of integers 3 ℤ+ Set of positive integers ℚ Set of rational numbers 𝓡 Set of real numbers S=T Set equality ∅ The empty set (or null set) |S| Cardinality of S P(S) The power set of S (a,b) Ordered pair 𝑺⊆𝑻 S is a subset of T 𝑺⊂𝑻 S is a proper subset of T 𝑨×𝑩 Cartisian product of A and B 𝑨∪𝑩 Union of A and B 𝑨−𝑩 The difference of A and b ̅ 𝑨 Complement of A 𝒂 ≡ 𝒃(𝒎𝒐𝒅 𝒎) 𝒂 is congruent to 𝒃 𝒎𝒐𝒅𝒖𝒍𝒖 𝒎 a| b 𝒂 divides 𝒃 𝒂∤𝒃 𝒂 𝒏𝒐𝒕 𝒅𝒊𝒗𝒊𝒅𝒆𝒔 𝒃 𝒂 div b Quotient when 𝒂 𝒊𝒔 𝒅𝒊𝒗𝒊𝒔𝒂𝒃𝒍𝒆 𝒃𝒚𝒃 𝒇(𝒂) Value of the function 𝒇 at 𝒂 4 𝒇: 𝑨→ B Function of A and B 𝒇𝟏 + 𝒇𝟐 Sum of the functions 𝒇𝟏 𝒂𝒏𝒅 𝒇𝟐 𝒇𝟏 . 𝒇𝟐 Product of the functions 𝒇𝟏 𝒂𝒏𝒅𝒇𝟐 𝒇°𝒈 Composite of 𝒇 and 𝒈 gcd(a,b) Greatest common divisor of a and b Lcm(a,b) Least common multiple of a and b (𝒂𝒌 𝒂𝒌−𝟏 … 𝒂𝟏 𝒂𝟎 )𝒃 Base b representation 𝑨∨𝑩 Join of A and B 𝑨˄ b The meet of A and B 𝑨⊙𝑩 Boolean product of A and B 𝒏! 𝒏 factorial C(a,b) Combination of a and b P(a,b) Permutation of a and b 𝟏𝟎 The sum of i from 0 to 10 ∑𝒊 𝒊=𝟎 5 Contents Introduction: 12 Chapter 1 (Logic and Proofs) 1.1 Logic: 13 13 1.1.1 Propositions : 13 1.1 2 Converse ,Contraposition and Inverse: 16 1.1.3 Biconditionals: 16 1.1.4 Logic and Bit Operations : 17 Exercises: 19 1.1.5 Logical Equivalence: 20 1.2 Introduction to Proofs : 21 1.2.1 Direct Proofs : 21 1.2.2 Indirect Proofs: 22 1.2.3 Proofs by Contradiction: 23 Exercises: 24 1.2.4 Mathematical Induction: 25 Exercises: 28 Chapter 2 29 Basic Structures( sets ,Relations and functions) 2.1 1 Sets: 29 2.1.2 The Power Set: 32 6 2.1.3 Cartesian Products: 33 2.1.4 Sets Operations: 34 2.1.5 Sets Identities: 37 2.1.6 Computer Representation of Sets: 40 Exercises: 41 2.2. Relations: 42 2.2.1 Relations and their properties: 42 2.2.2 Relations on a set: 43 2 .2. 3 Properties of relations: 44 2.2.4 Combining relations: 47 Exercises: 49 2.2.5 Representing relations using matrices: 50 2.2.6 The matrix for the composite relations: 53 2.2.7 Representing Relations Using Diagraphs: 54 Exercises: 57 2.2.8 Equivalence relations: 58 2.2.9 Equivalence classes: 60 Exercices: 64 2.2.10 Partial ordering: 65 2.2.11 Hasse diagrams: 66 2.2.12 Maximal and minimal elements: 68 7 2.2.13 The greater element and the least element: 68 2.2.14 Lattices: 72 Exercises: 73 2.3 Functions : 74 2.3.1 One-to-one and Onto functions : 77 2.3.2 Inverse functions and compositions of functions : 80 2.3.3 Some important functions: 82 Exercises: 83 Chapter 3 85 Algorithms ,Integers and Matrices 3.1 Algorithms: 85 3.2 Number theory: 87 3.2.1 The integers and division: 87 3.2.2 The division algorithm: 88 3.3 Modular Arithmetic: 89 3.4 Primes and greater common divisor primes: 90 3.5 The Greatest common divisor and the least common multiple: 91 Exercises: 93 3.6 Integers and algorithms: 94 3.6.1 Representation of integers: 94 3.6.2 Base conversion: 95 8 3.6.3 Algorithms for integers operations: 98 3.6.4 The Euclidean algorithm: 101 Exercises: 102 Chapter 4 (Boolean Algebra) 4.1.1 Boolean Functions: 105 105 4.1.2 Boolean Expressions and Boolean Functions: 106 4.1.3 Identities of Boolean algebra: 109 4.2 Duality : 110 4.3 The abstract definition of a Boolean algebra: 111 4.4 Representing Boolean Functions: 111 4.5 Logic Gates: 113 4.6 Combinations of Gates: 115 4.7 Minimization of Circuits: 115 4.8 Karnaugh Maps: 115 Exercises: 117 Chapter 5 119 An Introduction to Graph Theory 5.1 Basic Terminology: 120 5.2 Some special simple graphs: 122 5.3 Bipartite graphs: 124 5.4 Representing Graphs and Graph Isomorphism: 9 125 5.5 Adjency Matrices: 127 5.6 Incidence Matrices: 128 5.7 Isomorphism of Graphs: 129 Exercises: 131 5.8.1 Paths: 132 5.8.2 Connectedness in undirected graphs: 133 5.8.3 Connectedness in directed graphs: 135 5.8.4 Counting path between vertices: 136 5.9.1 Euler and Hamilton Paths: 138 5.9.2 Hamilton Paths and Circuits: 139 5.10 Planar Graphs: 141 Exercises: 144 Chapter 6 (Counting) 145 6.1 Basic Counting Principles: 145 6.2 The sum rule: 145 Exercises: 146 6.3 The Pigeonhole Principle: 147 6.4 Sequences and Summations: 148 6.4.1 Sequences: 148 6.4.2 Summations: 150 Exercises: 152 10 6. 5 Discrete Probability: 154 6.5.1 Random variables and sample Spaces : 154 Exercises: 157 6.6 Permutations and Combinations: 158 6.6.1 Permutations: 158 6.6.2 Combinations: 159 6.6 .3 The Binomial Theorem: 160 6.6 .7 Pascal’s triangle: 165 6.8. 1 Recurrence relations: 165 6.8. 2 Inhomogenious Requrrence Relations : 170 6.8.3 Another method of solving inhomogenous recurrence relations: 172 6.8.4 A formula for Fibonaci numbers : 174 Exercises: 175 References: 177 11 Discrete Mathematics Introduction What is discrete mathematics? Discrete mathematics is the part of mathematics denoted to the study of discrete objects. Why We Study Discrete Mathematics? There are several important reasons for studying discrete mathematics. First, through this course you can develop your mathematical maturity: that is, your ability to understand and create mathematical arguments. You will not get very far in your studies in the mathematical sciences without these skills. Second, discrete mathematics is the gate-way to more advanced courses in all parts of the mathematical sciences. Discrete mathematics provides the mathematical foundations for many computer science courses including data structures, algorithms, database theory, automata theory, formal languages, compiler theory, computer security and operating systems students find these courses much more difficult when they have not had the appropriate mathematical foundations from discrete mathematics. 12 Chapter 1 Logic and Proofs 1.1 Logic: 1.1.1 Propositions: Def. (1): A proposition is a declarative sentence (declares a fact) that is either true or false, but not both. Example (1): All the following declarative sentences are propositions 1. Khartoum is the capital of Sudan. 2. 1 + 1 = 2 3. 2 + 2 = 3 Propositions 1 and 2 are true but 3 is false. Example (2): Consider the following sentences: 1. What time it is? 2. Read this carefully. 3. x+1= 2 4. x+y = z Sentences 1 and 2 are not propositions because they are not declarative sentences. Sentences 3 and 4 are not propositions because they are neither true nor false. Def. (2) : Let p be a proposition. The negation of p denoted by is the statement "It is not the case that p p p is p ". read "not p " the truth value of negation of p , p is the opposite of the truth value of . Example (3): Find the negation of the proposition: Today is Friday 13 Solution: Today is not Friday. Example (4): Find the negation of the proposition: "At least 10 inches of rain fell today in Makka" Solution: "Less than 10 inches of rain fell today in Makka". Logic Connectives and Truth Tables of Compound Propositions: Def. (3) : Let p and q be propositions. The conjunction of p and q denoted by p q is the proposition "p and q". The conjunction p q is true when both p and q are true and false otherwise. The truth table for the conjunction of two propositions: p q pq T T T T F F F T F F F F Def. (4): let p and q be propositions. The disjunction of p and q denoted by p q , is the proposition "p or q". The disjunction p q is false when both p and q are false and is true otherwise. The table for the disjunction of two propositions: p q pq T T T T F T F T T F F F 14 Def. (5): Let p and q be propositions. The exclusive OR of p and q denoted by pq, is the proposition that is true when exactly one of p and q is true and false otherwise. The truth table for the exclusive or of two propositions: Def. (6): p q pq T T F T F T F T T F F F Let p and q be propositions. The conditional statement p q is the proposition "if p, then q", the conditional statement p q otherwise. is false when p is true and q is false, and true In the conditional statement pq, p is called the hypothesis and q is called the conclusion. The truth value for the condition statement: p q pq T T T T F F F T T F F T The following ways express the conditional statement: "if p then q "p implies q" "if p, q "p only if q" 'p is sufficient for q" "a sufficient condition for q is p" "q if p" "q whenever p" "q when p" "q is necessary for p" "a necessary condition for p is q" "q unless p" "q follows from p" 15 Example (7): Let p be the statement "Maha learns discrete mathematics" and q the statement Maha will find a good job" express the statements p q as a statement. Solution: If "Maha learns discrete mathematics then she will find a good job" or "Maha will find a good job when she learns discrete mathematics" or "for Maha to get a good job, it is sufficient for her to learn discrete mathematics". 1.1.2 Converse, Contrapositive, and Inverse The proposition q p is called the converse of p q , the contrapositive of p q is the proposition q p . The proposition p q is called the inverse of p q . Example (8): What are the contrapositive, the converse, and the inverse of the conditional statement "The home team wins whenever it is raining". Solution: Because " p whenever q" is one of the ways to express the conditional statement p q , the original statement can be written as "If it is raining, then the home team wins". The contrapositive of the conditional statement is: "If the home team does not win, then it is not raining". The converse is : "If the home team wins, then it is raining" The inverse is : "If it is not raining, then the home team does not win". 1.1.3 Biconditionals: Def. (7): statement Let p and q be propositions. p q is The biconditional the proposition "p if and only if q". the biconditional statement p q is true when p and q have the same 16 truth values, and it is false otherwise biconditional statements are called bi-implications. The truth table for the biconditional p q p q pq T T T T F F F T F F F T Some other common ways to express p q "p is necessary and sufficient for q" "If p then q, and conversely" "p iff q" So p q p q q q Example (10): Construct the truth table of the compound proposition p q p q Solution: p q pq p q p q P q q T T F T T T T F T T F F F T F F F T F F T T F F 1.1.4 Logic and Bit Operations: Def. (8): A bit is a symbol with two values zero and one, a bit string is a sequence of zero or more bits. The length of this string is the number of bits in the strings. 17 Example (11): 1 0101 0011 is a bit string of length nine. The table for the Bit operators OR,AND and XOR: x y x y 0 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 x y 0 0 0 x y Truth value Bit T 1 F 0 Example (12): Find the bitwise OR, bit wise AND and bitwise XOR of the bit strings 01 1011 0110 and 11 0001 1101 Solution: 01 1011 0110 11 0001 1101 11 1011 1111 bit wise OR 01 0001 0100 bit wise AND 10 1010 1011 bitwise XOR 18 Exercises: 1) Which of these sentences are propositions? What are the truth values of those that are propositions? (a) London is the capital of America (b) 2 + 3 = 5 (c) x + 2 = 11 (d) 5 + 7 = 10 (e) Answer this question? 2) What is the negation of each of these propositions (a) Today is Thursday (b) 2 + 1 = 3 (c) The summer in Khartoum is hot and sunny. 3) Construct a truth table for each of these compound propositions: (a) p q pq (b) (c) p q p p (d) p q p q (e) p q p q 4) Construct a truth table for each of these compound propositions: (a) p q r (b) p q r (c) p q p r (d) p q p r 5) Find the bitwise OR, bitwise AND and bitwise XOR of each of these pairs of bit strings: (a) 101 1110 , 010 001 (b) 111 0000 , 1010 1010 (c) 00 0111 0001 , 10 0100 1000 (d) 11 1111 1111 , 00 0000 0000 6) Evaluate each of these expressions (a) 1 1000˄ (1 1011 1 1011) 19 (b) (0 1111 1 010) 0 1000 (c) (0 1010 11011) 0 1000 Def.(9): A Compound proposition that always true is called a tautology, a compound proposition that is always false is called a contradiction and a compound proposition that neither a tautology nor a contradiction is called a contingency. Examples of a tautology and a contradiction p p p ˅ p p ˄ p T F T F F T T F 1.1.5 Logical Equivalence: Def.(10): The compound propositions p and q are called logically equivalent if p q is a tautology. The notation p q denotes that p and q are logically equivalent. Example (13): Show that p q and p q are logically equivalent Solution: p q pq p q p q pq p q ↔( p q ) T T T F F F F T T F T F F T F T F T T F T F F T F F F T T T T T Example (14): Show that p q is logically equivalent to 20 pq Solution: P q p pq pq T T F T T T T F F F F T F T T T T T F F T T T T ( p q) ↔( p q ) Example (15): Show that p q p q is a tautology P q pq pq p q p q T T T T T T F F T T F T F T T F F F F T 1.2 Introduction to Proofs: Introduction : In this section we introduce the notation of a proof and describe methods for constructing proofs. A proof is a valid argument that establishes the truth of a mathematical statement. 1.2.1The Direct Proofs: Def(11).: A direct proof of a conditional statement p q is constructed when the first step is the assumption that p is true; subsequent steps are constructed using rules of inference with the final step showing that q must also be true. Def(12).: The integer n is even if there exists an integer k such that: n = 2k , and n is odd if there exists an integer k such that n = 2k + 1. 21 Example (16): Give a direct proof of the theorem "If n is an odd integer, then n2 is odd". Solution: This theorem states n pn qn where pn is "n is an odd integer" and qn is "n2 is odd", assume that n is odd n 2k 1 , n 2 2k 1 k Z 2 n2 4k 2 4k 1 2 2k 2 2k 1 n2 is odd. 1.2.2 The Indirect Proofs: (Proof by contraposition) pq q p. p q can This means that the conditional statement be proved by showing that its contrapositive q p is true. Example (17): Prove that if n is an integer and 3n + 2 is odd, then n is odd. Solution: pq q p means if 3n + 2 is odd, then n is odd its contrapositive that is n is even implies 3n + 2 is even. Assume that n is even n 2k , k Z 3n 32k 3n 2 32k 2 6k 2 23k 1 22 3n 2 is even If 3n 2 is odd, then n is odd. 1.2.3 Proofs by Contradiction: The proof by contradiction does not prove a result directly. Example (18): Prove that 2 is irrational by giving a proof by contradiction. Solution: Let p be the proposition " 2 is irrational" suppose that p is true. Suppose 2 is rational 2a b where a and b have no common factors 2a 2 b2 2b 2 a 2 a 2 is an even integer a is an even integer a 2c c , Z 2b 2 4c 2 b 2 2c 2 b 2 is an even integer b is an even integer This contradicts a and b have no common factor hence 2 is irrational. Example (19): Give a proof by contradiction of the theorem "if 3n 2 is odd, then n is odd". Solution: p q q p Let p be " 3n 2 is odd" and q be "n is odd". 23 To construct a proof by contradiction assume that both p and ` q are true 3n 2 is odd and n is not odd n is even n 2k , k Z 3n 32k 3n 3 32k 2 3n 2 6k 2 2(3k 1) is even This contradict our assumption that 3n 2 is odd, hence n is odd . Exercises: 1) Use a direct proof to show that the sum of two odd integers is even. 2) Use a direct proof to show that the sum of two even integers is even. 3) Use a proof by contradiction to prove that the sum of an irrational number and a rational number is irrational. 4) Show that if n is an integer and 𝒏𝟑 + 𝟓 𝒊𝒔 𝒐𝒅𝒅 , then n is even using : a) A proof by contraposition. b) A proof by contradiction . 5) Prove that if n is an integer and 3n+2 is even , then n is even using : a) A proof by contraposition. b) A proof by contradiction. 24 6) Show that these statements about the integer x are equivalent; (i) 3x +5 is even . (ii) x+5 is odd. (iii) 𝑥 2 is even. 1.2.4 Mathematical Induction: Introduction: In general, mathematical induction can be used to prove statements that assert that where p (n ) p (n ) is true for all positive integers n , is a propositional function. A proof by mathematical induction has two parts, a basis step, where we show that p (1) is true and inductive step, where we show that for all positive integers k , if p (k ) p (k 1) is true, then is true. Example (1): Show that if n is a positive integer, then 1 2 ..... n n(n 1) 2 Solution: Let p (n ) integers is be the proposition that the sum of the first n positive n( n 1) . 2 Basis step: p (1) inductive step is true because 1 p (k ) (1 1) . 2 holds. Inductive step: Assume that 1 2 ..... k k (k 1) is true ----- (1) 2 we must show that : 1 2 ..... k (k 1) Add (k 1) (k 1)( k 1) 1 (k 1)( k 2) is also true? -----(2) 2 2 to both sides of equation (1) 25 1 2 ..... k (k 1) k (k 1) k (k 1) 2(k 1) (k 1)( k 2) (k 1) 2 2 2 is equal to both sides of equation(2) Hence p ( k 1) p (n) is is true true n IN . Example (2): Use mathematical induction to show that n IN 1 2 22 ... 2n 2n 1 1 Solution: Let p (n ) be the proposition that 1 2 ... 2n 2n 1 1 . Basis step: p ( 0) is true because 20 21 1 1 n IN Inductive step: for the inductive hypothesis, we assume that p (k ) is true. That is, we assume that 1 2 ... 2k 2k 1 1 -----(1) is true To carry out the inductive step using this assumption we must show that when we assume that p (k ) is true, then p ( k 1) is also true. That is, we must show that: 1 2 ... 2k 2k 1 2( k 1) 1 1 2k 2 1 -----(2) is true. ???? assuming the inductive hypothesis assumption of p (k ) , p (k ) is add 2k 1 to both sides of equation (1) 2 1 2 22 ... 2k 2k 1 1 2 22 ... 2k 2k 1 k 1 2.2 2 1 2k 1 k 1 k 2 1 1 is equal to both sides of equation (2) p (k 1) Hence is true p (n) true. is true n IN . 26 Under the Example(3): Use mathematical induction to prove: n IN n 2n Solution: Let be the proposition that p (n ) Basis step: p (1) is true, because 1 21 2 Inductive step: Assume that i.e p (k ) is true n IN ----(1) k 2k To complete the inductive step, we need to show that if true, then p ( k 1) = k 1 2k 1 p (k ) is is true ----(2)??? We add 1 to both sides of inequality (1) k 1 2k 1 2k 2k 2.2k 2k 1 is equal to both sides of inequality (2) hence p ( k 1) p (n) is is true true n IN . Example (4): Use mathematical induction to prove that 2n n! n 4 Solution : Let p (n ) be the propositional that Basis step: p ( 4) is true because Inductive step: Assume that 2k k! 2 n n! 24 16 4! 24 p (k ) is true k 4 We must show that under this hypothesis 2k 1 (k 1)!? We have 2 k 1 2.2 k (by definition of exponent) 27 p ( k 1) is also true 2.k! (by inductive hypothesis) (k 1)k! ( k 1)! (because 2 k 1 ) (by definition of factorial function) This shows that p ( k 1) is true when p (k ) is true. Exercises: 1) Prove that ∀𝒏 ∈ ℤ 1.2 + 2.3 + ⋯ + 𝑛(𝑛 + 1) = 𝒏(𝒏+𝟏)(𝒏+𝟐) 𝟑 2) Let 𝒑(𝒏) be the statement that 𝒏! < 𝒏𝒏 where 𝒏 > 1 a) What is 𝒑(𝟐)? b) Show that 𝒑(𝟐) 3) Prove that 3𝑛 < 𝑛!, ∀𝑛 > 6 4) Prove that 2𝑛 > 𝑛2 , ∀𝑛 > 4 5) Prove that 12 + 32 + 52 + ⋯ + (2n + 1) = (𝒏+𝟏)(𝟐𝒏+𝟏)(𝟐𝒏+𝟑) 6) Let 𝑝(𝑛) be the statement that 12 + 22 + 𝑛2 = 𝟑 𝒏(𝒏+𝟏)(𝟐𝒏+𝟏) 𝟔 ,∀𝑛 ∈ ℤ+ 𝒏(𝒏+𝟏) 𝟐 7) Let 𝒑(𝒏) be the statement that 𝟏𝟑 + 𝟐𝟑 + 𝒏𝟑 = ( ∀𝒏 ∈ ℤ+ a) What is the statement 𝒑(𝟏)? b) Show that 𝒑(𝟏) is true. 28 𝟐 ) , Chapter 2 Basic Structures 1) Sets 2) Relations 3) Functions 2.1 Sets : Def. (1): A set is a collection of an unordered of objects. Def. (2): The objects in a set are called the elements, or members, of the set. A set is said to contain its elements. We write a A to denote a is an element of the set A. the notation a A denotes that a is not an element of the set A. We use a notation where all members of the set are listed between braces {a, b, c, d} represent the set with four elements a, b, c and d. Example (1): 1) The set V of all vowels in the English alphabet can be written as: V = {a, e, i, o, u} 2) The set O of odd +ve integers less than 10 can be represented by : O = {1, 3, 5, 7, 9} 3) The set of +ve integers less than 100 can be denoted by {1, 2, …., 99} Another way to describe a set is to use set builder notation. We characterize all those elements in the set by stating the property or properties they must have to be members. e.g., the set O of all odd +ve integers less than 10 can be written as O = { x | x is an odd positive integer < 10} O = { x Z | x is odd and x < 10} Q+ = { x | x p/q , for some +ve integers p and q} 29 is the set of all +ve rational numbers IN = {0, 1, 2, 3, ….} the set of natural numbers. Z = {…, -1, -1, 0, 1, 2, …} the set of integers Z + = {1, 2, 3, …} the set of +ve integers Q = {p/q | p ,q Z, q 0} the set of rational numbers IR, the set of real numbers. Def (3). Two sets are equal if and only if they have the same elements. Example (2): The set {1, 2, 3} and {3, 2, 2,1} are equal because they have the same elements. Note that the order in which the elements of a set are listed does not matter. Sets can be represented graphically using Venn diagrams. In Venn diagrams the universal set U which contains all the objects under consideration, is represented by a rectangle. In side this rectangle, circles or other geometrical figures are used to represent sets. Example (3): Draw a Venn diagram that represent V, the set of vowels in the English alphabet. U ax ux e V ox i . . Venn diagram for the set of vowels 30 Def (4).: The set A is said to be a subset of B if and only if every element of A is also an element of B . we use the notation A B to indicate that A is a subset of the set B . A B U A B A B B A B A Venn diagram showing A B Example (4): The set of all odd positive integers less than 10 is a subset of the set of all positive integers less than 10. The set of rational numbers is a subset of real numbers Q IR Theorem: For every set S (i) S (ii) S S Proof: We will prove (i) and leave the proof of (ii) as an exercise Let S be a set x( x x S ) is true because the empty set contains no elements it follows that conditional statement x is always false, it follows that the x x S is always true because its hypothesis is always false and a conditional statement with a false hypothesis is true. 31 When we wish to emphasize that a set A is a subset of the set B but A B we write A B and say that A is a proper subset of B x( x A x B) x( x B x A) . If A and B are sets with A B and B A , then A = B . Def. (4): Let S be a set. If there are exactly n distinct elements in S where n is a nonnegative integer, we say that S is a finite set and that n is the cardinality of S. The cardinality of S is denoted by: |S|. Examples (5): 1) LetA be the set of odd positive integers less than 10. Then |A|= 5. 2) Let S be the set of letters in the English alphabet. Then | S | = 26. 3) 0 . Def.(6): A set is said to be infinite if it is not finite. Example (6): The set of positive integers is infinite. 2.1.2 The Power Set: Def. (1): Given a set S , the power set of S is the set of all subsets of the set S and is denoted by p (S ) . Example (7): What is the power set of the set {0, 1, 2}? Solution: p0,1,2 is the set of all subsets of {0, 1, 2}. Hence p0,1,2 ,0 , 1 , 2 , 0,1 , 0,2 , 1,2 , 0,1,2 Example (8): What is the power set of the empty set? What is the power set of the set 32 Solution : p p ,{ If a set has n elements, then its power set has 2n elements 2.1.3 Cartesian Products: Def. (7) : The ordered n–tuple a1 , a 2 , , a n is the ordered collection that has a1 as its first element a 2 as its second element and a n as its nth element. Def. (8): Let A and B be sets. The Cartesian product of A and B, denoted by A B , is the set of all ordered pairs ( a , b ) where a A and b B A B = {( a , b ) | a A b B } Example (9): What is the Cartesian product of A = {1,2} and B = { a , b , c }? Solution: A B (1, a), (1, b), (1, c), (2, a), (2, b), (2, c) Def.(9):A subset R of the Cartesian product A B is called a relation from the set A to the set B . the elements of R are ordered pairs. For example R a,0), (a,1), (b,1), (b,2), (c,0), (c,3) is a relation from the set a, b, c to the set 0,1,2,3. Example (10): Show that the Cartesian product A B B A where A and B are the sets in example (9) A B 1, a), (1, b), (1, c), (2, a), (2, b), (2, c) B A (a,1), (b,1), (c,1)(a,2)(b,2), (c,2) 33 Def. (10): The Cartesian product of A1 , A2 , ... , An denoted by A1 A1 A3 ... An is the set of ordered n-tuples a1 , a 2 , ... , a n where ai A i 1,2,...., n . Example (11): What is the Cartesian product A B C where A 0,1, B 1,2 and C 0,1,2? Solution: A B C (0,1,0), (0,1,1), (0,1,2), (0,2,0), (0,2,1), (0,2,2), (1,1,0), (1,1,1) (1,1,2), 1,2,0), (1,2,1), (1,2,2) 2.1.4 Sets Operations: Def. (11) : Let A and B sets. The union of the sets A and B, denoted by A B , is the set that contains those elements are either in A or in B, A B x x Avx B u A B A B Example (12): The union of the sets 1,3,5 and 1,2,3 is the set 1,2,3,5. Def. (12): Let A and B be sets. The intersection of the sets A and B, denoted by A B , is the set containing those elements in both A and B. A B x x A x B u A A B 34 B Example (13): The intersection of the sets 1,3,5 and 1,2,3 is the set 1,3. Def. (13): Two sets are called disjoint if their intersection is the empty set. Example (14): Let A 1,3,5,7,9, B 2,4,6,8 A B , A and B are disjoint A B A B A B Def. (14): Let A and B sets. The difference of A and B , denoted by A – B , is the set containing those elements that are in A but not in B. A B x x A x B Example (15): The difference of 1,3,5 and 1,2,3 is the set 5 Def. (15) : Let U be the universal set. denoted by A, The complement of the set A, is complement of A with respect to U A A A x x A A A 35 Table (1) Sets identities A A A U A Identity laws A U U A Domination laws A A A A A A Idempotent laws A A Complementation law A B B A A B B A Commutative laws A B C A B C A B C A B C Associative laws A B C A B A C A B C A B A C Distributive laws A B A B Demorgans laws A B A B A A B A A A B A Absorption laws A A U Complement laws A A 36 Example (16): Let A a, e, i, o, u (where the universal set is the set of the letters of the English alphabet). Then A b, c, d , f , g , h, j, k , l , m, n, p, q, r , s, t , v, w, x, y, z Example (17): Let A be the set of positive integers greater than 10 (with universal set the set of all positive integers). Then A 1,2,3,4,5,6,7,8,9,10. 2.1.5 Sets Identities: Table 1 list the most important set identities here we prove several of these identities using three different methods the proofs of the remaining identities will be left as exercises. Example (18): Use set builder notation express the reasoning establish the 2nd demorgan’s law A B A B Proof : A B x x ( A B) (def of complement) = x x A B (def. of does not belong symbol) = x x A x B (def . of intersection) = x x A x B (first demorgan’s law) = x x A x B (by definition of does not belong symbol) = x x A x B (by definition of complement) = x x ( A B)(by definition of union) = A B (by meaning of set building notation). Example (19): Prove the first distributive law from table (1), which states that A B C A B A C sets A, B and C. 37 Solution: (i) Suppose x A B C x A and x ( B C ) x A and x B or x C (or both) x A and x B or x A and x C x A B or x A C x A B A C A B C A B A C . (ii) Suppose that x ( A B A C ) x ( A B) or x ( A C) x A and x B or x A x C x A and x B or x C x A and x ( B C ) x ( A B C ) A B A C A B C From (i), (ii) we complete the proof. Table (2): A membership table for the distributive property A B C BC A B C A B AC A B A C 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 To complete the proof. 38 Example (20): Let A, B and C be sets. Show that A B C C B A . Solution : A B C A B C (First Demorgan’s law) = A B C (2nd Demorgan’s law) = B C A (commutative law for intersections) = C B A (Commutative law for unions) Generalized Unions and intersections. U A U B A B C Union of A, B and C Intersection of A, B and C Example (21): Let A 0,2,4,6,8 , B 0,1,2,3,4 and C 0,3,6,9 what are A B C and A B C Solution: A B C 0,1,2,3,4,6,8,9 A B C 0 Def. (16): The union of a collection of sets is the set that contains those elements that are members of at least one set in the collection n A1 A2 An Ai i 1 39 Def. (17): The intersection of a collection of sets is the set that contains those elements that are members of all the sets in the collection n A1 A2 An Ai i 1 We can extend the notation we have introduce for unions and intersections to other families can be denoted by 1) A1 A2 An Ai i 1 2) A1 A2 An Ai i 1 Example (22): Suppose that Ai 1,2, , i for i 1,2, Then i 1 i 1 Ai 1,2, , ii 1,2,3, and A Ai 1,2, , i 1 i i 1 i i 1 2.1.6 Computer Representation of sets: There are various ways to represent sets using a computer. One method is to store the elements of the set in an unordered fashion. However, if this is done, the operations of computing the union, intersection or difference of two sets would be time-consuming, because each of these operations would require a large amount of searching for elements. We will present a method for storing elements using an arbitrary ordering of the elements of the universal set. This method of representing sets makes computing combinations of sets easy. 40 Assume that the universal set is finite. arbitrary ordering of elements of First, specify an a1 , a 2 , , a n . Represent a subset of with the bit string of length n, where the ith bit in this string is 1 if ai belongs to A and 0 if ai does not belong to A. Example (23): Suppose that the universal set U= { 1,2,3,4,…,10} The bit string for the subsets 1,2,3,4,6 and 1,3,5,7,9 of U are 11 1101 0000 and 10 1010 1010 respectively. Use bit strings to find the union and intersection of these sets? Solution: 1) The bit string for the union of these sets is 11 1101 0000 10 1010 1010 = 11 1111 1010 which corresponds to the set 1,2,3,4,5,6,7,9 . 2) The bit string for the intersection of these sets is 11 1101 0000 10 1010 1010 = 10 1000 000 Which corresponds to the set 1,3 Exercises: 1) Let 𝑨 = {𝟏, 𝟐 , 𝟑, 𝟒, 𝟓} and 𝑩 = {𝟎, 𝟑, 𝟔} Find (a) 𝑨 ∪ 𝑩 (b) 𝑨 ∩ 𝑩 (c) 𝑨 − 𝑩 (d) 𝑩 − 𝑨 2) Find the sets A and B if 𝑨 − 𝑩 = {𝟏, 𝟓, 𝟕, 𝟖}, 𝑩 − 𝑨 = {𝟐, 𝟏𝟎} and 𝑨 ∩ 𝑩 = {𝟑, 𝟔, 𝟗} 3) Determine whether these statements are true or false: (a) 𝟎 ∈ ∅ (b) ∅ ∈ {𝟎} (c) {𝟎} ⊂ ∅ (d) ∅ ⊂ {𝟎} (e) {𝟎} ∈ {𝟎} (f) {𝟎} ⊂ {∅, {∅}} (g) {{∅}} ⊂ {{∅}} , {∅}} 4) Use Venn diagram to illustrate the subset of odd integers in the set of all positive integers not exceeding 10. 5) Use Venn diagram to illustrate the relation ship 𝑨 ⊆ 𝑩 and 𝑩 ⊆𝑪 41 6) What is the Cartesian product 𝑨 × 𝑩 × 𝑪 where 𝑨 = {𝒂, 𝒃, 𝒄} , 𝑩 = {𝒙, 𝒚} and 𝑪 = {𝟎, 𝟏} 7) Let 𝑨 = {𝟎, 𝟐, 𝟒, 𝟔, 𝟖, 𝟏𝟎}, 𝑩 = {𝟎, 𝟏, 𝟐, 𝟑, 𝟒, 𝟓, 𝟔} and 𝑪 = {𝟒, 𝟓, 𝟔, 𝟕, 𝟖, 𝟗, 𝟏𝟎}. Find: (a) 𝑨 ∩ 𝑩 ∩ 𝑪 (b) 𝑨 ∪ 𝑩 ∪ 𝑪 (c) (𝑨 ∪ 𝑩) ∩ 𝑪 (d) (𝑨 ∩ 𝑩) ∪ 𝑪 8) Suppose that the universal set 𝑼 = {𝟏, 𝟐, 𝟑, … , 𝟏𝟎} Express each of these sets with bit strings where the ith in the string is 1 if i is the set and 0 otherwise. a) {𝟑, 𝟒, 𝟓} 𝒃){𝟏, 𝟑, 𝟔, 𝟏𝟎} c) {𝟐, 𝟑, 𝟒, 𝟕, 𝟖, 𝟗} 9) Using the same universal set in problem (8) find the set specified by each of these bit strings (a) 11 1100 1111 (b) 01 0111 1000 (c) 10 0000 0001 2.2.1 Relations and their properties: Def. (1): let A and B be sets. A binary relation from A to B is a subset of A B We use aRb to denote that ( a, b) IR and aRb to denote that ( a , b) R Example (1): Let A be the set of students in your school, and let B be the set of courses. Let R be the notation that consists of those pairs ( a, b) , where a is a student enrolled in course b . For instance, if Ahmed and Ali and Zeid are enrolled in CS518 , the pairs( Ahmed, CS518 ) and (Ali, CS518 ), belong to R , if Ali also enrolled in CS510 then the pair (Ali, CS510 ) is also in R , however, if Zeid is not enrolled in CS510 then the pair (Zeid, CS510 ) is not in R . 42 Example (2): Let A 0,1,2 and B a, b. Then {(0, 𝑎), (0, 𝑏), (1, 𝑎), (2, 𝑏)} is a relation from A to B , aRa but 1Rb . Relations can be represented graphically as shown in the figure: 0. a 1. 2. b R a b 0 x x 1 x 2 x 2.2.2 Relations on a set : Relations from a set A to itself are of special interest. Def. (2): A relation on the set A is a relation from A to A Example (3): Let A 1,2,3,4 which ordered pairs are in the relation R (a, b) a divides b Solution : ( a, b) R if and only if a and b are positive integers not exceeding 4 such that a divides b R (1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4) R 1 2 3 4 1 1 1 x x x x 2 2 2 x 3 3 3 4 4 4 x x x Example (4) : How many relations are there on a set with n elements? 43 Solution: A relation on a set A A A since A A has n 2 elements when A has n elements, hence A has 2 n subsets. there are 2n subsets of A A . 2 2 Thus there are 2 n relations on a set of n elements. For example there are 23 29 512 relations on the set a, b, c 2 2.2.3 Properties of relations: Def. (3): A relation R on a set A is called reflexive if (a, a) R, a A . Example (5): On 1,2,3,4 R1 (1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4) R2 (1,1), (1,2), (2,1) R3 (1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4) R4 (2,1), (3,1), (3,2), (4,1), (4,2), (4,3) R5 (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4) R6 (3,4) Which of these relations are reflexive? Solution: The relations R3 and R5 are reflexive because they both contain all pairs of the form ( a , a ) namely (1,1), (2,2), (3,3), (4,4) . The other relations are not reflexive and because they do not contain all of these ordered pairs. In particular R1 , R2 , R4 and R6 are not reflexive because (3,3) is not in any of these relations. Example (6): Is the "divides" relation on the set of positive integers reflexive. 44 Solution: Since a a whenever a is a positive integer denoted by Rdiv integer, the "divides" relation is reflexive. If we replace the set of positive integers with the set of all integers the relation is not reflexive because 0 does not divides 0 . Def. (4): A relation on a set A is called symmetric if (a, b) R , a, b A . ( a, b) R and (b, a ) R A relation R on a set A such that (b, a) R , whenever a, b A , if then a b is called antisymmetric. Example (7): Consider the relations on the set of integers: R1 (a, b) a b R2 (a, b) a b 𝑅3 = {(𝑎,b)│a = b , or a = - b } R4 (a, b) a b R5 (a, b) a b 1 R6 (a, b) a b 3 Which of these relations contain each of the pairs (1,1) ,(1,2) ,(2,1) ,(1,-1) and (2,2)? Solution: The pair (1,1) is in 𝑅1 , 𝑅3 , 𝑅4 𝑎𝑛𝑑 𝑅6 , (1,2) 𝑖𝑠 𝑖𝑛 𝑅1 𝑎𝑛𝑑 𝑅6 , (2,1) 𝑖𝑠 𝑖𝑛 𝑅2 , 𝑅5 𝑎𝑛𝑑 𝑅6 , (1, −1)𝑖𝑠 𝑖𝑛 𝑅1 , 𝑅3 𝑎𝑛𝑑𝑅6 and finally, (2,2)is in𝑅1 , 𝑅3 , 𝑎𝑛𝑑 𝑅4 Example (8): Which of the relations from example (5) are symmetric and which are antisymmetric. 45 Solution : The relations R2 and R3 are symmetric because in each case belongs to the relation whenever ( a, b) does. For R2 both (b, a) (2,1) and (1,2) R2 . For R3 both (2,1), (1,2) R3 and (1,4), (4,1) R3 . R4 , R5 and R6 are antisymmetric. Example (9): Which of the relations from example (7) are symmetric and which are antisymmetric. Solution: The relations R3 , R4 and R6 are symmetric. R3 is symmetric, for a b or a b , then b a or b a R4 is symmetric because a b b a . R6 is symmetric because a b 3 b a 3 . non of the other relations is symmetric (verify). The relations R1, R2 , R4 and R5 are antisymmetric R1 is antisymmetric because the inequalities a b and b a a b R2 is antisymmetric because it is impossible for a b and b a . R4 is antisymmetric, because two elements are related with respect to R4 if and only if they are equal. R5 is antisymmetric because it is impossible that a b 1 and b a 1 . Example (10): Is Rdiv on the set of positive integers symmetric? antisymmetric? 46 Is it Solution: Rdiv is not symmetric because (1,2) Rdiv 1 2 but (2,1) Rdiv since 2∤1. It is antisymmetric, a, b Z with a b and b a , then a b . Def. (3): A relation R on a set A is called transitive if whenever and (b, c) R , then ( a, b) R (a, c) R. a, b, c A . Using quantifiers a, b, c A (a, b) R (b, c) R (a, c) R . Example (11): Which of the relations in example (7) are transitive? Solution: The relations R1 , R2 , R3 and R4 are transitive. R1 is transitive since a b and b c a c R2 is transitive since a b and b c a c R3 is transitive since a b and b c a c R4 is clearly transitive.(verify)? R5 is not transitive since (2,1) and (1,0) R5 but (2,0) R5 R6 is not transitive since (2,1) and (1,2) R5 but (2,2) R6 Example (12): Is Rdiv on the set of positive integers is transitive?. Solution: Suppose that a divides b and b divides c . Then there are positive integers k and L such that b ak so a divides c . Hence Rdiv is transitive . 2.2.4 Combining relations: Example (13): Let A 1,2,3 and B 1,2,3,4 47 and c bL . Hence c a(kL) , The relation R1 (1,1), (2,2), (3,3)and R2 (1,1), (1,2), (1,3), (1,4) Can be combined to obtain: R1 R2 (1,1), (1,2), (1,3), (1,4), (2,2), (3,3) R1 R2 (1,1) R1 R2 (2,2), (3,3) R2 R1 (1,2), (1,3), (1,4) Example (14): Let R1 be the "less than" relation on the set of real numbers and let R2 be the "greater than" relation on the set of real numbers, that is R1 ( x, y) x y and R2 ( x, y) x y what are (1) R1 R2 (2) R1 R2 (3) R1 R2 (4) R2 R1 and (5) R1 R2 ? Solution (1) We note that ( x, y) R1 R2 iff ( x, y) R1 or ( x, y) R2 . Hence ( x, y) R1 R2 iff x y or x y . Because the condition x y or x y is the same as the condition x y it follows that R1 R2 ( x, y) x y (2) ( x, y) R1 R2 since x y and x y is impossible. Hence R1 R2 =𝝓 (3) R1 R2 R1 (4) R2 R1 R2 (5) R1 R2 R1 R2 R1 R2 ( x, y) x y Def. (4): Let R be a relation from a set A to the set B and S be a relation from B to a set C . The composite of R and S is the relation consisting of ordered pairs ( a, c ) where a A and c C , and for which there exists an element b B such that denote the composite of R and S by SoR . 48 ( a, b) R and (b, c) S . We Example (15): What is the composite of R and S where R is a relation from 1,2,3 to 1,2,3,4 with R (1,1), (1,4), (2,3), (3,1), (3,4) and S is a relation from 1,2,3,4 to 0,1,2 with S (1,0), (2,0), (3,1), (3,2), (4,1) Solution: SoR (1,0), (1,1), (2,1), (2,2), (3,0), (3,1) Def. (5): Let R be a relation on the set A . The powers R n , n 1,2,.... are defined recursively by R1 R and R n 1 R n oR ( R 2 RoR , R 3 R 2 oR RoRoR and so on) Example (16): Let R (1,1), (2,1), (3,2), (4,3) find R n for n 4,5,.... . Solution: Since R 2 RoR R 2 (1,1), (2,1), (3,1), (4,2) R 3 R 2 oR R 4 R3 . R 2 (1,1), (2,1), (3,1), (4,2) Hence Rn R3 for n 5,6,7,....... Theorem(1) : The relation R on a set A is transitive iff R n R for n 1,2,.... Exercises: 1) List the ordered pairs in the relation R from A={1,2,3,4} to B={0,1,2,3}, where (a,b) R if and only if : a) a=b (b) a+b =4 (c) a b (d) a│b 2) For each of these relations on the set {1,2,3,4}, decide whether it is reflexive ,symmetric ,antisymmetric and whether it is transitive: a){(2,2) ,(2,3),(2,4),(3,2),(3,3),(3,4)} b) {(1,1),(1,2),(2,1) ,(2,2),(3,3) ,(4,4)} 49 c) {(1,2),(2,3) ,(3,4)} d) {(2,4),(4,2)} 3) Determine whether the relation R on the set of all people is reflexive , symmetric ,antisymmetric and /or transitive ,where (a,b) R if and only if : a) a is taller than b b) a and b were born on the same day. c) a has the same first name as b. d) a and b have a common grandparent. 4) Let 𝑹𝟏 = { (𝟏, 𝟐), (𝟐, 𝟑), (𝟑, 𝟒)} And 𝑹𝟐 = { (𝟏, 𝟏), (𝟏, 𝟐), (𝟐, 𝟏), (𝟐, 𝟐), (𝟐, 𝟑), (𝟑, 𝟏), (𝟑, 𝟐), (𝟑, 𝟒)} be relations from {1,2,3} to {1,2,3,4} find: a) 𝑹𝟏 ∪ 𝑹𝟐 b) 𝑹𝟏 ∩ 𝑹𝟐 c) 𝑹𝟏 ⨁ 𝑹𝟐 d) 𝑹𝟏 − 𝑹𝟐 e) 𝑹𝟐 − 𝑹𝟏 5) Let R be the relation {(1,2),(1,3),(2,3),(2,4),(3,1)} and S be the relation {(2,1),(1,3),(2,3),(2,4),(3,1)} find SR 2.2.5 Representing Relations Using Matrices: A relation between finite sets can be represented using a zero – one matrices. Suppose that R is a relation from A a1, a2 ,..., an to B b1, b2 ,..., bn (Here the elements of the sets A and B have been listed in a particular, but arbitrary, order. Furthermore when A B we use the same ordering from A and B . The relation R can be represented by the matrix where 𝑀𝑅 = [𝑚𝑖𝑗 ] 50 1 if ai , b j R mij 0 if ai , b j R Example (17): Suppose that A 1,2,3and B 1,2 let R be the relation from A to B containing (a, b) if a A , b B , and a b . What is the matrix representing R if a1 1, a2 2, a3 3 and b 1, b2 2 ? Solution: Because R (2,1), (3,1), (3,2), the matrix for R is 0 0 M R 1 0 1 1 Example (18): Let A a1 , a2 , a3 and B b1, b2 , b3 , b4 , b5 represented by the matrix 0 1 0 0 0 M R 1 0 1 1 0 1 0 1 0 1 Solution: Since R consists of those ordered pairs ai , b j with mij 1 , it follows that R a1 , b2 , a2 , b1 , a2 , b3 , a2 , b4 , a3 , b1 , a3 , b3 , a3 , b5 If the matrix of R is a square matrix, we say that R is reflexive if ai , ai R, i 1,2,..., n (the elements in the diagonal of the matrix are 1's). The relation R is symmetric if a, b R implies a, b R m ij m ji i 1,2,...., n . a, b R and The relation R is antisymmetric if and only if ( b, a) R a b . Consequently, the matrix of an 51 antisymmetric relation has the property that if m ji 1 with i j then m ji 0 . Or, in other words, either m ji 0 or mij 0 when i j 1 1 1 0 1 1 0 Symmetric relation 0 0 0 1 antisymmetric matrix Example (19): Suppose that the relation R on a set is represented by the matrix. 1 1 0 M R 1 1 1 0 1 1 Is R reflexive, symmetric, and/or antisymmetric. Solution: Because all the diagonal elements of the matrix are equal to 1, R is reflexive. Moreover, because M R is symmetric, it follows that R is symmetric. It is also easy to see that R is not antisymmetric. The Boolean operations join and meet , can be used to find the matrices representing the union and intersection of two relations. Suppose that R1 and R2 are relations on a set A represented by the matrices M R and M R respectively. The matrix representing the 1 2 union of these relations has a 1 in the position where both M R and 1 M R2 have 1. Thus the matrices representing the union and 52 intersection of these relations are M R1 R2 M R1 M R2 and M R1 R2 M R1 M R2 Example (20): Suppose that the relations R1 and R2 on a set A are represented by the matrices: M R1 1 0 1 1 0 0 , 0 1 0 M R2 1 0 1 0 1 1 1 0 0 What are the matrices representing R1 R2 and R1 R2 Solution: The matrices of these relations are M R1 R2 M R1 M R2 1 0 1 1 1 1 1 1 0 M R1 R2 M R1 M R2 1 0 1 0 0 0 0 0 0 2.2.6 The matrix for the composite relations: Suppose that A, B and C sets have m, n, p elements, respectively let the zero – one matrices for SoR ( R is a relation from A to B and S is a relation from B to C ), R and S be M SoR t ij , M R rij and M S Sij resp, (these matrices have sizes m p , m n and n p and resp.). The ordered pairs ai , c j SOR if and only if there is an element bk such that ai , bk R and bk , c j S . It follows that t ij 1 iff rik s kj 1 for some k . From the definition of the Boolean product, this means that: M SoR M R • M S 53 Example (21): Find the matrix representing the relations SoR , where the matrices representing R and S are 1 0 1 M R 1 1 0 , 0 0 0 0 1 0 M S 0 0 1 1 0 1 Solution: The matrix for SoR is M SoR M R 1 1 1 • MS 0 1 1 0 0 0 The matrix representing the composite of two relations can be used to find the matrix for M R in particular n M Rn M Rn Example (22): Find the matrix representing the relation R 2 , where the matrix representing R is 0 1 0 M R 0 1 1 1 0 0 Solution: The matrix for R2 is 2 M R2 M R 0 1 1 1 1 1 0 1 0 2.2.7 Representing Relations Using diagraphs: Def. (6): A directed graph or diagraph consists of a set V of vertices (nodes) together with a set E of ordered pairs of elements of V called 54 edges (arcs). The vertex a is called the initial vertex of the edge a, b and the vertex b is called the terminal vertex of this edge. An edge of the form a, a is represented using an arc from the vertex, a back to itself. Such an edge is called a loop. Example (23): The directed graph with vertices a , b, c and d , and edges a, b , a, d , b, b , b, d , c, a , c, b , and d, b is displayed as in the figure: a b d Example (24): The directed graph of the relation c R (1,1), (1,3), (2,1), (2,3), (2,4), (3,1), (3,2), (4,1) on the set 1 shown in the figure: 2 3 4 Example (25): 1,2,3,4 is What are the ordered pairs in the relation R represented by the directed graph shown in the figure: 1 2 3 4 55 Solution : The ordered pairs x, y in the relation are: R (1,3), (1,4), (2,1), (2,2), (2,3), (3,1), (3,3), (4,1), (4,3) Each of these pairs corresponds to an edge of the directed graph with 2,2 and 3,3 corresponding to loops. The directed graph representing a relation can be used to determine whether the relation has various properties. A relation is reflexive if and only if there exist a loop at every vertex of the directed graph, so that every ordered pair of he form x, x occurs in the relation. A relation is symmetric if and only if for every edge between distinct vertices in its diagraph there is an edge to the opposite direction, so that y, x is in the relation whenever x, y is in the relation. Similarly a relation is antisymmetric if and only if there are edges in opposite direction between distinction vertices. A relation is transitive if and only if whenever there is an edge from a vertex x to a vertex y and an edge from a vertex y to a vertex z , there is an edge from x to z. Example (26): Determine whether the relations for the directed graph shown in the given figure are reflexive, symmetric, antisymmetric, and/or a transitive. a b c b d c R S 56 Solution : There are loops at every of the directed graph of R , it is reflexive, R is neither symmetric nor antisymmetric because there is an edge from a to b but not one from b to a , but there are edges in both directions connecting b and c . R is not transitive because there is an edge from a to b and an edge from b to c but no edge from a to c . The loops are not present at all the vertex of the directed graph of S , this relation is not reflexive. It is symmetric and not antisymmetric because every edge between distinct vertices is acompanied by an edge in the opposite direction. It is also S is not transitive because (c,a) ,(a,b)S but (c, b ) S . Exercises: Represent each of these relations on {𝟏, 𝟐, 𝟑} with (a) {(𝟏, 𝟏), (𝟏, 𝟐), (𝟏, 𝟑)} (b) {(𝟏, 𝟐), (𝟐, 𝟏), (𝟐, 𝟐), (𝟑, 𝟑)} (b) {(𝟏, 𝟏), (𝟏, 𝟐), (𝟏, 𝟑), (𝟐, 𝟐), (𝟐, 𝟑), (𝟑, 𝟑)} (c) {(𝟏, 𝟑), (𝟑, 𝟏)} 2) List the ordered pairs in the relations on {𝟏, 𝟐, 𝟑} corresponding to these matrices 𝟏 (a) [𝟎 𝟏 𝟎 𝟏 𝟏 𝟎] 𝟎 𝟏 𝟎 (b) [𝟎 𝟎 𝟏 𝟎 𝟏 𝟎] 𝟏 𝟎 (c) 𝟏 𝟏 [𝟏 𝟎 𝟏 𝟏 𝟏 𝟏] 𝟏 3) List the ordered pairs in the relations represented by the a directed graphs b (a) c (b) 57 (c) 4) Draw the directed graph that represents the relation {(𝒂, 𝒂), (𝒂, 𝒃), (𝒃, 𝒄), (𝒄, 𝒃), (𝒄, 𝒅), (𝒅, 𝒂), (𝒅, 𝒃)} 2.2.8 Equivalence Relations: Def. (7): A relation on a set A is called an equivalence relation if it is reflexive, symmetric and transitive. Equivalence relations are important throughout mathematics and computer science. One reason for this is that are equivalence relations, when two elements are related it makes sense to say they are equivalent. Def. (8): Two elements a and b that are related by an equivalence relation are called equivalent the notation a ~ b is often used to denote that a and b that are equivalent elements with respect to a particular equivalence relation. Example (27): Let R be a relation on the set of real numbers a Rb if and only if a b Z . Is R an equivalence relation? Solution: 1) R is reflexive since 2) R is 3) R is a R : a a 0 Z symmetric since a, b R : a b Z aRa a IR and b a Z aRb, bRa transitive let aRb and bRc a bZ b cZ . Therefore a c (a b) (b c) Z aRc Hence R is an equivalence relation. One of the most widely used equivalence relations is conqurence modulo m , where m Z m 1 . 58 Example (28): m 1. Let m be a positive integer Show that the relation R (a, b) a b(mod m) is an equivalence relation on Z Solution: 1) We have seen that a b mod m if and only if m divides a b . Note that a a 0 is divisible by m , because 0 0.m . Hence a a (mod m) R is reflexive. a b km where k Z . b a (mod m) . Then a b is divisible by m , so a b(mod m) . 2) Suppose that It follows that b a (k )m , so hence is symmetric. 3) Suppose that a b(mod m) and b c(mod m) . Then m divides a b and b c . Therefore, there are integers k and L with a b km and b c Lm . Adding these two equations a c (a b) (b c) km Lm (k L)m Hence a c(mod m) R is transitive form (1) , (2) and (3) R is an equivalence relation. Example (29): Show that the "divides" relation Rdiv of the set of positive integers is not an equivalence relation. Solution: By example (6) and example (12), we show that the " Rdiv" is reflexive and transitive and by example (10) Rdiv is not symmetric (for instance 2│4 but 4∤2. Hence " Rdiv" on Z is not an equivalence relation. 59 Example (30): Let R be the relation on the set of real numbers such that and only if x, y IR xRy if (real numbers) such that x y 1 . show that R is not an equivalence relation. Solution : 1) R is reflexive since x x 0 1 2) R is symmetric since, for if xRy, x, y IR x, y 1 , which tells us that y x x y 1 so yRx 3) R is not transitive. Take so that x 2.8, y 1.9 x y 2.8 1.9 0.9 1, and Z 1.1 , y z 1.9 1.1 0.8 1 but x z 2.8 1.1 1.7 1 . That is, 2.8R1.9, 1.9 R1.1 but 2.8R1.1 R is not an equivalence relation. 2.2.9 Equivalence Classes: Def. (9): Let R be an equivalence relation on a set A . The set of all elements that are related to an element a A is called the equivalence class of a . The equivalence class of a with respect to R is denoted by aR . When only one relation is under consideration, we can delete the subscript R and write a for this equivalence class. Example (31): What are the equivalence classes of 0 and 1 for congruence module 4? Solution: The equivalence class of 0 contains all integers a such that a 0(mod 4) . The integers in this class are those divisible by 4 0 ...,8,4,0,4,8,... 60 The equivalence class of 1 contains all the integers a such that a 1(mod 4) . The integers in this class are those that have a remainder of 1 when divided by 4. Hence 1 ...,7,3,1,5,9,... The equivalence classes of the relation congruence modulo are called the congruence classes modulo m. The congruence class of an am , so am ..., a 2m, a m, a, a m, a 2m,... integer a modulo m is denoted by For instance, it follows that : 04 ...,8,4,0,4,8,... and 14 ...,7,3,1,5,9,... Theorem(2) : Let R be an equivalence relation on a set A . These statements for elements (i) aRb a, b A are equivalent: (ii) a b (iii) a b Proof : 1) (i) implies (ii) Assume that aRb . We will prove that a b by showing a b and b a . Suppose c a . Then (bRa ) . aRc . Since aRb and R is symmetric Furthermore, since R is transitive and bRa and aRc , it follows that bRc . Hence c b a b, b a is left and exercise for the reader. 2) (ii) implies (iii). Assume that a b . It follows that a b because a a aR is reflexive. 3) (ii) implies (i): suppose that c b. ( aRc and bRc ). a b = Then c a and By the symmetric property, cRb . Then by transivity, aRc and cRb aRb . Because (i) implies 61 (ii), (ii) implies (iii), and (iii) implies (i), the three statements, (i), (ii) and (iii) are equivalent. The union of the equivalence classes of R is all of A (1) aA aR A (2) aR bR when aR bR These two observations show the equivalence classes from a partition of A , because they split A into disjoint subsets. More precisely, a partition of a set S is a collection of disjoint nonempty subsets of S that have S as their union. In other words, the collection of subsets Ai , i I (I is an index set) forms a partition of S if and only if. 1) Ai , i I 2) Ai A j , i j 3) iI Ai S The figure illustrates the concept of a partition of a set A2 A1 A4 A3 A5 A7 A6 A9 A8 Example (32): Suppose that S 1,2,3,4,5,6. The collection of the sets A1 1,2,3, A2 4,5 and 6 forms a partition of S because these sets are disjoint and their union is S . 62 Theorem (3) : Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S . Conversely, given a partition { Ai i I } of the set S , there is an equivalence relation R that has the sets Ai , i I , as its equivalence classes. Example (33): List the ordered pairs in the equivalence relation R produced by the partition A1 1,2,3, A2 4,5 and A3 6 of S 1,2,3,4,5,6 in example (32). Solution: The subsets in the partition are the equivalence classes of R . The pair ( a, b) R The pairs iff a and b are in the same subset of the partition. (1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,2) and (3,3) R because A1 1,2,3 is an equivalence class. The pairs (4,4), (4,5), (5,4) and (5,5) R , equivalence class. The pair (6,6) R , because A2 4,5 is an because 6 is an equivalence class. No pair other than those listed belong to R . Example (34): What are the sets in the partition of the integers arising from congruence modulo 4? Solution: There are four congruence classes, corresponding to 04 , 14 , 24 and 34 . They are the sets: 04 ...,8,4,0,4,8,... 63 14 ...,7,3,1,5,9,... 24 ...,6,2,2,6,10,... 34 ...,5,1,3,7,11,... These congruence classes are disjoint, and every integer is exactly one of them. In other words, as theorem (2) says, these congruence classes form a partition. Exercises : Which of these relations on {𝟎, 𝟏, 𝟐, 𝟑} are equivalence relations (a) {(𝟎, 𝟎), (𝟏, 𝟏), (𝟐, 𝟐), (𝟑, 𝟑)} (b) {(𝟎, 𝟎), (𝟎, 𝟐), (𝟐, 𝟎), (𝟐, 𝟐), (𝟐, 𝟑), (𝟑, 𝟐), (𝟑, 𝟑)} (c) {(𝟎, 𝟎), (𝟏, 𝟏), (𝟏, 𝟐), (𝟐, 𝟏), (𝟐, 𝟐), (𝟑, 𝟑)} 2) Determine whether the relations represented by these matrices are equivalence relations: 𝟏 (a) [𝟎 𝟏 𝟏 𝟏 𝟏 𝟏] 𝟏 𝟏 𝟏 (b) [𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟏 𝟏 𝟎 𝟏 𝟎 𝟎 𝟏] 𝟎 𝟏 𝟏 (c) [𝟏 𝟏 𝟎 𝟏 𝟏 𝟏 𝟎 3) Which of these collections of subsets are partions of {𝟎, 𝟏, 𝟐, 𝟑, 𝟒, 𝟓, 𝟔}? (a) {𝟏, 𝟐}, {𝟐, 𝟑, 𝟒}, {𝟒, 𝟓, 𝟔} (b) {𝟏}, {𝟐, 𝟑, 𝟔}, {𝟒}, {𝟓} (c) {𝟐, 𝟒, 𝟔}, {𝟏, 𝟑, 𝟓} 4) What is the congruence class [𝟒]𝒎 when m is (a) 2? (b) 3? (c) 6? 64 (d) -3? 𝟏 𝟏 𝟏 𝟎 𝟎 𝟎] 𝟎 𝟏 2.2.10 Partial ordering: Def. (1): A relation R on a set S is called partial ordering if it is reflexive, antisymmetric, and transitive. A set S together with a partial ordering R is called a partially ordered set, or poset, and is denoted by S, R . Members of S are called elements of the poset. Example (1): Show that the "greater than or equal" relation is a partial ordering on the set of integers. Solution: 1) Because a aa Z , hence "" is reflexive 2) If A b and b a , then a b , hence "" is antisymmetric. 3) "" is transitive since a b b c implies a c . Hence "" is a partial ordering on the set of integers ( Z , ) is a poset. Example (2):The divisibility relation | is a partial ordering relation on Z , because it is reflexive, antisymmetric and transitive ( 𝒁+ , | ) is a poset. Example (3): Show that the inclusion relation "" is a partial ordering on the power set of a set S . Solution 1) Since A A when ever, A S , " " is reflexive. 2) It is antisymmetric because A B B A imply that A B . 3) "" is transitive, because A B B C imply that A C . Hence "" is a partial ordering on P(S), (P(S),) is a poset. 65 Def. (2): The elements a and b of a poset ( S , ) are called comparable if either a b or b a . When a and b are elements of such that neither a b nor b a , a and b are called S incomparable. Example (4): In the poset (Z , ) are the integers 3 and 9 comparable? Are 5 and 7 comparable. Solution : 3 and 9 are comparable since 3|9 . The integers 5 and 7 are incomparable because 𝟓 ∤ 𝟕 and 𝟕 ∤ 𝟓 2.2.11 Hasse diagrams: The resulting diagram contains sufficient information to find the partial ordereing is called a Hasse diagram Example (5): Draw the Hasse diagram representing the partial ordering (a, b) a divides b on 1,2,3,4,6,8,12. Solution : Begin with the diagraph for the partial order as shown in the figure. 8 12 4 2 2)Remove all loops, as 6 shown in figure 1(b) 8 3 4 2 1 1 (a) 1 1(b) (b(a Then delete all the edges implied by the transitive property. ) 66 1 2 2 6 2 2 2 3 2 2 2 2 8 These are (1,4), (1,6) (1,8), 1 2 4 (1,12), (2,8), (2,12) and (3,12) Arrange all edges to point upward And delete all arrows to obtain the 6 2 3 Hasse diagram as shown in the figure (c) 1 Example (6): Draw the Hasse diagram for the partial ordering {(𝑨, 𝑩)|𝑨 𝑩} on the power set 𝑷(𝑺) where 𝑺 = {𝒂, 𝒃, 𝒄}. Solution: The Hasse diagram for this partial ordering is obtained from the associated diagraph by deleting all the loops and all the edges that occur from transitivity, namely (∅, {𝒂, 𝒃}), (∅, {𝒂, 𝒄}), (∅, {𝒃, 𝒄}), ({𝒄}, {𝒂, 𝒃, 𝒄}). (∅, {𝒂, 𝒃, 𝒄}), ({𝒂}, {𝒂, 𝒃, 𝒄}), ({𝒃}, {𝒂, 𝒃, 𝒄}), Finally all edges point upward, and arrows are deleted as shown in figure 2. Hasse diagram of (𝑷 {𝒂, 𝒃, 𝒄}, ) 67 2.2.12 Maximal and Minimal Elements: Def.(3): 1) An element of a poset is called maximal if it is not less than any element of the poset. 1) An element of a poset is called minimal if it is not greater than any element of the poset. Maximal and minimal elements are easy to spot using Hasse diagram. They are “top” and “bottom” in the diagram. Example (7): Which elements of the poset ({𝟐, 𝟒, 𝟓, 𝟏𝟎, 𝟏𝟐, 𝟐𝟎, 𝟐𝟓}, │) are maximal, and which are minimal? Solution: 20 12 For this poset shows that 10 the maximal elements 4 are 12, 20 and 25 and the minimal elements 25 5 2 are 2 and 5. 2.2.13 The greatest element and the least element: Def.(8):1) An element 𝒃 in the poset (𝑺, ≤) is called the greatest element of (𝑺, ≤) if 𝒃 ≤ 𝒂 ∀ 𝒂 ∈ 𝑺. The greatest element is unique. 2)An element 𝒂 in the poset (𝑺, ≤) is called the least element of (𝑺, ≤) if 𝒂 ≤ 𝒃 ∀ 𝒃 ∈ 𝑺. The least element is unique. 68 Example (8): Determine whether the posets represented by each of the Hasse diagram in the figure have greatest element and least element. b c d d e d d b c a a a (a) b (b) a b (c) (d) Solution: 1) The least element of the poset with Hasse diagram (a) is a. this poset has no greatest element. 2) The poset with Hasse diagram (b) has neither a least nor a greatest element. 3) The poset with Hasse diagram (c) has no least element. Its greatest element is d. 4) The poset with Hasse diagram (d) has least element a and greatest element d. Example (9): Let 𝑺 be a set. Determine whether there is a greatest element and a least element in the poset (𝑷(𝑺), .) Solution: The least element is the empty set, because ∅ T , ∀T∈S. The set 𝑺 is the greatest element in this poset, because 𝑻 𝑺 whenever 𝑻 is a subset of 𝑺. 69 Example (10): Is there a greatest element and least element in the poset (ℤ+ , │). Solution: The integer 1 is the least element because 1│𝒏, ∀ 𝒏 ∈ ℤ+ , there is no integer that divide all positive integers, there is no greatest element. Def.(4): 1) An element 𝒖 ∈ 𝑺 is called an upper bound of 𝑨 𝑺 if 𝒂 ≤ 𝒖 ∀𝒂 ∈ 𝑨. 2) An element 𝑳 ∈ 𝑺 is called a lower bound of 𝑨 if ∀𝒂 ∈ 𝑨 , 𝑳 ≤ 𝒂. Example (11): Find the lower and upper bounds of the subsets {𝒂, 𝒃, 𝒄}, {𝒋, 𝒉} and {𝒂, 𝒄, 𝒅, 𝒇} in the poset with the given Hasse diagram. Solution: j h 1) The g upper bounds {𝒂, 𝒃, 𝒄} are 𝒆, 𝒇, 𝒋 and f of and its only lower bound is 𝒂. d 2) There are no upper bounds e of b {𝒋, 𝒉}, and its lower pounds are 𝒂, 𝒃, 𝒄, 𝒅, 𝒆 and c 𝒇. a 3) The upper bounds {𝒂, 𝒄, 𝒅, 𝒇} are 𝒇, 𝒉 and 𝒋, and its lower bound is 𝒂. 70 of Def.(5): 1) The element 𝒙 is called the least upper bound of the subset 𝑨 if 𝒙 is an upper bound that is less than every other upper bound of 𝑨. 2) The element 𝒚 is called the greatest lower bound of 𝑨 if 𝒚 is the lower bound of 𝑨. Example (12): Find the greatest lower bound and the least upper bound of {𝒃, 𝒅, 𝒈}, if they exist in the poset shown in example (11). Solution: 1) The upper bounds of 𝒃, 𝒅, 𝒈 are 𝒈 and because 𝒈 < ℎ, 𝒈 is the least upper bound. 2) The lower bounds of {𝒃, 𝒅, 𝒅} are 𝒂, and 𝒃, because 𝒂 < 𝑏, 𝑏 is the greatest lower bound. Example (13): Find the greatest lower bound and the least upper bound of the sets {𝟑, 𝟗, 𝟏𝟐} and {𝟏, 𝟐, 𝟒, 𝟓, 𝟏𝟎} if they exist, in the poset (ℤ+ , │). Solution: 1) An integer is a lower bound of {𝟑, 𝟗, 𝟏𝟐} if 𝟑, 𝟗 and 𝟏𝟐 is divisible by this integer. The only such integers are 1 and 3. Since 1│3, 3 is the greatest lower bound of {𝟑, 𝟗, 𝟏𝟐}. 2) The only lower bound for the set {𝟏, 𝟐, 𝟒, 𝟓, 𝟏𝟎} with respect to │ is the element 1. Hence 1 is the greatest lower bound for {𝟏, 𝟐, 𝟒, 𝟓, 𝟏𝟎}. 71 3) An integer is an upper bound for {𝟑, 𝟗, 𝟏𝟐} iff it is divisible by 3, 9 and 12. The integers with this property are those divisible by LCm (3, 9, 12) which is 36. Hence 36 is the least upper bound of {𝟑, 𝟗, 𝟏𝟐}. 4) A positive integer is an upper bound for {𝟏, 𝟐, 𝟒, 𝟓, 𝟏𝟎} iff it is divisible by 1, 2, 4, 5 and 10. The integers with this property are those integers divisible by LCm (1, 2, 4, 5, 10) which is 20. Hence 20 is the least upper bound of {𝟏, 𝟐, 𝟒, 𝟓, 𝟏𝟎}. 2.2 .14 Lattices : Def.(6): A partially ordered set in which every pair of elements has both least upper bound and greatest lower bound is called a lattice. Example (14): Determine whether the posets represented by each of the Hasse diagrams in the figure are lattices. f f Solution: h e e c e d d b d d c b b a a (a) a (b) (c) 1) The posets represented by the Hasse diagrams in (a), (c) are both lattices because in each poset every pair of elements has 72 both a least upper bound and a greatest lower bound. (verify). 2) The poset with the Hasse diagram in (b) is not lattice, because the elements b and c have no least upper bound. Example (15): Is the poset (ℤ+ , │) a lattice? 𝒂, 𝒃 ∈ ℤ+ . the least upper bound and greatest Solution: Let lower bound of these two integers are the least common multiple and the greatest common divisor of these integers resp. (verify). Hence (ℤ+ , │) is a lattice . Example (16): Determine whether (𝑷(𝒙), ) is a lattice where 𝑺 is a set? Solution: Let 𝑨 and 𝑩 be two subsets of 𝑺. The least upper bound and the greatest lower bound of 𝑨 and 𝑩 are 𝑨𝑩 and 𝑨𝑩 respectively. Hence (𝑷(𝑺), ) is a lattice. Exercises: 1) Which of these are posets? (a) (ℤ, =) (b) (ℤ, ≠) (c) (ℤ, ≥) (d) (ℤ, ∤) 2) Which of these pairs of elements in these posets? (a) 𝑷({𝟎, 𝟏, 𝟐}, ) (b) ({𝟏, 𝟐, 𝟒, 𝟔, 𝟖}, │) 3) Draw the Hasse diagram for the “less than or equal to relation on {𝟎, 𝟐, 𝟓, 𝟏𝟎, 𝟏𝟏, 𝟏𝟓} 4) answer these questions for the poset ({𝟑, 𝟓, 𝟗, 𝟏𝟓, 𝟐𝟒, 𝟒𝟓}, │) (a) Find the maximal elements. (b) Find the minimal elements. (c) Is there a greater elements. 73 (d) Is there a least element? (e) Find all upper bounds of {𝟑, 𝟓} (f) Find the least upper pound of {𝟑, 𝟓}, if it exists (g) Find all lower bounds of {𝟏𝟓, 𝟒𝟓} (h) Find the greatest lower pound of {𝟏𝟓, 𝟒 𝟓}, if it exists 5) Determine whether the posets with these Hasse diagrams are lattices. g h f (a) (b) g f d e d e c b b c a 2.3 Functions: Def. (1): Let A and B be non empty sets, a function f from A to B is an assignment of exactly one element of B to each element of A . We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A . If f is a function from A to B , we write f :AB Remark : Functions are sometimes also called mappings or transformations b a B A A function f :AB f can also be defined in terms of a relation from A to B. A relation from A to B is just a subset of 74 A B . A relation from A to B that contains one and only one, ordered pair ( a, b), a A defines a function from A to B. f (a) b , where ( a, b) is the unique ordered pair in the relation that has a as its first element. Def. (2): If a function from A to B, we say that A is the domain of f. If f (a) b we say that b is the image of a and a is a preimage of b. The range of f is the set of all images of elements of A. also, if f is a function from A to B, we say that f maps A to B. Two functions are equal when they have the same domain, have the same codomain, and map elements of their common domain to the same elements in their common codomain. Example(1): What are the domain, codomain and range of the function that assigns grades to students shown in the figure Ahmed A Ali B Fahad C Omer D Osman F Solution: Let g be the function that assigns a grade to a student 1) The domain f of g is {Ahmed, Ali, Fahad, Omer, Osman} 2) The codomain of g is {A, B, C, D, F} 3) The range of g is {A, B, C, F} Example(2): Let f be the function that assigns the last two bits of length 2 or greater to that string e.g. f(11010) = 10. Then, the domain of f is the 75 set of all bit strings of length 2 or greater, and both the codomain and range are the set {00, 01, 10, 11}. Example(3): Let, f: Z→ Z assigns the square of an integer to this integer. Then f ( x) x 2 the domain of f is the set of all integers ,the codomain of f to be the set of all integers and the range of f is the set of all integers that are perfect squares namely 0,1,4, ,9, . Example(4): The domain and codomain of functions are often specified in programming languages. For instance, the Java statement in t floor (float real) ( …..) and the pascal statement function floor (x : real): integer both state that the domain of the floor function is the set of real numbers and its codomain is the set of integers. Def.(3): Let f1 + f2 be functions from A to IR then f1 + f2 and f1f2 are also functions from A to IR defined by (1) f1 f 2 x f1 x f 2 x (2) f1 f 2 x f1 x f 2 x Example(5): Let f1 and f2 be functions from IR to IR such that f1 x x 2 , f 2 x x x 2 what are the functions (1) f1 f 2 (2) f1 f 2 Solution: (1) f1 f 2 x f1 x f 2 x x 2 x x 2 x (2) f1. f 2 x f1 x . f 2 x x 2 .x x 2 x3 x 4 Def.(4): Let f be a function from the set A to the set B and let S be a subset of A . the image of S under the function f is the subset of 76 B that contains of the images of the elements of S we denote the image of S by f S f S t s S t f (s) f (s) s S Example(6): Let A a, b, c, d , e and B 1,2,3,4 with , f (d ) 1 and f (e) 1 . f (a) 2 , f (b) 1 , f (c ) 4 The image of the subset S={b,c,e} is the set f (S ) 1,4. 2.3.1 One-to-One and Onto functions: Some functions never assign the same value to two different domain elements. These functions are said to be one-to-one Def.(5): A function f is said to be one-to-one or injective, if and only if f (a) b implies that a b for all a and b D f . A function is said to be injection if it is one-to-one. Note that a function f is one- to-one if and only if 𝑓(𝑎) ≠ 𝑓(𝑏) whenever 𝑎 ≠ 𝑏. Remark: We can express that f is one-to-one using quantifiers as ab f (a) f (b) a b or equivalently ∀𝑎, ∀𝑏 𝑎 ≠ 𝑏 → 𝑓(𝑎) ≠ 𝑓(𝑏) where the universe of discourse is the domain of the function. Example(7): Determine whether the function with f (a) 4 , f (b) 5 , f (c) 1 and 77 f from a, b, c, d to 1,2,3,4,5 f (d ) 3 is one-to-one. Solution: The function is one-to-one because f f takes on different values at the four elements of the domain as shown in the figure .1 a . b. .2 .3 .4 .5 c. d. Example(8): Determine whether the function f ( x) x 1 from IR to IR is one- to-one function. Solution: f ( x) x 1 The function is a One-to-One function , note that x+1 ≠ y +1 when x≠y. Def.(6): A function f whose domain and codomain are subsets of the set of real numbers is called increasing if increasing if domain of f f ( x) f ( y ) . Similarly whenever f stricktly decreasing if f ( x) f ( y ) f ( x) f ( y ) and stricktly x y and x and y are in the is called decreasing if f ( x) f ( y ) and f ( x) f ( y ) and stricktly decreasing if where x y and x and y are in the domain of f . Def.(7): A function from A to B is called onto or surjective if and only if b B a A with f (a) b . A function onto. 78 is called surjective if it is Example(9) : Let , be the function from a, b, c, d to 1,2,3 defined by f f (b) 2 , f (c) 1 and f (d ) 3 f (a) 3 is onto function a . . 1 b . . 2 c . . 3 d . An onto function Example(10): Is the function f ( x) x 2 from the set of integers to the set of integers onto? Solution: The function f is not onto because there is no an integer x with 𝑥 2 = −1 for instance. Example (11): Is the function 𝑓(𝑥) = 𝑥 + 1 from the set of integers to the set of integers onto? Solution: This function is onto, because this, note that f ( x) y if and only if y Z x Z x 1 y , f ( x) y . To see which holds if and only if x=y - 1. Def.(8): The function is a one-to-one correspondence or bijective, if it is both one-to-one and onto. Example(12): Let f (b) 2 , f be the function from a, b, c, d to 1,2,3,4 with f (c ) 1 and f (d ) 3 is f 79 a bijection? f (a) 4 , Solution: The function is one-to-one and onto. It is one-to-one because no two values in the domain are assigned the same function value. It is onto because all the four elements of the codomain are integers of elements in the domain. Hence f is a bijection. Example(13): Let A be a set. The identity function on A is the function I A : A A where I A ( x) x the function I A is bijection function. 2.3.2 Inverse functions and compositions of functions: Def.(9): let B. be a one-to-one correspondence from the set A to the set f The inverse function of the unique element a A is the function assigns to an element f (a) b . denoted by f 1 (b) a when The inverse function of f is f (a) b . Example(14): Let and be the function from a, b, c to 1,2,3 f f (c ) 1 is f f (a ) 2 , f (b) 3 invertable, and if it is what is its inverse. Solution: The function correspondence. f The is invertable because it is one-to-one inverse f 1 function correspondence given by so f 1 (1) c , f 1 (2) a and reverses the f 1 (3) b . Example(15) : Let f : R R be such that it is what is its inverse? 80 f ( x) x 1 . Is f invertable, and if Solution: The function f has an inverse because it is a one-to-one correspondence, as we have shown in example (10) it is invertible. To find its inverse let y x 1 x y 1 f ( y) y 1 Def.(10).: Let g be a function from the set A to the set B and let f be a function from the set B to the set C . The composition of the function and denoted by ( fog )( a) f ( g (a )) is defined by . Example(16): Let g be the function from the set a, b, c to itself g (b) c and set 1,2,3 f g (c ) a let f g (a) b , be the function from the set a, b, c to the f ( a) 3 , f (b) 2 and f (c ) 1 what is the composition of and g , and what is the composition of g and f ? Solution: The composition is denoted by ( fog )( a) f ( g (a)) = f (b) 2 , ( fog )(b) f ( g (b)) f (c) 1 and ( fog )(c) f ( g (c)) f (a) 3 . Example(17): Let f,g be the functions from Z to Z defined by and g(x)=3x+2 what is the composition of composition of g and f f f ( x) 2 x 3 and g and what is the ? Solution: (1) (𝑓°𝑔)(𝑥) = 𝑓(𝑔(𝑥)) = 𝑓(3𝑥 + 2) = 2(3𝑥 + 2) = 6𝑥 + 4 (2) ( gof )( x) g ( f ( x)) g (2 x 3) 3(2 x 3) 2 6 x 11 81 Remark: Note that fog gof if f 1 f (a) f 1 ( f (a)) f 1 (b) a if f (a ) b and fof 1 (b) f f 1 (b) f (a) b 2.3.3 Some important functions: Def.(11): The floor function assigns to the real number x the largest integer that is less than or equal to x and is defined by x . The ceiling function assigns to the real number x the smallest integer that is greater than or equal to x . The value of the ceiling function at x is denoted by ⌈𝒙⌉ 3 o 3 o 2 1 1 -3 -2 -1 -1 o o 2 1o o -3 -2 -1 3 o o -2 o o 2 o -3 1 2 3 -1 -2 -3 The graph of a floor function The graph of the ceiling function. 82 Example(18) : There are some values of the floor and ceiling functions 1 2 0 , 1 1 1 2 1 , 2 1 , 2 0 , 3.1 3 , 3.1 4 , 7 7 Example(19) : Data stored on a computer disk or transmitted over a data network are usually represented as a string of bytes. Each byte is made up of 8 bits. How many bytes are required to encode 100 bits of data? Solution: To determine the number of bytes needed, we determine the smallest integer that is at least as large as the quotient when 100 is divided by 8, the number of bits is a byte. 100 8 12.5 13 bytes are required. Consequently, Exercises : 1) Why is 𝒇 not a function from ℝ 𝒕𝒐ℝ if : a) 𝒇(𝒙) = 𝟏 𝒙 ? ( b) 𝒇(𝒙) = √𝒙 ? (c) 𝒇(𝒙) = ±√𝒙𝟐 + 𝟏 2)Determine whether each of these functions from Z to Z is one- to-one 𝒏 a) 𝒇(𝒏) = 𝒏 − 𝟏 (b) 𝒇(𝒏) = 𝒏𝟐 + 𝟏 (c) 𝒇(𝒏) = 𝒏𝟑 (d) 𝒇(𝒏) = ⌈ ⌉ 𝟐 3) Find these values : 𝒂)⌊𝟏. 𝟏⌋ 𝟑 (e) ⌈ ⌉ 𝟒 (b) ⌈𝟏. 𝟏⌉ ( c) ⌊−𝟎. 𝟏⌋ (d) ⌈−𝟎. 𝟏⌉ 𝟕 (f) ⌊ ⌋ 𝟖 (g) ⌈𝟑⌉ (h) ⌊−𝟏⌋ 4) Find 𝒇°𝒈 where𝒇(𝒙) = 𝒙𝟐 + 𝟏 and 𝒈(𝒙) = 𝒙 + 𝟐, are functions from R to R. 83 5) Find 𝒇 + 𝒈 and 𝒇. 𝒈 for the functions 𝒇 𝒂𝒏𝒅 𝒈 given in Exercise (4). 6) Let 𝒇 be the function from R to R denoted by𝒇(𝒙) = 𝒙𝟐 .Find : a) 𝒇−𝟏 ({𝟏}) (b) 𝒇−𝟏 ({𝒙|𝟎 < 𝑥 < 1}) 84 Chapter 3 Algorithms, the integers and matrices 3.1 Algorithms: Def.(1): An algorithm is a finite set of precise instructions for performing a computation or for solving a problem. Example(1): Describe an algorithm for finding the maximum (largest) value in a finite sequence of integers. Solution: We perform the following steps : 1- Set the temporary maximum equal to the first integer in the sequence. 2- Compare the next integer in the sequence to the temporary maximum, and if it is larger than temporary maximum, set the temporary maximum equal to this integer. 3- Repeat the previous step if there are more integers in the sequence. 4- Stop when there are no integers left in the sequence. The temporary maximum at this point is the largest integer in the sequence. Algorithm (1): Finding the maximum element in a finite sequence. Procedure max ( a1 , a2 , , an : integers) max : = a1 for i: = 2 to n if max < ai then max : = ai {max is the largest element} 85 There are several properties that algorithms generally share. They are useful to keep in mind when algorithms are describes these properties are: Input. An algorithms has input values from a specified set. Output. From each set of input values an algorithm produces output values from a specified set. The output values are the solution to the problem. Definiteness. The steps of an algorithm must be defined precisely. Correctness. An algorithm should produce the correct output values for each set input values. Finiteness. An algorithm should produce the described output after a finite (but perhaps large) number of steps for any input in the set. Effectiveness. It must be possible to perform each step of an algorithm exactly and into a finite amount of time. Generality. The procedure should be applicable for all problems of the desired farm, not just for a particular set of input values. 86 3.2 The Number Theory 3.2.1 The integers and division: Def. (2): if a and b are integers with a 0 , we say a that divides b if there is an integer c (such that b ac when a divides b we say that a is a factor of b and that b is a multiple of a . The notation a b denoted that a divides b . We write 𝒂∤𝒃 when a doesnot divide b . Example(2): Determine whether 3 7 and 312 . Solution: because 7 3 is not an integer 1) 𝟑∤𝟕 2) 312 because 12 3 4 . Example(3) : Let n and d be positive integers. Howmany positive integers not exceeding n are divisible by d ? Solution: The positive integers divisible by d are all integers of the form dk , where k is a positive integer. Hence, the number of positive integers divisible by d that donot exceed n equals the number of integers k with 0 dk n or with 0 k n d . Therefore, there are positive integer not exceeding n that are divisible by d . Theorem (1): Let a, b , and c be integers. Then 1- if a b and a c , then a (b c) 2- if a b , then a bc for all integers c . 3- if a b and b c , then a c . 87 Proof: Using direct proof of (1) suppose that a b and a c . Then, from the definition of divisibility, it follows that there are integers s and t with b = as and c = st hence b c as at a( s t ) Therefore, a divides b c . The proof of (2) and (3) are left as exercise for the reader. Corollary(1): If a, b and c are integers such that a b and a c , then a mb nc whenever m and n are integers. Proof: We will give a direct proof. By part (2) of theorem (1) it follows that a mc and a nc whenever m and n are integers. By part (1) of theorem (1) it follows that a mb nc . 3 .2.2 The division algorithm: Theorem (2): The division algorithm let a be an integer and d a positive integer. Then there are unique integers q and r with 0 r d such that a dq r . Def.(3): In the equality in the division algorithm, d is called the divisor, a is called the divided, q is called the quotient, and r is called the remainder. This notation is used to express the quotient and remainder. q a div d, r a mod d Example (4): What are the quotient and remainder when 101 is divisible by 11? Solution: We have 101 = 11*9 + 2 9 = 101 div 11 2 101 mod 11 88 Example (5): What are the quotient and remainder when -11 is divisible by 3. Solution: -11 = 3(-4) + 1 q = - 4 and r = 1 - 4 = - 11 div 3 1 -11 mod 3 3.3 Modular Arithmetic: Def.(4): If a and b are integers and m is a positive integer, then a is congruent to b modulo m if m divides a b . we use the notation a b mod m to indicate that a is congruent to b modulo m . If a and b are not congruent modulo m , we write a b mod m . Theorem( 3): Let a and b be integers, and let m be a positive integer. then mod if and only if a mod = b mod . Example (6): Determine whether 17 is congruent to 5 modulo 6 and whether 24 and 14 are not congruent modulo 6. Solution: Since 6 divides 17-5 = 12, we say that 17 ≡ 5 mod 6. Since 24 – 14 = 10 is not divisible by 6 24 ≢ 14 mod 6. Theorem (4): Let m be a positive integer. The integers a and b are congruent modulo m iff there is an integer k such that a b km . Theorem (5): Let m be a positive integer if a b mod and c d (mod m ), then a c b d (mod m ) and ac bd (mod m ). 89 Proof; Since a b (mod m ) and c d (mod m ) s, t with b a sm and d c tm . Hence b d a sm c tm a c ms t . and bd a smc tm ac mat cs stm . Hence a c b d (mod m ) and ac bd (mod m ). Example(7) : Since 7 ≡ 2 mod 5 and 11 ≡ 1 mod 5 hence 18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5) and 77 = 7*11 , 2.1 ≡ 2 (mod 5) Corollary (2); Let m be a positive integer and let a and b be integers. Then a b mod m = (( a mod m ) + ( b mod m )) and ab mod m = (( a mod m ) ( b mod m )) mod m . Proof: By the definition mod m and the definition of congruence modulo m , we know that a b ( a mod m ) (mod m ) and b ( b mod m ) (mod m ) Hence, from theorem (5) tells us that a b ( a mod m ) + ( b mod m ) (mod m ) and ab ( a mod m ) ( b mod m ) (mod m ) 3.4 Primes and greater common divisor primes: Def.(4): A positive integer p greater than 1 is called prime if the only positive factors of p are 1 and p . A positive integer that is greater than 1 and is not prime is called composite. 90 Example(8): The integer 7 is prime since its only positive factors are 1 and 7, where the integer 9 is composite because it is divisible by 3. The primes less than 100 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 , and 97. Theorem (6): ( The fundamental theorem of arithmetic) Every positive integer greater than 1 can be written uniquely in a prime or as the product of two or more primes where the prime factors are written in order of non decreasing size. Example(9): Give the prime factorizations of 100, 64, 999 and 1024 Solution: 1. 100 = 2.2.5.5 = 22.52 2. 641 = 641 3. 999 = 3.3.3.37 = 33.37 4. 1024 = 2.2.2.2.2.2.2.2.2.2 = 210 Theorem (7): If n is a composite integer, then has a prime less than or equal to n. Example(10): Show that 101 is prime Solution: The only are exceeding 101 are 2, 3, 5 and 7. Because 101 is not divisible by 2, 3, 5 and 7 it follows that 101 is prime. 3.5 Greatest common divisor and least common multiple: Def.(5): Let a and b be integers, not both zero. The largest integer such that d a and d b is called the greatest common divisor of a and b and is denoted by gcd( a, b) . 91 Example(11) : What is the greatest common divisor of 24 and 36? Solution: The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6 and 12, Hence gcd (24, 36) = 12. Example(12) : What is the greatest common divisor of 17 and 22? Solution: The integers 17 and 22 have no positive common divisors other than 1, so that gcd (17, 22) = 1. Def.(6): The integers a and b are relatively prime of their greatest common divisor is 1. gcd (17, 22) = 1 Example(12): Determine whether the integers 10, 17 and 21 are pairwise relatively prime and whether the integers 10, 19 and 24 are pairwise relatively prime? Solution: gcd (10, 17) = 1, gcd (17, 21) = 1 (10, 21) = 1, hence 10, 17 and 21 are pairwise relatively prime. Example (13): 1)gcd(300,18)= gcd(12,18)= gcd(12,6)=6 2)gcd(101,100)=gcd(1,100)=1 3)gcd(89,55)=gcd(34,55)= gcd(34,21)=gcd(13,21)=gcd(13,8) =gcd(5,8 )=gcd(5,3)=gcd(2,3)=gcd(2,1)=1 You can check in each case (using a prime factorization of the numbers ). 92 Example(14): The prime factorization of 120 and 500 are 120 = 23 . 3 . 5 and 500 = 22. 53. the gcd (120, 500) = 2 min( 3, 2). 3min(1,0). 5min(1,3) = 22.30.51 = 20 Def.(7): The least common multiple of the positive integers a and b is the smallest positive integer that is divisible by both a and b . The least common multiple of a and b denoted by max a1 , b1 . P2max a 2 , b2 .... Pnmax a n , bn Lcm( a, b) P1 Example(15): Find Lcm (23.35.72, 24.33) = 2max(3,4).3max(5,3).7max(0,2) = 24.35.72 Theorem(8) : Let a and b be positive integers. Then ab gcd( a, b). Lcm(a, b) Exercises: 1) Does 17 divides each of these numbers : a) 68 (b) 84 (c) 357 (d) 1001 2) Show that if a is an integer other than 0 , then : a) 1 divides a (b) a divides 0 3) What are the quotient and remainder when : a) 19 is divisible by 7? b) -111 is divisible by 11 ? c) 789 is divisible by 23 ? d) 1001 is divisible by 13 ? 4) Evaluate these quantities: a) – 17mod 2 (b) 144mod 7 (c) -101mod13 (d) 199mod19 5) List five integers that are congruent to 4modulo12 6) Decide whether which each of these integers is congruent to 5 modulo17 : 93 a) 80 (b)103 (c)-29 (d) -122 7) Determine whether each of these integers is prime : a) 21 (b) 29 (c) 71 (d) 97 (e) 111 (f) 143 (g) 113 (h) 107. 8) Determine whether the integers in each of these sets are pairwise relatively prime : a) 21 , 34 , 55 (b) 14 , 17 ,85 (c) 25 ,41,49 ,64 (d) 17 ,18 ,19 ,23. 9) Find gcd(1000,625) and lcm(1000,625) and verify that gcd(1000,625).lcm(1000,625)= 1000.625. 10) What are the greatest common divisors of these pairs of integers: a) 𝟑𝟕 . 𝟓𝟑 . 𝟕𝟑 , 𝟐𝟏𝟏 . 𝟑𝟓 . 𝟓𝟗 b) 2.3.5.7.11.13, 𝟐𝟏𝟏 . 𝟑𝟗 . 𝟏𝟏. 𝟏𝟕𝟏𝟒 c) 17, 𝟏𝟕𝟏𝟕 d) 𝟐𝟐 . 𝟕, 𝟓𝟑 . 𝟏𝟑 3.6 Integers and algorithms: 3.6.1 Representation of integers: In every day life we used decimal notation to express integers. For example, 965 is used to denote 9.102 + 6.10 + 5. However, it is often convenient to use bases other than 10. In particular computers usually use binary notation (with 2 as a base) when carrying out arithmetic, and octal (base 8) or hexadecimal (base 16). Theorem(9) : Let b be a positive integer greater than 1. Then if n is positive integer, it can be expressed uniquely in the form n ak b k ak 1b k 1 a1b a0 94 Example(16): What is the decimal expansion of the integer that has (1 0101 111)2 as its binary expansion? Solution: (1 0101 111)2 = 1.28 + 0.27 + 1.26 + 0.25 + 1.24 + 1.23 +1.22 + 1.21 + 1.20 = 351 Usually, the hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C , D, E and F , where the letters A through F represent the digits corresponding to the numbers 10 through 15 (in decimal notation). Example(17): What is the decimal expansion of the hexadecimal expansion 2AEOB 16 Solution: We have 2AEOB 16 = 2.164 + 10.163 + 14. 162 + 0.161 + 11 = (175627)10 3.6.2 Base conversion: We will now describe an algorithm for constructing the base expansion of an integer n . First, divide n by b to obtain a quotient and remainder, that is to obtain q0 bq1 a1 0 a1 b We see that a1 is the second digit from the right in the base b expansion of n . Continue this process, successively dividing the quotient by b , obtaining additional base b digits as the remainders. This process terminates when we obtain a quotient equal to zero. Example(18) : Find the base 8, or octal, expansion of (12345)10 95 Solution: First, divide 12345 by 8 to obtain 12345 = 8.1543 + 1 1543 = 8.192 + 7 192 = 8.24 + 0 24 = 8.3 + 0 3 = 8.0 + 3 (12345)10 = (30071)8 Example(19) : Find the hexadecimal expansion of (177130)10 Solution: 177130 = 16.11070 + 10 11070 = 16.691 + 14 691 = 16.43 + 3 43 = 16.2 + 11 2 = 16.0 + 2 (177130)10 = 2 B3EA16 Example(20): Find the binary expansion of (241)10 Solution: 241 = 2.120 + 1 120 = 2.60 + 0 60 = 2.30 + 0 30 = 2.15 + 0 15 = 2.7 + 1 7 = 2.3 + 1 3 = 2.1 + 1 1 = 2.0 +1 (241)10 = (111 1001)2 Example(21): Find the binary form of the non negative integers up to 10 ? 96 Solution: 0 = (0)2 1 = (1)2 2 = (10)2 3 = 2+ 1 = (11)2 2 = 3 + 1 = (100)2 3 = 4+ 1 = (101)2 4 = 4+2+1 = (110)2 5 = 4 + 2 + 1 =(111)2 6 = 7+1 = (1000)2 7 = 8 + 1 = (1001)2 8 = 8 + 2 = (1010)2 Example(22) : Find the hexadecimal expansion of (11 1110 1011 11 00)2 and binary expansion of A8D 16 Solution: To convert (11 1110 1011 1100)2 into hexadecimal notation we group the binary digits into blocks of four adding initial zeros at the start of the leftmost block if necessary. These blocks are 0011, 1110, 1011 and 1100 which correspond to the hexadecimal digits 3, E, B and C respectively consequently (11 110 1011 1100)2 = (3EBC ) Algorithm(1): constructing base expansion ( n : positive integer) q : n k : 0 While q0 Begin ak : q mod b 97 expansion procedure base q : Lq / b k : k 1 end {the base b expansion of n is ak 1 a1a0 b } Hexadecimal octal and binary representation of the integers 0 -15 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 3.6.3 Algorithms for integers operations: The algorithms for performing operations with integers using their binary expansions are extremely important in computer arithmetic. We will describe algorithms for the additional and multiplication of two integers expressed in binary notation. We will also analyze the computational complexity of these algorithms, in terms of the actual number of bit operations used. Throughout this discussion, suppose that the binary expansion of a and b are a an1an2 a1a0 2 , b bn1bn2 b1b0 2 So that a and b each have bits (putting bits equal to 0 at the beginning of one of these expansions if necessary). To add a and b , first add their right most bits a0 b0 c0 .2 s0 Where s0 is the rightmost bit in the binary expansion of a b and c0 is the carry, which is either 0 or 1 . Then a1 b1 c0 c1.2 s1 Where s1 , is the next bit (from the right in the binary expansion of a b and c1 is the carry. Continue this process, adding the corresponding bits in the two binary expansions and the carry to determine the next bit from the right in the binary expansion of a b . 98 At the last stage, add an1 , bn1 and cn2 to obtain cn1.2 sn1 . The leading bit of the sum is sn cn1 . This procedure produces the binary expansion of the sum, namely, a b sn sn1 s1s0 Example(23) : Add a 111012 and b 111012 Solution : a0 b0 0 1 0.2 1 So that c0 0 and s0 1 a1 b1 c1 1 1 0 1.2 0 c1 1 and s1 0 a2 b2 c2 1 1 1 1.2 0 c2 1 and s2 0 a3 b3 c3 1 1 1 1.2 1 it follow that c3 1 and s3 1 s4 c3 1 s a b 110012 111 1110 1011 11001 Algorithm (2) Addition of integers: Procedure add ( a,b : positive integers) { the binary expansions of a and b are an 1an 2 a1a0 2 and bn 1bn 2 b1b0 2 respectively} c : 0 for j : 0 to n 1 begin 99 d : La j b j c / 2 s j : a j b j c 2d c : d end sn : c {the binary expansion of the sum is sn sn 1 s0 2 } Multiplication of two n -bit integers a and b The conventional algorithm (used when multiplying with pencil and paper) works as follows: ab 2 ab 2 ab 2 ab a b0 20 b1 21 bn 1 2n 1 0 0 1 1 n 1 n 1 Algorithm (3) Multiplying integers: Procedure multiply ( a,b : positive integers) {the binary expansions of a and b are an 1an 2 a1a0 2 and bn 1bn 2 b1b0 2 , respectively} for j : 0 to n 1 begin if b j 1 then c j : a shifted j places else c j 0 end { c0 , c1, , cn 1 and partial products} p : 0 for j : 0 to n 1 p : p c j { p is the value of ab } Example (24): Find the product of a 1102 and b 1012 100 Solution ; ab0 .20 1102 .1.20 1102 ab1.21 1102 .0.21 00002 ab2 .2 2 110 2 .1.2 2 11000 2 To find the product add 110 2 and 11000 2 ab 1.11102 3.6.4 The Euclidean Algorithm: The method described in section 3.5 for computing the greatest common divisor of two integers , using the prime factorization of these integers is inefficient. We will give a more efficient method of finding the greatest common divisor ,called the Euclidean algorithm . Before describing the Euclidean algorithm , we will show how it is used to find gcd(91,287). First ,divide 287 by 91 (the larger of the two integers by the smaller) to obtain 287 = 91*3+14 Any divisor of 91 and 287 must also be a divisor of 287- 91*3 = 14. Also,any divisor of 91 and 14 must also be a divisor of 287 = 91*3 + 14. Hence , the greatest common divisor of 91 and 287 is the same as the greatest common divisor of 91 and 14 . This means that the problem of finding gcd(91 ,287) has been reduced to the problem of finding gcd(91,14). Next ,divide 91 by 14 to obtain 91 = 14*6 + 7 Because any common divisor of 91 – 14*6 = 7 and any common divisor of 14 and 7 divides 91 , it follows that gcd(91,14) = gcd(14,7) Continuing by dividing 14 by 7, to obtain 14 = 7*2 Because 7 divides 14 ,it follows that gcd(14,7 ) = 7 101 Hence gcd(287,91) = gcd(91,14) = gcd(14,7) = 7 Lemma: Let a = bq +r , where a ,b and r are integers . Then gcd(a,b) = gcd(b,r). Example (25): Find gcd(414,662) using the Euclidean algorithm. Solution: 662 = 414*1+ 248 414 = 248*1 + 166 248 = 166*1 + 82 166 = 82*2 + 2 82 = 2*41 Hence , gcd(414,662) = 2 Algorithm (4) The Eculidean Algorithm: Procedure gcd(a,b: positive integers ) x :=a y :=b while y ≠ 0 begin r := x mod y x := y y := r end {gcd(a,b) is x } Exercises: 1) Convert these integers from decimal notation to binary notation : a) 231 (b) 4532 (c) 97644 (d) 321 102 (e) 1023 (f) 100632 2) Convert these integers from binary notation to decimal notation : a) 1 1111 (b) 10 0000 0001 (c) 1 0 101 0101 d) 110 1001 0001 (e) 1 1011 (f) 10 1011 0101 3) Convert these integers from hexadecimal notation to binary notation : a) 80E (b) 135AB (c) ABBA (d) DEFACED 4) Convert (𝑩𝑨𝑫𝑭𝑨𝑪𝑬𝑫)𝟏𝟔 from its hexadecimal expansion to its binary expansion . 5) Convert these integers from binary notation to its hexadecimal notation : a) 1111 0111 b) 1010 1010 1010 c) 111 0111 0111 0111 6)Convert (a) (𝟏𝟎𝟏𝟏 𝟎𝟏𝟏𝟏 𝟏𝟎𝟏𝟏)𝟐 (b) (𝟏 𝟏𝟎𝟎𝟎 𝟎𝟏𝟏𝟎 𝟎𝟎𝟏𝟏)𝟐 to their hexadecimal expansions. 7) Convert (𝟕𝟑𝟒𝟓𝟑𝟐𝟏)𝟖 to its binary expansion and (𝟏𝟎 𝟏𝟎𝟏𝟏 𝟏𝟎𝟏𝟏)𝟐 to its octal expansion . 8) Convert (𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟎)𝟖 to its hexadecimal expansion and (𝑨𝑩𝑩𝟎𝟗𝟑𝑩𝑨𝑩𝑩𝑨)𝟏𝟔 to its octal expansion . 9) Use the Euclidean algorithm to find : (a) gcd(12,18) (b) gcd(111,201) 103 (c) gcd(1001,1331) ( d) gcd(12345,54321) (e) gcd(1000,5040) (f) gcd(9888,6060) 104 Chapter 4 Boolean Algebra 4.1.1 Boolean Functions: Introduction : Boolean algebra provides the operations and the rules for working with the set (0, 1). Electronic and optical switches can be studied using this set and the rules of Boolean algebra. The three operations in Boolean algebra that will use most are complementation, the Boolean sum, and the Boolean product. The complement of an element, denoted with a bar, is defined by ō = 1 and I = 0. The Boolean sum, denoted by + or by OR, has the following values: 1+1 = 1, 0+0=0 , 0+1=1+0 =1 1.1= 1, 1.0 = 0 = 0.1 = 0, 0.0 = 0 , Example (1): ̅̅̅̅̅̅̅ Find the value of 𝟏. 𝟎 + (𝟎 + 𝟏) Solution: Using the definitions of complementation, the Boolean sum, and the Boolean product, it follows that : ̅̅̅̅̅̅̅ ̅ =𝟎+𝟎= 𝟎 𝟏. 𝟎 + (𝟎 + 𝟏) = 𝟎 + 𝟏 The complement, Boolean sum, and Boolean product correspond to the logical operators, , and respectively where 0 corresponds to F (false) and 1 corresponds to T (true) Equalities in Boolean algebra can be directly translated into equivalences of compound propositions can be translated into equalities in Boolean algebra. 105 Example (2): Translate ̅̅̅̅̅̅̅ 𝟏. 𝟎 + (𝟎 + 𝟏) = 𝟎, into a logical equivalence. Solution: We obtain a logical equivalence when we translate each 1 into a T, each 0 into a F, each Boolean sum into disjunction, each Boolean product into a conjunction and each complementation into negation, we obtain ̅̅̅̅̅̅̅ 𝟏. 𝟎 + (𝟎 + 𝟏) = 𝟎 𝑻 𝑭 (𝑻 𝑭) 𝑭 Example (3): Translate the logical equivalence (𝑻 𝑻) F T into an identity in Boolean algebra. Solution: (𝑻 𝑻) F (1.1) + ō = 1 4.1.2 Boolean Expressions and Boolean Functions: Def.(1): Let B = (0,1). Then is the set of all possible n-tuples of 0s and 1s. The variable x is called a Boolean variable if it assumes values only from B, that is, if its only possible values are 0 and 1. A function from to is called a Boolean function of degree 𝒏. 𝒇: 𝑩𝟐 → 𝑩 ̅ from the set of ordered Example (4): The function 𝒇(𝒙, 𝒚) = 𝒙𝒚 pairs of Boolean variables to the set {𝟎, 𝟏} is a Boolean function of degree 2 ,𝒇(𝟏, 𝟏) = 𝟏. 𝑻 = 𝟏. 𝟎 = 𝟎, ̅ = 𝟏. 𝟏 = 𝟏 𝒇(𝟏, 𝟎) = 𝟏. 𝒐 ̅ = 𝟎. 𝟏 = 𝟎 𝒇(𝟎, 𝟏) = 𝟎. 𝑻 = 𝟎. 𝟎 = 𝟎 and 𝒇(𝟎, 𝟎) = 𝟎. 𝒐 𝒙 𝒚 𝒇(𝒙, 𝒚) 1 1 0 1 0 1 0 1 0 0 0 0 106 Example (5): Find the values of the Boolean function represented by 𝒇(𝒙, 𝒚, 𝒛) = 𝒙𝒚 + 𝒛̅. Solution: The values of this function are displayed in the given table 𝒙 𝒚 𝒛 𝒙𝒚 𝒛̅ 𝒇(𝒙, 𝒚, 𝒛) = 𝒙𝒚 + 𝒛̅ 1 1 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 1 Example (6): The function 𝒇(𝒙, 𝒚, 𝒛) = 𝒙𝒚 + 𝒛̅ from 𝑩𝟑 to 𝑩 can be represented by distinguishing the vertices that correspond to the five 3-tuples (1,1,1) , (1,1,0), (1,0,0), (0,1,0) and (0,0,0) where shown in the given figure 107 is 110 111 101 100 010 011 000 001 These vertices are displayed using solid black circles. The Boolean sum of they function 𝒇 and 𝒈 and Boolean product of 𝒇 and 𝒈 are given by 1) (𝒇 + 𝒈)(𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 ) = 𝒇(𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 ) + 𝒈(𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 ) 2) (𝒇 + 𝒈)(𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 ) = 𝒇(𝒙𝟏 , 𝒙𝟐 , 𝒙𝒏 ) + 𝒈(𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 ) 108 4.1.3 Identities of Boolean algebra: Boolean identities: Identity Name ̿=𝒙 𝒙 Law of the double complement 𝒙+𝒙=𝒙, 𝒙. 𝒙 = 𝒙 Idempotent lows 𝒙 + 𝟎 = 𝒙, 𝒙. 𝟏 = 𝒙 Identity laws 𝒙 + 𝟏 = 𝟏, 𝒙. 𝟎 = 𝟎 Domination laws 𝒙 + 𝒚 = 𝒚 + 𝒙, 𝒙𝒚 = 𝒚𝒙 Commutative laws 𝒙 + (𝒚 + 𝒛) = (𝒙 + 𝒚) + 𝒛 Associative laws 𝒙. (𝒚. 𝒛) = (𝒙. 𝒚). 𝒛 (𝒙 + 𝒚𝒛) = (𝒙 + 𝒚)(𝒙 + 𝒛) Distributive laws 𝒙(𝒚 + 𝒛) = 𝒙𝒚 + 𝒙𝒛 ̅̅̅̅̅̅̅ (𝒙𝒚 ̅̅̅̅) = 𝒙 ̅+𝒚 ̅, (𝒙 ̅. 𝒚 ̅ + 𝒚) = 𝒙 𝒙 + 𝒙𝒚 = 𝒙 Deomorgan’s laws Absorption laws 𝒙(𝒙 + 𝒚) = 𝒙 ̅=𝟏 𝒙+𝒙 Unit property ̅=𝟎 𝒙. 𝒙 Zero property 109 Example (7): Translate the distributive law𝒙 + 𝒚𝒛 = (𝒙 + 𝒚)(𝒙 + 𝒛) into a logical equivalenc Solution : 𝒙 + 𝒚𝒛 = (𝒙 + 𝒚)(𝒙 + 𝒛) ≡ 𝒑(𝒒𝒓) ≡ (𝒑𝒒)(𝒑 𝒓) Example (8): Prove the absorption law 𝒙(𝒙 + 𝒚) = 𝒙 using the other identities of Boolean algebra. Solution: 𝒙(𝒙 + 𝒚) = (𝒙 + 𝟎)(𝒙 + 𝒚) identity law for the Boolean sum = 𝒙 + 𝟎. 𝒚 distributive law = 𝒙 + 𝒚. 𝟎 commutative law =𝒙+𝟎 domination law =𝒙 identity law 4.2 Duality: Def.(2) The dual of a Boolean expression is obtained by interchanging Boolean sums and Boolean products and interchanging 𝟎𝒔 and 𝟏𝒔 . Example (9): Find the duals of (1) 𝒙(𝒚 + 𝟎) ̅. 𝟏 + (𝒚 ̅ + 𝒛) (2) 𝒙 Solution: 1) 𝒙 + (𝒚. 𝟏) ̅ + 𝟎)(𝒚 ̅. 𝒛) 2) (𝒙 Example (10): Construct an identity from the absorption law 𝒙(𝒙 + 𝒚) = 𝒙 by taking duals. Solution : 𝒙 + 𝒙 . 𝒚 = 𝒙 110 4 .3 The abstract definition of a Boolean algebra: Def. (3): A Boolean algebra is a set 𝑩 with two binary operations 𝒗 and 𝒏, elements 0 and 1, and a unary operation such that these properties hold ∀𝒙, 𝒚∀, 𝒛 ∈ 𝑩 𝒙∨𝒙 = 𝒙 } identity law. 𝒙∧𝒙 = 𝒙 ̅=𝟏 𝒙∨𝒙 } Commutative laws. ̅=𝟎 𝒙∧𝒙 (𝒙𝒚)𝒛 = 𝒙(𝒚𝒛) } Associative laws. (𝒙𝒚)𝒛 = 𝒙(𝒚𝒛) 𝒙𝒚 = 𝒚𝒙 𝒙𝒚 = 𝒚𝒙} Commutative laws. 𝒙(𝒚 𝒛) = (𝒙 𝒚) (𝒙𝒛) } Distributive laws. 𝒙(𝒚 𝒛) = (𝒙 𝒛) (𝒙𝒛) 4.4 Representing Boolean Functions: Example (11): Find Boolean expressions that represent the functions 𝒇(𝒙, 𝒚, 𝒛) and 𝒈(𝒙, 𝒚, 𝒛), which are given in the table 𝒙 𝒚 𝒛 𝒇 𝒈 1 1 1 0 0 1 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 111 Solution : 1) An expression that has the value 1 when 𝒙 = 𝒛 = 𝟏 and 𝒚 = 𝟎 and value otherwise, is needed to represent 𝒇. Such an expression can be formed by taking the Boolean product of ̅ and 𝒛. 𝒙, 𝒚 ̅𝒛 has the value This product, 𝒙𝒚 ̅= if 𝒙 = 𝒚 𝒛 = 𝟏 which holds iff 𝒙 = 𝒛 − 𝟏 and 𝒚 = 𝟎. 2) To represent 𝒈, we need an expression that equals 1 when 𝒙 = 𝒚 = 𝟏 and 𝒛 = 𝟎 or when 𝒙 = 𝒛 = 𝟎 and 𝒚 = 𝟏. We can form an expression with these values by taking the Boolean sum of two different Boolean products. the Boolean product 𝒙𝒚𝒛̅ has the value 1 iff 𝒙 = 𝒚 = 𝟏 and 𝒛 = 𝟎. Similarly, the ̅𝒚𝒛̅ has the value 1 iff 𝒙 = 𝒛 = 𝟎 and 𝒚 = 𝟏. The product 𝒙 ̅𝒚𝒛̅ represents 𝒈. Boolean sum of these two products 𝒙𝒚𝒛̅ + 𝒙 Def.(4): A literal is a Boolean variable or its complement. A minterm of the Boolean variables 𝒙𝟏 , 𝒙𝟐 , … . , 𝒙𝒏 is the Boolean product 𝒚𝟏 𝒚𝟐 …. 𝒚𝒏 where 𝒙𝒊 = 𝒚𝒊 or 𝒚𝒊 = ̅ 𝒙i. Hence a minterm is a product of n literals, with one literal for each variable. Example (12): Find a minterm that equals 1 if 𝒙𝟏 = 𝒙𝟑 = 𝟎 and 𝒙𝟐 = 𝒙𝟒 = 𝒙𝟓 = 𝟏, and equals 0 otherwise. Solution: ̅𝟏 𝒙𝟐 𝒙 ̅3.𝒙𝟒 𝒙𝟓 has the correct set of values. The minterm 𝒙 Example (13): Find the sum-of-products expansion of the function 𝒇(𝒙, 𝒚, 𝒛) = (𝒙 + 𝒚)𝒛̅. Solution: 𝒇(𝒙, 𝒚, 𝒛) = (𝒙 + 𝒚)𝒛̅ 112 = 𝒙𝒛̅ + 𝒚𝒛̅ distributive law = 𝒙𝟏𝒛̅ + 𝟏𝒚𝒛̅ identity law ̅)𝒛̅ + (𝒙 + 𝒙 ̅)𝒚𝒛̅ unit property = 𝒙(𝒚 + 𝒚 ̅𝒛̅ + 𝒙𝒚𝒛̅ + 𝒙 ̅𝒚𝒛̅ distributive = 𝒙𝒚𝒛̅ + 𝒙𝒚 law. ̅𝒛̅ + 𝒙 ̅𝒚𝒛̅ idempotent law𝐬. = 𝒙𝒚𝒛̅ + 𝒙𝒚 4.5 Logic gates: Introduction: Boolean algebra is used to model the circuitry electronic devices. Each input and each output of each device can be thought of as a member of the set {𝟎, 𝟏}. A computer, or other electronic device, is made up of a number of circuits. x y x Inverter OR gate AND gate X1 X2x X1+x2+..+xn Xn gates with n inputs 4.6 Combinations of Gates: Example (14): Construct circuits that produce the following out puts: ̅ (a) (𝒙 + 𝒚)𝒙 ̅̅̅̅̅̅̅ ̅ (𝒚 ̅𝒚 ̅𝒛̅) (b) 𝒙 + 𝒛̅) (c) (𝒙 + 𝒚 + 𝒛) (𝒙 113 Solution: a) (x ( x.y)𝑥̅ x b) x ( x c) x+y+z x Minimization of Circuits: 114 4.7 Minimization of Circuits: Example (15): ̅𝒛 Minimize and construct the out put circuit 𝒙𝒚𝒛 + 𝒙𝒚 Solution: ̅𝒛 = (𝒚 + 𝒚 ̅)𝒙𝒛 𝒙𝒚𝒛 + 𝒙𝒚 = 𝟏. 𝒙𝒛 = 𝒙𝒛 4.8 Karnaugh Maps: To reduce the number of terms in a Boolean expression representing a circuit, it is necessary to find terms to combine. There is a graphical method, called a Karnaugh map or K-map for finding terms to combine for Boolean functions involving a relatively small number of variables. Example (2): Find the K-maps for: ̅𝒚 (a) 𝒙𝒚 + 𝒙 ̅+𝒙 ̅𝒚 (b) 𝒙𝒚 ̅+𝒙 ̅𝒚 + 𝒙 ̅𝒚 ̅ (c) 𝒙𝒚 115 Solution: 𝒚 ̅ 𝒚 𝒙 1 1 ̅ 𝒙 1 ̅ 𝒚 𝒚 𝒙 𝒙 1 ̅ 𝒙 ̅ 𝒙 1 (a) ̅ 𝒚 𝒚 1 1 (b) 1 (c) Example (16): Simplify the sum-of-products expansion for ̅𝒚 (a) 𝒙𝒚 + 𝒙 ̅+𝒙 ̅𝒚 (b) 𝒙𝒚 ̅+𝒙 ̅𝒚+ 𝒙 ̅𝒚 ̅ (c) 𝒙𝒚 ̅𝒚 = (𝒙 + 𝒙 ̅)𝒚 = 𝟏. 𝒚 = 𝒚 Solution : (a) 𝒙𝒚 + 𝒙 ̅+ 𝒙 ̅𝒚 = 𝒙𝒚 ̅+𝒙 ̅𝒚 b) 𝒙𝒚 ̅+𝒙 ̅𝒚 + 𝒙 ̅𝒚 ̅ = 𝒙𝒚 ̅+𝒙 ̅(𝒚 + 𝒚 ̅) c) 𝒙𝒚 ̅+𝒙 ̅. 𝟏 = 𝒙𝒚 ̅+ 𝒚 ̅ = 𝒙 Example (17): Use the K-maps to minimize these sum-ofproducts expansions ̅𝒛̅ + 𝒙 ̅𝒚𝒛 + 𝒙 ̅𝒚 ̅𝒛̅ a) 𝒙𝒚𝒛̅ + 𝒙𝒚 ̅𝒛 + 𝒙𝒚 ̅𝒛̅ + 𝒙 ̅𝒚𝒛 + 𝒙 ̅𝒚 ̅𝒛 + 𝒙 ̅𝒚 ̅𝒛̅ b) 𝒙𝒚 ̅𝒛 + 𝒙𝒚 ̅𝒛̅ + 𝒙 ̅𝒚𝒛 + 𝒙 ̅𝒚 ̅𝒛 + 𝒙 ̅𝒚 ̅𝒛̅ c) 𝒙𝒚𝒛 + 𝒙𝒚𝒛̅ + 𝒙𝒚 ̅𝒛̅ + 𝒙 ̅𝒚 ̅𝒛 + 𝒙 ̅𝒚 ̅𝒛̅ d) 𝒙𝒚𝒛̅ + 𝒙𝒚 Solution: 𝒚𝒛 𝒙 ̅ 𝒙 1 𝒚𝒛̅ ̅𝒛̅ 𝒚 ̅𝒛 𝒚 1 1 𝒙 1 ̅ 𝒙 𝒚𝒛 ̅𝒛̅ + 𝒙 ̅𝒚𝒛 (a) 𝒙𝒛̅ + 𝒚 𝒚𝒛̅ 1 ̅+𝒙 ̅𝒛 (b) 𝒚 116 ̅𝒛̅ 𝒚 ̅𝒛 𝒚 1 1 1 1 𝒚𝒛 𝒚𝒛̅ ̅𝒛̅ 𝒚 ̅𝒛 𝒚 𝒙 1 1 1 1 𝒙 ̅ 𝒙 1 1 1 ̅ 𝒙 𝒚𝒛 ̅+ 𝒛 (c) 𝒙 + 𝒚 𝒚𝒛̅ ̅𝒛̅ 𝒚 1 1 ̅𝒛 𝒚 1 1 ̅𝒚 ̅ (d) 𝒙𝒛̅ + 𝒙 Exercises: 1) Find the output of the given circuits: x y a) y x b) y x y c) z x 2) Construct circuits from inverters, AND gates and OR gates to produce these out puts. ̅̅̅̅̅̅̅ ̅ + 𝒚 (b) (𝒙 (a) 𝒙 + 𝒚)𝒙 ̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅ ̅𝒚 ̅𝒛̅ (d) (𝒙 ̅ + 𝒛)(𝒚 + 𝒛̅) (c) 𝒙𝒚𝒛 + 𝒙 117 3) Draw a k–map for a function in two variables and put a 1 in the ̅𝒚 cell representing 𝒙 4) Draw the k–maps of these sum-of-products expansions in two variables: ̅ (b) 𝒙𝒚 + 𝒙 ̅𝒚 ̅ (a) 𝒙𝒚 ̅+𝒙 ̅𝒚 + 𝒙 ̅𝒚 ̅ (c) 𝒙𝒚 + 𝒙𝒚 118 Chapter 5 An Introduction to Graph Theory Def.(1): A graph 𝑮 = (𝑽, 𝑬) consists of 𝑽, a nonempty set of vertices (nodes) and 𝑬, a set of edges. Each edge has either one or two vertices associated with it , called its endpoints. An edge is said to connect the end points. Remark: The set of vertices 𝑽 of a graph 𝑮 may be finite. A graph with an infinite vertex set is called an infinite graph, and in comparison, a graph with a finite vertex set is called a finite graph, here we consider only finite graphs. Now suppose that a network is made up of data centers and communication links between computers. We can represent the location of each data center by a point and each communication link by a line segment as shown in the figure Hafralbatin Demam Riadh Jedda Medina Hafoof Mekka This computer network can be modeled using a graph in which the vertices of the graph represent the data centers and edges represent communication links. A graph in which each edge connects two different vertices and where no two edges connect the same pair of vertices is called a simple graph. 119 Def.(2): A directed graph (diagraph) (𝑽, 𝑬)consists of nonempty set of vertices 𝑽 and a set of directed edges (or arcs) 𝑬, each directed edge is associated with an ordered pair of vertices. The directed edge associated with the ordered pair (𝒖, 𝒗) is said to start a 𝒖 and end at 𝒗. A graph with no loops and has no simple directed edges is called a simple directed graph. 5 .1 Basic Terminology: Def.(3): Two vertices 𝒖 and 𝒗 in an undirected graph 𝑮 are called adjacent (neighbours) in 𝑮 if 𝒖 and 𝒗 are endpoints of an edge of 𝑮. If 𝒆 is associated with {𝒖, 𝒗} the edge e is called incident with the vertices 𝒖 and 𝒗. The edge 𝒆 is also said to connect 𝒖 and 𝒗. The vertices 𝒖 and 𝒗 called end points of an edge associated with {𝒖, 𝒗}. Def.(4): The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex. The degree of the vertex 𝒗 is denoted by deg (𝒗). Example (1): What are the degrees of the vertices in the graphs 𝑮 and 𝑯 in the given figures c b a f d b a d e e G 120 c H Solution: In 𝑮 ∶ deg (𝒂) = 2, deg (𝒃) = deg (𝒄)= deg (𝒇)= 4 , deg (𝒅) = 1 and deg (𝒈) = 0. In 𝑯 ∶ deg (𝒂) = 4, deg (𝒃) = deg (𝒆)= 6, deg (𝒄) = 1 and deg (𝒅) = 5. A vertex of degree zero is called isolated, a vertex is pendant iff it has degree one. Example (2): What does the degree of a vertex in a niche overlap graph represents? Which vertices in this graph are pendant and which are isolated in the given figure Owl Raccoon Hawk Squirrel Opossum Crow Shrew Mouse Wood pecker Solution: There is an edge between two vertices in a niche overlap graph iff the two species represented by these vertices complete. Hence, the degree of a vertex in a niche overlap graph is the number of species in the ecosystem that complete with the species represented by this vertex. 121 The degree of the vertex representing the squirrel is 4 because the squirrel competes with four other species: the crow, the opossum, the raccoon and the wood pecker. The mouse is the only species represented by a pendant vertex. The vertex representing a species is pendant if this species competes with only one other species. There are no isolated vertices. Theorem(1): (The handshaking theorem) Let 𝑮 = (𝑽, 𝑬) be an undirected graph with 𝒆 edges. Then 𝟐𝒆 = ∑ 𝐝𝐞𝐠(𝒗) 𝒗∈𝑽 Example (3): How many edges are there in a graph with 10 vertices each of degree 6? Solution: Because the sum of the degrees of the vertices is 6.10 = 60, it follows that 2e = 60 e = 30. Theorem(2): An undirected graph has an even number of vertices of odd degrees. 5 .2 Some Special Simple Graphs: Example (4): (Complete graphs) The complete graph on n vertices, denoted by 𝒌𝒏 , is the simple graph that contains exactly one edge between each pair of district vertices as shown in the figures: . k1 . . k2 k3 k4 122 k5 k6 Example (5): (cycles) The cycles 𝑪𝒏 , 𝒏 ≥ 𝟑, consists of n vertices 𝒗𝟏 , 𝒗𝟐 … , 𝒗𝒏 and edges {𝒗𝟏 , 𝒗𝟐 } , {𝒗𝟐 , 𝒗𝟑 } … , {𝒗𝒏−𝟏 , 𝒗𝒏 } 𝒂𝒏𝒅 {𝒗𝒏 , 𝒗𝟏 } .The cycles 𝑪𝟑 , 𝑪𝟒 , 𝑪𝟓 , 𝒂𝒏𝒅 𝑪𝟔 , are displayed in the figure: c3 c4 c5 c6 Example (6): (wheels) We obtain the wheel 𝑾𝒏 when we add additional vertex to the cycle 𝒄𝒏 𝒇𝒐𝒓 𝒏 ≥ 𝟑 and connect this new vertex to each of n vertices in 𝒄𝒏 , by new edges th wheels 𝑾𝟑 , 𝑾𝟒 , 𝑾𝟓 , 𝑾𝟔 , are displayed in the figure: 𝑾𝟑 𝑾𝟒 𝑾𝟓 𝑾𝟔 Example (7): (n-cubes) The n-dimentional hypercuble or n-cube, denoted by 𝑸𝒏 is the graph that has vertices representing the 𝟐𝒏 bit strings of length n. 110 0 𝑮𝟏 1 111 11 10 101 100 010 011 01 00 000 𝑮𝟐 001 𝑮𝟑 123 5.3 Bipartite graphs: Def.(5): A simple graph 𝑮 is called bipartite if its vertex set V can be partitioned into two disjoint sets 𝑽𝟏 and 𝑽𝟐 such that every edge in the graph connects a vertex in 𝑽𝟏 and a vertex in 𝑽𝟐 . When this condition holds, we call the pair (𝑽𝟏 , 𝑽𝟐 ) a bipartition of the vertex set 𝑽 of 𝑮. In example (3) 𝒄𝟔 is a bipartite. Example (8): 𝒄𝟔 in the given figure is bipartite because its vertex set can be partitioned into the two sets 𝑽𝟏 = {𝒗𝟏 , 𝒗𝟑 , 𝒗𝟓 } and 𝑽𝟐 = {𝒗𝟐 , 𝒗𝟒 , 𝒗𝟔 } and every edge of 𝒄𝟔 connects a vertex in 𝑽𝟏 and a vertex in 𝑽𝟐 . Theorem(3): In every graph , the number of nodes with odd degree is even . Proof: We start with a graph with no edges in which every degree is 0 And so the number of nodes with odd degree is 0 , which is an even number. (1) If we connect two nodes by a new edge , we change the parity of the degrees at these nodes . In particular, if both endpoints of 124 the new edge have even degree , we increase the number of nodes with odd degree by 2 . (2) If both endpoints of the new edge had odd degree , we decrease the number of nodes with odd degree by 2. , (3) If one endpoint of the new edge had even degree and the other had odd degree. Thus if the number of nodes with odd degree was even before adding the new edge, it remained even after this step .This proves the theorem. Theorem (4): (a) A graph G is a tree if and only if it is connected , but deleting any of its edges , results in a disconnected graph . (b) A graph G is a tree if and only if it contains no cycle , but adding any new edge creates a cycle. Theorem (5): Every tree on n nodes has n-1 edge. 5. 4 Representing Graphs and Graph Isomorphism: Representing Graphs ; One way to represent a graph without multiple edges is to list all the edges of this graph. Another way to represent a graph with no multiple edges is to use adjacency lists, which specify the vertices that are adjacent to each vertex of the graph. 125 Table ( 1)An adjacency list for a simple graph b vertex Adjacency vertices c a e d a b, c, e b a c a, d, c d c, e e a, c, d Example (9): Use adjacency lists to describe the simple graph given in the above figure. Solution: Table 1 lists those vertices adjacent to each of the vertices of the graph. Example (10): Represent the directed graph shown in figure (2) by listing all the vertices that are the terminal vertices of edges starting at each vertex of the graph Initial vertex Terminal b vertices a c e a b, c, d, e b b, d c a, c, e d d e directed graph Figure (2) 126 b, c, d Solution: Table (2) represent the directed graph shown in figure (2) above. 5.5 Adjacency Matrices: The adjacency matrix 𝑨 of 𝑮 with respect to the listing of vertices, is the 𝒏 × 𝒏 zero-one matrix with 1 as its (𝒊, 𝒋)𝒕𝒉 entry when 𝒗𝒊 and 𝒗𝒋 are adjacent, and 0 as its (𝒊, 𝒋)𝒕𝒉 entry when they are not adjacent 𝟏 𝒂𝒊𝒋 = { 𝟎 𝑨 = [𝒂𝒊𝒋 ] , then if {𝒗𝒊 , 𝒗𝒋 } is edge of 𝑮 otherwise Example (11): Use an adjacency matrix to represent the graph shown in the figure : a b c d Solution: We order the vertices as a, b, c, d. The matrix representing this graph is 0 1 1 [1 1 0 1 0 1 1 0 0 1 0 0 0] Example (12): Draw the graph with this adjacency matrix 0 1 1 [0 1 0 0 1 1 0 0 1 127 0 1 1 0] with respect to the ordering of vertices a, b, c, d. a b c d Figure (4) Example (13): Use an adjacency matrix to represent the pseudograph shown in figure (5) a b c d Figure (5) A Pseudograph Solution: The adjacency matrix using the ordering of vertices a, b, c, d is 0 3 0 [2 3 0 1 1 0 1 1 2 2 1 2 0] 5.6 Incidence Matrices: Another common way to represent graphs is to use incidence matrices. Let 𝑮 = (𝑽, 𝑬) be an undirected graph. Suppose that 𝒗𝟏 , 𝒗𝟐 , … , 𝒗𝒏 are vertices and 𝒆𝟏 , 𝒆𝟐 , … , 𝒆𝒎 are the edges of 𝑮. Then 128 the incidence matrix with respect to this ordering of 𝑽 and 𝑬 is the 𝒏 × 𝒎 matrix 𝑴 = [𝒎𝒊𝒋 ], where 𝟏 𝐰𝐡𝐞𝐧 𝐞𝐝𝐠𝐞 𝒆𝒋 𝐢𝐬 𝐢𝐧𝐜𝐢𝐝𝐞𝐧𝐭 𝐰𝐢𝐭𝐡 𝒗𝒊 𝒎𝒊𝒋 = { 𝟎 𝐨𝐭𝐡𝐞𝐫𝐰𝐢𝐬𝐞 Example (14): Represent the graph shown in figure 6 with an incidence matrix. Solution: The incidence matrix is: 𝒆𝟏 𝒆𝟐 𝒆𝟑 𝒆𝟒 𝒆𝟓 𝟏 𝟎 𝟎 𝟏 [𝟎 𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟏 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟏 𝒆𝟔 𝟎 𝟏 𝟏 𝟎 𝟎] Figure 7 A Pseudo graph Example (15): Represent the pseudo graph shown in the figure using incidence matrix v1 e2 v2 e1 e3 e4 e7 v3 e5 e6 v4 v5 e8 𝒆𝟏 𝒆𝟐 𝒆𝟑 𝒆𝟒 𝒆𝟓 𝒆𝟔 𝒆𝟕 𝒆𝟖 𝟏 𝟎 𝟎 𝟎 [𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟏 𝟏 𝟎 𝟎 𝟎 𝟏 𝟏 𝟎 𝟎 𝟎 𝟎 𝟏 𝟏 𝟎 𝟎 𝟎 𝟎 𝟏 𝟎 𝟏 𝟎 𝟏 𝟎 𝟏 𝟎 𝟎 𝟎 𝟎 𝟏 𝟎] A Pseudograph 5.7 Isomorphism of Graphs: Def.(6): The simple graphs 𝑮𝟏 = (𝑽𝟏 , 𝑬𝟏 ) and 𝑮𝟐 = (𝑽𝟐 , 𝑬𝟐 ) are isomorphic if there is a one-to-one and onto function from 𝑽𝟏 to 129 𝑽𝟐 with the property that 𝒂 and 𝒃 are adjacent in 𝑮𝟏 iff 𝒇(𝒂) and 𝒇(𝒃) are adjacent in 𝑮𝟐 ∀𝒂, 𝒃 ∈ 𝑽𝟏 . such function f is called isomorphism. Example (16): Show that the graphs 𝑮 = (𝑽, 𝑬) and 𝑯 = (𝑾, 𝑭), displayed in figure 8, are isomorphic. G Solution: The function f with 𝒇(𝒖𝟏 ) = 𝒗𝟏 , 𝒇(𝒖𝟐 ) = 𝒗𝟒 , 𝒇(𝒖𝟑 ) = 𝒗𝟑 , 𝒇(𝒖𝟒 ) = 𝒗𝟐 is one-to-one correspondence between V and W. To see that this correspondence presents adjacency, note that adjacent vertices in 𝑮 are 𝒖𝟏 and 𝒖𝟐 , 𝒖𝟏 and 𝒖𝟑 , 𝒖𝟐 and 𝒖𝟒 , and 𝒖𝟑 and 𝒖𝟒 , and each of the pairs 𝒇(𝒖𝟏 ) = 𝒗𝟏 and 𝒇(𝒖𝟐 ) = 𝒗𝟒 , 𝒇(𝒖𝟏 ) = 𝒗𝟏 and 𝒇(𝒖𝟑 ) = 𝒗𝟑 , 𝒇(𝒖𝟐 ) = 𝒗𝟒 and 𝒇(𝒖𝟒 ) = 𝒗𝟐 and 𝒇(𝒖𝟑 ) = 𝒗𝟑 and 𝒇(𝒖𝟒 ) = 𝒗𝟐 are adjacent in H . Example (17): Show that the graphs displayed in the figure isomorphic. G H 130 are not Solution: Both G and H have five vertices and six edges. However, H has a vertex of degree one, namely e, whereas G has no vertices of degree one. It follows that G and H are not isomorphic. Exercises: In exercise 1 – 3 find the number of vertices, the number of edges, and the degree of each vertex in the given undirected graph b a a c b 1) f e e .d a .f 2) c b i h d c .d g 3) 4) Draw these graphs: (a) 𝑲𝟕 (b) 𝑲𝟏,𝟖 (c) 𝑲𝟒,𝟒 (d) 𝑪𝟕 (e) 𝑾𝟕 (f) 𝑸𝟒 131 5) In Exercises 1 – 4 use an adjacency list to the given graph a c b a d d b c 1) e 2) a c b a b 3) c 4) e d d 6) Draw a graph with the given adjacency matrices a) 𝟎 𝟏 [𝟏 𝟎 𝟎 𝟏 𝟎 𝟏] 𝟎 (b) 𝟎 [𝟎 𝟏 𝟏 𝟎 𝟎 𝟏 𝟏 𝟏 𝟏 𝟎 𝟏 𝟏 𝟎] 𝟏 𝟎 5.8.1 Paths: A path is a sequence of edges that begins at a vertex of a graph and travels from vertex to vertex along edges of the graph. Def. (7): Let n be a nonnegative integer and G an undirected graph. A path of length n from u to v in G is a sequence of n edges 𝒆𝟏 , 𝒆𝟐 , … , 𝒆𝒏 of G such that 𝒆𝟏 is associated with {𝒙𝟎 , 𝒙𝟏 }, 𝒆𝟐 is associated with {𝒙𝟏 , 𝒙𝟐 } and so on, with 𝒆𝒏 associated with {𝒙𝒏−𝟏 , 𝒙𝒏 } where 𝒙𝟎 = 𝒖 and 𝒙𝒏 = 𝒗. When the graph is simple we denote this path by its vertex sequence 𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 . The path is a circuit if it begins and end at the same vertex, that is, if u = v, and has length greater than zero. The path or circuit is said to pass through the vertices 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏−𝟏 or traverse the edges 𝒆𝟏 , 𝒆𝟐 , … , 𝒆𝒏 . A path or circuit is simple if it does not contain the same edge more than once. 132 Example (18): In the simple graph in the figure a b c d e f Simple graph a, d, c, e, f is a simple path of length 4, because {𝒂, 𝒅}, {𝒅, 𝒄}, {𝒄, 𝒇} and {𝒇, 𝒆} are all edges. However, d, e, c, a is not a path, because {𝒆, 𝒄} is not an edge. Note that b, c, f, e, b is a circuit of length 4 because {𝒃, 𝒄}, {𝒄, 𝒇}, {𝒇, 𝒆} and {𝒆, 𝒃} are edges, and this path begins and ends at b. The path a, b, e, d, a, b which is of length 5, is not simple because it contains the edge {𝒂, 𝒃} twice. 5.8.2 Connectedness in Undirected Graphs: Def. (8): An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph. Thus, any two computers in the network can communicate iff the graph of this network is connected. 133 Example (19): The graph 𝑮𝟏 in the given figure: c f b a b a c e d d e f is connected, because for every pair of d distinct vertices there is a path between them. However, the graph 𝑮𝟐 in the figure is not connected. There is no path in 𝑮𝟐 between vertices a and d. Theorem (3): There is a simple path between every pair of distinct vertices of a connected undirected graph. A connected component of a graph G is a connected subgraph of G that is not proper subgraph of another connected subgraph of G. That is, a connected component of a graph G is a maximal connected subgraph of G. a graph G that is not connected has two or more connected components that are disjoint and have G as their union. 134 Example (20): What are the connected components of the graph H shown in the figure: 𝐻2 𝐻1 b d e 𝐻3 a f c e g The connected components 𝑯𝟏 , 𝑯𝟐 and 𝑯𝟑 Solution: The graph H is the union of three disjoint connected subgraphs 𝑯𝟏 , 𝑯𝟐 and 𝑯𝟑 . These three subgraphs are the connected components of H. 5.8.3 Connectedness in directed graphs: Def. (9): A directed graph is strongly connected if there is a path from a to b and from b to a whenever a and b are vertices in the graph. Def. (10): A directed graph is weakly connected if there is a path between every two vertices in the underlying undirected graph. That is, a directed graph is weakly connected iff there is always a path between two vertices when the directions of the edges are disregarded. Any strongly connected directed graph is also weakly connected. 135 h Example (21): Are the directed graphs G and H shown in the figure: a b b a c e G c e d H d The directed graphs G and H. Strongly connected?. Are they weakly connected? Solution: G is strongly connected because there is a path between any two vertices in this directed graph (verify). Hence, G is also weakly connected. The graph H is not strongly connected. There is no directed path from a to b in this graph. However, H is weakly connected, because there is a path between any two vertices in the underlying undirected graph of H (verify). 5.8.4 Counting paths between vertices: The number of paths between two vertices in a graph can be determined using its adjacency matrix. Example (22): Let G be a graph with adjacency matrix A with respect to the ordering 𝒗𝟏 , 𝒗𝟐 , … , 𝒗𝒏 (with directed or undirected edges, with multiple edges and loops allowed). The number of different paths of length 𝒓 from 𝒗𝒊 to 𝒗𝒋 , where 𝒓 is a positive integer, equals the (i, j)th entry of 𝑨𝒓 . 136 Example (23): How many paths of length 4 are there from a to d in the simple graph G in the figure a b c d Figure Solution: The adjacency matrix of G (ordering the vertices as a, b, c, d) is 0 1 𝑨= 1 [0 1 0 0 1 1 0 0 1 0 1 1 0 ] Hence, the number of paths of length 4 from a to d is the (1,4)th entry of A4. 8 0 𝑨𝟒 = 0 [8 0 8 8 0 0 8 8 0 8 0 0 8 ] Because there are exactly eight paths of length 4 from a to d. By inspection of the graph, we see that a, b, a, b, d; a, b, a, c, d; a, b, d, b, d; a, b, d, c, d; a, c, a, c, d; a, c, d, b, d; and a, c, d, c, d are the eight paths from a to d. 137 5.9 .1 Eulr and Hamilton Paths: Def. (11): An Euler circuit in a graph G a simple circuit containing every edge of G. An Euler path in G is a simple path containing every edge of G. Example(24):Which of the undirected graphs in the figure have an Euler circuit? Of those that do not, which have an Euler path? a b a e d b a b c d c e c d e Solution: The graph 𝑮𝟏 has an Euler circuit, for example, a, e, c, d, e, b, a. Neither of the graphs 𝑮𝟐 or 𝑮𝟑 has an Euler circuit (verify). However, 𝑮𝟑 has an Euler path, namely, a, c, d, e, b, d, a, b. 𝑮𝟐 does not have an Euler path (verify). 138 Example (25): Which of the directed graphs in the figure have an Euler circuit? Of those that do not, which have an Euler path? a a b d c b f e d c d a b Solution: The graph H2 has an Euler circuit, for example, a, g, c, b, g, e, d, f, a. Neither H1 nor H3 has an Euler circuit (verify). H3 has an Euler path namely, c, a, b, c, d, b, but H1 does not (verify) 5.9.2 Hamilton Paths and Circuits: Def.(12): A simple path in a graph G that passes through every vertex exactly once is called a Hamilton path, and a simple circuit in a graph G that passes through every vertex exactly once is called a Hamilton circuit. That is, the simple path 𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 in the graph 𝑮 = (𝑽, 𝑬) is a Hamilton path if 𝑽 = {𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 } and 𝒙𝒊 ≠ 𝒙𝒋 for 𝟎 ≤ 𝒊 < 𝑗 ≤ 𝑛, and the simple circuit𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 , (𝒏 > 0)𝐢𝐬 𝐚 𝐇𝐚𝐦𝐢𝐥𝐭𝐨𝐧 𝐜𝐢𝐫𝐜𝐮𝐢𝐭 if 𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 is a Hamilton path. Example (26): Which of the simple graphs in the figure have a Hamilton circuit or, if not, a Hamilton path? b a c e a b a b d c d c Simple graphs d 139 e f Solution: 𝑮𝟏 has a Hamilton circuit a, b, c, d, e, a. There is no Hamilton circuit in 𝑮𝟐 (this can be seen by noting that any circuit containing every vertex must contain the edge {𝒂, 𝒃} twice), but 𝑮𝟐 does have a Hamilton path, namely, a, b, c, d. 𝑮𝟑 has neither a Hamilton circuit nor a Hamilton path, because any path containing all vertices must contain one of the edges {𝒂, 𝒃}, {𝒆, 𝒇} and {𝒄, 𝒅} more than once. Example (27): Show that neither graph displayed in the given figure has aa Hamiltondcircuit. e d a c b c b G e H Solution: There is no Hamilton circuit in G because G has a vertex of degree one, namely, e. Now consider H. Because the degrees of vertices a, b, d and e are all two, every edge incident with these vertices must be part of any Hamilton circuit. It is now easy to see that no Hamilton circuit can exist in H, for any Hamilton circuit would have to contain four edges incident with c, which is impossible. Theorem (4): (Dirac’s Theorem) If G is a simple graph with n vertices with 𝒏 ≥ 𝟑 such that the degree of every vertex in G is at least 𝒏/𝟐 , then G has a Hamilton circuit. Theorem (5): (Ore’s Theorem) If G is a simple graph with n vertices with 𝒏 ≥ 𝟑 such that deg(u) + deg(v) n for every pair of nonadjacent vertices u and v in G, then G has a Hamilton circuit. 140 5.10 Planar Graphs: Def. (13): A graph is called planar if it can be drawn in the plane without any edges crossing (where a crossing of edges is the intersection of the lines or arcs representing them at a point other than their common endpoint). Such a drawing is called a planar representation of the graph. A graph may be planar even if it is usually drawn with crossings, because it may be possible to draw it in a different way without crossings. Example (28): Is K4 (shown in the given figure with two edges crossing) planar? K4 K4 drawn with no crossings. Solution: K4 is planar because it can be drawn without crossings. Example (29): Is Q3, shown in the given figure, planar? Q3 Aplanar representing of Q3 141 Solution: Q3 is planar, because it can be drawn without any edges crossing. Theorem(6): (Euler’s Formula): Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G. Then r = e – v + 2. Example (30): Suppose that a connected planar simple graph has 20 vertices, each of degree 3. Into how many regions does a representation of this planar graph split the plane? Solution: This graph has 20 vertices, each of degree 3, so v = 20. Because of the sum of the degrees of the vertices, 3v = 3.20 = 60, is equal to twice the number of edges, 2e we have 2e = 60 e = 30. Consequently, from Euler’s formula, the number of regions is: r = e – v + 2 = 30 – 20 + 2 = 12. Corollary (1): If G is a connected planar simple graph with e edges and v vertices, where 𝒗 ≥ 𝟑, then 𝒆 ≤ 𝟑𝒗 − 𝟔. Corollary (2): If G is a connected planar simple graph, then G has a vertex of degree not exceeding five. Example (31): Show that K5 is nonplanar using corollary (1) 142 Solution: The graph K5 has vertices and 10 edges. However, the inequality 𝒆 ≤ 𝟑𝒗 − 𝟔 is not satisfied for this graph because e = 10 and 𝟑𝒗 − 𝟔 = 𝟗 (𝟏𝟎 ≤ 𝟗). Therefore, K5 is not planar. Corollary (3): If a connected planar simple graph has e edges and v vertices with 𝒗 ≥ 𝟑 and no circuits of length 3 , then 𝒆 ≤ 𝟐𝒗 − 𝟒 Example (32): Use corollary( 3) to show that K3.3 is nonplanar. Solution: Because K3.3 has no circuits of length 3 (this is easy to see because it is bipartite), corollary (3) can be used. K3.3 has 6 vertices and 9 edges. Because e=9 and 2v-4 = 8 K3.3 is non planar. Exercises: 1) Does each of these lists of vertices form a path in the following graphs? Which paths are simple? Which are circuits? What are the lengths of those that are paths? (a) a, e, b, c, b (b) a, e, a, d, b, c, a (c) e, b, a, d, b, e (d) c, b, d, a, e, c 2) Determine whether the given graph is connected 143 3) Determine whether the given graph has an Euler circuit. construct such a circuit when one exists. If no Euler circuit exists, determine whether the graph has an Euler path and construct such a path if one bexists. c a d e 4) Does the graph have a Hamilton path? If so find, such a path. If it doesnot, give an argument to show why no such path exists d a c f e b 144 Chapter 6 Counting 6.1 Basic Counting Principles: We will present two basic counting principles, the product rule and the sum rule. The Production Rule: The product rule applies when a procedure is made up to separate tasks. Example (1) There are 32 microcomputers in a computer centre. microcomputer has 24 parts. Each How many different parts to a microcomputer in the center are there? Solution: Because there are 32 ways to choose the microcomputer and 24 ways to choose the part no matter which microcomputer has been selected, the product rule shows that there are 32*24 = 768 parts. Example (2) How many functions are there from a set with m elements to a set with n elements? Solution: A function corresponds to a choice of one of the n elements in the codomain for each of the m elements in the domain. Hence by the product rule there are n.n. ….. n = nm functions From a set with m elements to one with n elements. 6.2 The Sum Rule: If a task can be done either in one of n1 ways or in one of n2 ways, where none of the set of n1 ways is the same as any of the set of n2 ways, there are n1 + n2 ways to do the task. 145 Example (3): Suppose that either a member of the mathematics faculty or a student who is a mathematics major is chosen as a representive to a university committee. How many different choices are there for this representive if there are 37 members of the mathematics faculty and 83 mathematics majors and no one is both a faculty member and a student? Solution: There are 37 ways to choose a member of the mathematics faculty and there are 83 ways to choose a student who is mathematics major. Choosing a member of the mathematics faculty is never the same as choosing a student who is a mathematics major because no one is both a faculty member and a student. By the sum rule it follows that there are 37 + 83 = 120 possible ways to pick this representive. Example (4): A student can choose a computer project from one of three lists. The three lists contain 23, 15 and 19 possible projects respectively. No project is on more than one list. How many possible projects are there to choose from? Solution: The student can choose a project by selecting a project from the first list, the second list, or the third list. Because no project on more than one list, by the sum rule there are 23 + 15 + 19 = 57 ways to choose a project. Exercises: 1) How many +ve integers between 50 and 1000 (a) are divisible by 7? Which integers are these? 146 (b) are divisible by 11? Which integers are there? (c) are divisible by both 7 and 11? Which integers 2) How many +ve integers less than 1000 are there? (a) are divisible by 7? (b) are divisible by 7 but not by 11? (c) are divisible by both 7 and 11? 3) How many +ve integers between 100 and 999 (a) are divisible by 7? (b) are odd? (c) Have the same three decimal digits? (d) Are not divisible by 4? (e) Are divisible by 3 or 4. 6.3 The Pigeonhole Principle: Theorem(1): If k is a positive integer and k+1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects. Proof: We will prove the pigeonhole principle using a proof by contraposition. Suppose that none of the k boxes contains more than one object. Then the total number of objects would be at most k. this contradiction, because there are at least k+1 objects. Example (5): Among any group of 367 people, there must be at least two with the same birthday, because there are only 366 possible birthdays. 147 Example (6): In any group of 27 English words, there must be at least two that begin, with the same letter, because there are 26 letters in the English alphabet. Example (7): How many students must be in a class to guarantee that at least two students receive the same score on the final exam, if the exam graded in a scale from 0 to 100 points. Solution: There are 101 possible scores on the final. The pigeonhole principle show that among any 102 students there must be at least 2 students with same score. 6. 4. Sequences and Summations: 6.4.1. Sequences: A sequence is a discrete structure used to represent an ordered list . For example ,1,2,3,5,8 is a sequence with five terms and 1,3 9,27,81,…is an infinite sequence . Def.(1): A Sequence is a function from a subset of integers (usually either the set {0,1,2,…} or the set {1,2,3,…}to the set S. We use the notation 𝒂𝒏 to denote the image of the integer n . We call 𝒂𝒏 a term of the sequence . Example(1): Consider the sequence {𝒂𝒏 } ,where 𝒂𝒏 = 𝟏 𝒏 The list of the terms of this sequence ,beginning with 𝒂𝒏 ,namely , 𝒂𝟏 , 𝒂𝟐 , 𝒂𝟑 , … Def.(2): A geometric progression is a sequence of the form 𝒂, 𝒂𝒓 , 𝒂𝒓𝟐 , 𝒂𝒓𝟑 , … , 𝒂𝒓𝒏 , … 148 Where the initial term 𝒂 and the common ratio 𝒓 are real numbers. Example (2): The sequence {𝒃𝒏 } with 𝒃𝒏 = (-1)𝒏 , {𝒄𝒏 } with 𝟏 𝒄𝒏 = 𝟐. 𝟓𝒏 and {𝒅𝒏 } with 𝒅𝒏 = 6 . ( )𝒏 are geometric progressions 𝟑 with initial term and common ratio equal to 1 and -1 ; 2and 5 ; and 6 and 𝟏 𝟑 , respectively , if we start at n=0 . The list of terms 𝒃𝟎 , 𝒃𝟏 , 𝒃𝟑 , 𝒃𝟒 ,…. begins with 1,-1, 1 ,-1 ,1,…; The list of terms 𝒄𝟎 , 𝒄𝟏 , 𝒄𝟐 , 𝒄𝟑 , … begins with 2, 10, 50, 250, 1250, …; And the list of terms 𝒅𝟎 , 𝒅𝟏 , 𝒅𝟐 , 𝒅𝟑 , … 𝒃𝒆𝒈𝒊𝒏𝒔 𝒘𝒊𝒕𝒉 6, 2, 𝟐 , 𝟑 𝟐 , 𝟗 𝟐 𝟐𝟕 ,… Def.(3): An arithmetic progressions is a sequence of the form : 𝒂, 𝒂 + 𝒅, 𝒂 + 𝟐𝒅, 𝒂 + 𝟑𝒅, … , 𝒂 + 𝒏𝒅, … Where the initial term 𝒂 and the common difference 𝒅 are real numbers. Example(3): The sequence {𝒔𝒏 } with 𝒔𝒏 = -1+4n and {𝒕𝒏 } with 𝒕𝒏 =7-3n are both arithmetic progressions with initial terms and common differences equal to -1 and 4 ,and 7 and -3, respectively, if we start at n=0 . The list of terms 𝒔𝟎 , 𝒔𝟏 , 𝒔𝟐 , 𝒔𝟑 , … begins with -1,3,7,11,… And the list of terms 𝒕𝟎 , 𝒕𝟏 , 𝒕𝟐 , 𝒕𝟑 , … begins with 7 ,4 ,1 ,-2,… Example(4): Find formula for the sequences with the following first five terms: (a) 1, 𝟏 𝟐 , 𝟏 𝟒 , 𝟏 𝟖 , 𝟏 𝟏𝟔 (b) 1 ,3 ,5 ,7 ,9 (c) 1 ,-1 , 1 ,-1 ,1. 149 Solution: (a) We recognize that the denominators are powers of 2. The sequence with 𝒔𝟎 = 𝟏 𝟐𝒏 , n = 0 ,1 ,2 , … is a possible match . The proposed sequence is a geometric progression with 𝒂 = 𝟏 𝒂𝒏𝒅 𝒓 = 𝟏 𝟐 (b)We note that each term is obtained by adding 2 to the previous term . The sequence with 𝒂𝒏 = 2n +1 , n= 0 ,1, 2 ,… is a possible match . This proposed sequence is an arithmetic progression with 𝒂 = 𝟏 𝒂𝒏𝒅 𝒅 = 𝟐. (c) The terms alternate between 1 and -1 . The sequence with 𝒂𝒏 = (-1)𝒏 ,n= 0 ,1, 2 ,… is possible match . This proposed sequence is a geometric progression with 𝒂 = 𝟏 𝒂𝒏𝒅 𝒓 = −𝟏. Some Useful Sequences nth Term First 10 Terms 𝒏𝟐 1, 4 , 9 , 16 , 49 , 64 , 81 , 100 ,… 𝒏𝟑 1 , 8 ,27 , 64 , 125 , 216 , 343 , 512 , 729 , 100 ,… 𝒏𝟒 1 , 16 , 81 , 256 , 625 , 1296 , 2401 , 4096 , 6561 , 10000,… 𝟐𝒏 2, 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024,… 𝟑𝒏 3 , 9 , 27 , 81 , 243 , 729 , 2187 , 6561 , 19683, 59049,… n! 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880, 3628800,… 6.4.2 Summations: The sum of terms : 𝒂𝒎 , 𝒂𝒎+𝟏 , 𝒂𝒎+𝟐, , 𝒂𝒎+𝟑 , … , 𝒂𝒏 sequence {𝒂𝒏 }. We use the notation : ∑𝒏𝒋=𝒎 𝒂𝒋 , to represent: 150 form the 𝒐𝒓 ∑𝒊≤𝒋≤𝒏 𝒂𝒋 𝒂𝒎 +𝒂𝒎+𝟏 + 𝒂𝒎+𝟐, + 𝒂𝒎+𝟑 + ⋯ + 𝒂𝒏 . The variable j is called the index of summation , and the choice of the letter j as the variable is arbitrary ; that is , we could have used any other letter ,such as I or k, in notation ∑𝒏𝒋=𝒎 𝒂𝒋 = ∑𝒏𝒊=𝒎 𝒂𝒊 = ∑𝒏𝒌=𝒎 𝒂𝒌 Here , the index of summation runs through all integers starting with lower limit m and ending with its upper limit n. Example(1): Express the sum of the first 100 terms of the sequence {𝒂𝒏 }, where 𝒂𝒏 = 𝟏 𝒏 , for n = 1 ,2 , 3, … Solution: The lower limit for the index of summation is 1 , and the upper limit is 100 .We write the sum as: ∑𝟏𝟎𝟎 𝒋=𝟏 𝟏 𝒋 . Example(2): What is the value of : ∑𝟓𝒋=𝟏 𝒋𝟐 ? Solution: ∑𝟓𝒋=𝟏 𝒋𝟐 = 𝟏𝟐 + 𝟐𝟐 + 𝟑𝟐 + 𝟒𝟐 + 𝟓𝟐 = 1+4+9+16+25 =55. Example (3): What is the value of : ∑𝟖𝒌=𝟒 (−𝟏)𝒌 ? Solution : ∑𝟖𝒌=𝟒 (−𝟏)𝒌 = (−𝟏)𝟒 + (−𝟏)𝟓 + (−𝟏)𝟔 + (−𝟏)𝟕 + (−𝟏)𝟖 = 1+(-1 )+1+(-1)+ 1 = 1. Example (4): Suppose we have the sum : ∑𝟓𝒋=𝟏 𝒋𝟐 But we want the index of summation to run from 0 and 4 rather than 1 to 5 . To do this ,we let k= j-1 . Then the new summation index runs from 0 to 4 , and the term 𝒋𝟐 becomes (𝒌 + 𝟏)𝟐 . Hence , 151 ∑𝟓𝒋=𝟏 𝒋𝟐 = ∑𝟒𝒌=𝟎 (𝒌 + 𝟏)𝟐 . It is easily checked that both sums are 1+4+9+16+25 = 55. Theorem(1): (Formula for the sum of terms of geometric progression). 𝒂𝒓𝒏+𝟏 −𝒂 ∑𝒏𝒋=𝟎 𝒂𝒓𝒋 , 𝒊𝒇 𝒓 ≠ 𝟏 = { 𝒓−𝟏 (𝒏 + 𝟏)𝒂 , 𝒊𝒇 𝒓 = 𝟏 Example(5):(Double summations) ∑𝟒𝒊=𝟏 ∑𝟑𝒋=𝟏 𝒊 𝒋. To evaluate the double sum, first expand the inner summation and then continue by computing the outer summation : 𝟒 𝟑 𝟒 𝟒 ∑ ∑ 𝒊 𝒋 = ∑(𝒊 + 𝟐𝒊 + 𝟑𝒊) = ∑ 𝟔𝒊 = 𝟔 + 𝟏𝟐 + 𝟏𝟖 + 𝟐𝟒 = 𝟔𝟎 . 𝒊=𝟏 𝒋=𝟏 𝒊=𝟏 𝒊=𝟏 Exercises: 1) What are the terms 𝒂𝟎 , 𝒂𝟏 , 𝒂𝟐 , 𝒂𝒏𝒅 𝒂𝟑 of the sequence { 𝒂𝒏 } Where 𝒂𝒏 equals : (a) 𝟐𝒏 + 𝟏? (b) (n +1)𝒏+𝟏 ? (c) ⌊𝒏⁄𝟐⌋ ? (d) ⌊𝒏⁄𝟐⌋ + ⌈𝒏⁄𝟐⌉ ? 2) What are the terms 𝒂𝟎 , 𝒂𝟏 , 𝒂𝟐 , and 𝒂𝟑 of the sequence : { 𝒂𝒏 } Where 𝒂𝒏 equals : (a) (-2)𝒏 ? (b) 3 ? (c) 7 + 𝟒𝒏 ? (d) 𝟐𝒏 + (− 𝟐)𝒏 ? 3) List the first 10 terms of each of these sequences : (a) The sequence that begins with 2 and in which each successive term is 3 more than preceding term. (b) The sequence that lists each positive integer three times , in increesing order . 152 (c) The sequence that lists the odd positive integers in increasing order , listing each odd integer twice . (d) The sequenc whose nth term is 𝒏! − 𝟐𝒏 . 4) List the first 10 terms of these sequences : (a) The sequence obtained by starting with 10 and obtaining each term by subtracting 3 from the previous term. (b) the sequence whose nth term is the sum of the first n positive integers . (c) The sequence whose nth term is 𝟑𝒏 − 𝟐𝒏 . (d) The sequence whose terms are constructed sequentially as follows : start with 1 , then add 1 , then multiply 1 , then add 2 , then multiply by 2 , and so on. 5) What are the values of these sums : (a)∑𝟓𝒌=𝟏(𝒌 + 𝟏) (b) ∑𝟒𝒋=𝟎(−𝟐)𝒋 (c) ∑𝟏𝟎 𝒊=𝟏 𝟑 (d) ∑𝟖𝒋=𝟎(𝟐𝒋+𝟏 − 𝟐𝒋 ) 6) Compute each of these double sums: (a) ∑𝟐𝒊=𝟏 ∑𝟑𝒋=𝟏( 𝒊 + 𝒋) (b) ∑𝟐𝒊=𝟎 ∑𝟑𝒋=𝟎( 𝟐𝒊 + 𝟑𝒋) (c) ∑𝟑𝒊=𝟏 ∑𝟐𝒋=𝟎 𝒊 ∑𝟐𝒊=𝟎 ∑𝟑𝒋=𝟏 𝒊𝒋 153 6. 5. Discrete Probability: 6.5.1: Random variables and sample spaces: Def.(1): Suppose we have an experiment whose outcome depends on chance .We represent the outcome of the experiment by a capital letter ,such that as X called a random variable . The sample space of the experiment is the set of all possible outcomes . If the sample space is either finite or countable infinite , the random variable is called discrete . We generally denote a sample space by the capital Greek letter 𝛀 . Example(1): A die is rolled once , let X denote the out come of this experiment is the 6- element set , 𝛀 = { 1 , 2 , 3 , 4 , 5 , 6 } where each outcome i , for i = 1 , … ,6 correspond to the number of dots on the face which turns up . The event E = { 2 ,4 , 6 }corresponds to the statement that the result is an even number . The event E can also be described by saying that X is even . Unless there is reason to believe the die is loaded , the natural assumption is that every outcome is equally likely . A dopting this convention means that we assign a probability of i. e , m(i) = 𝟏 𝟔 𝟏 𝟔 to each of the outcomes, for 1≤ 𝒊 ≤ 𝟔. Example (2): Consider an experiment in which a coin is tossed twice . Let X be the random variable which corresponds to theis experiment . We note that there are several ways to record the 154 outcomes of this experiment . We could , for example record the two tosses , in the order in which they occurred . In this case , we have 𝛀 = { HH , HT , TH , TT }. We also could record the outcomes by simply noting the number of heads that appeard. In this case , we have 𝛀 = { 0 , 1 , 2 }. Finally , we could record the two outcomes , outcomes , without regard to the order in which they occurred . In this case , we have 𝛀 = { HH , HT , TT }. We will use , for the moment , the first of the sample spaces given above , we will assume that all four outcomes are generally likely , and define the distribution function m( 𝒘) by : m(HH) = m(HT) = m(TH) = m(TT) = 𝟏 𝟒 Let E = { HH , HT, TH } be the event that at least one head comes up .. Then , the probability of E can be calculated as follows: P(E) = m(HH) + m(HT) +m(TH) = 𝟏 𝟒 + 𝟏 𝟒 + 𝟏 𝟒 = 𝟑 𝟒 Similarly , if F = { HH , HT } is the event that heads comes up on the first toss , then we have : P(F) = m(HH) + m(HT) = 𝟏 𝟒 + 𝟏 𝟒 = 𝟏 𝟐 Example (3): Three people A, B and C , are running for the office , and we assume that one and only one of them wins . The sa sample space may be taken as the 3- element set 𝛀= { A , B , C}. 155 Where each element corresponds to the outcome of that candidates winning , suppose that A and B have the same chance of winning , but C has only 𝟏 𝟐 the chance of A and B . Then we assign : m(A) = m(B) =2 m( C) since m(A) + m(B)+m(C)= 1, we see that 5m(C) =1 . Hence m(A) = 𝟐 𝟓 , m(B) = 𝟐 𝟓 , m(C) = 𝟏 𝟓 . Let E be the event that either A or C wins , then E = { A ,C } and P(E) = m(A) + m(C) = 𝟐 𝟓 + 𝟏 𝟓 = 𝟑 𝟓 . Theorem(1) : The probabilities assigned to events by a distribution function on a sample space 𝛀 satisfy the following properties : (1) 𝟎 ≤ 𝑷(𝑬) ≤ 𝟏 , ∀ 𝑬 ⊂ 𝛀 . (2) P(𝛀) = 𝟏. (3) If E ⊆ 𝑭 ⊆ 𝛀 , then P(E) ≤ P(F) . (4) If A and B are disjoint subsets of 𝛀 , then P(A∪ 𝑩) = P(A) + P(B). ̅ ) = 1 – P(A) , ∀ 𝑨 ⊂ 𝛀 . (5) P( 𝑨 Theorem(2): If 𝑨𝟏 , 𝑨𝟐 , 𝑨𝟑 , … , 𝑨𝒏 are pairwise disjoint subsets of 𝛀 , then P( 𝑨𝟏 ∪ 𝑨𝟐 ∪ 𝑨𝟑 ∪ … ∪ 𝑨𝒏 ) = ∑𝒏𝒊=𝟏 𝑷(𝑨𝒊 ). 156 Theorem(3): Let 𝑨𝟏 , 𝑨𝟐 , 𝑨𝟑 , … , 𝑨𝒏 be pairwise disjoint events with 𝛀 = 𝑨𝟏 ∪ 𝑨𝟐 ∪ 𝑨𝟑 ∪ … ∪ 𝑨𝒏 and let E be any event . Then P(E) = ∑𝒏𝒊=𝟏 𝑷(𝑬 ∩ 𝑨𝒊 ). Corrllary: For any two event A and B ̅) . P(A) = P(𝑨 ∩ 𝑩) + P(𝑨 ∩ 𝑩 Theorem(4): If A and B are subsets of 𝛀 , then P( A∪ 𝑩) = P(A) + P(B) – P(𝑨 ∩ 𝑩). Exercises: 1) Let 𝛀 = { a , b , c } be a sample space , let m(a) = and m(c) = 𝟏 𝟔 𝟏 𝟐 , m(b) = 𝟏 𝟑 . Find the probabilities of all eight subsets of 𝛀 . 2) Describe in words the events specified by the following subsets of 𝛀 = { HHH , HHT , HTH , HTT, THH , THT, TTH , TTT } a) E = { HHH , HHT , HTH , HTT}. b) E = { HHH, TTT}. c) E = { HHT, HTH , THH}. d) E = { HHT, HTH , HTT, THH, THT ,TTH}. 3) What are the probabilities of the events described in 157 exercise (2)? 4) Let A and B be events such that P(𝑨 ∩ 𝑩) = and P(B) = 𝟏 𝟐 𝟏 𝟒 ̅) = , 𝑷(𝑨 𝟏 𝟑 .What is P( A∪ 𝑩) ? 6.6 Permutations and Combinations: 6.6.1 Permutations: Example (8): In how many ways can we select three students from a group of five students to stand in line for a picture? Solution: There are 5 ways to select the first student to stand at the start of the line there are 4 ways to select the 2nd student there are 3 ways to select the 3rd student in the line. Hence there are 5 – 4 – 3 = 50 ways to select three students from a group of 5 students to stand for a picture. Example (9): Let S = {1, 2, 3}. There ordered arrangement 3,1,2 is a permutation of S. The ordered arrangement 3,2 is a 2 – permutation of S. The number of r-permutations of a set with n elements is denoted by P(n,r). Theorem(2): 𝒏! If n and r are integers with 𝟎 ≤ 𝒓 ≤ then 𝑷(𝒏, 𝒓) = (𝒏−𝒓)! Example (10): How many ways are there to select a first-prize winner, a second-prize winner, and a third-prize winner from 100 different people who have entered a contest? 158 Solution : The number of 3-permutations of a set of 100 elements. 𝟏𝟎𝟎! 𝑷(𝟏𝟎𝟎, 𝟑) = (𝟏𝟎𝟎−𝟑)! = = 𝟏𝟎𝟎.𝟗𝟗.𝟗𝟗.𝟗𝟖.𝟗𝟕! 𝟗𝟕! 𝟏𝟎𝟎! 𝟗𝟕! = 𝟗𝟕𝟎𝟐𝟎𝟎 Example (11): Suppose that there are eight runners in a race. The winner receives a gold medal, the second-place finisher receives a silver medal, and the third-place finisher receives a bronze medal. How many different ways are there to a word these medals, if all possible outcomes of the race can occur and there are no ties? Solution: The number of different ways to a word the medals is the number of 3-penmutations of a set with 8 elements. Hence there are 𝑷(𝟖, 𝟑) = 𝟖! 𝟓! = 336 possible ways to a ward the medals. 6.6.2 Combinations: Def .(1): The number of r-combinations of a set with n distinct 𝒏 elements is denoted by 𝑪(𝒏, 𝒓) = ( ). 𝒓 Example (12): c(4,2) = 4! Theorem (3): The number of r-combinations of a set with n elements, where n is a nonnegative integer and r is an integer 𝟎 ≤ 𝒓 ≤ 𝒏 equals 𝑪(𝒏, 𝒓) = 𝒏! 𝒓! (𝒏 − 𝒓)! Proof : 𝑷(𝒏, 𝒓) = 𝒏! 𝒓!(𝒏−𝒓)! 159 𝑪(𝒏, 𝒓) = 𝑷(𝒏,𝒓) 𝑷(𝒓−𝒓) = 𝒏!(𝒏−𝒓)! 𝒓!/(𝒓−𝒓)! = 𝒏! 𝒓!(𝒏−𝒓)! Example (13): How many poker hands of five cards can be dealt from a standard deck of 52 cards? Also, How many ways are there to select 37 cards from a standard deck of 52 cards? Solution: The order in which the 5 cards are dealt from a deck of 52 cards does not matter, are 1) 𝑪(𝟓𝟐, 𝟓) = 𝟓𝟐! 𝟓!.𝟒𝟕! 2) 𝑪(𝟓𝟐, 𝟒𝟕) = = 𝟓𝟐! 𝟒𝟕!.𝟓! 𝟓𝟐.𝟓𝟏.𝟓𝟎.𝟒𝟗.𝟒𝟖.𝟒𝟕! 𝟓.𝟒.𝟑.𝟐.𝟏.𝟒𝟕! = 𝟐𝟓𝟗𝟖𝟗𝟔𝟎 = = 𝟐𝟓𝟗𝟖𝟗𝟔𝟎 Corollary(1): Let n and r be nonnegative integers 𝒓 ≤ 𝒏. Then 𝒄(𝒏, 𝒓) = 𝒄(𝒏, 𝒏 − 𝒓) Proof: From theorem (2) it follows that 𝒄(𝒏, 𝒓) = 𝒏! 𝒓! (𝒏 − 𝒓) 𝒏! 𝒏! and 𝒄(𝒏, 𝒏 − 𝒓) = (𝒏−𝒓!)(𝒏−(𝒏−𝒓))! = (𝒏−𝒓)!.𝒓! Hence, 𝒄(𝒏, 𝒓) = 𝒄(𝒏, 𝒏 − 𝒓) Example (14): How many ways are there to select 5 players from a 10-member tennis team to make a trip to match at another school? Solution: By theorem (2) 𝒄(𝟏𝟎, 𝟓) = 𝟏𝟎! = 𝟐𝟓𝟐 𝟓! 𝟓! 6.6.3 The Binomial Theorem: The expansion of (𝒙 + 𝒚)𝟑 = (𝒙 + 𝒚)(𝒙 + 𝒚)(𝒙 + 𝒚) = 𝒙𝟑 + 𝒙𝟐 𝒚 + 𝒙𝟐 𝒚 + 𝒙𝒚𝟐 + 𝒚𝒙𝟐 + 𝒙𝒚𝟐 + 𝒙𝒚𝟐 + 𝒚𝟑 160 = 𝒙𝟑 + 𝟑𝒙𝟐 𝒚 + 𝟑𝒙𝒚𝟐 + 𝒚𝟑 Theorem (4): (The Binomial Theorem) Let x and y be variables, and let n be a non negative integer. Then 𝒏 𝒏 (𝒙 + 𝒚)𝒏 = ∑ ( 𝒋 ) 𝒙𝒏−𝒋 𝒚𝒋 𝒋=𝟎 𝒏 𝒏 𝒏 𝒏 = ( ) 𝒙𝒏 + ( ) 𝒙𝒏−𝟏 𝒚 + ( ) 𝒙𝒏−𝟐 𝒚𝟐 + ⋯ + ( ) 𝒚𝒏 𝟎 𝒏 𝟏 𝟐 Proof: Using the mathematical induction form: 𝒏 Let p(n)= (𝒙 + 𝒚)𝒏 , 𝒑(𝒏) = ∑𝒏𝒋=𝟎 ( 𝒋 ) 𝒙𝒏−𝒋 𝒚𝒋 Basic step: 1) Let n = 1, p(1) = (𝒙 + 𝒚)𝟏 = 𝒙 + 𝒚 p(1) is true. 𝐦 𝐦−𝐣 𝐣 2) Assume that 𝐩(𝐦) = (𝐱 + 𝐲)𝐦 = ∑𝐦 𝐲 is true ( 𝐣−𝟎 𝐣 ) 𝐱 3) The inductive step 𝒑(𝒎) → 𝒑(𝒎 + 𝟏) 𝒑(𝒎 + 𝟏) = (𝒙 + 𝒚)𝒎+𝟏 = (𝒙 + 𝒚)(𝒙 + 𝒚)𝒎 𝒎 𝒎 = (𝒙 + 𝒚) ∑ ( 𝒋 ) 𝒙𝒎−𝒋 𝒚𝒋 𝒋=𝟎 𝒎 𝒎 𝒋=𝟎 𝒋=𝟎 𝒎 𝒎 = ∑ ( 𝒋 ) 𝒙𝒎−𝒌+𝟏 𝒚𝒋 + ∑ ( 𝒋 ) 𝒙𝒎−𝒋 𝒚𝒋+𝟏 𝒎 𝒎−𝟏 𝒋=𝟏 𝒋=𝟏 𝒎 𝒎 𝒎 𝒎 = ( ) 𝒙𝒎+𝟏 ∑ ( 𝒋 ) 𝒙𝒎−𝟏+𝒋 𝒚𝒋 + ∑ ( 𝒋 ) 𝒙𝒎−𝒋 𝒚𝒋+𝟏 + ( ) 𝒚𝒎+𝟏 𝟎 𝒎 𝒎 𝒎 𝒋=𝟏 𝒋=𝟏 𝒎 𝒎 = 𝒙𝒎+𝟏 ∑ ( 𝒋 ) 𝒙𝒎+𝟏−𝒋 𝒚𝒋 + ∑ (𝒋 − 𝟏) 𝒙𝒎+𝟏−𝒋 𝒚𝒋 + 𝒚𝒎+𝟏 161 𝒎 𝒎 𝒎 = 𝒙𝒎+𝟏 ∑ [( 𝒋 ) ∗ (𝒋 − 𝟏)] 𝒙𝒎+𝟏−𝒋 𝒚𝒋 + 𝒚𝒎+𝟏 𝒋=𝟏 𝒎 𝒎 + 𝟏 𝒎+𝟏−𝒋 𝒎 + 𝟏 𝒎+𝟏 𝒎 + 𝟏 𝒎+𝟏 =( + ∑( +( )𝒙 )𝒙 )𝒚 𝒋 𝒎+𝟏 𝒐 𝒋=𝟏 𝒎+𝟏 = ∑( 𝒋=𝟎 𝒎 + 𝟏 𝒎+𝟏−𝒋 𝒋 𝒚 )𝒙 𝒋 Hence p(m+1) is true P(n) is true, ∀𝒏 ∈ 𝜨 Example (15): What is the expansion of (x+y)4? Solution: From the Binomial theorem 𝟒 𝟒 (𝒙 + 𝒚)𝟒 = ∑ ( ) 𝒙𝟒−𝒋 𝒚𝒋 𝒋 𝒋=𝟎 𝟒 𝟒 𝟒 𝟒 𝟒 = ( ) 𝒙𝟒 + ( ) 𝒙𝟑 𝒚 + ( ) 𝒙𝟐 𝒚𝟐 + ( ) 𝒙𝒚𝟑 + ( ) 𝒚𝟒 𝟎 𝟏 𝟐 𝟑 𝟒 = 𝒙𝟒 + 𝟒𝒙𝟑 𝒚 + 𝟔𝒙𝟐 𝒚𝟐 + 𝟒𝒙𝒚𝟑 + 𝒚𝟒 Example (16): What is the coefficient of 𝒙𝟏𝟐 𝒚𝟏𝟑 in the expansion of (𝒙 + 𝒚)𝟐𝟓? Solution: From the Binomial theorem it follows that this coefficient is 𝟐𝟓! 𝟐𝟓 = 𝟓𝟐𝟎𝟎𝟑𝟎𝟎 ( )= 𝟏𝟑 𝟏𝟑!. 𝟏𝟐! Example (17): What is the coefficient of 𝒙𝟏𝟐 𝒚𝟏𝟑 in the expansion of (𝟐𝒙 − 𝟑𝒚)𝟐𝟓? Solution: (𝟐𝒙 − 𝟑𝒚)𝟐𝟓 = (𝟐𝒙 + (−𝟑𝒚)) 162 𝟐𝟓 𝟐𝟓 ∴ (𝟐𝒙 + (−𝟑𝒚)) 𝟐𝟓 = ∑( 𝒋=𝟎 𝟐𝟓 ) (𝟐𝒙)𝟏𝟐 (−𝟑𝒚)𝟏𝟑 𝒋 The coefficient of 𝒙𝟏𝟐 𝒚𝟏𝟑 in the expansion is obtained when j = 13, namely 𝟐𝟓! 𝟐𝟓 𝟐𝟏𝟑 . 𝟑𝟏𝟑 ( ) 𝟐𝟏𝟐 (−𝟑)𝟏𝟑 = − 𝟏𝟑 𝟏𝟑!. 𝟏𝟐! Corollary (2): Let n be nonnegative integer, then 𝒏 𝒏 ∑ ( ) = 𝟐𝒏 𝒌 𝒌=𝟎 Proof: Using the Binomial theorem with x = 1 and y = 1, we see that 𝒏 𝒏 𝒌=𝟎 𝒌=𝟎 𝒏 𝒏 𝟐𝒏 = (𝟏 + 𝟏)𝒏 = ∑ ( ) 𝟏𝒌 . 𝟏𝒏−𝒌 = ∑ ( ) 𝒌 𝒌 Corollary (3): Let n be a positive integer, then 𝒏 𝒏 ∑(−𝟏)𝒌 ( ) = 𝟎 𝒌 𝒌=𝟎 Proof: Using the Binomial theorem with x = -1 and y = 1, we see 𝒏 𝒏 that 𝟎 = 𝟎𝒏 = ((𝟏 − 𝟏) + 𝟏) = ∑𝒏𝒌=𝟎 ( ) (−𝟏)𝒌 𝟏𝒏−𝒌 𝒌 𝒏 𝒏 = ∑ ( ) (−𝟏)𝒌 𝒌 𝒌=𝟎 Corollary (4): Let n be a nonnegative integer, then 𝒏 𝒏 ∑ 𝟐𝒌 ( ) = 𝟑𝒏 𝒌 𝒌=𝟎 𝒏 𝒏 Proof: 𝟑𝒏 = (𝟏 + 𝟐)𝒏 = ∑𝒏𝒌=𝟎 ( ) 𝟏𝒏−𝒌 𝟐𝒌 = ∑𝒏𝒌=𝟎 ( ) 𝟐𝒌 𝒌 𝒌 163 Theorem (5) : Pascal’s identity Let n and k be positive integers with 𝒏 ≥ 𝒌, then ( 𝒏 𝒏 𝒏+𝟏 )=( )+( ) 𝒌−𝟏 𝒌 𝒌 Example(18): Prove the identity: 𝒏+𝟐 𝒏+𝒌 𝒏+𝒌+𝟏 (𝒏𝟎) + (𝒏+𝟏 ) + ( ) + ⋯ + ( ) = ( )……..(*) 𝟏 𝟐 𝒌 𝒌 Proof: We use the mathematical induction on k. If k = 0 (Basis step): The identity just says 1=1 So it is trivially true.( we can check it also for k = 1). n+1 = n+1 The inductive step: Assume that the identity (*) is true for a given value k We want to prove that it also holds for k+1 in place of k , we want to prove that: 𝒏+𝟐 𝒏+𝒌 𝒏 𝒏+𝒌+𝟐 (𝒏𝟎) + (𝒏+𝟏 ) + ( ) + ⋯ + ( ) + ( ) = ( ) 𝟏 𝟐 𝒌 𝒌+𝟏 𝒌+𝟏 Here the sum of the first k terms on the left hand side is: (𝒏+𝒌+𝟏 ) by induction hypothesis , and so the 𝒌 left hand side equal to (𝒏+𝒌+𝟏 ) + (𝒏+𝒌+𝟏 ) 𝒌 𝒌+𝟏 But this is indeed equal to (𝒏+𝒌+𝟐 ) 𝒌+𝟏 164 By the fundamental property of Pascal triangle this complete the proof by induction. 6.7. Pascal’s triangle: 1 11 121 1331 14641 1 5 10 10 5 1 1 6 15 20 15 61 1 7 21 35 35 21 71 1 8 28 36 70 56 2881 (b) (a) 6.8. 1 Recurrence Relations: Def.(1): A recurrence relation for the sequence {𝒂𝒏 } is an equation that express 𝒂𝒏 in terms of one or more of the previous terms of the sequence , namely , 𝒂𝟎 , 𝒂𝟏 , 𝒂𝟐 , … , 𝒂𝒏−𝟏 , for all integers n with n ≥ 𝒏𝟎 , where 𝒏𝟎 is non negative integer . A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation . 165 Example(1): Let {𝒂𝒏 } be a sequence that satisfies the recurrence relation 𝒂𝒏 = 𝒂𝒏−𝟏 − 𝒂𝒏−𝟐 𝒇𝒐𝒓 𝒏 = 𝟐, 𝟑 , 𝟒 , … , and suppose that 𝒂𝟎 = 𝟑 𝒂𝒏𝒅 𝒂𝟏 = 𝟓 . What are 𝒂𝟐 𝒂𝒏𝒅 𝒂𝟑 ? Solution : We see from the recurrence relation that 𝒂𝟐 = 𝒂𝟏 − 𝒂𝟎 = 𝟓 − 𝟑 = 𝟐 𝒂𝒏𝒅 𝒂𝟑 = 𝒂𝟐 − 𝒂𝟏 = 𝟐 − 𝟓 = −𝟑 We can find 𝒂𝟒 𝒂𝒏𝒅 𝒂𝟓 , and each successive term in a similar way. Example (2): The recurrence relation 𝑷𝒏 = (𝟏. 𝟏𝟏)𝑷𝒏−𝟏 is a linear homogenous relation of degree one . The recurrence relation 𝑭𝒏 = 𝑭𝒏−𝟏 + 𝑭𝒏−𝟐 The recurrence relation 𝒂𝒏 = 𝒂𝒏−𝟓 is a linear homogenous recurrence relation of degree five. Example(3): Determine whether the sequence {𝒂𝒏 } , where 𝒂𝒏 = 𝟑𝒏 𝒇𝒐𝒓 𝒆𝒗𝒆𝒓𝒚 nonnegative integer n , is a solution of the recurrence relation 𝒂𝒏 = 𝟐 𝒂𝒏−𝟏 – 𝒂𝒏−𝟐 𝒇𝒐𝒓 𝒏 = 𝟐 , 𝟑 , 𝟒 …. 𝑨𝒏𝒔𝒘𝒆𝒓 the same question where 𝒂𝒏 = 𝟐𝒏 and 𝒂𝒏 = 𝟓. Solution: Suppose that 𝒂𝒏 = 𝟑𝒏 for every nonnegative integer n.Then , for n ≥ 𝟐 , we see that 2 𝒂𝒏−𝟏 − 𝒂𝒏−𝟐 = 𝟐 [𝟑(𝒏 − 𝟏)] − 𝟑 (𝒏 − 𝟐) = 𝟑𝒏 = 𝒂𝒏 Therefore, {𝒂𝒏 } , where 𝒂𝒏 = 𝟑𝒏 , 𝐢𝐬 𝐚 𝐬𝐨𝐥𝐮𝐭𝐢𝐨𝐧 for the recurrence relation . 166 Suppose that 𝒂𝒏 = 𝟐𝒏 for every nonnegative integer n . Note that 𝒂𝟎 = 𝟏, 𝒂𝟏 = 𝟐 , 𝐚𝐧𝐝 𝒂𝟐 = 𝟒. Because 𝟐𝒂𝟏 − 𝒂𝟎 = 2.2 -1=3 ≠ 𝒂𝟐 , we see that {𝒂𝒏 }, where 𝒂𝒏 = 𝟐𝒏 , is not a solution of the recurrence relation. Suppose that 𝒂𝒏 = 𝟓 for every nonnegative integer n . Then for n ≥ 𝟐 , we see that 𝒂𝒏 = 𝟐𝒂𝒏−𝟏 − 𝒂𝒏−𝟐 = 𝟐. 𝟓 − 𝟓 = 𝟓 = 𝒂𝒏 . Therefore , {𝒂𝒏 }, where 𝒂𝒏 = 𝟓 ,is a solution of the recurrence relation. Example (4):The recurrence relation 𝒂𝒏 = 𝒂𝒏−𝟏 − 𝒂𝟐 𝒏−𝟐 is non linear . The recurrence relation 𝑯𝒏 = 𝟐𝑯𝒏−𝟏 + 𝟏 is not homogeneous. The recurrence relation 𝑩𝒏 = 𝒏𝑩𝒏−𝟏 does not have constant coefficients. Example(5): an = 2 an-1 + 3 an-2 and a0 = a1 = 1 Solution by use of the characteristic equation: 1. Substitute rn for an (rn-1 for an-1, etc.) and simplify the result. For this example the characteristic equation is rn = 2rn-1 + 3rn-2 which simplifies to: r2 = 2r + 3 2. Find the roots of the characteristic equation: r2 - 2r - 3 = 0 factors as (r - 3)(r + 1) giving roots r1 = 3 and r2 = -1 When there are two distinct roots, the general form of the solution is: an = 1•r1n + 2•r2n where 1 and 2 are constants. In this case, we have: an = 1•3n + 2•(-1)n 167 3. Using the initial conditions we can find the constants 1 and 2 a 0 = 1 = 1 + 2 a1 = 1 = 31 - 2 so 1 = 1/2 and 2 = 1/2 and the final solution is an = (1/2)•3n + (1/2)•(-1)n. If a characteristic equation has equal roots, (i.e. r1 =r2), then the general solution has the form: an = 1•rn + 2•n•rn Example( 6): an = 2an-2 – an-4 with a0 = 0, a1 = -2, a2 = 4 and a3 = -4. In this case, we have a degree four linear homogeneous recurrence whose characteristic equation is r4 = 2 r2 - 1 or r4 -2 r2 + 1 = 0. This factors as: (r2 - 1)( r2 - 1) = 0 so the roots are r1 = r2 = 1 and r3 = r4 = -1. (The order of the roots is arbitrary.) Note there are two pairs of equal roots so there will be two terms each with n as a factor. The form of the general solution is: an = 1•r1n + 2•n•r2n + 3•r3n + 4•n•r4n Setting up the equations we have: a 0 = 0 = 1 + 3 a1 = -2 = 1 + 2 - 3 - 4 168 a2 = 4 = 1 + 22 + 3 + 24 a3 = -4 = 1 +32 - 3 - 34 so 1 = -1/2, 2 = 1/2, 3 = 1/2 and 4 = 3/2 and the final solution is: an = (-1/2)•1n + (1/2)•n•1n + (1/2)• (-1)n + (3/2)•n•(-1)n = -1/2 + n/2 + (1/2)•(-1)n + (3/2)•n•(-1)n Example( 7): Draw n straight lines on a paper so that every pair of lines intersect, but no three lines intersect at a common point. Determine how many regions the plane is divided into if n lines are used. (Draw yourself some pictures.) If n = 0 then there is 1 region. If n = 1 there are 2 regions. If n = 2 there are 4 regions. If n = 3 there are 7 regions. In general, the nth line intersects n -1 others and each intersection subdivides a region, so the number of regions that are subdivided by the nth line is: 1 before the first line, 1 after the last line, and n - 2 regions between the n -1 lines. This gives us the following recurrence relation: an = an-1 + n This can be solved iteratively by backward substitution. Specifically, = an-2 + (n - 1) + n = an-3 + (n - 2) + (n - 1) + n 169 • • • = a0 + 1 + 2 + ... + (n - 2) + (n - 1) + n = a0 + i = 1 + n(n + 1)/2 Example( 8): Consider the relation an2 = 5(an-1) 2 where an > 0 and a0 = 2. Make the following change of variable: let bn = an2. Then, b0 = 4 and bn = 5 bn-1. Since this is a geometric series, its solution is bn = 4•5n. Now substituting back, an = √bn = 2√5n for n 0. 6.8.2.Inhomogeneous Recurrence Relations: We now turn to inhomogeneous recurrence relations and look at two distinct methods of solving them. These recurrence relations in general have the form an = cn-1an-1 + g(n) where g(n) is a function of n. (g(n) could be a constant) One of the first examples of these recurrences usually encountered is the tower of Hanoi recurrence relation: H(n) = 2H(n-1) + 1 which has as its solution H(n) = 2n – 1. One way to solve this is by use of backward substitution as above. We’ll see another method shortly. Example( 9): Consider the Tower of Hanoi recurrence: H(n) = 2H(n1) + 1 with H(1) = 1. The solution to the homogeneous part is •2n. Since g(n) = 1 is a constant, the particular solution has the form 170 p(n) = . Substituting into the original recurrence to solve for we get: = 2 +1 so that = -1. Thus, p(n) = -1. This means that H(n) = •2n – 1. Using the fact that H(1) = 1, gives 1 = •2 –1 so = 1. Thus, the solution to the original recurrence is H(n) = 2n – 1. (Note that alternative ways to get this solution are backward substitution and the method shown below.) Example( 10): an = 2an-1 + n2 with a1 = 3. The homogeneous part an = 2an-1 has a root of 2, so f(n) = •2n. The particular solution should have the form an = 2•n2 + 1•n + 0. Substituting this into the original recurrence gives 2n2 + 1n + 0 = 2[2(n-1)2 + 1(n-1) + 0] + n2. Expanding and combining like terms gives us 0 = n2(2 + 1) + n(-42 + 1) + (22 - 21 + 0). Notice that each parenthesized expression must evaluate to 0 since the left hand side of the equation is 0. This gives us the following values for the constants: 2 = -1, 1 = -4 and 0 = -6. Thus, p(n) = -n2 -4n - 6. Then we have an = •2n -n2 -4n - 6. This gives us = 7 and the final solution is an = 7•2n -n2 - 4n - 6. If g(n) consists of two or more terms, then each term is handled separately using the table above. For example, solving an = 3 an-1 + 6n – 2n, requires finding particular solutions for two recurrences— an = 3 an-1 + 6n and an = 3 an-1 – 2n. 171 There is one case in which the particular solutions above will not work. This happens when the particular solution is a solution of the homogeneous recurrence. Then, the particular solution that should be tried is a higher degree polynomial. For example. if g(n) = dn and d is a solution of the homogeneous part then try •n•dn as the particular solution. Example( 11): an = 3an-1 + 2n with a1 = 5. The homogeneous part an = 3an-1 has a root of 3, so f(n) = •3n. The particular solution should have the form an = •2n. Substituting this into the original recurrence gives •2n = 3 •2n-1 + 2n. Solving this equation for gives us the particular solution p(n) = -2n+1. Thus the solution has the form an = •3n - 2n+1. Using the initial condition that a1 = 5 we get 5 = 3 - 4 which gives = 3. Thus, the final solution is an = 3n+1 - 2n+1. 6.8.3 A nother method of solving inhomogeneous recurrence relations: Let’s consider the Tower of Hanoi recurrence again: H(n) = 2H(n-1) + 1 or H(n) – 2H(n-1) = 1. Substitute n – 1 for n in this equation to get H(n-1) – 2 H(n-2) = 1. Notice what happens if we subtract the second equation from the first: H(n) – 2H(n-1) – H(n-1) +2H(n-2) = 1 – 1, or H(n) – 3H(n-1) + 2H(n-2) = 0, a homogeneous linear recurrence relation. The characteristic equation x2 – 3x + 2 = 0 factors as (x-2)(x-1) = 0 so the general form of the solution is H(n) = 1• 2n + 2•1n = 1• 2n + 2. Using the initial conditions to obtain the constants we find that 1 = 1 and 2 = -1 and thus we have 172 H(n) = 2n – 1 as we found before. Example (12): an – an-1 = 2n with a0 = 0 Using the same method as above we find that an-1 - an-2 = 2(n-1). Now, subtracting we get an – an-1 = 2n -an-1 + an-2 = -2(n-1) an -2an-1 + an-2 = 2 This is not yet a homogeneous recurrence but one more application of the method will give us a linear homogeneous recurrence relation. an -2an-1 + an-2 =2 -an-1 + 2an-2 – an-3 = -2 an -3an-1 +3an-2 –an-3 = 0 has characteristic equation x3 – 3x2 + 3x - 1 = 0 that factors as (x – 1)3. The general form of the answer must be an = 1•1n +2•n•1n + 3•n2•1n or 1 + 2•n + 3•n2. Since a0=0 we immediately get that 1 = 0. a1 = 2 and a2 = 6 giving us 2 = 2 + 3 and 6 = 22 + 4 3. Solving for 2 and 3 we get 2 = 1 and 3 = 1 so the solution to the recurrence is an = n + n2 or n(n + 1). The same method can be used to solve recurrence relations in which g(n) is a higher order polynomial. The substitute n – 1 for n and subtract may have to be used several times, but eventually you will 173 obtain a linear homogeneous recurrence relation. (However, factoring the characteristic equation could turn into a challenge.) A similar method can be used if the function g(n) is an exponential. Example( 13): an = 3an-1 + 2n with a1 = 5. Rewriting the recurrence relation gives us an - 3an-1 = 2n. First we multiply by 2 to get 2an - 6an-1 = 2n+1. Now substitute n – 1 for n in this new equation to get: 2an-1 - 6an-2 = 2n. Now, subtracting this new recurrence from the original one we get: an - 3an-1 = 2n -2an-1 + 6an-2 = -2n an – 5an-1 + 6an-2 = 0. The characteristic equation is x2 – 5x + 6 = 0 which factors as (x - 3)(x – 2) = 0, so the answer has the form an = 1•3n + 2•2n. Using the facts that a1 = 5 and a2 = 19 we get 5 = 31 + 2 2 and 19 = 91 + 42. Solving for the constants we get: 1 = 3 and 2 = -2 giving us the solution an = 3•3n + (-2)•2n = 3n+1 – 2n+1 6.8.4 .A formula for Fibonacci numbers: 𝑭𝒏+𝟏 = 𝑭𝒏 + 𝑭𝒏−𝟏 , n= 2 ,3 ,4 ,… (*) 𝑭𝟏 = 𝟏 , 𝑭𝟐 = 𝟏 , 𝑭𝟑 = 𝟐 , 𝑭𝟒 = 𝟑 , 𝑭𝟓 = 𝟓 , 𝑭𝟎 = 𝟎 174 Using the equation (*) we can easily determine any number of terms in this sequence numbers : 0 , 1 ,1 2,3, 5,8,13,21,34, 55, 89,144, 233, 377, 610, 987,1597,… The numbers in this sequence are called Fibonacci numbers . Example(3): What is the sum of the first n Fibonacci numbers 0=0 0+1=1 0 + 1 +1 = 2 0 +1 + 1+ 2 = 4 0 + 1 +1 + 2 + 3 = 7 0 + 1 + 1 + 2 + 3 + 5 =12 0 + 1 + 1 + 2 + 3 + 5 + 8 = 20 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 = 33 ………. 𝑭𝟎 + 𝑭𝟏 + 𝑭𝟐 + 𝑭𝟑 + ⋯ + 𝑭𝒏 = 𝑭𝒏+𝟐 − 𝟏 𝑭𝟎 + 𝑭𝟏 + ⋯ + 𝑭𝒏 = (𝑭𝟎 + 𝑭𝟏 + ⋯ + 𝑭𝒏−𝟏 ) + 𝑭𝒏 = (𝑭𝒏+𝟏 − 𝟏) + 𝑭𝒏 = 𝑭𝒏+𝟐 − 𝟏 Exercises: 1)Find the value of each of these quantities: a) P(6,3) (b)P(6,5) (c) P(8,1) (d) P(8,5) e) C(5,1) (f) C(5,3) (g) C(12,6) (h) C(8,8) 2 )Find the number of 5- permutations of a set with nine elements 3) What is the row of Pascal 's triangle containing the binomial coefficients (𝟗𝒌) , 0≤ k ≤ 9 ?. 3) Find the expansion of (𝒙 + 𝒚)𝟒 . 4) What is the coefficient of 𝒙𝟖 𝒚𝟗 in the expansion of 5) (𝟑𝒙 + 𝟐𝒚)𝟏𝟕 . 175 𝒓 6) Prove that ∑ (𝒏+𝒌 ) =(𝒏+𝒓+𝟏 ). 𝒌 𝒓 𝒌=𝟎 7) Find recurrenc relations that are satisfied by the sequences formed from the following functions : (i) 𝒂𝒏 = 𝒏𝟐 − 𝟔𝒏 + 𝟖 (ii) 𝒂𝒏 = 𝒏! 𝟏𝟓! (iii) 𝒂𝒏 = 176 𝒏! [𝟏𝟓!(𝒏−𝟏𝟓 )!] for n 14 References: [1] AL Doerr, Ken Levasseur (2003) .Applied Discrete Mathematics. [2] Charles M. Grinslead Swarthamore College .Introduction to Probability. [3] James L. Hein (2003) Discrete Mathematics .Jones and Bartlett learning. [4] Kenneth H. Rosen (2007) Discrete Mathematics and its Applications . Sixth Edition . McGROW Hill. [5] Laszlo Lovasz and Katlin Vesztergombi, (1999), Discrete Mathematics Yale University. [6] L. Lovaszan K. Vesztergombi(1979).Discrete Mathematics. Elsevier ,Amesterdam. [7] Migual A.Lerma Noteson (2005). Discrete Mathematics. Northwestern University. [8] M .O. Albertson , (1988) .Discrete Mathematics with Algorithms. John Wiley and Sons [9] Richard Johnsonbough .(2007).Applied Discrete Mathematics. Prentice Hall Amazon .com. [10] Susanna S. EPP . Discrete Mathematics with Applications. Fourth Edition. De Paul University .Amazon .com. [11] Tucker,Alan,Applied combinatorics,2nd ed. [12]http://www.answers.com/topic/recurrence-relations. [13]http://mathcircle.berkeley.edu/BMC3/Bjorn1/node10htm1 177 178