CMPSCI 187: Programming With Data Structures

Practice for Third Midterm Exam

David Mix Barrington

Posted 10 November 2011

Directions:

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

Some typos fixed on 12 November 2011.

Format is similar to first midterm, 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 LinearDog<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 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) {...}}
   




Last modified 12 November 2011