0% found this document useful (0 votes)
30 views

Discrete Maths

This document contains an assignment submission for a discrete math unit. It includes: 1) A summary of set theory concepts like sets, operations, cardinality and theorems 2) An overview of function theory including one-to-one, bijective and surjective functions 3) Details of graph theory topics such as graph definitions, types, trees, and algorithms 4) An analysis of how set theory and functions apply to software engineering 5) A reference section with sources cited The assignment contains explanations and examples of key concepts in set theory, functions and graph theory for a computing coursework submission.

Uploaded by

tahaianh2110
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Discrete Maths

This document contains an assignment submission for a discrete math unit. It includes: 1) A summary of set theory concepts like sets, operations, cardinality and theorems 2) An overview of function theory including one-to-one, bijective and surjective functions 3) Details of graph theory topics such as graph definitions, types, trees, and algorithms 4) An analysis of how set theory and functions apply to software engineering 5) A reference section with sources cited The assignment contains explanations and examples of key concepts in set theory, functions and graph theory for a computing coursework submission.

Uploaded by

tahaianh2110
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

PROGRAM TITLE: BTEC in Computing (Software Engineering)

UNIT TITLE: Unit 18: Discrete Maths


ASSIGNMENT NUMBER: 1
ASSIGNMENT NAME: Set theory and functions - Graph theory
SUBMISSION DATE: 08/02/2024
DATE RECEIVED: 08/02/2024
TUTORIAL LECTURER: Luu Thi Huong Giang
WORD COUNT: 4439

STUDENT NAME: Nguyen Quy Duong


STUDENT ID: BKC13167
MOBILE NUMBER: 0903246189
Summative Feedback:

