SlideShare a Scribd company logo
1 of 32
13.1
1313
FileFile
StructuresStructures
Foundations of Computer Science © Cengage
Learning
13.2
 Define two categories of access methods: sequential access and random
access.
 Understand the structure of sequential files and how they are updated.
 Understand the structure of indexed files and the relation between the index
and the data file.
 Understand the idea behind hashed files and describe some hashing methods.
 Describe address collisions and how they can be resolved.
 Define directories and how they can be used to organize files.
 Distinguish between text and binary files.
ObjectivesObjectives
After studying this chapter, the student should be able to:After studying this chapter, the student should be able to:
13.3
13-1 ACCESS METHODS13-1 ACCESS METHODS
When we design a file, the important issue is how weWhen we design a file, the important issue is how we
will retrieve information (a specific record) from thewill retrieve information (a specific record) from the
file. Sometimes we need to process records one afterfile. Sometimes we need to process records one after
another, whereas sometimes we need to access aanother, whereas sometimes we need to access a
specific record quickly without retrieving the precedingspecific record quickly without retrieving the preceding
records. The access method determines how records canrecords. The access method determines how records can
be retrieved:be retrieved: sequentiallysequentially oror randomlyrandomly..
13.4
Sequential access
If we need to access a file sequentially—that is, one record
after another, from beginning to end—we use a sequential
file structure.
Random access
If we need to access a specific record without having to
retrieve all records before it, we use a file structure that
allows random access. Two file structures allow this:
indexed files and hashed files. This taxonomy of file
structures is shown in Figure 13.1.
13.5
Figure 13.1 A taxonomy of file structures
13.6
13-2 SEQUENTIAL FILES13-2 SEQUENTIAL FILES
A sequential file is one in which records can only beA sequential file is one in which records can only be
accessed one after another from beginning to end.accessed one after another from beginning to end.
Figure 13.2 shows the layout of a sequential file.Figure 13.2 shows the layout of a sequential file.
Records are stored one after another in auxiliaryRecords are stored one after another in auxiliary
storage, such as tape or disk, and there is an EOF (end-storage, such as tape or disk, and there is an EOF (end-
of-file) marker after the last record. The operatingof-file) marker after the last record. The operating
system has no information about the record addresses, itsystem has no information about the record addresses, it
only knows where the whole file is stored. The onlyonly knows where the whole file is stored. The only
thing known to the operating system is that the recordsthing known to the operating system is that the records
are sequential.are sequential.
13.7
Figure 13.2 A sequential file
13.8
Algorithm 13.1 shows how records in a sequential fileAlgorithm 13.1 shows how records in a sequential file
are processed.are processed.
13.9
Updating sequential files
Sequential files must be updated periodically to reflect
changes in information. The updating process is very
involved because all the records need to be checked and
updated (if necessary) sequentially.
Files involved in updating
There are four files associated with an update program: the
new master file, the old master file, the transaction file
and the error report file. All these files are sorted based on
key values. Figure 13.3 is a pictorial representation of a
sequential file update.
13.10
Figure 13.3 Updating a sequential file
13.11
Processing file updates
To make the updating process efficient, all files are sorted on
the same key. This updating process is shown in Figure 13.4.
Figure 13.4 Updating process
13.12
13-2 INDEXED FILES13-2 INDEXED FILES
To access a record in a file randomly, we need to knowTo access a record in a file randomly, we need to know
the address of the record.the address of the record.
Figure 13.5 Mapping in an indexed file
13.13
Figure 13.6 Logical view of an indexed file
13.14
Inverted files
One of the advantages of indexed files is that we can have
more than one index, each with a different key. For example,
an employee file can be retrieved based on either social
security number or last name. This type of indexed file is
usually called an inverted file.
13.15
12-2 HASHED FILES12-2 HASHED FILES
AA hashed filehashed file uses a mathematical function touses a mathematical function to
accomplish this mapping. The user gives the key, theaccomplish this mapping. The user gives the key, the
function maps the key to the address and passes it to thefunction maps the key to the address and passes it to the
operating system, and the record is retrieved (Figureoperating system, and the record is retrieved (Figure
13.7).13.7).
Figure 13.7 Mapping in a hashed file
13.16
Hashing methods
For key-address mapping, we can select one of several
hashing methods. We discuss a few of them here.
Direct hashing
In direct hashing, the key is the data file address without any
algorithmic manipulation. The file must therefore contain a
record for every possible key. Although situations suitable
for direct hashing are limited, it can be very powerful,
because it guarantees that there are no synonyms or
collisions (discussed later in this chapter), as with other
methods.
13.17
Figure 13.8 Direct hashing
13.18
Modulo division hashing
Also known as division remainder hashing, the modulo
division method divides the key by the file size and uses the
remainder plus 1 for the address. This gives the simple
hashing algorithm that follows, where list_size is the number
of elements in the file. The reason for adding a 1 to the mod
operation result is that our list starts with 1 instead of 0.
13.19 Figure 13.9 Modulo division
13.20
Digit extraction hashing
Using digit extraction hashing, selected digits are extracted
from the key and used as the address. For example, using our
six-digit employee number to hash to a three-digit address
(000–999), we could select the first, third and fourth digits
(from the left) and use them as the address. Using the keys
from Figure 13.9, we hash them to the following addresses:
Other hashing methods
Other popular methods exist, but we leave the exploration of
these as exercises.
13.21
Collision
Generally, the population of keys for a hashed list is greater
than the number of records in the data file. For example, if
we have a file of 50 students for a class in which the students
are identified by the last four digits of their social security
number, then there are 200 possible keys for each element in
the file (10,000/50). 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. We call the set
of keys that hash to the same address in our list synonyms.
The collision concept is illustrated in Figure 13.10.
13.22 Figure 13.10 Collision
13.23
Collision resolution
With the exception of the direct method, none of the methods
we have discussed for hashing creates one-to-one mappings.
This means that when we hash a new key to an address, we
may create a collision. There are several methods for
handling collisions, each of them independent of the hashing
algorithm. That is, any hashing method can be used with any
collision resolution method. In this section, we discuss some
of these methods.
13.24 Figure 13.11 Open addressing resolution
13.25 Figure 13.12 Linked list resolution
13.26 Figure 13.13 Bucket hashing resolution
13.27
13-5 DIRECTORIES13-5 DIRECTORIES
Directories are provided by most operating systems forDirectories are provided by most operating systems for
organizing files. Aorganizing files. A directorydirectory performs the sameperforms the same
function as a folder in a filing cabinet. However, afunction as a folder in a filing cabinet. However, a
directory in most operating systems is represented as adirectory in most operating systems is represented as a
special type of file that holds information about otherspecial type of file that holds information about other
files. A directory not only serves as a kind of index thatfiles. A directory not only serves as a kind of index that
tells the operating system where files are located on antells the operating system where files are located on an
auxiliary storage device, but can also contain otherauxiliary storage device, but can also contain other
information about the files it contains, such as who hasinformation about the files it contains, such as who has
the access to each file, or the date when each file wasthe access to each file, or the date when each file was
created, accessed or modified.created, accessed or modified.
13.28
Directories in the UNIX operating system
In UNIX, the directory system is organized as shown in
Figure 13.14.
Figure 13.14 An example of the directory system in UNIX
13.29
Special directories
There are four special types of directory that play an
important role in the directory structure in UNIX: the root
directory, home directories, working directories and
parent directories.
Paths and pathnames
The file’s path is specified by its absolute pathname, a list
of all directories separated by a slash character (/). UNIX
also provides a shorter pathname, known as a relative
pathname, which is the path relative to the working
directory.
13.30
13-6 TEXT VERSUS BINARY13-6 TEXT VERSUS BINARY
Two terms used to categorize files:Two terms used to categorize files: text filestext files andand binarybinary
filesfiles. A file stored on a storage device is a sequence of. A file stored on a storage device is a sequence of
bits that can be interpreted by an application program asbits that can be interpreted by an application program as
a text file or a binary file, as shown in Figure 13.15.a text file or a binary file, as shown in Figure 13.15.
Figure 13.15 Text and binary interpretations of a file
13.31
Text files
A text file is a file of characters. It cannot contain integers,
floating-point numbers, or any other data structures in their
internal memory format. To store these data types, they must
be converted to their character equivalent formats. Some
files can only use character data types. Most notable are file
streams (input/output objects in some object-oriented
language like C++) for keyboards, monitors and printers.
This is why we need special functions to format data that is
input from or output to these devices.
13.32
Binary files
A binary file is a collection of data stored in the internal
format of the computer. In this definition, data can be an
integer (including other data types represented as unsigned
integers, such as image, audio, or video), a floating-point
number or any other structured data (except a file).
Unlike text files, binary files contain data that is meaningful
only if it is properly interpreted by a program. If the data is
textual, one byte is used to represent one character (in ASCII
encoding). But if the data is numeric, two or more bytes are
considered a data item.

