CMPSCI 187: Programming With Data Structures

Practice for Second Midterm Exam

David Mix Barrington

Posted 12 October 2011


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

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");

public class Cell {
   private int x;
   private int y;
   private boolean isOpen;
   // public get and set methods, two- and three-parameter constructors

public class SCell extends Cell {
   private boolean seen;
   // public get and set methods, constructors

public class QCell extends SCell {
   private int distance;
   private QCell parent;
   // public get and set methods, constructors

In Project #2 Maze is a two-dimensional array of SCells, in Project #4 of QCells. Both versions have methods path and isPath.

Last modified 15 October 2011