ASSIGNMENT 1 FRONT SHEET Qualification Pearson BTEC Level 5 Higher National Diploma in Computing Unit number and title Unit 18: Discrete Maths Submission date 8-7-2024 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Chu Duc Anh Student ID BH01254 Class SE06206 Assessor name Ta Quang Hieu Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Anhhhh Grading grid P1 P2 P3 P4 M1 M2 D1 D2 β Summative Feedback: Grade: β Resubmission Feedback: Assessor Signature: Internal Verifier’s Comments: Signature & Date: Date: A. Introduction B. Content My ID : BH01106 I have a = 4 ; b = 5 I. Activity 1. Part I. Stick in mind that π < π represents the largest digits in your ID. 1. Let A and B be two non-empty finite sets. Assume that cardinalities of the sets A,B and A β B are 9π, 2π and a + b, respectively. Determine the cardinality of the set A β B. Solution: |A| = 95 , |B|=24 |A β B| = 9 |A β B| = |A| + |B| - |A β B| = 110 2. Suppose |A – B| = 3π ,|A β B| =11π and |A β B| = 1π . Determine |B| Solution: |A – B| = 34 |A β B| = 115 |A β B| = 14. |A β B| = |A| + |B| - |A β B| 115 = (|A – B| + |A β B|) + |B| - |A β B| 115 = (34 + 14) + |B| - 14 115 = 48 + |B| - 14 |B| = 81 3. At a local market, there are 35π customers. Suppose 11π have purchased fruits,9π have purchased vegetables, 8π have purchased bakery items, 4π have purchased both fruits and vegetables, 3π have purchased both vegetables and bakery items, 2π have purchased both fruits and bakery items, and 1π have purchased all three categories . How many customers have not purchased anything? Number of customers at the market: |U| = 355 Number of customers buying fruit: |A| = 114 Number of customers buying vegetables: |B| = 95 Number of customers buying bread: |C| = 84 Number of customers buying fruits and vegetables: |A ∩ B| = 45 Number of customers buying vegetables and bread: |B ∩ C| = 35 Number of customers buying fruit and bread: |A ∩ C|= 24 Number of customers buying all 3 types mentioned above: |A ∩ B ∩ C | = 14 Solution: |π΄ ∪ π΅ ∪ C| = |A| + |B| + |C| - |A ∩ B| - |B ∩ C| - |A ∩ C| + |A ∩ B ∩ C | |A β B β C| = 114 + 95 + 84 – 45 – 24 – 35 + 14 |A β B β C| = 203 Number of customers who did not buy anything: = |U| - |π΄ ∪ π΅ ∪ C| = 355 − 203 =152 Part II. Keep in mind that represents the largest digits in your ID. 1. List the bag of prime factors for each of the provided numbers. a) Solution: 142 = 2 × 71 A= {|2:1,71:1 |}. b) Solution: 250 = 2 x 5 x 5 x 5 B = {|2:1,5:3|} 2. Find the cardinalities of a) each of the aforementioned bags. For the bag representing 114: {β£ 2 : 1, 71 : 1} ο· Element 2 appears 1 time ο· Element 71 appears 1 time => The cardinality is 1 + 1 = 2 For the bag representing 250: {β£ 2: 1, 5: 3|} ο· Element 2 appears 1 time ο· Element 5 appears 3 time => The cardinality is 1 + 3 = 4 b) the intersection of the aforementioned bags. To clarify, let's first revisit the bags of prime factors for the given numbers and then find their intersection using the specified rules. The only common prime factor is 2 ο· Bag for 142: {2, 71} ο· Bag for 250: {2, 5, 5, 5} ο° The only common prime factor is {2,2} ο° The intersection will take the minimum multiplicity of 2 from both bags: {2,2} c) the union of the aforementioned bags. The union of two bags contains the maximum of the multiplicities for each element present in either of the bags. Union: {2 : max(1, 1), 5: max(0, 3), ,71 : max(1, 0)} = {β£2 : 1, 5 : 3 ,71 : 1|} d) The difference of the aforementioned bags. The difference of two bags contains the elements with their multiplicities from the first bag minus the multiplicities in the second bag, only if the result is positive. Difference (142 - 250): {β£2 : max(1 , 1), 71: max(1 , 0)} = {β£71 : 1|} For 5: Do not appear in the bag for 142, so they are not included in the difference ο· Element 2 appears max(1 , 1) = 0 times ο· Element 71 appears max(1 , 0) = 1 times => The cardinality of the difference is {71} Part III. Bear in mind that π < π represents the largest digits in your ID. a. Ascertain whether the given functions are invertible. If they are, identify the rule for the inverse function f-1 a) π: β → β π€ππ‘β π(π₯) = ππ₯ + π I have π: β → β π€ππ‘β π(π₯) = 5π₯ +4 A function is injective if different inputs produce different outputs. Let's check: π(π₯1) = π(π₯2) ⇒ 5π₯1 + 4 = 5π₯2 + 4 ⇒ 5π₯1 = 5π₯2 ⇒ π₯1 = π₯2 (π ≠ 0) So, f is injective. A function is surjective if every element in the codomain is mapped by some element in the domain. For any π¦ ∈ β , we need to find an π₯ ∈ β such that π(π₯) = π¦ x= (π¦−4) 5 => f(x)= 5(π¦−4) 5 +4 =y The function f is a onto. Given y=bx+ a solve for x: π₯= (π¦ – 4) 5 Thus, the inverse function f-1 (y) is: π−1(π¦) = (y - 4) 5 b) π: [−π, +∞) → [0, +∞) π€ππ‘β π(π₯) = √π₯ + π To determine if f is invertible, we need to check if it is a bijection (both injective and surjective) Injectivity: Assume x1, x2 ∈ [– 5, +∞) Then: π(π₯1) = π(π₯2) ⇒ √π₯1 + 5 = √π₯2 + 5 ⇒ π₯1 + 5 = π₯2 + 5 ⇒ π₯1 = π₯2 ο° The function f is one-to-one. A function is surjective if every element in the codomain is mapped by some element in the domain. For any. For any π¦ ∈ [-5, +∞), we need to find an π₯ ∈ [−π, +∞) such that π(π₯) = π¦ Choose x = π¦ 2 − 5 we have f(x)=√(π¦ 2 − 5) + 5 = √π¦ 2 = y ο° The function f is a onto Given π¦ = √π₯ + 5 solve for x: π¦2 = π₯ + 5 ⇒ π₯ = π¦2 − 5 Thus, the inverse function π−1(π¦) is: π−1(π¦) = π¦2 − 5 b. Let π, π: β → β ππ πππππππ ππ π(π₯) = { 2π₯ + π, π₯ < 0 πππ π(π₯) = ππ₯ − π. πΉπππ π ° π π₯3 + π, π₯ ≥ 0 For π₯ < 0: π(π₯) = 2π₯ +4 Now apply to g: π(π(π₯)) = 5(2π₯ + 4) − 4 = 10π₯ + 20 − 4 = 10π₯ + 19(1) When π₯ ≥ 0: π(π₯) = π₯3 +5 Now apply to g: π(π(π₯)) = 5(π₯3 + 5) − 4 = 5π₯3 + 25 − 4 = 5π₯3 + 21(2) From (1) , (2) ⇒ (π ° π)(π₯) = { 10π₯ + 19 , π₯ < 0 5π₯3 + 21, π₯ ≥ 0 Μ Μ ∩π© Μ ∩πͺ Part IV. Show that if , A B and C are sets , then Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π¨∪π©∪πͺ=π¨ Μ Μ ∩π© Μ ∩πͺ b. Demonstrate that each side is a subset of the other side. Show that Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π¨∪π©∪πͺ=π¨ ο· Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΄ ∪ π΅ ∪ πΆ ⊆ π΄Μ ∩ π΅Μ ∩ πΆΜ ο· Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΄ ∩ π΅ ∩ πΆ ⊆ π΄Μ ∪ π΅Μ ∪ πΆΜ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ If π₯ ∈ π΄ ∪ π΅ ∪ πΆ , then x ∉ A ∪ B ∪ C that mean x ∉ A, x ∉ B and x ∉ C Μ ∩π΅ Μ ∩ πΆΜ ο° x ∈ π΄Μ , x ∈ πΜ ,x ∈ πΆΜ => x ∈ π΄ Μ ∩π΅ Μ ∩ πΆΜ ο° Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΄∪π΅∪πΆ⊆π΄ If π₯ ∈ π΄Μ ∩ π΅Μ ∩ πΆΜ , then x ∈ π΄Μ , x ∈ πΜ ,x ∈ πΆΜ => x ∉ A, x ∉ B and x ∉ C ο° x∉ π΄ ∪ π΅ ∪ πΆ ο° π₯ ∈ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΄∪π΅∪πΆ Μ ∩π΅ Μ ∩ πΆΜ ⊆ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ ο° π΄ π΄∪π΅∪πΆ c. Verify the equality using a membership table. d. Verify the equality using a membership table. Make a truth table in order to confirm the equality. π₯∈A π₯∈B π₯∈C A∪B∪C 1 1 1 1 Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ π΄∪π΅∪πΆ 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 π΅ 0 A 0 0 πΆ A∩B∩C 0 Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ Μ The membership table is used to confirm the equivalence because the columns π΄ ∪ π΅ ∪ πΆ and π΄Μ ∩ π΅Μ ∩ πΆΜ have the same values for every conceivable combination of A, B, and C II. Activity 2. Part I. Discuss two notable instances of binary trees, providing both quantitative and qualitative analyses. 1. Binary Tree Data Structure: A binary tree is a hierarchical data structure commonly used in computer science to organize and manage data effectively. It consists of nodes, each of which can have up to two children, known as the left child and the right child. This structure enables efficient searching, sorting, and manipulation of data. Figure 1:Binary Tree Data Structure Definition: ο· ο· A binary tree is a collection of nodes where each node has at most two children, referred to as the left child and the right child. The binary tree structure facilitates the representation of hierarchical relationships between elements, making it a fundamental data structure in computer science. Root: ο· ο· The topmost node in a binary tree is called the root. It serves as the starting point for accessing other nodes in the tree and is essential for traversing the entire tree structure. Nodes: ο· ο· ο· Each node in a binary tree contains data and references (or links) to its left and right children. The data stored in each node can vary in type and format, depending on the specific application and requirements. These references enable navigation between parent and child nodes, facilitating efficient tree traversal and manipulation operations. Child Nodes: ο· ο· ο· Depth: Nodes that are connected below another node are referred to as its children. Each node can have at most two children: a left child and a right child. Leaf nodes, also known as terminal nodes, are nodes that do not have any children and reside at the bottom of the tree structure. ο· ο· The level of a node is defined as its depth in the tree, with the root node considered to be at level 0. The depth of a node indicates the distance from the root to that particular node, measured by the number of edges traversed along the path. Height: ο· ο· ο· The height of a binary tree is the length of the longest path from the root to a leaf node. It represents the maximum number of levels or layers in the tree, providing insights into the overall structure and complexity of the tree. The height of a binary tree influences its performance and efficiency in terms of traversal, insertion, and deletion operations. Applications: Binary trees have widespread applications in various domains of computer science and software engineering, including: ο· ο· ο· ο· Searching: Binary search trees leverage the binary tree structure to perform efficient search operations with logarithmic time complexity. Sorting: Binary trees can be utilized for sorting elements in logarithmic time through techniques such as heap sort and balanced binary search trees. Expression Parsing: Binary expression trees are employed for parsing and evaluating mathematical expressions, providing a structured representation of arithmetic operations. Hierarchical Representation of Data: Binary trees serve as a foundational structure for representing hierarchical data sets, including file systems, organization charts, and XML parsing algorithms. 2. Types of binary tree: a) Full Binary Tree. Definition of a Full Binary Tree: A full binary tree is a specific type of binary tree in which every node has either zero or two children. In other words, each node in a full binary tree is either a leaf node (having no children) or an internal node (having exactly two children). Figure 2:Full binary tree Characteristics of a Full Binary Tree: 1. Node Structure: o Every node has either 0 or 2 children. o There are no nodes with only one child. 2. Height and Nodes Relationship: o For a full binary tree of height h, the total number of nodes N is given by the formula: N=2h+1−1 o This indicates an exponential growth in the number of nodes with respect to the height of the tree. 3. Leaf Nodes and Internal Nodes: o The number of leaf nodes LLL in a full binary tree is L=(N+1)/2 o The number of internal nodes (nodes with two children) is I=(N−1)/2 Properties of a Full Binary Tree: 1. Balanced Structure: o A full binary tree is more balanced compared to other types of binary trees, as every level except possibly the last is completely filled. 2. Traversal Efficiency: o Traversal operations like in-order, pre-order, and post-order are efficient due to the balanced nature of the tree. 3. Application Suitability: o Full binary trees are particularly useful in applications where a balanced structure is crucial, such as in certain types of heap implementations and in some search algorithms. Examples: 1. Full Binary Tree of Height 2: o Height h=2 o Number of nodes N=22+1−1=7 The tree structure would have 3 levels with the root having 2 children, each of which has 2 children of its own. 2. Full Binary Tree of Height 3: o Height h=3 o Number of nodes N=23+1−1=15 o The tree structure would have 4 levels with each internal node having exactly 2 children. o Applications of Full Binary Trees: 1. Heap Data Structures: o Full binary trees form the basis of heap structures, where each level of the tree is fully filled except possibly the last level, which is filled from left to right. 2. Binary Search Trees: o When implementing balanced binary search trees, full binary trees are often used to ensure optimal performance in search, insertion, and deletion operations. 3. Hierarchical Data Representation: o Full binary trees are used in representing hierarchical data where each node has a fixed number of children, facilitating structured and predictable data organization. b) Complete Binary Tree. Definition of a Complete Binary Tree: A complete binary tree is a type of binary tree in which all levels, except possibly the last, are completely filled, and all nodes are as far left as possible. This structure ensures that there are no gaps between nodes, maintaining a compact and balanced shape. Figure 3:complete binary tree Characteristics of a Complete Binary Tree: 1. Node Arrangement: o All levels are fully filled except possibly the last level. Nodes at the last level are filled from left to right without any gaps. 2. Height and Nodes Relationship: o For a complete binary tree of height h the number of nodes N can range between 2h and 2h+1 - 1 3. Balanced Nature: o While not perfectly balanced like a full binary tree, a complete binary tree ensures a high degree of balance, minimizing the tree's height and ensuring efficient operations. o Properties of a Complete Binary Tree: 1. Node Indexing: o Nodes can be indexed in a level-order manner, which simplifies the implementation of binary heaps. o For a node at index iii: ο§ Its left child is at index 2i+1 ο§ Its right child is at index 2i+2 ο§ Its parent is at index [(i−1)/2] 2. Efficiency in Operations: o Operations such as insertion, deletion, and searching are efficient, typically having a time complexity of O(log n) due to the balanced nature of the tree. 3. Memory Utilization: o The compact structure of complete binary trees ensures efficient memory utilization, making them suitable for array representations. Examples: 1. Complete Binary Tree of Height 2: o Height h=2 o Number of nodes N ranges from 22=4 to 22+1−1=7 o The tree could have all levels fully filled or the last level partially filled from left to right. 2. Complete Binary Tree of Height 3: o Height h=3 o Number of nodes N ranges from 23=8 to 23+1−1=15 o The tree could have all levels fully filled or the last level partially filled from left to right. Applications of Complete Binary Trees: 1. Binary Heaps: o Complete binary trees are the underlying structure for binary heaps (both min-heaps and max-heaps), used in priority queue implementations. 2. Breadth-First Search (BFS): o The structure of complete binary trees makes them ideal for BFS operations, where nodes are processed level by level. 3. Efficient Storage: Due to their compact nature, complete binary trees are often stored using arrays, allowing for efficient indexing and minimal wasted space. 4. Data Structures and Algorithms: o Complete binary trees are used in various algorithms and data structures that require balanced and efficient access patterns, such as segment trees and binary indexed trees. o Part II. Stick in mind that a < b represents the largest digits in your ID. My ID:BH01106 I have a = 1 , b = 6 1. State Dijkstra’s Algorithm in an undirected graph. Dijkstra's algorithm can solve the problem of finding the shortest path on both undirected and directed graphs as long as the weights are not negative.. Let G be a weighted graph. To find the shortest path between a and z in G, we use the Dijkstra’s algorithm as the following Finds the length of the shortest path from a to the first vertex. Finds the length of the shortest path from a to the second vertex. Finds the length of the shortest path from a to the third vertex. ... Continue the process until z is reached. 2. Apply Dijkstra’s algorithm to determine the shortest path length between vertices Aand Z in the provided weighted graph. Figure 4:Example of Dijkstra's Algorithm. 2. Apply Dijkstra’s algorithm to determine the shortest path length between vertices Aand Z in the provided weighted graph. Next, we start at and have two paths including A, B with length 1 and A, C with length 4. Accordingly, B is the first vertex closest to A and the shortest path from A to b has length 1. Now, we need to find the second closest vertex to a by examining all paths that begin with the shortest path from the vertex b (Note that this shortest path contains A and B). Figure 5:Step 1 Here, B is the second closest vertex to C, and the shortest path from A to B is A,C, with length 4. But we will not consider this vertex because the distance from A to D that passes through vertex B, A,C,B, has a length of 7 greater than the distance from A to D that passes through vertex C with distance A, C has a length of 4. To determine the third closest vertex to A, we need to checking all paths that begin with shortest path from the vertex D (Note that this shortest path contains A,C,D). From vertex D there will be 2 paths: D,F has a length of 13 and D,E has a length of 8. It is easy to determine the fourth vertex closest to A, which is E. Here, the shortest path is A,B,C,D,E with length 8. Figure 6 We will consider the contact G because G has the smallest weight. From G we will only have a new path to Z with a smaller distance than the original so we will update it. Figure 7 And finally, at the end of the algorithm, we will obtain the shortest path to every point in the graph. And to vertex Z, go through points A, C, D, E, G with a length of 20. Figure 8 Part III . Does the following graph have a Hamilton path? If so, find such a path. If it does not, give an argument to show why no such path exists Number of Vertices (nnn): 17 Degree Distribution: ο· ο· ο· 5 vertices: degree 4 4 vertices: degree 3 8 vertices: degree 2 Analysis: According to Dirac's Theorem, a simple graph with n≥3 vertices possesses a Hamiltonian circuit if every vertex maintains a degree of at least n/2. In our instance: ο· ο· ο· With n=17, the condition n≥3n is satisfied. However, 17/2 is not an integer, which implies n/2 is approximately 8.5. Therefore, it is unfeasible for every vertex to uphold a degree of at least 8.5. Our examination reveals that: ο· 8 vertices have a degree of 2, which falls significantly short of the required minimum degree. Due to the graph's failure to adhere to Dirac's Theorem's degree criterion, it lacks a Hamiltonian circuit. Consequently, it also negates the presence of a Hamiltonian path, as a Hamiltonian circuit encompasses such a path. Part IV . Construct a proof of the Five Color Theorem Five Color Theorem: Any planar graph can have 5 colors. Proof: I will prove this theorem by induction on the number of vertices. Base case: The simplest connected planar graph consists of a single vertex. Pick a color for that vertex. We are done. Induction step: Assume k ≥ 1, and assume that every planar graph with k or fewer vertices can be 5-colored. Now consider the graph has a vertex of degree 5 or fewer. Remove that vertex (and all edges connected to it). By the induction hypothesis, we can 5-color the remaining graph. Put the vertex (and edges) back in. We have a graph with every vertex colored (without conflicts) except for the one. If the vertex has degree less than 5, or if it has degree 5 and only 4 or fewer colors are used for vertices connected to it, we can pick an available color for it, and we are done (numbers represent colors). Figure 9 Step1 If the vertex has degree 5, and all 5 colors are connected to it, we have a little more work to do. In this case, using numbers 1 through 5 to represent colors, we label the vertices adjacent to the “special” (degree 5) vertex 1 through 5 (in order). Figure 10 Step 2 Now make a subgraph out of all the vertices colored 1 or 3 which are connected to the 1 and 3 colored vertices adjacent to the “special” vertex. Figure 11 Step 3 If the adjacent vertex colored 1 and the adjacent vertex colored 3 are not connected by a path in this subgraph, simply exchange the colors 1 and 3 throughout the subgraph connected to the vertex colored 1. This will leave color 1 available to color the “special” vertex, and we are done. Figure 12 Step 4 On the other hand, if the vertices colored 1 and 3 are connected via a path in the subgraph, we do the same “subgraph” process with vertices colored 2 and 4 adjacent to the “special” vertex. Note that this will be a disconnected pair of subgraphs, separated by a path connecting the vertices colored 1 and 3. Now we can exchange the colors 2 and 4 in the subgraph connected to the adjacent vertex labeled 2. This will leave color 2 for the “special” vertex. Figure 13 Step 5 Thus, we will be able to color the entire planar graph with 5 colors, and the induction is done. C. Conclusion In this exploration of Discrete Mathematics, we embarked on a journey through fundamental concepts and problem-solving techniques. Focusing on sets, prime factorization, inverse functions, binary trees, Dijkstra's Algorithm, and the existence of Eulerian and Hamiltonian circuits in graphs, we aimed to deepen our understanding of discrete mathematical principles and their versatile applications. Starting with the cardinalities of sets, we precisely determined the elements within various sets. Moving forward, the intricate process of prime factorization revealed the foundational components of numbers, organized into cardinality-defined groups. Our venture into inverse functions underscored their significance across diverse applications, from cryptography to data encryption. Activity 2 illuminated the captivating realm of binary trees, distinguishing between complete and balanced binary trees through quantitative and qualitative analyses. D. References GeeksforGeeks. (2020). Introduction to Binary Search Tree. [online] Available at: https://www.geeksforgeeks.org/introduction-to-binary-search-tree/ [Accessed 6 Jul. 2024]. GeeksforGeeks. (2021). Introduction to Tree Data Structure. [online] Available at: https://www.geeksforgeeks.org/introduction-to-tree-data-structure/ [Accessed 6 Jul. 2024]. Nhα»―ng ngΖ°α»i Δóng góp vào các dα»± án Wikimedia (2010). trang Δα»nh hΖ°α»ng Wikimedia. [online] Wikipedia.org. Available at: https://vi.wikipedia.org/wiki/%C4%90%E1%BB%8Bnh_l%C3%BD_Dirac [Accessed 6 Jul. 2024]. Nhα»―ng ngΖ°α»i Δóng góp vào các dα»± án Wikimedia (2013). Δα»nh lý nΔm màu. [online] Wikipedia.org. Available at: https://vi.wikipedia.org/wiki/%C4%90%E1%BB%8Bnh_l%C3%BD_n%C4%83m_m%C3%A0u [Accessed 6 Jul. 2024]. Programiz (2019). Dijkstra’s Algorithm. [online] Programiz.com. Available at: https://www.programiz.com/dsa/dijkstra-algorithm [Accessed 6 Jul. 2024]. www.studytonight.com. (n.d.). Binary Tree and its Types | Data Structure Tutorial | Studytonight. [online] Available at: https://www.studytonight.com/data-structures/introduction-to-binary-trees [Accessed 6 Jul. 2024].