Internal verification:
Contents
1. Set theory and functions....................................................................................................................3
I. Set theory.......................................................................................................................................3
1.Definition of sets, basic concepts...............................................................................................3
2. Operations in sets.......................................................................................................................3
3. The force of gathering................................................................................................................4
4. Theorems of sets........................................................................................................................5
5. Definition of multiset, characteristics, notation, and cardinality of multiset.............................5
II. Function theory.............................................................................................................................6
1. function definition......................................................................................................................6
2. Definition of single light, double light, full light.......................................................................6
3. Inverse function.........................................................................................................................6
2. Graph theory......................................................................................................................................7
II. Graph theory.....................................................................................................................................7
1. Graph definition.............................................................................................................................7
2. Types of graphs, how to classify and represent graphs on computers..........................................7
3. Define binary tree characteristics..................................................................................................7
4. Defines the spanning tree of the graph..........................................................................................8
5. Euler line, Hamilton cycle, 2 isomorphic graphs..........................................................................9
5.1. Euler's 1-line...........................................................................................................................9
5.2. Hamiltonian cycle.................................................................................................................10
5.3. Two isomorphic graphs........................................................................................................10
6. Algorithms: find Dijkstra's shortest path, find Prim's smallest spanning tree.............................11
6.1. Dijkstra's algorithm...............................................................................................................11
6.2. Prim's smallest frame tree.....................................................................................................12
III. Examine set theory and functions applicable to software engineering.........................................12
Part 1................................................................................................................................................12
Part 2:.............................................................................................................................................14
Part 3...............................................................................................................................................15
Part 4:.............................................................................................................................................17
Part 5:.............................................................................................................................................17
Part 6 :............................................................................................................................................18
IV. Reference......................................................................................................................................20
1. Set theory and functions.
I. Set theory
1.Definition of sets, basic concepts
- A set is a collection of objects, called elements, in which the order is not important and an object
cannot appear twice in the same set
- Example 1.1
Explicit definitions of sets, that is, where each element is listed, are:
A = {a, b, c}
B = {3, 4, 6, 7, 8, 9}
C = {Linda, Raka, Sue, Joe, Nigel, Mary}
a ∈ A means ‘a is an element of A’ or ‘a belongs to A’; therefore in the above examples:
3∈B
Linda ∈ C
- A set is a collection of objects, called elements, in which the order is not important and an object
cannot appear twice in the same set
- The universal set is the set of all objects we are interested in and will depend on the problem under
consideration. It is represented by E.
The empty set (or null set) is the set with no elements. It is represented by ∅ or { }.
- Sets can be represented diagrammatically – generally as circular shapes. The universal set is
represented as a rectangle. These are called Venn diagrams
- Sets can be represented diagrammatically – generally as circular shapes. The universal set is
represented as a rectangle. These are called Venn diagrams
2. Operations in sets
- Intersection:
Symbol: A ∩ B.
Meaning: The set of elements that simultaneously belong to both A and B.
For example: If A = {1, 2, 3} and B = {2, 3, 4}, then A ∩ B = {2, 3}.
- Union:
Symbol: A ∪ B.
Meaning: The set of all elements belonging to A or B or both.
For example: If A = {1, 2, 3} and B = {3, 4, 5}, then A ∪ B = {1, 2, 3, 4, 5}.
- Subtraction (Difference):
Symbol: A - B or A \ B.
Meaning: The set of elements that belong to A but do not belong to B.
For example: If A = {1, 2, 3} and B = {2, 3, 4}, then A - B = {1}.
- Complement:
Symbol: A̅ or complement(A).
Meaning: The set of elements in the sample space that do not belong to A.
For example: If U is the sample space and A = {1, 2, 3}, then A̅ is the set of elements that do not
belong to {1, 2, 3}.
3. The force of gathering
The cardinality of a set is a concept in mathematics expressed by the number of elements in that set.
This is also known as "cardinality" (usually denoted |A|) and is often used to measure the size or
number of elements of a set.
For example, if A is a set of natural numbers from 1 to 5, then the cardinality of A (denoted |A|) will
be 5, because there are 5 elements in that set.
For example:
The set A = {1, 2, 3} has cardinality |A| = 3.
The set B = {a, b, c, d} has cardinality |B| = 4.
The empty set ∅ has cardinality |∅| = 0.
4. Theorems of sets.
5. Definition of multiset, characteristics, notation, and cardinality of multiset.
- Multiset is a concept in mathematics, especially in set theory, which is similar to a regular set but
can contain more than one copy of each element. This means that an element can appear multiple
times in a multi-set, as opposed to a regular set where each element appears only once.
- Characteristics of multiple sets include:
+ Duplicate elements: Elements in a multi-set can appear multiple times.
+ Order is not important: The order of elements is not important in the multiset.
+ This means that {1, 2, 3} and {3, 2, 1} are considered the same multiset.
- Multi-set notation may vary depending on context and programming language. Some common
ways include using curly braces {} or merge marks (), and using dashes or colons to indicate
repeated elements. For example:
+ Curly braces: {1, 2, 2, 3, 3, 3}
+ Merge sign: (1, 2, 2, 3, 3, 3)
+ Symbols with dashes: {a, b, c, c, c} or {a, b, c3}
+ Symbol with dot: {a, b, c...}
- The power of multiple sets lies in modeling real-life situations where the multiple occurrence of
particular elements is important. Multiple sets are used in many fields such as statistics, information
technology, and consensus theory. In programming, languages like Python provide data structures
like Counter in the collections module to represent multiple collections.
II. Function theory
1. function definition
- A function is a rule or law that determines the relationship between elements of two different sets
such that each element of the first set is uniquely mapped to an element of the second set. two.
Simply put, a function is a rule that assigns each of its (independent) input values to a corresponding
(dependent) output value.
2. Definition of single light, double light, full light.
- One-to-one: A mapping f:A→B is said to be one-to-one if each element in set A is mapped to a
single element in set B. In other words, there are no two different elements in A which is mapped to
the same element in B.
- Bijective: A mapping f:A→B is called bijective if each element in set B has at least one element in
A mapped to it. In other words, there is no element in B that there is not at least one element in A
mapped to.
- Omnijective: A mapping f : A→B is called holographic if it is both unijective and bijective. In
other words, each element in A is mapped uniquely, and each element in B has at least one element
in A mapped to.
3. Inverse function.
An inverse function is a concept in mathematics related to the mapping between two sets. If a
function f : A→B is an injective, i.e. no two different elements in A are mapped to the same element
in B, then it can have an inverse function. island.
The inverse function of f, denoted f−1, is a function g : B→A such that if f(a) = b then (b) = a. In
other words, the inverse function works the opposite of the original function: if you apply the
function f to a value a and then apply the inverse function f−1 to that result, you will rotate return to
the original value a.
The condition for a function to have an inverse is that it must be a unijective and bijective mapping.
This ensures uniqueness and ensures every value in B is mapped to a unique value in A.

