recitation09

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

Info iconThis preview shows pages 1–9. 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.17
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 suffice if no such i exists, say so
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 find i Time: O(log(n))
Background image of page 6
Problem 2: Knapsack A[1 . .. n] numbers (not necessary integers) s also number (not necessary integer) i) find i 1 , i 2 s.t. A[i 1 ]+A[i 2 ] = s ii) find 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Knapsack: Intuition k = 2, S = 13 Play with the examples
Background image of page 8
Image of page 9
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 Right Arrow Icon
Ask a homework question - tutors are online