The exam featured a lot of "bank" questions -- this answer guide is for the example exam, but has information about the other banks when appropriate.
Questions 1 and 2 are "what is your username" and "if you have comments, put them here." So we start with question 3.
![]() |
On the quicksort question, I gave three points to any answer between 85 and 110. If you gave an answer between 80 and 84, you received one point, and if you answered greater than 110, you got a point.
On the DFS question, you got full credit for 64 seconds. I gave 0.5 points for values less than 10; 1 point for values between 10 and 19; 1.5 points for values between 20 and 30. 2 points for 32, and 1.5 points for 256.
![]() |
D-GB-H-IFC-JEA |
The D and H stayed where they were. G swaps with B. I swaps with F and C. J swaps with E and A. So you end with:
D-BG-H-FCI-EAJ |
There were five banks. Here are the answers for the five banks:
I-KD-P-QHE-XMC | L-PE-U-VJG-XTB | P-SH-U-WLJ-YTE | N-SD-X-YJH-ZTB | N-RC-T-ULK-ZSA I-DK-P-HEQ-MCX | L-EP-U-JGV-TBX | P-HS-U-LJW-TEY | N-DS-X-JHY-TBZ | N-CR-T-LKU-SAZ |
MFQLJ-C-W-B-RI | ZXKMH-E-IN-A-W | IMFX-C-UZ-B-LW | FQY-B-TIN-A-XO | RNMVQX-I-YZ-K BCQLJ-F-W-M-RI | AEKMH-X-IN-Z-W | BCFX-M-UZ-I-LW | ABY-Q-TIN-F-XO | IKMVQX-R-YZ-N |
WRKSI-JLMGC | WNLKQ-ICTVR | YVCGI-BXEMA | YAQHG-IJURP | XPFLW-DBHSQ IKRSW-JLMGC | KLNQW-ICTVR | CGIVY-BXEMA | AGHQY-IJURP | FLPWX-DBHSQ |
The answer is IKRSWJLMGC.
YMLCH-KVANF | ZVUEH-QXCWF | XRNGJ-LTASH | XRQDJ-NUCSI | ZPMBE-KVAQD CHLMY-AFKNV | EHUVZ-CFQWX | GJNRX-AHLST | DJQRX-CINSU | BEMPZ-ADKQV |
Here are the answers for the three pivot selections for every string:
DAEMSHFIT S DCEMRGFLS R EDJSTMKQX T GEJSUMKPX U HGITUNMPW U HLGCPQEIJ J HTEAUWBPR R ISHAVWGLQ Q JBFQVNHME J KAHQTPJLB K LSICTVHNR R MAJXYVLQG M MRLFSVINP P NAETWRLQC N QGLVWUMSJ Q |
Here are the answers for the banks:
PPSFPHPTQB | HVDTZESFAU | IIRCIEIUQB | GXCRYEHFAS | IIREIHIUJA PBPFHPSTQP | HADFEZSTVU | IBICEIRUQI | GACFEYHRXS | IAIEHIRUJI |
Here are the answers for the banks:
QXIUYMRPAW | LLPBLELRMA | LRENTGMHCP | KKNBKJKSMA | IYCMZDKGAT QAIPMYRUXW | LALBELPRML | LCEHGTMNRP | KAKBJKNSMK | IACGDZKMYT |
![]() |
- A is clearly in its own component: A - B, F and I are in the same component: A BFI - C is in that component too: A BCFI - D and E are in the same component: A BCFI DE - E gives us no new information: A BCFI DE - F and J are in the same component: A BCFIJ DE - G and L are in the same component: A BCFIJ DE GL - H and K are in the same component: A BCFIJ DE GL HK - I gives us no new information: A BCFIJ DE GL HK - J gives us no new information: A BCFIJ DE GL HK - K gives us no new information: A BCFIJ DE GL HK - L gives us no new information: A BCFIJ DE GL HKSo the answer is 5.
In your grading file, your answer was keyed off othe adjacency list for B. Here are the answers for the various banks:
Key Answer
-------- ------
0-B{F,I} 5
0-B{} 5
0-B{K,L} 4
0-B{J,K} 4
0-B{I} 4
|
Visit A: call DFS(B) A
Visit B: call DFS(A), then C, F, J B
Visit A: Already visited
Visit C: call DFS(B), then D C
Visit B: Already visited
Visit D: call DFS(C), then E, I, J D
Visit C: Already visited
Visit E: call DFS(D) E
Visit D: Already visited
Visit I: call DFS(D), then H I
Visit D: Already visited
Visit H: call DFS(I) H
Visit I: Already visited
Visit J: call DFS(B), then D and G J
Visit B: Already visited
Visit D: Already visited
Visit G: call DFS(J) G
In fact, at this point, we've visited
everything but F, so print that last F
The answer is ABCDEIHJGF.
In the grading file, I keyed your exam with the line of the adjacency matrix for node A. Here are the keys and answers:
1-A|.X........ 1-A|.XX....XX. 1-A|.......X.. 1-A|.......XX. 1-A|...X..X... abcdeihjgf abegjchifd ahbjdcfegi ahbfjigcde adgefihbjc |
ABCDEFGHIJ Q: A
Put A on the queue: Path_length: 0......... Q: A
Process A: Path_length: 01........ Q: B
Process B: Path_length: 012..2...2 Q: CFJ -- Backedge for J is BJ. Distance is 2.
Process C: Path_length: 0123.2...2 Q: FJD -- Backedge for D is CD.
Process F: Path_length: 0123.2...2 Q: JD
Process J: Path_length: 0123.23..2 Q: DG
Process D: Path_length: 0123423.42 Q: G -- We're done. Distance to I is 4.
The answers are 2, 4, BJ, CD.
In the grading file, I keyed your exam with the adjacency list for node B. Here are the keys and answers:
B{A,C,F,J} | B{H} | B{F} | B{J} | B{F,H,J}
2 | 2 | 2 | 2 | 2
4 | 4 | 4 | 4 | 4
BJ | HF | EJ | JI | HE
CD | DC | JI | GD | BF
|
Grading: Each of the three problems was worth 5 points.
![]() |
Ok -- so the first setting of each node is:
A B C D E F G H I J 0 92 47 79 110 141 97 45 99 66The nodes whose final distances are different from the above are B-89, F121, I-86 and J-62. I said I didn't care about order, so you don't need to figure out when they were changed.
In your grading, I keyed off the adjacency list for node A (yes, I gave you an adjacency matrix, but you can turn the line for A into a list):
Key A{92,79,45,99,66}
1st 4 Questions (order matters) C-47,G-97,F-141,E-110 (You can flip G and F)
2nd 4 Questions (any order) B-89,F-121,I-86,J-62
Key A{37,21,17,12,80}
1st 4 Questions (order matters) I-23,B-82,D-38,C-91 (You can flip B and D )
2nd 4 Questions (any order) B-68,C-60,J-78,J-46
Key A{24,66,85,30}
1st 4 Questions (order matters) E-75,I-68,D-47,H-62 (You can flip E and I)
2nd 4 Questions (any order) G-32,I-45,H-55,E-33
Key A{8,10,2,86,70}
1st 4 Questions (order matters) D-3,E-5,F-43,J-74 (You can flip D and E)
2nd 4 Questions (any order) I-63,I-20,J-65,H-81
Key A{48,9,84,2}
1st 4 Questions (order matters) J-78,D-31,H-46,C-51 (You can flip D and H)
2nd 4 Questions (any order) J-43,G-79,G-52,B-12
|
For grading, the first four questions were worth 8 points, as were the second four questions.
![]() |
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void dfs(int node, vector <int> &am, int &visited)
{
int i;
if (visited & (1 << node)) return;
visited |= (1 << node);
printf("%d\n", node);
for (i = 0; i < am.size(); i++) {
if (am[node] & (1 << i)) dfs(i, am, visited);
}
}
int main()
{
vector <int> am;
int f, t, i, v;
while (cin >> f >> t) {
if (f >= am.size()) am.resize(f+1, 0);
if (t >= am.size()) am.resize(t+1, 0);
am[f] |= (1 << t);
am[t] |= (1 << f);
}
for (i = 0; i < am.size(); i++) printf("AM[%d]: 0x%x\n", i, am[i]);
v = 0;
dfs(0, am, v);
return 0;
}
|
Here we test it on the following graph:
0 ----------> 1 --------> 3 | | | | | | v v 2 --> 5 ----> 4 |
UNIX> ( echo 0 1 ; echo 0 2 ; echo 1 3 ; echo 1 4 ; echo 2 5 ; echo 5 4 ) | a.out AM[0]: 0x6 AM[1]: 0x18 AM[2]: 0x20 AM[3]: 0x0 AM[4]: 0x0 AM[5]: 0x10 0 1 3 4 2 5 UNIX>Grading: This was 11 points. Typically you started with 11 points and were deducted for things like:
![]() |