{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

recitation18

# recitation18 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .

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

View Full Document
6.006 Recitation Build 2008.38
6.006 Proudly Presents Warmup: Maxing out sums Fun:Tetris pwnage Bonus: Pwn Mario v2: mushrooms, monsters

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

View Full Document
Max. Sum Sub-array a is a list of real numbers want i, j so that a[i:j] is as large as possible want to compute this as fast as possible answer for this case i = 2 j = 6 sum = 187 i 0 1 2 3 4 5 6 7 8 9 a[i] 31 -41 59 26 -53 58 97 -93 -23 84
Max. Sum Sub-array: Naive Solution max_sum, max_i, max_j = 0, 0, 0 for i in 0:len(a) for j in i:len(a) if max_sum < a[i:j] max_sum, max_i, max_j = a[i:j], i, j i 0 1 2 3 4 5 6 7 8 9 a[i] 31 -41 59 26 -53 58 97 -93 -23 84

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

View Full Document
Running Time for Naive Solution i, j go through all possible intervals a[i:j] O(N 2 ) intervals evaluating a[i:j] at each interval O(N) work per interval O(N 3 ) total
Max. Sub-Array:

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 19

recitation18 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

View Full Document
Ask a homework question - tutors are online