Transcript Slide 1

Exhaustion,
Branch and Bound,
Divide and Conquer
•
•
•
•
Bin packing
Maximum Consecutive Sum
Fast Exponentiation
Closest Pair
• 窮舉/窮尋/暴力法
• Also called Brute Force
• Anyway it is not about violence...
Why Exhaustion
• Sometimes it’s the only way out.
• Case Study 1
• Irreversible Transform
• Given a transform H, you can calculate y = H(x)
• But given y, you cannot easily calculate x such
that y = H(x), we call H is irreversible
• Given y, tell me how many x can be
transformed to y
Why Exhaustion
• Simple
• Less Error Prone
• …
• But that may take a LONG TIME.
Not that simple
• The way you exhaust matters
• Case Study 2
• Narrow Range Broadband
• Given all clients’ positions as well as the
profits that can be made from each of them
• You can only setup one server station
with limited transmission distance
• Give the best possible position and
the profit for the company
• Case Study 2
• Give the best possible position and the profit
for the company
• Any definite answer, first?
• The more the clients it covers, the better?
• Map size: at most 100 x 100 (w x h)
• Number of clients: at most 1000 (n)
• Maximum distance: 200 (d)
• Manhatten Distance:
• Case Study 2
• Give the best possible position and the profit
for the company
• Solution 1
• Each position can be the best
• For each position
• Find from its reachable distance
• Add profit if that position is a client
• Complexity?
• Case Study 2
• Give the best possible position and the profit
for the company
• Solution 1
• Complexity?
• Can we be faster?
• Case Study 2
• Give the best possible position and the profit for
the company
• Solution 2
• A client is served if a server can reach
it within d units
• Similarly, if a client can reach the server d units, it
is served
• By exploiting the fact that distance is symmetric,
one can achieve an
algorithm
• Any faster algorithm?
• Summary
• If you cannot figure out fast way to solve a
given problem (may or may not exist), try
brute force
• For small case (usually 30%~50%), they are
designed for brute force purposes
• Exhaust in a smart way
Tricks
• Pre-process
• Memorization
• MRV (Minimum Remaining Values)
– Aka. MCV (Most Constrained Variables)
• LCV (Least Constraining Value)
Branch and Bound
• Basically like exhaustion
• Try to be faster
– Prune sub-optimal searching early
Branch and Bound
• Idea: “Estimate” the best solution of the
current Search Tree with a heuristic
function
• If the estimation says this search tree will
not produce better result, give up on it…
• Well… is it possible that we miss the
optimal solution if we give up on some
search tree?
Branch and Bound
• An admissible heuristic function is a
heuristic function that never overestimates
• It can be proved that if a admissible
heuristic function is used, the result is
always optimal
Examples
• Bin Packing
Divide and Conquer
• Three steps – Divide, Conquer, and Combine
– Divide: Breaks the problem into some sub-problems
– Conquer: Solve individual sub-problems
– Combine: Use solutions to sub-problems to
construct a solution to the original problem
• Question: How are sub-problems solved?
Examples (D&C)
•
•
•
•
Finding Max and Min in a list of numbers
Merge Sort
Quick Sort
L-Block
Mergesort
Maximum Consecutive Sum
• Given a sequence of numbers, find a
consecutive subsequence, such that its
total sum is largest.
Fast Exponentiation
Fast Exponentiation
Closest Pair
• Given a plane of points, find the distance
of the closest pair
Closet Pair
Appendix
• Complexity: Master Theorem