More Related Content

What's hot

File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systemsvampugani
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiSowmya Jyothi
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3Ala Qunaibi
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
84640411 study-of-unix-os
84640411 study-of-unix-os84640411 study-of-unix-os
84640411 study-of-unix-oshomeworkping3
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File ManagementDamian T. Gordon
 
Os10
Os10Os10
Os10issbp
 
How to Interpret the Contents of Stored Memory Data
How to Interpret the Contents of Stored Memory DataHow to Interpret the Contents of Stored Memory Data
How to Interpret the Contents of Stored Memory Dataadil raja
 
File management ppt
File management pptFile management ppt
File management pptmarotti
 

What's hot (20)

DBMS
DBMSDBMS
DBMS
 
File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
 
File and fat 2
File and fat 2File and fat 2
File and fat 2
 
File
FileFile
File
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Ch10
Ch10Ch10
Ch10
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
File management
File managementFile management
File management
 
84640411 study-of-unix-os
84640411 study-of-unix-os84640411 study-of-unix-os
84640411 study-of-unix-os
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File Management
 
File system structure
File system structureFile system structure
File system structure
 
Basics of unix
Basics of unixBasics of unix
Basics of unix
 
Os10
Os10Os10
Os10
 
File management
File management File management
File management
 
How to Interpret the Contents of Stored Memory Data
How to Interpret the Contents of Stored Memory DataHow to Interpret the Contents of Stored Memory Data
How to Interpret the Contents of Stored Memory Data
 
