L14 PPT IVSem
L14 PPT IVSem
L14 PPT IVSem
File
Structures
Sequential Files,
Indexed Sequential Files
OBJECTIVES
After reading this chapter, we should
be able to:
Understand the file access methods.
methods.
Describe the characteristics of a sequential file.
file.
Describe the characteristics of an indexed file.
file.
Describe the characteristics of a hashed file.
file.
Distinguish between a text file and a binary file
file..
File
Fil
A file is an external collection of related data
treated as a unit.
Files
Fil are stored
t d iin auxiliary/secondary
ili /
d
storage devices.
Disk
Tapes
13.1
ACCESS
METHODS
Figure 13-1
SEQUENTIAL
FILES
Figure 13-2
Sequential file
Sequential file
records can only
onl be accessed sequentially,
seq entiall
one after another, from beginning to end.
Program 13.1
13 1 Processing records in a sequential file
While Not EOF
{
Read the next record
Process the record
}
A li ti
Applications
Applications
that need to access all records from beginning to end.
Personal
information
Add transaction
D l t ttransaction
Delete
ti
Change transaction
A key is one or more fields that uniquely identify the data in the file.
Error
Report File
>
: write
it old
ld master
t fil
file record
d tto new master
t fil
file
(transaction code = A(add) )
Updating process
INDEXED
FILES
Indexed files
Inverted file
yyou can have more than one index,, each with a different key.
y
i
inverted
t d file
fil
HASHED
FILES
Mapping
pp g in a hashed file
Hashing
g methods
Direct Hashing
the keyy is the address without anyy algorithmic
g
manipulation.
p
Direct hashing
Direct Hashing
the key is the address without any algorithmic manipulation.
Direct Hashing
g
Modulo division
A new employee
p y numbering
g system
y
that will handle 1 million employees.
Digit
g Extraction Hashingg
For example :
1,3,4
6 di it employee
6-digit
l
number
b 3-digit
3 di it address
dd
125870 158
122801 128
121267 112
123413 134
Collision
Because there are many keys for each address in the file,
there is a possibility that more than one key will hash to the
same address in the file.
Synonyms the set of keys that hash to the same address
address.
Collision a hashing algorithm produces an address for an
insertion key, and that address is already occupied.
Prime area the part of the file that contains all of the home
addresses.
Home address
Collision Resolution
Figure 13-11
Figure 13-13
Bucket
a node that can accommodate more than one record.
TEXT
VERSUS
BINARY
Text files
A file of characters.
C
Cannot
t contain
t i iintegers,
t
fl
floating-point
ti
i t numbers,
b
or any other
th d
data
t
structures in their internal memory format.
Encoding system ASCII or EBCDIC
Binary files