This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Fall Semester 2008 CS300 Algorithms Solution #2 1. (a) function C(n, m: integer): integer; begin if (m = 0 or m = n) then return 1; return C(n-1, m) + C(n-1, m-1); end (b) Let c 1 and c 2 be the times required in the comparison and the addition, respectively. Then we can express T ( n, m ), the running time of the C ( n, m ) as follows: T ( n, m ) = T ( n- 1 , m ) + T ( n- 1 , m- 1) + c 1 + c 2 , where 0 < m < n and its boundary conditions are T ( n, 0) = T ( n, n ) = c 1 . To illustrate recursive evaluation process, we make a full binary tree B n,m whose root node, internal nodes, and leaf nodes represent T ( n, m ), T ( i, j ), and the boundary conditions, respectively, where 1 ≤ n , 0 ≤ m ≤ n , 0 < i < j , j ≤ m , i ≤ n . Since each leaf node contributes 1 in evaluating C ( n, m ), there are C ( n, m ) leaf nodes and C ( n, m )- 1 internal nodes. From this observation, T ( n, m ) = c 1 · C ( n, m ) + ( c 1 + c 2 ) · ( C ( n, m )- 1) ....
View Full Document
This note was uploaded on 02/04/2010 for the course COMPUTER S cs300 taught by Professor Unkown during the Spring '08 term at Korea Advanced Institute of Science and Technology.
- Spring '08