You are on page 1of 2

# Birla Institute of Technology & Science, Pilani Work-Integrated Learning Programmes Division First Semester 2009-2010 Comprehensive Examination

(EC-2 Regular) Course No. Course Title Nature of Exam Weightage Duration Date of Exam Note:
1. 2. 3. 4.

: IS ZC361 : DATA STRUCTURES AND ALGORITHMS : Open Book : 60% No. of Pages =2 : 3 Hours No. of Questions = 5 : 25/10/2009 (AN)

Please follow all the Instructions to Candidates given on the cover page of the answer book. All parts of a question should be answered consecutively. Each answer should start from a fresh page. Mobile phones and computers of any kind should not be used inside the examination hall. Use of any unfair means will result in severe disciplinary action.

Q.1 (a).

Given a coin set of Rs. 1, 5, 10, 20, 50, 100, 500 and 1000. A person wishes to travel with minimum number of coins in exchange for his money (say Rs. R). Write a greedy algorithm for obtaining minimum number of coins for exchange for Rs. R. The algorithm should be written in pseudocode and should produce output as the value and number of each coin used for exchange. [6] Prove or disprove that the solution thus obtained above is optimal. Give one example to support your logic. [6]

Q.1 (b).

Q.2.

A carpenter has a piece of wood of a certain length that must be cut at positions a1, a2 ..., an where ai is the distance from the left end of the original piece of wood. Notice that after making the first cut, the carpenter now has two pieces of wood; after making the second cut, the carpenter has three pieces of wood, etc. Assume that the cost of making a cut in a piece of wood of length l is equal to l, and is the same no matter which position in that piece of wood is being cut. Let L be the length of the original piece of wood.

|______________________________|____________|________________________| ai aj an a0 2.1 Use dynamic programming to find minimum cost solution of the above problem. Describe the problem substructure. [5] Write an algorithm to find optimal sequence of cut marks for cutting the wood into n pieces. The optimality refers to the minimum cost of cutting the wood log. [7]

2.2

Page 1 of 2

Q.3.

Page 2

## 3.1 3.2 3.3

Q.4 (a).

Construct the adjacency list representing the above graph. [4] Use Dijkstras algorithm to find the shortest path from vertex A to vertex F. Compute the shortest path. [4] Is vertex A reachable from vertex F? Give the path. [4] Draw a figure illustrating the comparisons done by brute force pattern matching algorithm for the case when the text is aaabaadaabaaa and the pattern is aabaaa. [8] Use Knuth-Morris-Pratt pattern matching Algorithm and illustrate the pattern matching for the text and the pattern strings given in the above question. [4] [NOTE: You are not required to write any algorithm in both of the above two parts of question 4. Only illustrate the pattern matching process as asked. END NOTE]

Q.4 (b).

Q.5. Let G be a graph whose vertices are integers 1 through 8, and let the adjacent vertices be given by the table below: Vertex 1 2 3 4 5 6 7 8 5.1 5.2 5.3 Adjacent vertices 2,3,4 3,5,7,1 2,4,5 6,7,8 2,7 8 2,5,6 3

Draw G. Is the graph directed or undirected? [4] Order the vertices as they are visited in a DFS (Depth First Traversal) traversal starting at vertex 1. [4] Order the vertices as they are visited in a BFS (Breadth First Traversal) traversal starting at vertex 1. [4] ******** Page 2 of 2