Final Exam Part II
The due date for this quiz is Mon 20 May 2013 8:59 AM PDT -0700.
To specify an array or sequence of values in an answer, you must separate the values by a single space character (with no punctuation and with no leading or trailing whitespace). For example, if the question asks for the first ten powers of two (starting at 1), the only accepted answer is: 1 2 4 8 16 32 64 128 256 512 If you wish to discuss a particular question and answer in the forums, please post the entire question and answer, including the seed (which is used by the course staff to uniquely identify the question) and the explanation (which contains the correct answer).
In accordance with the Coursera Honor Code, I (Yinhuan Yuan) certify that the answers here are my own work.
Question 1
(seed = 388464) Which of the following statements about connectivity in an undirected graph are true? Check all that apply.
If there are two edge-disjoint paths connecting vertices u and v, then there is a simple cycle containing both u and v.
If you delete two edges from a graph G, its number of strong components can increase by at most 2.
A graph G that has a unique simple path between every pair of vertices has exactly V-1 edges.
Given a graph G and a vertex s, G is connected if and only if every vertex is connected to s.
Removing any edge from a connected graph G breaks the graph into two connected components.
Question 2
(seed = 599575) Which of the following statements about depth-first search are guaranteed to be true? Check all that apply.
If a vertex has no edges pointing from it, it will be first in any postorder
The postorder of a digraph G is the reverse of its preorder.
If there is a unique vertex reachable from every other vertex in a digraph, it will be first in some postorder.
The reverse postorder of a digraph's reverse is the same as the postorder of the digraph.
If a digraph has a vertex with no edges pointing from it, then some vertex with no edges pointing from it will be first in any postorder.
Question 3
(seed = 694838) Which of the following statements about minimum spanning trees (MSTs) are guaranteed to be true? Check all that apply.
Let G be a connected edge-weighted graph and let T be a MST of G. Then, the cheapest spanning tree of G besides T can be obtained by deleting the most expensive edge in T and computing the MST of the resulting graph.
Let G be a connected edge-weighted graph and let T be an MST of G. If you decrease the weight of some edge in T, then T will still be a MST.
Let G be a connected edge-weighted graph with distinct edge weights and no parallel edges. Then, the MST must contain the third cheapest edge.
Let T and T' be two MSTs of some edge-weighted graph and let a[] and b[] be the sorted array of edge weights. Then a[i] = b[i] for each i.
Let G be a connected edge-weighted graph with distinct edge weights and let (A, B) be a cut with at least 3 crossing edges. Then, the MST can contain the smallest and third smallest crossing edges without containing the second smallest crossing edge.
Question 4
(seed = 959653) Which of the following statements about shortest paths are true? Check all that apply.
If you run the Bellman-Ford algorithm on an edge-weighted digraph with positive edge weights and the shortest path from s to t has k edges, then Bellman-Ford will require at least k passes.
Bellman-Ford finds the shortest simple path from s to every other vertex, even if the edge weights are arbritary positive or negative integers.
Bellman-Ford finds the shortest simple path from s to every other vertex, even if the edge weights are positive or negative integers, provided there are no negative cycles.
Let G be a digraph with positive edge weights. During Bellman-Ford, if you trace back the edgeTo[] entries starting from v back to s, the path has distance equal to distTo[v].
Let G be a digraph with positive edge weights. Suppose that you increase the length of an edge by x. Then, the length of the shortest path from s to t can increase by more than x.
Question 5
(seed = 392474) Which of the following statements about maxflow and mincut are guaranteeed to be true? Check all that apply.
If all edge capacities are increased by an additive constant, then any mincut in the original network is a mincut in the modified network.
There exists a maxflow for which there is no directed cycle on which every edge carries positive flow.
Given a mincut (S, T) if the capacity of one edge is decreased by x, the value of the maxflow will decrease by exactly x.
If all edge capacities are integral, then any maxflow has integer flow on each edge.
If the capacity of some cut (S, T) equals the value of some flow f, then f is a maxflow.
Question 6
(seed = 725630)
The column on the left contains the original input of 24 strings to be sorted;
the column on the right contains the strings in sorted order; the other 7 columns contain the
contents at some intermediate step during one of the 3 radix sorting algorithms listed below.
moth lamb boar puma ibex toad bass boar bass
puma hare bass tuna boar clam boar dove boar
ibex carp carp lamb dove boar carp bass carp
boar bass clam toad kiwi gnat clam carp clam
dove ibex dove dove carp wren dove erne dove
kiwi mink erne sole erne ibex erne clam erne
carp lion gnat hare lion sole gnat hare gnat
tuna kiwi hare mole lamb mole hare gnat hare
sole clam ibex erne gnat mule ibex ibex ibex
lion slug kiwi mule loon puma kiwi loon kiwi
lamb gnat lion slug hare lamb lion lamb lamb
wren toad lamb moth clam tuna lamb lion lion
gnat boar loon kiwi bass erne loon kiwi loon
loon sole moth mink moth mink moth moth mink
hare mole mole clam mink lion mole mink mole
clam loon mink lion mole loon mink mole moth
bass moth mule wren mule hare mule mule mule
oryx dove oryx loon slug carp oryx slug oryx
slug wren puma carp oryx bass puma oryx puma
mole erne sole boar toad moth sole toad slug
toad oryx slug bass wren slug slug wren sole
erne mule tuna gnat sole dove tuna sole toad
mink puma toad ibex tuna kiwi toad tuna tuna
mule tuna wren oryx puma oryx wren puma wren
---- ---- ---- ---- ---- ---- ---- ---- ----
0 ? ? ? ? ? ? ? 4
Match up each column with the corresponding sorting algorithm from the given list:
0. Original input
1. LSD radix sort
2. MSD radix sort
3. 3-way radix quicksort (no shuffle)
4. Sorted
You may use an algorithm more than once. Your answer should be a sequence of 9 integers between
0 and 4 (starting with 0 and ending with 4) and with each integer separated by a single space.
Hint: think about algorithm invariants. Do not trace code.
Answer for Question 6
Question 7
(seed = 727971)
What is the Burrows-Wheeler inverse transform of the following?
5 B D A C D D A A
Your answer should be a sequence of 8 characters, with a single space
separating each character.
Answer for Question 7
Question 8
(seed = 955798) Which problems are known to have the same asymptotic complexity as multiplying two N-bit integers? Check all that apply.
Computing the remainder when dividing one N-bit integer into an N-bit integer.
Adding two N-bit integers.
Computing the remainder when dividing an N-bit integer by 17.
Squaring an N-bit integer.
Factoring an N-bit integer.
Question 9
(seed = 908805)
Consider the following linear programming simplex tableaux with 6 equations and 8 variables:
maximize Z
- 3 x1 + 3/4 x7 - Z = -156
---------------------------------------------------------------------------------------------------------
+ 4 x1 + 1 x5 + 1 x7 = 18
+ 1 x0 - 1 x1 - 6/5 x7 = 24
+ 3/2 x1 + 1 x4 + 3/5 x7 = 42
+ 5/4 x1 + 1 x2 + 1/2 x7 = 48
+ 2 x1 + 1 x6 - 5/2 x7 = 30
+ 5/2 x1 + 1 x3 = 48
x0 , x1 , x2 , x3 , x4 , x5 , x6 , x7 >= 0
What is the value of variable x5 in the current basic feasible solution?
Specify your answer with two digits after the decimal place.
Answer for Question 9
Question 10
(seed = 940895) A problem is intractable if and only if it cannot be solved in
linear time
constant time
exponential space
exponential time
polynomial time
Question 11
(seed = 899132) You are applying for a job at a new software technology company. Your interviewer asks you to identify which of the following tasks are known to be possible. Check all that apply.
Given an undirected graph and two vertices s and t, find a path from s to t in E + V time.
Given an undirected graph, design an E + V algorithm to find a spanning tree.
Given an undirected graph, find an edge whose removal increases the number of connected components in (E+V) E time.
Given an digraph, design an E V algorithm to find the shortest directed cycle.
Given a digraph with positive edge weights and two vertices s and t, design an E + V algorithm to find a max st-flow.
Question 12
(seed = 121999) You are applying for a job at a new software technology company. Your interviewer asks you to identify which of the following tasks are known to be possible. Check all that apply.
Given an array of N strings, sort them in time linear in N in the worst case.
Determine whether a pattern string of length M is a substring of a text string of length N using a constant amount of extra memory.
Compute the suffix array of a string of length N in time proportional to N log N in the worst case.
Determine whether an M-character regular expression matches an N-character text in time polynomial in M and N.
Construct a DFA corresponding to an M-character regular expression.
Question 1
(seed = 388464) Which of the following statements about connectivity in an undirected graph are true? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
If there are two edge-disjoint paths connecting vertices u and v, then there is a simple cycle containing both u and v. |
✘ | 0.00 | |
If you delete two edges from a graph, its number of connected components can increase by at most 2. |
✔ | 0.20 | |
A graph that has a unique simple path between every pair of vertices has exactly V-1 edges. |
✔ | 0.20 | |
Given a graph and a vertex s, the graph has one connected component if and only if every vertex is connected to s. |
✔ | 0.20 | |
Removing any edge from a connected graph breaks the graph into two connected components. |
✔ | 0.20 | |
| Total | 0.80 / 1.00 |
Question Explanation
Question 2
(seed = 599575) Which of the following statements about depth-first search in a digraph are guaranteed to be true? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
If a vertex has outdegree 0, then it will be first in any postorder. |
✘ | 0.00 | |
The postorder of a digraph is the reverse of its preorder. |
✔ | 0.20 | |
If there is a vertex reachable from every other vertex, it will be first in some postorder. |
✘ | 0.00 | |
The reverse postorder of G^R is equal to the postorder of G. |
✔ | 0.20 | |
If there is a vertex with outdegree 0, then some vertex with outdegree 0 will be first in any postorder. |
✘ | 0.00 | |
| Total | 0.40 / 1.00 |
Question Explanation
Question 3
(seed = 694838) Which of the following statements about minimum spanning trees (MSTs) are guaranteed to be true? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
Let G be a connected edge-weighted graph and let T be a MST of G. Then, the cheapest spanning tree of G besides T can be obtained by deleting the most expensive edge in T and computing the MST of the resulting graph. |
✔ | 0.20 | |
Let G be a connected edge-weighted graph and let T be an MST of G. If you decrease the weight of some edge in T, then T will still be a MST. |
✔ | 0.20 | |
Let G be a connected edge-weighted graph with distinct edge weights and no parallel edges. Then, the MST must contain the third cheapest edge. |
✔ | 0.20 | |
Let T and T' be two MSTs of some edge-weighted graph and let a[] and b[] be the sorted array of edge weights for T and T', respectively. Then a[i] = b[i] for each i. |
✔ | 0.20 | |
Let G be a connected edge-weighted graph with distinct edge weights and let (A, B) be a cut with at least 3 crossing edges. Then, the MST can contain the smallest and third smallest crossing edges without containing the second smallest crossing edge. |
✔ | 0.20 | |
| Total | 1.00 / 1.00 |
Question Explanation
Question 4
(seed = 959653) Which of the following statements about shortest paths are true? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
If you run the Bellman-Ford algorithm on an edge-weighted digraph with positive edge weights and the shortest path from s to t has k edges, then Bellman-Ford will require at least k passes. |
✘ | 0.00 | |
Bellman-Ford finds the shortest simple path from s to every other vertex, even if the edge weights are arbritary positive or negative integers. |
✔ | 0.20 | |
Bellman-Ford finds the shortest simple path from s to every other vertex, even if the edge weights are positive or negative integers, provided there are no negative cycles. |
✔ | 0.20 | |
Let G be a digraph with positive edge weights. During Bellman-Ford, if you trace back the edgeTo[] entries starting from v back to s, the path has distance equal to distTo[v]. |
✘ | 0.00 | |
Let G be a digraph with positive edge weights. Suppose that you increase the length of an edge by x. Then, the length of the shortest path from s to t can increase by more than x. |
✔ | 0.20 | |
| Total | 0.60 / 1.00 |
Question Explanation
Question 5
(seed = 392474) Which of the following statements about maxflow and mincut are guaranteeed to be true? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
If all edge capacities are increased by an additive constant, then any mincut in the original network is a mincut in the modified network. |
✘ | 0.00 | |
There exists a maxflow for which there is no directed cycle on which every edge carries positive flow. |
✘ | 0.00 | |
Given a mincut (A, B), if the capacity of one edge from A to B is decreased by x, then the value of the maxflow will decrease by exactly x. |
✘ | 0.00 | |
If all edge capacities are integral, then any maxflow has integer flow on each edge. |
✘ | 0.00 | |
If the capacity of some cut (A, B) equals the value of some flow f, then f is a maxflow. |
✘ | 0.00 | |
| Total | 0.00 / 1.00 |
Question Explanation
Question 6
(seed = 725630)
The column on the left contains the original input of 24 strings to be sorted;
the column on the right contains the strings in sorted order; the other 7 columns contain the
contents at some intermediate step during one of the 3 radix sorting algorithms listed below.
moth lamb boar puma ibex toad bass boar bass
puma hare bass tuna boar clam boar dove boar
ibex carp carp lamb dove boar carp bass carp
boar bass clam toad kiwi gnat clam carp clam
dove ibex dove dove carp wren dove erne dove
kiwi mink erne sole erne ibex erne clam erne
carp lion gnat hare lion sole gnat hare gnat
tuna kiwi hare mole lamb mole hare gnat hare
sole clam ibex erne gnat mule ibex ibex ibex
lion slug kiwi mule loon puma kiwi loon kiwi
lamb gnat lion slug hare lamb lion lamb lamb
wren toad lamb moth clam tuna lamb lion lion
gnat boar loon kiwi bass erne loon kiwi loon
loon sole moth mink moth mink moth moth mink
hare mole mole clam mink lion mole mink mole
clam loon mink lion mole loon mink mole moth
bass moth mule wren mule hare mule mule mule
oryx dove oryx loon slug carp oryx slug oryx
slug wren puma carp oryx bass puma oryx puma
mole erne sole boar toad moth sole toad slug
toad oryx slug bass wren slug slug wren sole
erne mule tuna gnat sole dove tuna sole toad
mink puma toad ibex tuna kiwi toad tuna tuna
mule tuna wren oryx puma oryx wren puma wren
---- ---- ---- ---- ---- ---- ---- ---- ----
0 ? ? ? ? ? ? ? 4
Match up each column with the corresponding sorting algorithm from the given list:
0. Original input
1. LSD radix sort
2. MSD radix sort
3. 3-way radix quicksort (no shuffle)
4. Sorted
You may use an algorithm more than once. Your answer should be a sequence of 9 integers between
0 and 4 (starting with 0 and ending with 4) and with each integer separated by a single space.
Hint: think about algorithm invariants. Do not trace code.
Answer for Question 6
You entered:
| Your Answer | Score | Explanation | |
|---|---|---|---|
| 0 3 2 1 3 3 2 3 4 | ✘ | 0.00 | |
| Total | 0.00 / 1.00 |
Question Explanation
The correct answer is:0 1 2 1 3 1 2 3 4 0: Original input 1: LSD radix sort after 3 passes 2: MSD radix sort after the first call to key-indexed counting 1: LSD radix sort after 1 pass 3: 3-way radix quicksort after the first partitioning step 1: LSD radix sort after 2 passes 2: MSD radix sort after the second call to key-indexed counting 3: 3-way radix quicksort after the second partitioning step 4: Sorted
Question 7
(seed = 727971)
What is the Burrows-Wheeler inverse transform of the following?
5 B D A C D D A A
Your answer should be a sequence of 8 characters, with a single space
separating each character.
Answer for Question 7
You entered:
| Your Answer | Score | Explanation | |
|---|---|---|---|
| ✘ | 0.00 | ||
| Total | 0.00 / 1.00 |
Question Explanation
The correct answer is:D A D C B A A D Below are the sorted cyclic suffixes and the next[] array: i suffixes[i] t next[i] ----------------------------- 0 A ? ? ? ? ? ? B 2 1 A ? ? ? ? ? ? D 6 2 A ? ? ? ? ? ? A 7 3 B ? ? ? ? ? ? C 0 4 C ? ? ? ? ? ? D 3 * 5 D ? ? ? ? ? ? D 1 6 D ? ? ? ? ? ? A 4 7 D ? ? ? ? ? ? A 5 Since first = 5, the first character is D (the first character in row 5). Since next[5] = 1, the second character is A (the first character in row 1). Since next[next[5]] = 6, the third character is D (the first character in row 6). Since next[next[next[5]]] = 4, the fourth character is C (the first character in row 4).
Question 8
(seed = 955798) Which problems are known to have the same asymptotic complexity as multiplying two N-bit integers? Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
Computing the remainder when dividing one N-bit integer into an N-bit integer. |
✔ | 0.20 | |
Adding two N-bit integers. |
✔ | 0.20 | |
Computing the remainder when dividing an N-bit integer by 17. |
✔ | 0.20 | |
Squaring an N-bit integer. |
✔ | 0.20 | |
Factoring an N-bit integer. |
✔ | 0.20 | |
| Total | 1.00 / 1.00 |
Question Explanation
Question 9
(seed = 908805)
Consider the following linear programming simplex tableaux with 6 equations and 8 variables:
maximize Z
- 3 x1 + 3/4 x7 - Z = -156
---------------------------------------------------------------------------------------------------------
+ 4 x1 + 1 x5 + 1 x7 = 18
+ 1 x0 - 1 x1 - 6/5 x7 = 24
+ 3/2 x1 + 1 x4 + 3/5 x7 = 42
+ 5/4 x1 + 1 x2 + 1/2 x7 = 48
+ 2 x1 + 1 x6 - 5/2 x7 = 30
+ 5/2 x1 + 1 x3 = 48
x0 , x1 , x2 , x3 , x4 , x5 , x6 , x7 >= 0
What is the value of variable x5 in the current basic feasible solution?
Specify your answer with two digits after the decimal place.
Answer for Question 9
You entered:
| Your Answer | Score | Explanation | |
|---|---|---|---|
| ✘ | 0.00 | ||
| Total | 0.00 / 1.00 |
Question Explanation
The basis is { x5, x0, x4, x2, x6, x3 }.
The nonbasic variables are { x1, x7 }.
The basic variable x5 appears in row 0.
Its current value equals the value of the RHS entry in that row, which is 18.
Question 10
(seed = 940895) A problem is intractable if and only if it cannot be solved in
| Your Answer | Score | Explanation | |
|---|---|---|---|
linear time |
✔ | 0.20 | |
constant time |
✔ | 0.20 | |
exponential space |
✔ | 0.20 | |
exponential time |
✔ | 0.20 | |
polynomial time |
✔ | 0.20 | |
| Total | 1.00 / 1.00 |
Question Explanation
Question 11
(seed = 899132) You are applying for a job at a new software technology company. Your interviewer asks you to identify which of the following tasks are known to be possible. Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
Given an undirected graph and two vertices s and t, find a path from s to t in E + V time. |
✘ | 0.00 | BFS or DFS |
Given an undirected graph, design an E + V algorithm to find a spanning tree. |
✘ | 0.00 | BFS or DFS. |
Given an undirected graph, find an edge whose removal increases the number of connected components in (E+V) E time. |
✘ | 0.00 | Remove each each and count number of components. Finding such a bridge edge can also be solved in E+V time using DFS. |
Given an digraph, design an E V algorithm to find the shortest directed cycle. |
✔ | 0.20 | Run BFS from each vertex s. The shortest directed cycle through s is an edge v->s, plus a shortest path from s to v. |
Given a digraph with positive edge weights and two vertices s and t, design an E + V algorithm to find a max st-flow. |
✔ | 0.20 | Best known algorithm is approximately E V. |
| Total | 0.40 / 1.00 |
Question Explanation
Question 12
(seed = 121999) You are applying for a job at a new software technology company. Your interviewer asks you to identify which of the following tasks are known to be possible. Check all that apply.
| Your Answer | Score | Explanation | |
|---|---|---|---|
Given an array of N strings, sort them in time linear in N in the worst case. |
✘ | 0.00 | The strings might be long. |
Determine whether a pattern string of length M is a substring of a text string of length N using a constant amount of extra memory. |
✔ | 0.20 | Brute-force substring search. |
Compute the suffix array of a string of length N in time proportional to N log N in the worst case. |
✔ | 0.20 | Use Manber-Myers algorithm. |
Determine whether an M-character regular expression matches an N-character text in time polynomial in M and N. |
✔ | 0.20 | Our RE-to-NFA construction algorithm + NFA simulation algorithm. |
Construct a DFA corresponding to an M-character regular expression. |
✘ | 0.00 | Kleene’s theorem implies this. |
| Total | 0.60 / 1.00 |
Question Explanation