2. Graph theory

II. Graph theory.


1. Graph definition.
- Definition: A graph is understood as a set of two finite sets: a set of vertices and a set of edges
connecting these vertices together.
- Notation: graph is G (Graph), set of vertices is V (vertex), set of edges is E (edge).
2. Types of graphs, how to classify and represent graphs on computers.
- How to classify:
+ Classify by set of vertices and edges
Finite graph: When both V and E are finite sets
Infinite graph: When V or E is an infinite set
Note: we only study finite graphs.
+ Classification based on edge properties
Undirected graph: a graph in which all edges are undirected
Directed graph: a graph whose edges are all directed
Mixed graph: is a graph that has both undirected edges and directed edges

+ In addition, we also have the following types of graphs:


Simple graph: is a graph that does not contain rings or double edges
Multigraph: is a graph that contains double edges and does not contain rings
Pseudograph: is a graph that contains both double and circular edges
Point graph: is a graph with only one point and no edges
Empty graph: is a graph that has no vertices or edges.
3. Define binary tree characteristics.
A binary tree is a tree data structure in which each node has at most two branches, called left branch
and right branch. Binary trees are commonly used in many applications, including data storage and
search.
Node: Each element in a binary tree is called a node. Each node can have a maximum of two
children, one on the left and one on the right.
Root Node: The root node is the node at the highest level in the tree. It has no parent node and is the
starting point of the tree.
Leaf Node: A leaf node is a node that has no children, meaning it is located at the last level of the
tree.
Left Branch and Right Branch: Each node can have a maximum of two children, one on the left and
one on the right. These branches are arranged according to a certain rule.
Binary Search Tree (BST): In a binary search tree, each node has a value such that the value of the
left node is less than the value of the parent node and the value of the right node is large. than the
value of the parent node.
Height: The height of a binary tree is the maximum number of levels in the tree. The height of a
binary tree can affect its performance in some operations, such as searching.

4. Defines the spanning tree of the graph.


- Definition: Let the graph G = (V, E) be a connected undirected graph. A subgraph G' of G is called
a spanning tree (or spanning tree) of G if:
+ G' is a tree
+ G' contains all vertices of the tree
- For example:
- Determining a spanning tree is the construction of a tree containing all the vertices of the graph.
- There are two algorithms for determining spanning trees:
+ Determine priorities based on breadth
+ Determine priorities in depth
5. Euler line, Hamilton cycle, 2 isomorphic graphs.
5.1. Euler's 1-line.
- Concept: Given an undirected graph G = (V, E) with n vertices, m edges. The Euler line in G is a
sequence containing all m edges of the graph and has the form P1, e1, P2, e2, ..., Pm, em, Pm+1 such that
edge ei is the edge connecting two vertices Pi and Pi + 1.
-If P1 = Pm+1, we call it a closed Euler line
- If P1 ≠ Pm+1 we call it an open Euler line
- Theorem 1: The undirected and connected graph G = (V, E) has a closed Euler line  the degree of
all vertices in G is even.
- Theorem 2: The necessary and sufficient condition for a connected graph G to have an open Euler
line is that the number of odd degree vertices in the graph is 2.
- Euler graphs are applied in practical problems such as finding the shortest journey for postmen,
garbage trucks, and police patrols.
- Closed Euler line finding algorithm:
+ B1: Select vertex a as the starting vertex. Build a one-line line that closes child C'.
+ B2: Remove edges in C' from the graph. Remove isolated peaks (if any).
+ Step 3: Take a common vertex of C' and the remaining graph to build the next subline C''. Then
merge into C' and return to step 2. Repeat until all edges are inserted into C'.
5.2. Hamiltonian cycle.
- Concept: Given graph G = (V, E). A cycle C is called a Hamilton cycle if it passes through all
vertices of the graph.
+ If there exists a path H with the above properties, then H is called a Hamilton path.
+ The problem of finding Hamiltonian cycles in graphs was raised by British mathematician
Hamilton in 1858.
- Hamilton cycle enumeration algorithm:
Procedure Hamilton(k);
Begin
For y ∈ Ke(X[k-1]) do
If (k =N+1) and (y=v0) then Ghinhan(X[1],. . . , X[n], v0)
Else if Chuaxet[y] then
Begin
X[k] := y;
Chuaxet[y] := False;
Hamilton(k+1);
Chuaxet[y] := True;
End;
End;

