Download 9 Problems on Algorithm Implementation - Midterm Exam 3 | CS 1501 and more Exams Computer Science in PDF only on Docsity!
CS 1501 Spring 2006 Midterm Exam 3 Name____________________________________
- (5 Points) According to your instructor, what are the two reasons that it is quite difficult to write programs to implement geometric algorithms?
- (20 points) a) Fill in the following table for the One-Time-Pad cipher. Message Bit Secret Bit Sent Bit 0 0 0 1 1 0 1 1
b) Give an example of a well defined problem, for which there is provably no algorithm that can solve this problem. Explain the problem by stating what the input to the problem is, and what would constitute correct output. c) It is known that if any one NP-complete algorithm has a polynomial time algorithm, then every NP-complete problem has a polynomial time algorithm. To establish this fact, computer scientists had to show that if a particular problem A had an efficient (polynomial time) algorithm, then another problem B would also have an efficient (polynomial time) algorithm. Explain how you could show such a fact. HINT: What sort of program would you have to demonstrate? d) What can be said about the man that each woman gets in the standard stable marriage algorithm? That is, from the woman’s point of view, what can be said about how good the man is that she is married to?
- (10 points) Consider the following flow network. Edges are label by flow/capacity. Node s is the source and node t is the sink. State which path is next found by Ford-Fulkerson. Then draw the updated flow network below.
s
d
c
b
a
t
- (10 points) a) Give an example of a network that would take less than 1000 bytes to store, and would force the generic version of Ford-Fulkerson to run an extraordinarily long time (extraordinary in this context is at least a billion years). b) Formally prove that Ford-Fulkerson is not a polynomial time algorithm. Start with a formal definition of polynomial time algorithm.
Low value
- (15 points) Consider the following Priority First Search Code from the text. You may answer the questions below by giving an English explanation. That is, you need not provide actual code. Although you may give code, if you think that it is easier to explain this way. PQ pq(maxV); visit(int k) // PFS, adjacency lists { struct node *t; if (pq.update(k, -unseen) != 0) dad[k] = 0; while (!pq.empty()) { id++; k = pq.remove(); val[k] = -val[k]; if (val[k] == -unseen) val[k] = 0; for (t = adj[k]; t != z; t = t->next) if (val[t->v] < 0) if (pq.update(t->v, priority) ) { val[t->v] = -(priority); dad[t->v] = k; } } } a) To turn the above code into Prim’s minimum spanning tree algorithm, the value of the priority in the statement (pq.update(t->v, priority) should be set to what? b) To turn the above code into Dijkstra’s shortest path algorithm (where the length of the path is the sum of the lengths of the edges), the value of the priority in the call (pq.update(t->v, priority)should be set to what? c) To turn the above code into Dijkstra’s shortest path algorithm (where the length of the path is the maximum length of an edge on the path), the value of the priority in the call (pq.update(t->v, priority)should be set to what?
8) (10 points) Write code that will efficiently compute m
e
mod n , where m, e and n are 500 bit
integers. You may assume that you have a data type to hold 500 bit integers, and that you have operations for adding, multiplying and mod’ing such integers.
Students: Do not write on this page. Total Score: _________________________________
- __________________ (5 points)
- a) _________________ (5 points) b)_________________ (5 points) c)_________________ (5 points) d) __________________ (5 points)
- __________________ (10 points)
- __________________ (10 points)
- a) __________________ (5 points) b)__________________ (5points)
- ___________________ (5 points)
- a) _________________ (5 points) b)_________________ (5 points) c)_________________ (5 points)
- ___________________ (10 points)
- ___________________ (15 points)