Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Course overview.
Course Staff
Keith Schwarz (htiek@cs.stanford.edu)
Kyle Brogle (broglek@stanford.edu)
Daniel Hollingshead (dhollingshead@stanford.edu)
Nick Isaacs (nisaacs@stanford.edu)
Aparna Krishnan (aparnak@stanford.edu)
Sen Wu (senwu@stanford.edu)
Course Staff Mailing List:
cs166-spr1314-staff@lists.stanford.edu
http://cs166.stanford.edu
Required Reading
Introduction to
Algorithms, Third
Edition by Cormen,
Leiserson, Rivest, and
Stein.
You'll want the third
edition for this
course.
Available in the
bookstore; several
copies on hold at the
Engineering Library.
Prerequisites
Grading Policies
Grading Policies
50% Assignments
25% Midterm
25% Final Project
31
41
59
26
53
58
97
93
A Trivial Solution
An Observation
1 subarray of
length 5
2 subarrays of
length 4
3 subarrays of
length 3
4 subarrays of
length 2
5 subarrays of
length 1
A Different Approach
0
1
16
0
18
1
33
2
98
3
2
3
18
0
1
2
3
4
5
6
7
Each
Eachentry
entryin
inyellow
yellowrequires
requiresat
at
least
leastnn/ /22==(n)
(n)work
workto
toevaluate.
evaluate.
2
2
There
are
roughly
n
2/ 8 = (n )
There are roughly n / 8 = (n2)
entries
entrieshere.
here.
3
Total
work
required:
(n
Total work required: (n)3)
A Different Approach
Can we do better?
0
0
16
0
18
1
33
2
98
3
16 16 16
18 18 18
33 33
98
Some Notation
A Block-Based Approach
31
Here, b = 3.
59
26
26
53
58
97
23
93
23
84
62
62
64
33
27
83
27
Preprocessing time:
31
31
41
59
26
26
53
58
97
23
93
23
84
62
62
64
33
27
83
27
Intuiting O(b + n / b)
As b increases:
As b decreases:
Optimizing b
Summary of Approaches
An Intuition
An Observation
0
0 31 31 31 26
1
2
41 41 26 26
59 26 26 26
31 41 59 26 53 58 97 93
53 53 53 53
58 58 58
97 93
93
5 6
26 26 26 26
The Intuition
Some Observations
The Approach
Creating Ranges
18
16
16
Creating Ranges
4
4
Doing a Query
31 41 59 26 53 58 97 93
0
0
1
2
3
4
5
6
7
20
21
22
31
41
59
26
53
58
97
93
31
41
26
26
53
58
93
23
Sparse Tables
Can we do better?
Blocking Revisited
31
31
41
59
26
26
53
58
97
23
93
23
84
62
62
64
33
27
83
27
Blocking Revisited
This
Thisisisjust
justRMQ
RMQon
on
the
theblock
blockminimums!
minimums!
31
31
41
59
26
26
53
58
97
23
93
23
84
62
62
64
33
27
83
27
Blocking Revisited
31
31
41
59
26
26
53
58
97
23
93
23
84
This
Thisisisjust
justRMQ
RMQ
inside
insidethe
theblocks!
blocks!
62
62
64
33
27
83
27
The Setup
The Framework
31
31
41
59
26
26
53
58
97
23
93
23
84
62
62
64
33
27
83
27
A Sanity Check
An Observation
Preprocessing time:
Another Hybrid
Let's suppose we use the O(n log n), O(1) sparse table
for both the top and bottom RMQ structures with a
block size of log n.
The preprocessing time is
=
=
=
=
Where We Stand
Next Time
Cartesian Trees