Discrete Maths Practices
Discrete Maths Practices
Practice Class 6
12-03-2024
I1 dis &
O I I 10 O G
10 S
I E
10
A :
· I O
(ii) Create this graph in Magrada, introducing the weighting matrix (Menu Graph, option New,
Select Weighted, Insert Weighted adjacency matrix). Check the adjacency matrix computed
in (i) using Magrada (Menu Basic Calculations, option Adjacency matrix).
number : 1 2 3654789
(i) Apply the numbering algorithm of vertices and argue if the graph has circuits or not.
V =
(a ,
b ,
c ,
g ,
e ,
f ,
h , m . r4 -
din(a) = 0
v" = v -(a) =
(b ,
c , g ,
e , fi h , m
, r) >
-
din(D) =
v3 = v -(b) =
(c ,
g ,
e , f ,
n ,
m , r) - din( = 0
v" = ve -(c) =
(g ,
e , f ,
h ,
m ,
r1 -
Din (f) =
v
S
= v" w(f) (g e h r) = , , ,
m , -
din(e) = 0
vS vs
whe) yg h mir) din (g) 0
= - =
= ,
,
=
v =
us w/g) (n r) =
,
m ,
-o din (h) =
v8 =
r4
=
=
v whh) hm din (m)
=
-
V Vawhrl
= ,
9
V -
10 ~hml = bri - din (r) 0 = - :
By doing the
numbering algorithm ,
we arrive to the last iteration
circuits. The
the
graph has no
resulting graph with the numbers
that we
get by doing the algorithm is the next :
5
2 >
- 6
T go
&
3
3 9
4 &
-
f
I f
5 7
-
9
T 9
↑
6
5
2 v 3
I 3 1
3 ~
3
D 4
2
D g
(ii) Using Bellman’s equations, compute the shortest paths and their weights from the initial vertex
a to the rest.
0
u
=
en
= min
(e ,
+ w
, 2) =
minh 3) = 3
M
way) min(2 3 + 1) 2
ye
= =
3 min + W un + =
,
, , g
,
was) min(3 + 2 2 + 6 5 +
3) =
7
miri(uz
+ =
= + was Me +
was ,
un ,
,
Ms ,
Ms = min
(M2 + Was , ug
+
was) =
min(3 + 5
,
7 +
3) = 8
u
z
=
min(my +
Wyz , My
+
ws) =
min(5 + 5
,
8 + 94 = 10
mo =
min(mn +
wy8 , uz + w = 0) =
min(5 + 2
,
10 +
3) =
7
Ma =
min(us +
wjq ,
xz + wa ,
n8 +
woa) =
min(8 + 8
,
10 +
1 ,
7 + 1) = 8
(iii) Introduce the graph in Magrada using Graphic Mode. Check the result of (ii) with Magrada
(Menu Algorithms, Option Shortest paths in acyclic graphs, first select Renumber and then
Apply).
Problem 3. Bake a cake project.
2. Clean up kitchen 45 -
4. Prepare frosting 15 1, 2
5. Prepare batter 30 2, 3
6. Bake 60 5
7. Frost cake 30 4, 6
(i) Draw the graph that represents the project (including the fictitious vertices representing the
start and the end of the project).
130 -
End
-
6
Start -
O
2
- %
st 30
- 5 - 6
3
(ii) Obtain the weighting matrix of the graph.
Io I
S O O G D D D D ①
1 & *
N N 30 ↓
⑭
Z # * - 45 45 N - 8
2
- W - 30 * *
* 2
* - -15 *
↓
* 300
5
W
30
F * X
⑧
12345678 9
(iv) Compute the critical path and the minimum time needed to complete the project.
u 1
= 0
= 0 + 0
= 0
vz
= u + we
,
0 0 = 0
M3 =
mi +
wez
= +
mi + 0 =
0
My Wy 0 +
=
=
us
=
max(uz +
wz ,
uy
+
was) = max
/30 497 ,
= 45
u
=
max(uy +
wy6 ,
uy +
was) =
max 745 ,
307 = 45
=
My nj
+
wjz = 45 + 30 = 75
up =
max(ug +
8 ,
17 + w =
8) = max
160 1354
,
= 135
=
ma My +
w8q = 139 + 30 =
165
(i) Use Dijkstra's algorithm to find the shortest path and its weight between the vertex a and the
others.
Iteration 1 : Iteration 2 : Iteration 3 :
p ha d) P
(a 0 b)
(a)
=
P =
=
,
, ,
T =
(b ,
c
,
0
,
e
,
f ,
g ,
h) T =
(b ,
c ,
e , f , g , h) T =
(c ,
e ,
f , g h/ ,
Ma = 0 =
2 = min (4 4) = 4
My
u ,
c
Mb = 2
4
Me =
min (0 , 4) = Y
uc =
Mc = * uf =
0
Me = 0
ug
= 6
ur
!
=
uf = x
=
un = 2
Me
S
uf = x
vg =
Ng N
un
=
= @
Mn = X
Iteration 4 Iteration 6 :
Iteration 7 :
:
p ha d b c e h)
P :
(a ,
0 ,
b
, c) p =
na ,
0 ,
b ,
c
, e) =
, , , , ,
(7 4 T =
(f g)
4)
i
he f g
= ,
g
,
T
,
= , , .
7 min (6 11) : 6
min(8 , 7)
=
ug
= ,
=
Me
=
h uz
min (7 6) = 6
uf
=
8
,
6
Me
= min(0 ,
4 + 4) =
ug
=
Mn = 5
6
my =
un : -
h
weight
I
pa +
Iteration 8
ad - 1
d b e h
g) a tod -
P (a
c
= , , , ,
, ,
- ab
to b -
2
T =
3f) a
= min (6 12) =
6 to c- abc -
4
uq
,
a to e-able 4
a to h - abeh-5
C to adg -6 g
-
6
a to f-abehf >
-
(ii) Introduce the graph in Magrada using Graphic Mode. Check the result of (i) with Magrada
(Menu Algorithms, Option Dijkstra).
Problem 2. It is known the iteration m = 5 of the Floyd-Warshall’s algorithm:
I ( I (
↓ Z 2 S 6 [12] 2 25 6
:
Y
e 8
-
[14] [is] [is] 38
6 881112
688m1
I
g
I & ↑ es
ee(
- eec
G
- - · d se &
b
3
- C
8
- C
-
-
-
-
- -
[a] [e [e][9 b
ecd ec
g
a e a e
from to b
weight is :
the shortest
path and his a
path : a -e -c -
b weight :
11
b to 2 is :
and the shortest path and his weight from
path : b -
a -
e -
c
weight : 13
Problem 3. A computer network connects 5 points A, B, C, D and E. The connections can be
represented using an undirected weighted graph, where the weights assigned to the edges
represent the time in milliseconds needed to transmit a word from one point to another. We need
to know the minimum transmission time routes between each pair of points. Express the general
solution for any pair of points using a matrix. Calculate, in particular, the route for the connection
from A to C and the time necessary for this connection. On the other hand, it is known that the
links from point B fail sometimes. When this failure occurs a message can not pass through point
B. Calculate the minimum transmission time alternative route to use it, from A to C, in the case
that this failure takes place.
B -
X
D
-
&
-
3
-
=
- g
E
a)
a) I
a a
a
The route connection between
bb
A and C is :
C C
The -b
path to follow : a -
e -
~
a a a
operative R",
C
we look at the second
shortest route from A to ) is
passing through
D the
being path A-D-C and
being 7 long.
/I
[b] ,
,
ms
b b
C
=.I
a
a b
CC
b b
: eb b
I
~ I
0]
S
2 a a
b
is
a b
= [0] ( CC
3 G G G b b
2 e b b
a b c d e
·I
J
le
2 I Y a a
b b
(e) es
a
↓
( C
b b
Problem 4. A computer network connects 5 points A, B, C, D and E. The connections can be
represented using an undirected weighted graph, where the weights assigned to the edges
represent the time in milliseconds needed to transmit a word from one point to another. We need to
know the minimum transmission time routes between each pair of points. Express the general
solution for any pair of points using a matrix. Calculate, in particular, the route for the connection
from A to C and the time necessary for this connection. On the other hand, it is known that the links
from D fail sometimes. When this failure occurs a message can not pass through point D.
Calculate the minimum transmission time alternative route to use it, from A to C, in the case that
this failure takes place. It is known the penultimate iteration (m = 5) of the Floyd-Warshall
algorithm.
I I I I
2 (5) 1[4] 3
(s) 2[n] + 2
a
(B) B[D] A B
= 8 = C BE [D]
1 [u) 2 (3)2
[D] B(D] A B
[u) e (3)2 1
DB D DB
12
322
D C
time route A-B
-
4
-
: ms :
Since B is
If the message
can not pass through D ,
alternative
to A need to find an
connection we
the only ,
with time
has a more direct connection to c
,
route to C B
just
need
.
without A-B-C we
alternative path D is ,
3 .
ms Since the only
from B to .
C
A to B and
to sum the times from
A to B = 5 ms
1 + 3 =
.
B + 2 =
Y
Discrete Mathematics
Practice Class 8
16-04-2024
Problem 1. A computer network is to be set up for a system of five points. Connection possibilities
are given in the following graph, where the weights assigned to the edges represent the cost of
construction of the corresponding line.
26
es
27 el
es ey
23
2z
(i) Use two different algorithms to design a minimum-cost communications network connecting all
the computers represented by the graph.
(1 numbered
Using -> First we order the
edges by weight in
ascending order
already
them in the
graph above (
Kouskal's
OGa en j
Algorithm FINAL
es ese
e ,
SPANNING TREE
the in
We select one
by one
edges 2 3
order the ones that form cycles. 4
, excluding
The
resulting edges
are the following :
I 1
+ =
449 , 24 49 34 44 34 64
, , ,
,
, ,
934
3
And Lastly we sum the weight of them :
h
5
3
1 + 3 + 3 + 4 =
11
gro Iteration
- 1st Iteration zno Iteration
Using T 49 43 74 37 0 31 = 3 41
be 21
= , ,
, , ,
he us 0 :
Prim's T : ,
,
T =
Q 0 :
beg L(2) = min (4 , 5) : 4
8) 4
min (4
:
Algorithm
= ,
L (2) L (5) = min (3 4) = 3
222)
,
= 4
min(0 1) = 1
((3)
,
=
((3) =
[8 3) : 3
L(s) = min ,
L(4) = 3
L(s) = 8
Final Solution :
th Iteration
i =
41 74 64 33
, , , ,
44 91,
i = 169 , 44 44 31 ,
.
,
64 54, ,
49 .
24
v 41 2 3 4 34
97
=
,
31
,
3 4
, ,
u =
, , ,
5) = 4 Total Weight :
((2) = min (4 ,
3 + 4 = 19
3 + 1 +
(ii) Solve this problem using Magrada (Menu Algorithms, Option Kruskal and Option Prim).
(iii) In addition, assuming that the traffic between points 3 and 5 will be very intensive, it is desired
a direct communication between 3 and 5 and with minimum cost. Modify the previous algorithms
(explaining those modifications) and apply them to solve this problem.
Clue:
๏ Kruskal: First, write this edge and then order the rest of the edges in an ascending order of
-
weights.
๏ Prim: Initialize:
T = {{3, 5}}, U = {3, 5}
For v ∉ U, L(v)= mín{wuv, u ∈ U},
From this initialization, Prim’s algorithm is applied in the usual way.
Kruskal :
we move ey13 51 ,
to the first position and continue with the
algorithm as
normally
& en Get
FINAL
SPANNING TREE
2 3
4
final Path :
i =
733 97 43 73 42 47 ,
, ,
42 . 24h Y
I 1
, ,
,
final Weight :
3
4 + 1 + 3 + y =
12
5
h
Primi
gro Iteration
1st Iteration zno Iteration
43 33 73 74 6e 47 0 31 3 7
51
77 T
=
43
= , ,
5
,
, , ,
43 57 33 210
,
= ,
T
,
= ,
33 57
,
(3 570
,
(4 , 5) 4
,
T =
,
= L(2) = min :
min (8 , 3)
,
= 3
=
8) =
8 (1)
min (0
(21) = ,
min (5 a) = 5
(2)
,
=
25 5) : S
↓
(2) = min ,
L (4) = min (1 ,
3) =
1
Final Solution :
i = 161 , 43 44 31 ,
,
,
43 39, ,
49 ,
231
v =
49 ,
2 ,
3 ,
4 , 34
Total Weight :
3 + 4 = 1
4 + 1 +
Problem 2. We are interested in designing a minimum-cost network connecting six computers
A,B,C,D,E, F. The connection cost of each pair of computers is given in the following table.
If there is not a value in the table, this indicates that the corresponding connection is not feasible.
Which links should be made to ensure that there is a path between any two computers so that the
total cost of the network is minimized? Solve this problem in two different ways, using two different
algorithms. Kruskal :
-
#
8O
C
G
⑳ eb
a
E
eby
Y
cab eene
eae
D E
= =
A B c
↓
WEIGTH
I
FINAL
3
1 + 2 + 3 + 3 + 5 = 14
E = F
D
Pri
:
(b e) 0 4b e) T =
(b e) he f) V =
(b e
f)
(b)
= , , ,
,
T
Qu
= ,
=
T , ,
=
(5 %) S
min (5 9) : 5 (cal = min ,
:
((a) = ,
= 5 L() (b 8) 3
((a) min =
=
(() = min (3 , 8) = 3 ,
3 ((0) min (x 0) a
((c)
= =
=
8)
,
((O) = min (0 ,
= -
L(0) = 0
((f) = min (4 ,
2) = 2
((e) = 1
L(f) =
4
4b 7, T /b ed he 7) 1b c 1 4 b al U =
(b e 8 2
9
(b e7 he +7 bb
=
c) U e , , , , , ,
=
T , , . ,
= , , ,
, , ,
, ,
LCO) : min (5 3)
,
= 3
8) 5
min (5
=
((a) = ,
(0 5) 5
(20) = min ,
=
T =
(4b , e3 ,
he 3 4 b 34
,
,
,
,
ha b) 4a ,
,
,
01]
v = a
,
b ,
c ,
0
,
e ,
7)
Final Weight : 1 + 2 + 3 + 3 + 5 = 14
Discrete Mathematics
Practice Class 9
23-04-2024
28110 =
1000110012
1148 I 2
I
2
O 7O
2
033
1 17 L
2
1 8 L 2
O Y L
2
O 2 L
2
O I
2 .
8 + 5 .
8 = 15253
336258 =
1523310
Problem 2. Compute using the Euclidean algorithm d = gcd(46,24) and using the steps of that
algorithm, express d = gcd(46,24) as a linear combination of 46 and 24, i.e., find a solution of the
Bézout’s Identity. Find this solution, in two different ways, using both studied methods.
4624 22
24 2
22 g2d(46 ,
24) =
2
1 0 11
22 1 2
,
46x 2
(6y
=
+
2 = 24 -
22
46
2 =
24 -
(45 -
24) = 2 .
24 -
2 =
2 .
24 -
1 .
46
-
-
gad (25 ,
115) = 5
1152234 1540
3 M
10
10 1
194
(ii) Using the steps of that algorithm, express d = gcd(25,115) as a linear combination of 25 and
115, i.e., find a solution of the Bézout’s Identity
115 s + 25 t = d.
Find this solution, in two different ways, using both studied methods.
11522341340
3 M
10
O
10 1
15 4
5 =
15 -
10
19) 2 15 1 25
(25
-
5
. .
=
=
15
-
-
115 9 25
(115 25) 1 25 2
- .
5 = 2 .
-
4 .
- . = .
(-9) = 5
>
- 115 .
2 + 25 .
(i)(ii)(ii)(ii) (in)(in)(ii)
:
:
=
(i)(ii) (ii) :
Problem 1. Find the greatest common divisor (gcd) of the following pairs a and b using the
Euclidean algorithm. Then, using the gcd compute the least common multiple (lcm) of those pairs.
Check the results with ArtEM.
255)
i) L
4422552952187
187 46844 5117
g(d(442 17
=
0 3
68 512 171
1871 A ,
442 .
255 =
gc (n42 , 255) ·
km (442 ,
255)
km (442 ,
255) = 442255 : 6630
17
28 O G
1681 I
3641 1961
568
124
.
iii) -
5322852852247 (532 289) = 19
247 1 381
38
247
19 6
38119
02
gad ,
km (532 ,
285) =
2285 : 7980
(3960 2541) 33
god
=
,
2541
kcm (3960 , 2541) 24460
.
: = 304920
33
Problem 2. Decide whether the following diophantine equations have a solution. If they do have a
solution, find all such solutions to the equation. Notice that you can use the results from Problem 1.
Check the results with ArtEM.
i) 442 x + 255 y = 17
ii) 924 x + 560 y = 84
iii) 532 x + 285 y = 27
iv) 3960 x + 2541 y = −132
i) gcd (442 ,
255) = 17 & 17117
17 68 (187 68 3 68 187
-
: - .
= . -
17 =
3 .
(255 -
187) -
187 = 3 :
255 -
4 -
187
17 = 3 .
255 -
4 .
(442 -
255) = 4 .
442 + 7 .
255
Bezoot's
28 = 196 -
168
C -
3 , 5)
28 = 196 -
(364 -
196) = 2 .
196 -
364
Solution :
28 = 2 .
(560 -
364) -
364 = 2.960 -
3 .
364(-3 .
3 5 ·
3) = ( - 9
,
15)
,
28 : 2 .
560 -
3(924 -
560) : 5 .
560 -
3 .
924
(3960
=
132 - .
-
Bezout's :
33 231 66 3
53)
=
- -
( -
34 ,
33 : (31 -
3 .
-
Solution :
(1177 297) 3 4 1122 15 297
4))
297
-
33 4 3 = . .
- .
.
= .
-
=
53 (
(( ( 34)
.
1419 4)
1122)
. -
4 (1419 19
-
33 : .
1122 -
15 . -
= 19 .
1122 -
.
,
= .
tablet =
y
(620 460
1) Find
gcd ,
160140140 460)
I
20
2620
=
62020400/100
46
gcd ,
has solutions
1601 1402 20 1
2016000 0
2) Bezoot's equation :
20 = 160 -
1 - 140
160 1 460
160) 3
- .
= .
(460 2
- .
20 = 160 -
1 .
20 = 3 .
(620 -
1 .
460) -
1 .
460
20 = 3 .
620 -
4 .
460
20
460y
=
60000
= 20 300
since
-
(4)) 19000 -
12000
3000
=
3
diophantine 3000
,
A
·
4) solution
generic :
9000 + 23k
h
X =
620/20
=
31
2
=
17000
-
31k
y
= -
B = 460/20 = 23
5) Valid solutions
- - 12000
-
3117750
X - 9000 + 23k750 y
-
31k), 12050
23k7
-
8950
389
ky -
0
177
-
23
The only valid solution between
K7, -389
[-389 ,
-389] is 1 = -389
59
.
the
generic solution ,
we get X = 53 and
y
=