0% found this document useful (0 votes)
36 views14 pages

DSA Unit VI

The document discusses various file organization methods in computer engineering, including sequential, indexed sequential, and direct access file organizations, along with their advantages and disadvantages. It also covers operations performed on sequential files such as adding, deleting, and searching records, and provides pseudo code for these operations. Additionally, it highlights the importance of file organization factors and indexing techniques for efficient data retrieval.
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)
36 views14 pages

DSA Unit VI

The document discusses various file organization methods in computer engineering, including sequential, indexed sequential, and direct access file organizations, along with their advantages and disadvantages. It also covers operations performed on sequential files such as adding, deleting, and searching records, and provides pseudo code for these operations. Additionally, it highlights the importance of file organization factors and indexing techniques for efficient data retrieval.
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

SRES’s

SHREE RAMCHANDRA COLLEGE OF ENGINEERING


Lonikand, Pune – 412216
Department of Computer Engineering

DSA Unit VI

Q. Define sequential file organization. Give it’s advantages and disadvantages.


[May 2022 6M]

A sequential file contains records organized by the order in which they were
entered. The order of the records is fixed. Records in sequential files can be read or
written only sequentially. After you place a record into a sequential file, you
cannot shorten, lengthen, or delete the record.

Advantages
equential processing ensures that instructions are executed in a predictable and
ordered manner, allowing for reliable and consistent results. It is essential for tasks
that require a specific sequence of steps to be performed correctly.

Disadvantages
It can be time-consuming because it doesn't allow for accessing a specific record
directly. Instead, it requires sequential access, which can be slow. Sorting records
in the sorted file method can take more time and space.

Q. What is file? List different file opening modes in C++. Explain concept
of inverted files. [May 2022 6M]
File is a a collection of related data records .

Shree Ramchandra College of Engineering ,Pune Page 1


Q. Explain indexed sequential file organization. Compare it with direct access
file. [May 2022 5M]

Direct access file organization


Direct access file is also known as random access or relative file organization.
In direct access file, all records are stored in direct access storage device (DASD),
such as hard disk. The records are randomly placed throughout the file. The
records does not need to be in sequence because they are updated directly and
rewritten back in the same location. This file organization is useful for immediate
access to large amount of information. It is used in accessing large databases. It is
also called as hashing. Advantages of direct access file organization
Direct access file helps in online transaction processing system (OLTP) like online
railway reservation system. In direct access file, sorting of the records are not
required. It accesses the desired records immediately. It updates several files
quickly. It has better control over record allocation.
Disadvantages of direct access file organization
Direct access file does not provide back up facility. It is expensive. It has less
storage space as compared to sequential file.

Shree Ramchandra College of Engineering ,Pune Page 2


Q. A write a C++ program to create a file. Insert records into the file by
opening file in append mode. Search for a specific record into file. [May 2022
6M]

Q. Explain multilist files & coral rings. [May 2023 9M]

Q. What is Sequential and index sequential file organization? State its


advantages and disadvantages. [May 2023 8 M]

Sequential access file organization


• Storing and sorting in contiguous block within files on tape or disk is called as
sequential access file organization.
• In sequential access file organization, all records are stored in a sequential order.
The records are arranged in the ascending or descending order of a key field.

Shree Ramchandra College of Engineering ,Pune Page 3


• Sequential file search starts from the beginning of the file and the records can be
added at the end of the file.
• In sequential file, it is not possible to add a record in the middle of the file
without rewriting the file.
Advantages of sequential file:
• It is simple to program and easy to design. • Sequential file is best use if storage
space.
Disadvantages of sequential file :
• Sequential file is time consuming process. • It has high data redundancy. •
Random searching is not possible
Indexed sequential access file organization
• Indexed sequential access file combines both sequential file and direct access file
organization.
• In indexed sequential access file, records are stored randomly on a direct access
device such as magnetic disk by a primary key.
• This file have multiple keys. These keys can be alphanumeric in which the
records are ordered is called primary key.
• The data can be access either sequentially or randomly using the index. The index
is stored in a file and read into memory when the file is opened.
Advantages of Indexed sequential access
file organization
• In indexed sequential access file, sequential file and random file access is
possible.
• It accesses the records very fast if the index table is properly organized.
• The records can be inserted in the middle of the file.
• It provides quick access for sequential and direct processing.
• It reduces the degree of the sequential search.
Disadvantages of Indexed sequential access file organization
• Indexed sequential access file requires unique keys and periodic reorganization.
• Indexed sequential access file takes longer time to search the index for the data
access or retrieval.
• It requires more storage space.
• It is expensive because it requires special software.
• It is less efficient in the use of storage space as compared to other file
organizations.
Q. Write short notes on: [Nov 2022 6M]
i) Factors affecting the file organization
ii) Indexed sequential files
iii) Indexing techniques

