20Jan/090
Class Note for SC445 on Jan 20, 2009
Announcements
- Office hours posted on the course webpage: M-F
- Optional discussion section will be on Wednesdays at 7-8pm
Problem (Largest Monochromatic Rectangle)
Given an m*n boolean array A[1:m, 1:n] of zeroes and ones, find a subarray A[i:k, j:l] that contains only zeros.
Exhaustive Search (examine all possibilities; pick the best one)
function exhaustive(A, m, n) begin * returns the area of the largest solution
a := 0
for i := 1 to m do
for j := 1 to n do
for k := i to m do
for l := j to n do begin
scan A[i:k, j:l]
if it contains only zeroes then
a := max{a, (k-i+1)*(l-j+1)}
end (for)
return a
end (function)
- (a) scan - a := max{}
- (b) for l:= j to n
- (c) for k := i to m
- (d) for j := 1 to n
- (e) for i := 1 to m
Analysis
(a)

(b)

(c)

(d)

(e)
: time for exhaustive search without any optimization
Notations and Formulas
upper- and lower-bounded by constant times f(n)
upper-bounded by constant times f(n)
lower-bounded by constant times f(n)
(almost always)
Divide and Conquer
Cut the input array vertically at the middle column. Then the optimal rectangle falls into three cases:
- It lies strictly in left half. (recurse)
- It lies strictly in right half. (recurse)
- It spans the middle. (some work to do)
If we cut it at the middle column, it breaks into a left rectangle that ends at the middle column and is optimal, and a right rectangle that starts at the middle column and is optimal. (where the start and end rows i and k are fixed -> new subproblem!)