MIT6 006F11 Lec01 PDF
MIT6 006F11 Lec01 PDF
MIT6 006F11 Lec01 PDF
Lecture Overview
Administrivia
Course Overview
Course Overview
This course covers:
Ecient procedures for solving problems on large inputs (Ex: U.S. Highway Map,
Human Genome)
Scalability
The course is divided into 8 modules each of which has a motivating problem and problem
set(s) (except for the last module). Tentative module topics and motivating problems are
as described below:
8. Advanced Topics
1
Lecture 1 Introduction and Peak Finding 6.006 Fall 2011
Peak Finder
One-dimensional Version
Position 2 is a peak if and only if b a and b c. Position 9 is a peak if i h.
1 2 3 4 5 6 7 8 9
a b c d e f g h i
Straightforward Algorithm
6 7 4 3 2 1 4 5
might be peak
Figure 2: Look at n/2 elements on average, could look at n elements in the worst case
What if we start in the middle? For the conguration below, we would look at n/2 elements.
Would we have to ever look at more than n/2 elements if we start in the middle, and choose
a direction based on which neighboring element is larger that the middle element?
n/2
2
Lecture 1 Introduction and Peak Finding 6.006 Fall 2011
Can we do better?
If a[n/2] < a[n/2 1] then only look at left half 1 . . . n/2 1 to look for peak
Else if a[n/2] < a[n/2 + 1] then only look at right half n/2 + 1 . . . n to look for peak
a[n/2] a[n/2 1]
a[n/2] a[n/2 + 1]
T (n) = T (n/2) + (1) = (1) + . . . + (1) (log2 (n) times) = (log2 (n))
' -v "
to compare a[n/2] to neighbors
In order to sum up the (i)s as we do here, we need to nd a constant that works for all.
If n = 1000000, (n) algo needs 13 sec in python. If algo is (log n) we only need 0.001 sec.
Argue that the algorithm is correct.
Two-dimensional Version
b a d
n rows
e
m columns
a is a 2D-peak i a b, a d, a c, a e
3
Lecture 1 Introduction and Peak Finding 6.006 Fall 2011
14 13 12
15 9 11 17
16 17 19 20
j = m/2
Find a 1D-peak at i, j.
Attempt #1 fails
10
14 13 12
15 9 11
16 17 19 20
4
Lecture 1 Introduction and Peak Finding 6.006 Fall 2011
Attempt # 2
When you have a single column, nd global maximum and youre done.
Example of Attempt #2
go with
10 8 10 10 10 10 10
14 13 12 11 12 11 11
15 9 11 21 11 21 21 find 21
16 17 19 20 19 20 20
Complexity of Attempt #2
If T (n, m) denotes work required to solve problem with n rows and m columns
Question: What if we replaced global maximum with 1D-peak in Attempt #2? Would that
work?
5
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.