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

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

View Full Document Right Arrow Icon
n CS 323 ± ± Lecture 4 o Hoeteck Wee · hoeteck@cs.qc.cuny.edu http://www.cs.qc.edu/~hoeteck/f09/
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
I Homework 1 : max 9 / 10 , mean 3 . 1 , standard deviation 3 . 0 I
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

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

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

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