File system implementation
File system implementationFile system implementation
File system implementation
 
File management ppt
File management pptFile management ppt
File management ppt
 

Viewers also liked

Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013MattKilner
 
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakProbabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakPyData
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashingJohan Tibell
 
Chapter 4 record storage and primary file organization
Chapter 4 record storage and primary file organizationChapter 4 record storage and primary file organization
Chapter 4 record storage and primary file organizationJafar Nesargi
 
Indexing and-hashing
Indexing and-hashingIndexing and-hashing
Indexing and-hashingAmi Ranjit
 
Best for b trees
Best for b treesBest for b trees
Best for b treesDineshRaaja
 
BTree, Data Structures
BTree, Data StructuresBTree, Data Structures
BTree, Data StructuresJibrael Jos
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2SHAKOOR AB
 
Op Sy 03 Ch 41
Op Sy 03 Ch 41Op Sy 03 Ch 41
Op Sy 03 Ch 41 Google
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 

Viewers also liked (20)

Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013Security in the Real World - JavaOne 2013
Security in the Real World - JavaOne 2013
 
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr PryymakProbabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashing
 
Hashing
HashingHashing
Hashing
 
Ds 8
Ds 8Ds 8
Ds 8
 
Chapter 4 record storage and primary file organization
Chapter 4 record storage and primary file organizationChapter 4 record storage and primary file organization
Chapter 4 record storage and primary file organization
 
