Test 3 Review Sheet for Csc227 Fall 2006
Total Page:16
File Type:pdf, Size:1020Kb
Final Exam Review Sheet C Sc 227 Summer 2013
Wednesday 3-July 1:00 pm to 3:50 pm in our lecture room, GS 906 o Or at the arranged time with your test proctor for students who cannot attend the final in person The final is not comprehensive, about 9 pages, 20 questions, 200pts Use the Practice Final for the scope and type of questions. o It is linked under Monday and Tuesday Announcements It is worth 20% of your final grade Closed book, closed notes, closed neighbors No calculators or other electronic devices allowed Use pencil, not pen (please) Main topics: The Singly-Linked Structure, Recursion, and Binary Trees Review session: Tuesday, 2-July 2:30-4:00 pm in 906 Gould Simpson Material: Chapters 15-19 and JavaCollectionFrameWork.pdf
Topics
The Singly-Linked Structure We will use the same private inner Node class shown on the practice final inside of class LinkedList
private class Node {
private E data; private Node next;
public Node(E objectReference) { data = objectReference; next = null; }
public Node(E objectReference, Node nextReference) { data = objectReference; next = nextReference; } }
o Then you can declare Node objects like this
Node ref2 = new Node(element); // element must be of type E Node ref3 = new Node(element, ref1);
Add two methods to the same LinkedList
Recursion Show output from recursive methods Determine return values from recursive methods Write recursive methods with integers, Strings, and arrays. Code Demo: Change two methods on CodingBat from an iterative to a recursive solution o From String-2 http://codingbat.com/prob/p109637 . Iterative and Recursive solutions are at end of this document o From Array-2 http://codingbat.com/prob/p105771 . Iterative and Recursive solutions are at end of this document
Trees Tree Terminology: root, leaf, internal node, level, parent, child Binary Trees o Tree traversals: in-, pre-, and post-order o The ordering property of Binary Search Trees o Tree algorithms in Java, both iterative and recursive o Add two methods to OrderedSet
ArrayList
Code Demo Solutions from today http://codingbat.com/prob/p109637 Iterative Recursive public String repeatSeparator(String word, public String repeatSeparator(String word, String sep, String sep, int count) { int count) { if(count == 0) if(count == 0) return ""; return ""; else { else if(count == 1) String result = ""; return word; for(int c = 1; c < count; c++ ) { else result = result + word + sep; return word + sep + repeatSeparator(word, sep, } count - 1); return result + word; } } }
http://codingbat.com/prob/p105771 Recursive Iterative public int[] evenOdd(int[] nums) { public int[] evenOdd(int[] nums) { evensLeft(nums, 0, -1); int spot = -1; return nums; for(int i = 0; i < nums.length; i++) { } if(nums[i] % 2 == 0) { spot++; private void evensLeft(int[] a, int temp = nums[spot]; int index, nums[spot] = nums[i]; int insertionSpot) { nums[i] = temp; if (index == a.length) } return; } else if (a[index] % 2 != 0) return nums; evensLeft(a, index + 1, insertionSpot); } else { // pull the even int to insertSpot insertionSpot++; int temp = a[insertionSpot]; a[insertionSpot] = a[index]; a[index] = temp; evensLeft(a, index + 1, insertionSpot); } }
public boolean isFull() { return isFull(root); }
private boolean isFull(TreeNode t) { if(t == null) return true; else if(t.left == null && t.right != null) return false; else if(t.left != null && t.right == null) return false; else return isFull(t.left) && /* AND */ isFull(t.right);
} private void setMap() { allnGrams = new HashMap