Held Monday, March 13, 2000
Today we begin our in-depth investigation of data structures
by considering some of the general rules for data structure
design. We also start building a hierarchy of data structures.
- Phase 3 of the project is
due tomorrow. Are there questions? Do you want to use some
class time for discussion?
- One group has sent me a draft of the
We'll walk through parts of it together.
- Are there questions on
- I will not be grading homework 3.
- I will, however, make sure that you turned something reasonable in.
- Some notes are
- Introduction to data structures
- Four key issues: functionality, implementation, efficiency,
- Compound data types
- Iterated Collections
- Keyed Tables
- As you saw from some of the algorithms we visited last week, the
way that you organize your information can have a significant
effect on the running time of your algorithms.
- We can find the element in the middle of an array in O(1) time.
It takes O(n) time to find the element in the middle of a list.
- Hence, we often define data structures that help
us organize information.
- As you might guess, there is a close relationship between data
structures and algorithms.
- Typically, we use data structures to create efficient implementations
of the operations needed by algorithms.
- Some data structures suggest new algorithms.
- As in many other cases, we separate the implementation implementation
and specification when talking about ways to organize information.
- Abstract Data Type (ADT) is the term typically used for the
specification. For most data types, we specify the core
operations in the ADT. We will almost always use interfaces
- Data Structure is the term typically used for the
implementation. We will almost always use classes for
- But people are casual with terminology.
- Note that their are typically five issues we will consider when
we work with ADTs and data structures:
- Their overall concept: what grounds the design of
this ADT or structure;
- Their functionality: what ``methods'' the structures
provide (the ADT);
- Their implementation: how they do what they do;
- Their efficiency: how fast they are (or with how much memory
they consume); and
- Their applications: how we might use them.
- How do we build new data structures? Using other data structures,
including Java's built-in arrays.
- We'll begin by reconsidering arrays.
- What are the key operations that you might use to describe
- Don't read the next few lines until we've had a chance
to discuss them.
- We want to create new arrays
- Input: size of the array
- Input: type of the elements in the array
- We want to set elements of arrays
- We want to get elements of arrays
- We want to get the size of arrays
- What else?
- Given the wonders of inheritance, we may want to think about
the data types and structures we define in terms of a hierarchy.
- We start with one big division:
- Primitive types
- Compound types
- We then move on to a division within the compound types
- Some structures, like lists and arrays, are used to collect
an arbitrary number of values.
- Other structures, such as a Point, may collect values, but
only have a fixed number.
- Here's what we have so far:
- Most data structures are used to collect a number of objects
(just like arrays).
- Hence, most data structures we create will be variations (subinterfaces)
of a general
- What methods might such an interface include? We'll need to consider
purpose and detailed meaning (perhaps even the legendary ``6 P's''.
- Here are some basics (without detailed definitions):
- We might create collections.
- We might add elements to the collection.
- We might delete elements from the collection.
- We might check if there is room for more elements.
- We might clear all the elements in the collection.
- Are there others you can think of?
- I tend to start with very simple collections and then immediately
- Iterated Collections: Collections in which you can step
through the values, one-by-one.
- Tables: Collections in which you can look up values.