Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2014:journals:emily:entryeight [2014/03/26 02:02] – [Chapter 6.3] hardye | courses:cs211:winter2014:journals:emily:entryeight [2014/03/26 03:04] (current) – [Chapter 6.4] hardye | ||
|---|---|---|---|
| Line 156: | Line 156: | ||
| ====== Chapter 6.4 ====== | ====== Chapter 6.4 ====== | ||
| + | **Subset Sums and Knapsacks: Adding a Variable** | ||
| + | |||
| + | In this section we solve a problem that has duration and deadline but not have an interval by which they need to be done. The problem we are considering is a machine that processes a set of requests 1 through n where we can only use the machine from 0 to W and each job has a process time w< | ||
| + | |||
| + | **The Algorithm: | ||
| + | |||
| + | One way we could try the algorithm is to consider the first i requests but this does not work. We need more subproblems. To find opt(n) we need the value of opt(n-1) and the best solution of subset n-1 and total allowed weight W-w< | ||
| + | |||
| + | Subset-Sum(n, | ||
| + | Array M[0..n, 0..w] | ||
| + | initialize M[0,w] = 0 for each w = 0, 1,...W | ||
| + | for i = 1,2,...,n | ||
| + | for w = 0,...W | ||
| + | M[i,w] = opt(i,w) = max(opt(i-1, | ||
| + | Endfor | ||
| + | Endfor | ||
| + | Return M[n, W] | ||
| + | | ||
| + | We prove the algorithms correctness by induction. Instead of a single array, we use a matrix of subproblems to build up the values. We compute each of the values in M in constant time so the runtime is the number of entries in M which is O(nW). It is a polynomial function of n and W, not just n. This is // | ||
| + | |||
| + | This section was really interesting to me and seems like something really practical and would be used a lot. I thought like the previous section it cut out a lot of the in depth descriptions but it was a little more easy to read because I understood it better with more experience. Readability 8/10 | ||
