midsamp206-sol2

# midsamp206-sol2 - ECS 222A Algorithm Design and Analysis...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECS 222A: Algorithm Design and Analysis Handout ?? UC Davis — Charles Martel Nov. 2006 Samplel Exam Solutions 1 Dynamic Programming • (a) T (1 , , 0) = 0 T (1 ,w i ,s i ) = v i else, T (1 ,j,k ) =-∞ • (b) We can either use item i or not. If we use item i , we look in the cell already computed ( i- 1 ,j- w i ,k- s i ) in order to find the optimal solution with the weight and size left. This leads to the following forumla: T ( i,j,k ) = max [ T ( i- 1 ,j,k ) , T ( i- 1 ,j- w i ,k- s i ) + v i ] • (c) cleary, our table is of size n * W * S and we do θ (1) work at each cell. Then, overall work is θ ( nWS ) • (d) If we have the entire table around, we can simply do backtracking. We must first find the optimal solution which lay in the bottom plane, in some cell T ( n,w * ,s * ). We can find this cell by brute force in worst case time of θ ( SW ) time. Once found, we follow this method. Starting with i = n can see if T ( i,w * ,s * ) = T ( i- 1 ,w * ,s * ). If so, item i was not included. If T ( i,w * ,s * ) = T ( i- 1 ,w * - w i ,s * - s i ) + v i , then we know item i was included and we continue from cell T ( i- 1 ,w *- w i ,s *- s i ). We then repeat this procedure on whichever cell gave us our value. We stop when we reach an ( i, , 0) cell, or i = 1 so we know no more items are to be added. 2 Network Flow [10 points] Suppose you are given a maximum flow f in a network G=(V,E) with integer capacities. a) Suppose that we increase the capacity of a single edge by 1. Describe how to find a new maximum flow in O( | E | + | V | ) time. Form the new residual graph G f and look for a path from s to t in O( | E | + | V | ) time using BFS or DFS. If found, augment the flow (by one since integer capacities). The flow can go up by at most one since the min-cut increased by at most one from the change....
View Full Document

## This note was uploaded on 01/21/2010 for the course CS 210 taught by Professor Chip during the Fall '09 term at UC Davis.

### Page1 / 3

midsamp206-sol2 - ECS 222A Algorithm Design and Analysis...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online