You are on page 1of 4

124ms Logic and Sets

Tutorial Sheet 3: Matrices, Graphs and Networks


Topics covered: relations and matrices, graphs, spanning trees, adjacency matrix, con-
nectedness, Dijkstras algorithm, edge connectivity, applications of trees.

1. We have sets A = { a, b, c, d}, B = {1, 2, 3} and C = {w, x, y, z}, and relations R


on A B and S on B C given by

R = {( a, 1), ( a, 2), (c, 3), (d, 1), (d, 3)}


S = {(1, w), (1, x ), (1, y), (1, z)}.

Give the matrices of truth values for R and S, and hence find the matrix for R; S.
Also find R; S by inspection, and check that you get the same answer both ways.

2. Given the matrices A and B defined by



  1 3
2 1 0
A= B= 0 1
1 1 3
4 2

Find M = AB, N = BA, M2 and N 2 .

3. Find the degree of edge-connectivity of each of the following graphs:-

(a) q 1 5p (b) 1q q2 (c) p q2


1
4q p4
q 3 q
3
q p q p
q p 5 6 3 4
2 6

4. For each of the graphs in the previous questions, find whether it is possible to
travel round the graph

(a) travelling along each edge exactly once.


(b) visiting each node exactly once.

Does anything change if you have to end your journey at the same node you
started at?

5. Give the adjacency matrix for each of the following graphs:-

1
(a) (b)

2 3 2
p p p p r 4
3

p 7 p
4
1 p
p r p q p

5 6 1 6 5

Use the connectivity algorithm to show that the first graph is connected and the
second is not.

6. Draw the graphs defined by each of the following adjacency matrices.



0 1 0 0 0 0 1 1 1 1
1 0 1 0 0 1 0 1 1 1

( a)
0 1 0 0 0
( b ) 1 1 0 1 1

0 0 0 0 1 1 1 1 0 1
0 0 0 1 0 1 1 1 1 0

Use the connectivity algorithm to find which of these graphs is connected.

7. Consider the following graph:-

q q 2
1

q p
3 4

How many paths of length two are there between vertices 1 and 3? How many
paths of length three are there between vertices 2 and 4?

8. One can show that if a graph has n vertices, and adjacency matrix A, then it is
connected if and only if the matrix A + A2 + . . . + An1 has no zero entries.
Check that this works for the two graphs:-

2
(b)
(a)
r 1 p q 2
1 r
2

r q
3 3

Also use the connectivity algorithm in each of these cases: which way is easier?

9. For each of the graphs in Q3 and 5(a), find spanning trees using breadth first
search and depth first search from a selection of initial nodes.

10. Consider the graphs with edge lengths as shown:-

b c
1 4
3
1
a 2 d
1
2
f 3 e

Use Dijkstras algorithm to find the shortest route between each pair of vertices
in the graph.

11. Use heapsort to sort each of the following lists of numbers into increasing order:

(a) 1, 5, 3, 8, 10, 2, 6
(b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
(c) 15, 25, 4, 80, 2, 99, 50, 6, 34, 27, 85, 3, 1, 70, 8

12. Give the trees corresponding to the two codes:

a : 01, d : 101, e : 0, t : 110, s : 10

and
a : 01, d : 101, e : 00, t : 110, s : 111
and say which of them is a prefix code.

3
13. A Huffman code is given by the tree

0 1
e
0  1
 a
0 1
t
0 1
r c

(a) Give the codes for each of e, a, t, r and c.


(b) What are the codes for cat, rat, ate, area and cart?
(c) Decode each of 011100, 111010100, and 1000111010.

14. (a) Construct optimal Huffman codes and give the average encoded symbol
length for the following set of symbols and associated frequencies:

e : 0.4, t : 0.29, s : 0.16, a : 0.1, c : 0.05

Give the average encoded symbol length and find a non-prefix code which
is more efficient.
(b) Find at least two different optimal Huffman codes for the following set of
symbols and associate frequencies, and check that in each case the average
encoded symbol length is the same.

a : 0.1, b : 0.2, c : 0.2, d : 0.3, e : 0.2

RJL,124ms\tut3.tex

You might also like