Data Types and Structures Flashcards
What is meant by a serial file?
A file in which data is stored in time order only. New data is added to the end of the file.
Simple and on the whole easier to implement.
Adding new records is easy.
Searching can be extremely slow.
How is data retrieved from a serial file?
Check the file is not empty.
If it is empty, report ‘Empty’ and stop.
If it is not empty, start at the first record in the file
Check if it is the record you want.
If it is, report ‘Record found’ and stop.
If it is not, get the next record and repeat, until you either find the record you want or you get to the end of the file.
If you get to the end of the file, report ‘File not found’.
How is data deleted from a serial file?
Create a new file, copy all content except file that needs deleting, clear the original and save the new.
What is meant by a sequential file?
A file in which data is stored in some other defined order than time.
What is an indexed sequential file?
Data is stored in some order other than time and is organised according to a primary key, which allows groups of records to be accessed directly.
New data needs to be inserted correctly and the index updated.
Fast access to individual files.
Have to maintain the key.
What is a random access file?
A file to which access is extremely fast through the use of hashing algorithms to find the correct file straight away.
Hashing can cause redundancy due to files being spread out over very large areas.
What is hashing?
Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value.
How would you update a file?
If you wanted to update a file:
a) You would need to get the original file, using DECLARE, ASSIGN, OPEN and READ or WRITE as described above. b) You then need to create a second file, using DECLARE, ASSIGN, OPEN and READ or WRITE as described above. c) You would copy across the original data plus the extra data into this second file. d) The first, original file would then be renamed as a backup file. e) The second updated file would be given the name of the original file. f) Close the files.
How would you delete or append a file?
Inserting and deleting data in a file requires two files and is similar to updating a file:
a) You would need to get the original file, using DECLARE, ASSIGN, OPEN and READ or WRITE as described above. b) You then need to create a second file, using DECLARE, ASSIGN, OPEN and READ or WRITE as described above. c) You would copy across the original data to the second file, up to the point you want to add or delete some data. d) You then add or delete the data you want to add or delete. e) You then copy the remaining part of the file from the first file across to the second file. f) The first, original file would then be renamed as a backup file. g) The second updated file would be given the name of the original file. h) Close the files.
What is a two dimensional array?
A collection of data entries all of the same data type.
They can be represented using a tables as they use two index numbers.
It is called using a single identifier followed by the location, of the data referred to, in the array.
What is an array?
An array is a set of data items of the same type grouped together using a single identifier.