0% found this document useful (0 votes)
109 views20 pages

Adt PDF

This document introduces the topics of data structures and file structures that will be covered in the course. It discusses how data structures can be used to efficiently organize and store information in memory and on disk to save time and memory. The document outlines the goals of the course, which are to teach efficient data structures for memory and disk, algorithms for different tasks, and how to measure the effectiveness of algorithms and data structures. It also introduces the concepts of abstract data types and how logical data types can be implemented physically with different data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views20 pages

Adt PDF

This document introduces the topics of data structures and file structures that will be covered in the course. It discusses how data structures can be used to efficiently organize and store information in memory and on disk to save time and memory. The document outlines the goals of the course, which are to teach efficient data structures for memory and disk, algorithms for different tasks, and how to measure the effectiveness of algorithms and data structures. It also introduces the concepts of abstract data types and how logical data types can be implemented physically with different data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

TECHNICAL UNIVERSITY OF CRETE

DEPT OF ELECTRONIC AND COMPUTER ENGINEERING

DATA STRUCTURES
AND

FILE STRUCTURES

Euripides G.M. Petrakis


http://www.intelligence.tuc.gr/~petrakis
Chania, 2007

E.G.M. Petrakis Abstract Data Types (ADT) 1


Introduction
ƒ We study data structures and we
learn how to write efficient programs
ƒ this hasn’t to do with programming tricks
but rather with
ƒ good organization of information and
good algorithms that save
ƒ computer memory and running time

E.G.M. Petrakis Abstract Data Types (ADT) 2


Data Structures
ƒ Representation of data in the memory
ƒ file structure: representation of data on
the disk
ƒ e.g., collection of records (list, tree, etc)
ƒ Efficient programs require efficient
data structures
ƒ a problem has to be solved within the
given time and space constraints
E.G.M. Petrakis Abstract Data Types (ADT) 3
Problem Constraints
ƒ Each problem puts constraints on time and
space
ƒ e.g., bank example:
ƒ start account: a few minutes
ƒ transactions: a few seconds
ƒ close account: overnight
ƒ A solution is efficient if it solves the
problem within its space and time
constraints
ƒ Cost of solution: amount of resources
consumed
E.G.M. Petrakis Abstract Data Types (ADT) 4
Goals of this course
ƒ Teach data structures for main memory
and disk
ƒ Teach algorithms for different tasks and
data structures
ƒ Teach the idea of trade-offs
ƒ there are costs and benefits associated with
each data structure and each algorithm
ƒ Teach how to measure effectiveness of
each algorithm and data structure

E.G.M. Petrakis Abstract Data Types (ADT) 5


Selecting Data Structures
1. Analyze the problem to determine the
resource constraints a solution must meet
2. Determine the operations that must be
supported
• e.g., record search, insertion, deletion etc.
3. Quantify the constraints for each
operation
• e.g., search operations must be very fast
4. Select data structure that best meet
these requirements

E.G.M. Petrakis Abstract Data Types (ADT) 6


Costs & Benefits
ƒ Each data structure requires:
ƒ space for each data item it stores
ƒ time to perform each operation
ƒ programming effort to implement it
ƒ Each data structure has costs and benefits
ƒ rarely one data structure is better than
another in all situations
ƒ one may permit faster search (or insertion or
deletion) operations than another
ƒ are all operations the same important?
E.G.M. Petrakis Abstract Data Types (ADT) 7
Abstract Data Type (ADT)
ƒ ADT: definition of a data type in terms of
ƒ a set of values and
ƒ a set of operations allowed on that data type.

ƒ Each ADT operation is defined by its


inputs and outputs
ƒ ADTs hide implementation details
ƒ A data structure is the implementation of
an ADT
ƒ operations associated with the ADT are
implemented by one or more functions
E.G.M. Petrakis Abstract Data Types (ADT) 8
Logical and Physical forms
ƒ Data items have both a logical and a
physical form
1. Logical form: definition of the data
item within an ADT
ƒ e.g., integers in mathematical sense: +, -
2. Physical form: implementation of the
data item
ƒ e.g., 16 or 32 bit integers

