BÁO CÁO CUỐI KỲMÔN CẤU TRÚC RỜI RẠCNgười hướng dẫn: TS NGUYỄN THỊ HUỲNH TRÂMNgười thực hiện: NGUYỄN VÕ CÔNG HUYLớp : 20050301Khoá : 24THÀNH PHỐ HỒ CHÍ MINH, NĂM 2021... BÁO CÁO CUỐI KỲMÔ
Trang 1BÁO CÁO CUỐI KỲ
MÔN CẤU TRÚC RỜI RẠC
Người hướng dẫn: TS NGUYỄN THỊ HUỲNH TRÂMNgười thực hiện: NGUYỄN VÕ CÔNG HUY
Lớp : 20050301Khoá : 24
THÀNH PHỐ HỒ CHÍ MINH, NĂM 2021
Trang 2BÁO CÁO CUỐI KỲ
MÔN CẤU TRÚC RỜI RẠC
Người hướng dẫn: TS NGUYỄN THỊ HUỲNH TRÂMNgười thực hiện: NGUYỄN VÕ CÔNG HUY
Lớp : 20050301Khoá : 24
THÀNH PHỐ HỒ CHÍ MINH, NĂM 2021
Trang 3LỜI CẢM ƠN
Em xin chân thành cảm ơn đến cô Nguyễn Thị Huỳnh Trâm, và đội ngũ giảngviên trường đại học Tôn Đức Thắng đã tận tình giảng dạy trong suốt đại dịch giúp emhoàn thành bài cáo này
Trang 4CÔNG TRÌNH ĐƯỢC HOÀN THÀNH
TẠI TRƯỜNG ĐẠI HỌC TÔN ĐỨC THẮNG
Tôi xin cam đoan đây là công trình nghiên cứu của riêng tôi và được sự hướngdẫn khoa học của TS Nguyễn Thị Huỳnh Trâm; Các nội dung nghiên cứu, kết quảtrong đề tài này là trung thực và chưa công bố dưới bất kỳ hình thức nào trước đây.Những số liệu trong các bảng biểu phục vụ cho việc phân tích, nhận xét, đánh giá đượcchính tác giả thu thập từ các nguồn khác nhau có ghi rõ trong phần tài liệu tham khảo.Ngoài ra, trong luận văn còn sử dụng một số nhận xét, đánh giá cũng như số liệucủa các tác giả khác, cơ quan tổ chức khác đều có trích dẫn và chú thích nguồn gốc.Nếu phát hiện có bất kỳ sự gian lận nào tôi xin hoàn toàn chịu trách nhiệm
về nội dung luận văn của mình Trường đại học Tôn Đức Thắng không liên quan đếnnhững vi phạm tác quyền, bản quyền do tôi gây ra trong quá trình thực hiện (nếu có)
TP Hồ Chí Minh, ngày 25 tháng 12 năm 2021
Tác giảHuy
Nguyễn Võ Công Huy
Trang 5TÓM TẮT
Bài báo cáo bao gồm các nội dung cốt lõi, chung nhất của môn Cấu Trúc RờiRạc, giúp nắm vững nền móng các hướng tư duy thuần cơ bản nhằm giúp sinh viên ghinhớ và hiểu sâu hơn về bộ môn này
Trang 6MỤC LỤC
LỜI CẢM ƠN i
TÓM TẮT iii
MỤC LỤC 1
DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT 2
DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ, ĐỒ THỊ 3
Question 1 – Euclid’s algorithm and Bezout’s identity 4
Question 2 – Recurrence relation 5
Question 3 – Set 7
Question 4 – Relations 8
Question 5 – Multiplicative inversion 9
Question 6 – Kruskal’s algorithm 11
Question 7 – Eulerian circuit 15
Question 8 – Map coloring 18
TÀI LIỆU THAM KHẢO 25
PHỤ LỤC 26
Trang 7DANH MỤC KÍ HIỆU VÀ CHỮ VIẾT TẮT
CÁC KÝ HIỆU
CÁC CHỮ VIẾT TẮT
Trang 8DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ, ĐỒ THỊDANH MỤC HÌNH
DANH MỤC BẢNG
Trang 9Question 1: Euclid’s algorithm and Bezout’s identity
a Using Euclid’s algorithm to calculate gcd(2021, 1000 + m) and lcm(2021, 1000 +m), where m is the last 3 digits of your student ID
SolveStudent ID : 52000765 m = 765
Let’s trace Euclid’s algorithm to calculate gcd(2021;1765)
Equation : 2021x + 1765y = gcd(2021; 1765)
1 = 27 – 13*2 = 27 + 13*(–2)
Trang 10= 27 + (229 – 27*8)*(–2) = 229*(–2) + 27*17
= 229*(–2) + (256 – 229)*17
= 229*(–19) + 256*17 = (1765 – 256*6)*(-19) + (2021 – 1765)*17 = [1765 – (2021 – 1765)*6]*( –19) + (2021 – 1765)*17
= [2021*(–6) + 1765*7]*( –19) + (2021 – 1765)*17
= 2021*131 + 1765*(–150)
Thus 1 = 2021*131 + 1765*(–150)
Due to the form of equation: ax + by = d, so
Once a solution pair (x, y) is found, additional pairs may be generated by , where k is any integer
Question 2: Recurrence relation
Solve the recurrence relation
an = 8a – 15an−1 n−2
with a0 = 5 and a1 = m, where m is the last 2 digits of your student ID
SolveStudent ID : 520007 m = 65 65
Trang 11Suppose a sequence a , a , a ,… satisfies the recurrence relation0 1 2
an = 8a – 15an−1 n−2 for every integer n 2,with initial conditions
a0 = 5 and a = m = 65.1
This sequence sitisfies part of the hypothesis of the single-root theorem because
it satisfies a second-order linear homogeneous recurrence relation with constantcoefficients(A = 8 and B = –15) To check that it satisfies the second part of thehypothesis, examine the characteristic equation
t2 – 8t + 15 = 0
By the quadratic formula t = 5, t = 3 [since t2 – 8t + 15 = (t – 5)*(t – 3)] and so theroots are distinct Thus it follows from the distinct-roots theorem that the sequence isgiven by the explicit formula
an = C*5 + D*3n n for each integer n 0Where C and D are the numbers whose values are determined by the fact that a = 5; 0
a1 = 65 To find C and D, write a = 5 = C + D and a = 65 = 5*C + 3*D0 1
Now substitute C = 25 and D = 20 into formula to conclude that –
an = 52 + n – 20*3n for each integer n 0
Question 3: Set
a Create a set Γ of characters from your case-insensitive non-diacritical full name For example, the set corresponding with “Tôn Đức Thắng” is Δ = {A, C, D, G, H, N, O, T, U}
Solve
My full name: “Nguyễn Võ Công Huy”
Trang 12Γ = {C, E, G, H, N, O, U, V, Y}
b Find the union, intersect, non-symmetric difference, and symmetric difference of Γ and Δ, where Γ and Δ are from question 3a
SolveRewrite : Γ = {C, E, G, H, N, O, U, V, Y}
Trang 13Question 4: Relations
Let be a binary relation defined on 2 integers as follow: ℜ
∀∀ , � ∈ N (aRb↔� |(�.�))where m is the last 2 digits of your student ID
Is R reflexive, symetric, anti-symetric, transitive? Prove your answer
SolveStudent ID : 520007 m = 65 65
Rewrite the binary relation defined on 2 integers subtituted:
∀∀, N (aRb↔65|(� ∈ � ))�
R is not reflexive: To show that R is reflexive, it is necessary to show that
For every a N, aRa∈
By definition of R, this means that
For every a N , 65|(a.a),∈which is false because a.a = a and a N such that 65 a As a counterexample, let a2
∃ ∈ ∤ 2
= 4 a = 16 and 652
∤16
Hence R is not reflexive
R is symmetric: To show that R is symmetric, it is necessary to show that
For every a N, if aRb then bRa∈
By definition of R, this means that
For every a N, if 65|(a.b) then 65|(b.a)∈
which is true because a.b = b.a by the commutative law of multiplication F1(A-1 Epp)Hence R is symmetric
Trang 14R is not anti-symmetric: To show that R is anti-symmetric, it is necessary to show that
For every a N, if aRb and bRa then b = a∈
By definition of R, this means that
For every a N, if 65|(a.b) and 65|(b.a) then b = a∈
which is false because 65|(a.b) and 65|(b.a) but a and b can be different As acounterexample, a = 1 and b = 65 then 65|(a.b) and 65|(b.a) but 1 ≠ 65
Hence R is not anti-symmetric
R is not transitive: To show that R is transitive, it is necessary to show that
For every a ,b, c N, if a R b and b R c then a R c∈
By definition of R, this means that:
For every a,b,c N, if 65|(a + b) and 65|(b+ c) then 65|(a + c).∈
which is false because a = 42, b = 23, c = 107 then 2|(a + b) and 2|(b+ c) but 65 (a + c).∤Hence R is not transitive
Question 5: Multiplicative invertion
a Study and present your knowledge about Extended Euclidean algorithm to compute multiplicative inverses in modular structures
SolveThe version of the Euclidean algorithm described above (and by Euclid) can take many subtraction steps to find the GCD when one of the given numbers is much bigger than the other A more efficient version of the algorithm shortcuts these steps, instead replacing the larger of the two numbers by its remainder when divided by the smaller of the two (with this version, the algorithm stops when reaching a zero remainder) With this improvement, the algorithm never requires more steps than five times the number of digits (base 10) of the smaller integer
Trang 15b Apply the algorithm to find (m+1) (mod 101) where m is the last 2 digits of your-1
student ID
SolveStudentID : 52000765 m = 66
Trang 16Question 6: Kruskal’s Algorithm
Propose a solution for circuit-checking in Kruskal's algorithm
SolveThis is a graph example to find a solution for circuit-checking in Kruskal’s algorithm
as follow:
Trang 17Step 1: Remove all loops and ParallelEdges (*Note: In case of parallel edges, keep theone which has the least cost associated and remove all others).
Step 2: Create a set of edges and weight, and arrange them in an ascending order ofweightage (cost)
B,D D,T A,C C,D C,B B,T A,B S,A S,C
Step 3: Add the edge which has the least weightage
Now we start adding edges to the graph The least cost is 2 and edges involved are B,Dand D,T We add them Adding them does not violate spanning tree properties, so wecontinue to our next edge selection
Trang 18Next cost is 3, and associated edges are A,C and C,D We add them again
Trang 19Next cost in the table is 4, and we observe that adding it will create a circuit in thegraph So we ignore it In the process we shall avoid all edges that create a circuit.
We observe that edges with cost 5 and 6 also create circuits We ignore them and move
on Now we are left with only one node to be added Between the two least cost edgesavailable 7 and 8, we shall add the edge with cost 7 By add edge S,A we haveminimumcos spanning tree
Trang 20Question 7: Eulerian circuit
a Does the following graph have an Eulerian circuit or Eulerian path? Why?
1873 by Carl Hierholzer
Thus, the graph don’t have Eulerian path
Trang 21b Study and present your knowledge about Hierholzer’s algorithm to find an Eulerian circuit.
Solve
We start with a random node and then follows an arbitrary unvisited edge to a neighbour This step is repeated until one returns to the starting node This yields a firstcircle in the graph If this circle covers all nodes it is an Eulerian cycle and the algorithm is finished
Otherwise, one chooses another node among the cycles' nodes with unvisited edges and constructs another circle, called subtour By choice of edges in the construction the new circle does not contain any edge of the first circle, both are disjunct However, both circles must intersect in at least one node by choice of the starting node of the second circle Therefore one can represent both circles as one new circle To do so, one iterates the nodes of the first circle and replaces the subtour's starting node by the complete node sequence of the subtour Thus, one inegrates additional circles into the first circle If the extended cycle does include all edges the algorithm is finished Otherwise, we can find another cycle to include
In the case of an undirected, semi-Eulerian graph the algorithm starts with one of the two nodes with odd degree In the directed case with the node with one additional outgoing edge One of the subtours to be found will then not form a cycle, instead it will also be a path When integrating this "subtour" into the circle one has to make surethat start and end node of this path also form start and end of the complete Eulerian path
Trang 22c If the graph has an Eulerian circuit, use Hierholzer's algorithm to find an Eulerian circuit of that graph when the initial circuit R1 is:
SolveStudent ID : 52000765 abcd % 4 = 1 R1 is abhga
The initial circuit R1: a b h g a
Trang 23Question 8: Map Coloring
Give this map:
Trang 24a Modeling this map by a graph.
Solve
b Color the map (graph) with a minimum number of colors Present your solution step
by step
SolveStudent ID: 52000765 abcd % 4 = 1 Start from Orissa
Trang 25Step 1: Choose Orissa vertex and color it with Red.
Trang 27Detail: Look at the graph, we can see vertices like: West Bengal, Jharkhand,Chhattisgarh, Telangana, Andhra Prahdesh adjacent with Orissa so we can colour themsame color.
Repeat this thing and priority is given to vertices of higher degree So we colorUttar Pradesh(9), Maharashtra(7), Assam(7) same colour with Orrisa, and we checkcontinue to the non-adjacent vertices, and we can colour vertices like: Laskshadweep,Andaman and Nicobar Islands, Tamil Nadu, Daman and Diu, Punjab and Sikkim samecolour with Orrisa
Trang 28Step 3: Choose a new color (Yellow, Blue, Green,…v.v), and repeat what we did inStep 2 for vertices not already colored.(The second color is Yellow, the third color isGreen and the final color is Blue).
Trang 29Step 4: Repeat Step 2 until all vertices are colored.
Trang 30All vertices is colored.
Trang 31TÀI LIỆU THAM KHẢO
Tiếng Việt
1 Đại học Tôn Đức Thắng – Tài liệu lý thuyết môn Cấu Trúc Rời Rạc
2 Thien Hoang (tvhoang.com) – Thuật toán Euclid mở rộng, Nghịch đảo Modulo, và Định lý số dư Trung Quốc
3 Chuong Le Hoang (wordpress.com) – Thuật toán Kruskal – Tìm cây bao trùmnhỏ nhất
Tiếng Anh
4 GeeksforGeeks – Euclidean algorithms (Basic and Extended)
5 Javatpoint – Kruskal's Algorithm
6 GeeksforGeeks – Eulerian path and circuit for undirected graph
7 GeeksforGeeks – Hierholzer's Algorithm for directed graph
8 Dr Rhyd Lewis – Cardiff School of Mathematics, Cardiff University
9 Lewis, R (2015) – A Guide to Graph Colouring: Algorithms and
Applications Berlin, Springer
Trang 32PHỤ LỤC