Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DATA STRUCTURES
AND
FILE STRUCTURES
Euripides G.M. Petrakis
http://www.intelligence.tuc.gr/~petrakis
Chania, 2014
E.G.M. Petrakis
Introduction
! We study data structures and we
learn how to write efficient programs
! this hasnt 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
Data Structures
! Representation of data in the memory
! file structure: representation of data on
the disk
! e.g., collection of records (list, tree, etc)
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
E.G.M. Petrakis
E.G.M. Petrakis
E.G.M. Petrakis
E.G.M. Petrakis
10
Data Type
ADT:Type +
Operations
Data Structure:
Storage Space +
functions
E.G.M. Petrakis
Data Items:
Logical Form
Data Items:
Physical Form
11
What ADT
! Depends on the application
! Different definitions for the same
application
! An ADT hides implementation details
E.G.M. Petrakis
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
E.G.M. Petrakis
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 computers
resources
! Complexity: it must be easy to implement, code
and debug
E.G.M. Petrakis
14
Tiling Problem
! The algorithm inputs a finite set T of tiles
15
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
17
Taxonomy of Algorithms
! An algorithmic
problem that
admits no algorithm
is termed noncomputable
! If it is a decision
problem it is
termed
undecidable
E.G.M. Petrakis
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
19
time
20