Assignment: 2
Design & Analysis of algorithm
Total marks: 5
This assignment is compulsory for all including roll no 30 and 71.
This assignment is to be submitted tomorrow latest by 5 PM. If you fail to submit it
tomorrow 3 marks will be deducted. You may submit it on Friday with a penalty of 3
marks. After Friday no submission will be accepted and no marks will be given.
From 23rd
April no presentation will be held. For remaining students an extra
assignment will be given. For tomorrow, three next groups may (not necessary) give
presentations (Last presentation).
Dynamic Programming Technique:
Q1: What does dynamic programming has in common with divide-and-conquer? What is a
principal difference between them?
Q2: Design an efficient algorithm for computing the binomial coefficient C(n, k) that uses no
multiplications. What are the time and space efficiencies of your algorithm?
Q3: Rod-cutting problem: Design a dynamic programming algorithm for the following
problem. Find the maximum total sale price that can be obtained by cutting a rod of n units
long into integer-length pieces if the sale price of a piece i units long is pi for i = 1, 2, . . . , n.
What are the time and space efficiencies of your algorithm?
Q4: Shortest-path counting: A chess rook can move horizontally or vertically to any square
in the same row or in the same column of a chessboard. Find the number of shortest paths by
which a rook can move from one corner of a chessboard to the diagonally opposite corner.
The length of a path is measured by the number of squares it passes through, including the
first and the last squares. Solve the problem
a. by a dynamic programming algorithm.
b. by using elementary combinatorics.
Decrease-and-Conquer Technique:
Q5: What is Decrease and Conquer algorithm design technique? Explain these three
variations of this design technique with few examples.
(i) decrease by a constant
(ii) decrease by a constant factor
(iii) variable size decrease
Q6: Ferrying soldiers: A detachment of n soldiers must cross a wide and deep river with no
bridge in sight. They notice two 12-year-old boys playing in a rowboat by the shore. The boat
is so tiny; however, that it can only hold two boys or one soldier. How can the soldiers get
across the river and leave the boys in joint possession of the boat? How many times need the
boat pass from shore to shore?
Q7: Insertion sort is a good example of Decrease-and-Conquer technique. Apply insertion
sort to sort the list E, X, A, M, P, L, E in alphabetical order.
Q8: Can binary search algorithm (performed on any array) be considered as an instance of
Decrease-and-Conquer technique? Explain.
Q9: Consider the following algorithm designed by applying Decrease and Conquer
technique, to check connectivity of a graph defined by its adjacency matrix.
ALGORITHM Connected(A[0..n − 1, 0..n − 1])
//Input: Adjacency matrix A[0..n − 1, 0..n − 1]) of an undirected graph G
//Output: 1 (true) if G is connected and 0 (false) if it is not
if n = 1 return 1 //one-vertex graph is connected by definition
else
if not Connected(A[0..n − 2, 0..n − 2]) return 0
else for j ←0 to n − 2 do
if A[n − 1, j] return 1
return 0
Does this algorithm work correctly for every undirected graph with n > 0 vertices? If you
answer yes, indicate the algorithm’s efficiency class in the worst case; if you answer no,
explain why.

Assignment 2 daa

  • 1.
    Assignment: 2 Design &Analysis of algorithm Total marks: 5 This assignment is compulsory for all including roll no 30 and 71. This assignment is to be submitted tomorrow latest by 5 PM. If you fail to submit it tomorrow 3 marks will be deducted. You may submit it on Friday with a penalty of 3 marks. After Friday no submission will be accepted and no marks will be given. From 23rd April no presentation will be held. For remaining students an extra assignment will be given. For tomorrow, three next groups may (not necessary) give presentations (Last presentation). Dynamic Programming Technique: Q1: What does dynamic programming has in common with divide-and-conquer? What is a principal difference between them? Q2: Design an efficient algorithm for computing the binomial coefficient C(n, k) that uses no multiplications. What are the time and space efficiencies of your algorithm? Q3: Rod-cutting problem: Design a dynamic programming algorithm for the following problem. Find the maximum total sale price that can be obtained by cutting a rod of n units long into integer-length pieces if the sale price of a piece i units long is pi for i = 1, 2, . . . , n. What are the time and space efficiencies of your algorithm? Q4: Shortest-path counting: A chess rook can move horizontally or vertically to any square in the same row or in the same column of a chessboard. Find the number of shortest paths by which a rook can move from one corner of a chessboard to the diagonally opposite corner. The length of a path is measured by the number of squares it passes through, including the first and the last squares. Solve the problem a. by a dynamic programming algorithm. b. by using elementary combinatorics. Decrease-and-Conquer Technique: Q5: What is Decrease and Conquer algorithm design technique? Explain these three variations of this design technique with few examples. (i) decrease by a constant (ii) decrease by a constant factor (iii) variable size decrease Q6: Ferrying soldiers: A detachment of n soldiers must cross a wide and deep river with no bridge in sight. They notice two 12-year-old boys playing in a rowboat by the shore. The boat is so tiny; however, that it can only hold two boys or one soldier. How can the soldiers get
  • 2.
    across the riverand leave the boys in joint possession of the boat? How many times need the boat pass from shore to shore? Q7: Insertion sort is a good example of Decrease-and-Conquer technique. Apply insertion sort to sort the list E, X, A, M, P, L, E in alphabetical order. Q8: Can binary search algorithm (performed on any array) be considered as an instance of Decrease-and-Conquer technique? Explain. Q9: Consider the following algorithm designed by applying Decrease and Conquer technique, to check connectivity of a graph defined by its adjacency matrix. ALGORITHM Connected(A[0..n − 1, 0..n − 1]) //Input: Adjacency matrix A[0..n − 1, 0..n − 1]) of an undirected graph G //Output: 1 (true) if G is connected and 0 (false) if it is not if n = 1 return 1 //one-vertex graph is connected by definition else if not Connected(A[0..n − 2, 0..n − 2]) return 0 else for j ←0 to n − 2 do if A[n − 1, j] return 1 return 0 Does this algorithm work correctly for every undirected graph with n > 0 vertices? If you answer yes, indicate the algorithm’s efficiency class in the worst case; if you answer no, explain why.