Questions 1 and 2 are logistical.
![]() |
Hash | Part-1 Part-2 Part-3 Part-4 Part 5 ---- - ------ ------ ------ ------ ---- - 367a7 | 5b456 369ff d720f cad1b 367a7 22c95 | 22c95 40328 2ee12 c0414 7b84a 369ff | 5b456 369ff d720f cad1b 367a7 535d5 | 535d5 31c55 a0f7a 76b08 46afb 5b456 | 5b456 369ff d720f cad1b 367a7 a1fbd | a1fbd 448eb 7c450 8c9d4 8667eIn your grading file, I graded the questions in the following order: BFS, DFS, Topological, MST, Min-Cut.
Here are the answers for the banks, keyed by the hash at the bottom of the quetion:
22c95 A,D,BCHE,IF,G 535d5 A,BD,IFG,CEH 5b456 A,B,DGH,F,E,IC a1fbd A,BG,DE,IF,C,HGrading: I calculated the longest prefix of your answer that is part of a legal BFS. Then I took that number and multiplied by 4/9 and rounded to the nearest 0.1. So, for example, if your hash was 22c95 and you answered ADBCHIEFG, then your longest legal prefix is ADBCH -- you needed E before I. So your answer is 20/9 = 2.2.
Visited
Call Print ABCDEFGHI
DFS(A) A X
DFS(B) B XX
DFS(H) H XX X
DFS(D) D XX X X
DFS(G) G XX X XX
DFS(E) E XX XX XX
DFS(C) C XXXXX XX
DFS(I) I XXXXX XXX
DFS(F) F XXXXXXXXX
We can stop here, since all nodes are visited. ABHDGECIF.
Grading -- Same as BFS -- longest prefix that is part of a legal DFS.
K L M N O P Q R S 1 1 0 0 0 3 3 1 1So you can start with MNO. When you remove those nodes and their edges, you get:
K L M N O P Q R S 1 1 0 0 0 1 2 0 0That gives you R and S. When you remove those nodes and their edges, you get:
K L M N O P Q R S 1 1 0 0 0 0 2 0 0So you add P. Remove that:
K L M N O P Q R S 0 1 0 0 0 0 1 0 0That gives you K. Remove that:
K L M N O P Q R S 0 0 0 0 0 0 0 0 0So that gives you Q and L. The final answer: MNORSPKQL. Obviously, there are a lot of legal answers here, so I tested your answer to see if it was legal.
Grading -- Same as BFS -- longest prefix that is part of a legal Topological Sort.
For example:
Edge Disjoint-Sets Part of MST
ABCDEFGHI
IF 1 1 Yes
HE 21 21 Yes
HI 22 22 Yes
EB 2 22 22 Yes
FC 22 22 22 Yes
GD 22222222 Yes
DE 22222222 No
DA 222222222 Yes
Done: Answer: IF,HE,HI,EB,FC,GD,DE,DA.
Grading: You get the number of edges that are part of the MST. If you gave more, then
you lost one "edge" for every extra edge. Then multiply the answer by 1/2.
Grading: The answer was the same for every part. Grading was the same as Topological Sort, with no multiplier.
![]() |
When a problem is in NP, then a given input evaluates to either "yes" or "no". To be in NP, you need to be able to verify a "yes" answer in polynomial time.
Grading: 4 points for P, and 4 for NP. You needed to mention the verification to receive full credit.
![]() |
![]() |
Next, we process [4:1]. That improves 4's distance to 36, so we set 4's distance to 36. ninc[4] is set to 1.
Next, we process [6:45]. That doesn't improve 6's distance; however it does set ninc[6] to 0, so 6 gets added to the queue.
Finally, we process [8:35]. That doesn't improve 8's distance. We set ninc[8] to 3, and we're done.
The answers are:
D:3:78 D:4:36 Q:3 Q:6Here are the four answers for each of the questions in the bank. The hash is the last line of the question:
hash | Event-1 Event-2 Event-3 Event-4 ---- - ------- ------- ------- ------- c3f81 | D:5:43 D:9:9 Q:3 Q:5 d3f7d | D:3:74 D:9:39 Q:3 Q:4 53693 | D:3:78 D:4:36 Q:3 Q:6 17cc6 | D:3:31 D:7:45 Q:2 Q:3 |
Grading: Two points per event. You got 1.5 if you got the right node for "D", but the wrong distance.
![]() |
SA with a capacity of 77. AC with a capacity of 40. CT with a capacity of 44.Thus, the flow through the path is 40. We subtract 40 from SA and CT, to leave capacities of 37 and 4 respectively. That deletes the edge AC.
We also add reverse edges with flows of 40, so we add AS and TC with capacities of 40. We add 40 to the capacity of CA, so its capacity is now 62. So the answer is:
SA:37 AC:X CT:4 AS:40 TC:40 CA:62Here are the answers for the four questions in the bank, sorted alphabetically. The hash is the last line of the question:
64715 | AC:X AS:39 CA:60 CT:5 SA:39 TC:39 66abe | AC:X AS:40 CA:62 CT:4 SA:37 TC:40 a01ef | AC:X AS:39 CA:57 CT:6 SA:38 TC:39 e9d0e | AC:X AS:36 CA:57 CT:5 SA:38 TC:36 |
Grading: 1.5 points per modification. If you got the capacity wrong, you only got 0.7 for that modification.
![]() |
double BIF::bif(int x)
{
if (x < 0) return -1;
if (x > 100) return -1;
if (x == 100 || x == 99) return 1;
return (x + A) / (x + B) * bif(x+1) * bif(x+2);
}
|
protected:
vector <double> cache;
|
Then I access it when it's set, and otherwise set it:
double BIF::bif(int x)
{
if (x < 0) return -1;
if (x > 100) return -1;
if (x == 100 || x == 99) return 1;
if (cache.size() != 99) cache.resize(99, -1);
if (cache[x] != -1) return cache[x];
cache[x] = (x + A) / (x + B) * bif(x+1) * bif(x+2);
return cache[x];
}
|
double BIF::bif(int x)
{
int i;
if (x < 0) return -1;
if (x > 100) return -1;
cache.resize(101);
cache[100] = 1;
cache[99] = 1;
for (i = 98; i >= x; i--) cache[i] = (i + A) / (i + B) * cache[i+1] * cache[i+2];
return cache[x];
}
|
double BIF::bif(int x)
{
int i;
if (x < 0) return -1;
if (x > 100) return -1;
cache.resize(2);
cache[0] = 1;
cache[1] = 1;
for (i = 98; i >= x; i--) cache[i%2] = (i + A) / (i + B) * cache[0] * cache[1];
return cache[x%2];
}
|
![]() |