# Outline of Class 14: Vectors, Continued

Held: Tuesday, February 10, 1998

## Administrivia

• 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.

## Implementing Vectors

• 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 memory.
• 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 arrays.

## Lab

Today we'll work on lab 6.

On to Vectors and Dictionaries
Back to The Vector
Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
Current position in syllabus

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Tue Jan 12 11:52:20 1999.

This page generated on Mon Jan 25 09:49:01 1999 by SiteWeaver. Validate this page.

Contact our webmaster at rebelsky@math.grin.edu