47 | P a g e DISCRETE MATHEMATICS Activity 3b 1) From the graphs below, determine whether it has Euler path and Euler circuit, Euler path only, Euler circuit only or none. 2) Determine whether each of the following graphs has an Euler circuit and Euler Path. For each graph that does have an Euler circuit and Euler Path. 3) Do the graphs below have a Hamilton Path? If so, find such a path, if not, give an argument to show why no such path exist. 4) Consider the following map showing several cities and the roads connecting them. a) Is it possible for a travelling salesman to find a route which passes through each of the cities exactly once (not necessarily using all the roads) and end up where he started? a) b) a) b) a) b)
48 | P a g e DISCRETE MATHEMATICS b) Is it possible for the travelling salesman to pass through the cities using all of the roads exactly once? Explain your answers. 3.2 Follow concept of trees 3.2.1 Identify the properties of trees Tree is a graph in which any two vertices are connected by exactly one simple path. In other words, tree is a connected graph without a cycle. Each dot is called a node or a vertex. An edge is drawn as a line connecting two vertices. A tree consists of nodes with a parent-child relation. Let T be a graph with n vertices. Then the following statements are equivalent: • T is a tree; • T contains no cycles, and has n – 1 edges; • T is connected, and has n – 1 edges; • T is connected, and each edge is a bridge; • any two vertices of T are connected by exactly one path; The graphs shown in figure (a) below is tree, while those in (b) are not. (a) (b)
49 | P a g e DISCRETE MATHEMATICS 3.2.2 Describe the terminology and characteristics of trees From the figure above, the properties of trees are: • Root: node without parent (A) • Internal node: node with at least one child (A, B, C, F) • External node (leaf): node without children (E, I, J, K, G, H, D) • Ancestors of a node: parent, grandparent, grand-grandparent, etc. • Descendant of a node: child, grandchild, grand-grandchild, etc. • Height of a tree: the largest level number of a tree • Sub tree: tree consisting of a node and its descendants • Node degree is the number of children it has. • Tree degree is the maximum of node degrees. Activity 3c 1) Which of the following graphs are trees? Level 1 Level 2 Level 0 Level 3 Sub tree root B C D E F G H A I J K
50 | P a g e DISCRETE MATHEMATICS 2) A tree has precisely five vertices of degree 1 and one vertex of degree 5. a. Draw this tree. b. Find the total degrees of all the vertices in this tree. 3) Draw any two such trees, one with eight vertices and one with six vertices. 4) Each relation R is defined on the set A. In each case determine if R is a tree and if it is, find the root. a) A = { a, b, c, d, e } R = { (a, d), (b, c), (c, a), (d, e) } b) A = { a, b, c, d, e, f } R = { (a, b), (c, e), (f, a), (f, c), (f, d) } c) A = { 1, 2, 3, 4, 5, 6 } R = { (1, 1), (2, 1), (2, 3), (3, 4), (4, 5), (4, 6) } 5) Consider the tree with root V0 shown in figure below. Find: a. The level of V0 and V5 b. The height of this rooted tree c. The children of V3 d. The parent of V2 e. The siblings of V8 f. The descendants of V3 g. Tree degree of the tree 6) For a binary tree below, find the: a) height of the tree b) root c) leaves/external nodes d) siblings of 6 e) descendants of 10 f) internal nodes V2 V1 V7 V8 V9 V10 V4 V3 V6 V0 V5
51 | P a g e DISCRETE MATHEMATICS 7) Consider the complete binary tree shown below. Find the: a. Level of 10? b. Height of this rooted tree? c. Children of 6? d. Parent of 20? e. Descendants of 3? f. Ancestors of 18? 3.2.3 Explain the spanning trees A spanning tree of a graph with n vertices is a subset of n – 1 edges that form a tree. For example, the spanning trees of the cycle graph, diamond graph and complete graph are illustrated below. A minimal spanning tree is a spanning tree for which the sum of the weights of all the edges is as small as possible. Weighted graph as shown below is a graph which each edge is labelled with a numeric value, called weight. The total weight of a tree is just the sum of weights of all edges. Obviously, different trees have different lengths.
52 | P a g e DISCRETE MATHEMATICS 3.2.4 Construct the minimal spanning trees using: a) Prim Algorithm o Prim's algorithm is an algorithm that finds a minimum spanning tree for a connected weighted undirected graph. o This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. o Prim's algorithm is an example of a greedy algorithm, and the algorithm are as follows: i. Pick any vertex as a starting vertex (call it a). ii. Find the edge with smallest weight incident to a. Color the edge to the next vertex calls it b. iii. Find the edge of smallest weight incident to either a or b. Call that vertex c. iv. Repeat the step by choosing the edge of smallest weight that does not form a cycle until it spans all the vertices. The resulting subgraph is a minimum spanning tree. o For example, refer to the table below: Image Description This is our original weighted graph. The numbers near the edges indicate their weight. Vertex D has been chosen as a starting point. Vertices A, B, E and F are connected to D through a single edge. A is the vertex nearest to D and will be chosen as the second vertex along with the edge AD.
53 | P a g e DISCRETE MATHEMATICS The next vertex chosen is the vertex nearest to either D or A. B is 9 away from D and 7 away from A, E is 15, and F is 6. F is the smallest distance away, so we highlight the vertex F and the arc DF. The algorithm carries on as above. Vertex B, which is 7 away from A, is highlighted. In this case, we can choose between C, E, and G. C is 8 away from B, E is 7 away from B, and G is 11 away from F. E is nearest, so we highlight the vertex E and the arc BE. Here, the only vertices available are C and G. C is 5 away from E, and G is 9 away from E. C is chosen, so it is highlighted along with the arc EC.
54 | P a g e DISCRETE MATHEMATICS Vertex G is the only remaining vertex. It is 11 away from F, and 9 away from E. E is nearer, so we highlight it and the arc EG. Now all the vertices have been selected and the minimum spanning tree is shown in green. In this case, it has weight 39. b) Kruskal Algorithm o Kruskal's algorithm also constructs the minimum spanning tree of a graph by adding edges to the spanning tree one-by-one. o The edges are selected and added to the spanning tree in increasing order of their weights. An edge is added to the tree only if it does not create a cycle. o The beauty of Kruskal's algorithm is the way that potential cycles are detected. o Kruskal algorithm are as follows: i. Find the edge in the graph with smallest weight (if there is more than one, pick one at random). ii. Find the next edge in the graph with smallest weight that doesn't close a cycle. Color that edge and the next incident vertex. iii. Repeat Step 2 until you reach out to every vertex of the graph. The chosen edges form the desired minimum spanning tree.
55 | P a g e DISCRETE MATHEMATICS o For example, refer to the table below: Image Description This is our original graph. The numbers near the arcs indicate their weight. None of the arcs are highlighted. AD and CE are the shortest arcs, with length 5, and AD has been arbitrarily chosen, so it is highlighted. CE is now the shortest arc that does not form a cycle, with length 5, so it is highlighted as the second arc. The next arc, DF with length 6, is highlighted using much the same method.
56 | P a g e DISCRETE MATHEMATICS The next-shortest arcs are AB and BE, both with length 7. AB is chosen arbitrarily and is highlighted. The arc BD has been highlighted in red, because there already exists a path (in green) between B and D, so it would form a cycle (ABD) if it were chosen. The process continues to highlight the next-smallest arc, BE with length 7. Many more arcs are highlighted in red at this stage: BC because it would form the loop BCE, DE because it would form the loop DEBA, and FE because it would form FEBAD. Finally, the process finishes with the arc EG of length 9, and the minimum spanning tree is found.
57 | P a g e DISCRETE MATHEMATICS Activity 3d 1) Find a spanning tree for each connected graph. Because many spanning trees are possible, answers may vary. a) 2) Use Prim’s algorithm to find a minimum spanning tree in the following weighted graph. a) b) c) A A B C D E F b) C A A B A D A E A A B C D E F 2 3 5 2 2 4 1 3 6 a b c d e f g 3 3 4 4 4 5 7 7 1 10 11 12 A B C D E G F 20 12 20 14 10 12 10 16 15 15 10
58 | P a g e DISCRETE MATHEMATICS 3) Use Kruskal’s algorithm to find a minimum spanning tree in the following weighted graph. a) 3.2.5 Describe a binary search tree A Binary Search Tree can be used to store items in its vertices. It enables efficient searches. A Binary Search Tree (BST) is a special kind of binary tree in which: • each child of a vertex is designated as a right or left child • no vertex has more than one right child or left child • each vertex is labeled with a key, which is one of the items • vertices are assigned keys so that the key of a vertex is both larger than the keys of all vertices in its left subtree and smaller than the keys of all vertices in its right subtree. a b c d e f g 1 8 9 2 7 6 10 5 3 4 2 3 f b) a b c d e h g 2 4 3 5 2 5 4 4 5 c) A B C D E G F 4 8 12 15 5 2 20 18 19 7 13 10 H
59 | P a g e DISCRETE MATHEMATICS Example: Shape of a binary search tree depends on its key values and their order of insertion. Insert the elements ‘J’ ‘E’ ‘F’ ‘T’ ‘A’ in that order. Solution: a. The first value to be inserted is put ‘J’ into the root. b. Thereafter, each value to be inserted begins by comparing itself to the value in the root, moving left it is less, or moving right if it is greater. This continues at each level until it can be inserted as a new leaf. c. Begin by comparing ‘F’ to the value in the root, moving left it is less, or moving right if it is greater. This continues until it can be inserted as a leaf. d. Begin by comparing ‘T’ to the value in the root, moving left it is less, or moving right if it is greater. This continues until it can be inserted as a leaf. J J E J E F J E F T
60 | P a g e DISCRETE MATHEMATICS e. Begin by comparing ‘A’ to the value in the root, moving left it is less, or moving right if it is greater. This continues until it can be inserted as a leaf. 3.2.6 Illustrate tree traversals A traversal algorithm is a procedure for systematically visiting every vertex of an ordered binary tree. Tree traversals are defined recursively. Three traversals are named: a. Pre-order traversal Let T be an ordered binary tree with root r. If T has only r, then r is the preorder traversal. Otherwise, suppose T1, T2 are the left and right subtrees at r. The preorder traversal begins by visiting r. Then traverses T1 in preorder, then traverses T2 in preorder. Example Preorder Traversal: J, E, A, H, T, M, Y J E F T A Root Visit first Visit left subtree second Visit right subtree last J E H T A M Y
61 | P a g e DISCRETE MATHEMATICS b. In-order traversal Let T be an ordered binary tree with root r. If T has only r, then r is the inorder traversal. Otherwise, suppose T1, T2 are the left and right subtrees at r. The inorder traversal begins by traversing T1 in inorder. Then visits r, then traverses T2 in inorder. Example Inorder Traversal: A, E, H, J, M, T, Y c. Post-order traversal Let T be an ordered binary tree with root r. If T has only r, then r is the postorder traversal. Otherwise, suppose T1, T2 are the left and right subtrees at r. The postorder traversal begins by traversing T1 in postorder. Then traverses T2 in postorder, then ends by visiting r. Example Post-order Traversal: A, H, E, M, Y, T, J J E H T A Root Visit second Visit left subtree first M Y Visit right subtree last J E H T A Root Visit last Visit left subtree first M Y Visit right subtree second
62 | P a g e DISCRETE MATHEMATICS 3.2.7 Show the differences between binary and complete binary tree Binary tree: A binary tree is a tree with the following properties: o Each internal node has at most two children o Each child is designated either the left child or the right child Full binary tree: A binary tree in which each internal vertex has exactly two children. Complete binary tree: A complete binary tree is a binary tree in which each vertex has two or no children. ✓ The process of converting the general tree to a binary tree is as follows: 2 is the left child of 7. 9 is the right child of 5. BB A CC DD EE HH I I J J KK F F G Figure 13.8 A complete binary tree
63 | P a g e DISCRETE MATHEMATICS • Use the root of the general tree as the root of the binary tree. • Determine the first child of the root. This is the leftmost node in the general tree at the next level. • Insert this node. The child reference of the parent node refers to this node. • Continue finding the first child of each parent node and insert it below the parent node with the child reference of the parent to this node. • When no more first children exist in the path just used, move back to the parent of the last node entered and repeat the above process. In other words, determine the first sibling of the last node entered. • Complete the tree for all nodes. In order to locate where the node fits you must search for the first child at that level and then follow the sibling references to a nil where the next sibling can be inserted. The children of any sibling node can be inserted by locating the parent and then inserting the first child. Then the above process is repeated. Given the following general tree: The following is the binary version: ✓ 1 st Children – go to the left ✓ Other sibling – go to the right A B C D K H I J E F G A B K C H I J D E F G
64 | P a g e DISCRETE MATHEMATICS 3.2.8 Construct the tree from the algebraic expression 1) (7 + (6 − 2)) − ( − ( − 4)) 2) (/)/(( + 3) − (/5)) 3) (7 ∗ 3) + (6 − (9/5)) + * * - 2 9 / 5 5 6 / 4 7 7 3 + - y 4 + 7 - 6 2 - - x / - + 3 x / 5 z / y x
65 | P a g e DISCRETE MATHEMATICS Activity 3e 1) What binary search tree is obtained by inserting the elements ‘A’ ‘E’ ‘F’ ‘J’ ‘T’ in that order? 2) Form a binary search tree for the words mathematics, physics, geography, zoology, meteorology, geology, psychology and chemistry using alphabetical order. 3) Build a binary search tree for the words banana, peach, apple, pear, coconut, mango and papaya using alphabetical order. 4) Find binary search tree for the sentences “The quick brown fox jumps over the lazy dog”. 5) For the given ordered rooted tree below, determined the order in which a preorder, in-order and post-order traversals visit the vertices. a) b) / + J - B D C a b c d e f g
66 | P a g e DISCRETE MATHEMATICS 6) Draw a tree with the given specifications: a) Complete binary tree with nine vertices b) Binary tree with height 3 and seven leaves c) Full binary tree with height 3 and 8 leaves 7) Convert the following tree to the binary version. 8) Construct the tree of the algebraic expression a) ((1 + 1) + (1 − 2)) ÷ ((2 − ) + 1) b) ((2 + ) ÷ (3 − (4/))) + ( − (3 ÷ 11)) c) 3 − ( + (6 × (4 ÷ (2 − 3)))) d) ((2 + ) − (2 × )) − ( − 2) e) (3 − (2 × )) + (( − 2) − (3 + )) f) ((3 × (1 − )) ÷ ((4 + (7 − ( + 2))) × (7 + ( ÷ )))) A B C D E F G H I J K L M N a) b) 1 2 8 6 9 5 4 7 3
67 | P a g e DISCRETE MATHEMATICS 3.2.9 Apply tree theories in searching and Travelling Salesman Problem (TSP) solving 1) The small town of Social Circle maintains a system of walking trails between the recreational areas in town. Model of the system is represented by using a weighted graph like below, where weight is in kilometre. Social Circle plans to pave some of the walking trails to make them bicycle paths as cheaply as possible. Assuming that construction costs are the same on all parts of the system, use Prim’s Algorithm to find a plan for the town’s paving. 2) A communication company is in the process of identifying required cost to updates all paths between its stations. A weighted graph below shows the stations and the costs in millions of dollars for upgrading each link. Use Kruskal’s Algorithm to find the minimum cost needed for upgrading these links. A C B D E F G H 2 2 2 3 3 3 4 4 5 5 6 6 A B C D E F G H I J 1.7 3.4 1.8 2.4 2.7 2.6 2.1 3.6 2.8 3.2 5.3 2.9 2.2 4.2 2.1 2.5 4.4 3.3 Scan this QR code to get the previous Final Examination Question related to this chapter
68 | P a g e DISCRETE MATHEMATICS CHAPTER 4: SETS, RELATIONS AND FUNCTIONS 4.1 Derive sets and set operations • A set is a collection of objects, which are called elements or members of the set. For example, the United States is a collection or set of 50 states. The 50 individual states are the members or elements of the set that is called the United States. • Three methods are commonly used to indicate a set: i. Description of sets ▪ Write a description of the set containing the elements Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. Solution: The set is the day of the week. ii. Roster Form of Sets ▪ Set A is the set of natural number less than 6. Solution: The natural number less than 6 are 1,2,3,4, and 5. Thus, set A in roster form is = {1,2,3,4, 5}. iii. Using Set-Builder Notation ▪ Write set = {1,2,3,4, 5}in set-builder notation Solution: = {| ∈ ⟨6} = {| ∈ ≤ 5} 4.1.1 Identify lists of standards notations in sets i. A set is defined to be an unordered collection of objects. • There are several ways to describe a set. If a set is finite and not too large, we may describe it by listing all its elements. • However, if a set is large or infinite, we may describe it by listing a property necessary for its membership. • For example, the set of all real number can be written as R = {x | x is a real number}. • The empty set { } is denoted by ii. Set A is a subset of set B, symbolized by ⊆ , if and only if all the elements of set A are also elements of set B. • For example, determine whether set A is a subset of set B.
69 | P a g e DISCRETE MATHEMATICS = {, , } = { , , } • Solution: All the element of set A are contained in set B, so ⊆ . Note that set A = set B. iii. Set A is a proper subset of set B, symbolized by ⊂ , if and only if all the elements of set A are elements of set B and set ≠ . That is, set B must contain at least one element not in set A. • For example, determine whether set A is a proper subset of set B. = {, , ℎℎ} = {, , , ℎℎ, } • Solution: All the element of set A are contained in set B, and set A and B are not equal; thus ⊂ . iv. Let X be a set. If there are exactly n distinct elements in X where n is a nonnegative integer, we say that X is a finite set and n is the cardinality of X which denoted by |X|. • For example, let A be the set of prime integers less than 10. Find the cardinality of A? • Solution: Since A = { 2, 3, 5, 7 }. Therefore |A| = 4. v. The set of all subsets of a set X is called the power set of X, denoted by P(X). If a set has n elements, then its power set has 2n elements. • For example, If X = {a, b, c}, then P(X) = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}. vi. Let X and Y be sets. The Cartesian product of X and Y is denoted by X x Y, is the set of all ordered pairs (x, y) where x ∈ X and y∈Y. Hence, X x Y = {(x, y) |x∈X ∧ y∈Y}. • For example, what is the Cartesian product of A = {1, 2, 3} and B = {a, b}? • Solution: A x B = {(1, a), (2, a), (3,a),(1, b), (2, b),(3,b)} • Note that since (x, y) is an ordered pair, then X x Y ≠Y x X .
70 | P a g e DISCRETE MATHEMATICS Activity 4a 1) Express each set-in set-builder notation: a. = {4,5,6,7,8,9,10} b. {3,6,9,12, … … . .} c. ℎ ℎ ℎ ℎ 30 2) Given, U = {natural numbers}; A = {2, 4, 6, 8, 10}; B = {1, 3, 6, 7, 8} State whether each of the following is true or false: a. 2 ∈ A b. 11 ∈ B c. 4 ∉ B d. A ∈ U 3) Given that U = {natural numbers}; A = {2, 4, 6, 8, 10}; B = {1, 3,6,7,8}. State whether each of the following is true or false: a. A ⊂ U b. B ⊆ A c. B ⊂ U 4) Determine whether set A is a proper subset of set B. a. = { , , } = { , , ℎ, } b. = {2,3,4, 5} = {2,3} c. = {| } = {| } d. = {, , , } = {, , , } 5) Given that sets A = {0, 1}, B = {1,2} and C = {0, 1, 2}. What is the Cartesian products of: a. A x B b. B x C 6) Given that X = {a, c} and Y = {a, b, e, f}. Write down the elements of: a. X × Y b. Y × X c. X 2 (= X × X) d. What could you say about two sets X and Y if X × Y = Y × X?
71 | P a g e DISCRETE MATHEMATICS 4.1.2 Apply Venn diagram to represent set operations • Set theoretic operations allow us to build new sets, just as the logical connectives allowed us to create compound propositions from simpler propositions. • Given sets A and B, the set theoretic operators are: a) UNION - Elements in at least one of the two sets: A B = { x | x A x B } - Venn diagram representing the union of A and B: - For example, the union of the sets {1,3, 5} {1,2, 3} is the set {1,2,3, 5}; that is, {1,3, 5} ∪ {1,2, 3} = {1,2,3, 5}. b) INTERSECTION - Elements in exactly one of the two sets: A B = { x | x A x B } - Venn diagram Representing the Intersection of A and B: - For example, the Intersection of the sets {1,3, 5} {1,2, 3} is the set{1, 3} that is {1,3, 5} ∩ {1,2, 3} = {1, 3} . c) DISJOINT - If A and B have no common elements, they are said to be disjoint. - Two sets are called disjoint if their intersection is the empty set, ∩ = . - Venn diagram representing the disjoint of A and B: - For example, let = {1,3,5,7, 9} and = {2,4,6,8, 10}. Since ∩ = , then are disjoint. U A B U A B U A B
72 | P a g e DISCRETE MATHEMATICS d) DIFFERENCE - Elements in first set but not second. An element belongs to the difference of A and B if and only if ∈ ∉ . This tells us that, − = { | ∈ ∧ ∉ } - For example, the difference of {1,3, 5} and {1,2, 3} is the set {5};that is,{1,3, 5} − {1,2, 3} = {5}. e) COMPLEMENT - Let U be the universal set. The complement of the set A, denoted by , is the complement of A with respect to U. In other words, the complement of the set A is U-A, = {| ∉ }. - Venn diagram for the complement of the Set A: - For example, let A = {,, , , }where the universal set is the set of letters of the English alphabet. Then, = {, , , , , ℎ,, , , , , , , , ,, , , , , } A A U
73 | P a g e DISCRETE MATHEMATICS 4.1.3 Create set properties followed D’Morgan’s Law • The properties of D’Morgan’s Law are as below: • The visual for D’Morgan’s: 1. (A B) = A B 2. (A B) = A B A B A B A B = A B
74 | P a g e DISCRETE MATHEMATICS Activity 4b 1) Make six copies of the Venn diagram shown alongside, and then shade the areas represented by: a. ' ∪ b. ∩ ' c. ( ∩ )' d. ' ∪ ' e. ( ∪ )' f. ' ∩ ' 2) Given the Venn diagram below. List all the elements for each of the following. a. P Q b. P R c. Q R d. P Q R e. P` Q f. (P R)` Q 3) Construct a Venn diagram illustrating the following sets. U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, A = {2, 4, 6, 8,10}, B = (1, 3, 6, 7,8}, C = {3, 7} Using your Venn diagram, list the elements in each of the following sets: a. ∩ b. ∪ c. d. e. ∩ f. ∩ g. − 4) Given that set: P = { 5, 6 }, Q = { 3, 4, 5, 6 , 8, 9}, R = ( 1, 2, 3, 6, 8} and U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, a. Draw a Venn Diagram to show the relations between set P, Q dan R. b. List the element of set Q R c. Find n(P Q ’ ). 5) Construct a Venn diagram illustrating the following sets. U = {a, b, c, d, e, f, g, h}, R = {a, b, c, d, e, f}, S = {c, d, e}, T = {f, g, h} a. What is the relation between set R and set S? b. Give the element for S` c. Find n(R T)` P Q R U
75 | P a g e DISCRETE MATHEMATICS 6) Given the following set K = {2, 4}, set M = {2, 3, 4, 5, 6}, set Q = {0, 1, 2, 4, 6, 7, 8, 9} and universal set U = K M Q. a. Construct a Venn diagram illustrating the given sets. b. List all the elements for set M Q c. Find n(K M ` ) 7) Given the following sets: = {1,2,3,4,5,6,7,8,9,10} = {1,2,4,6} = {1,3,6,7,9} = { } Find: a. ∩ b. ∩ c. ' ∩ d. ( ∩ )' 8) Given the following sets: = {1,2,3,4,5,6,7,8,9,10} = {1,2,4,6} = {1,3,6,7,9} = { } Find: a. ∪ b. ∪ c. ' ∪ d. ( ∪ )' 9) Given the following sets: = {, , , ,, , } = {, ,, } = {, , ,} = {,, } Find: a. ( ∪ ) ∩ ( ∪ ). b. ( ∪ ) ∩ ' c. ' ∩ ' 10)For the following Venn Diagrams, the numbers show the cardinality of the elements. State the number of elements of the following sets: a. n(U) b. n(E) c. n(F) d. n(G) e. n(E F) f. n(E G)` g. n(F G)` h. n(E F G)` E F G U 4 5 2 3 3 6
76 | P a g e DISCRETE MATHEMATICS 11)Given the Universal set, = {x: 15 ≤ x ≤ 30, x is an integer}and sets J, K and L are as follows: J = {x | x is a prime numbers} K = {x | x is a multiple of 3} L = {x | x is a number where the difference between the digit is more than 5} a. Determine all the elements in sets J, K and L. b. Determine all the elements of ∪ . c. Determine all the elements of ( − ). d. Determine ( ∩ ).
77 | P a g e DISCRETE MATHEMATICS 4.2 Explain relations 4.2.1 Identify the properties of relations in a directed graph • Given an ordered pair (, ) in × , is related to , written , if and only if (, ) is in. • The notation for relation may be written symbolically as follows: • For example, let = {0,1, 2} and = {1,2, 3}. Let us say that an element in is related to an element in if, and only if, is less than. Let us use the notation as a shorthand for the sentence “ is related to y.” • Recall that the Cartesian product of and where × , consists of all ordered pairs whose first element is in A and whose second element is in B: . × = { (0, 1) , (0,2), (0,3), (1,1), (1,2), (1,3), (2,1), (2,2), (2,3) }. • Then: 0 1 0 < 1, 0 2 0 < 2, 0 3 0 < 3, 1 2 1 < 2, 1 3 1 < 3, 2 3 2 < 3. • The elements of some ordered pairs in × are related, whereas the elements of other ordered pairs are not. Consider the sets of all ordered pairs in × whose elements are related: = { (0, 1) , (0,2), (0,3), (1,2), (1,3), (2,3) } • In a directed graph of R: x R y (x, y) R .1 .3 .0 .2
78 | P a g e DISCRETE MATHEMATICS 4.2.2 Explain the equivalent relation Because of the equivalent of the expressions (, ). ∈ for all in A, the reflexive, symmetric, and transitive properties can also be written as follows: Let R be a binary relation on a set A. 1) R is reflexive if, and only if, for all x A, x R x. 2) R is symmetric if, and only if, for all x, y A, if x R y then y R x. 3) R is transitive if, and only if, for all x, y,z A, if x R y and y R z then x R z 1) R is reflexive for all A, (x, x) R. 2) R is symmetric for all x and y in A, if (x, y) R then (y, x) R 3) R is transitive for all x, y,and z in A, if (x, y) R and (y,z) R then (x,z) R.
79 | P a g e DISCRETE MATHEMATICS Activity 4c 1. Let = {1, 2} = {1,2, 3} and define a binary relation from A to B as follows: Given any (, ) ∈ × , (, ) ∈ ↔ − is even number. a. State explicitly which ordered pairs are in × and which are in . b. Is 1 3? 2 3? 2 2? 2. Let = {0,1,2, 3} and define relation and on as follows: = { (0,0), (0,1), (0,3), (1,0), (1,1), (2,2), (3,0), (3,3) } = { (0,0), (0,2), (0,3), (2,3) } a. Is reflexive? symmetric? transitive? b. Is reflexive? symmetric? transitive? Prove your answers by using directed graph. 3. Given the following relations: 1 = {(0,0), (0,1), (0,3), (1,1), (1,0), (2,3), (3,3)} 2 = {(2,3), (3,2)} The relations show a few binary relations are defined on the set = {0,1,2,3}. For each relation: a. Draw the directed graph b. Determine whether the relation is reflexive c. Determine whether the relation is symmetric d. Determine whether the relation is transitive
80 | P a g e DISCRETE MATHEMATICS 4.3 Carry out functions 4.3.1 Describe basic constructions • Functions are a special kind of relation. It's a set of ordered pairs such as {(0, 1), (5, 22), (11, 9)}. • Like a relation, a function has a domain and range made up of the x and y values of ordered pairs. • In mathematics, what distinguishes a function from a relation is that each x value in a function has one and only ONE y-value. • Compare the two relations on the below. Which of the following relations are functions? Relation 1 Relation 2 • Since Relation 1 has ONLY ONE y value for each x value, this relation is a function. • On the other hand, Relation 2 has TWO distinct y values '2' and '4' for the same x value of '1'. Therefore, relation 2 does not a function. • But TWO x values for the same y value called many-to-one relation can be a function. 0 1 2 1 2 4 5 P Q 0 1 2 1 2 4 0 1 1 2 4 x y x y codomain domain object image x y f
81 | P a g e DISCRETE MATHEMATICS • The diagram above shows the relation that maps the elements of set P to the elements of set Q. o Set P is called the domain of the relation. Each element in the domain is called an object. o Set Q is called the codomain of the relation. Each element in the codomain is an image. o The subset of the codomain that contains all the images that have been mapped is called the range. • A function f which maps x in the domain onto y in the range can be written as: : → or () = 4.3.2 Explain the properties of following functions a) One-to-one functions • A one to one function is a function in which every element in the range of the function corresponds with one and only one element in the domain. Example of a one-to-one function: {(0,1), (5,2),(6,4)} Domain: 0,5,6 Range: 1,2,4 Each element in the domain (0,5 and 6) correspond with a unique element in the range. Therefore this function is a one-to-one function. • Represent functions using “node and arrow” notation: One-to-One means that no clashes occur. ◼ GOOD: (no clashes, is 1-to-1) ◼ BAD:(a clash occurred, not 1-to-1) 1 2 3 a b c d 1 2 3 A B C
82 | P a g e DISCRETE MATHEMATICS b) Onto functions • Onto means that every possible output is hit ◼ GOOD - everything hit, onto ◼ BAD - 2nd output missed, not onto Activity 4d 1. Determine which relations below are functions? a. ‘is less than’ c. ‘is two power of’ b. ‘is passes in subject’ d. has 1 2 3 4 1 2 3 4 5 6 4 9 -3 -2 2 3 • Jun • July • August • 30 days • 31 days Azlan Ain Yuna John Discrete Maths C++ Programming Operating System 1 2 3 4 a b c a b c d 1 2 3 4
83 | P a g e DISCRETE MATHEMATICS 2. Which relations below are functions? a. Relation 1: {(-1,2), (-4,51), (1, 2), (8, -51)} b. Relation 2: {(13,14), (13,5), (16,7), (18,13)} c. Relation 3: {(3,90), (4,54), (6,71), (8,90)} 3. For the following relation to be a function, X cannot be what values? a. {(8, 11), (34,5), (6,17), (X ,22)} b. {(12,14), (13,5) , (-2,7), (X,13)} 4. The arrow diagram below shows the function f : x → 2x + 3. Determine: a. The domain of function f b. The image of 2 c. The object of 9 d. The range of the function f 5. Let = {, , } and = {1,2,3,4}. A function from to are define by the arrow diagram below. • 1 • 2 • 3 • 5 • 6 • 7 • 8 • 9 x 2x+ 3 f a b c 1 2 3 4
84 | P a g e DISCRETE MATHEMATICS a. Write the domain and co-domain of . b. Find (a), (b), and (c). c. What is the range of ? d. Find the inverse image of 2, 4 and 1 e. Represent as a set of ordered pairs. 6. Determine whether each of the following relations is a one-to one functions and/or onto functions. a. . 7. Which functions below are one to one? a. Function 1: {(2, 27), (3, 28), (4, 29), (5, 30)} b. Function 2: {(11, 14), (12, 14) , (16, 7), (18, 13)} c. Function 3: {(3, 12), (4, 13), (6, 14), (8, 1)} d. Function 4: {(9, 19), (34,5), (6,17), (8,19)} 8. A relation between set A and set B is represented by the ordered pairs given below. {(-1, 3), (0, 2), (1, 3), (2, 4)} Find: a. An arrow diagram b. The type of functions c. The range Jay Asri Bala 160 cm 163 cm 167 cm height of 170 cm P Q a b c d w x y b.
85 | P a g e DISCRETE MATHEMATICS c) Composition functions • A composition of functions occurs when you insert one function into another. In effect, the range of the one function becomes the domain of the second. • The notation for composition of functions is either: Composition of two functions Example 1: The functions f and g are defined as () = 5 − 2 and () = 2 2 + 1. Find the composite functions of: a. () b. 2 () Solution: a. () () = (2 2 + 1) = 5(2 2 + 1) − 2 = 10 2 + 3 • f(g(x)) • f ∘ g(x) The composition of function notation on the left is the composition. f(g(x)) = f ∘ g(x) However it should be noted that f(g(x)) ≠ g(f(x))
86 | P a g e DISCRETE MATHEMATICS b. 2 () () = (5 − 2) = 5(5 − 2) − 2 = 25 − 12 Example 2: Given that ℎ() = 2 − 3 and () = 2 + 5. Evaluate the composition of functions: a. ℎ((1)) b. (ℎ(2)) Solution: a. ℎ((1)) ℎ((1)) = ℎ[(1) 2 + 5] = ℎ(6) = 2 − 3(6) = −16 b. (ℎ(2)) (ℎ(2)) = [2 − 3(2)] = (−4) = (−4) 2 + 5 = 21 Example 3: Given that () = 2 − 7, find the function of () if: a. () = 3 + 5 b. () = − 6 Solution: a. () = 3 + 5 2() − 7 = 3 + 5
87 | P a g e DISCRETE MATHEMATICS 2() = 3 + 12 () = 3 + 12 2 = 3 2 + 6 b. () = − 6 (2 − 7) = − 6 Let, = 2 − 7 = +7 2 () = ( + 7 2 ) − 6 = − 5 2 Hence, () = −5 2
88 | P a g e DISCRETE MATHEMATICS Activity 4e 1) The functions f and g are defined as () = 2 − 3and() = 2 + 2. Find the composite functions of: a. b. c. 2 2) Given that () = 3 − 1and () = 2 + 1. Evaluate the composition of functions: a. ((1)) b. ((2)) 3) Given that () = 2 + 1and () = 2 , find (2) and (−2). 4) Given that () = 5 + 1and () = −4 2 . Find: a. The value of if () = 11 b. The value of if () = c. (6) d. 2 (4) 5) Given that () = 4 + 5and() = 7 − 3, find the function. 6) Given that () = + 3, find the function if composition of functions is () = 2 +3 , ≠ −3 7) Given that() = 4 , ≠ 0, and () = 2 + 3, find the function. 8) Given that () = + 3, find function if: a. () = 2 + 6 b. () = + 4
89 | P a g e DISCRETE MATHEMATICS d) Inverse functions • Inverse function is a function that undoes the action of another function. • The inverse of the function is when the domain and the range trade places. All elements of the domain become the range, and all elements of the range become a domain. If ƒ maps X to Y, then ƒ–1 maps Y back to X. • Example of the inverse of a simple function: Original function f(x) Inverse of function or f-1 (x) {(0,3), (1,4), (2, 5)} {(3, 0), (4,1), (5, 2)} • If f denotes a function that maps set A to set B and the process is reversed, then the inverse mapping can be represented by the symbol −1 . • Hence, if() = , then −1 () = . Example 4: Given that () = 3 + 5, determine the inverse function −1 () and −1 (3). Solution: () = 3 + 5 Let () = then −1 () = 3 4 5 0 1 2 0 1 2 3 4 5
90 | P a g e DISCRETE MATHEMATICS = 3 + 5 3 = − 5 = − 5 3 Hence, −1 () = −5 3 Therefore, −1 () = −5 3 −1 (3) = 3 − 5 3 = −2 3 Activity 4f 1) What is the inverse of this functions? a. () = {(1,2), (3,4), (5,6)} b. () = {(33,14), (23,15), (11,12), (13, 14)} 2) Given that() = 5 − 6, determine the inverse function −1 . 3) Given that() = 3 − 2 , ≠ 0, find the inverse function −1 . 4) Given that() = 2 + 1, find −1 (3). 5) Given that() = 5 − 3, find −1 (2). 6) The function ℎ is defined as ℎ() = 4 −5 , ≠ 5. Find: a. ℎ −1 () b. ℎ −1 (8) 7) Given that () = 3 + 2 and ℎ() = 5 , ≠ 0, Find: a. −1 () b. −1ℎ() c. ℎ −1 () d. (ℎ) −1 ()
91 | P a g e DISCRETE MATHEMATICS 8) Given that () = 5 + 3 and () = 2 2 + , Find: a. () b. (−2) c. −1 (6) d. −1() 4.3.3 Describe graphs of the Floor and Ceiling functions • The floor and ceiling functions give you the nearest integer up or down. • Example: What is the floor and ceiling of 2.31? The Floor of 2.31 is 2 The Ceiling of 2.31 is 3 • Here are some example values for you: x Floor Ceiling -1.1 -2 -1 0 0 0 1.01 1 2 2.9 2 3 3 3 3 • Symbols: The symbols for floor and ceiling are like the square brackets [ ] with the top or bottom part missing:
92 | P a g e DISCRETE MATHEMATICS • Example: How do we define the floor of 2.31? • Solution: Well, it has to be an integer and it has to be less than (or maybe equal to) 2.31, right? o 2 is less than 2.31 ... but 1 is also less than 2.31, and so is 0, and -1, -2, -3, etc. • There are lots of integers less than 2.31. But we choose the greatest one (which is 2 in this case). So we get the greatest integer that is less than (or equal to) 2.31 is 2. Floor Function: the greatest integer that is less than or equal to x Ceiling Function: the smallest integer that is greater than or equal to x • As A Graph: The Floor and Ceiling Function is this curious "step" function (like an infinite staircase): The Floor Function The Ceiling Function • If it looks confusing, just imagine you are at some x-value (say x = 1.5), and see what y-value you get ... does it make sense now? • Example: at x = 2 we meet an open dot at y = 1 (so it does not include x = 2), and a solid dot at y = 2 (which does include x=2) so the answer is y = 2.
93 | P a g e DISCRETE MATHEMATICS Activity 4g 1. What is the value of floor(-3.2)? 2. What is the value of ceil(-3.2)? 3. What is the value of floor(√3)? 4. What is the value of ceil(√5)? 5. Fill in the table below: Sample value Floor Ceiling 12/5 = 2.4 2.7 −2.7 −2 6. Calculate the value of the following functions: a. ⌈⌊1.4⌋ + 3.5 − ⌈1.2⌉⌉ b. ⌈⌊2.3⌋ − ⌊−5.7⌋⌉ c. ⌊0.5 + ⌈1.3⌉ − ⌈−1.3⌉⌋ Scan this QR code to get the previous Final Examination Question related to this chapter
94 | P a g e DISCRETE MATHEMATICS CHAPTER 5: BASIC COUNTING RULES 5.1 Derive counting principle 5.1.1 Describe the following basic counting principle: a) Sum Rule: ( ∪ ) = () + () ▪ Also called the addition rule. ▪ If there are ways to do task 1, and ways to do task 2 and these tasks can be done at the same time, then there are + ways to do one of the two tasks. ▪ We must make one choice OR a second choice. Example 1: There are 18 math majors and 25 science majors. How many ways are there to pick one math major OR one science majors? Solution: There are 18 ways to select math major and 25 ways to select science major. Total majors are 18 + 25 = 43 Example 2: In how many ways can we select one book from different subjects among five distinct computer science books, three distinct mathematics books and two distinct arts books? Solution: There are 5 + 3 + 2 = 10 ways to selecting one book from different subject among the computer science, mathematics and arts books.
95 | P a g e DISCRETE MATHEMATICS b) Product Rule: ( × ) = () ⋅ () ▪ Also called the multiplication rule. ▪ If there are ways to do task 1 and ways to do task 2, then there are • ways to do both tasks in sequence. ▪ Applies when a “procedure” is made up of separate tasks. ▪ We must make one choice AND a second choice. Example 1: There are 18 math majors and 25 science majors. How many ways are there to pick one math major AND one science majors? Solution: There are 18 ways to select math major and 25 ways to select science major. Total majors are 18 × 25 = 450 Example 2: Consider a wedding picture of 6 people. There are 10 people, including the bride and groom. How many possible options are available to choose if the bride must be in the picture? Solution: Place the bride AND then place the rest of the people. First place the bride: • The bride can be in one of 6 positions. Next, place the other five people via the product rule: • There are 9 people to choose for the second person, 8 for the third, etc. • Total = 9 × 8 × 7 × 6 × 5 = 15120 Hence, Product Rule yields 6 × 15120 = 90720 options.
96 | P a g e DISCRETE MATHEMATICS 5.1.2 Solve problem using the basic counting principle rule. Example 1: Consider a wedding picture of 6 people. There are 10 people, including the bride and groom. How many possible options is available to choose if only one of the bride and groom are in the picture? Solution: ❖ Sum rule - Place only the bride ✓ Product rule: place the bride AND then place the rest of the party. ✓ First place the bride. ⚫ She can be in one of 6 positions. ✓ Next, place the other five people via the product rule ⚫ There are 8 people to choose for the second person, 7 for the third, etc. » We can’t choose the groom! ⚫ Total = 8*7*6*5*4 = 6720 ✓ Product rule yields 6 * 6720 = 40,320 possibilities ❖ OR place only the groom ✓ Same possibilities as for bride: 40,320 Hence, by the Sum Rule yields 40,320 + 40,320 = 80,640 options.