$ du -sh * 170K dj_Mitzura_-_If_you_really_want_to_rock_the_funky_beats.jpg 140M dj_Mitzura_-_If_you_really_want_to_rock_the_funky_beats.mp3 74M djspooky_ghostworldmix.m4a 8.0K djspooky_ghostworldmix.txt 245M fast-flux.mp3 2.0K fast-flux.txt 109M Green_Cheese_-_Green_Cheese_Vol_39_Reality_Adjustment.mp3 4.0K Green_Cheese_-_Green_Cheese_Vol_39_Reality_Adjustment.txt 333M Kper_-_Attention_Deficit_Disorder.mp3 6.0K Kper_-_Attention_Deficit_Disorder.txt 336K Tea_Time_at_Brian_Enos_House.jpg 110M Tea_Time_at_Brian_Enos_House.mp3 4.0K Tea_Time_at_Brian_Enos_House.txt $ du -h 1.0G . $
files packed sum 0 = 0 351 = 351 350 = 350 350 = 350 351 350 = 701 351 350 = 701 350 350 = 700 351 350 350 = 1051
answer solve(p) candidates = generate-all-candidates(p) for each candidate in candidates if solution(p, candidate) return candidate return none
files file-pack(files) candidates = possible-packings(file) max = 0 solution = nil for each c in candidates if c.size < 700 and c.size > max solution = c max = c.size return solution
n 2n GHz-1 20 106 30 109 1 sec. 40 1012 16 min. 50 1015 11 days
max-sum-path(triangle) all-paths = all-paths(triangle) max-path = pick(all-paths) max-sum = path-sum(triangle, max-path) for each path in all-paths sum = path-sum(triangle, path) if sum > max-sum max-sum = sum max-path = path return [ max-sum, max-path ]
sort(a[]) candidates = generate-all-candidates(a) for each candidate in candidates if sorted(candidate) return candidate return none
|
|
route file-route(cities) candidates = possible-routes(cities) solution = pick c in candidates min = c.size for each c in candidates if c.size < min solution = c min = c.size return solution
|
|
answer solve(p) candidates = generate-all-candidates(p) for each candidate in candidates if solution(p, candidate) return candidate return none
answer solve(p) candidates = generate-all-candidates(p) best = pick a candidate for each candidate in candidates if candidate is better than best best = candidate return best
generate(problem) candidates = { } n = problem.size() for i = 0 to 2n - 1 candidates.add(select(i, problem)) return candidates
select()
makes subsets based on i
's 1 bits.
generate(problem) candidates = { } p = first-permutation(problem) do candidates.add(p) p = next-permutation(p) while p ≠ first-permutation(problem) return candidates
answer solve(p) candidates = generate-all-candidates(p) for each candidate in candidates if solution(p, candidate) return candidate return none
generate all the candidates,
store them, and
evaluate them one by one.
answer solve(p) solution = first-candidate() while candidates-left() candidate = next-candidate() if candidate better than solution solution = candidate return solution
Constant O(1) Log O(log n) Linear O(n) Log-linear O(n log n) Polynomial O(ni) Exponential O(2n) Factorial O(n!)