This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COMP 271 Design and Analysis of Algorithms 2004 Fall Semester Question Bank 3 Solving these questions will give you good practice for the midterm exam. Some of these questions (or similar ones) will definitely appear on your exam! Note that you do not have to submit answers to these questions for grading. Your TAs will discuss answers to selected questions in the tutorials. 1. Recall that in the matrixchain multiplication problem, we are given a sequence A 1 ,A 2 ,...,A n of n matrices, where A i has size p i − 1 × p i . The goal is to determine the least number of scalar multiplications needed to compute the matrix chain product, A 1 A 2 ...A n . (a) Let m ( i,j ) denote the least cost of multiplying matrices A i ...A j , where j ≥ i . In class we wrote a recurrence relation for m ( i,j ). This recurrence relation can be directly translated into a recursive function that takes two arguments, i and j . Draw a recursion tree to show what recursive calls result when this function is called with arguments i = 3 and j = 6, respectively. (b) By looking at the recursion tree of part (b), give two examples of subproblems which are being solved more than once. (c) Give an intuitive explanation as to why the purely recursive approach is inef ficient for solving this problem. (Answer in just two lines.) (d) Dynamic programming can be used to solve this problem much faster than the purely recursive approach. Give the basic idea of this method, clearlythe purely recursive approach....
View
Full Document
 Spring '07
 ARYA
 Algorithms, Dynamic Programming, C Programming, purely recursive approach

Click to edit the document details