Professional Documents
Culture Documents
Yadu Vasudev
yadu@cse.iitm.ac.in
IIT Madras
Module plan
1. Asymptotic analysis
3. Order statistics
1
Asymptotic analysis
Recall: Asymptotic analysis
2
Recall: Asymptotic analysis
2
Recall: Asymptotic analysis
2
Recall: Asymptotic analysis
Definitions of O, Ω, and Θ
• A function f(n) = O(g(n)) if ∃c > 0 and n0 ≥ 1 such that
f(n) ≤ cg(n), ∀n ≥ n0
• A function f(n) = Ω(g(n)) if ∃c > 0 and n0 ≥ 1 such that
f(n) ≥ cg(n), ∀n ≥ n0
• A function f(n) = Θ(g(n)) iff f(n) = O(g(n)) and f(n) = Ω(g(n))
2
Recall: Asymptotic analysis
Little-oh
• A function f(n) = o(g(n)) if ∀c > 0, there exists an n0 s.t
f(n) < cg(n), ∀n ≥ n0
2
Recall: Asymptotic analysis
Little-oh
• A function f(n) = o(g(n)) if ∀c > 0, there exists an n0 s.t
f(n) < cg(n), ∀n ≥ n0
• Equivalently,
f(n)
lim =0
n→∞ g(n)
2
Recall: Asymptotic analysis
Little-oh
• A function f(n) = o(g(n)) if ∀c > 0, there exists an n0 s.t
f(n) < cg(n), ∀n ≥ n0
• Equivalently,
f(n)
lim =0
n→∞ g(n)
• f(n) is a strictly slower growing function than g(n)
2
Recall: Asymptotic analysis
Little-omega
• A function f(n) = ω(g(n)) if ∀c > 0, there exists an n0 s.t
f(n) > cg(n), ∀n ≥ n0
• Equivalently,
f(n)
lim =∞
n→∞ g(n)
• f(n) is a strictly faster growing function than g(n)
2
Recall: Asymptotic analysis
3
Recall: Asymptotic analysis
3
Recall: Asymptotic analysis
(
1 if n is even,
f(n) =
log n otherwise
3
Recall: Asymptotic analysis
(
1 if n is even,
f(n) =
log n otherwise
3
Some interesting functions
4
Some interesting functions
·2
··
22
• non-elementary functions - f(n) = 2 : height of the tower of
2s depends on the input size
4
Some interesting functions
·2
··
22
• non-elementary functions - f(n) = 2 : height of the tower of
2s depends on the input size
• iterated logarithm - log∗ n: number of times log has to be taken
before n is at most 1
• log∗ n ≤ 4 for all practical values of n
4
Some interesting functions
·2
··
22
• non-elementary functions - f(n) = 2 : height of the tower of
2s depends on the input size
• iterated logarithm - log∗ n: number of times log has to be taken
before n is at most 1
• log∗ n ≤ 4 for all practical values of n
• Ackermann function
• α(n, 0) - increment by 1
• α(n, 1) - perform incremement n times: addition
• α(n, 2) - perform addition n times: multiplication
• α(n, 3) - perform multiplication n times: exponentiation
• α(n, 4) - perform exponentiation n times: ? . . .
4
Integer Multiplication Redux
Recall: Peasant multiplication
5
Recall: Peasant multiplication
Running time:
5
Recall: Peasant multiplication
Running time:
5
Recall: Peasant multiplication
Running time:
5
Recall: Peasant multiplication
Running time:
5
Faster integer multiplication
Recursive solution:
6
Faster integer multiplication
Recursive solution:
6
Faster integer multiplication
Recursive solution:
6
Faster integer multiplication
Recursive solution:
6
Faster integer multiplication
Recursive solution:
6
Analyzing recurrence relations
7
Analyzing recurrence relations
n
T(n) = 4 T( ) + O(n)
2
7
Analyzing recurrence relations
n
T(n) = 4 T( ) + O(n)
2
7
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
8
Analyzing recurrence relations: Recursion trees
n cn
n n n n
2 2 2 2 2cn
n n n n n n n n
4 4 4 4 ··· 4 4 4 4 ··· 22 cn
.. .. .. .. .. .. ..
. . . . . . .
2log n cn
Running time: cn(1 + 2 + 22 + · · · + 2log n ) = O(n2 )
8
Recursion trees: The master theorem
n n n n
b b b b af( bn )
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
9
Recursion trees: The master theorem
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
n n n n
b b b b af( bn )
a a
n n n n n n n n
b2 b2 b2 b2 ··· b2 b2 b2 b2 a2 f( bn2 )
.. .. .. .. .. .. ..
. . . . . . .
alogb n f(1)
When
logb n−1 n
T(n) = Θ(nlogb a ) + ai f
X
,
bi
i=0
10
Recursion trees: The master theorem
When
logb n−1 n
T(n) = Θ(nlogb a ) + ai f
X
,
bi
i=0
10
Recursion trees: The master theorem
When
logb n−1 n
T(n) = Θ(nlogb a ) + ai f
X
,
bi
i=0
Points to remember:
• Floors and ceilings are not important in proving the upper
bounds (for most cases)
• Use recursion trees directly when the master theorem cannot
be applied
10
Integer multiplication: Karatsuba’s method
11
Integer multiplication: Karatsuba’s method
11
Integer multiplication: Karatsuba’s method
11
Integer multiplication: Karatsuba’s method
(a − b)(c − d)
11
Integer multiplication: Karatsuba’s method
(a − b)(c − d)
11
Integer multiplication: Karatsuba’s method
(a − b)(c − d)
11
Integer multiplication: Karatsuba’s method
(a − b)(c − d)
11
Integer multiplication: A short history
12
Integer multiplication: A short history
“...our work is expected to be the end of the road for this problem, al-
though we don’t know yet how to prove this rigorously.“
12
Order statistics
Order statistics
Given an array A[1, 2, . . . , n], find the kth element in the sorted array
13
Order statistics
Given an array A[1, 2, . . . , n], find the kth element in the sorted array
13
Order statistics
Given an array A[1, 2, . . . , n], find the kth element in the sorted array
13
Order statistics
Given an array A[1, 2, . . . , n], find the kth element in the sorted array
13
Median of medians
14
Median of medians
n
5
• Divide the array A into n/5 subarrays of length 5 and find their
medians
14
Median of medians
n
5
• Divide the array A into n/5 subarrays of length 5 and find their
medians
• How good is the median of these medians as a pivot?
14
Median of medians
n
5
• Divide the array A into n/5 subarrays of length 5 and find their
medians
• How good is the median of these medians as a pivot?
14
Median of medians
n
5
• Divide the array A into n/5 subarrays of length 5 and find their
medians
• How good is the median of these medians as a pivot?
• All the blue elements are ≤ m and all the green elements are
≥ m - How many are there?
14
Median of medians
n
5
3n
10
m
3n
10
• Divide the array A into n/5 subarrays of length 5 and find their
medians
• How good is the median of these medians as a pivot?
• All the blue elements are ≤ m and all the green elements are
≥ m - How many are there?
14
A recursive algorithm
15
A recursive algorithm
15
Running time - median of medians algorithm
16
Running time - median of medians algorithm
7n
T(n) ≤ 2T +O(n)?
10
16
Running time - median of medians algorithm
7n
T(n) ≤ 2T +O(n)?
10
O(nlog10/7 2 )
16
Running time - median of medians algorithm
7n
T(n) ≤ 2T +O(n)?
10
O(nlog10/7 2 )
16
Running time using recursion trees
n 7n
T(n) = T +T + O(n)
5 10
17
Running time using recursion trees
n 7n
T(n) = T +T + O(n)
5 10
n 7n
5 10
n 7n 7n 49n
25 50 50 100
.. .. .. ..
. . . .
17
Running time using recursion trees
n 7n
T(n) = T +T + O(n)
5 10
n n
n 7n 9
5 10 10 n
n 7n 7n 49n 9 2
n
25 50 50 100 10
.. .. .. ..
. . . . 9 i
n
≤ 10
17
Running time using recursion trees
n 7n
T(n) = T +T + O(n)
5 10
n n
n 7n 9
5 10 10 n
n 7n 7n 49n 9 2
n
25 50 50 100 10
.. .. .. ..
. . . . 9 i
n
≤ 10
2 !
9 9
T(n) ≤ 1+ + + ··· n = O(n)
10 10
17
Fast Fourier Transform
Convolution of vectors
18
Convolution of vectors
18
Convolution of vectors
18
Convolution of vectors
18
Convolution of vectors
19
Convolution of vectors
19
Convolution of vectors
19
Convolution of vectors
19
Convolution of vectors
19
Convolution of vectors
19
Vectors and polynomials
20
Vectors and polynomials
20
Vectors and polynomials
20
Vectors and polynomials
20
Polynomials - an alternate view
21
Polynomials - an alternate view
n−1
ai xi
X
P(x) =
i=0
a0 P(α0 )
a P(α )
1 1
a2 ≡ P(α2 )
vector of coefficients vector of evaluations
.. ..
. .
an−1 P(αn−1 )
21
Polynomials - an alternate view
n−1 n−1
ai xi Q(x) = bi xi
X X
P(x) =
i=0 i=0
a0 b0 P(α0 )Q(α0 )
a b P(α )Q(α )
1 1 1 1
a2 ∗ b2 ≡ P(α2 )Q(α2 )
.. .. ..
. . .
an−1 bn−1 P(α2n−2 )Q(α2n−2 )
21
Convolution - outline of an algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
P(α0 )Q(α0 ),
P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
22
Convolution - outline of an algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
P(α0 )Q(α0 ),
P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
22
Convolution - outline of an algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
P(α0 )Q(α0 ),
P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
22
Convolution - outline of an algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
pointwise product
P(α0 )Q(α0 ),
P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
22
Convolution - outline of an algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
pointwise product
P(α0 )Q(α0 ),
interpolation P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
22
Polynomial evaluation
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
24
Polynomial evaluation
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
24
Polynomial evaluation
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
24
Polynomial evaluation
P(x) = a0 + a1 x + a2 x2 + a3 x3 + · · ·
= (a0 + a2 x2 + a4 x4 + · · · ) + x(a1 + a3 x2 + a5 x4 + · · · )
25
Polynomial evaluation - a “complex” approach
25
Polynomial evaluation - a “complex” approach
1, ω, ω 2 , . . . , ω i , . . . , ω n−1 1
e2πi/n
25
Polynomial evaluation - a “complex” approach
4π/n
1, ω, ω 2 , . . . , ω j , . . . , ω n−1 1
e2πi/n
26
Polynomial evaluation - a “complex” approach
4π/n
1, ω, ω 2 , . . . , ω j , . . . , ω n−1 1
e2πi/n
n
• For each j, ω 2 +j = −ω j when n is even
26
Polynomial evaluation - a “complex” approach
4π/n
1, ω, ω 2 , . . . , ω j , . . . , ω n−1 1
2π/n + π
e2πi/n
n
• For each j, ω 2 +j = −ω j when n is even
n 2πi n
πi 2πi j
ω 2 +j = e n 2 +j =e (e n )
= −ω j
26
Polynomial evaluation - a “complex” approach
4π/n
1, ω, ω 2 , . . . , ω j , . . . , ω n−1 1
2π/n + π
e2πi/n
n
• For each j, ω 2 +j = −ω j when n is even
n 2πi n
πi 2πi j
ω 2 +j = e n 2 +j =e (e n )
= −ω j
26
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Polynomial evaluation - the Fast Fourier Transform
27
Where are we now?
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
P(α0 )Q(α0 ),
interpolation P(α1 )Q(α1 ),
P(x)Q(x)
...
P(α2n−2 )Q(α2n−2 )
28
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a matrix view
n−1
aj ωij
X
P(ω) =
j=0
P(1) 1 1 1 1 a0
···
P(ω) 1
ω ω2 ··· ω n−1 a1
P(ω 2 ) = 1 ω2 (ω 2 )2 ··· 2 n−1
(ω ) a2
.. .. .. ..
. . . .
··· ···
n−1
P(ω ) 1 ω n−1 n−1 2
(ω ) ··· (ω n−1 )n−1 an−1
29
Polynomial evaluation - a geometric view
30
Polynomial evaluation - a geometric view
1 1 1 1 0
···
1
ω ω2 ··· ω n−1 0
1 ω 2 (ω 2 )2 · · · (ω 2 )n−1 1
.. .. ..
. . .
··· ···
n−1 n−1 2 n−1 n−1
1 ω (ω ) · · · (ω ) 0
30
Polynomial evaluation - a geometric view
1 1 1 1 0
···
1
ω ω2 ··· ω n−1 0
1 ω 2 (ω 2 )2 · · · (ω 2 )n−1 1
.. .. ..
. . .
··· ···
n−1 n−1 2 n−1 n−1
1 ω (ω ) · · · (ω ) 0
30
Polynomial evaluation - a geometric view
1 1 1 1 0
···
1
ω ω2 ··· ω n−1 0
1 ω 2 (ω 2 )2 · · · (ω 2 )n−1 1
.. .. ..
. . .
··· ···
n−1 n−1 2 n−1 n−1
1 ω (ω ) · · · (ω ) 0
30
Polynomial evaluation - a geometric view
31
Polynomial evaluation - a geometric view
31
Polynomial evaluation - a geometric view
Pn−1
• If j = k, then i=0 ω i(j−k) = n
• If j 6= k,
n−1
1 − ω n(j−k)
ω i(j−k) =
X
1 − ω j−k
i=0 31
Polynomial evaluation - a geometric view
Pn−1
• If j = k, then i=0 ω i(j−k) = n
ω n = 1 - nth root of unity
• If j 6= k,
n−1
1 − ω n(j−k)
ω i(j−k) =
X
=0
1 − ω j−k
i=0 31
Polynomial evaluation - a geometric view
31
Polynomial evaluation - a geometric view
31
Polynomial evaluation - a geometric view
V(ω)V(ω)∗ = nI
complex conjugate
31
Interpolation - Inverting the Vandermonde matrix
32
Interpolation - Inverting the Vandermonde matrix
1 1 1 1
···
1
ω −1 (ω −1 )2 ··· (ω −1 )n−1
V(ω)∗ = 1 ω −2 (ω −2 )2 ··· (ω −2 )n−1
.. ..
. .
··· ···
−(n−1) 2 −(n−1) n−1
1 ω −(n−1)
(ω ) ··· (ω )
32
Interpolation - Inverting the Vandermonde matrix
1 1 1 1
···
1
ω −1 (ω −1 )2 ··· (ω −1 )n−1
V(ω)∗ = 1 ω −2 (ω −2 )2 ··· (ω −2 )n−1
.. ..
. .
··· ···
−(n−1) 2 −(n−1) n−1
1 ω −(n−1)
(ω ) ··· (ω )
32
Interpolation - Inverting the Vandermonde matrix
1 1 1 1
···
1
ω −1 (ω −1 )2 ··· (ω −1 )n−1
V(ω)∗ = 1 ω −2 (ω −2 )2 ··· (ω −2 )n−1
.. ..
. .
··· ···
−(n−1) 2 −(n−1) n−1
1 ω −(n−1)
(ω ) ··· (ω )
ω −j = ω n−j
32
Interpolation - Inverting the Vandermonde matrix
1 1 1 1
···
1 ω n−1 (ω n−1 )2 ··· (ω n−1 )n−1
V(ω)∗ = 1 ω n−2 (ω n−2 )2 ··· (ω n−2 )n−1
.. ..
. .
··· ···
1 ω (ω)2 ··· (ω) n−1
ω −j = ω n−j
32
Convolution - the final algorithm
n−1 n−1
i
bi xi
X X
P(x) = ai x Q(x) =
i=0 i=0
P(α0 )Q(α0 ),
interpolation P(α1 )Q(α1 ),
P(x)Q(x)
O(n log n) ...
P(α2n−2 )Q(α2n−2 )
33
Closest pair of points
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1)
(−0.5, −0.5)
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1) √
0.5
(−1, 0.5) (1.5, 0.5)
(−0.5, −0.5)
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1) √
0.5
(−1, 0.5) (1.5, 0.5)
(−0.5, −0.5)
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1) √
0.5
(−1, 0.5) (1.5, 0.5)
(−0.5, −0.5)
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1) √
0.5
(−1, 0.5) (1.5, 0.5)
(−0.5, −0.5)
34
Pairwise distances of points
Given n points {pi = (xi , yi )}1≤i≤n on the plane, find a pair of points
that are closest to each other
(1, 1) √
0.5
(−1, 0.5) (1.5, 0.5)
(−0.5, −0.5)
34
Pairwise distances - the 1D case
Given n points on the real line - find the pair of points that are
closest to each other
35
Pairwise distances - the 1D case
Given n points on the real line - find the pair of points that are
closest to each other
35
Pairwise distances - the 1D case
Given n points on the real line - find the pair of points that are
closest to each other
35
Pairwise distances - the 1D case
Given n points on the real line - find the pair of points that are
closest to each other
35
Pairwise distances - the 2D case
36
Pairwise distances - the 2D case
36
Pairwise distances - the 2D case
(1, 3)
(3, 1)
(−3, −1)
(−1, −3)
36
Pairwise distances - the 2D case
(1, 3)
(3, 1)
√
2 10
(−3, −1)
√
2 2
(−1, −3)
36
Pairwise distances - a divide and conquer approach
37
Pairwise distances - a divide and conquer approach
37
Pairwise distances - a divide and conquer approach
37
Pairwise distances - a divide and conquer approach
δ1
δ2
37
Pairwise distances - a divide and conquer approach
δ1
δ3
δ2
37
Pairwise distances - a divide and conquer approach
δ1
δ3
δ2
37
Pairwise distances - a divide and conquer approach
δ1
δ3
δ2
37
Pairwise distances - a divide and conquer approach
δ1
δ3
δ2
37
Pairwise distances - a divide and conquer approach
δ1
δ2
38
Pairwise distances - a divide and conquer approach
δ1
δ = min(δ1 , δ2 )
δ2
38
Pairwise distances - a divide and conquer approach
2δ
δ1
δ = min(δ1 , δ2 )
δ2
38
Pairwise distances - a divide and conquer approach
2δ
δ1
δ = min(δ1 , δ2 )
δ2
38
Pairwise distances - a divide and conquer approach
2δ
δ1
δ = min(δ1 , δ2 )
δ2
38
Pairwise distances - bounding the number of points
δ δ
39
Pairwise distances - bounding the number of points
39
Pairwise distances - bounding the number of points
39
Pairwise distances - bounding the number of points
39
Pairwise distances - bounding the number of points
39
Closest pair of points - a divide and conquer algorithm
40
Closest pair of points - a divide and conquer algorithm
δ 0 ← min(δ 0 , d(p, p0 ))
return min(δ 0 , δ)
n
T(n) = 2T + O(n log n)
2
40
Closest pair of points - solving the recurrence
n
T(n) = 2T + O(n log n)
2
41
Closest pair of points - solving the recurrence
n
T(n) = 2T + O(n log n)
2
a b f(n)
41
Closest pair of points - solving the recurrence
n
T(n) = 2T + O(n log n)
2
a b f(n)
41
Closest pair of points - solving the recurrence
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
a b f(n)
41
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
42
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
42
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
42
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
42
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
42
Closest pair of points - preprocessing the input
Can we avoid sorting
n
T(n) = 2T + O(n log n)
2 at each step?
n
T(n) = 2T + O(n) + one-time cost of sorting
2
42