Professional Documents
Culture Documents
Tut3 PDF
Tut3 PDF
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.
4. For each of the graphs in the previous questions, find whether it is possible to
travel round the graph
Does anything change if you have to end your journey at the same node you
started at?
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.
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.
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
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
14. (a) Construct optimal Huffman codes and give the average encoded symbol
length for the following set of symbols and associated frequencies:
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.
RJL,124ms\tut3.tex