Questions are in black, answers in blue.
Q1: 10 points Q2: 10 points Q3: 15 points Q4: 15 points Q5: 20 points Q6: 30 points Total: 100 points
TRUE. This follows from Question 2 being true, because we know that the GS algorithm always gives a stable matching. To prove it directly, note that no man will propose to W unless he has been rejected by all n-1 other women. Let X be the first man to propose to W. At the time this happens, all the other women must be engaged to men they prefer to X. This can only happen if X is M, as otherwise M would have been preferred to X by some woman. So M proposes to W, she accepts and then everyone is engaged and the algorithm stops.
TRUE. If M is instead married to W' and W is married to M', then M' and W' each prefer each other to their assigned spouse, and the matching is not stable. So if M and W are not married to each other, the matching is not stable.
When we receive a job, we place it in a priority queue based on its deadline. When the machine becomes available, we remove the front job from the queue. We thus have n inserts and n extract-min operations, and the size of the queue never exceeds n. We know that with a heap, we can implement a priority queue so that the insert and extract-min operations take O(log n) time. Thus we have O(n) operations taking O(log n) time each for O(n log n) total time. There also might be O(1) overhead to handle each job, adding another O(n) which goes away when added to O(n log n).
(Recall the definition of the Θ symbol. If f and g are functions, "f = Θ(g)" means that both f = O(g) and f = Ω(g) are true. Thus "T(i) = Θ(i)" means that there are two constants c and d, with c > d > 0, such that for sufficiently large i (i greater than some i0), T(i) satisfies di2 ≤ T(i) ≤ ci2. When you show that the total time is Θ(n3), you may assume that n is sufficiently large relative to i0.)
We first show that the total time is O(n3). Since we have n jobs,
and each is O(i2) and thus O(n2), the total time is
O(n3) by the multiplication rule for big-O.
To see that the total time is &Omega(n3), note that the last
n/2 jobs each have time at least (n/2)2 which is
Ω(n2). Since n/2 is Ω(n), the total time is
Ω(n3) by the multiplication rule for big=Ω.
Carefully describe the result of a breadth-first search and a depth-first search of Kn. For each search, describe the tree and indicate where there are non-tree edges. (There are choices made during the course of each search, but it turns out that these choices do not affect the shape of either tree.)
It may help to draw the result of BFS and DFS on the graph K4 or K5 before attempting to describe the general case.
For the BFS, the algorithm looks at all the neighbors of the root node before
going to the second level. Since every node in the graph is a neighbor of every
other node, every node other than the root is put at level 1. Thus the tree
has one node at level 0 and n-1 nodes at level 1. The non-tree edges are
exactly those edges between different nodes on level 1 -- there are (n-1 choose
2) of these.
For the DFS, the search of the root node (call it 1) will find another
node 2, and then the recursive call on node 2 will find node 3, and so forth.
None of the recursive calls can terminate while any undiscovered nodes remain.
So the tree edges form a single path of n-1 edges, with one node on each level
and thus a single leaf. There are back edges, (n-1 choose 2) of them, as each
node has a back edge to each of its ancestors except its parent.
We need to place a sign in each town indicating the distance from it to Boston by the shortest route along the edges. Describe an algorithm to find this distance for each town, and give a big-O bound on this algorithm's running time in terms of n.
We carry out the Dijkstra algorithm for the single-source shortest path
problem. (You are not required to know the name of this algorithm if you
describe it in enough detail to show that you understand it.) We maintain a
set of nodes S for which we know the shortest distance. Initially S = {Boston}
and the distance from Boston to Boston is 0. We have a priority queue where
each element is a town with the best distance found so far (the length of the
shortest path that stays in S until its last edge). We repeatedly take the
front element F from the queue, add town F to S (noting its distance to Boston
for the sign), and then process the edges out of F. Processing an
edge (F,G)
means looking at the path formed by appending that edge to the path from
Boston to F and computing the total distance. If we have no entry yet in the
priority queue for G, we make one with the new distance. If there is such an
entry, we compare the distance on it with the new distance and do a change-key
operation if the new distance is smaller.
We need to carry out n extract-min operations on the queue, one for each
element, and up to m processings of edges. Each of these operations takes
O(log n) time, so our total time is O((n+m)(log n)). Note that we need to
keep a pointer into the priority queue for each town, so that we can retrieve
the queue element to do the change-key if needed. This pointer can also tell
us if the endpoint of the new edge is already in S, or not yet in the queue.
Prove that your algorithm takes no longer than any other algorithm (That is, that the route to Boston it finds is no longer than any other algorithm's route.) You should probably use mathematical induction.
Suppose we are finding the route to Boston from A. We look at all the edges (A,B), and for each we compute f(B) which is the sum of the distance s(B) from Boston to B (on B's sign) and the length of the edge from A to B. We choose the B that minimizes this sum. We let this (A,B) be the first edge on our path, recursively find the best path from B to Boston, and append this path to (A,B). We prove that this algorithm gets the optimal route by using the "greedy algorithm stays ahead" method. Consider any route from town A to Boston. For every town B on that route, we compute the sum of the distance traveled from A to B with the distance s(B) from B to Boston given on B's sign. This starts out being 0 plus s(A). It can never be smaller than this, because this sum is the length of an actual path from A to Boston and s(A) is the length of the shortest path. But the greedy algorithm maintains this sum as equal to s(A) throughout. A to Boston. This is because at every town B, the distance on the sign was set during the Prim algorithm to be the sum of the distance from B to some town C plus the distance s(C) from C to Boston. So when the greedy algorithm looks at C, it will see the chance to get the sum of the two distances to be s(B). When it finds the minimum, then, it will choose either this edge or another with the same property.
Last modified 2 October 2006