Adjacency Matrix - Computer Science - Exam, Exams of Computer Science

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

2012/2013

Uploaded on 03/28/2013

beboo
beboo 🇮🇳

4.4

(14)

242 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Cork Institute of Technology
Bachelor of Science (Honours) in Software Development – Stage 3
(NFQ – Level 8)
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
CD
B
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Adjacency Matrix - Computer Science - Exam and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Science (Honours) in Software Development – Stage 3

(NFQ – Level 8)

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

• • b

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:

A Z

G

F

D

B E

A Z

G

F

D

B E

A Z

G

F

D

B E

NAME:

A Z

G

F

D

B E

A Z

G

F

D

B E

A Z

G

F

D

B E

NAME:

A Z

G

F

D

B E

A Z

G

F

D

B E

A Z

G

F

D

B E