Recap and Practice, Week 3

Home | Staff and Office Hours | Lectures and Assignments | MyWPI | Policies

During week 3, you should have learned

- How to use BSTs as an implementation for ISets
- The operations and behaviors for the ADTs for Queues, Stacks, and Priority Queues
- More generally, how to use a specific data structure to implement an ADT
- How to connect the class for a data structure with an ADT in Java code
- How to create, manipulate and iterate over lists in Java's LinkedList class
- What Java's access modifiers are and how they behave
- That well designed programs encapsulate data structure decisions in separate classes from the applications that use those data structures

- Use different data structures that implement the same ADT interface
- Program with LinkedLists in Java
- Know whether a Stack, Queue, or Priority Queue is the right ADT for a particular problem
- Be able to decide which data structures (lists, sorted lists, binary trees, BSTs, and AVL trees) are good for implementing different ADTs
- Choose appropriate access modifiers for variables and methods
- Produce programs that encapsulate their data structures

**Interfaces:** I know many are still confused about
the role of interfaces, and are unsure why they are necessary.
Interfaces are a hallmark of good designs. They are not strictly
necessary (in that you can write code that produces the right answer
without them), but they are critical in practice for writing code that
can be maintained over time (what if you need to change the data
structure later), and for writing code in large teams (where
interfaces summarize what different members of the team can expect
from each others' code).

**What are ADTs?** Many are also still struggling with
what an ADT is, and how it differs from a data structure. Generally
speaking, an *ADT* describes data with particular operations and
behavior, but does not commit to a concrete implementation; as such,
one can't talk about the performance of an ADT. A *data
structure* is a concrete organization of data with concrete
implementation of methods; we can talk about the performance of
different operations on data structures.

So far, this course has covered 4-5 ADTs: sets, bags (in the notes only), queues, priority queues, and stacks. We have covered 4-5 data structures: lists, sorted lists (implicitly, assuming you saw sorting in a previous CS course), binary trees, BSTs, and AVL trees. We could ask how fast each of the data structures could perform the operations required of each ADT. If you can evaluate the performance, you have a data structure; if you know only how an operation should behave, but don't have a specific algorithm or code for it, you have an ADT.

(To those in my Friday review session: we accidentally classified stacks, queues, and priority queues as data structures on Friday afternoon. They should have been classified as ADTs.)

**Terminology for axioms, invariants, and
properties:** Invariants are about data structures: they
capture a data structure requires about data in some core shape (such
as what makes a binary tree be a BST). Axioms and properties are
about ADTs: the former captures how the operations behave and
interact; the latter is more descriptive, to help a programmer
understand characteristics of data (such as "no duplicates").