CMPSCI 187: Programming With Data Structures

Practice for Final Exam

David Mix Barrington

Posted 7 December 2011

Directions:

  Q1: 20 points
  Q2: 15 points
  Q3: 15 points
  Q4: 15 points
  Q5: 15 points
  Q6: 20 points
  Q7: 20 points
 Total: 120 points

Format is similar to the midterms, some text explaining the question types is omitted.

Here is a code base from previous assignments, that is assumed to be available throughout the exam:

public class Dog {
   private String name;
   private int age;
   // public get and set methods, two-parameter constructor
   }

public class SledDog extends Dog {
   private String breed = "Husky";
   // public get and set methods, three-parameter constructor
   }

public class LinearNode<T> {
   private T element;
   private LinearNode<T> next;
   // public get and set methods, zero-parameter and one-parameter constructors
   }

public class DogTeam {
   private LinearNode<SledDog> leadNode;
   private int size;
   // public get and set methods, zero-parameter constructor
   public void addToLead (SledDog newLead) {…}
   public SledDog removeLead ( ) {…}
   public void switchLastTwo ( ) {…}
   public SledDog removeYoungest ( ) {…}
   public int countHuskies ( ) {…}
   }

Code run before other code fragments:

   Dog ace = new Dog ("Ace", 6);
   Dog biscuit = new Dog ("Biscuit", 1);
   Dog cardie = new Dog ("Cardie", 3);
   Dog duncan = new Dog ("Duncan", 1);
   SledDog balto = new SledDog ("Balto", 92, "Husky");
   SledDog king = new SledDog ("King", 73, "Husky");
   SledDog buck = newSledDog ("Buck", 108, "Mixed");

Some useful API information for L&C's code base:
   public interface StackADT<T> {
      public void push (T element);
      public T pop ( );
      public t peek ( );
      public boolean isEmpty( );
      public int size ( );
      public String toString( );
   public interface QueueADT<T> {
      public void enqueue (T element);
      public T dequeue ( );
      public T first ( );
      public boolean isEmpty( );
      public int size ( );
      public String toString ( );
   public interface ListADT<T> extends Iterable<T> {
      public T removeFirst( );
      public T removeLast( );
      public T remove (T element);
      public T first( );
      public T last( );
      public boolean contains (T target);
      public boolean isEmpty( );
      public int size( );
      public Iterator<T> iterator( );
      public String toString( );}
   public interface OrderedListADT<T> extends ListADT<T> {
      public void add (T element);}
   public interface UnorderedListADT<T> {
      public void addToFront (T element);
      public void addToRear (T element);
      public void addAfter (T element, T target);}
   public class SortingandSearching <T> {
      public static <T extends Comparable<? super T >> boolean
           linearSearch (T [ ] data, int min, int max, T target) {...}
      public static <T extends Comparable<? super T >> boolean
           binarySearch (T [ ] data, int min, int max, T target) {...}
      public static <T extends Comparable<? super T >> void
           selectionSort (T [ ] data) {...}
      public static <T extends Comparable<? super T >> void
           quickSort (T [ ] data, int min, int max) {...}
      public static <T extends Comparable<? super T >> void
           mergeSort (T [ ] data, int min, int max) {...}}
   public interface BinaryTreeADT<T> {
      public T getRoot ( );
      public boolean isEmpty( );
      public int size( );
      public boolean contains (T target);
      public T find (T target);
      public String toString( );
      public Iterator<T> iteratorPreOrder( );
      public Iterator<T> iteratorPostOrder( );
      public Iterator<T> iteratorInOrder( );
      public Iterator<T> iteratorLevelOrder( );}
  public interface SetADT<T> extends Iterable<T> {
      public void add (T element);
      public T removeRandom ( );
      public T remove (T element);
      public SetADT<T> union (SetADT<T> set);
      public boolean contains (T target);
      public boolean equals (SetADT<T> set);
      public boolean isEmpty ( );
      public int size ( );
      public Iterator<T> iterator( );
      public String toString ( );}




Last modified 10 December 2011