Shree Ramchandra College of Engineering ,Pune Page 4


i) Factors affecting the file organization

In choosing a file organization for a particular file in a database, we should


consider seven important factors:

 Fast data retrieval.

 High amount of work for processing data input & maintenance transaction.

 Efficient use of storage space.

 Protection from failures or data loss.

 Minimizing need for reorganization.

 Accommodating growth.

 Security from unauthorized use.

ii) Indexed sequential files:

ISAM method is an advanced sequential file organization. In this method, records


are stored in the file using the primary key. An index value is generated for each
primary key and mapped with the record. This index contains the address of the
record in the file.

Shree Ramchandra College of Engineering ,Pune Page 5


If any record has to be retrieved based on its index value, then the address of the
data block is fetched and the record is retrieved from the memory.

Pros of ISAM:

o In this method, each record has the address of its data block, searching a
record in a huge database is quick and easy.
o This method supports range retrieval and partial retrieval of records. Since
the index is based on the primary key values, we can retrieve the data for the
given range of value. In the same way, the partial value can also be easily
searched, i.e., the student name starting with 'JA' can be easily searched.

Cons of ISAM

o This method requires extra space in the disk to store the index value.
o When the new records are inserted, then these files have to be reconstructed
to maintain the sequence.
o When the record is deleted, then the space used by it needs to be released.
Otherwise, the performance of the database will slow down.

Shree Ramchandra College of Engineering ,Pune Page 6


iii) Indexing techniques:

Indexing is a data structure technique that helps to speed up data retrieval. As we


can quickly locate and access the data in the database, it is a must-know data
structure that will be needed for database optimizing. Indexing minimizes the
number of disk accesses required when a query is processed. Indexes are created as
a combination of the two columns.

 First column is the Search key. It contains a copy of the primary key or
candidate key of the table. The values of this column may be sorted or
not. But if the values are sorted, the corresponding data can be accessed
easily.

 Second column is the Data reference or Pointer. It contains the address


of the disk block where we can find the corresponding key value.

Q. Compare sequential indexed sequential and direct access files. [Nov 2022
6M]

Sequential access file organization


• Storing and sorting in contiguous block within files on tape or disk is called as
sequential access file organization.

Shree Ramchandra College of Engineering ,Pune Page 7


• In sequential access file organization, all records are stored in a sequential order.
The records are arranged in the ascending or descending order of a key field.
• Sequential file search starts from the beginning of the file and the records can be
added at the end of the file.
• In sequential file, it is not possible to add a record in the middle of the file
without rewriting the file. Advantages of sequential file
• It is simple to program and easy to design.
• Sequential file is best use if storage space.
Disadvantages of sequential file
• Sequential file is time consuming process.
• It has high data redundancy.
• Random searching is not possible.
Direct access file organization
• Direct access file is also known as random access or relative file organization.
• In direct access file, all records are stored in direct access storage device
(DASD), such as hard disk. The records are randomly placed throughout the file.
• The records does not need to be in sequence because they are updated directly
and rewritten back in the same location.
• This file organization is useful for immediate access to large amount of
information. It is used in accessing large databases. • It is also called as hashing.
Advantages of direct access file organization
• Direct access file helps in online transaction processing system (OLTP) like
online railway reservation system.
• In direct access file, sorting of the records are not required.
• It accesses the desired records immediately.
• It updates several files quickly.
• It has better control over record allocation.
Disadvantages of direct access file organization
• Direct access file does not provide back up facility.
• It is expensive.
• It has less storage space as compared to sequential file.

Q. Explain any 4 modes of opening the file in C or C++. [Nov 2022 5M]

Shree Ramchandra College of Engineering ,Pune Page 8


Q. Explain following operations carried out on sequential files. [Nov 2022
6M]
i) Add
ii) Delete
iii) Search

i) Add:

When adding records to a sequential file, the new record is typically appended to
the end of the file. The process involves opening the file in append mode,
positioning the file pointer at the end of the file, and then writing the new
record.This operation is relatively straightforward and efficient because it doesn't
require rearranging existing records. It's commonly used for tasks like logging new
data entries, appending new transactions to a transaction log, or adding new entries
to a sequential data structure.

ii) Delete:

Deleting records from a sequential file can be more complex compared to


additionbecause it involves removing a specific record without leaving any gaps.

Shree Ramchandra College of Engineering ,Pune Page 9


