# lec4 - CS 323 Lecture 4 Design and Analysis of Algorithms...

This preview shows pages 1–5. Sign up to view the full content.

n CS 323 ± ± Lecture 4 o Hoeteck Wee · http://www.cs.qc.edu/~hoeteck/f09/

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

View Full Document
Homework 1 Problem 1 PROBLEM. compute the n ’th Fibonacci number, F 0 = 0 , F 1 = 1 , n > 1 , F n = F n - 1 + F n - 2 ALGORITHM. compute recursively with memoization (attempt) def fib_memoize (n): fib_memo = { 0 : 0, 1 : 1 } if n in fib_memo: return fib_memo[n] else : ans = fib_memoize(n-1) + fib_memoize(n-2) fib_memo[n] = ans return ans Hoeteck Wee CS 323 Sep 14, 2009 2 / 14
Homework 1 Problem 3 PROBLEM. determine experimentally the running time of set intersection. ALGORITHM. import timeit def intersect (x,y): a = set(range(10 ** x)) b = set(range(10 ** y)) return b.intersection(a) t = timeit.Timer(‘‘intersect(3,3)’’, ‘‘from __main__ import intersect’’) print min(t.repeat(10,1)) Hoeteck Wee CS 323 Sep 14, 2009 3 / 14

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

View Full Document
I Homework 1 : max 9 / 10 , mean 3 . 1 , standard deviation 3 . 0 I
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

lec4 - CS 323 Lecture 4 Design and Analysis of Algorithms...

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

View Full Document
Ask a homework question - tutors are online