recitation09

# recitation09 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

This preview shows pages 1–9. 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.17
Quiz Rev Problems Interesting Get you irkhe right min We'll run out of time, no No Concepts = if you don't now, ask in office hours iew dset t problems know them by

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

View Full Document
Problem 1: Poke A[1 . .. n] sorted array of integers can contain negative integers no duplicates Want: i s.t. A[i] = i if multiple possibilities, one will sufﬁce if no such i exists, say so
Poke: Intuition 1 2 3 4 5 6 7 8 Play with the examples on the right 1 2 3 4 5 6 7 8 Build the intuition 1 2 3 4 5 6 7 8 Figure it out 1 2 3 4 5 6 7 8 -3 -1 1 3 5 7 9 11 2 4 6 8 10 12 14 16 -1 0 1 2 4 5 6 8 1 3 4 6 9 10 11 13

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

View Full Document
Poke: Solution Key : if A[i] > i,A[j] > j for any j > i proof:A[i . .. j] has j - i + 1 cells, must contain j - i + 1 values; integers only, no duplicates, so A[j] i + (j - i) + 1 > j Solution: using key above, adapt binary search to ﬁnd i Time: O(log(n))
Problem 2: Knapsack A[1 . .. n] numbers (not necessary integers) s also number (not necessary integer) i) ﬁnd i 1 , i 2 s.t. A[i 1 ]+A[i 2 ] = s ii) ﬁnd i 1 , i 2 ... i k s.t. A[i 1 ] + . .. + A[i k ] = s Hint: do better than O(n k ) Palantir phone interview, 2007

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

View Full Document
Knapsack: Intuition k = 2, S = 13 Play with the examples
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 / 26

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

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

View Full Document
Ask a homework question - tutors are online