tape file storage optimization
the algorithm provided in the book 4.5
is a greedy algorithm. The most important thing about greedy algorithms is to prove their correctness.
1. Prove greedy and selective.
set X = {x1, x2, X3 ,..., Xn} is an optimal solution. The length of job Xi is L [XI], and the probability of access is P [XI].
set Y = {y1, Y2, Y3 ,..., Yn} is a greedy solution. Where p [Yi]/L [Yi]> = P [Y (I + 1)]/L [Y (I + 1)].
If X and Y are identical, the greedy solution is an optimal solution.
If X and Y are different, set XI and Yi as the first different job. Set Yi to XJ in X.
X = x1, x2, X3,..., XI ,..., XJ ,..., XN
insert XJ to the front side of Xi, then x becomes
x' = x1, x2, X3 ,..., XJ, XI ,..., XN
the cost of X is E (x), and the cost of X is E (x ').
E (x')-E (x) = (P [XI] + P [x (I + 1)] +... P [x (J-1)]) * l [XJ]-(L [XI] + L [x (I + 1)] +... + L [x (J-1)]) * P [XJ] =
set xi <= XK <= x (J-1 ). According to the greedy solution of y, we can see that P [XJ]/L [XJ]> = P [XK]/L [XK], that is:
P [XJ] * l [XK]> = L [XJ] * P [XK]
E (x')-E (X) = Σ (P [XK] * l [XJ]-l [XK] * P [XJ]), xi <= XK <= x (J-1)
<= 0
therefore, x' is an optimal solution.
2. Verify the sub-structure
set X = {x1, x2, X3 ,..., Xn} is the optimal solution obtained by greedy algorithms. The optimal solution for the sub-problem after removing the last XN is subx = {x1, x2, X3 ,..., X (n-1 )}. If subx is not the optimal solution of a subproblem, assume that the optimal solution of the subproblem is y ', E (Y '0000xn) = E (y ') + (L [X1] + L [X2] +... + L [XN]) * P [XN]