5.3. Two isomorphic graphs.


- Definition: two graphs G1 = (V1, E1) and G2 = (V2, E2) are said to be isomorphic to each other if
there exists a bijection f : V1 → V2 such that f preserves the adjacency relationship between pairs of
vertices, i.e.: (u, v)  E1  (f(u), f(v))  E2.
+ Then: f is called an isomorphism.
- Two isomorphic simple graphs will have a one-to-one correspondence between the vertices of the
two graphs preserving the adjacency relationship.
- Comment:
+ Determining whether two graphs are isomorphic or not is not simple because n! One-to-one
correspondence between two simple graphs with n vertices.
+ To show that two graphs are not isomorphic to each other, we show that they do not share a
property that two isomorphic graphs must have (called an invariant):
i. Number of peaks
ii. Number of edges
iii. The level of the peak
- In addition to the three invariants mentioned above, the existence of a simple cycle with a special
length is a useful invariant to show that two graphs are not isomorphic.
- Note: there are no invariants by which two simple graphs can be determined to be isomorphic.
- Two simple graphs have the same invariant quantities, but it cannot be concluded that they are
isomorphic.
6. Algorithms: find Dijkstra's shortest path, find Prim's smallest spanning tree.
6.1. Dijkstra's algorithm.
- Dijkstra is an algorithm used to find the shortest path from a vertex to all other vertices in a graph
with non-negative weights. This algorithm was developed by mathematician and computer scientist
Edsger W. Dijkstra.

- How it works:
+ Create a set of vertices with known shortest paths and a set of vertices that have not yet been
considered.
+ Assign the distance value from the starting vertex to itself as 0, the remaining value is infinity.
+ Select the vertex with the shortest distance from the unconsidered set and mark it as considered.
+ Update the distance from the current vertex to the remaining adjacent vertices through the
considered vertex, if the new distance is shorter.
+ Repeat the process until all vertices have been considered.
- Dijkstra's algorithm:
+ Step 1: L(a) = 0, S = Ø, vV, v  a: L(v) = 
+ Step 2: If z  S then finish.
+ Step 3: Choose v  S so that L(v) is smallest.
Insert v into S.
+ Step 4: For each vertex x adjacent to v and x  S, set: L(x) = min{L(x), L(v) + c(v,x)}
Go back to step 2.
6.2. Prim's smallest frame tree.
- Definition: The smallest spanning tree in a connected, weighted graph is a spanning tree with the
smallest total weight on its edges.
- Algorithm to find the smallest spanning tree:
¤ Prim (Robert Prim - 1957)
¤ Kruskal (Joseph Kruskal – 1965)
- How it works:
+ Starting from any vertex, choose the edge with the smallest weight connecting that vertex with
another vertex.
+ Select the edge with the smallest weight connecting a selected vertex with a vertex that is not yet
in the tree.
+ Repeat the above step until all vertices belong to the tree.
- Prim algorithm:
- Graph G = (V, E) is connected, has n vertices.
+ Step 1: Choose any edge with the smallest weight, place it in the spanning tree.
+ Step 2: In turn, add to the tree the edges with the smallest weight that belong to a vertex of the tree
and do not create a cycle in the tree.
+ Step 3: The algorithm stops when (n - 1) edges are merged into the tree.
- Kruskal algorithm:
- The graph G = (V, E) is connected, has n vertices.
+ Step 1: Choose any edge with the smallest weight, place it in the spanning tree.
+ Step 2: In turn, join the edges with the smallest weight into the tree without creating a cycle in the
tree.
+ Step 3: The algorithm stops when (n  1) edges are merged into the tree.

