recitation18

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

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

View Full Document Right Arrow Icon
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 .
Background image of page 1

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

View Full DocumentRight Arrow Icon
6.006 Recitation Build 2008.38
Background image of page 2
6.006 Proudly Presents Warmup: Maxing out sums Fun:Tetris pwnage Bonus: Pwn Mario v2: mushrooms, monsters
Background image of page 3

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

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

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Max. Sub-Array:
Background image of page 7

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

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

This note was uploaded on 09/24/2010 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.

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 Right Arrow Icon
Ask a homework question - tutors are online