Test 3 Review Sheet for Csc227 Fall 2006

Test 3 Review Sheet for Csc227 Fall 2006

<p>Final Exam Review Sheet C Sc 227 Summer 2013</p><p> 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</p><p>Topics</p><p>The Singly-Linked Structure  We will use the same private inner Node class shown on the practice final inside of class LinkedList<E extends Comparable<E>> Know how to use compareTo! o It stores these 2 things 1. The parameter E type as a reference to the data. Could match any java reference type, including Integer, Double, Character 2. A reference to another Node of the same type o It will have two constructors, so feel free to use either one (or use both). </p><p> private class Node {</p><p> private E data; private Node next;</p><p> public Node(E objectReference) { data = objectReference; next = null; }</p><p> public Node(E objectReference, Node nextReference) { data = objectReference; next = nextReference; } }</p><p> o Then you can declare Node objects like this</p><p>Node ref2 = new Node(element); // element must be of type E Node ref3 = new Node(element, ref1);</p><p> Add two methods to the same LinkedList<E> class shown on the practice final  Algorithms with linked structures might include o traverse the linked structure o find an element at a given index o find an element using compareTo o remove elements from a linked structure o insert elements into a linked structure o insert an element into a linked structure to maintain a natural ordering list.get(0) <= list.get(1) < list.get(2),..., list.get(n-2) <= list.get(n-1)  Code Demo: Make addLast(E) run O(1) with an addition</p><p>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</p><p>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<E> . Like the two on the practice final or those from OrderedSet<E>  You will not be asked to remove elements!  Code Demo: isFull() ANSWER AT END OF DOC </p><p>ArrayList<E> and HashMap<K, V> usage and TreeMap<K, V>  Topics are not in the book, see beginning of presentation JavaCollectionFrameWork.pdf  Some of the methods from interface java.util.List<E> o boolean add(E) E get(int) in size() boolean contains(E) boolean remove(E)  Some of the methods from interface java.util.Map<K V> o V put(K V) V get(K) boolean containsKey(K) o keyset() values() keys in order for TreeSet  Polymorphic methods from class Collections o sort binarySearch max min  Code Demo: setupMap for probabilistic text generation ANSWER AT END OF DOC Not on the Final Hash table implementations or collision resolution, just know 5 methods</p><p>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; } } }</p><p> 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); } }</p><p> public boolean isFull() { return isFull(root); }</p><p> 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);</p><p>} private void setMap() { allnGrams = new HashMap<String, ArrayList<Character>>(); for (int i = 0; i < theText.length() - nGram.length() - 1; i++) { String key = theText.substring(i, i + nGram.length()); if(! allnGrams.containsKey(key)) { ArrayList<Character> value = new ArrayList<Character>(); // Dolok=[h, h, h] // olokh=[o, o, o] value.add(theText.charAt(i + nGram.length())); allnGrams.put(key, value); } else { allnGrams.get(key).add(theText.charAt(i + nGram.length())); } } </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us