Beruflich Dokumente
Kultur Dokumente
4
Primitive Types as Data Types
Type Values Representation Operations
5
The Need for Data Structures
Data structures organize data
⇒ more efficient programs.
6
What is a data structure?
7
Organizing Data
Any organization for a collection of records can be searched,
processed in any order, or modified.
8
Efficiency
9
Costs and Benefits
• programming effort.
10
Example: Banking Application
11
Example: Banking Application
12
Example: Banking Application
13
Example: Banking Application
• One data structure that meets these requirements is the hash
table.
• Records are accessible by account number (called an exact-
match query)
• Hash tables allow for extremely fast exact-match search.
• Hash tables also support efficient insertion of new records.
• Deletions can also be supported efficiently (but too many
deletions lead to some degradation in performance –
requiring the hash table to be reorganized).
14
Example: City Database
• Database system for cities and towns.
• Users also find all places that match a particular value (or
range of values), such as location or population size (called a
range query).
15
Example: City Database
16
Example: City Database
• The hash table is inappropriate for implementing the city
database because:
– It cannot perform efficient range queries
17
Selecting a Data Structure
Select a data structure as follows:
19
Data Structure Philosophy
Each data structure has costs and benefits.
20
Data Structure Philosophy
Each problem has constraints on available space and time.
Bank example:
– Start account : a few minutes
– Transactions : a few seconds
– Close account : overnight
21
Abstract Data Types
22
Abstract Data Types
• A data structure is the physical implementation of an ADT.
– Each operation associated with the ADT is implemented by
one or more subroutines in the implementation.
• In a OO language such as Java, an ADT and its implementation
together make up a class.
• Data structure usually refers to an organization for data in
main memory.
• File structure: an organization for data on peripheral storage,
such as a disk drive.
23
Labeling collections of objects
Humans deal with complexity by assigning a label to an
assembly of objects. An ADT manages complexity through
abstraction.
– Hierarchies of labels
Example : transistors ⇒ gates ⇒ CPU.
24
Logical vs. Physical Form
Data items have both a logical and a physical form.
Logical form: definition of the data item within an ADT.
– Ex: Integers in mathematical sense: +, -
Physical form: implementation of the data item within a data
structure.
– Ex: 16/32 bit integers, overflow.
25
Data Type
ADT:
Type Data Items:
Operations Logical Form