Outline of Class 14: Vectors, Continued
Held: Tuesday, February 10, 1998
- Barry McKeown and Charlotte Abe of Towers Perrin will speak on
"What Does An Actuary Actually Do" Thursday, February 12, 4:30 p.m.
in Science 2413. Refreshments at 4:15.
- Our Convocation speaker, Prof. Doris Schattschneider, will be having
lunch with students at Grinnell House on Thursday , February 26. Please
send a note to Prof. Herman if you would like to join her for lunch.
- If we have time, we'll spend some of today on
lab 6. If not, I'd like you to
try to do the lab as a take-home exercise.
- For Wednesday, read section 13.1 of Bailey.
- Up to now, we've talked about the use of vectors and the design
of an interface for vectors.
- How does one implement vectors?
- Bailey implements his Vector class with Java's built-in arrays.
- Each Vector has an associated array which can contain at least as
many elements as are in the Vector.
- To update an element in a Vector, you simply assign to the corresponding
place in the array.
- To insert an element in a Vector, you grow the array if necessary,
shift the objects in the incorrect places, and then put it in place.
- But what would we do if we had to implement Vectors and did not have
access to arrays?
- It depends on some other assumptions.
- In particular, t is generally assumed that it takes only a
few steps to set or get the nth element of a vector.
- Later this term, we'll see other
structures (such as lists) that have behaviors similar to vectors,
but that are less efficient for setting and getting (but perhaps
more efficient for other operations).
- In order to get that efficiency, you must either already have a
class that provides such efficiency, or you must have direct access to
- Using direct access to memory, you can create an array (or Vector) of
N elements by allocating N*sizeof(element).
- Suppose the memory allocated begins at position X.
- The initial (0th) element is at position X.
- The next (1st) element is at position X+sizeof(element).
- The ith element is at _____
- In Java, the Vector class relies on the existence of the already-efficient
Today we'll work on lab 6.