GRADING INFORMATION FOR WRITTEN ASSIGNMENT ZERO ----------------------------------------------- Grading breakdown ================= Average 0: 21 a: 7 4.25 b: 7 3.42 c: 7 3.31 1: 15 a: 5 3.65 b: 5 2.32 c: 5 3.56 2: 8 a: 4 2.31 b: 4 3.08 3: 44 a: 2 1.14 b: 4 3.17 c: 4 2.85 d: 4 2.86 e: 4 2.97 f: 4 2.56 g: 4 2.76 h: 4 2.34 i: 4 2.66 j: 4 1.76 k: 2 0.92 l: 4 1.61 4: 12 b: 4 2.92 c: 4 3.41 d: 4 3.44 ____ 63.27 CLASS AVERAGE General comments ================ If you had a correct answer that wasn't quite phrased as expected, no points were deducted, but what was expected was noted. For example, if a question asked you to express the running time of an algorithm in terms of O-notation, and the algorithm was a linear time algorithm, the expected answer is O(n). If you wrote O(n-1), usually a note like "=O(n)" was penned in by the grader, but no points were taken off. (The idea being that for O-notation, usually the simplest expression is written.) The following is a rough guideline to how Written Assignment Zero was graded. Occasionally the grader strayed from these guidelines for exceptional cases. If you did not receive full credit on a given question and there is no specific explanation on your assignment then the key below should indicate why points were deducted. If for some reason you still do not understand why you received the grade you did, please see the TA. Note that in most cases where the question asks for the running time of an algorithm in terms of O-notation, the expected answer was to be "precise" (also known as "tight") meaning as small (and yet simple) an O-expression as possible. For example, if the running time of an algorithm is 4n+3, the expected answer is O(n). It is correct to write O(n^2), just imprecise. Specific criteria ================= O-notation: 21 points ---------- a) Let f(n) = 2n^3 + 47 and g(n) = (n-1)^4. Find constants k,N that demonstrate that f=O(g). 7 points 3 points for any correct k, N. 4 points for explaining why: 2 points for showing that the inequality is satisfied for those values. 2 points for arguing, graphically or otherwise that for all n>N the inequality will still hold. b) Prove or disprove: If f=O(g) and g=O(h) then f=O(h). 7 points If reasoning is unclear -1; very unclear -2. Full credit mentions k2 >= k0 * k1 and N2 >= max(N2,N1) (and, of course, the proof is correct). c) Explain why the statement, ``The running time of the algorithm A is at least O(n^2),'' is content-free. 7 points Full credit for explaining that O-Notation is used for upper bounds and to say that something has an upper bound that is at least is meaningless. Similar arguments about "at least no worse than" is meaningless, etc. also accepted as long as they are clearly stated. Partial credit for correct statements that didn't hit the point. Fibonacci numbers: 15 points ----------------- a) What is the run-time complexity of the iterative version of the Fibonacci function fibIter in terms of O-notation? 5 points 1 points for a correct, imprecise answer (such as O(n^2)). 3 points for a correct precise answer (O(n)). 2 points for a correct explanation. b) What is the run-time complexity of the recursive version of the Fibonacci function fib in terms of O-notation? 5 points 2 points for a correct answer, imprecise or precise (including O(fib) as correct - that is realizing that the function grows as fib #s themselves). 3 points for explaining why it is an answer. Partial credit possible if explanation on the right track. c) Comment (briefly) on the relative advantages of the two different implementations of the Fibonacci functions. 5 points 2 points for noting that fib-iter is more efficient. 1 more point for noting that fib-iter is MUCH MORE efficient. 2 points for at least one valid arguments as to why fibrec might be preferred - most notably it is more compact and more intuitive. The Towers of Hanoi: 8 points ------------------- a) In terms of O-notation and n (the number of discs Towers of Hanoi is played with), what is the run-time complexity of the above move function? 4 points 1 point for a correct imprecise answer. 2 points for correct precise answer. 2 points for explanation - 1 point if part way there. b) What does this say about how long it would take a person to play an 100-disc version of the game? 4 points 4 points for stating roughly that it would take a very, very long time even on the fastest of computers. Partial credit for stating a precise number (plugged into big O, but without any or much explanation to its significance). Partial credit for stating it would take a long time, but not stressing the magnitude of how long. (Comments like "it would take forever" are okay for partial credit.) Bags vs. Lists & Arrays vs. Linked Lists: 44 points ---------------------------------------- a) In terms of O-notation, what is the worst-case run-time complexity of Bag::insert? 2 points 1 for correct precise answer. 1 for correct explanation. b) In terms of O-notation, what is the worst-case run-time complexity of List::insert, where the class List is implemented with arrays? 4 points 1 point for a correct imprecise answer. 3 points for correct precise answer. 1 point for explanation. c) In terms of O-notation, what is the worst-case run-time complexity of List::insert, where the class List is implemented with linked lists? 4 points 1 point for a correct imprecise answer. 3 points for correct precise answer. 1 point for explanation. d) Write pseudocode for an equality operator for the class List implemented with arrays. 4 points 4 points for correct answer - C++ code okay (need not be syntactically correct) as long as it's reasonable to follow (if not, then 1-2 points off if still correct) and that it makes use of arrays. Partial credit (3 pts) for being right, but imprecise. Partial credit (1-2 pts) for being on the right track. e) In terms of O-notation, what is the worst-case run-time complexity of the equality operator for the class List, implemented with arrays? 4 points 1 point for a correct imprecise answer. 3 points for correct precise answer. 1 point for explanation. f) Write pseudocode for an equality operator for the class List implemented with linked lists. 4 points - same as d) above, except that it makes use of linked lists. g) In terms of O-notation, what is the worst-case run-time complexity of the equality operator for the class List, implemented with linked lists? 4 points - same as e) above. h) Compare the efficiency of the equality operator for the two list implementations as well as for the class Bag (discussed in class and as part of Programming Assignment Zero). 4 points 2 points for stating that both list == ops take roughly the same time. 2 points for stating that bag's == op is slower. Partial credit possible, especially for noting that array operations may be faster than pointer operations so array list == might be slightly faster than linked-list ==. i) What is the run-time complexity of this algorithm, in terms of O-notation? 4 points - same as e) above. j) Write pseudocode for a selection sort member function for the List class implemented with linked lists rather than arrays. 4 points - same as f) above. k) Which of these two sort implementations is more efficient? 2 points 2 points for stating that they are roughly equivalent in terms of efficiency. 1 point for arguing that array reps is faster than pointer dereferencing. 1 point for simply presenting linked-list representation running time. l) Briefly discuss the relative merits of the two implementations of the class List discussed in class in terms of run-time efficiency. 4 points 4 points for saying that linked-lists are faster for some ops (insert, etc.) and that they are equivalent for others. Partial credit for saying some of this. 1 point if missed the mark and thought the question referred to the difference between singly- and doubly-linked lists. 1 point for arguing that array rep is better because of inefficiency of pointer dereferencing. Dynamic Arrays -------------- 12 points b) What is the complexity (in terms of O-notation) of Bag::resize? 4 points 1 point for a correct imprecise answer. 3 points for correct precise answer. 1 point for explanation. c) Is such resizing needed for a linked-list representation of a container class? Why or why not? 4 points 2 points for stating NO. 2 points for correctly backing this up. Partial credit for poor explanation, or for reasonable attempt to explain why YES might be needed (that is if a student is confused about what's going on, says YES resizing might be needed, but then makes a reasonable explanation why, then 1-2 points might be awarded). d) Which representation makes more sense if the size of the container class is likely to change frequently? Explain. 4 points 2 points for stating that linked-list is preferable. 2 points for explaining why. Partial credit for poor explanation, or for reasonable attempt to explain why arrays might be better (the latter is very unlikely).