E.G.M. Petrakis Abstract Data Types (ADT) 9


Data Type
ADT:Type +
Operations Data Items:
Logical Form

Data Structure: Data Items:


Storage Space + Physical Form
functions

E.G.M. Petrakis Abstract Data Types (ADT) 10


ADT String: Sequence of chars
• ADT function length (s: string): integer;
post condition : length = len(s);
• ADT function concat (s1,s2: string): string;
post condition: concat = s1 + s2;
ƒ ADT function substr (s: string, i, j: integer): string;
precondition: 0 < i < len(s), 0 < j < len(s) – i + 1
post condition: substr(s, i, j);
ƒ ADT function pos (s1, s2): integer;
precondition …
post condition …

E.G.M. Petrakis Abstract Data Types (ADT) 11


Definition of an ADT
ƒ Depends on the application
ƒ Different definitions for the same
application
ƒ An ADT hides implementation details
ƒ different implementations for the same ADT
ƒ When the ADT is given, its data type can
be used by the programmer
ƒ e.g., string, math libraries in C
ƒ when the implementation changes the programs
need not be changed

E.G.M. Petrakis Abstract Data Types (ADT) 12


Algorithms
ƒ The method that solves a problem
ƒ An algorithm takes the input to a problem
and transforms it to the output
ƒ a mapping of input to output
ƒ a problem can have many algorithms
ƒ A program is the implementation of an
algorithm in some programming language

E.G.M. Petrakis Abstract Data Types (ADT) 13


Properties of Algorithms
ƒ Effectiveness: the algorithm can be written as a
program
ƒ there are problems for which no algorithm
exists
ƒ Correctness: finds the correct solution for every
input
ƒ Termination: terminates after a finite number of
steps
ƒ each step requires a finite amount of time
ƒ Efficiency: makes efficient use of the computer’s
resources
ƒ Complexity: it must be easy to implement, code
and debug
E.G.M. Petrakis Abstract Data Types (ADT) 14
Tiling Problem
ƒ The algorithm inputs a finite set T of tiles
ƒ it is assumed that an unlimited number of cards
of each type is available
ƒ asks whether any finite area, of any size, can
be covered using tiles in T so that
ƒ the colors in any two touching edges are the
same
ƒ For any algorithm there can be inputs T for
which the algorithm never terminates or
finds a wrong answer
E.G.M. Petrakis Abstract Data Types (ADT) 15
Tile tile types that Tile tile types that
can tile any area cannot tile any area
From “Algorithmics”, David Harel,

E.G.M. Petrakis Abstract Data Types (ADT) 16


A Termination Problem
ƒ An algorithm must terminate with the
correct solution for any input
int OddEven( int n ) {
while ( n > 1 )
if (( n % 2 ) == 0) n = n / 2;
else n = 3n + 1;
return n;
}
ƒ No one has been able to prove that the
algorithm terminates for any positive n
although most people believe that it does!!
E.G.M. Petrakis Abstract Data Types (ADT) 17
Taxonomy of Algorithms
ƒ An algorithmic
problem that
admits no algorithm
is termed “non-
computable”
ƒ If it is a decision
problem it is
termed
“undecidable”
E.G.M. Petrakis Abstract Data Types (ADT) 18
Disk Model
ƒ T = Taccess +
Trotation + Tread
ƒ Block: unit memory
size for disk
ƒ size of data
transferred in main
memory per disk
access
ƒ In most cases
page=block=track
ƒ e.g., 1, 2, 4, 8Kbytes
E.G.M. Petrakis Abstract Data Types (ADT) 19
Disk Model (cont.)
ƒ Taccess > Trotation > Tread Î increase the amount of data which is
transferred to the main memory per disk access
ƒ large blocks, compression, data in memory
ƒ in multi-user systems, the disk head can be anywhere

time

distance coved by disk head

E.G.M. Petrakis Abstract Data Types (ADT) 20

You might also like