• Like
  • 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.

File structures

  • 3,753 views
Uploaded on

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.

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,753
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.  
  • 2. PRIMARY STORAGE SECONDARY STORAGE 1)Faster Access Slower Access 2)Expensive Cheaper 3)Lesser storage capacity Greater Storage capacity 4)Temporary Storage Permanent Storage
  • 3.
    • 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.
  • 4.
    • 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.
  • 5.
    • Sometimes data is too large to be stored in main memory.
    • Maintaining permanent record is possible only by using a secondary storage. Hence files.
  • 6.
    • 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.
  • 7.
    • 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
  • 8.
    • 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.
  • 9.
    • 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));
  • 10.
    • 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
  • 11.
    • Records are stored in the order entered
    • Used when all the records have to be processed.
    • Complexity for searching O(n)
  • 12.
    • 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.
  • 13.
    • 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.