1 Three Motivating Problems
2 Sets and Their Operations

Introduction to Data Structures

Kathi Fisler

We’ve covered the fundamental parts of Java programs: classes, abstract classes, and interfaces. Classes capture new concrete kinds of data. Abstract classes share fields, methods, and helper functions that are common to classes. Interfaces define types based on required methods, but omit the details of fields and how the methods are implemented.

Today we shift a gears a bit, beginning to consider one of the other course themes: data structures. We’ll take a shrt break from new Java content in favor of some new computer science content.

1 Three Motivating Problems

Consider the following problems:

Each of these problems involves working with a bunch of strings that cannot have duplicates. This suggests that all three problems could use a similar data definition or set of classes to capture their bunch of strings. But if we look more closely, each problem is more concerned with certain operations on the bunch of strings:

There are many ways to organize a bunch of strings as data (whether as Java classes, Racket structs, or constructs in other languages). Different organizations make different operations easier or harder to perform. Today, we begin to look at several different data structures that you can use to capture a bunch of strings and the tradeoffs between them in terms of which operations they best support.

2 Sets and Their Operations

Getting more precise, we will be studying data structures for sets, collections of elements without duplicates. We’ll return to the question of duplicates a bit later.

There are many standard operations on sets. Here, we will be concerned with supporting the following operations:

We’ll start by studying several specific data structures for sets, then come back to some issues that arise when we implement them in Java.