






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























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 BH
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
Grade: Assessor Signature: Date:
Internal Verifier’s Comments:
Signature & Date:
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:
Solution:
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:
Number of customers who did not buy anything:
a)
Solution: 142 = 2 × 71
b)
Solution: 250 = 2 x 5 x 5 x 5
a) each of the aforementioned bags.
Difference (142 - 250): {∣ 2 : max(1 , 1), 7 1 : 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}
a. Ascertain whether the given functions are invertible. If they are, identify the rule for the inverse
function f
a) 𝑓: ℝ → ℝ 𝑤𝑖𝑡ℎ 𝑓
I have 𝑓: ℝ → ℝ 𝑤𝑖𝑡ℎ 𝑓
A function is injective if different inputs produce different outputs. Let's check:
1
2
1
2
1
2
1
2
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=
( y − 4 )
=> f(x)=
5 ( y − 4 )
=y
The function f is a onto.
Given y=bx+ a solve for x:
Thus, the inverse function f
(y) is:
−
(y - 4)
b)
To determine if f is invertible, we need to check if it is a bijection (both injective and surjective)
Injectivity: Assume x
1
, x
2
From (1) , (2) ⇒
3
b. Demonstrate that each side is a subset of the other side. Show that
If
x ∈ A ∪ B ∪C , then x ∉ A ∪ B ∪ C that mean x ∉ A, x ∉ B and x ∉ C
x
, x
∈ b ,x
=> x
If
x ∈ A ∩ B∩ C , then x
, x
∈ b ,x
=> x ∉ A, x ∉ B and x ∉ C
x∉
x ∈ A ∪ B ∪C A ∩ B∩ C ⊆ A ∪ B ∪C
c. Verify the equality using a membership table.
Make a truth table in order to confirm the equality.
The membership table is used to confirm the equivalence because the columns
and
A ∩ B∩ C have the same values for every conceivable combination of A, B, and C
II.Activity 2.
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.
The level of a node is defined as its depth in the tree, with the root node considered to be at level
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:
o Every node has either 0 or 2 children.
o There are no nodes with only one child.
o For a full binary tree of height h, the total number of nodes N is given by the formula:
h+
o This indicates an exponential growth in the number of nodes with respect to the height
of the tree.
o The number of leaf nodes LLL in a full binary tree is L=(N+1)/
o The number of internal nodes (nodes with two children) is I=(N−1)/
Properties of a Full Binary Tree:
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.
o Traversal operations like in-order, pre-order, and post-order are efficient due to the
balanced nature of the tree.
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:
o Height h=
o Number of nodes N=
2+
o Nodes at the last level are filled from left to right without any gaps.
o For a complete binary tree of height h the number of nodes N can range between 2
h
and
h+
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.
Properties of a Complete Binary Tree:
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+
Its right child is at index 2i+
Its parent is at index [(i−1)/2]
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.
o The compact structure of complete binary trees ensures efficient memory utilization,
making them suitable for array representations.
Examples:
o Height h=
o Number of nodes N ranges from 2
2
=4 to 2
2+
o The tree could have all levels fully filled or the last level partially filled from left to right.
o Height h=
o Number of nodes N ranges from 2
3
=8 to 2
3+
o The tree could have all levels fully filled or the last level partially filled from left to right.
Applications of Complete Binary Trees:
o Complete binary trees are the underlying structure for binary heaps (both min-heaps and
max-heaps), used in priority queue implementations.
o The structure of complete binary trees makes them ideal for BFS operations, where
nodes are processed level by level.
o Due to their compact nature, complete binary trees are often stored using arrays,
allowing for efficient indexing and minimal wasted space.
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.
My ID:BH
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.
provided weighted graph.
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).