Hashing
HashingHashing
Hashing
 
Indexing and-hashing
Indexing and-hashingIndexing and-hashing
Indexing and-hashing
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
BTree, Data Structures
BTree, Data StructuresBTree, Data Structures
BTree, Data Structures
 
File organisation
File organisationFile organisation
File organisation
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 
b+ tree
b+ treeb+ tree
b+ tree
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2Hashing Techniques in Data Structures Part2
Hashing Techniques in Data Structures Part2
 
File structures
File structuresFile structures
File structures
 
Op Sy 03 Ch 41
Op Sy 03 Ch 41Op Sy 03 Ch 41
Op Sy 03 Ch 41
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 

Similar to Computer

File Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasFile Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasPrabu U
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systemsdonny101
 
Learn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptLearn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptgeethasenthil2706
 
Week 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental ConceptsWeek 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental Conceptsoudesign
 
Operating Systems - Implementing File Systems
Operating Systems - Implementing File SystemsOperating Systems - Implementing File Systems
Operating Systems - Implementing File SystemsMukesh Chinta
 
Ch12 OS
Ch12 OSCh12 OS
Ch12 OSC.U
 
Linux File System.docx
Linux File System.docxLinux File System.docx
Linux File System.docxBhuvanaR13
 
Files Allocation.ppt
Files Allocation.pptFiles Allocation.ppt
Files Allocation.pptChinmaya M. N
 
Model of file system
Model of file systemModel of file system
Model of file systemIshucs
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingChereLemma2
 

Similar to Computer (20)

file management
 file management file management
file management
 
File Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasFile Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with Pandas
 
Dude.pptx
Dude.pptxDude.pptx
Dude.pptx
 
Chapter 12.pptx
Chapter 12.pptxChapter 12.pptx
Chapter 12.pptx
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
 
DFSNov1.pptx
DFSNov1.pptxDFSNov1.pptx
DFSNov1.pptx
 
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
 
Learn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptLearn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems ppt
 
Week 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental ConceptsWeek 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental Concepts
 
Operating Systems - Implementing File Systems
Operating Systems - Implementing File SystemsOperating Systems - Implementing File Systems
Operating Systems - Implementing File Systems
 
Files
FilesFiles
Files
 
Files
FilesFiles
Files
 
Files
FilesFiles
Files
 
Ch12 OS
Ch12 OSCh12 OS
Ch12 OS
 
OS_Ch12
OS_Ch12OS_Ch12
OS_Ch12
 
Linux File System.docx
Linux File System.docxLinux File System.docx
Linux File System.docx
 
File System operating system operating system
File System  operating system operating systemFile System  operating system operating system
File System operating system operating system
 
Files Allocation.ppt
Files Allocation.pptFiles Allocation.ppt
Files Allocation.ppt
 
Model of file system
Model of file systemModel of file system
Model of file system
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 

