CS 1501
Here are some sample problems for Exam 2. Note that these are by no means the only types of problems that will be on the exam, nor do they cover all of the material that will be on the exam (you should study everything since Exam 1 on the Online Syllabus). Try not to look at the solutions until after you have given each problem a good try.
________________________________________________________________________________
1)
I would like to send a message to a friend such that only the friend can read it and such that the friend knows that the message must be from me. Describe how I can do this in a fairly simple way using RSA, and how my friend will be able to read the message and know that it was from me.
________________________________________________________________________________
2)
I can represent a graph using either an adjacency list or an adjacency matrix. Explain what each is and when (if at all) each is preferable. Be SPECIFIC about when each is preferable.
________________________________________________________________________________
3)
The text uses Priority First Search (PFS) for both the MST and Shortest Path algorithms (using an adjacency list). Explain the difference between the algorithms, and why PFS can be used for both.
_________________________________________________________________________
4)
In the Karp-Edmonds algorithms for finding network flow, once an augmenting path is found, the flow values of the edges are updated to reflect the additional flow. Write the C++ or Java code segment that does this update. Assume that the graph has V vertices, that flow[x][y] represents the current flow from vertex x to vertex y, that the val[] array contains the amount that the flow will be augmented, that the dad[] array contains the path from the sink back to the source, and that V is the sink vertex.
5)
Assume you want to save time and (you hope) space with your Huffman code by using a standardized tree, rather that one tailored to each file. In this way you can incorporate the frequencies directly into your algorithm as constants, rather than having to put them in the front of your encoded file. Furthermore, you do not have to count the frequencies in each file, so you can encode in 1 pass rather than two. It seems like this is a great idea, but maybe it isn't. Explain what, if anything, may be bad about your variation.
6) Consider a file containing the following text
data:
AAABBBAAB
Trace the LZW encoding
process for the file (in the same way done in handout lzw.txt, so each
"step" produces a single codeword).
Assume that the extended ASCII set will use codewords 0-255. For each step in the encoding, be sure to
show all of the information indicated below.
Note: The ASCII value for 'A' is 65.
LONGEST
STEP # PREFIX MATCHED CODEWORD OUTPUT (STRING,
CODE) ADDED TO DICTIONARY
------ -------------- --------------- ----------------------------------
7) Write the code for BFS using an adjacency list representation of the graph. Use the partial code below as a starting point.
void
search()
{
int k;
for (k = 1; k <= V; k++) val[k] =
unseen;
for (k = 1; k <= V; k++)
if (val[k] == unseen) visit(k);
}
Queue
queue(maxV);
void
visit(int k) // BFS, adjacency lists
{
}
8)
Consider the weighted
graph below. The numbers are the edge capacities.
S is the source vertex and T is the sink vertex.
Using the Priority First
Search implementation of the Ford-Fulkerson algorithm, show EACH AUGMENTING PATH generated, the
amount of flow for each path, and the Maximum Flow for the graph.
9)
Fill in the blank
a) An RSA code can be broken in a straightforward way by __________________________________________________.
b) To be unambiguous, variable-length coding schemes (such as Huffman) should meet the _________________________.
c) The N in NP-complete stands for _____________________.
d) If an NP-complete problem can be solved in deterministic polynomial time, it means that ___________________.
e) The Ford-Fulkerson technique to finding maximum flow involves improving a previous flow value by finding a(n) _____________________________ to the flow.