< 15-100 Spring '05 Lecture 28 (Friday, April 1, 2005) return to lecture notes index

15-100 Lecture 28 (Friday, April 21, 2005)

Mastery Exam...aka the Final

The general announcement is posted. You can go to http://www.intro.cs.cmu.edu to see what's it's all about. The sign up is online. You have up until 24hrs before the exam to go move your exam time (but please don't wait till that short notice...the spots tend to fill up since there is limited seating for each time slot). Try to bring as little with you as possible. You will be asked to leave all excess stuff at the front of the room. However, do be sure to bring your student ID and a pen or pencil (we will provide the paper) Start seating about 15 min before the exam is scheduled to start.

Format: Question 1: You are given a sample out put, a microsoft word description, and a test driver. Your program when run through the test driver should EXACTLY match the sample out put. You can get most of your information on how to implement the class by reading the test driver. After you have read the driver twice and have a good grasp of what the program should do then read the microsoft document to fill in SMALL (the word doc will not give you complete knoweledge of how to treat the question so be sure to treat it appropriatly) gaps in your knowledge that may have not been obvious from the test driver.

Questions 2-4: Deal with arrays. You are given a simple insert at end and are asked to write a filter, add, and remove method for your array . There is no penelty and no reward for good or bad coding. As long as you get the required out put (save a whole buch of println()'s) you will pass the question.

We will cover the Mastery Exam in more detail at a later date.

Exclusive or (Xor)

It is like a union except for objects in the intersection of the sets are excluded. It can exsist in one set or the other set but not both. Could do Xor By finding the union of two sets and then removing the intersection elements from it. This method is short and easy to code, but how efficent is this method? Both finding the union and the intersection of two sets are a O(N^2) operation... in the worst case we will have to scan a list N objects long for each of the N items that you insert.

Let's build off of our previous code for Set.java (it has an overloaded constructor, a copy constructor, an overloaded isMember(), an add(), an addAlways(), and a toString(), a grow(), an interesection(), and a union()):



public Set xOr (Set otherSet) {
  Set unionSet = union (otherSet);
  Set intersectionSet = intersection(otherSet);
  
  return unionSet.subtractSet(intersectionSet);
}

private subtractSet(otherSet){
  for (int otherIndex; otherIndex < otherSet.count; otherIndex++ ) 
    if(isMember(otherSet[otherIndex])) 
      remove(memberLocation);
}

public void remove(Comparable item) {
  if (!isMember(item)) {
    return;
  }
  
  remove(memberLocation);
}

//overloading remove
private void remove (int index) {
  for( ; index < count-1; index++){
    members[index] = members[index+1]
  }
  
  count--;
}

//here is a faster way of doing it...using a binary search
public Set xOrFaster(Set otherSet) {
  Set xOrSet = new Set(count);
  
  for (int index = 0; index < count; index++) {
    if (!otherSet.isMember(members[index]))
      xOrset.addAlways(members[index]);
    
    /*which does the same thing as...
     *if (xOrSet.count == xOrSet.length)
     *  xOrSet.grow();
     *
     *xOrSet.members[xOrSet.count++] = members[index];
     */
  }
  
  for (int index = 0; index < otherSet.count; index++)
    if (!isMember(otherSet[index]))
      xOrset.addAlways(members[index]);
    }
}