Advanced Algorithms - uni-wuerzburg.de · 1 Lecture 3. 2D Linear Programming via sweep-lines and...
Transcript of Advanced Algorithms - uni-wuerzburg.de · 1 Lecture 3. 2D Linear Programming via sweep-lines and...
1
Lecture 3. 2D Linear Programming via sweep-lines andrandomization
Advanced AlgorithmsWinter term 2019/20
Steven Chaplick & Alexander Wolff Chair for Computer Science I
Source: CG: A&A §4
2 - 1
Maximizing ProfitYou are the boss of a small company that produces twoproducts, P1 and P2. If you produce x1 units of P1 and x2units of P2, your profit in e is
G(x1, x2) = 300x1 + 500x2
2 - 2
Maximizing ProfitYou are the boss of a small company that produces twoproducts, P1 and P2. If you produce x1 units of P1 and x2units of P2, your profit in e is
G(x1, x2) = 300x1 + 500x2
Your production runs on three machines MA, MB, and MCwith the following capacities:
MA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
2 - 3
Maximizing ProfitYou are the boss of a small company that produces twoproducts, P1 and P2. If you produce x1 units of P1 and x2units of P2, your profit in e is
G(x1, x2) = 300x1 + 500x2
Your production runs on three machines MA, MB, and MCwith the following capacities:
Which choice of (x1, x2) maximizes your profit?
MA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
3 - 1
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 1500
0
linear constraints:
3 - 2
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 1500
0
linear constraints:
3 - 3
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 1500
0
linear constraints:
3 - 4
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 1500
0
linear constraints:
3 - 5
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
00
linear constraints:
3 - 6
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
00
linear constraints:
3 - 7
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
00
linear constraints:
set offeasiblesolutions
3 - 8
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2
00
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 9
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 10
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 11
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
30,000e
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 12
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 13
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 14
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 15
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
linear constraints:
linear objective fct.:
∂MA ∩ ∂MB =set offeasiblesolutions
3 - 16
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
linear constraints:
linear objective fct.:
∂MA ∩ ∂MB ={(110
40 )}
set offeasiblesolutions
3 - 17
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
G(110, 40) =
linear constraints:
linear objective fct.:
set offeasiblesolutions
3 - 18
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000set offeasiblesolutions
3 - 19
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000set offeasiblesolutions
3 - 20
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000set offeasiblesolutions
3 - 21
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
set offeasiblesolutions
3 - 22
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
x ≥ 0
set offeasiblesolutions
3 - 23
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
x ≥ 0
set offeasiblesolutions
3 - 24
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
maximize cTx
x ≥ 0
set offeasiblesolutions
3 - 25
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
maximize cTx
x ≥ 0
maximum value of objec-tive fct. given constraints
=set offeasiblesolutions
3 - 26
The AnswerMA : 4x1 + 11x2 ≤ 880MB : x1 + x2 ≤ 150MC : x2 ≤ 60
50
100
150
200
x2
x150 100 150
x1 ≥ 0x2 ≥ 0
G(x1, x2) = 300x1 + 500x2= (300, 500)(x1
x2)
00
”iso-profit line“ (orthogonal to (300500))
15,000e
45,000e30,000e
53,000e
G(110, 40) =
linear constraints:
linear objective fct.:
53,000
Ax ≤ b
maximize cTx
x ≥ 0
maximum value of objec-tive fct. given constraints
=
max{cTx | Ax ≤ b, x ≥ 0}=
set offeasiblesolutions
4 - 1
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
4 - 2
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).Many algorithms known, e.g.:
4 - 3
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).Many algorithms known, e.g.:– Simplex [Dantzig ’47]
4 - 4
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
4 - 5
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
4 - 6
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
4 - 7
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
4 - 8
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
[“Book” application: casting]
4 - 9
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
[“Book” application: casting]
4 - 10
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
[“Book” application: casting]
4 - 11
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
c
[“Book” application: casting]
4 - 12
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
c
[“Book” application: casting]
4 - 13
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
cc
[“Book” application: casting]
4 - 14
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
cc
[“Book” application: casting]
4 - 15
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
cc
⋂H bounded.[“Book” application: casting]
4 - 16
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
cc
⋂H bounded.
set of optima: segment vs. point
[“Book” application: casting]
4 - 17
Definition and Known Algorithms
Given a set H of n halfspaces in Rd and a direction c, finda point x ∈ ⋂
H such that cx is maximum (or minimum).
We consider d = 2.VERY important problem, e.g., in Operations Research.
Many algorithms known, e.g.:– Simplex [Dantzig ’47]– Ellipsoid method [Khatchiyan ’79]
– Inner-point method [Karmakar’ 84]
Good for instances where n and d are large.
⋂H = ∅
⋂H unbnd. in dir. c
cc c
⋂H bounded.
set of optima: segment vs. point
[“Book” application: casting]
5 - 1
First Approach
• compute⋂
H iteratively
5 - 2
First Approach
• compute⋂
H iteratively
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
5 - 3
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
5 - 4
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
Running time:
5 - 5
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
Running time:
5 - 6
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Running time:
5 - 7
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Walk around C to findsj, sj′ ∈ C intersecting hi
Running time:
5 - 8
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Walk around C to findsj, sj′ ∈ C intersecting hi
Update C
Running time:
5 - 9
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Walk around C to findsj, sj′ ∈ C intersecting hi
Update C
O(n)Running time:
5 - 10
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Walk around C to findsj, sj′ ∈ C intersecting hi
Update C
Total Time: O(n2) :(
O(n)Running time:
5 - 11
First Approach
• compute⋂
H iteratively
IntersectHalfplanes(H)
Let H = (h1, . . . , hn)C ← h1foreach i from 2 to n do
C ← C ∩ hi
return C
TIH(n) = n·
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
C := chain of linesegments (s1, . . . , st)
Walk around C to findsj, sj′ ∈ C intersecting hi
Update C
Exercise: Compute C ∩ hi faster.
Total Time: O(n2) :(
O(n)Running time:
6 - 1
Second Approach
• compute⋂
H via divide and conquer
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 2
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 3
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 4
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
Running time:
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 5
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
Running time: TIH(n) = 2TIH(n/2) + TICR(n)
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 6
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
Running time: TIH(n) = 2TIH(n/2) + TICR(n)
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
6 - 7
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
Running time: TIH(n) = 2TIH(n/2) + TICR(n)
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
How complex canthe new region be?
6 - 8
Second Approach
• compute⋂
H via divide and conquer
IntersectHalfplanes(H)
if |H| = 1 thenC ← h, where {h} = H
elsesplit H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return C
Running time: TIH(n) = 2TIH(n/2) + TICR(n)
How??
• walk ∂ (⋂
H), find vertex x w/ cx maximum, O(n) time
How complex canthe new region be?
7 - 1
Intersecting Convex Regions
C1C2
7 - 2
Intersecting Convex Regions
C1C2
`
7 - 3
Intersecting Convex Regions
C1C2
`How many segments on `?
7 - 4
Intersecting Convex Regions
C1C2
`How many segments on `?
7 - 5
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
Lright(C2)
How many segments on `?
7 - 6
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
leftEdgeC1
rightEdgeC1
leftEdgeC2
rightEdgeC2
Lright(C2)
How many segments on `?
7 - 7
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
leftEdgeC1
rightEdgeC1
leftEdgeC2
Is > 4 possible?
rightEdgeC2
Lright(C2)
How many segments on `?
7 - 8
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
leftEdgeC1
rightEdgeC1
leftEdgeC2
Is > 4 possible?No!
rightEdgeC2
Lright(C2)
How many segments on `?
7 - 9
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
leftEdgeC1
rightEdgeC1
leftEdgeC2
Is > 4 possible?No!
rightEdgeC2
Lright(C2)
How many segments on `?
How does this help us?
7 - 10
Intersecting Convex Regions
Lleft(C1)
C1C2
`
Lright(C1)
Lleft(C2)
leftEdgeC1
rightEdgeC1
leftEdgeC2
Theorem. The intersection of two convex polygonalregions can be computed in linear time.
Is > 4 possible?No!
rightEdgeC2
Lright(C2)
How many segments on `?
How does this help us? sweep-line algorithm!
8 - 1
Sweep-Line Algorithm
C1 C2
8 - 2
Sweep-Line Algorithm
C1 C2
sweep line
events
8 - 3
Sweep-Line Algorithm
C1 C2
events
8 - 4
Sweep-Line Algorithm
C1 C2
events
8 - 5
Sweep-Line Algorithm
C1 C2
events
8 - 6
Sweep-Line Algorithm
C1 C2
events
8 - 7
Sweep-Line Algorithm
C1 C2
events
next event?
8 - 8
Sweep-Line Algorithm
C1 C2
events
next event?
8 - 9
Sweep-Line Algorithm
C1 C2
events
8 - 10
Sweep-Line Algorithm
C1 C2
events
8 - 11
Sweep-Line Algorithm
C1 C2
events
8 - 12
Sweep-Line Algorithm
C1 C2
events
8 - 13
Sweep-Line Algorithm
C1 C2
events
8 - 14
Sweep-Line Algorithm
C1 C2
events
8 - 15
Sweep-Line Algorithm
C1 C2
events
next event?
8 - 16
Sweep-Line Algorithm
C1 C2
events
next event?
8 - 17
Sweep-Line Algorithm
C1 C2
events
8 - 18
Sweep-Line Algorithm
C1 C2
events
Done, since we havefinished C!
9 - 1
Data Structures1) event (-point) queue Q
2) (sweep-line) status T
9 - 2
Data Structures1) event (-point) queue Q
p ≺ q ⇔def.
2) (sweep-line) status T
9 - 3
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. yp > yq
2) (sweep-line) status T
9 - 4
Data Structures1) event (-point) queue Q
p ≺ q ⇔def.
p q
yp > yq
2) (sweep-line) status T
9 - 5
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
2) (sweep-line) status T
9 - 6
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
2) (sweep-line) status T
`
9 - 7
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
2) (sweep-line) status T
`
9 - 8
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺
2) (sweep-line) status T
`
9 - 9
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺
2) (sweep-line) status T
`
... linear time?
9 - 10
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
`
9 - 11
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
`
... runtime?
9 - 12
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
`
... runtime? O(1), since num. active segments ≤ 4 :)
9 - 13
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
`
`
... runtime? O(1), since num. active segments ≤ 4 :)
9 - 14
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
Store the segments intersected by ` in left-to-right order.
`
`
... runtime? O(1), since num. active segments ≤ 4 :)
9 - 15
Data Structures1) event (-point) queue Q
p ≺ q ⇔def. or (yp = yq and xp < xq)
p q
yp > yq
Store event pts in sorted order acc. to ≺nextEvent() : either, next point (by ≺), or the intersectionpt. of two active segments (below the sweep-line)
2) (sweep-line) status T
Store the segments intersected by ` in left-to-right order.
`
`
Also, maintain the new convex hull.
... runtime? O(1), since num. active segments ≤ 4 :)
10 - 1
Second Approach: Halfplane IntersectionTheorem. The intersection of two convex polygonal
regions can be computed in linear time.
10 - 2
Second Approach: Halfplane IntersectionTheorem. The intersection of two convex polygonal
regions can be computed in linear time.
IntersectHalfplanes(H)
if |H| = 1 then C ← h, where {h} = Helse
split H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return CRunning time: TIH(n) = 2TIH(n/2) + TICR(n)
10 - 3
Second Approach: Halfplane IntersectionTheorem. The intersection of two convex polygonal
regions can be computed in linear time.
Corollary. The intersection of n half planes can becomputed in O(n log n) time.
IntersectHalfplanes(H)
if |H| = 1 then C ← h, where {h} = Helse
split H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return CRunning time: TIH(n) = 2TIH(n/2) + TICR(n)
10 - 4
Second Approach: Halfplane IntersectionTheorem. The intersection of two convex polygonal
regions can be computed in linear time.
Corollary. The intersection of n half planes can becomputed in O(n log n) time.
Can we do better?
IntersectHalfplanes(H)
if |H| = 1 then C ← h, where {h} = Helse
split H into sets H1 and H2 with |H1|, |H2| ≈ |H|/2C1 ← IntersectHalfplanes(H1)C2 ← IntersectHalfplanes(H2)C ← IntersectConvexRegions(C1, C2)
return CRunning time: TIH(n) = 2TIH(n/2) + TICR(n)
11 - 1
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
c
11 - 2
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
c
11 - 3
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 c
11 - 4
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1
m2
c
11 - 5
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1
m2
c
11 - 6
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
c
11 - 7
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
m2 =
{y ≤ M if cy > 0,y ≥ M otherwise.
c
11 - 8
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
m2 =
{y ≤ M if cy > 0,y ≥ M otherwise.
c
Idea: M based on obj.fct. c.see §4.5 of CG: A&A for moreon unbounded LPs.
11 - 9
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
m2 =
{y ≤ M if cy > 0,y ≥ M otherwise.
• Take the lexicographically largest solution.
c
Idea: M based on obj.fct. c.see §4.5 of CG: A&A for moreon unbounded LPs.
11 - 10
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
m2 =
{y ≤ M if cy > 0,y ≥ M otherwise.
• Take the lexicographically largest solution.
c
Idea: M based on obj.fct. c.see §4.5 of CG: A&A for moreon unbounded LPs.
11 - 11
A Small Trick: Make Solution Unique⋂
H = ∅⋂
H unbnd. in dir. c
c c
⋂H bounded.
• Add two bounding halfplanes m1 and m2
m1 =
{x ≤ M if cx > 0,x ≥ M otherwise,
for some sufficiently large M
m1
m2
m2 =
{y ≤ M if cy > 0,y ≥ M otherwise.
• Take the lexicographically largest solution.
⇒ Set of solutions is either empty or a uniquely defined pt.
c
Idea: M based on obj.fct. c.see §4.5 of CG: A&A for moreon unbounded LPs.
12 - 1
Incremental ApproachIdea: Don’t compute
⋂H, but just one (optimal) point!
12 - 2
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 3
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 4
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 5
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 6
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 7
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 8
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
12 - 9
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
12 - 10
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
12 - 11
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
12 - 12
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
12 - 13
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
12 - 14
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
12 - 15
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
12 - 16
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
12 - 17
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
12 - 18
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
12 - 19
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
O(i)
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
12 - 20
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
O(i)
T(n) = ∑ni=1 O(i) =
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
12 - 21
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
O(i)
T(n) = ∑ni=1 O(i) =
= O(n2) :-(
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
12 - 22
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
O(i)
T(n) = ∑ni=1 O(i) =
= O(n2) :-(
RandomizedIdea: Don’t compute
⋂H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
12 - 23
Incremental Approach
2DBoundedLP(H, c, m1, m2)
H0 = {m1, m2}v0 ← corner of m1 ∩m2for i← 1 to n do
if vi−1 ∈ hi thenvi ← vi−1
elsevi ← 1DBoundedLP(π∂hi
(Hi−1), π∂hi(c))
if vi = nil thenreturn nil
Hi = Hi−1 ∪ {hi}return vn
w-c running time:
O(1)
O(i)
T(n) = ∑ni=1 O(i) =
= O(n2) :-(
Randomized
compute random permutation of H
Idea: Don’t compute⋂
H, but just one (optimal) point!
∂hi
c
π∂hi(c)
O(1)
13 - 1
Result
:-)Theorem. The 2D bounded LP problem can be solved in
O(n) expected time.
13 - 2
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
13 - 3
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
Then the expected running time is
E[T2d(n)] =
13 - 4
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
13 - 5
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
13 - 6
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
13 - 7
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
We fix the i random halfplanes in Hi.
13 - 8
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
We fix the i random halfplanes in Hi.
13 - 9
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
We fix the i random halfplanes in Hi.
13 - 10
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
13 - 11
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
i.e., when vi ∈ ∂hiand vi ∈ ∂hj forexactly one j < i.
13 - 12
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
≤ 2/i.
i.e., when vi ∈ ∂hiand vi ∈ ∂hj forexactly one j < i.
13 - 13
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
≤ 2/i. This is independent of the choice of Hi.
i.e., when vi ∈ ∂hiand vi ∈ ∂hj forexactly one j < i.
13 - 14
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
≤ 2/i. This is independent of the choice of Hi.
13 - 15
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
≤ 2/i. This is independent of the choice of Hi.
= O(n).
�
13 - 16
Result
:-)
Proof. Let Xi =
{1 if vi−1 6∈ hi,0 else.
}(indicator random variable).
Theorem. The 2D bounded LP problem can be solved inO(n) expected time.
= O(n) + ∑ E[Xi] ·O(i)
= O(n) + ∑ Pr[Xi = 1] ·O(i)
Then the expected running time is
E[T2d(n)] = E[∑ni=1(1− Xi) ·O(1) + Xi ·O(i)]
Pr[Xi =1] = probability that the optimal solutionchanges when hi is added to Hi−1.
= probability that the optimal solutionchanges when hi is removed from Hi.
We fix the i random halfplanes in Hi.
≤ 2/i. This is independent of the choice of Hi.
= O(n).
�
Proof technique:Backward analysis!
14 - 1
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) =
CG: A & A §2
14 - 2
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
CG: A & A §2
14 - 3
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.here: I ≤
CG: A & A §2
14 - 4
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.here: nI ≤
CG: A & A §2
O(n log n) for ICR
14 - 5
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
Running time TIH(n) = 2TIH(n/2) + TICR(n)
here: nI ≤
≤
CG: A & A §2
O(n log n) for ICR
14 - 6
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
Running time TIH(n) = 2TIH(n/2) + TICR(n)
here: nI ≤
≤ 2TIH(n/2) + O(n log n)
∈
CG: A & A §2
O(n log n) for ICR
14 - 7
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
Running time TIH(n) = 2TIH(n/2) + TICR(n)
here: nI ≤
≤ 2TIH(n/2) + O(n log n)
∈ O(n log2 n)
CG: A & A §2
O(n log n) for ICR
14 - 8
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
Running time TIH(n) = 2TIH(n/2) + TICR(n)
here: nI ≤
≤ 2TIH(n/2) + O(n log n)
∈ O(n log2 n)As this is more general, it is unsurprisingly worse ... ∗
CG: A & A §2
O(n log n) for ICR
∗ it can happen sometimes that general algorithms give optimal runtimes for special cases
14 - 9
Alt. for Intersecting Convex Regions
Use sweep-line alg. for map overlay (line-segment intersections) !
Running time TMO(n) = O((n + I) log n),where I = # intersection points.
Running time TIH(n) = 2TIH(n/2) + TICR(n)
here: nI ≤
≤ 2TIH(n/2) + O(n log n)
∈ O(n log2 n)As this is more general, it is unsurprisingly worse ... ∗
Better to use specialized algorithm for intersectingconvex regions/polygons
CG: A & A §2
O(n log n) for ICR
∗ it can happen sometimes that general algorithms give optimal runtimes for special cases