Tutorial 08

# Tutorial 08 - the algorithm is executed Use big-oh notation...

This preview shows page 1. Sign up to view the full content.

p q r s t COMP2781, COMP8781, Sem. 1, 2011, Flinders University Tutorial 8 Question 1. Set 6.1: Ex. 30, Set 6.2: Ex. 39, Set 6.3: Ex. 33 Question 2. Set 7.4: Ex. 12 Question 3. Give an example of a recursive program such that its number of runs a n satisFes the recur- rence a n = 2 a n/ 2 + n, for n 2 , with a 1 = 0 . Solve the recurrence when n is a power of 2 . Check your formula by comparing Frst Fve terms of the sequence generated directly from your formula with those produced by the recurrence relation. Is this algorithm faster than the one satisfying the relation: s n = 2 s n - 1 , where s n is the number of runs? Question 3. Assume that n is a positive integer and consider the following algorithm: p=0, x=2 for i=2 to n p = (p+i) * x next i Compute the actual number of additions and multiplications that must be performed when
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the algorithm is executed. Use big-oh notation for this number. Question 4. s=0 for i=1 to n for j=1 to i s = s + j * (i-j+1) next j next i Compute the actual number of additions, subtractions and multiplications that must be per-formed when the algorithm is executed. Use big-oh notation for this number. Question 5. Assume that n is a positive integer and consider the following algorithm: for i = floor(n/2) to n a = n-i next i Compute the actual number of subtractions that must be performed when the algorithm is executed. Use big-oh notation for this number. Page 1 Last updated May 11, 2011 by M. Bajger...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online