Computer

  • 2. 13.2  Define two categories of access methods: sequential access and random access.  Understand the structure of sequential files and how they are updated.  Understand the structure of indexed files and the relation between the index and the data file.  Understand the idea behind hashed files and describe some hashing methods.  Describe address collisions and how they can be resolved.  Define directories and how they can be used to organize files.  Distinguish between text and binary files. ObjectivesObjectives After studying this chapter, the student should be able to:After studying this chapter, the student should be able to:
  • 3. 13.3 13-1 ACCESS METHODS13-1 ACCESS METHODS When we design a file, the important issue is how weWhen we design a file, the important issue is how we will retrieve information (a specific record) from thewill retrieve information (a specific record) from the file. Sometimes we need to process records one afterfile. Sometimes we need to process records one after another, whereas sometimes we need to access aanother, whereas sometimes we need to access a specific record quickly without retrieving the precedingspecific record quickly without retrieving the preceding records. The access method determines how records canrecords. The access method determines how records can be retrieved:be retrieved: sequentiallysequentially oror randomlyrandomly..
  • 4. 13.4 Sequential access If we need to access a file sequentially—that is, one record after another, from beginning to end—we use a sequential file structure. Random access If we need to access a specific record without having to retrieve all records before it, we use a file structure that allows random access. Two file structures allow this: indexed files and hashed files. This taxonomy of file structures is shown in Figure 13.1.
  • 5. 13.5 Figure 13.1 A taxonomy of file structures
  • 6. 13.6 13-2 SEQUENTIAL FILES13-2 SEQUENTIAL FILES A sequential file is one in which records can only beA sequential file is one in which records can only be accessed one after another from beginning to end.accessed one after another from beginning to end. Figure 13.2 shows the layout of a sequential file.Figure 13.2 shows the layout of a sequential file. Records are stored one after another in auxiliaryRecords are stored one after another in auxiliary storage, such as tape or disk, and there is an EOF (end-storage, such as tape or disk, and there is an EOF (end- of-file) marker after the last record. The operatingof-file) marker after the last record. The operating system has no information about the record addresses, itsystem has no information about the record addresses, it only knows where the whole file is stored. The onlyonly knows where the whole file is stored. The only thing known to the operating system is that the recordsthing known to the operating system is that the records are sequential.are sequential.
  • 7. 13.7 Figure 13.2 A sequential file
  • 8. 13.8 Algorithm 13.1 shows how records in a sequential fileAlgorithm 13.1 shows how records in a sequential file are processed.are processed.
  • 9. 13.9 Updating sequential files Sequential files must be updated periodically to reflect changes in information. The updating process is very involved because all the records need to be checked and updated (if necessary) sequentially. Files involved in updating There are four files associated with an update program: the new master file, the old master file, the transaction file and the error report file. All these files are sorted based on key values. Figure 13.3 is a pictorial representation of a sequential file update.
  • 10. 13.10 Figure 13.3 Updating a sequential file
  • 11. 13.11 Processing file updates To make the updating process efficient, all files are sorted on the same key. This updating process is shown in Figure 13.4. Figure 13.4 Updating process
  • 12. 13.12 13-2 INDEXED FILES13-2 INDEXED FILES To access a record in a file randomly, we need to knowTo access a record in a file randomly, we need to know the address of the record.the address of the record. Figure 13.5 Mapping in an indexed file
  • 13. 13.13 Figure 13.6 Logical view of an indexed file
  • 14. 13.14 Inverted files One of the advantages of indexed files is that we can have more than one index, each with a different key. For example, an employee file can be retrieved based on either social security number or last name. This type of indexed file is usually called an inverted file.
  • 15. 13.15 12-2 HASHED FILES12-2 HASHED FILES AA hashed filehashed file uses a mathematical function touses a mathematical function to accomplish this mapping. The user gives the key, theaccomplish this mapping. The user gives the key, the function maps the key to the address and passes it to thefunction maps the key to the address and passes it to the operating system, and the record is retrieved (Figureoperating system, and the record is retrieved (Figure 13.7).13.7). Figure 13.7 Mapping in a hashed file
  • 16. 13.16 Hashing methods For key-address mapping, we can select one of several hashing methods. We discuss a few of them here. Direct hashing In direct hashing, the key is the data file address without any algorithmic manipulation. The file must therefore contain a record for every possible key. Although situations suitable for direct hashing are limited, it can be very powerful, because it guarantees that there are no synonyms or collisions (discussed later in this chapter), as with other methods.
  • 18. 13.18 Modulo division hashing Also known as division remainder hashing, the modulo division method divides the key by the file size and uses the remainder plus 1 for the address. This gives the simple hashing algorithm that follows, where list_size is the number of elements in the file. The reason for adding a 1 to the mod operation result is that our list starts with 1 instead of 0.
  • 19. 13.19 Figure 13.9 Modulo division
  • 20. 13.20 Digit extraction hashing Using digit extraction hashing, selected digits are extracted from the key and used as the address. For example, using our six-digit employee number to hash to a three-digit address (000–999), we could select the first, third and fourth digits (from the left) and use them as the address. Using the keys from Figure 13.9, we hash them to the following addresses: Other hashing methods Other popular methods exist, but we leave the exploration of these as exercises.
  • 21. 13.21 Collision Generally, the population of keys for a hashed list is greater than the number of records in the data file. For example, if we have a file of 50 students for a class in which the students are identified by the last four digits of their social security number, then there are 200 possible keys for each element in the file (10,000/50). 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. We call the set of keys that hash to the same address in our list synonyms. The collision concept is illustrated in Figure 13.10.
  • 22. 13.22 Figure 13.10 Collision
  • 23. 13.23 Collision resolution With the exception of the direct method, none of the methods we have discussed for hashing creates one-to-one mappings. This means that when we hash a new key to an address, we may create a collision. There are several methods for handling collisions, each of them independent of the hashing algorithm. That is, any hashing method can be used with any collision resolution method. In this section, we discuss some of these methods.
  • 24. 13.24 Figure 13.11 Open addressing resolution
  • 25. 13.25 Figure 13.12 Linked list resolution
  • 26. 13.26 Figure 13.13 Bucket hashing resolution
  • 27. 13.27 13-5 DIRECTORIES13-5 DIRECTORIES Directories are provided by most operating systems forDirectories are provided by most operating systems for organizing files. Aorganizing files. A directorydirectory performs the sameperforms the same function as a folder in a filing cabinet. However, afunction as a folder in a filing cabinet. However, a directory in most operating systems is represented as adirectory in most operating systems is represented as a special type of file that holds information about otherspecial type of file that holds information about other files. A directory not only serves as a kind of index thatfiles. A directory not only serves as a kind of index that tells the operating system where files are located on antells the operating system where files are located on an auxiliary storage device, but can also contain otherauxiliary storage device, but can also contain other information about the files it contains, such as who hasinformation about the files it contains, such as who has the access to each file, or the date when each file wasthe access to each file, or the date when each file was created, accessed or modified.created, accessed or modified.
  • 28. 13.28 Directories in the UNIX operating system In UNIX, the directory system is organized as shown in Figure 13.14. Figure 13.14 An example of the directory system in UNIX
  • 29. 13.29 Special directories There are four special types of directory that play an important role in the directory structure in UNIX: the root directory, home directories, working directories and parent directories. Paths and pathnames The file’s path is specified by its absolute pathname, a list of all directories separated by a slash character (/). UNIX also provides a shorter pathname, known as a relative pathname, which is the path relative to the working directory.
  • 30. 13.30 13-6 TEXT VERSUS BINARY13-6 TEXT VERSUS BINARY Two terms used to categorize files:Two terms used to categorize files: text filestext files andand binarybinary filesfiles. A file stored on a storage device is a sequence of. A file stored on a storage device is a sequence of bits that can be interpreted by an application program asbits that can be interpreted by an application program as a text file or a binary file, as shown in Figure 13.15.a text file or a binary file, as shown in Figure 13.15. Figure 13.15 Text and binary interpretations of a file
  • 31. 13.31 Text files A text file is a file of characters. It cannot contain integers, floating-point numbers, or any other data structures in their internal memory format. To store these data types, they must be converted to their character equivalent formats. Some files can only use character data types. Most notable are file streams (input/output objects in some object-oriented language like C++) for keyboards, monitors and printers. This is why we need special functions to format data that is input from or output to these devices.
  • 32. 13.32 Binary files A binary file is a collection of data stored in the internal format of the computer. In this definition, data can be an integer (including other data types represented as unsigned integers, such as image, audio, or video), a floating-point number or any other structured data (except a file). Unlike text files, binary files contain data that is meaningful only if it is properly interpreted by a program. If the data is textual, one byte is used to represent one character (in ASCII encoding). But if the data is numeric, two or more bytes are considered a data item.