Problem 1 --------- A: calculate(2043), 2,4,8,...,1024,2048 returns 2048 O(log n) +1 +1 +1 justify ---- B: (each is +1, any missing justification/bad justification is -1) O(n), any reasonable justification ok O(n^2), arjo, 1+2+...+n O(docalc(docalc(n)) must be docalc(n^2) [see student response though] so O(n^2). Anything consistent with A/B ok docalc(n^2) so O(n^4), anything consistent with A/B ok ****************************************** Problem 2 --- Part A +2 use a stack: must remove from q, add to stack, add back +2 right (must be void, must declare stack right) -- +1 for something that removes and adds -- Without a stack, can't get more than 1 (unless I'm missing something) ---- Stack s = new Stack(); while (q.size() > 0) { s.push(q.remove()); } while (s.size() > 0) { q.add(s.pop()); } ***Part B if (q.size() > 0 { } OR if (q.size() == 0) return; if (q.isEmpty()) return; +2 add the right if-statement +2 use braces correctly, get it all right, syntax not an issue ***Part C O(1) v O(n) add front/back, remove front/back +2 mention add/remove O(1) +1 mention add/remove O(n) for array +1 compare properly ****************************************** Problem 3 --------- Part A 4 points public Node makeSubList(int n) { Node first = new Node(""+n,null); Node last = first; for(int k=1; k < n; k++){ last.next = new Node(""+n,null); last = last.next; } return first; } public Node makeSubList(int n) { return helper(n,n); } public Node helper(int n, int count) { if (count == 0) return null; return new Node(""+n, helper(n,count-1)); } +2 create a new node, link via .next to it (idea) +1 first and last (or recursion?) +1 all right --- Part B 6 points public Node makeWholeList(int n) { Node first = makeSubList(1); Node last = first; for(int k=2; k <= n; k++){ while (last.next != null) { last = last.next; } last.next = makeSubList(k); } return first; } +2 call makeSubList n times, return a node +1 try to find end to link via .next (two loops and CALL) +2 correctly find end and link +1 everything right ---- Part C: Abuse of O-notation, e.g., O(n*(n+1)) is -1 over all parts Answer without justification, max +1, must be perfect O(n^2) fewer than half removed, anything reasonable O(n^2) This is a makeWholeList(n/2) O(n) root(n)^2 = O(n) O(n^2) remove a third of the elements? max? can't be less than O(n^2) really ****************************************** Problem 4: Part A: Mention resetting score or removing words, must discuss cumulative result over many games, Must call clear in super-class to remove all words from saved set and to set score to 0 as well. Part B: using the set of letters to bypass calls will result in saving time for LFAP, most of the time is in calls to findAllValidWords. Making the set is O(b*b) where b = board size, looking up a word is O(w) where w is # letters in word (assuming hash-set). This isn't much, but it's some overhead, but looking up everyword that's never found takes time at least O(b*b) per word, and usually more. Lots of words aren't found, the lexicon is huge compared to # words found on the board, that's why LFAP is slow, but bypassing the lookup should save time. Part C: Comment out list.contains and justify Part D: if find(word,index1,row,col,board,list) return true; re-use same letter in a recursive call. explain ****************************************** Problem 5: private boolean help(int row, int col) { // 2 points for all of this if (row < 0 || col < 0 || row >= myGrid.length || col >= myGrid[0].length) return false; if (myGrid[row][col] != 'x') return false; // 1 point if (col == myGrid[0].length - 1) return true; // 1 point myGrid[row][col] = '.'; // mark +2 points // +3 points for calls and using result if (help(row-1,col) || help(row+1,col) || help(row,col-1) || help(row,col+1)) return true; // myGrid[row][col] = 'x'; // unmark, can leave out return false; // + 1 points }