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

Tutorial 6 (With Answers)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Tutorial 6 (With Answers)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UCCM1363 DISCRETE MATHEMATICS

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)}.

2. What is the maximum number of vertices in a binary tree of height n?

3. Construct a labeled tree represents the algebraic expression.


(i) (x + (y – (x + y)))  ((3  (2  7))  4)
(ii) ((2  7) + x)  y)  (3 – 11)
(iii) (3 – (2 – (11 – (9 – 4))))  (2 + (3 + (4 + 7)))

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

5. Evaluate the expression which is given in prefix notation.


  + 3 4 – 7 2  12  3 – 6 4

6. Evaluate the expressions which are given in postfix notation.


(i) 4 3 2   5  4 2  5  3  
(ii) 3 7  4 – 9  6 5  2 + 

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.

(ii) R is not a rooted tree because there exists a loop.

(iii) R is not a rooted tree because the graph is not connected.

2. The maximum number of vertices in a binary tree of height n is


1 + 2 + 2 2 + 23 + … + 2 n = 2n + 1 – 1

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–12
postorder: 23+1–2

(ii) preorder: abcghidkejf


inorder: gchbiakdjef
postorder: ghcibkjfeda

(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
=22
=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.

Kruskals algorithm (C,E)


1) Select the three edges (A, C), (B, D) and (C, D) of minimum weight 2.
C, E
2) Select the edge (C, D) of minimum weight 3.
3) Select the two edges (E, F) and (G, H) of minimum weight 4.
4) Select the edge (F, G) of minimum weight 5.
Thus the minimal spanning tree, T = {(A, C), (C, D), (D, B), (C, E), (E, F), (F, G), (G,
B, D
H)} and the weight is 25.
22.

You might also like