






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Multiplication, Addition Method,, Reachability Matrix, Running Time, Algorithmic Structure, Operation, Workings Clearly, Chromatic Number, Recursive Code, Bubble Sort Algorithm
Typology: Exams
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Autumn 2006 COMPUTER SCIENCE (Time : 3 Hours)
Answer any four questions. Examiners : Mr. V. Ryan Dr. M. O Cinneide Mr. M. Donnelly
Question 1 a) Prove the following result: The number of walks of length q from vertex i to vertex j in a graph/digraph/multigraph G=(V,E) with adjacency matrix M is Mq^ (i,j) [7 Marks] b) Using the matrix multiplication and addition method, calculate the reachability matrix MR^ for the following digraph:
[8 Marks]
c) What is the definition of the running time of a program being O(f(n))? [3 Marks] d) What is the complexity of the following algorithmic structure with respect to the problem size n? Assume that S is some operation in the order of O(1) and a is a constant greater than 1. Show all workings clearly. (i) for ( i=1 ; i<=n ; i++ ) for ( j=1 ; j<=a ; j++ ) S; [3 Marks] (ii) for ( i=1 ; i<=n ; i+=a ) S; [4 Marks]
A
D C
B
Question 2 a) List two useful guidelines that can be used when finding the chromatic number of a graph. [4 Marks]
b) Using these guidelines, find the chromatic number of the following graph. Your answer must clearly illustrate that you used the guidelines. [6 Marks]
c) What can you say about graphs for which χ (G) = 1? What can you say about graphs for which χ (G) = 2? [5 Marks] d) Consider the following recursive code for the bubble sort algorithm. Give a full complexity analysis of the code, leading to working out its big-Oh function. typedef int BigIntArray[100] ; void BubbleLargest(BigIntArray A, int n); { int i,temp; if (n > 1) { for (i= 1; i<n ; i++) if (A[i] > A[i+1]) { temp = A[i]; A[i] = A[i+1]; A[i+1] = temp; } BubbleLargest(A,n-1); } } [10 Marks]
k
j
l m
i
h
g f
e
c
d
b
a
d) What recurrence relation would model the complexity of the following code outline? _int test( int n) { if ( n == 1 ) S 1 ; else if ( n == 4 ) S 2 ; else return ( 3test(n-1) + 5test(n-2) ); }_** Assume that the time complexities of S 1 and S 2 are both O(1). N.B. You are not expected to solve the recurrence relation that you derive. [4 Marks]
e) Solve the following linear recurrence relation: h 0 = 0 h 1 = 2 h (^) n = 6h^ n-1 + 9h^ n-2 ,^ n>1. [6 Marks]
Question 4 a) Prove the following Let T be a connected multigraph with n vertices and no circuits. Then, T has n-1 edges. [5 Marks]
b) Using the above result, show that if G=(V,E) is a connected loop-free planar graph with more than one edge ( e>1 ), then 2e is ≥ 3r , where e and r denote the number of edges and regions in G respectively. [5 Marks]
c) Show that the Petersen Graph (below) has a subgraph which is homeomorphic to K 33.
[5 Marks]
d) Explain the differences between an optimisation problem and a decision problem. [3 Marks] Explain why the classification of problems concerns itself with decision problems only. [3 Marks]
e) What do you understand by the class of problems called P.? [3 Marks] Give an example of a problem which is not in P. [1 Mark]
e
c
j
i
d
h
g
f
a
Question 6 a) Define what is meant by a tree. [3 Marks]
b) What is meant by a variable length character code (vlcc)? [3 Marks] Why are such coding systems desirable? [2 Marks]
c) Using Huffman’s Algorithm, assign binary codes to the following letters: a,b,c,d,e,f and g , if their frequency of occurrence is 45,11,8,21,96,22 and 33. [7 Marks]
d) How would you proceed if you wanted to prove that a problem is in the class NP-complete? [3 Marks]
e) Compare the Travelling Salesman Problem with the Hamilton Cycle Problem. [4 Marks]
f) What is meant by the NPI class of problems? [3 Marks]
Appendix
NAME:
NAME:
NAME: