You are on page 1of 2

Birla Institute of Technology and Science, Pilani

Distance Learning Programmes Division


MS Software Engineering in Collaboration with Wipro Technologies
First Semester 2005 – 2006
Comprehensive examination
Regular

Course No. : SEWP ZG511


Course Name : Design and Analysis of Algorithms
Nature of Exam : Open Book Exam Bangalore
weightage : 60 %
Duration : 3Hours
Date : September 18, 2005 (FN)

Note: Attempt all questions. Start each answer from a fresh page

Instructions
• Answers must be written clearly. Untidy work will fetch lower marks
• Diagrams must be drawn clearly and legibly. Untidy work will fetch lesser credit.

1. Illustrate the operation of HEAPSORT on the array A = {5, 13, 2, 25, 7, 17, 20, 8, 4}. Show,
visually, the binary tree just after the BUILD-HEAP is called and at the end of each of the
HEAPIFY operation. (6)

2. Construct the prefix function p for the pattern abcabcab using the Knuth-Morris-Pratt
algorithm. It is sufficient to draw the final look-up table. You need not show the complete steps
of the algorithm. (6)

3. Write a complete, modified Rabin-Karp algorithm for matching patterns on a text that is
known to have characters from the set of alphabets {a, b, c, d, e, f, g, h, i}.
(8)

4. Write a complete Greedy algorithm for the Fractional Knapsack problem. The problem is
defined as follows:

A thief robbing a store finds n items each item worth vi dollars and weighs wi pounds. The thief
has a knapsack of capacity W pounds (the thief can carry a total weight of not more than W
pounds). The thief is allowed to carry all the quantity available of an item or a fraction thereof.
What items should the thief take and how much of each of those items to maximize the value of
the theft? (10)

5. Draw the look-up table, based on the Dynamic Programming method, for the 0-1 knapsack
problem. The data is provided in the table below. Provide the final optimal solution, too. (10)

Item Weight Value


1 3 10
228
3 4 11
4 5 13
5 3 12

6. Determine a LCS of the strings <1, 0, 0, 1, 0, 1, 0, 1> and <0, 1, 0, 1, 1, 0, 1, 1, 0>. It is


sufficient to show the look-up table (along with the relevant arrows) and the solution. You need
not show the intermediate steps. (10)

7. Write a complete algorithm that determines if a given number is a perfect number or not. Use
the following definition of a perfect number. The algorithm should take one parameter, the
number, and print a message that says if the number is perfect or not.

A number N (greater than 0) is said to be perfect if the sum of all its factors equals the number.
For example, 6 is a perfect number because 1 + 2 + 3 = 6, and 1, 2 and 3 are factors of 6. 28 is
also a perfect number because 1 + 2 + 4 + 7 + 14 = 28, and the individual numbers are all factors
of 28. (10)

You might also like