BRUTE_FORCE(bar) // bar is mxn // BREAKR(bar, row) breaks the bar along the given row. // BREAKC(bar, col) breaks the bar along the given column
- for i ← 1 to m-1 do
- (bari,n,bar BREAKR(bar,1)
- for i ← 1 to m do
- for j ← 1 to n-1 do
- (chunk, bari,n) = BREAKC(bari,n,1)
T(m,n) = Σ1m-11 + Σ1m Σ 1n-1 1 = m-1 -1+1 + Σ1m n-1-1+1 = m-1 + (n-1)Σ1m 1 = m-1 + (n-1)(m-1+1) = m-1 +mn -m = mn - 1 ∈ Θ(mn)
QUICK_BREAK(bar)
- if m =1 and n = 1 then
- return
- elseif m ≥ n then
- (a,b) = BREAKR(m/2,n)
- QUICK_BREAK(a);
- QUICK_BREAK(b);
- return
- else
- (a,b) = BREAKC(m,n/2)
- QUICK_BREAK(a);
- QUICK_BREAK(b);
- return
| 1 n = 0 and m = 1 (We are counting breaks, none needed here) T(m,n) = | 2T(m/2,n) +1 m ≥ n | 2T(m,n/2) + 1 otherwise WLOG assume m=2a and n = 2b Also assume the bar is roughly square, but this really doesn't matter. T(m,n) = 2T(m/2),n) + 1, T(m/2,n) = 2T(m/2,n/2)+1 or 2T(m/22,n)+1 Since we assumed the bar is roughly square T(m,n) = 2[2T(m/2,n/2) + 1] + 1 = 22T(m/2,n/2)+21 + 20 T(m/2,n/2) = 2T(m/22,n/2)+1 or 2T(m/2,n/s2)+1 T(m,n) = 22[2T(m/22,n/2) + 1] + Σ012i = 23T(m/22,n/2) Σ022i at step k, k = c+d T(m,n) = 2kT(m/2c,n/2d) + Σ0k-1 2i = 2kT(m/2c,n/2d) + 2k-1 when c = a and d = b T(m,n) = 2a+bT(1,1) + 2a+b-1 = 2a+b*0 + 2a+b-1 = 2a2b-1 = mn-1 ∈ O(mn)
F(m,n) = 0 if m=1 and n=1 min(min row breaks, min col breaks) + 1 min row breaks = min1⌊m/2⌋ (F(i,n)+F(m-i,n)) min col breaks = min1⌊n/2⌋ (F(m,i)+F(m,n-i))
+ | F(3,1) + F(3,3) |
+ | F(3,2) + F(3,2) |
F n 1 2 3 4 m 1 0 F(1,2) = F(1,1) + F(1,1) + 1 = 1 2 F(2,1) = F(1,1) + F(1,1) + 1 = 1 3 4 5 F n 1 2 3 4 F(1,3) = F(1,1) + F(1,2) + 1 = 0 + 1 + 1 = 2 m 1 0 1 F(3,1) = F(1,1) + F(2,1) + 1 = 0 + 1 + 1 = 2 2 1 F(2,2) = min[ F(2,1)+F(2,1), F(1,2)+F(1,2)] + 1 3 = mim(2+2, 2+2) + 1 = 3 4 5 F n 1 2 3 4 F(1,4) = min(F(1,1)+F(1,3),F(1,2)+F(1,2)]+1 m 1 0 1 2 = min(0+2,1+1) + 1 = 3 2 1 3 Same for F(4,1) 3 2 F(3,2) = F(1,2)+F(2,2)+1 = 1+3+1 = 5 4 F(2,3) = F(2,1)+F(2,2) + 1 = 5 5 F n 1 2 3 4 m 1 0 1 2 3 2 1 3 5 3 2 5 4 3 5 F n 1 2 3 4 m 1 0 1 2 3 2 1 3 5 4 3 2 5 8 9 4 3 8 11 14 5 4 9 14 19