hw5 - CSE 780, Fall, 2009 Prof. R. Wenger Office: 485...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 780, Fall, 2009 Prof. R. Wenger Office: 485 Dreese Lab Tel.: 292–6253 e-mail : [email protected] CSE780 Homework 5: Corrected version Autumn, 2009 Write a recurrence relation describing the worst case running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using either substitution, a recursion tree or induction. You may NOT use the Master theorem. Assume that all arithmetic operations take constant time. Simplify and express your answer as Θ(nk ) or Θ(nk (log n)) wherever possible. If the algorithm takes exponential time, then only give exponential lower bounds. 1. Func1(A,n) /* A is an array of n integers if (n < 10) then return A[1]; i ← 1; while (i2 ≤ n) do A[i] ← A[2i] + A[i2 ]; i ← i + 1; end x ← Func1(A, n − 2); return x; */ 1 2 3 4 5 6 7 8 2. Func2(A,n) /* A is an array of n integers if (n < 20) then return A[1]; for i ← 1 to n do for j ← 1 to i do A[i] ← A[j ] − A[i]; end end x ← Func2(A, n − 5); y ← Func2(A, n − 8); z ← Func2(A, n − 11); return (x + y + z ); */ 1 2 3 4 5 6 7 8 9 10 3. Func3(A,n) /* A is an array of n integers if (n < 20) then return A[1]; for i ← 1 to n/2 do B [i] ← A[2 ∗ i]; C [i] ← A[2 ∗ i + 1]; for j ← 1 to i do A[i] ← B [j ] + C [i − j ]; end end x ← Func3(A, n/2 ); y ← Func3(B , n/2 ); z ← Func3(C , n/2 ); return (x + y + z ); */ 1 2 3 4 5 6 7 8 9 10 11 12 4. Func4(A,n) /* A is an array of n integers if (n < 20) then return A[1]; x ← 0; for i ← 1 to 8 do x ← x+ Func4(A, n/2 ); for j ← 1 to n do for k ← j to n do for m ← j to k do A[m] ← A[j ] − A[k ]; end end end end return x; */ 1 2 3 4 5 6 7 8 9 10 11 12 13 5. Func5(A,n) /* A is an array of n integers if (n < 20) then return A[1]; x ← 0; for i ← 1 to 9 do x ← x+ Func5(A, n/3 ); for j ← 1 to n/2 do A[j ] ← A[j ] − A[i + j ]; end end return x; */ 1 2 3 4 5 6 7 8 9 ...
View Full Document

This note was uploaded on 01/17/2010 for the course CSE 780 taught by Professor Prof during the Fall '09 term at Ohio State.

Page1 / 2

hw5 - CSE 780, Fall, 2009 Prof. R. Wenger Office: 485...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online