Vous êtes sur la page 1sur 4

RAJARATA UNIVERSITY OF SRI LANKA

FACULTY OF' APPLIED SCIENCES

B.Sc. Degree in Information and Communication Technology


Second Year Semester I Examination February/March 2013

ICT23O1 . DESIGN AND ANALYSIS OF ALGORITHMS


Answer any five questions Time:3 hours

a. What is the pu{pose of Analyzing algorithms?


(2 marks)
b. Define the space complexity and time complexity of an algorithm.
(2 marks)
Simple Factoring algorithm and Euclid algorithm are two algorithms that can be used to
find the Greatest Common Divisor (GCD) of two numbers. If you implement these two
algorithms in your computer, discuss the complexity of two algorithms. Justifo your
answer using an example. [hint: use 45 and l5 as two numbers]

d. Explain the concept of Asymptotic Notation, indicating the commonly rr.O no,L6i#t.]
e. The recurrence equation for the time complexity of a sorting algorithm is:

( Cr, ifn=l
r(n)-l*G)* cyn, if n>L

Show that the time complexity of the algorithm is O (n log n) by solving the recurrence
equation.
(4 marks)

02.

a, compare and contrast linear search and binary search using examples.
(5 marks)
b. Discuss the use of Hash Functions and Hash Tables in searching when compared to
linear search and binary search.
(4 marks)
c. What is a collision in hashing? Name three techniques which avoid collisions.
(3 marks)
d. State the differences between Depth First Search (DFS) and Breath First Search (BFS)?

Page I of4
{"[
(2 marks)
e. Perform the DFS in the graph given in Figure 1. Show how you use a stack for
traversing the graph. Use node G as sta(ing point.
(6 marks)

Figure 1: An undirected graph

03.

a. Draw the recursion tree for the execution of the r..*riw algorithm which finds the
factorial value of the number 6.
(2 marks)
b. Write a recursive algorithm to construct the Fibonacci series of a given number n and
comment on the time complexity of the algorithm.
(4 marks)
c. Explain the Divide and Conquer method in algorithm designing.
(2 marks)
d. Illustrate the Quick sort algorithm using the following set of unsorted numbers. Cleary
state the steps you followed. What can you say about the time complexity of the Quick
sort algorithm?

23 10 7 45 t6 86 50 2 31 18

What is a stable sorting algorithm? Give two algorithms which satisfu,ht, er"e{}il-r]

04.

a. Why we use compression algorithms?


(2 marks)
b. What is a Code in data compression? Discuss the difference between fixed length codes
and variable length codes.
(4 marks)
c. State the concept of prefix free coding.
(2 marks)

Page2 of 4
4t
d. Algorithm for the Huffman codes (Algorithm 1) and a message with the percentage of
occurrences of each symbol in the message are given below. Apply Huffman Codes for
the given message and generate the Huffman tree. Hence find the codewords for the
symbols in the message.
(8 marks)

Symbols in the Message: abcde


Frequency: 40"/" 18" l2o/o l6"h 14o
Algorithm:
Huffman(C)
1n € lcl
2Q<C
3for i€lton-l
4 allocate a new node z
5 z.left?x € EXTRACT-MIN(Q)
6 z.right € y € EXTRACT-MIN(Q)
7 z,freq € x.freq + y.freq
8 INSERT (Q, z)
9 return EXTRACT-MIN(Q) //Ileturn the root of the tree

Algorithm 1: Huffman Code algorithm. Lines of codes are numbered.

e. Discuss the lossy compression and the lossless compression.


(2 marks)

05.

a. Explain the term Hamiltonian Cycle using an example.


(2 marks)
b. Discuss the different methods of representing graphs in a computer.
(2 marks)
c. What is the Greedy method in algorithm designing?
(2 marks)
d. What is a Minimum Cost Spanning Tree (MST)? Use the Prim's algorithm to find the
MST of the graph given in Figure 2 by considering A as the starting point. What is the
cost of the resulting MST?
(6 marks)

Figure 2z A graph with weights of the edges

Page 3 of4
7,
e. Find out the shortest path from vertex 1 to all remaining vertices for the graph in Figure
3 using Digikstra algorithm.
(8 marks)

Figure 3: A graph with directed edges. weights are indicated.

06.

a. What is a heap? Explain the heap property'


(2 marks)
the time complexity of the algorithm.
b. what is the MAX-HEAPIFY algorithm? Discuss
(2 marks)
clearly.
Build the Max-Heap for the array given below. Show the steps

6 32 18 20 16 3 10 1 13 t2
(6 marks)

Max-Heap that you built in part c'


d. Apply the HEAP SORT algorithm and sorl the
Clearly show the stePs followed'
(8 marks)

Compare and contrast the Quick sort and Heap sort algorithms'
(2 marks)

Page 4 of 4

Vous aimerez peut-être aussi