Q1: A: 28 = 7*8/2 B: right: 100(101)/2 = 5050, left: 5050-99 = 4951 C: Middle row has roughly N/2 which is O(N) D: 1+2+...+N^2 = O(N^4) E: 1+2+...+2N = 2N(2N+1)/2 = O(N^2) F: return 4*n; G: Bottom row has roughly half the rectangles which is O(N) H: # rows is log_2(N) roughly which we write as O(log N) public int rowNum(int rec){ double log = Math.log10(rec)/Math.log10(2); // base 2 log of rec return ((int) Math.floor(log)) + 1; } This is O(1), we could also write a loop to divide by 2 and count how many times we do that. That would be O(log N) Q2: public String occursMost(String[] list){ HashMap map = new HashMap(); int max = 0; String maxStr = null; for(String s : list){ if (! map.containsKey(s)){ map.put(s,0); } map.put(s,map.get(s)+1); // increment count properly if (map.get(s) > max){ max = map.get(s); maxStr = s; } } return maxStr; } B: public String oldestAncestor(String[] families, String child){ Map map = new HashMap(); for(String s : families){ String[] pc = s.split(" "); map.put(pc[1],pc[0]); } if (! map.containsKey(child)) return ""; while (map.containsKey(child)){ child = map.get(child); } return child; } Q3: A: path top to bottom has N grid-cells, this is O(N) B: Shade all but last row, or checkerboard. Both are O(N^2) and have no path, so it is possible C: O(N), visits N diagonal cells once D: public boolean pathFound(){ myVisited = new boolean[myRows][myCols]; for(int c=0; c < myCols; c++){ if (pathToBottom(0,c)) return true; } return false; } E: public boolean addOne(){ for(int r=0; r < myRows; r++){ for(int c=0; c < myCols; c++){ if (!myGrid[r][c]){ // not on, try it and see myGrid[r][c] = true; if (pathFound()){ myGrid[r][c] = false; return true; } myGrid[r][c] = false; } } } return false; } Q4: A: public Node twin(Node list){ if (list == null) return null; if (list.next == null){ return new Node(list.info,list); } list.next = twin(list.next); return new Node(list.info,list); } public Node twin(Node list){ Node first = list; while (list != null){ list.next = new Node(list.info,list.next); list = list.next.next; } return first; } B: public Node removeOther(Node list){ Node first = list; while (list != null && list.next != null){ list.next = list.next.next; list = list.next; } return first; }