III. Examine set theory and functions applicable to software engineering


Part 1
1. Let A and B be two non-empty finite sets. If cardinalities of the sets A, B and A  B are 86,
43 and 11 respectively, find the cardinality of the set A  B?

1. Let A and B be two non-empty finite sets. If cardinality of the sets A, B, and A ∩ B are 86, 43
and 11 respectively, find the cardinality of the set A ∪ B.

- Set |A| is the number of elements in the set A, |B| is the number of elements in set B, and |A ∩ B| is
the number of common elements of A and B. Use the formula for the total number of elements of
the union of two sets:

|A ∪ B∣=∣A∣ + ∣B∣ − ∣ A ∩ B ∣

Instead, we have:

∣A ∪ B∣= 86 + 43 – 11 = 118

So, the number of elements of A ∪ B is 118.


2. Let A = {n  N: 30  n < 50} and B = {n  N: 10 < n ≤ 42} and C = {n  N: 5 < n  35}
Suppose D is a set such that D  A and D  B and D  C. What is the largest possible
cardinality of D?
Since A = {n ∈ N: 30  n < 50} and D  A, D = {n  N: 30  n < 50} (1)
Since B = {n  N: 10 < n ≤ 42} and D  B, D = {n  N: 10 < n  42} (2)
Since C = {n  N: 5 < n  35} and D  C, D = {n  N: 5 < n  35} (3)

3. Let A = {1, 2, ..., 10}. Define B2 = {B  A: |B| = 2}. Find |B2|?


|A| = 10, |B| = 2, so every element of B2 is a pair of A’s values.
10 !
=> |B2| = C 210 = = 45
2!∗( 10−2 ) !
4. Consider the sets A and B, where A = {3, |B|} and B = {1, |A|, |B|}. What are the sets?
A={3,∣B∣}
B={1,∣A∣,∣B∣}
For set A, ∣B∣ is the number of elements in set B. So, let's say
∣B∣=n. Then, A={3,n}.
For set B, ∣A∣ is the number of elements in set A. ∣A∣=2. So, B={1,2,n}.
Since ∣A∣=2, substitute this into set B: B={1,2,n}.
Now, notice that n is the same as the second element of set A. So, n=2.
Substitute n=2 back into set B:
B={1,2,2}.
Therefore, the final sets are:
A={3,2}
B={1,2,2}
In summary, set A has elements 3 and 2, and set B has elements 1, 2, and 2.
Part 2:

1. The multi-sets of prime factors of the given numbers are:

a. 1300: The prime factorization of 1300 is 2 x 2 x 5 x 5 x 13, so the multi-set of prime


factors is {2, 2, 5, 5, 13}.
b. 2024: The prime factorization of 2024 is 2 x 2 x 2 x 11 x 23, so the multi-set of prime
factors is {2, 2, 2, 11, 23}.

2. The cardinalities of each multi-set in part 2-1 are:

a. For 1300: The cardinality of the multi-set {2, 2, 5, 5, 13} is 5.

b. For 2024: The cardinality of the multi-set {2, 2, 2, 11, 23} is 5.

3. Sets and multisets are widely used in software engineering. They can be used to represent
collections of items where the order does not matter. A set does not allow duplicate
elements, making it useful for tasks such as removing duplicates from a list or checking
membership. A multiset, on the other hand, allows duplicate elements, which can be useful
for tasks such as counting the frequency of elements.

Here is a simple Python example using sets to remove duplicates from a list:

def remove_duplicates(input_list):
return list(set(input_list))

print(remove_duplicates([1, 2, 2, 3, 4, 4, 5, 6, 6, 7]))

This program will output: [1, 2, 3, 4, 5, 6, 7]

And here is a Python example using multisets (in Python, they are called Counter from the
collections module) to count the frequency of elements in a list:

from collections import Counter

