[Coursera] Stanford Algorithms: Design and Analysis, Part 1,Final exam (2014)

来源:互联网 发布:店名设计软件 编辑:程序博客网 时间:2024/05/29 15:45


Feedback — Final ExamHelp

You submitted this exam on Wed 18 Jun 2014 12:58 AM PDT. You got a score of 38.00 out of 40.00.

Question 1

Recall the Partition subroutine that we used in both QuickSort and RSelect. Suppose that the following array has just been partitioned around some pivot element: 3, 1, 2, 4, 5, 8, 7, 6, 9 

Which of these elements could have been the pivot element? (Hint: Check all that apply, there could be more than one possibility!)
Your Answer ScoreExplanation4Correct0.40All numbers to the left of it are less than it; all numbers to the right of it are bigger than it; so it could have been the pivot.3Correct0.40Because there is a "1" and "2" to the right of it, "3" could not have been the pivot.5Correct0.40All numbers to the left of it are less than it; all numbers to the right of it are bigger than it; so it could have been the pivot.2Correct0.40Because there is a "3" to the left of it, "2" could not have been the pivot.9Correct0.40All numbers to the left of it are less than it; all numbers to the right of it are bigger than it; so it could have been the pivot.Total 2.00 / 2.00 

Question 2

Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4 

Suppose we run MergeSort on this array. What is the number in the 7th position of the partially sorted array after the outermost two recursive calls have completed (i.e., just before the very last Merge step)? (When we say "7th" position, we're counting positions starting at 1; for example, the input array has a "0" in its 7th position.)
Your Answer ScoreExplanation1   2Correct2.00The array at this point of the algorithm is 1 3 5 8 9 0 2 4 6 7.3   4   Total 2.00 / 2.00 

Question 3

What is the asymptotic worst-case running time of MergeSort, as a function of the input array length n?
Your Answer ScoreExplanationθ(logn)   θ(n2)   θ(n)   θ(nlogn)Correct2.00As discussed in lecture.Total 2.00 / 2.00 

Question 4

Consider a directed graph G=(V,E) with non-negative edge lengths and two distinct vertices s and t of V. Let P denote a shortest path from s to t in G. If we add 10 to the length of every edge in the graph, then: [Check all that apply.]
Your Answer ScoreExplanationP might or might not remain a shortest stpath (depending on the graph).Correct0.50As discussed in lecture, adding a constant to every edge can change the shortest path. (But it might not, if you get lucky.)P definitely remains a shortest st path.Correct0.50As discussed in lecture, adding a constant to every edge can change the shortest path.P definitely does not remain a shortest stpath.Correct0.50If you get lucky (e.g., P has only one edge) then P might remain a shortest path.If P has only one edge, then P definitely remains a shortest st path.Correct0.50Every path P goes up in length by at least as much as P does, so Premains the shortest.Total 2.00 / 2.00 

Question 5

What is the running time of depth-first search, as a function of n and m, if the input graph G=(V,E) is represented by an adjacency matrix (i.e., NOT an adjacency list), where as usual n=|V| and m=|E| ?
Your Answer ScoreExplanationθ(nm)   θ(n+m)   θ(n2logm)   θ(n2)Correct2.00For the lower bound, in the worst case you have to look at every entry twice. For the upper bound, one easy approach is construct the adjacency list from the adjacency matrix (this is easy to do with a scan over the matrix) and then use the subroutine from the video lectures.Total 2.00 / 2.00 

Question 6

What is the asymptotic running time of the Insert and Extract-Min operations, respectively, for a heap with n objects?
Your Answer ScoreExplanationΘ(n) and Θ(1)   Θ(logn) and Θ(1)   Θ(logn) and Θ(logn)Correct2.00 Θ(1) and Θ(logn)   Total 2.00 / 2.00 

Question 7

On adding one extra edge to a directed graph G, the number of strongly connected components...?
Your Answer ScoreExplanation...might or might not remain the same (depending on the graph).Correct2.00That's correct!...cannot decrease by more than 1   ...cannot change   ...cannot decrease   Total 2.00 / 2.00 

Question 8

What is the asymptotic running time of Randomized QuickSort on arrays of length n, in expectation (over the choice of random pivots) and in the worst case, respectively?
Your Answer ScoreExplanationΘ(nlogn) [expected] and Θ(n2) [worst case]Correct2.00The expected case was shown to be O(nlogn) in lecture. In the worst case, you might repeatedly pick the minumum remaining element as the pivot.Θ(n) [expected] and Θ(nlogn) [worst case]   Θ(n2) [expected] and Θ(n2) [worst case]   Θ(nlogn) [expected] and Θ(nlogn) [worst case]   Total 2.00 / 2.00 

Question 9

Let f and g be two increasing functions, defined on the natural numbers, with f(1),g(1)1. Assume that f(n)=O(g(n)). Is 2f(n)=O(2g(n)) ? (Multiple answers may be correct, check all that apply.)
Your Answer ScoreExplanationYes if f(n)g(n) for all sufficiently large nCorrect0.50Take c=1 and n0 sufficiently large.AlwaysCorrect0.50Not if f(n)=2n and g(n)=n.NeverCorrect0.50Yes if f(n)=g(n)=n.Maybe, maybe not (depends on the functions f and g).Correct0.50For a positive example, take f(n)=g(n)=n. For a negative example, takef(n)=2n and g(n)=n.Total 2.00 / 2.00 

Question 10

Let 0<α<.5 be some constant. Consider running the Partition subroutine on an array with no duplicate elements and with the pivot element chosen uniformly at random (as in QuickSort and RSelect). What is the probability that, after partitioning, both subarrays (elements to the left of the pivot, and elements to the right of the pivot) have size at least α times that of the original array?
Your Answer ScoreExplanation22α   12αCorrect2.00That's correct!α   1α   Total 2.00 / 2.00 

Question 11

Which of the following statements hold? (As usual n and m denote the number of vertices and edges, respectively, of a graph.) [Check all that apply.]
Your Answer ScoreExplanationBreadth-first search can be used to compute shortest paths in O(m+n) time (when every edge has unit length).Correct0.50As covered in lecture.Depth-first search can be used to compute the strongly connected components of a directed graph in O(m+n) time.Correct0.50As covered in lecture.Breadth-first search can be used to compute the connected components of an undirected graph in O(m+n) time.Correct0.50As covered in lecture.Depth-first search can be used to compute a topological ordering of a directed acyclic graph in O(m+n) time.Correct0.50As covered in lecture.Total 2.00 / 2.00 

Question 12

When does a directed graph have a unique topological ordering?
Your Answer ScoreExplanationWhenever it has a unique cycle   Whenever it is a complete directed graph   None of the other options   Whenever it is directed acyclicInorrect0.00It might have many topological orderings.Total 0.00 / 2.00 

Question 13

Suppose that a randomized algorithm succeeds (e.g., correctly computes the minimum cut of a graph) with probability p (with 0<p<1). Letϵ be a small positive number (less than 1). How many independent times do you need to run the algorithm to ensure that, with probability at least 1ϵ, at least one trial succeeds?
Your Answer ScoreExplanationlog(p)logϵ   log(1p)logϵ   logϵlog(p)   logϵlog(1p)Correct2.00The failure probability after i independent trials is (1p)i. To get the correct answer, set this equal to the desired failure probability ϵ, take logarithms (the base doesn't matter) and solve for i.Total 2.00 / 2.00 

Question 14

Suppose you implement the operations Insert and Extract-Min using a sorted array (from biggest to smallest). What is the worst-case running time of Insert and Extract-Min, respectively? (Assume that you have a large enough array to accommodate the Insertions that you face.)
Your Answer ScoreExplanationΘ(n) and Θ(1)Correct2.00As in Homework #5. To keep the array sorted you need to do Θ(n) worst-case work on an Insert.Θ(n) and Θ(n)   Θ(1) and Θ(n)   Θ(logn) and Θ(1)   Total 2.00 / 2.00 

Question 15

Which of the following patterns in a computer program suggests that a heap data structure could provide a significant speed-up (check all that apply)?
Your Answer ScoreExplanationRepeated minimum computationsCorrect0.50E.g., in Dijkstra's shortest-path algorithm or in HeapSort.Repeated lookupsCorrect0.50Heaps do not generally support fast lookups (unless you happen to be looking for the minimum).Repeated maximum computationsCorrect0.50Heaps are just as useful for these as for minimum computations (e.g., just store the negative of each key, so the Extract Min winds up extracting the max).None of the other optionsCorrect0.50Useful in, e.g., in Dijkstra's shortest-path algorithm or in HeapSort.Total 2.00 / 2.00 

Question 16

Which of the following patterns in a computer program suggests that a hash table could provide a significant speed-up (check all that apply)?
Your Answer ScoreExplanationRepeated lookupsCorrect0.50The raison d'etre of a hash table.Repeated minimum computationsCorrect0.50Hash tables don't support fast queries that reference the ordering of the keys (just lookups).Repeated maximum computationsCorrect0.50Hash tables don't support fast queries that reference the ordering of the keys (just lookups).None of the other optionsCorrect0.50Hash tables are super-useful for repeated lookups.Total 2.00 / 2.00 

Question 17

Which of the following statements about Dijkstra's shortest-path algorithm are true for input graphs that might have some negative edge lengths? [Check all that apply.]
Your Answer ScoreExplanationIt may or may not correctly compute shortest-path distances (from a given source vertex to all other vertices), depending on the graph.Correct0.50 It is guaranteed to correctly compute shortest-path distances (from a given source vertex to all other vertices).Correct0.50We gave a counterexample in lecture.It is guaranteed to terminate.Correct0.50 It may or may not terminate (depending on the graph).Correct0.50 Total 2.00 / 2.00 

Question 18

Suppose you are given k sorted arrays, each with n elements, and you want to combine them into a single array of kn elements. Consider the following approach. Divide the k arrays into k/2 pairs of arrays, and use the Merge subroutine taught in the MergeSort lectures to combine each pair. Now you are left with k/2 sorted arrays, each with 2n elements. Repeat this approach until you have a single sorted array with kn elements. What is the running time of this procedure, as a function of k and n?
Your Answer ScoreExplanationθ(nlogk)   θ(nklogk)Correct2.00There are Θ(logk) iterations (you terminate once you've divided k by two enough times to get to 1), and each iteration takes Θ(nk) time.θ(nklogn)   θ(nk2)   Total 2.00 / 2.00 

Question 19

Running time of Strassen's matrix multiplication algorithm: Suppose that the running time of an algorithm is governed by the recurrence T(n)=7T(n/2)+n2. What's the overall asymptotic running time (i.e., the value of T(n))?
Your Answer ScoreExplanationθ(nlog2(7))Correct2.00That's correct!θ(n2)   θ(nlog2log7)   θ(n2logn)   Total 2.00 / 2.00 

Question 20

Recall the Master Method and its three parameters a,b,d. Which of the following is the best interpretation of bd, in the context of divide-and-conquer algorithms?
Your Answer ScoreExplanationThe rate at which the subproblem size is shrinking (per level of recursion).   The rate at which the total work is growing (per level of recursion).   The rate at which the work-per-subproblem is shrinking (per level of recursion).Correct2.00That's correct!The rate at which the number of subproblems is growing (per level of recursion).   Total 2.00 / 2.00

很可惜12题选错了,有向无环图的拓扑排序结果可能不是唯一的。当有向无环图中存在汉弥尔顿路径时,其拓扑排序才是唯一的。这道题目的答案应该是“None of the other options”。



0 0
原创粉丝点击