One approach is to rewrite the entire file, excluding the record you want to delete.
This process requires reading the file sequentially, identifying the record to be
deleted, and then rewriting the file without including that record. Alternatively,
you can mark the record as "deleted" or use a flag to indicate that it should be
skipped during subsequent operations. However, this approach doesn't physically
remove the record from the file. Deletion in sequential files can be less efficient
compared to other file organization methods like random access files, especially
when dealing with large files.

iii)Search:

Searching for records in a sequential file involves scanning through the file
sequentially from the beginning until the desired record is found.This process starts
by opening the file and reading records one by one until the target record is located
or until the end of the file is reached.Sequential search can be inefficient,
especially for large files, because it requires reading through the entire file, which
may take a considerable amount of time.If the records in the file are sorted based
on a key field, binary search techniques can be applied to improve search
efficiency. However, sorting the file initially can be an additional
overhead.Searching in sequential files is suitable for applications where the
primary access pattern is sequential, and real-time random access to individual
records is not crucial.

Q. Explain any 3 operations carried out on sequential file and its pseudo
code. [Nov 2022 6M]

1. Adding Records:

When adding records to a sequential file, the new record is typically


appended to the end of the file.The process involves opening the file
in append mode, positioning the file pointer at the end of the file, and
then writing the new record.Below is a pseudo code example for
adding a record to a sequential file:

Shree Ramchandra College of Engineering ,Pune Page 10


pseudo code

Procedure AddRecordToFile(file, record):

Open file in append mode

Write record to the end of the file

Close the file

2. Deleting Records:

Deleting records from a sequential file involves removing a specific


record without leaving any gaps.One approach is to rewrite the entire file,
excluding the record you want to delete. This process requires reading the
file sequentially, identifying the record to be deleted, and then rewriting
the file without including that record.Below is a pseudo code example for
deleting a record from a sequential file:

pseudo code

Procedure DeleteRecordFromFile(file, recordToDelete):

Open file in read mode

Open a temporary file in write mode

While(record=ReadNextRecord(file)) is not null:

If record is not equal torecordToDelete:

Write record to the temporary file

Shree Ramchandra College of Engineering ,Pune Page 11


Close both files

Replace the original file with the temporary file

3. Searching for Records:

Searching for records in a sequential file involves scanning through


the file sequentially from the beginning until the desired record is
found.This process starts by opening the file and reading records one
by one until the target record is located or until the end of the file is
reached.Below is a pseudo code example for searching for a record in
a sequential file:

pseudo code

Function SearchRecordInFile(file, target):

Open file in read mode

While (record = ReadNextRecord(file)) is not null:

If record is equal to target:

Close the file Return record

Close the file Return "Record not found"

Q. A file of employees records, has ‘employee no’ as primary key and the
‘department code’ and the ‘designation code’ as the secondary keys.
Write a procedure to answer the following query – ‘Which employees

Shree Ramchandra College of Engineering ,Pune Page 12


from systems department are above designation level 4? [Nov 2022 5M]

Procedure FindEmployeesAboveLevel4InSystemsDepartment(file):

Open file in read mode

Initialize a list to store matching employee records

While (record = ReadNextRecord(file)) is not null:

If record.department_code == "Systems" and


record.designation_level > 4:

Add record to the l

Close the file

In this procedure:

We open the file in read mode. We initialize an empty list to store


matching employee records. We iterate through each record in the file.
For each record, we check if the department code is "Systems" and if
the designation level is greater than 4.If the conditions are met, we add
the record to the list. Finally, we close the file and return the list of
matching employee records.

This procedure will effectively find and return all employee records
from the Systems department with a designation level above 4.

Q. Explain direct access file organization. State its advantages and


disadvantages. [May 2023 8 M]

Direct access file organization


• Direct access file is also known as random access or relative file organization.
• In direct access file, all records are stored in direct access storage device
(DASD), such as hard disk. The records are randomly placed throughout the file.
• The records does not need to be in sequence because they are updated directly
and rewritten back in the same location.
• This file organization is useful for immediate access to large amount of
information. It is used in accessing large databases. • It is also called as hashing.
Advantages of direct access file organization

Shree Ramchandra College of Engineering ,Pune Page 13


• Direct access file helps in online transaction processing system (OLTP) like
online railway reservation system.
• In direct access file, sorting of the records are not required.
• It accesses the desired records immediately.
• It updates several files quickly.
• It has better control over record allocation.
Disadvantages of direct access file organization
• Direct access file does not provide back up facility.
• It is expensive.
• It has less storage space as compared to sequential file.

Shree Ramchandra College of Engineering ,Pune Page 14

You might also like