Data Structures

ESM 261
Fall 2007
James Frew

[single page] [slide show]

Data Structures

  Data structures are containers
  • keep related stuff together
  • tell you something about what’s inside
    • how related
  • help you get at what's inside
  Common structures
  • Tuple
  • Set
  • List
  • Array
  • Tree

Tuple

  Grouping of simple types
  • ("James Frew", 261, "W", 2007)
    • name, course#, quarter, year
  Characterization
  • names and types of attributes

Operations

  • read/write tuple
  • read/write attribute

Why a Tuple?

 

Associate multiple attributes with a single object

  • "I want to know the values of a1, a2, ..., an for every x"

Manipulate all attributes of an object as a single unit

 

Examples

  • business card
  • field measurement
  • survey response

Set

  Unordered, homogeneous aggregation
  • homogeneous: all same type
  • e.g.: set of tuples
    • {
      ("James Frew", 261, "W", 2007),
      ("Hunter Lenihan", 260, "W", 2007)
      }
  Characterization
  • number and type of elements

Operations

  • add/delete element
  • intersection/union of two sets

Why a Set?

 

Gather all related objects into a single bag

Lowest-overhead aggregation

  • no implied relationship other than same type
  Examples
  • all the business cards you collected at the last conference
  • all the measurements you collected on your last field trip
  • all the responses to your survey

List

  Ordered aggregation
  • e.g.: list of tuples
    • ("James Frew", 261, "W", 2007) →
      ("Hunter Lenihan", 260, "W", 2007)
  Characterization
  • number, type, and sequence of elements

Operations

  • prepend/append element
  • walk (go to next element)
  • read/write element

Why a List?

 

Preserve ordering between objects

  • "These otherwise unrelated things happened in this order"

Simple structure

  • reference to next element
    or
  • delimited sequence
 

Examples

  • text file

NB: list vs set

  • list: order is built-in
  • set: order may be applied by sorting on attribute values

Array

 

Ordered, addressable aggregation

  • e.g.: array of tuples
... ...
i ("James Frew", 261, "W", 2007)
i+1 ("Hunter Lenihan", 260, "W", 2007)
... ...
  Characterization
  • number of dimensions
  • interleaving of dimensions
  • domain of each dimension
  • type of element

Operations

  • read/write ith element

Why an Array?

 

Preserve dimensional relationships between objects

  • "These things happened at fixed intervals"

Easily updated

  • individual elements directly addressable
 

Examples

  • quantized field
    • digital image
    • model output

Tree

 

Hierarchical aggregation

  • root
    • leaf
    • node
      • leaf
      • leaf
      • node
        • leaf
      • leaf
    • leaf
  Characterization
  • nodes vs leaves

Operations

  • descend/ascend
  • insert/delete node/leaf
  • read/write node/leaf

Why a Tree?

 

Preserve hierarchical relationships between objects

  • nested containment
  • superset/subset
  • generalization/refinement
 

Examples

  • filesystem (directories and files)
  • XML document
  • taxonomy

What's a Reference?

Single name or address referring to arbitrarily complex thing

Reading

Wikipedia

other