### CS171, Homework 5

• Solving recurrence relations

• Solve the following recurrence relations using the expansion technique (20 pts):

(Only the most significant part of the expression is required)

 ``` T(n) = 3×T(n-1) T(1) = 1 ```

• Solve the following recurrence relations using the expansion technique (20 pts):

(Only the most significant part of the expression is required)

 ``` T(n) = T(n/2) + n2 T(1) = 0 ```

For simplicity, you can assume that: n is some power of 2, i.e.: n = 2k

• Loop analysis

• Give the running time for the following loop: (20 pts)

 ``` for (i = 0; i < N; i = i + 2) for (j = i; j < N; j++) { operation(); } ```

• Give the running time for the following loop: (20 pts)

 ``` k = 0.5; for (i = 0; i < N; i = i + k) { operation(); k = 2*k; } ```

• Give the running time for the following loop: (20 pts)

 ``` s1 = 1; s2 = 1; for (i = 1; i <= N; i++ ) { for (j = 0; j < s2; j++) { operation(); } x = s1 + s2; s1 = s2; s2 = x; } ```

You will need to use this approximation formula:

 ``` Fibonacci numbers: f0 = 1 f1 = 1 f2 = f1 + f0 = 1 + 1 = 2 f3 = f2 + f1 = 2 + 1 = 3 f4 = f3 + f2 = 3 + 2 = 5 f5 = f4 + f3 = 5 + 3 = 8 f6 = f5 + f4 = 8 + 5 = 13 f7 = f6 + f5 = 13 + 8 = 21 ... You can approximate fk with: fk ~= φk (where φ ~= 1.618) ```