Tutorial 6 (With Answers)
Tutorial 6 (With Answers)
TUTORIAL 6
1. Let R be a relation defined on the set A = {1, 2, 3, 4, 5, 6}. Determine whether
R is a rooted tree and if it is, find the root.
(i) R = {(2, 1), (3, 4), (5, 2), (6, 5), (6, 3)}.
(ii) R = {(1, 1), (2, 1), (2, 3), (3, 4), (4, 5), (4, 6)}.
(iii) R = {(1, 2), (1, 3), (4, 5), (5, 6)}.
4. Show the results of performing preorder search, inorder search and postsorder
search of the trees shown.
(i) (ii)
a
b d
2
+ c e
1 i k
g h j
2 3 f
(iii) 1
2 3
4 5 6
7 8 9 10
11 12
1
UCCM1363 DISCRETE MATHEMATICS
7. Find a minimal spanning tree for the following graph by using Prim’s
algorithm and Kruskal’s algorithm.
(i)
A 4 B
5
2 3
2
C
1
D
(ii) B 2 D F
5
5 4
3 4 G
3
E 4
2
A 2 C 5
H
2
UCCM1363 DISCRETE MATHEMATICS
Solution 6
1. (i)
Vertex 1 2 3 4 5 6
In-degree 1 1 1 1 1 0
Since every vertex has in-degree 1 except vertex 6 has in-degree 0, so
R is a rooted tree with root = 6.
3. (i)
+
x 4
+
y 3
x y 7
2
(ii)
+ y 3 11
x
2 7
(iii)
+
3 2 +
+
2 3
11
4 7
9 4
3
UCCM1363 DISCRETE MATHEMATICS
4. (i) preorder: +2312
inorder: 2+3–12
postorder: 23+1–2
(iii) preorder: 1 2 4 7 5 8 11 3 6 9 10 12
inorder: 4 7 2 8 11 5 1 3 9 6 12 10
postorder: 7 4 11 8 5 2 9 12 10 6 3 1
5. + 3 4 – 7 2 12 3 – 6 4
= (3 + 4) (7 – 2) 12 3 (6 4)
= 7 5 12 3 2
= (7 5) 12 (3 2)
= 2 12 6
= 2 (12 6)
= 2 2
=22
=4
6. (i) 4 3 2 5 4 2 5 3
= 4 (3 2) 5 (4 2) 5 3
= 4 32 5 8 5 3
= (4 3
2 ) 5 (8 5) 3
= 5
2 5 40 3
= ( 52 5) (40 3)
= 25
2 40
3
= 15
16
(ii) 3 7 4 – 9 6 5 2 +
= (3 7) 4 – 9 (6 5) 2 +
= 21 4 – 9 30 2 +
= (21 4) 9 (30 + 2)
= 17 9 32
= (17 9) 32
= 153 32
= 153 32
= 153
32
4
UCCM1363 DISCRETE MATHEMATICS
7. (i)
Prim’s algorithm
Choose an arbitrary vertex, choose A.
Nearest neighbor of A with minimal weight: C. (A, C)
Nearest neighbor of A and C with minimal weight: D. (C, D)
Nearest neighbor of A, C and D with minimal weight: B. (D, B)
Thus the minimum spanning tree, T = {(A, C), (C, D), (D, B)} and the weight is 5.
Kruskals algorithm
1) Select the edge (C, D) of minimum weight 1.
2) Select the two edges (A, C) and (B, D) of minimum weight 2.
Thus the minimal spanning tree, T = {(A, C), (C, D), (D, B)} and the weight is 5.
(ii)
Prim’s algorithm
Choose an arbitrary vertex, choose A.
Nearest neighbor of A with minimal weight: C. (A, C)
Nearest neighbor of A and C with minimal weight: D. (C, D)
Nearest neighbor of A, C and D with minimal weight: B. (D, B)
Nearest neighbor of A, B, C and D with minimal weight: E. (C, E)
Nearest neighbor of A, B, C, D and E with minimal weight: F. (E, F)
Nearest neighbor of A, B, C, D, E and F with minimal weight: G. (F, G)
Nearest neighbor of A, B, C, D, E, F and G with minimal weight: H. (G, H)
Thus the minimum spanning tree, T = {(A, C), (C, D), (D, B), (C, E), (E, F), (F, G),
(G, H)} and the weight is 25.