def count_elements(input_list):
return Counter(input_list)

print(count_elements(['apple', 'banana', 'apple', 'orange', 'banana', 'banana']))

This program will output: Counter({‘banana’: 3, ‘apple’: 2, ‘orange’: 1})

Part 3
1. Determine whether the following functions are invertible or not. If it is invertible, then find the
rule of the inverse f-1 (x)
a) For the function f: R -> R+ where f(x) = x2
the function f(x) = x2 is not injective, because there are 2 real numbers that are not images of any
value of x, i.e. no value of x so that x2 = -1
Therefore, f(x) is not bijective => the function f(x) is not invertible
b) For the function f: [0, ] → [-2,2]
f(x) = 2cosx
x = 2cosy
x
cosy =
2
x
=> y = arcos( )
2
x
=> f-1(x)= arcos( )
2
5
2. Function f(x) = (x - 32) converts Fahrenheit temperatures into Celsius. What is the
9
function for opposite conversion?
It can be found by solving the lavation for x:
9
f-1(x) = x + 32
5

3. Present the application of function in software engineering? Give specific programming


example
def calculate_total_price(items):
total_price = sum(items)
if total_price > 100:
total_price *= 0.9 # Apply a 10% discount if total exceeds 100
return total_price
Part 4:

Part 5:

Here is a possible response:

Binary trees are tree data structures in which each node has at most two children, referred to as the
left child and the right child. Binary trees have various applications, advantages, and disadvantages
depending on the type and structure of the tree. Here are two examples of binary trees and their
properties:

 Binary search tree: A binary search tree is a binary tree in which the value of each node is
greater than or equal to the value of its left child and less than or equal to the value of its
right child. Binary search trees are useful for storing and retrieving data efficiently, as they
allow binary search operations on the tree. The average time complexity of searching,
inserting, and deleting in a binary search tree is O(log n), where n is the number of nodes in
the tree. However, the worst-case time complexity can be O(n) if the tree is skewed or
unbalanced. To avoid this, binary search trees can be balanced using various techniques,
such as rotations, red-black trees, or AVL trees
 Huffman tree: A Huffman tree is a binary tree that is used for data compression. It is
constructed by assigning frequencies to each symbol in the data and then creating a tree that
minimizes the total weighted path length of the symbols. The symbols are stored in the
leaves of the tree, and each symbol is encoded by the sequence of left and right branches
along the path from the root to the leaf. The Huffman tree ensures that the most frequent
symbols have the shortest codes and the least frequent symbols have the longest codes, thus
reducing the average code length and the size of the compressed data. The time complexity
of building a Huffman tree is O(n log n)

Part 6 :
1. State the Dijkstra's algorithm for a directed weighted graph with all non-negative edge weights

 Dijkstra’s algorithm for a directed weighted graph with all non-negative edge weights is a
greedy algorithm that finds the shortest path from a given source vertex to all other vertices
in the graph.
 The algorithm maintains a set of visited vertices and a set of unvisited vertices. It starts at the
source vertex and assigns it a distance of zero. It then selects the unvisited vertex with the
smallest distance from the source and marks it as visited. It then updates the distances of its
adjacent vertices by adding the weight of the edge to the current distance of the vertex. If the
new distance is smaller than the previous distance, it replaces it. This process repeats until all
vertices are visited or the destination vertex is reached.
 The algorithm can be implemented using a priority queue or a heap to store the unvisited
vertices and their distances. This allows the algorithm to select the vertex with the smallest
distance in logarithmic time. The algorithm can also return the shortest path by storing the
predecessor of each vertex and tracing back from the destination to the source.

2. Find the shortest path spanning tree for the weighted directed graph with vertices A, B, C, D, E,
F, G given using Dijkstra's algorithm
Weight Edge
1 D -> G
2 A -> B
2 C -> E
2 B -> D
2 G -> E
3 B -> C
3 D -> E
3 E -> G
3 G -> F
4 A -> C
4 C -> B
6 E -> F
L = 2 + 2 + 2 + 2 + 1 + 3 = 12

IV. Reference
Session 1-Set theory
Session 4_Graph theory.

You might also like