• Save

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

File structures

on

  • 3,892 views

This presentation gives a basic introduction to files as a Data Structure. Physical Files and Logical Files are covered. Files as a collection of records and as a stream of bytes are talked about. ...

This presentation gives a basic introduction to files as a Data Structure. Physical Files and Logical Files are covered. Files as a collection of records and as a stream of bytes are talked about. Basic operations in files are explained. C syntax is given. Types of files are briefly talked about.

Statistics

Views

Total Views
3,892
Views on SlideShare
3,889
Embed Views
3

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 3

https://bbpilot.nku.edu 3

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

File structures File structures Presentation Transcript

  •  
  • PRIMARY STORAGE SECONDARY STORAGE 1)Faster Access Slower Access 2)Expensive Cheaper 3)Lesser storage capacity Greater Storage capacity 4)Temporary Storage Permanent Storage
    • Secondary Storage Structure
    • Used for permanent storage
    • It’s a collection of records or a stream of bytes
    • Every Record is a collection of fields
    • A particular field is chosen as a Key
    • Records are organised in file by using the key. Primary and secondary keys.
    • Consider a student database.
    • Every student has a unique record
    • Record has details of student-i.e name, Student ID etc. These are the fields.
    • The unique key can be the Student ID. The records can be organised in the file on basis of student ID.
    • Sometimes data is too large to be stored in main memory.
    • Maintaining permanent record is possible only by using a secondary storage. Hence files.
    • Physical Files:
    • A collection of bits stored in the secondary storage device
    • Logical File:
    • A channel that connects he program to the physical file(Stream).
    • An example
    • FILE* out
    • out=fopen(“sample.txt”,”w”);
    • Here out is the logical file and sample.txt is the physical file.
    • Opening a File:
    • A logical file is associated with the physical file
    • Closing a File:
    • The logical file associated with the physical file is freed.
    • fclose(file pointer);
    • Readin g from file:
    • Data present in physical file is read by using the logical file
    • Writing to a File
    • Data can be written to physical file by using the logical file
    • Every logical file has a file position pointer.
    • When we open a new stream the position pointer is set to beginning of the file.
    • As data is read or written the file position pointer is moved accordingly.
    • To move file pointer to required position.
    • fseek(file pointer,offset, position); 
    • To display current location of pointer.
    • long position=ftell(pointer);
    • To check for end of file
    • while(!feof(pointer));
    • Sequential File
    • Stored in the order entered
    • Random Access Files
    • An record is accessed using an index.(Hashing).
    • Direct Access Files:
    • The records are stored based on their relative position with respect to first record.
    • Record with key 50 is placed at location 50
    • Records are stored in the order entered
    • Used when all the records have to be processed.
    • Complexity for searching O(n)
    • An record is accessed using an index.
    • The index of record position in file has to be maintained in the main memory.
    • The Index can be created using hashing.
    • Search complexity is less. Complexity of Indexing method used.
    • Disadvantage: While handling very large databases its not possible to maintain an index in the main memory.
    • The records are stored based on their relative position with respect to first record.
    • Record with key 50 is placed at location 50
    • The search complexity is O(1)
    • Disadvantage is a lot of memory is wasted.
    • For example if no record has key 100 the position 100 is wasted.